From 34ed2218aaf5d2e45b850d10523af62ec89795f5 Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 5 Feb 2025 17:21:54 +0400 Subject: [PATCH] feat: show full createCommunity contract call info --- .../helpers/transactionTokenInfoResolvers.ts | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/protocols/aeternity/helpers/transactionTokenInfoResolvers.ts b/src/protocols/aeternity/helpers/transactionTokenInfoResolvers.ts index 67c9e66f5..2b48a42ea 100644 --- a/src/protocols/aeternity/helpers/transactionTokenInfoResolvers.ts +++ b/src/protocols/aeternity/helpers/transactionTokenInfoResolvers.ts @@ -439,15 +439,40 @@ const sell: TransactionResolver = (transaction, tokens = null, tokenAddressMappe const createCommunity: TransactionResolver = ( transaction, tokens = null, + tokenAddressMapper = undefined, ) => { - const isConfirm = !transaction.tx.return; - const token = { - amount: transaction.tx.arguments?.[2]?.value, + const { internalEvents } = transaction.tx; + const additionalTokenEvents = internalEvents?.filter(({ type, payload: { recipientId } }) => ( + ACTIVITIES_TYPES.aex9TransferEvent === type + && transaction.tx.callerId === recipientId + )); + + let receivedTokens = additionalTokenEvents?.map(({ + payload: { + tokenSymbol, amount, contractId, + }, + }) => ({ + amount, ...defaultToken, - symbol: transaction.tx.arguments?.[1]?.value, - ...(isConfirm ? {} : tokens?.[transaction.tx.log?.[2]?.address]), + symbol: tokenSymbol, + ...(tokens?.[contractId] || {}), isReceived: true, - }; + })); + + const tokenAddress: string | undefined = tokenAddressMapper?.( + transaction.tx.return?.value[1]?.value, + ); + + if (!receivedTokens?.length) { + receivedTokens = [{ + amount: transaction.tx.arguments?.[2]?.value, + ...defaultToken, + symbol: transaction.tx.arguments?.[1]?.value, + ...(tokenAddress ? tokens?.[tokenAddress] : {}), + isReceived: true, + }]; + } + const aeToken = { ...defaultToken, assetType: ASSET_TYPES.coin, @@ -456,7 +481,7 @@ const createCommunity: TransactionResolver = ( isReceived: false, }; return { - tokens: [token, aeToken], + tokens: [...(receivedTokens || []), aeToken], }; };