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

🔧 identity balance #4999

Merged
merged 5 commits into from
Feb 17, 2023
Merged
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
18 changes: 6 additions & 12 deletions store/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import Vue from 'vue'
import { formatAddress } from '@/utils/account'
import type { ApiPromise } from '@polkadot/api'
import { getChainEndpointByPrefix } from '@/utils/chain'
import { unwrapOrNull } from '@/utils/api/format'
import type { Option, u32 } from '@polkadot/types'
import {
Unsubscribe,
UnsubscribePromise,
Expand Down Expand Up @@ -63,17 +61,12 @@ function free({ free }: any) {
async function subscribeTokens(
api: ApiPromise,
address: string,
prefix: string,
cb: (value: BalanceMap) => void
): UnsubscribePromise {
if (api.query.tokens) {
const version = await api.query.system
.lastRuntimeUpgrade()
.then((value) => unwrapOrNull(value)?.specVersion.toNumber())
const kusamaTokenId = await api.query.assetRegistry
.assetIds(Number(version) > 82 ? 'Kusama' : 'KSM')
.then((value) => unwrapOrNull(value as Option<u32>))
const realKusamaTokenId = kusamaTokenId ? '5' : '1'
return api.query.tokens.accounts.multi(
const realKusamaTokenId = prefix === 'bsx' || prefix === 'rmrk' ? '1' : '5'
return await api.query.tokens.accounts.multi(
[[address, realKusamaTokenId]],
([ksm]: any[]) =>
cb({
Expand Down Expand Up @@ -139,7 +132,8 @@ export const actions = {
{ commit, dispatch, rootState },
{ address, apiUrl }: ChangeAddressRequest
) {
const directEndpoint = getChainEndpointByPrefix(rootState.setting.urlPrefix)
const prefix = rootState.setting.urlPrefix
const directEndpoint = getChainEndpointByPrefix(prefix)
const endpoint = apiUrl || directEndpoint || rootState.setting.apiUrl
if (!address) {
balanceSub()
Expand All @@ -161,7 +155,7 @@ export const actions = {
dispatch('setBalance', balance)
})

tokenSub = await subscribeTokens(api, address, (balance) => {
tokenSub = await subscribeTokens(api, address, prefix, (balance) => {
commit('setTokenListBalance', balance)
})
} catch (e) {
Expand Down