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,7 +303,10 @@ export default function Swap() { ...@@ -303,7 +303,10 @@ 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 () => {
setApprovalPending(true)
try {
if (signatureState === UseERC20PermitState.NOT_SIGNED && gatherPermitSignature) { if (signatureState === UseERC20PermitState.NOT_SIGNED && gatherPermitSignature) {
try { try {
await gatherPermitSignature() await gatherPermitSignature()
...@@ -322,6 +325,9 @@ export default function Swap() { ...@@ -322,6 +325,9 @@ export default function Swap() {
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])
// check if user has gone through approval process, used to show two step buttons, reset on token change // check if user has gone through approval process, used to show two step buttons, reset on token change
...@@ -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