Skip to content

Commit

Permalink
improve targetMnsAddress confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed May 15, 2024
1 parent 3995f58 commit d249e05
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions web-frontend/src/pages/TransferCoins/SendCoins/SendForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ export function SendForm(props: SendFormProps) {
const [recipient, setRecipient] = useState<string>(
(sendOpData && sendOpData.recipientAddress) || '',
);
const [mnsAddressCorrelelation, setMnsAddressCorrelation] =
useState<boolean>();
const [mnsAddressCorrelation, setMnsAddressCorrelation] = useState<boolean>();

const [selectedAsset, setSelectedAsset] = useState<Asset | undefined>(
(sendOpData && sendOpData.asset) || undefined,
Expand Down Expand Up @@ -137,7 +136,17 @@ export function SendForm(props: SendFormProps) {

function handleSubmit(e: FormEvent<HTMLFormElement>) {
e.preventDefault();
const formObject = parseForm(e);
let formObject = parseForm(e);

if (targetMnsAddress && mnsExtension.test(recipient)) {
formObject = {
...formObject,
recipientAddress: targetMnsAddress,
};
} else {
setMnsAddressCorrelation(false);
resetTargetMnsAddress();
}

if (!validate(formObject) || !selectedAsset) return;

Expand All @@ -162,28 +171,20 @@ export function SendForm(props: SendFormProps) {

useEffect(() => {
setError({ recipient: '' });

if (mnsExtension.test(recipient)) {
const inputMns = recipient.replace(mnsExtension, '');
resolveDns(inputMns);
} else {
setMnsAddressCorrelation(false);
resetTargetMnsAddress();
}
}, [recipient]);

Check warning on line 181 in web-frontend/src/pages/TransferCoins/SendCoins/SendForm.tsx

View workflow job for this annotation

GitHub Actions / lint-web-frontend

React Hook useEffect has missing dependencies: 'mnsExtension', 'resetTargetMnsAddress', and 'resolveDns'. Either include them or remove the dependency array

useEffect(() => {
setMnsAddressCorrelation(
!!targetMnsAddress && checkAddressFormat(targetMnsAddress),
);
}, [recipient, targetMnsAddress]);

function confirmMnsAddress(): void {
if (targetMnsAddress && mnsExtension.test(recipient)) {
setRecipient(targetMnsAddress);
} else {
setMnsAddressCorrelation(false);
resetTargetMnsAddress();
}
}
}, [targetMnsAddress]);

return (
<div>
Expand Down Expand Up @@ -305,7 +306,7 @@ export function SendForm(props: SendFormProps) {
onChange={(e) => setRecipient(e.target.value)}
error={error?.recipient}
/>
{mnsAddressCorrelelation && (
{mnsAddressCorrelation && (
<div className="mas-caption text-brand">
{Intl.t('send-coins.mns.mns-correlation', {
mns: recipient,
Expand Down Expand Up @@ -340,7 +341,7 @@ export function SendForm(props: SendFormProps) {
<Button
type="submit"
posIcon={<FiArrowUpRight />}
onClick={() => confirmMnsAddress()}
// onClick={() => confirmMnsAddress()}
>
{Intl.t('send-coins.send')}
</Button>
Expand Down

0 comments on commit d249e05

Please sign in to comment.