From e9f8fb2cda0641bcdb7e15818a057c7492ed728c Mon Sep 17 00:00:00 2001 From: denviljclarke <60730266+denviljclarke@users.noreply.github.com> Date: Thu, 7 Sep 2023 21:55:39 -0500 Subject: [PATCH] refactor: improve error text logic readability --- src/features/swap/SwapForm.tsx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/features/swap/SwapForm.tsx b/src/features/swap/SwapForm.tsx index 7609262..01d6412 100644 --- a/src/features/swap/SwapForm.tsx +++ b/src/features/swap/SwapForm.tsx @@ -273,6 +273,7 @@ function SubmitButton() { const { switchNetworkAsync } = useSwitchNetwork() const { openConnectModal } = useConnectModal() const dispatch = useAppDispatch() + const { errors, touched } = useFormikContext() const isAccountReady = address && isConnected const isOnCelo = chains.some((chn) => chn.id === chain?.id) @@ -292,17 +293,20 @@ function SubmitButton() { } } - const { errors, touched } = useFormikContext() const error = touched.amount && (errors.amount || errors.fromTokenId || errors.toTokenId || errors.slippage) - const text = error - ? error - : !isAccountReady - ? 'Connect Wallet' - : !isOnCelo - ? 'Switch to Celo Network' - : 'Continue' - + let text; + + if (error) { + text = error; + } else if (!isAccountReady) { + text = 'Connect Wallet'; + } else if (!isOnCelo) { + text = 'Switch to Celo Network'; + } else { + text = 'Continue'; + } + const type = isAccountReady ? 'submit' : 'button' const onClick = isAccountReady ? (isOnCelo ? undefined : switchToNetwork) : openConnectModal