Skip to content

Commit

Permalink
fix: show asset as unrecognized if so
Browse files Browse the repository at this point in the history
  • Loading branch information
CedrikNikita committed Feb 18, 2025
1 parent 129d24f commit c6a4210
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
37 changes: 29 additions & 8 deletions src/composables/fungibleTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions src/composables/transactionData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computed, Ref } from 'vue';
import { Tag } from '@aeternity/aepp-sdk';

import type {
AccountAddress,
ITokenResolved,
Expand All @@ -14,6 +15,7 @@ import {
getTxTypeListLabel,
toShiftedBigNumber,
isAssetCoin,
isNonAex9TokenContract,
} from '@/utils';
import { ASSET_TYPES, PROTOCOLS, TX_DIRECTION } from '@/constants';
import { ProtocolAdapterFactory } from '@/lib/ProtocolAdapterFactory';
Expand Down Expand Up @@ -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!,
),
);

Expand Down
1 change: 1 addition & 0 deletions src/popup/components/TransactionDetailsBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
:amount="amount"
:symbol="assetSymbol"
:hide-fiat="hideFiat"
:hide-symbol="!assetSymbol"
:protocol="protocol"
:price="price"
high-precision
Expand Down
1 change: 1 addition & 0 deletions src/protocols/ethereum/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 14 additions & 1 deletion src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c6a4210

Please sign in to comment.