Skip to content

Commit

Permalink
fix(wallet-dashboard): improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cpl121 committed Nov 14, 2024
1 parent 94bcca1 commit 17058ad
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
1 change: 0 additions & 1 deletion apps/core/src/components/Inputs/AddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export function AddressInput({
const handleOnChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
const address = e.currentTarget.value;
iotaAddressValidation.cast(address);
helpers.setValue(iotaAddressValidation.cast(address));
},
[name, iotaAddressValidation],
Expand Down
31 changes: 15 additions & 16 deletions apps/core/src/components/Inputs/SendTokenFormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import { CoinStruct } from '@iota/iota-sdk/client';
import { useGasBudgetEstimation } from '../../hooks';
import { useEffect } from 'react';
import { FormikProps, useField } from 'formik';
import React from 'react';

export interface SendTokenInputProps<FormValues> {
coins: CoinStruct[];
symbol: string;
coinDecimals: number;
activeAddress: string;
values: {
amount: string;
to: string;
isPayAllIota: boolean;
};
amount: string;
to: string;
isPayAllIota: boolean;
onActionClick: () => Promise<void>;
isMaxActionDisabled?: boolean;
name: string;
Expand All @@ -25,7 +24,9 @@ export interface SendTokenInputProps<FormValues> {

export function SendTokenFormInput<FormValues>({
coins,
values,
amount,
to,
isPayAllIota,
symbol,
coinDecimals,
activeAddress,
Expand All @@ -38,20 +39,18 @@ export function SendTokenFormInput<FormValues>({
coinDecimals,
coins: coins ?? [],
activeAddress,
to: values.to,
amount: values.amount,
isPayAllIota: values.isPayAllIota,
to: to,
amount: amount,
isPayAllIota: isPayAllIota,
});

const [field, meta] = useField<string>(name);
const [field, meta, helpers] = useField<string>(name);

const numericPropsOnly: Partial<NumericFormatInputProps> = {
decimalScale: coinDecimals ? undefined : 0,
thousandSeparator: true,
onValueChange: (values) => {
form.setFieldValue(field.name, values.value).then(() => {
form.validateField(field.name);
});
helpers.setValue(values.value)

Check failure on line 53 in apps/core/src/components/Inputs/SendTokenFormInput.tsx

View workflow job for this annotation

GitHub Actions / turborepo / Lint, Build, and Test

Insert `;`
},
};

Expand All @@ -67,18 +66,18 @@ export function SendTokenFormInput<FormValues>({
// gasBudgetEstimation should change when the amount above changes
useEffect(() => {
form.setFieldValue('gasBudgetEst', gasBudgetEstimation, false);
}, [gasBudgetEstimation, form.setFieldValue, values.amount]);
}, [gasBudgetEstimation, form.setFieldValue, amount]);

return (
<Input
type={InputType.NumericFormat}
name={'amount'}
name="amount"
value={field.value}
caption="Est. Gas Fees:"
placeholder="0.00"
label="Send Amount"
suffix={` ${symbol}`}
prefix={values.isPayAllIota ? '~ ' : undefined}
prefix={isPayAllIota ? '~ ' : undefined}
allowNegative={false}
errorMessage={errorMessage}
amountCounter={!errorMessage ? (coins ? gasBudgetEstimation : '--') : undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ function FormInputs({
setFieldValue,
values,
submitForm,
touched,
errors,
coinType,
coinDecimals,
coinBalance,
Expand Down Expand Up @@ -122,12 +120,14 @@ function FormInputs({
return (
<SendTokenFormInput
form={form}
amount={values.amount}
to={values.to}
isPayAllIota={values.isPayAllIota}
name={field.name}
symbol={symbol}
coins={coins}
coinDecimals={coinDecimals}
activeAddress={activeAddress}
values={values}
onActionClick={onMaxTokenButtonClick}
isMaxActionDisabled={isMaxActionDisabled}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ export function SendTokenForm({
}}
validationSchema={validationSchemaStepOne}
enableReinitialize
validateOnChange={false}
validateOnBlur={false}
validateOnChange={true}
validateOnBlur={true}
onSubmit={handleFormSubmit}
>
{({
Expand All @@ -150,9 +150,6 @@ export function SendTokenForm({
setFieldValue,
values,
submitForm,
handleBlur,
touched,
errors,
}) => {
const newPayIotaAll =
parseAmount(values.amount, coinDecimals) === coinBalance &&
Expand Down Expand Up @@ -204,11 +201,13 @@ export function SendTokenForm({
<SendTokenFormInput
form={form}
name={field.name}
amount={values.amount}
to={values.to}
isPayAllIota={values.isPayAllIota}
symbol={symbol}
coinDecimals={coinDecimals}
activeAddress={activeAddress ?? ''}
coins={coins ?? []}
values={values}
onActionClick={onMaxTokenButtonClick}
isMaxActionDisabled={isMaxActionDisabled}
/>
Expand Down

0 comments on commit 17058ad

Please sign in to comment.