Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi committed Sep 23, 2024
1 parent c51af3c commit 83c59de
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/popup/components/ConnectWalletForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,17 @@ export const ConnectWalletForm = ({

const getWalletCurrency = React.useCallback(
async (walletAddressUrl: string): Promise<void> => {
setErrors((e) => ({ ...e, walletAddressUrl: '' }));
setErrors((_) => ({ ..._, walletAddressUrl: '' }));
if (!walletAddressUrl) return;
try {
setIsValidating((e) => ({ ...e, walletAddressUrl: true }));
const url = new URL(toWalletAddressUrl(walletAddressUrl));
const walletAddress = await getWalletInfo(url.toString());
setWalletAddressInfo(walletAddress);
} catch (error) {
setErrors((e) => ({
...e,
walletAddressUrl: error.message,
}));
setErrors((_) => ({ ..._, walletAddressUrl: error.message }));
} finally {
setIsValidating((e) => ({ ...e, walletAddressUrl: false }));
setIsValidating((_) => ({ ..._, walletAddressUrl: false }));
}
},
[getWalletInfo],
Expand All @@ -97,10 +94,10 @@ export const ConnectWalletForm = ({
amount: validateAmount(amount, currencySymbol.symbol),
};
if (!walletAddressInfo) {
setErrors((e) => ({ ...e, walletAddressUrl: 'Not fetched yet?!' }));
setErrors((_) => ({ ..._, walletAddressUrl: 'Not fetched yet?!' }));
return;
}
setErrors((e) => ({ ...e, ...err }));
setErrors((_) => ({ ..._, ...err }));
if (err.amount || err.walletAddressUrl) {
return;
}
Expand All @@ -112,7 +109,7 @@ export const ConnectWalletForm = ({
skipAutoKeyShare = true;
setAutoKeyShareFailed(true);
}
setErrors((e) => ({ ...e, keyPair: '', connect: '' }));
setErrors((_) => ({ ..._, keyPair: '', connect: '' }));
const res = await connectWallet({
walletAddressUrl: toWalletAddressUrl(walletAddressUrl),
amount,
Expand All @@ -124,13 +121,13 @@ export const ConnectWalletForm = ({
} else {
if (res.message.startsWith('ADD_PUBLIC_KEY_TO_WALLET:')) {
const message = res.message.replace('ADD_PUBLIC_KEY_TO_WALLET:', '');
setErrors((e) => ({ ...e, keyPair: message }));
setErrors((_) => ({ ..._, keyPair: message }));
} else {
throw new Error(res.message);
}
}
} catch (error) {
setErrors((e) => ({ ...e, connect: error.message }));
setErrors((_) => ({ ..._, connect: error.message }));
} finally {
setIsSubmitting(false);
}
Expand Down Expand Up @@ -193,7 +190,7 @@ export const ConnectWalletForm = ({
setWalletAddressUrl(value);

const error = validateWalletAddressUrl(value);
setErrors((e) => ({ ...e, walletAddressUrl: error }));
setErrors((_) => ({ ..._, walletAddressUrl: error }));
if (!error) {
await getWalletCurrency(value);
}
Expand Down Expand Up @@ -237,7 +234,7 @@ export const ConnectWalletForm = ({
}

const error = validateAmount(value, currencySymbol.symbol);
setErrors((e) => ({ ...e, amount: error }));
setErrors((_) => ({ ..._, amount: error }));

const amountValue = formatNumber(+value, currencySymbol.scale);
if (!error) {
Expand Down

0 comments on commit 83c59de

Please sign in to comment.