From 4c8a50dd02bea5d0b33a050b6f350404503f0230 Mon Sep 17 00:00:00 2001 From: Max Voloshinskii Date: Fri, 8 Mar 2024 21:01:33 +0300 Subject: [PATCH] fix(mobile): toNano fix for jetton transfer (#758) --- packages/mobile/src/blockchain/wallet.ts | 7 +++++-- packages/shared/utils/wallet.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/mobile/src/blockchain/wallet.ts b/packages/mobile/src/blockchain/wallet.ts index 1d1c046bf..b08c929fb 100644 --- a/packages/mobile/src/blockchain/wallet.ts +++ b/packages/mobile/src/blockchain/wallet.ts @@ -25,7 +25,7 @@ import { } from '@tonkeeper/core/src/legacy'; import { tk } from '$wallet'; -import { Address, Cell, internal, toNano } from '@ton/core'; +import { Address, Cell, internal } from '@ton/core'; import { emulateWithBattery, sendBocWithBattery, @@ -35,6 +35,7 @@ import { setBalanceForEmulation } from '@tonkeeper/shared/utils/wallet'; import { WalletNetwork } from '$wallet/WalletTypes'; import { createTonApiInstance } from '$wallet/utils'; import { config } from '$config'; +import { toNano } from '$utils'; const TonWeb = require('tonweb'); @@ -459,7 +460,9 @@ export class TonWallet { if ( !balance || - new BigNumber(Ton.toNano(balance.balance)).lt(new BigNumber(amountNano)) + new BigNumber(toNano(balance.balance, balance.metadata.decimals ?? 9)).lt( + new BigNumber(amountNano), + ) ) { throw new Error(t('send_insufficient_funds')); } diff --git a/packages/shared/utils/wallet.ts b/packages/shared/utils/wallet.ts index 1b9b8362d..257504e30 100644 --- a/packages/shared/utils/wallet.ts +++ b/packages/shared/utils/wallet.ts @@ -14,6 +14,6 @@ export async function getWalletSeqno(wallet?: Wallet) { } } -export function setBalanceForEmulation(balance: bigint) { +export function setBalanceForEmulation(balance: bigint | number | string) { return { balance: Number(balance), address: tk.wallet.address.ton.raw }; }