Skip to content

Commit

Permalink
refactor: improve error text logic readability
Browse files Browse the repository at this point in the history
  • Loading branch information
denviljclarke committed Sep 8, 2023
1 parent 39b122f commit e9f8fb2
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/features/swap/SwapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ function SubmitButton() {
const { switchNetworkAsync } = useSwitchNetwork()
const { openConnectModal } = useConnectModal()
const dispatch = useAppDispatch()
const { errors, touched } = useFormikContext<SwapFormValues>()

const isAccountReady = address && isConnected
const isOnCelo = chains.some((chn) => chn.id === chain?.id)
Expand All @@ -292,17 +293,20 @@ function SubmitButton() {
}
}

const { errors, touched } = useFormikContext<SwapFormValues>()
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

Expand Down

0 comments on commit e9f8fb2

Please sign in to comment.