Skip to content

Commit

Permalink
Fix Adv Input Prb (#389)
Browse files Browse the repository at this point in the history
* Fix Adv Input PRb

* Fix button preset
  • Loading branch information
pivilartisant authored Jun 9, 2023
1 parent 754d9c9 commit 883a41c
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 74 deletions.
2 changes: 0 additions & 2 deletions web-frontend/src/pages/TransferCoins/SendCoins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ function SendCoins() {

const tabIndex = parseInt(query.get('tabIndex') || '0');

console.log(tabIndex);

const { nickname } = useParams();
const { data: account } = useResource<AccountObject>(`accounts/${nickname}`);

Expand Down
11 changes: 9 additions & 2 deletions web-frontend/src/pages/TransferCoins/SendCoins/Advanced.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ function Modal({ ...props }) {
function handlePresetGas() {
setCustomFees(false);
setPresetGasFees(true);
handleFees('1000');
setErrorAdvanced(null);
}

function handleCustomGas() {
Expand All @@ -71,12 +73,18 @@ function Modal({ ...props }) {
function handleClose() {
setModal(!modal);
setErrorAdvanced(null);
handleFees('1000');
}

function handleOpen() {
handleFees('1000');
}

return (
<PopupModal
fullMode={true}
onClose={handleClose}
onOpen={handleOpen}
customClass="!w-1/2 min-w-[775px]"
>
<PopupModalHeader>
Expand Down Expand Up @@ -119,8 +127,7 @@ function Modal({ ...props }) {
type="text"
placeholder="Gas fees amount (nMAS)"
name="fees"
defaultValue=""
value={customGasFees ? fees : ''}
value={!customGasFees ? '' : fees}
disabled={!customGasFees}
onChange={(e) => handleFees(e.target.value)}
error={errorAdvanced?.amount}
Expand Down
4 changes: 2 additions & 2 deletions web-frontend/src/pages/TransferCoins/SendCoins/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useState, ChangeEvent, FormEvent } from 'react';

import {
validateInputs,
validateAmount,
SendInputsErrors,
validateAmount,
} from '../../../validation/sendInputs';
import { formatStandard, Unit } from '../../../utils/MassaFormating';
import { parseForm } from '../../../utils/parseForm';
Expand Down Expand Up @@ -46,7 +46,7 @@ function Send(props: SendProps) {
const errors = validateInputs(
amount,
recipient,
'recipient',
'Recipient',
unformattedBalance,
);
setError(errors);
Expand Down
138 changes: 72 additions & 66 deletions web-frontend/src/pages/TransferCoins/SendCoins/SendForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,76 +46,82 @@ export function SendForm({ ...props }) {
};

return (
<form onSubmit={handleSubmit}>
{/* Balance Section */}
<p className="mas-subtitle mb-5">{Intl.t('sendcoins.account-balance')}</p>
<Balance customClass="mb-5" amount={formattedBalance} />
<div className="flex flex-row justify-between w-full pb-3.5 ">
<p className="mas-body2"> {Intl.t('sendcoins.send-action')} </p>
<p className="mas-body2">
{Intl.t('sendcoins.available-balance')} <u>{formattedBalance}</u>
<div>
<form onSubmit={handleSubmit}>
{/* Balance Section */}
<p className="mas-subtitle mb-5">
{Intl.t('sendcoins.account-balance')}
</p>
</div>
<div className="pb-3.5">
<Input
placeholder={'Amount to send'}
value={amount}
name="amount"
onChange={(e) => handleChange(e)}
error={error?.amount}
/>
</div>
<div className="flex flex-row-reverse">
<ul className="flex flex-row mas-body2">
<SendPercentage percentage={25} />
<SendPercentage percentage={50} />
<SendPercentage percentage={75} />
<SendPercentage percentage={100} />
</ul>
</div>
<p className="pb-3.5 mas-body2">{Intl.t('sendcoins.recipient')}</p>
<div className="pb-3.5">
<Input
placeholder={'Recipient'}
value={recipient}
onChange={(e) => setRecipient(e.target.value)}
name="recipient"
error={error?.address}
/>
</div>
<div className="flex flex-row-reverse pb-3.5">
<p
className="hover:cursor-pointer"
onClick={() => setModalAccounts(!modalAccounts)}
>
<u className="mas-body2">
{Intl.t('sendcoins.transfer-between-acc')}
</u>
</p>
</div>
{/* Button Section */}
<div className="flex flex-col w-full gap-3.5">
<Button
onClick={() => setModal(!modal)}
variant={'secondary'}
posIcon={<FiPlus />}
>
{Intl.t('sendcoins.advanced')}
</Button>

<div>
<Button type="submit" posIcon={<FiArrowUpRight />}>
{Intl.t('sendcoins.send')}
<Balance customClass="mb-5" amount={formattedBalance} />
<div className="flex flex-row justify-between w-full pb-3.5 ">
<p className="mas-body2"> {Intl.t('sendcoins.send-action')} </p>
<p className="mas-body2">
{Intl.t('sendcoins.available-balance')} <u>{formattedBalance}</u>
</p>
</div>
<div className="pb-3.5">
<Input
placeholder={'Amount to send'}
value={amount}
name="amount"
onChange={(e) => handleChange(e)}
error={error?.amount}
/>
</div>
<div className="flex flex-row-reverse">
<ul className="flex flex-row mas-body2">
<SendPercentage percentage={25} />
<SendPercentage percentage={50} />
<SendPercentage percentage={75} />
<SendPercentage percentage={100} />
</ul>
</div>
<p className="pb-3.5 mas-body2">{Intl.t('sendcoins.recipient')}</p>
<div className="pb-3.5">
<Input
placeholder={'Recipient'}
value={recipient}
onChange={(e) => setRecipient(e.target.value)}
name="recipient"
error={error?.address}
/>
</div>
<div className="flex flex-row-reverse pb-3.5">
<p
className="hover:cursor-pointer"
onClick={() => setModalAccounts(!modalAccounts)}
>
<u className="mas-body2">
{Intl.t('sendcoins.transfer-between-acc')}
</u>
</p>
</div>
{/* Button Section */}
<div className="flex flex-col w-full gap-3.5">
<Button
onClick={() => setModal(!modal)}
variant={'secondary'}
posIcon={<FiPlus />}
>
{Intl.t('sendcoins.advanced')}
</Button>

<div>
<Button type="submit" posIcon={<FiArrowUpRight />}>
{Intl.t('sendcoins.send')}
</Button>
</div>
</div>
</div>
</form>
<div>
{modal ? (
<Modal {...modalArgsAdvanced} />
) : modalAccounts ? (
<ContactList {...modalArgsAccounts} />
) : null}
<div>
{modal ? (
<Modal {...modalArgsAdvanced} />
) : modalAccounts ? (
<ContactList {...modalArgsAccounts} />
) : null}
</div>
</div>
</form>
</div>
);
}
13 changes: 11 additions & 2 deletions web-frontend/src/validation/sendInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface SendInputsErrors {
unexpectedError?: string;
amount?: string;
address?: string;
fees?: string;
}

/**
Expand All @@ -21,7 +22,7 @@ export interface SendInputsErrors {
export function validateInputs(
amount: string,
address: string,
addressType = 'recipient',
addressType = 'Recipient',
balance?: string,
): SendInputsErrors | null {
let errorsAmount = null;
Expand All @@ -46,8 +47,16 @@ export function validateAmount(
balance?: string,
amountType = 'Amount',
): SendInputsErrors | null {
let amountInNanoMassa = reverseFormatStandard(amount);
let verb = amountType == 'Amount' ? 'is' : 'are';

if (Number.isNaN(+amount)) {
return {
amount: Intl.t('errors.send.invalid-amount', { type: amountType, verb }),
};
}

let amountInNanoMassa = reverseFormatStandard(amount);

if (Number.isNaN(amountInNanoMassa)) {
return {
amount: Intl.t('errors.send.invalid-amount', { type: amountType, verb }),
Expand Down

0 comments on commit 883a41c

Please sign in to comment.