polkadot-js / apps

Basic Polkadot/Substrate UI for interacting with a Polkadot and Substrate node. This is the main user-facing application, allowing access to all features available on Substrate chains.
https://dotapps.io
Apache License 2.0
1.75k stars 1.55k forks source link

Adding custom balance pallets in the accounts page #6744

Closed nud3l closed 2 years ago

nud3l commented 2 years ago

We are using the orml-tokens pallet for all our token needs on the kintsugi and interlay networks. I think we can show a custom token balance on the accounts page using the derive approach. However, I'm not sure how to go about doing that. Is there an example to achieve this?

Essentially, I just want the "KINT" balances to be displayed there:

image

To add some information, the balance I'd like to add can be queried via api.query.tokens('address', {'Token: 'KINT'})

jacogr commented 2 years ago

The balances page only displays the native balances. (eg. balances pallet or a renamed balances pallet).

If not of these, I suppose it could be done by injecting an own derive since the balances page retrieves the native balance using derives - there are some teams (the names of which escape me now) that do apply their own balances derives in apps-config, but honestly don't have the details to see what they change.

nud3l commented 2 years ago

Ok, thanks! I think Equilibrium did that when I browsed through the files. I will ask them directly.

jacogr commented 2 years ago

Sorry I'm not of much help here - I believe it is only the derive.balances.all that needs adjustment. (And yes, after looking, you are correct, seems to be Equilibrium)

nud3l commented 2 years ago

Ok, thanks! One related question: is it possible to enforce an ordering of the "TokenSymbol"? On-chain we have the following enum:

    pub enum TokenSymbol {
        DOT("Polkadot", 10) = 0,
        INTERBTC("interBTC", 8) = 1,
        INTR("Interlay", 10) = 2,

        KSM("Kusama", 12) = 10,
        KBTC("kBTC", 8) = 11,
        KINT("Kintsugi", 12) = 12,
    }

Apps will always take the first element as the main currency, however, in our case, we'd like to set KINT as the primary currency and INTR for the Interlay network. I saw that it's being fetched via the api.registry but it's a bit unclear to me how I could modify this.

jacogr commented 2 years ago

Where do you want to enforce ordering? The tokenSymbol retrieved from the registry is as defined in the chainspec, i.e. via system_properties it uses the first decimals/tokens defined in the arrays.

nud3l commented 2 years ago

Where does it get the system_properties from? Is that defined on-chain or somewhere in JS world (and extended question, if it comes form the on-chain data, which I assume, can it be "reordered")? I am aware of the ss58 prefix being defined on chain (here for Kintsugi: https://github.com/interlay/interbtc/blob/master/parachain/runtime/kintsugi/src/lib.rs#L234), but not really sure where the tokenSymbol would be set.

Essentially, what I am trying to do is tell polkadot.js to use not the first element in this enum:

    pub enum TokenSymbol {
        DOT("Polkadot", 10) = 0,
        INTERBTC("interBTC", 8) = 1,
        INTR("Interlay", 10) = 2,

        KSM("Kusama", 12) = 10,
        KBTC("kBTC", 8) = 11,
        KINT("Kintsugi", 12) = 12,
    }

But the last one. I thought that maybe I could achieve this by injecting custom ordering within apps.

jacogr commented 2 years ago

the properties is an RPC. It returns the properties section in the chainspec.

gregdhill commented 2 years ago

@jacogr would it be possible to also support "Send" using derives? The "Accounts" page currently crashes with the error api.consts.balances is undefined when I try to open the modal.

polkadot-js-bot commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.