fix: rounding integer parts in TokenAmount (#163)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { TokenAmount } from "@/components/TokenAmount"
|
||||
import { roundToSignificantDigits, TokenAmount } from "@/components/TokenAmount"
|
||||
import { BlockContext } from "@/state/block.state"
|
||||
import { client$ } from "@/state/chains/chain.state"
|
||||
import { polkadot_people } from "@polkadot-api/descriptors"
|
||||
@@ -53,7 +53,7 @@ export const AnalyzePriority: FC<{
|
||||
/>
|
||||
<DetailRow
|
||||
label="Weight"
|
||||
value={`${(Number(details.queryInfo.weight.proof_size) / 1024).toLocaleString(undefined, { maximumSignificantDigits: 3 })} KB / ${(Number(details.queryInfo.weight.ref_time) / 1_000_000).toLocaleString(undefined, { maximumSignificantDigits: 3 })} Mref`}
|
||||
value={`${roundToSignificantDigits(Number(details.queryInfo.weight.proof_size) / 1024)} KB / ${roundToSignificantDigits(Number(details.queryInfo.weight.ref_time) / 1_000_000)} Mref`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,12 +10,9 @@ export const formatToken = (
|
||||
symbol?: string
|
||||
},
|
||||
) => {
|
||||
const formattedValue = (
|
||||
Number(amount) /
|
||||
10 ** properties.decimals
|
||||
).toLocaleString(undefined, {
|
||||
maximumSignificantDigits: 3,
|
||||
})
|
||||
const formattedValue = roundToSignificantDigits(
|
||||
Number(amount) / 10 ** properties.decimals,
|
||||
)
|
||||
|
||||
return `${formattedValue} ${properties.symbol}`
|
||||
}
|
||||
@@ -41,3 +38,16 @@ export const TokenAmount: FC<{
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export const roundToSignificantDigits = (value: number) => {
|
||||
const abs = Math.abs(value)
|
||||
const maximumFractionDigits = abs >= 100 ? 0 : abs >= 10 ? 1 : 2
|
||||
|
||||
return abs >= 1
|
||||
? value.toLocaleString(undefined, {
|
||||
maximumFractionDigits,
|
||||
})
|
||||
: value.toLocaleString(undefined, {
|
||||
maximumSignificantDigits: 3,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user