From d721b0cba85a2b2812928330672c3e3844b4c4db Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Thu, 12 Sep 2024 06:34:35 +0200 Subject: [PATCH 1/2] Differentiate transaction amount and fee tickers Uses new fields amount_symbol and fee_symbol. Fixes Pontus-X transactions that transfer EUROe but pay fees in TEST. Pontus-X Devnet transaction: 40cd07b27f7edb42bbea128d473066a43877b12ba8be9f1253233dd79f283afc --- .changelog/1543.bugfix.md | 1 + .../Transactions/RuntimeTransactions.tsx | 4 ++-- .../RuntimeTransactionDetailPage/index.tsx | 21 +++++++++---------- src/oasis-nexus/api.ts | 5 ----- 4 files changed, 13 insertions(+), 18 deletions(-) create mode 100644 .changelog/1543.bugfix.md diff --git a/.changelog/1543.bugfix.md b/.changelog/1543.bugfix.md new file mode 100644 index 000000000..56961aa35 --- /dev/null +++ b/.changelog/1543.bugfix.md @@ -0,0 +1 @@ +Differentiate transaction amount and fee tickers diff --git a/src/app/components/Transactions/RuntimeTransactions.tsx b/src/app/components/Transactions/RuntimeTransactions.tsx index 04bbe9067..dec350ef6 100644 --- a/src/app/components/Transactions/RuntimeTransactions.tsx +++ b/src/app/components/Transactions/RuntimeTransactions.tsx @@ -146,12 +146,12 @@ export const RuntimeTransactions: FC = ({ }, { align: TableCellAlign.Right, - content: , + content: , key: 'fee_amount', }, { align: TableCellAlign.Right, - content: , + content: , key: 'value', }, ] diff --git a/src/app/pages/RuntimeTransactionDetailPage/index.tsx b/src/app/pages/RuntimeTransactionDetailPage/index.tsx index 7433a03ae..9006b29fc 100644 --- a/src/app/pages/RuntimeTransactionDetailPage/index.tsx +++ b/src/app/pages/RuntimeTransactionDetailPage/index.tsx @@ -25,7 +25,6 @@ import { TransactionLink } from '../../components/Transactions/TransactionLink' import { RuntimeTransactionEvents } from '../../components/Transactions/RuntimeTransactionEvents' import { useRequiredScopeParam } from '../../hooks/useScopeParam' import { DashboardLink } from '../ParatimeDashboardPage/DashboardLink' -import { Ticker } from '../../../types/ticker' import { AllTokenPrices, useAllTokenPrices } from '../../../coin-gecko/api' import { CurrentFiatValue } from '../../components/CurrentFiatValue' import { AddressSwitch, AddressSwitchOption } from '../../components/AddressSwitch' @@ -169,8 +168,8 @@ export const RuntimeTransactionDetailView: FC<{ const from = isOasisAddressFormat ? transaction?.sender_0 : transaction?.sender_0_eth const to = isOasisAddressFormat ? transaction?.to : transaction?.to_eth - const ticker = transaction?.ticker || Ticker.ROSE - const tokenPriceInfo = tokenPrices[ticker] + // @ts-expect-error Ignore index type error + const amountSymbolPriceInfo = tokenPrices[transaction?.amount_symbol] const gasPrice = getGasPrice({ fee: transaction?.charged_fee, gasUsed: transaction?.gas_used.toString() }) @@ -286,21 +285,21 @@ export const RuntimeTransactionDetailView: FC<{ {transaction.amount != null ? t('common.valueInToken', { ...getPreciseNumberFormat(transaction.amount), - ticker: ticker, + ticker: transaction.amount_symbol, }) : t('common.missing')} {showFiatValues && transaction.amount !== undefined && - !!tokenPriceInfo && - !tokenPriceInfo.isLoading && - !tokenPriceInfo.isFree && - tokenPriceInfo.price !== undefined && ( + !!amountSymbolPriceInfo && + !amountSymbolPriceInfo.isLoading && + !amountSymbolPriceInfo.isFree && + amountSymbolPriceInfo.price !== undefined && ( <>
{t('currentFiatValue.title')}
- +
)} @@ -309,7 +308,7 @@ export const RuntimeTransactionDetailView: FC<{
{t('common.valueInToken', { ...getPreciseNumberFormat(transaction.charged_fee), - ticker: ticker, + ticker: transaction.fee_symbol, })}
@@ -319,7 +318,7 @@ export const RuntimeTransactionDetailView: FC<{
{t('common.valueInToken', { ...getPreciseNumberFormat(convertToNano(gasPrice)), - ticker: `n${ticker}`, + ticker: `n${transaction.fee_symbol}`, })}
diff --git a/src/oasis-nexus/api.ts b/src/oasis-nexus/api.ts index 89fef90dd..a6a3ac8fd 100644 --- a/src/oasis-nexus/api.ts +++ b/src/oasis-nexus/api.ts @@ -43,7 +43,6 @@ declare module './generated/api' { export interface RuntimeTransaction { network: Network layer: Layer - ticker: Ticker } export interface Block { @@ -244,8 +243,6 @@ export const useGetRuntimeTransactions: typeof generated.useGetRuntimeTransactio amount: tx.amount ? fromBaseUnits(tx.amount, paraTimesConfig[runtime].decimals) : undefined, layer: runtime, network, - ticker: - tx.body?.amount?.Denomination || getTokensForScope({ network, layer: runtime })[0].ticker, method: adjustRuntimeTransactionMethod(tx.method, tx.is_likely_native_token_transfer), } }), @@ -324,8 +321,6 @@ export const useGetRuntimeTransactionsTxHash: typeof generated.useGetRuntimeTran amount: tx.amount ? fromBaseUnits(tx.amount, paraTimesConfig[runtime].decimals) : undefined, layer: runtime, network, - ticker: - tx.body?.amount?.Denomination || getTokensForScope({ network, layer: runtime })[0].ticker, method: adjustRuntimeTransactionMethod(tx.method, tx.is_likely_native_token_transfer), } }), From 01623c37197a6af7210904af83794c7d33c3b0fe Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Thu, 12 Sep 2024 07:27:50 +0200 Subject: [PATCH 2/2] Add fallback tickers to transaction amount and fee Emerald transaction is missing both fields: 0xee5d8af74e955fffde2e801d0b400107b769458aa4cd9b297763dc9630ba0933 --- src/oasis-nexus/api.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/oasis-nexus/api.ts b/src/oasis-nexus/api.ts index a6a3ac8fd..7885614d8 100644 --- a/src/oasis-nexus/api.ts +++ b/src/oasis-nexus/api.ts @@ -215,6 +215,11 @@ const adjustRuntimeTransactionMethod = ( isLikelyNativeTokenTransfer: boolean | undefined, ) => (isLikelyNativeTokenTransfer ? 'accounts.Transfer' : method) +function normalizeSymbol(rawSymbol: string | undefined, scope: SearchScope) { + const symbol = rawSymbol || getTokensForScope(scope)[0].ticker + return symbol +} + export const useGetRuntimeTransactions: typeof generated.useGetRuntimeTransactions = ( network, runtime, @@ -235,12 +240,14 @@ export const useGetRuntimeTransactions: typeof generated.useGetRuntimeTransactio return { ...tx, eth_hash: tx.eth_hash ? `0x${tx.eth_hash}` : undefined, - // TODO: Decimals may not be correct, should not depend on ParaTime decimals, but tx itself + // TODO: Decimals may not be correct, should not depend on ParaTime decimals, but fee_symbol fee: fromBaseUnits(tx.fee, paraTimesConfig[runtime].decimals), - // TODO: Decimals may not be correct, should not depend on ParaTime decimals, but tx itself + fee_symbol: normalizeSymbol(tx.fee_symbol, { network, layer: runtime }), + // TODO: Decimals may not be correct, should not depend on ParaTime decimals, but fee_symbol charged_fee: fromBaseUnits(tx.charged_fee, paraTimesConfig[runtime].decimals), - // TODO: Decimals may not be correct, should not depend on ParaTime decimals, but tx itself + // TODO: Decimals may not be correct, should not depend on ParaTime decimals, but amount_symbol amount: tx.amount ? fromBaseUnits(tx.amount, paraTimesConfig[runtime].decimals) : undefined, + amount_symbol: normalizeSymbol(tx.amount_symbol, { network, layer: runtime }), layer: runtime, network, method: adjustRuntimeTransactionMethod(tx.method, tx.is_likely_native_token_transfer), @@ -316,9 +323,14 @@ export const useGetRuntimeTransactionsTxHash: typeof generated.useGetRuntimeTran return { ...tx, eth_hash: tx.eth_hash ? `0x${tx.eth_hash}` : undefined, + // TODO: Decimals may not be correct, should not depend on ParaTime decimals, but fee_symbol fee: fromBaseUnits(tx.fee, paraTimesConfig[runtime].decimals), + fee_symbol: normalizeSymbol(tx.fee_symbol, { network, layer: runtime }), + // TODO: Decimals may not be correct, should not depend on ParaTime decimals, but fee_symbol charged_fee: fromBaseUnits(tx.charged_fee, paraTimesConfig[runtime].decimals), + // TODO: Decimals may not be correct, should not depend on ParaTime decimals, but amount_symbol amount: tx.amount ? fromBaseUnits(tx.amount, paraTimesConfig[runtime].decimals) : undefined, + amount_symbol: normalizeSymbol(tx.amount_symbol, { network, layer: runtime }), layer: runtime, network, method: adjustRuntimeTransactionMethod(tx.method, tx.is_likely_native_token_transfer),