Skip to content

Commit 7f08d28

Browse files
fix: handle amounts and prices per investor tx (#302)
* Handle amounts and prices per investor tx * [bot] New pkg version: 0.40.2 --------- Co-authored-by: GitHub Actions <[email protected]>
1 parent fb5303d commit 7f08d28

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@centrifuge/sdk",
3-
"version": "0.40.1",
3+
"version": "0.40.2",
44
"description": "",
55
"homepage": "https://github.com/centrifuge/sdk/tree/main#readme",
66
"author": "",

src/entities/Investor.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Centrifuge } from '../Centrifuge.js'
33
import type { HexString } from '../types/index.js'
44
import { AssetId, PoolId, ShareClassId } from '../utils/types.js'
55
import { Entity } from './Entity.js'
6-
import { Balance } from '../utils/BigInt.js'
6+
import { Balance, Price } from '../utils/BigInt.js'
77

88
export class Investor extends Entity {
99
address: HexString
@@ -131,8 +131,9 @@ export class Investor extends Entity {
131131
id: string
132132
address: string
133133
} | null
134-
token: { name: string; symbol: string; decimals: string }
135-
tokenAmount: string
134+
token: { name: string; symbol: string; decimals: string } | null
135+
tokenAmount: string | null
136+
tokenPrice: string | null
136137
centrifugeId: string
137138
poolId: string
138139
}[]
@@ -141,10 +142,10 @@ export class Investor extends Entity {
141142
}>(
142143
`query ($address: String!, $poolId: BigInt!, $limit: Int!, $offset: Int!) {
143144
investorTransactions(
144-
where: {
145+
where: {
145146
account: $address,
146147
poolId: $poolId
147-
}
148+
}
148149
limit: $limit
149150
offset: $offset
150151
) {
@@ -162,6 +163,7 @@ export class Investor extends Entity {
162163
}
163164
token { name symbol decimals }
164165
tokenAmount
166+
tokenPrice
165167
centrifugeId
166168
poolId
167169
}
@@ -181,29 +183,33 @@ export class Investor extends Entity {
181183

182184
return {
183185
transactions: investorTransactions.items
184-
.filter((item) => item.poolId === poolId.toString() && item.currencyAsset !== null)
186+
.filter((item) => item.poolId === poolId.toString())
185187
.map((item) => {
186188
const chainId = chainsById.get(item.centrifugeId)
187189
if (!chainId) return null
188-
if (!item.currencyAsset) return null
189190

190191
return {
191192
type: item.type,
192193
txHash: item.txHash,
193194
createdAt: item.createdAt,
194-
currency: {
195-
amount: new Balance(item.currencyAmount, item.currencyAsset.decimals),
196-
symbol: item.currencyAsset.symbol,
197-
decimals: item.currencyAsset.decimals,
198-
id: item.currencyAsset.id,
199-
address: item.currencyAsset.address,
200-
},
201-
token: {
202-
name: item.token.name,
203-
symbol: item.token.symbol,
204-
decimals: Number(item.token.decimals),
205-
amount: new Balance(item.tokenAmount, Number(item.token.decimals)),
206-
},
195+
currency: item.currencyAsset
196+
? {
197+
amount: new Balance(item.currencyAmount, item.currencyAsset.decimals),
198+
symbol: item.currencyAsset.symbol,
199+
decimals: item.currencyAsset.decimals,
200+
id: item.currencyAsset.id,
201+
address: item.currencyAsset.address,
202+
}
203+
: undefined,
204+
token: item.token && item.tokenAmount
205+
? {
206+
name: item.token.name,
207+
symbol: item.token.symbol,
208+
decimals: Number(item.token.decimals),
209+
amount: new Balance(item.tokenAmount, Number(item.token.decimals)),
210+
}
211+
: undefined,
212+
tokenPrice: item.tokenPrice ? new Price(item.tokenPrice) : undefined,
207213
chainId: Number(chainId),
208214
poolId: item.poolId,
209215
}

0 commit comments

Comments
 (0)