-
Notifications
You must be signed in to change notification settings - Fork 143
Support for MPT-DEX in Explorer #1302
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
base: main
Are you sure you want to change the base?
Changes from 29 commits
0b8367b
cd9ff32
9453ff8
67626a2
13c81a6
54cd50a
5fc004f
5782f14
d31ee18
8ac00cd
ec33f9c
805e630
7498ce0
72a44ea
976236f
a3641a8
a8f1f71
ad688b6
416846f
ab4553c
d14cd92
d749048
599e3bc
c82d0c3
d20a0c4
78c4164
bcf8cff
ddf45fc
4a58b18
67ba204
08e5675
f18ce99
2a15173
b02b7c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,39 @@ import { | |
| import { localizeNumber } from '../../../shared/utils' | ||
| import { Account } from '../../../shared/components/Account' | ||
| import Currency from '../../../shared/components/Currency' | ||
| import type { Amount } from '../../../shared/types' | ||
| import type { MetaRenderFunctionWithTx, MetaNode } from './types' | ||
|
|
||
| const normalize = (value: number | string, currency: string): string => | ||
| currency === 'XRP' ? (Number(value) / XRP_BASE).toString() : String(value) | ||
| const isMPTOrIOUAmount = ( | ||
| takerAmount: Amount | undefined, | ||
| ): takerAmount is Exclude<Amount, string> => | ||
| typeof takerAmount === 'object' && takerAmount !== null | ||
|
|
||
| const getCurrency = (takerAmount: Amount | undefined): string => { | ||
| if (!isMPTOrIOUAmount(takerAmount)) return 'XRP' | ||
| if ('mpt_issuance_id' in takerAmount) return takerAmount.mpt_issuance_id | ||
| return takerAmount.currency || 'XRP' | ||
| } | ||
|
|
||
| const getIsMPT = (takerAmount: Amount | undefined): boolean => | ||
| isMPTOrIOUAmount(takerAmount) && 'mpt_issuance_id' in takerAmount | ||
|
|
||
| const getIssuer = (takerAmount: Amount | undefined): string | undefined => { | ||
| if (!isMPTOrIOUAmount(takerAmount)) return undefined | ||
| if ('mpt_issuance_id' in takerAmount) return undefined | ||
| return takerAmount.issuer | ||
| } | ||
|
|
||
| const normalize = ( | ||
| value: number | string, | ||
| currency: string, | ||
| isMPT: boolean = false, | ||
| ): string => { | ||
| if (isMPT) return String(value) | ||
| return currency === 'XRP' | ||
| ? (Number(value) / XRP_BASE).toString() | ||
| : String(value) | ||
| } | ||
|
|
||
| const renderChanges = ( | ||
| _t: any, | ||
|
|
@@ -22,14 +51,16 @@ const renderChanges = ( | |
| const meta: JSX.Element[] = [] | ||
| const final = node.FinalFields | ||
| const prev = node?.PreviousFields | ||
| const paysCurrency = final.TakerPays.currency || 'XRP' | ||
| const getsCurrency = final.TakerGets.currency || 'XRP' | ||
| const paysCurrency = getCurrency(final.TakerPays) | ||
| const getsCurrency = getCurrency(final.TakerGets) | ||
| const paysIsMPT = getIsMPT(final.TakerPays) | ||
| const getsIsMPT = getIsMPT(final.TakerGets) | ||
| const finalPays = final.TakerPays.value || final.TakerPays | ||
| const finalGets = final.TakerGets.value || final.TakerGets | ||
| const prevPays = prev?.TakerPays?.value || prev?.TakerPays | ||
| const prevGets = prev?.TakerGets?.value || prev?.TakerGets | ||
| const changePays = normalize(prevPays - finalPays, paysCurrency) | ||
| const changeGets = normalize(prevGets - finalGets, getsCurrency) | ||
| const changePays = normalize(prevPays - finalPays, paysCurrency, paysIsMPT) | ||
| const changeGets = normalize(prevGets - finalGets, getsCurrency, getsIsMPT) | ||
|
|
||
| if (prevPays && finalPays) { | ||
| const options = { ...CURRENCY_OPTIONS, currency: paysCurrency } | ||
|
|
@@ -39,7 +70,8 @@ const renderChanges = ( | |
| <b> | ||
| <Currency | ||
| currency={paysCurrency} | ||
| issuer={final.TakerPays.issuer} | ||
| issuer={getIssuer(final.TakerPays)} | ||
| isMPT={paysIsMPT} | ||
| displaySymbol={false} | ||
| /> | ||
| </b>{' '} | ||
|
|
@@ -57,7 +89,7 @@ const renderChanges = ( | |
| { | ||
| { | ||
| previous: localizeNumber( | ||
| normalize(prevPays, paysCurrency), | ||
| normalize(prevPays, paysCurrency, paysIsMPT), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. localizeNumber has a argument isMPT, should we set it in all of the localizeNumber calls here (e.g payIsMPT) so that BigInt will be execute?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, fixed in 2a15173
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. follow-up in b02b7c6: added regression tests in Meta.test.tsx covering all 6 localizeNumber calls, plus mixed MPT/XRP offers and the MPToken/MPTokenIssuance renderers. they surfaced a small bug where Intl.NumberFormat rejected the mpt_issuance_id as a currency code (it validates |
||
| language, | ||
| options, | ||
| ), | ||
|
|
@@ -69,7 +101,7 @@ const renderChanges = ( | |
| { | ||
| { | ||
| final: localizeNumber( | ||
| normalize(finalPays, paysCurrency), | ||
| normalize(finalPays, paysCurrency, paysIsMPT), | ||
| language, | ||
| options, | ||
| ), | ||
|
|
@@ -88,7 +120,8 @@ const renderChanges = ( | |
| <b> | ||
| <Currency | ||
| currency={getsCurrency} | ||
| issuer={final.TakerGets.issuer} | ||
| issuer={getIssuer(final.TakerGets)} | ||
| isMPT={getsIsMPT} | ||
| displaySymbol={false} | ||
| /> | ||
| </b>{' '} | ||
|
|
@@ -106,7 +139,7 @@ const renderChanges = ( | |
| { | ||
| { | ||
| previous: localizeNumber( | ||
| normalize(prevGets, getsCurrency), | ||
| normalize(prevGets, getsCurrency, getsIsMPT), | ||
| language, | ||
| options, | ||
| ), | ||
|
|
@@ -118,7 +151,7 @@ const renderChanges = ( | |
| { | ||
| { | ||
| final: localizeNumber( | ||
| normalize(finalGets, getsCurrency), | ||
| normalize(finalGets, getsCurrency, getsIsMPT), | ||
| language, | ||
| options, | ||
| ), | ||
|
|
@@ -143,11 +176,14 @@ const render: MetaRenderFunctionWithTx = ( | |
| ) => { | ||
| const lines: JSX.Element[] = [] | ||
| const fields = node.FinalFields || node.NewFields | ||
| const paysCurrency = fields.TakerPays.currency || 'XRP' | ||
| const getsCurrency = fields.TakerGets.currency || 'XRP' | ||
| const paysCurrency = getCurrency(fields.TakerPays) | ||
| const getsCurrency = getCurrency(fields.TakerGets) | ||
| const paysIsMPT = getIsMPT(fields.TakerPays) | ||
| const getsIsMPT = getIsMPT(fields.TakerGets) | ||
| const takerPaysValue = normalize( | ||
| fields.TakerPays.value || fields.TakerPays, | ||
| paysCurrency, | ||
| paysIsMPT, | ||
| ) | ||
| const invert = | ||
| CURRENCY_ORDER.indexOf(getsCurrency) > CURRENCY_ORDER.indexOf(paysCurrency) | ||
|
|
@@ -214,16 +250,22 @@ const render: MetaRenderFunctionWithTx = ( | |
| components={{ | ||
| Currency: ( | ||
| <Currency | ||
| currency={(invert ? getsCurrency : paysCurrency) || 'XRP'} | ||
| issuer={invert ? tx.TakerGets?.issuer : tx.TakerPays?.issuer} | ||
| currency={invert ? getsCurrency : paysCurrency} | ||
| issuer={ | ||
| invert ? getIssuer(tx.TakerGets) : getIssuer(tx.TakerPays) | ||
| } | ||
| isMPT={invert ? getsIsMPT : paysIsMPT} | ||
| displaySymbol={false} | ||
| shortenIssuer | ||
| /> | ||
| ), | ||
| Currency2: ( | ||
| <Currency | ||
| currency={(invert ? paysCurrency : getsCurrency) || 'XRP'} | ||
| issuer={invert ? tx.TakerPays?.issuer : tx.TakerGets?.issuer} | ||
| currency={invert ? paysCurrency : getsCurrency} | ||
| issuer={ | ||
| invert ? getIssuer(tx.TakerPays) : getIssuer(tx.TakerGets) | ||
| } | ||
| isMPT={invert ? paysIsMPT : getsIsMPT} | ||
| displaySymbol={false} | ||
| shortenIssuer | ||
| /> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to use
BigInthere like we do insrc/containers/shared/metaParser.tsx?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks 67ba204