Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet-utilities): fix balance display issue and ensure accurate … #1345

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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