From d00e57d6f267e2a9c80d275557d46c1faa9f237a Mon Sep 17 00:00:00 2001 From: kurt Date: Thu, 17 Oct 2024 11:25:04 +0800 Subject: [PATCH] replace system token value with liquid --- src/lib/state/client/account.svelte.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/lib/state/client/account.svelte.ts b/src/lib/state/client/account.svelte.ts index f8b165b21..7ab709db6 100644 --- a/src/lib/state/client/account.svelte.ts +++ b/src/lib/state/client/account.svelte.ts @@ -43,7 +43,7 @@ export class AccountState { ); public balances = $derived.by(() => this.network - ? getBalances(this.sources, this.network.chain.id, this.network.tokenmeta) + ? getBalances(this.sources, this.network.chain.id, this.network.tokenmeta, this.balance) : undefined ); public delegations = $derived(getDelegations(this.sources)); @@ -216,12 +216,25 @@ export function getBalance(network: NetworkState, sources: DataSources): Balance export function getBalances( sources: DataSources, chain: Checksum256, - tokenmeta?: TokenMeta[] + tokenmeta?: TokenMeta[], + balance?: Balance ): TokenBalance[] { if (sources.light_account) { const balances: TokenBalance[] = []; + + //If the value of system token is 0, + //for example, the chain does not support lightapi. + //replace it with the value of liquid sources.light_account?.forEach((lightAccount) => { - const asset = Asset.from(`${lightAccount.amount} ${lightAccount.currency}`); + let amount = lightAccount.amount; + if ( + !Number(amount) && + balance?.liquid && + balance.liquid.symbol.name === lightAccount.currency + ) { + amount = String(balance.liquid.value); + } + const asset = Asset.from(`${amount} ${lightAccount.currency}`); const contract = Name.from(lightAccount.contract); const id = TokenIdentifier.from({ chain: chain,