From 87cac2e15fbdcc0e0c1b4c1cfd0ff54b940b43fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Mi=C3=B1o?= Date: Mon, 17 Jun 2024 02:07:46 -0400 Subject: [PATCH] fix: approve tx to (#1573) Co-authored-by: Daniel Sinclair --- src/core/types/transactions.ts | 1 + src/core/utils/transactions.ts | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/types/transactions.ts b/src/core/types/transactions.ts index 952554ceef..02139e55d0 100644 --- a/src/core/types/transactions.ts +++ b/src/core/types/transactions.ts @@ -199,6 +199,7 @@ export type TransactionApiResponse = { }; block_confirmations?: number; // also only available on the tx by hash endpoint meta: { + approval_to?: Address; contract_name?: string; contract_icon_url?: string; type?: TransactionType; diff --git a/src/core/utils/transactions.ts b/src/core/utils/transactions.ts index 9e77b688e8..88af384509 100644 --- a/src/core/utils/transactions.ts +++ b/src/core/utils/transactions.ts @@ -173,15 +173,18 @@ const getAssetFromChanges = ( return changes[0]?.asset; }; -const getAddressToFromChanges = ( +const getAddressTo = ( + meta: PaginatedTransactionsApiResponse['meta'], changes: { direction: TransactionDirection; asset: ParsedUserAsset; address_to: Address; }[], - type: TransactionType, ) => { - if (type === 'sale') + if (meta.type === 'approve') { + return meta?.approval_to; + } + if (meta.type === 'sale') return changes?.find((c) => c?.direction === 'out')?.address_to; return changes[0]?.address_to; }; @@ -266,9 +269,7 @@ export function parseTransaction({ ? parseAsset({ asset: meta.asset, currency }) : getAssetFromChanges(changes, type); - const addressTo = asset - ? getAddressToFromChanges(changes, type) - : tx.address_to; + const addressTo = asset ? getAddressTo(meta, changes) : tx.address_to; const direction = tx.direction || getDirection(type); @@ -426,9 +427,7 @@ export async function getNextNonce({ const { getNonce } = nonceStore.getState(); const localNonceData = getNonce({ address, chainId }); const localNonce = localNonceData?.currentNonce || 0; - console.log('- getNextNonce'); const provider = getProvider({ chainId }); - console.log('- getNextNonce', provider); const txCountIncludingPending = await provider.getTransactionCount( address, 'pending',