Skip to content

Commit

Permalink
Merge pull request #1345 from Pawar7349/fix/wallet-utilities-formatting
Browse files Browse the repository at this point in the history
fix(wallet-utilities): fix balance display issue and ensure accurate …
  • Loading branch information
gagdiez authored Nov 21, 2024
2 parents 19bad57 + 0769786 commit fd49528
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"prettier": "prettier --check 'src/**/*.{js,jsx,ts,tsx,json}'",
"prettier": "prettier --check \"src/**/*.{js,jsx,ts,tsx,json}\"",
"prettier:write": "prettier --write 'src/**/*.{js,jsx,ts,tsx,json}'",
"prepare": "is-ci || husky install && npm install commitizen -g",
"pre-commit": "pnpm prettier && pnpm lint --max-warnings 0 && pnpm ts:check",
Expand Down
14 changes: 6 additions & 8 deletions src/components/wallet-utilities/SendNear.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ type FormData = {
};

function displayBalance(balance: number) {
let display = Math.floor(balance * 100) / 100;

if (balance < 1) {
display = Math.floor(balance * 100000) / 100000;
if (balance && !display) return '< 0.00001';
const display = (balance * 100000).toFixed(5);
if (balance && parseFloat(display) === 0) return '< 0.00001';
return display;
}

return display;
return balance.toFixed(5);
}

export const SendNear = () => {
Expand All @@ -36,7 +33,8 @@ export const SendNear = () => {
try {
const balance = await wallet.getBalance(signedAccountId);
const requiredGas = 0.00005;
setCurrentNearAmount(balance - requiredGas);
const availableBalance = balance - requiredGas;
setCurrentNearAmount(Math.max(availableBalance, 0));
} catch (error) {
console.error(error);
}
Expand Down Expand Up @@ -65,7 +63,7 @@ export const SendNear = () => {
};
const result: any = await wallet.signAndSendTransactions({ transactions: [sendNear] });

setCurrentNearAmount((value) => value - (data.sendNearAmount || 0));
setCurrentNearAmount((value) => Math.max(value - (data.sendNearAmount || 0), 0));
form.reset();

openToast({
Expand Down

0 comments on commit fd49528

Please sign in to comment.