Commit 888f02db authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: approval pending ux (#4693)

* fix: approval button colors

* feat: show spinner while pending wallet interaction

* fix: constant allow button height
parent 728a5653
...@@ -16,6 +16,7 @@ const PopoverContainer = styled.div<{ show: boolean }>` ...@@ -16,6 +16,7 @@ const PopoverContainer = styled.div<{ show: boolean }>`
const ReferenceElement = styled.div` const ReferenceElement = styled.div`
display: inline-block; display: inline-block;
height: inherit;
` `
const Arrow = styled.div` const Arrow = styled.div`
......
...@@ -303,24 +303,30 @@ export default function Swap() { ...@@ -303,24 +303,30 @@ export default function Swap() {
gatherPermitSignature, gatherPermitSignature,
} = useERC20PermitFromTrade(trade, allowedSlippage, transactionDeadline) } = useERC20PermitFromTrade(trade, allowedSlippage, transactionDeadline)
const [approvalPending, setApprovalPending] = useState<boolean>(false)
const handleApprove = useCallback(async () => { const handleApprove = useCallback(async () => {
if (signatureState === UseERC20PermitState.NOT_SIGNED && gatherPermitSignature) { setApprovalPending(true)
try { try {
await gatherPermitSignature() if (signatureState === UseERC20PermitState.NOT_SIGNED && gatherPermitSignature) {
} catch (error) { try {
// try to approve if gatherPermitSignature failed for any reason other than the user rejecting it await gatherPermitSignature()
if (error?.code !== 4001) { } catch (error) {
await approveCallback() // try to approve if gatherPermitSignature failed for any reason other than the user rejecting it
if (error?.code !== 4001) {
await approveCallback()
}
} }
} } else {
} else { await approveCallback()
await approveCallback()
sendEvent({ sendEvent({
category: 'Swap', category: 'Swap',
action: 'Approve', action: 'Approve',
label: [TRADE_STRING, trade?.inputAmount?.currency.symbol].join('/'), label: [TRADE_STRING, trade?.inputAmount?.currency.symbol].join('/'),
}) })
}
} finally {
setApprovalPending(false)
} }
}, [signatureState, gatherPermitSignature, approveCallback, trade?.inputAmount?.currency.symbol]) }, [signatureState, gatherPermitSignature, approveCallback, trade?.inputAmount?.currency.symbol])
...@@ -696,7 +702,7 @@ export default function Swap() { ...@@ -696,7 +702,7 @@ export default function Swap() {
approvalState === ApprovalState.APPROVED || signatureState === UseERC20PermitState.SIGNED approvalState === ApprovalState.APPROVED || signatureState === UseERC20PermitState.SIGNED
} }
> >
<AutoRow justify="space-between" style={{ flexWrap: 'nowrap' }}> <AutoRow justify="space-between" style={{ flexWrap: 'nowrap' }} height="20px">
<span style={{ display: 'flex', alignItems: 'center' }}> <span style={{ display: 'flex', alignItems: 'center' }}>
{/* we need to shorten this string on mobile */} {/* we need to shorten this string on mobile */}
{approvalState === ApprovalState.APPROVED || {approvalState === ApprovalState.APPROVED ||
...@@ -708,8 +714,8 @@ export default function Swap() { ...@@ -708,8 +714,8 @@ export default function Swap() {
</Trans> </Trans>
)} )}
</span> </span>
{approvalState === ApprovalState.PENDING ? ( {approvalPending || approvalState === ApprovalState.PENDING ? (
<Loader stroke="white" /> <Loader stroke={theme.white} />
) : (approvalSubmitted && approvalState === ApprovalState.APPROVED) || ) : (approvalSubmitted && approvalState === ApprovalState.APPROVED) ||
signatureState === UseERC20PermitState.SIGNED ? ( signatureState === UseERC20PermitState.SIGNED ? (
<CheckCircle size="20" color={theme.deprecated_green1} /> <CheckCircle size="20" color={theme.deprecated_green1} />
...@@ -722,7 +728,7 @@ export default function Swap() { ...@@ -722,7 +728,7 @@ export default function Swap() {
</Trans> </Trans>
} }
> >
<HelpCircle size="20" color={'deprecated_white'} style={{ marginLeft: '8px' }} /> <HelpCircle size="20" color={theme.deprecated_white} style={{ marginLeft: '8px' }} />
</MouseoverTooltip> </MouseoverTooltip>
)} )}
</AutoRow> </AutoRow>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment