Skip to content

Commit

Permalink
fix: balance & prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo Alejandro Gallardo Diez authored and Guillermo Alejandro Gallardo Diez committed Jan 5, 2025
1 parent c480c04 commit 04c4c97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
17 changes: 6 additions & 11 deletions src/components/wallet-utilities/SendNear.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,13 @@ import type { SubmitHandler } from 'react-hook-form';
import { useForm } from 'react-hook-form';

import { NearContext } from '../wallet-selector/WalletSelector';
import { NEAR_NOMINATION } from 'near-api-js/lib/utils/format';

type FormData = {
sendNearAmount: number;
sendToAccountId: string;
};

function displayBalance(balance: number) {
if (balance < 1) {
const display = (balance * 100000).toFixed(5);
if (balance && parseFloat(display) === 0) return '< 0.00001';
return display;
}
return balance.toFixed(5);
}

export const SendNear = () => {
const form = useForm<FormData>();
const { wallet, signedAccountId } = useContext(NearContext);
Expand All @@ -31,7 +23,10 @@ export const SendNear = () => {

const loadBalance = async () => {
try {
const balance = await wallet.getBalance(signedAccountId);
const balanceYocto = await wallet.getBalance(signedAccountId);
const balance = parseFloat((BigInt(balanceYocto) / NEAR_NOMINATION).toString());

console.log('balance', balanceYocto, balance);
const requiredGas = 0.00005;
const availableBalance = balance - requiredGas;
setCurrentNearAmount(Math.max(availableBalance, 0));
Expand Down Expand Up @@ -105,7 +100,7 @@ export const SendNear = () => {
allowNegative: false,
allowDecimal: true,
}}
assistive={`${displayBalance(currentNearAmount)} available`}
assistive={`${currentNearAmount.toFixed(5)} available`}
error={form.formState.errors.sendNearAmount?.message}
{...form.register('sendNearAmount', {
min: {
Expand Down
23 changes: 11 additions & 12 deletions src/pages/privacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import { useBosComponents } from '@/hooks/useBosComponents';
import { useDefaultLayout } from '@/hooks/useLayout';
import type { NextPageWithLayout } from '@/utils/types';


const PrivacyPage: NextPageWithLayout = () => {
const components = useBosComponents();
return (
<ComponentWrapperPage
src={components.nearOrg.privacyPage}
meta={{ title: 'Privacy Policy', description: '' }}
componentProps={{
privacyDomainName,
}}
/>
);
};
<ComponentWrapperPage
src={components.nearOrg.privacyPage}
meta={{ title: 'Privacy Policy', description: '' }}
componentProps={{
privacyDomainName,
}}
/>
);
};

PrivacyPage.getLayout = useDefaultLayout;
PrivacyPage.getLayout = useDefaultLayout;

export default PrivacyPage
export default PrivacyPage;

0 comments on commit 04c4c97

Please sign in to comment.