Skip to content

Commit

Permalink
replace system token value with liquid
Browse files Browse the repository at this point in the history
  • Loading branch information
ttwishing committed Oct 17, 2024
1 parent cca8ad5 commit d00e57d
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/lib/state/client/account.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d00e57d

Please sign in to comment.