Skip to content

Commit

Permalink
chore: embed stringToBigNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbulat committed Oct 30, 2024
1 parent eb407e2 commit 0dc822c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/app/src/model/AccountBalances/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0

import type { VoidFn } from '@polkadot/api/types';
import { stringToBigNumber } from '@w3ux/utils';
import { rmCommas } from '@w3ux/utils';
import type { AnyJson } from '@w3ux/types';
import type { ChainId } from 'config/networks/types';
import { ApiController } from 'controllers/Api';
Expand All @@ -11,6 +11,7 @@ import type { Unsubscribable } from 'controllers/Subscriptions/types';
import type { ApiInstanceId } from 'model/Api/types';
import { getIndexFromInstanceId } from 'model/Api/util';
import type { OwnerId } from 'types';
import BigNumber from 'bignumber.js';

export class AccountBalances implements Unsubscribable {
// ------------------------------------------------------
Expand Down Expand Up @@ -88,16 +89,18 @@ export class AccountBalances implements Unsubscribable {
this.balances[address] = {
nonce: nonce.toNumber(),
balance: {
free: stringToBigNumber(accountData.free.toString()),
reserved: stringToBigNumber(accountData.reserved.toString()),
frozen: stringToBigNumber(accountData.frozen.toString()),
free: this.stringToBigNumber(accountData.free.toString()),
reserved: this.stringToBigNumber(
accountData.reserved.toString()
),
frozen: this.stringToBigNumber(accountData.frozen.toString()),
},
locks: locksResult
.toHuman()
.map((lock: { id: string; amount: string }) => ({
...lock,
id: lock.id.trim(),
amount: stringToBigNumber(lock.amount),
amount: this.stringToBigNumber(lock.amount),
})),
};

Expand Down Expand Up @@ -156,4 +159,12 @@ export class AccountBalances implements Unsubscribable {
unsub();
});
};

// ------------------------------------------------------
// Utils.
// ------------------------------------------------------

// Convert string to BigNumber.
stringToBigNumber = (value: string): BigNumber =>
new BigNumber(rmCommas(value));
}

0 comments on commit 0dc822c

Please sign in to comment.