Skip to content

Commit

Permalink
Merge pull request #1543 from oasisprotocol/lw/fix-tx-denominations
Browse files Browse the repository at this point in the history
Differentiate transaction amount and fee tickers
  • Loading branch information
lukaw3d authored Sep 16, 2024
2 parents 63101a6 + 01623c3 commit 13daf45
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
1 change: 1 addition & 0 deletions .changelog/1543.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Differentiate transaction amount and fee tickers
4 changes: 2 additions & 2 deletions src/app/components/Transactions/RuntimeTransactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ export const RuntimeTransactions: FC<TransactionsProps> = ({
},
{
align: TableCellAlign.Right,
content: <RoundedBalance value={transaction.charged_fee} ticker={transaction.ticker} />,
content: <RoundedBalance value={transaction.charged_fee} ticker={transaction.fee_symbol} />,
key: 'fee_amount',
},
{
align: TableCellAlign.Right,
content: <RoundedBalance value={transaction.amount} ticker={transaction.ticker} />,
content: <RoundedBalance value={transaction.amount} ticker={transaction.amount_symbol} />,
key: 'value',
},
]
Expand Down
21 changes: 10 additions & 11 deletions src/app/pages/RuntimeTransactionDetailPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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() })

Expand Down Expand Up @@ -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')}
</dd>

{showFiatValues &&
transaction.amount !== undefined &&
!!tokenPriceInfo &&
!tokenPriceInfo.isLoading &&
!tokenPriceInfo.isFree &&
tokenPriceInfo.price !== undefined && (
!!amountSymbolPriceInfo &&
!amountSymbolPriceInfo.isLoading &&
!amountSymbolPriceInfo.isFree &&
amountSymbolPriceInfo.price !== undefined && (
<>
<dt>{t('currentFiatValue.title')}</dt>
<dd>
<CurrentFiatValue amount={transaction.amount} {...tokenPriceInfo} />
<CurrentFiatValue amount={transaction.amount} {...amountSymbolPriceInfo} />
</dd>
</>
)}
Expand All @@ -309,7 +308,7 @@ export const RuntimeTransactionDetailView: FC<{
<dd>
{t('common.valueInToken', {
...getPreciseNumberFormat(transaction.charged_fee),
ticker: ticker,
ticker: transaction.fee_symbol,
})}
</dd>

Expand All @@ -319,7 +318,7 @@ export const RuntimeTransactionDetailView: FC<{
<dd>
{t('common.valueInToken', {
...getPreciseNumberFormat(convertToNano(gasPrice)),
ticker: `n${ticker}`,
ticker: `n${transaction.fee_symbol}`,
})}
</dd>
</>
Expand Down
23 changes: 15 additions & 8 deletions src/oasis-nexus/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ declare module './generated/api' {
export interface RuntimeTransaction {
network: Network
layer: Layer
ticker: Ticker
}

export interface Block {
Expand Down Expand Up @@ -216,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,
Expand All @@ -236,16 +240,16 @@ 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,
ticker:
tx.body?.amount?.Denomination || getTokensForScope({ network, layer: runtime })[0].ticker,
method: adjustRuntimeTransactionMethod(tx.method, tx.is_likely_native_token_transfer),
}
}),
Expand Down Expand Up @@ -319,13 +323,16 @@ 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,
ticker:
tx.body?.amount?.Denomination || getTokensForScope({ network, layer: runtime })[0].ticker,
method: adjustRuntimeTransactionMethod(tx.method, tx.is_likely_native_token_transfer),
}
}),
Expand Down

0 comments on commit 13daf45

Please sign in to comment.