From 18988f466d467b5ac44a4608688801be1fbd0c29 Mon Sep 17 00:00:00 2001 From: Preschian Febryantara Date: Wed, 17 May 2023 16:55:35 +0700 Subject: [PATCH 1/8] feat: multi chain balances --- components/balance/MultipleBalances.vue | 165 ++++++++++++++++++ .../common/ConnectWallet/WalletAsset.vue | 27 ++- 2 files changed, 178 insertions(+), 14 deletions(-) create mode 100644 components/balance/MultipleBalances.vue diff --git a/components/balance/MultipleBalances.vue b/components/balance/MultipleBalances.vue new file mode 100644 index 0000000000..7b6ad0c757 --- /dev/null +++ b/components/balance/MultipleBalances.vue @@ -0,0 +1,165 @@ + + + + + diff --git a/components/common/ConnectWallet/WalletAsset.vue b/components/common/ConnectWallet/WalletAsset.vue index eac44a2fe5..a17c3b7ebc 100644 --- a/components/common/ConnectWallet/WalletAsset.vue +++ b/components/common/ConnectWallet/WalletAsset.vue @@ -14,17 +14,18 @@
- - + +
-
- -
- {{ $i18n.t('spotlight.total') }}: - ${{ totalValue.toFixed(2) }} +
+
+
+ {{ $i18n.t('spotlight.total') }}: + ${{ totalValue.toFixed(2) }} +
@@ -52,8 +53,8 @@ import useIdentity from '@/components/identity/utils/useIdentity' const Identity = defineAsyncComponent( () => import('@/components/identity/module/IdentityLink.vue') ) -const AccountBalance = defineAsyncComponent( - () => import('@/components/shared/AccountBalance.vue') +const MultipleBalances = defineAsyncComponent( + () => import('@/components/balance/MultipleBalances.vue') ) const ProfileAssetsList = defineAsyncComponent( () => import('@/components/rmrk/Profile/ProfileAssetsList.vue') @@ -69,9 +70,7 @@ const emit = defineEmits(['back']) const account = computed(() => identityStore.getAuthAddress) const walletName = computed(() => walletStore.wallet.name) -const isSnekOrBsx = computed( - () => urlPrefix.value === 'snek' || urlPrefix.value === 'bsx' -) +const isSnek = computed(() => urlPrefix.value === 'snek') const { shortenedAddress } = useIdentity({ address: account, From 6d8b92f70b4987c3e7cb280637e538264c341eaf Mon Sep 17 00:00:00 2001 From: Preschian Febryantara Date: Wed, 17 May 2023 17:38:45 +0700 Subject: [PATCH 2/8] fix: available balance only --- components/balance/MultipleBalances.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/balance/MultipleBalances.vue b/components/balance/MultipleBalances.vue index 7b6ad0c757..460535f075 100644 --- a/components/balance/MultipleBalances.vue +++ b/components/balance/MultipleBalances.vue @@ -36,6 +36,7 @@ import { ApiPromise, WsProvider } from '@polkadot/api' import { decodeAddress, encodeAddress } from '@polkadot/util-crypto' import { CHAINS, ENDPOINT_MAP } from '@kodadot1/static' import { NeoSkeleton } from '@kodadot1/brick' +import { balanceOf } from '@kodadot1/sub-api' import format from '@/utils/format/balance' import { useFiatStore } from '@/stores/fiat' @@ -124,8 +125,8 @@ async function getBalance(chainName, token = 'KSM', tokenId = 0) { false ) } else { - const { data: balance } = await api.query.system.account(prefixAddress) - currentBalance = format(balance.free, chain.tokenDecimals, false) + const balance = await balanceOf(api, prefixAddress) + currentBalance = format(balance, chain.tokenDecimals, false) } const balance = delimiter(currentBalance) From e5f092a7569cdfa3eb491629cf257aedffc5a2e8 Mon Sep 17 00:00:00 2001 From: Preschian Febryantara Date: Wed, 17 May 2023 18:15:00 +0700 Subject: [PATCH 3/8] fix: add await to fetchBalance --- components/common/ConnectWallet/WalletAsset.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/common/ConnectWallet/WalletAsset.vue b/components/common/ConnectWallet/WalletAsset.vue index a17c3b7ebc..826fb64dcd 100644 --- a/components/common/ConnectWallet/WalletAsset.vue +++ b/components/common/ConnectWallet/WalletAsset.vue @@ -90,15 +90,15 @@ const setTotalValue = (value: number) => { totalValue.value = value } -onMounted(() => { +onMounted(async () => { if (identityStore.getAuthAddress) { $consola.log('fetching balance...') $consola.log(urlPrefix.value) - identityStore.fetchBalance({ + await identityStore.fetchBalance({ address: identityStore.getAuthAddress, }) $consola.log(identityStore.auth.balance) - $consola.log(identityStore.auth.balance[urlPrefix.value]) + $consola.log(identityStore.auth.balance?.[urlPrefix.value]) } }) From 920ca7f511471d54b85f1e70fdc8ea1194b9ae66 Mon Sep 17 00:00:00 2001 From: Preschian Febryantara Date: Wed, 17 May 2023 18:34:26 +0700 Subject: [PATCH 4/8] fix: style and parallel requests --- components/balance/MultipleBalances.vue | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/components/balance/MultipleBalances.vue b/components/balance/MultipleBalances.vue index 460535f075..9bc1049922 100644 --- a/components/balance/MultipleBalances.vue +++ b/components/balance/MultipleBalances.vue @@ -1,7 +1,7 @@