Skip to content

Commit

Permalink
fix(mobile): fetching balances for created wallet (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorokin0andrey authored Dec 7, 2023
1 parent d903dec commit 1403215
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions packages/mobile/src/blockchain/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,24 +677,40 @@ export class TonWallet {
}

async getLockupBalances(info: Account) {
if (['empty', 'uninit', 'nonexist'].includes(info?.status ?? '')) {
const balance = (
await this.blockchainApi.getRawAccount({ accountId: info.address })
).balance;
return [Ton.fromNano(balance), 0, 0];
}
try {
if (['empty', 'uninit', 'nonexist'].includes(info?.status ?? '')) {
const balance = (
await this.blockchainApi.getRawAccount({ accountId: info.address })
).balance;
return [Ton.fromNano(balance), 0, 0];
}

const balances = await this.vault.tonWallet.getBalances();
const result = balances.map((item: number) => Ton.fromNano(item.toString()));
result[0] = new BigNumber(result[0]).minus(result[1]).minus(result[2]).toString();
const balances = await this.vault.tonWallet.getBalances();
const result = balances.map((item: number) => Ton.fromNano(item.toString()));
result[0] = new BigNumber(result[0]).minus(result[1]).minus(result[2]).toString();

return result;
} catch (e) {
if (e?.response?.status === 404) {
return [Ton.fromNano('0'), 0, 0];
}

return result;
throw e;
}
}

async getBalance(): Promise<string> {
const account = await this.vault.getTonAddress(this.isTestnet);
const balance = (await this.blockchainApi.getRawAccount({ accountId: account }))
.balance;
return Ton.fromNano(balance);
try {
const account = await this.vault.getTonAddress(this.isTestnet);
const balance = (await this.blockchainApi.getRawAccount({ accountId: account }))
.balance;
return Ton.fromNano(balance);
} catch (e) {
if (e?.response?.status === 404) {
return Ton.fromNano(0);
}

throw e;
}
}
}

0 comments on commit 1403215

Please sign in to comment.