Skip to content

Commit

Permalink
Try to auto-detect token type used in runtime transactions
Browse files Browse the repository at this point in the history
Use tx.data to figure out if it's something special,
or the default native token.
  • Loading branch information
csillag committed Feb 21, 2024
1 parent a69897d commit 1da61cb
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/oasis-nexus/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export const useGetRuntimeTransactions: typeof generated.useGetRuntimeTransactio
params?,
options?,
) => {
const ticker = getTokensForScope({ network, layer: runtime })[0].ticker // TODO: find this out from tx data
return generated.useGetRuntimeTransactions(network, runtime, params, {
...options,
request: {
Expand All @@ -186,7 +185,8 @@ export const useGetRuntimeTransactions: typeof generated.useGetRuntimeTransactio
amount: tx.amount ? fromBaseUnits(tx.amount, paraTimesConfig[runtime].decimals) : undefined,
layer: runtime,
network,
ticker,
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 @@ -238,7 +238,6 @@ export const useGetRuntimeTransactionsTxHash: typeof generated.useGetRuntimeTran
) => {
// Sometimes we will call this with an undefined txHash, so we must be careful here.
const actualHash = txHash?.startsWith('0x') ? txHash.substring(2) : txHash
const ticker = getTokensForScope({ network, layer: runtime })[0].ticker // TODO: find this out from tx data
return generated.useGetRuntimeTransactionsTxHash(network, runtime, actualHash, {
...options,
request: {
Expand All @@ -258,7 +257,8 @@ export const useGetRuntimeTransactionsTxHash: typeof generated.useGetRuntimeTran
amount: tx.amount ? fromBaseUnits(tx.amount, paraTimesConfig[runtime].decimals) : undefined,
layer: runtime,
network,
ticker,
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 @@ -752,7 +752,9 @@ export const useGetRuntimeEvents: typeof generated.useGetRuntimeEvents = (
event.body.amount.Amount,
paraTimesConfig[runtime].decimals,
),
Denomination: getTokensForScope({ network, layer: runtime })[0].ticker, // TODO find this out from event data
Denomination:
event.body?.Denomination ??
getTokensForScope({ network, layer: runtime })[0].ticker,
}
: event.body.amount,
},
Expand Down

0 comments on commit 1da61cb

Please sign in to comment.