Skip to content

Commit a595166

Browse files
authored
Merge pull request #1895 from argentlabs/hotfix/unknown-nft-sim
hotfix: adapt to backend simulation api
2 parents d909bde + e8fe58e commit a595166

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

packages/extension/src/shared/transactionSimulation/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ export interface TransactionSimulationApproval {
1212
tokenAddress: string
1313
owner: string
1414
spender: string
15-
value: string
15+
value?: string
16+
tokenId?: string
1617
details?: TokenDetails
1718
}
1819

1920
export interface TransactionSimulationTransfer {
2021
tokenAddress: string
2122
from: string
2223
to: string
23-
value: string
24+
value?: string
25+
tokenId?: string
2426
details?: TokenDetails
2527
}
2628

packages/extension/src/ui/features/actions/transaction/useTransactionSimulatedData.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export const useAggregatedSimData = (
138138
details: t.details,
139139
erc20TokensRecord,
140140
nftContracts,
141-
tokenId: t.value,
141+
tokenId: t.tokenId ?? t.value, // For fallback compatibility, we use the value as the tokenId. This will be ignored for ERC20 tokens
142142
networkId: network.id,
143143
})
144144

@@ -157,7 +157,7 @@ export const useAggregatedSimData = (
157157
details: a.details,
158158
erc20TokensRecord,
159159
nftContracts,
160-
tokenId: a.value,
160+
tokenId: a.tokenId ?? a.value, // For fallback compatibility, we use the value as the tokenId. This will be ignored for ERC20 tokens
161161
networkId: network.id,
162162
})
163163

@@ -217,7 +217,7 @@ export const useAggregatedSimData = (
217217
token: a.token,
218218
owner: a.owner,
219219
spender: a.spender,
220-
amount: BigNumber(a.token.type === "erc721" ? 1 : a.value),
220+
amount: BigNumber(a.value ?? 1),
221221
usdValue: a.usdValue ? BigNumber(a.usdValue) : undefined,
222222
}))
223223
.filter((a) => a.owner === account?.address) ?? []
@@ -239,10 +239,10 @@ export const useAggregatedSimData = (
239239
const amount = transfers.reduce<BigNumber>((acc, t) => {
240240
const isTokenTranfer = checkIsTokenTransfer(t)
241241
if (isTokenTranfer && t.from === account?.address) {
242-
return t.token.type === "erc721" ? acc.minus(1) : acc.minus(t.value)
242+
return acc.minus(t.value ?? ONE) // This works because ERC721 tokens have value undefined and the amount is always 1
243243
}
244244

245-
return t.token.type === "erc721" ? acc.plus(1) : acc.plus(t.value)
245+
return acc.plus(t.value ?? ONE)
246246
}, ZERO)
247247

248248
const usdValue = transfers.reduce<BigNumber>((acc, t) => {
@@ -259,7 +259,7 @@ export const useAggregatedSimData = (
259259
}, ZERO)
260260

261261
const recipients = transfers.reduce<Recipient[]>((acc, t) => {
262-
const amount = t.token.type === "erc721" ? ONE : BigNumber(t.value)
262+
const amount = BigNumber(t.value ?? 1)
263263

264264
const negated = amount.negated()
265265
const isTokenTranfer = checkIsTokenTransfer(t)
@@ -330,7 +330,7 @@ export function apiTokenDetailsToToken({
330330
tokenAddress: string
331331
details?: TokenDetails
332332
networkId: string
333-
tokenId: string
333+
tokenId?: string
334334
erc20TokensRecord: Record<string, Token>
335335
nftContracts?: string[]
336336
}): TokenWithType | undefined {

0 commit comments

Comments
 (0)