Skip to content

Commit 47a660e

Browse files
committed
fix approve and simulation convert
1 parent a0c9612 commit 47a660e

File tree

3 files changed

+73
-55
lines changed

3 files changed

+73
-55
lines changed

src/modules/ethereum/transactions/addressAction/addressActionMain.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ export function convertAssetToFungibleOutline(
8888
};
8989
}
9090

91-
function convertNftToNftPreview(nft: NFT): NFTPreview {
91+
export function convertNftToNftPreview(nft: NFT | null): NFTPreview | null {
92+
if (!nft) {
93+
return null;
94+
}
9295
return {
9396
chain: nft.chain,
9497
contractAddress: nft.contract_address,

src/modules/ethereum/transactions/interpret.ts

Lines changed: 68 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { baseToCommon } from 'src/shared/units/convert';
2-
import type { Asset, AddressAction, Client } from 'defi-sdk';
2+
import type { Asset, AddressAction, Client, NFT } from 'defi-sdk';
33
import { client as defaultClient } from 'defi-sdk';
44
import { rejectAfterDelay } from 'src/shared/rejectAfterDelay';
55
import { valueToHex } from 'src/shared/units/valueToHex';
@@ -11,8 +11,11 @@ import type { TypedData } from '../message-signing/TypedData';
1111
import type { InterpretResponse } from './types';
1212
import { getGas } from './getGas';
1313
import type { ChainId } from './ChainId';
14-
import { getFungibleAsset } from './actionAsset';
15-
import { convertAssetToFungibleOutline } from './addressAction';
14+
import { getFungibleAsset, getNftAsset } from './actionAsset';
15+
import {
16+
convertAssetToFungibleOutline,
17+
convertNftToNftPreview,
18+
} from './addressAction';
1619

1720
type LegacyInterpretResponse = Omit<InterpretResponse, 'action'> & {
1821
action: AddressAction | null;
@@ -129,73 +132,85 @@ async function convertToNewInterpretation(
129132
direction: 'in' as const,
130133
amount: {
131134
currency,
132-
quantity: baseToCommon(
133-
transfer.quantity,
134-
getDecimals({
135-
asset: getFungibleAsset(
136-
transfer.asset
137-
) as Asset,
138-
chain: createChain(
139-
legacyAction.transaction.chain
140-
),
141-
})
142-
).toFixed(),
143-
value: baseToCommon(
144-
transfer.quantity,
145-
getDecimals({
146-
asset: getFungibleAsset(
147-
transfer.asset
148-
) as Asset,
149-
chain: createChain(
150-
legacyAction.transaction.chain
151-
),
152-
})
153-
)
154-
.multipliedBy(transfer.price || 0)
155-
.toNumber(),
135+
quantity: getFungibleAsset(transfer.asset)
136+
? baseToCommon(
137+
transfer.quantity,
138+
getDecimals({
139+
asset: getFungibleAsset(
140+
transfer.asset
141+
) as Asset,
142+
chain: createChain(
143+
legacyAction.transaction.chain
144+
),
145+
})
146+
).toFixed()
147+
: '1',
148+
value: getFungibleAsset(transfer.asset)
149+
? baseToCommon(
150+
transfer.quantity,
151+
getDecimals({
152+
asset: getFungibleAsset(
153+
transfer.asset
154+
) as Asset,
155+
chain: createChain(
156+
legacyAction.transaction.chain
157+
),
158+
})
159+
)
160+
.multipliedBy(transfer.price || 0)
161+
.toNumber()
162+
: null,
156163
usdValue: null,
157164
},
158165
fungible: convertAssetToFungibleOutline(
159166
getFungibleAsset(transfer.asset)
160167
),
161-
nft: null,
168+
nft: convertNftToNftPreview(
169+
getNftAsset(transfer.asset) as NFT | null
170+
),
162171
})
163172
) || []),
164173
...(legacyAction.content.transfers.outgoing?.map(
165174
(transfer) => ({
166175
direction: 'out' as const,
167176
amount: {
168177
currency,
169-
quantity: baseToCommon(
170-
transfer.quantity,
171-
getDecimals({
172-
asset: getFungibleAsset(
173-
transfer.asset
174-
) as Asset,
175-
chain: createChain(
176-
legacyAction.transaction.chain
177-
),
178-
})
179-
).toFixed(),
180-
value: baseToCommon(
181-
transfer.quantity,
182-
getDecimals({
183-
asset: getFungibleAsset(
184-
transfer.asset
185-
) as Asset,
186-
chain: createChain(
187-
legacyAction.transaction.chain
188-
),
189-
})
190-
)
191-
.multipliedBy(transfer.price || 0)
192-
.toNumber(),
178+
quantity: getFungibleAsset(transfer.asset)
179+
? baseToCommon(
180+
transfer.quantity,
181+
getDecimals({
182+
asset: getFungibleAsset(
183+
transfer.asset
184+
) as Asset,
185+
chain: createChain(
186+
legacyAction.transaction.chain
187+
),
188+
})
189+
).toFixed()
190+
: '1',
191+
value: getFungibleAsset(transfer.asset)
192+
? baseToCommon(
193+
transfer.quantity,
194+
getDecimals({
195+
asset: getFungibleAsset(
196+
transfer.asset
197+
) as Asset,
198+
chain: createChain(
199+
legacyAction.transaction.chain
200+
),
201+
})
202+
)
203+
.multipliedBy(transfer.price || 0)
204+
.toNumber()
205+
: null,
193206
usdValue: null,
194207
},
195208
fungible: convertAssetToFungibleOutline(
196209
getFungibleAsset(transfer.asset)
197210
),
198-
nft: null,
211+
nft: convertNftToNftPreview(
212+
getNftAsset(transfer.asset) as NFT | null
213+
),
199214
})
200215
) || []),
201216
]

src/ui/pages/SendTransaction/SendTransaction.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ function SendTransactionContent({
771771
const allowanceQuantityCommon =
772772
fungibleDecimals && allowanceQuantityBase
773773
? baseToCommon(allowanceQuantityBase, fungibleDecimals).toFixed()
774-
: requestedAllowanceQuantityBase;
774+
: requestedAllowanceQuantityCommon;
775775

776776
if (!addressAction) {
777777
return null;

0 commit comments

Comments
 (0)