From c6a4210d2d6cbfe45a95d6344b6ae791f608deaa Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 18 Feb 2025 17:23:40 +0400 Subject: [PATCH] fix: show asset as unrecognized if so --- src/composables/fungibleTokens.ts | 37 +++++++++++++++---- src/composables/transactionData.ts | 9 +++-- .../components/TransactionDetailsBase.vue | 1 + src/protocols/ethereum/helpers/index.ts | 1 + src/utils/common.ts | 15 +++++++- 5 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/composables/fungibleTokens.ts b/src/composables/fungibleTokens.ts index 21485fce6..fa60f1d2b 100644 --- a/src/composables/fungibleTokens.ts +++ b/src/composables/fungibleTokens.ts @@ -3,9 +3,9 @@ import { computed, watch } from 'vue'; import { uniqBy, isEmpty } from 'lodash-es'; import BigNumber from 'bignumber.js'; -import { Encoding, Tag } from '@aeternity/aepp-sdk'; +import { Encoding } from '@aeternity/aepp-sdk'; -import { isAssetCoin, toShiftedBigNumber } from '@/utils'; +import { isAssetCoin, toShiftedBigNumber, isNonAex9TokenContract } from '@/utils'; import type { AccountAddress, AssetContractId, @@ -24,7 +24,12 @@ import { ProtocolAdapterFactory } from '@/lib/ProtocolAdapterFactory'; import FungibleTokenFullInterfaceACI from '@/protocols/aeternity/aci/FungibleTokenFullInterfaceACI.json'; import { AE_COIN_PRECISION } from '@/protocols/aeternity/config'; -import { aettosToAe, categorizeContractCallTxObject, getTokenSaleBuyAmount } from '@/protocols/aeternity/helpers'; +import { + aettosToAe, + categorizeContractCallTxObject, + getInnerTransaction, + getTokenSaleBuyAmount, +} from '@/protocols/aeternity/helpers'; import { useCurrencies } from './currencies'; import { useAccounts } from './accounts'; @@ -253,9 +258,22 @@ export function useFungibleTokens() { const { protocol = PROTOCOLS.aeternity, tx = {} as ITx } = transaction || {}; const protocolTokens = getProtocolAvailableTokens(protocol); - return (isAssetCoin(tx.contractId) || !tx.contractId) - ? ProtocolAdapterFactory.getAdapter(protocol).coinSymbol - : protocolTokens[tx.contractId]?.symbol; + const innerTransaction = getInnerTransaction(tx); + + const isNonTokenContract = isNonAex9TokenContract( + innerTransaction?.contractId, + getProtocolAvailableTokens(protocol), + innerTransaction.tag, + ); + + if (isAssetCoin(innerTransaction?.contractId) || !innerTransaction?.contractId) { + return ProtocolAdapterFactory.getAdapter(protocol).coinSymbol; + } + + if (!isNonTokenContract && innerTransaction?.contractId) { + return ''; + } + return protocolTokens[innerTransaction?.contractId]?.symbol; } /** @@ -272,8 +290,11 @@ export function useFungibleTokens() { // This is out of place but since we are treating new protocols as fungible tokens // it is better to have it here than in the protocol specific helper file if (protocol && protocol !== PROTOCOLS.aeternity) { - const isNonTokenContract = !getProtocolAvailableTokens(protocol)[tx.contractId] - || tx.tag === Tag.ContractCreateTx; + const isNonTokenContract = isNonAex9TokenContract( + tx?.contractId, + getProtocolAvailableTokens(protocol), + tx.tag, + ); return new BigNumber(tx?.amount || 0) .plus(isReceived || (!isAssetCoin(tx.contractId) && !isNonTokenContract) ? 0 : tx?.fee || 0) diff --git a/src/composables/transactionData.ts b/src/composables/transactionData.ts index 4d44dbd8b..92f3d759d 100644 --- a/src/composables/transactionData.ts +++ b/src/composables/transactionData.ts @@ -1,5 +1,6 @@ import { computed, Ref } from 'vue'; import { Tag } from '@aeternity/aepp-sdk'; + import type { AccountAddress, ITokenResolved, @@ -14,6 +15,7 @@ import { getTxTypeListLabel, toShiftedBigNumber, isAssetCoin, + isNonAex9TokenContract, } from '@/utils'; import { ASSET_TYPES, PROTOCOLS, TX_DIRECTION } from '@/constants'; import { ProtocolAdapterFactory } from '@/lib/ProtocolAdapterFactory'; @@ -114,9 +116,10 @@ export function useTransactionData({ ); const isNonTokenContract = computed( - (): boolean => ( - !getProtocolAvailableTokens(protocol.value)[innerTx.value?.contractId] - || innerTxTag.value === Tag.ContractCreateTx + (): boolean => isNonAex9TokenContract( + innerTx.value?.contractId, + getProtocolAvailableTokens(protocol.value), + innerTxTag.value!, ), ); diff --git a/src/popup/components/TransactionDetailsBase.vue b/src/popup/components/TransactionDetailsBase.vue index 251c588a8..db835c407 100644 --- a/src/popup/components/TransactionDetailsBase.vue +++ b/src/popup/components/TransactionDetailsBase.vue @@ -126,6 +126,7 @@ :amount="amount" :symbol="assetSymbol" :hide-fiat="hideFiat" + :hide-symbol="!assetSymbol" :protocol="protocol" :price="price" high-precision diff --git a/src/protocols/ethereum/helpers/index.ts b/src/protocols/ethereum/helpers/index.ts index af2c3083d..108954039 100644 --- a/src/protocols/ethereum/helpers/index.ts +++ b/src/protocols/ethereum/helpers/index.ts @@ -55,6 +55,7 @@ export function normalizeWeb3EthTransactionStructure( senderId: from ? toChecksumAddress(from) : undefined, recipientId: to ? toChecksumAddress(to) : undefined, type: isEthTransfer ? 'SpendTx' : 'ContractCallTx', // TODO: create own types + tag: (isEthTransfer ? 'SpendTx' : 'ContractCallTx') as any, // TODO: create own types arguments: [], callerId: '', contractId, diff --git a/src/utils/common.ts b/src/utils/common.ts index 5d8462fcc..613ce3ca7 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -12,14 +12,19 @@ import { ref, computed, } from 'vue'; -import { defer, isEqual, uniqWith } from 'lodash-es'; +import { + defer, isEmpty, isEqual, uniqWith, +} from 'lodash-es'; import BigNumber from 'bignumber.js'; import { Share } from '@capacitor/share'; import { ComposerTranslation } from 'vue-i18n'; import { LocationQuery } from 'vue-router'; +import { Tag } from '@aeternity/aepp-sdk'; + import type { AccountAddress, AssetContractId, + AssetList, BigNumberPublic, IAccount, ICommonTransaction, @@ -536,6 +541,14 @@ export function isAssetCoin(assetContractId: AssetContractId): boolean { ); } +export function isNonAex9TokenContract( + assetContractId: AssetContractId, + assets: AssetList, + tag?: Tag, +): boolean { + return ((!isEmpty(assets) && !assets[assetContractId]) || tag === Tag.ContractCreateTx); +} + /** * Clean options from members that cause issues when sending messages * or when signing transactions.