Skip to content

Commit

Permalink
Merge pull request #3376 from superhero-com/feature/show-fiat-value-i…
Browse files Browse the repository at this point in the history
…n-transaction-item

Show fiat value in `transactionItem`
  • Loading branch information
CedrikNikita authored Nov 1, 2024
2 parents d26e8d8 + c4cf011 commit f0a96b3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/composables/transactionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ export function useTransactionData({
const { dexContracts } = useAeSdk();
const { accounts, activeAccount } = useAccounts();
const { tippingContractAddresses } = useTippingContracts();
const { getProtocolAvailableTokens, getTxAmountTotal, getTxAssetSymbol } = useFungibleTokens();
const {
getProtocolAvailableTokens,
getTxAmountTotal,
getTxAssetSymbol,
tokenBalances,
} = useFungibleTokens();
const {
tokenSaleAddresses,
tokenSaleAddressToTokenContractAddress,
Expand Down Expand Up @@ -267,10 +272,13 @@ export function useTransactionData({
.map(({
amount,
decimals,
contractId,
...otherAssetData
}) => ({
amount: +toShiftedBigNumber(amount!, -decimals!),
contractId,
...otherAssetData,
price: tokenBalances.value.find((token) => contractId === token.contractId)?.price,
}));
}
}
Expand Down Expand Up @@ -308,6 +316,9 @@ export function useTransactionData({
name: token?.name,
protocol,
symbol: getTxAssetSymbol(transaction.value),
price: tokenBalances.value.find(
(tokenBalance) => outerTx.value!.contractId === tokenBalance.contractId,
)?.price,
}].concat(isReceived || hideFeeFromAssets ? [] : [feeToken]);
});

Expand Down
1 change: 1 addition & 0 deletions src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const STORAGE_KEYS = {
fungibleTokenBalances: 'fungible-token-balances',
permissions: 'permissions',
appsBrowserHistory: 'apps-browser-history',
tokenSales: 'token-sales',
transactionsLatest: 'transactions-latest',
transactionsLoaded: 'transactions-loaded',
transactionsPending: 'transactions-pending',
Expand Down
15 changes: 12 additions & 3 deletions src/popup/components/TransactionListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,24 @@ export default defineComponent({
});
const fiatAmount = computed(() => {
const tokenAsset = transactionAssets.value[0];
const protocolCoin = transactionAssets.value?.find(
({ assetType }) => assetType === ASSET_TYPES.coin,
);
if (!protocolCoin || isErrorTransaction.value || isDexPool.value || !protocolCoin.protocol) {
if (
(!tokenAsset?.price && !protocolCoin)
|| isErrorTransaction.value
|| isDexPool.value
) {
return 0;
}
return getFormattedAndRoundedFiat(
+amountRounded(protocolCoin.amount || 0),
protocolCoin.protocol,
+amountRounded(
tokenAsset?.price && tokenAsset?.amount
? +tokenAsset.amount * tokenAsset.price
: protocolCoin?.amount || 0,
),
transactionProtocol.value,
);
});
Expand Down
9 changes: 6 additions & 3 deletions src/protocols/aeternity/composables/aeTokenSales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { computed, ref } from 'vue';
import camelCaseKeysDeep from 'camelcase-keys-deep';

import { ITokenSale } from '@/types';
import { NETWORK_TYPE_CUSTOM } from '@/constants';
import { NETWORK_TYPE_CUSTOM, STORAGE_KEYS } from '@/constants';
import {
createCustomScopedComposable,
fetchAllPages,
Expand All @@ -12,6 +12,7 @@ import {
import { useNetworks } from '@/composables';
import { AE_TOKEN_SALES_URLS } from '@/protocols/aeternity/config';
import { createPollingBasedOnMountedComponents } from '@/composables/composablesHelpers';
import { useStorageRef } from '@/composables/storageRef';

const POLLING_INTERVAL = 60000;

Expand All @@ -26,7 +27,10 @@ const initPollingWatcher = createPollingBasedOnMountedComponents(POLLING_INTERVA
/**
* List of all token sales available
*/
const tokenSales = ref<ITokenSale[]>([]);
const tokenSales = useStorageRef<ITokenSale[]>(
[],
STORAGE_KEYS.tokenSales,
);

export const useAeTokenSales = createCustomScopedComposable(() => {
const { activeNetwork, onNetworkChange } = useNetworks();
Expand Down Expand Up @@ -68,7 +72,6 @@ export const useAeTokenSales = createCustomScopedComposable(() => {
));
tokenSales.value = response || [];
} catch (e) {
tokenSales.value = [];
handleUnknownError(e);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
AE_CONTRACT_ID,
AE_PROTOCOL_NAME,
} from '@/protocols/aeternity/config';
import { ASSET_TYPES, PROTOCOLS } from '@/constants';

interface TransactionResolverReturnData {
tokens: ITokenResolved[];
Expand Down Expand Up @@ -379,6 +380,8 @@ const buy: TransactionResolver = (transaction, tokens = null, tokenAddressMapper
};
const aeToken = {
...defaultToken,
assetType: ASSET_TYPES.coin,
protocol: PROTOCOLS.aeternity,
amount: transaction.tx.amount,
isReceived: false,
};
Expand Down Expand Up @@ -407,6 +410,8 @@ const sell: TransactionResolver = (transaction, tokens = null, tokenAddressMappe
};
const aeToken = {
...defaultToken,
assetType: ASSET_TYPES.coin,
protocol: PROTOCOLS.aeternity,
amount: aeAmount,
isReceived: true,
};
Expand Down

0 comments on commit f0a96b3

Please sign in to comment.