Skip to content

Commit eec4f4f

Browse files
committed
feat: disable continue button on submit to avoid rage clicking
1 parent 0510a3f commit eec4f4f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/features/swap/components/SubmitButton.tsx

+8-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function SubmitButton({ isWalletConnected, isBalanceLoaded }: ISubmitButt
2222
const { switchNetworkAsync } = useSwitchNetwork()
2323
const { openConnectModal } = useConnectModal()
2424
const dispatch = useAppDispatch()
25-
const { errors, touched, values } = useFormikContext<SwapFormValues>()
25+
const { errors, touched, values, isSubmitting } = useFormikContext<SwapFormValues>()
2626

2727
const switchToNetwork = useCallback(async () => {
2828
try {
@@ -93,10 +93,12 @@ export function SubmitButton({ isWalletConnected, isBalanceLoaded }: ISubmitButt
9393
return undefined
9494
}, [isWalletConnected, isOnCelo, openConnectModal, switchToNetwork])
9595

96-
const isDisabled =
97-
buttonText === Button3DText.balanceStillLoading
98-
? isWalletConnected && !hasError
99-
: isWalletConnected && !Number(values.quote) && !hasError
96+
const isDisabled = useMemo(() => {
97+
if (!isWalletConnected || hasError) return false
98+
if (buttonText === Button3DText.balanceStillLoading) return true
99+
if (isSubmitting) return true
100+
return !Number(values.quote)
101+
}, [isWalletConnected, hasError, buttonText, values.quote, isSubmitting])
100102

101103
return (
102104
<div className="flex flex-col items-center justify-center w-full">
@@ -109,7 +111,7 @@ export function SubmitButton({ isWalletConnected, isBalanceLoaded }: ISubmitButt
109111
isWalletConnected={isWalletConnected}
110112
isBalanceLoaded={isBalanceLoaded}
111113
>
112-
{buttonText}
114+
{isSubmitting ? 'Loading...' : buttonText}
113115
</Button3D>
114116
</div>
115117
)

0 commit comments

Comments
 (0)