Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to auto-detect token type used in runtime transactions #1279

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/1279.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Try to auto-detect token type used in runtime transactions
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 ??
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't exist. event.body?.amount.Denomination exists.
But event.body.amount.Denomination === '' above means that it is empty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen both existing on different data, IIRC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, maybe not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, when this code is executed, it's always empty. Removed useless condition in #1285.

getTokensForScope({ network, layer: runtime })[0].ticker,
}
: event.body.amount,
},
Expand Down
Loading