You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any balances should be displayed denominated as the currency of the chain e.g. 100CAN, 1MCAN, instead of e.g. 10000000000000000000000000000
Details
By default all balances are represented by a u128 which is the smallest unit of a chain's balance e.g. in Polkadot it is called a Planck.
So in this case an account with 1 DOT == 10_000_000_000 Plancks.
At the moment we would display the big number which is obviously not very user friendly.
So we should convert the raw units into the denominated token. You can query thesystem_properties rpc to fetch arbitrary JSON encoded properties defined in the chainspec. By convention it may contain the following useful properties:
The other thing to figure out is how to identify where such a Balance type is being used, and then to decode it into a custom type that can display the required conversion.
The slightly tricky thing might be that Balance is typically a primitive u128 type and not its own type, so it may be required to check the typeName field of the type metadata to see if it is Balance or T::Balance, since usually a type alias or associated type is used for this. Needs some investigation though.
The text was updated successfully, but these errors were encountered:
Extracted from #432.
Any balances should be displayed denominated as the currency of the chain e.g. 100CAN, 1MCAN, instead of e.g. 10000000000000000000000000000
Details
By default all balances are represented by a
u128
which is the smallest unit of a chain's balance e.g. in Polkadot it is called aPlanck
.So in this case an account with 1 DOT == 10_000_000_000 Plancks.
At the moment we would display the big number which is obviously not very user friendly.
So we should convert the raw units into the denominated token. You can query the
system_properties
rpc to fetch arbitrary JSON encoded properties defined in the chainspec. By convention it may contain the following useful properties:These can be used to convert the raw units into more human readable balances.
If those properties are not present we should consider defaulting to some sensible defaults. I suggest looking at how
polkadot.js
handles this for inspiration: https://github.com/polkadot-js/api/search?q=tokenDecimalsDisplaying it
The other thing to figure out is how to identify where such a
Balance
type is being used, and then to decode it into a custom type that can display the required conversion.Suggest looking at how other custom display types are registered e.g. with
AccountId
andHash
types: https://github.com/paritytech/cargo-contract/blob/f903c0349ba97b0219e14efcd81f67f4c48733eb/transcode/src/lib.rs#L154-L156The slightly tricky thing might be that
Balance
is typically a primitiveu128
type and not its own type, so it may be required to check thetypeName
field of the type metadata to see if it isBalance
orT::Balance
, since usually a type alias or associated type is used for this. Needs some investigation though.The text was updated successfully, but these errors were encountered: