From a216c032a068ed8cf3590a238022969a8a2fa757 Mon Sep 17 00:00:00 2001 From: banklesss <105349292+banklesss@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:16:35 +0100 Subject: [PATCH] fix(wallet-mobile): tx review reference inputs (#3770) --- .../ReviewTx/common/hooks/useFormattedTx.tsx | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/apps/wallet-mobile/src/features/ReviewTx/common/hooks/useFormattedTx.tsx b/apps/wallet-mobile/src/features/ReviewTx/common/hooks/useFormattedTx.tsx index 9d1e97a0ef..f4b0420786 100644 --- a/apps/wallet-mobile/src/features/ReviewTx/common/hooks/useFormattedTx.tsx +++ b/apps/wallet-mobile/src/features/ReviewTx/common/hooks/useFormattedTx.tsx @@ -66,8 +66,8 @@ export const useFormattedTx = (data: TransactionBody): FormattedTx => { ]) const portfolioTokenInfos = usePortfolioTokenInfos({wallet, tokenIds}, {suspense: true}) - const formattedInputs = useFormattedInputs(wallet, inputs, portfolioTokenInfos, inputUtxos) - const formattedReferenceInputs = useFormattedInputs(wallet, inputs, portfolioTokenInfos, referenceInputUtxos) + const formattedInputs = useFormattedInputs(wallet, portfolioTokenInfos, inputUtxos) + const formattedReferenceInputs = useFormattedInputs(wallet, portfolioTokenInfos, referenceInputUtxos) const formattedOutputs = useFormattedOutputs(wallet, outputs, portfolioTokenInfos) const formattedFee = formatFee(wallet, data) const formattedCertificates = formatCertificates(data.certs) @@ -85,13 +85,12 @@ export const useFormattedTx = (data: TransactionBody): FormattedTx => { export const useFormattedInputs = ( wallet: YoroiWallet, - inputs: TransactionInputs, tokenInfosResult: ReturnType, inputUtxos: ReturnType, ) => { const query = useQuery( - ['useFormattedInputs', inputs, inputUtxos], - async () => formatInputs(wallet, inputs, tokenInfosResult, inputUtxos), + ['useFormattedInputs', inputUtxos], + async () => formatInputs(wallet, tokenInfosResult, inputUtxos), { suspense: true, }, @@ -120,19 +119,13 @@ export const useFormattedOutputs = ( const formatInputs = async ( wallet: YoroiWallet, - inputs: TransactionInputs, portfolioTokenInfos: ReturnType, inputUtxos: ReturnType, ): Promise => { - if (inputUtxos.length === 0) return Promise.resolve([]) - return Promise.all( - inputs.map(async (input) => { - const receiveUTxO = inputUtxos.find( - (utxo) => utxo?.tx_hash === input.transaction_id && utxo?.tx_index === input.index, - ) - const address = receiveUTxO?.receiver - const coin = receiveUTxO?.amount != null ? asQuantity(receiveUTxO.amount) : null + inputUtxos.map(async (utxo) => { + const address = utxo?.receiver + const coin = utxo?.amount != null ? asQuantity(utxo.amount) : null const addressKind = address != null ? await getAddressKind(address) : null const rewardAddress = @@ -154,7 +147,7 @@ const formatInputs = async ( : [] const multiAssets = - receiveUTxO?.assets + utxo?.assets .map((a) => { const tokenInfo = portfolioTokenInfos.tokenInfos?.get(a.assetId as Portfolio.Token.Id) if (!tokenInfo) return null @@ -176,8 +169,8 @@ const formatInputs = async ( addressKind: addressKind ?? null, rewardAddress, ownAddress: address != null ? isOwnedAddress(wallet, address) : null, - txIndex: input.index, - txHash: input.transaction_id, + txIndex: utxo.tx_index, + txHash: utxo.tx_hash, } }), )