Commit cee4b8c7 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: disable swap button w/o account (#3177)

* fix: disable swap button w/o account

* nit: indent less
parent 3153db9f
...@@ -15,7 +15,10 @@ enum Mode { ...@@ -15,7 +15,10 @@ enum Mode {
STATUS, STATUS,
} }
export default function SwapButton() { interface SwapButtonProps {
disabled?: boolean
}
export default function SwapButton({ disabled }: SwapButtonProps) {
const [mode, setMode] = useState(Mode.SWAP) const [mode, setMode] = useState(Mode.SWAP)
const { const {
trade, trade,
...@@ -30,8 +33,12 @@ export default function SwapButton() { ...@@ -30,8 +33,12 @@ export default function SwapButton() {
// TODO(zzmp): Pass optimized trade to SummaryDialog // TODO(zzmp): Pass optimized trade to SummaryDialog
const actionProps = useMemo(() => { const actionProps = useMemo(() => {
if (disabled) return { disabled: true }
if (inputCurrencyAmount && inputCurrencyBalance?.greaterThan(inputCurrencyAmount)) { if (inputCurrencyAmount && inputCurrencyBalance?.greaterThan(inputCurrencyAmount)) {
if (approval === ApprovalState.NOT_APPROVED) { if (approval === ApprovalState.PENDING) {
return { disabled: true }
} else if (approval === ApprovalState.NOT_APPROVED) {
return { return {
updated: { updated: {
message: <Trans>Approve {inputCurrencyAmount.currency.symbol} first</Trans>, message: <Trans>Approve {inputCurrencyAmount.currency.symbol} first</Trans>,
...@@ -39,13 +46,11 @@ export default function SwapButton() { ...@@ -39,13 +46,11 @@ export default function SwapButton() {
}, },
} }
} }
if (approval === ApprovalState.PENDING) {
return { disabled: true }
}
return {} return {}
} }
return { disabled: true } return { disabled: true }
}, [approval, inputCurrencyAmount, inputCurrencyBalance]) }, [disabled, approval, inputCurrencyAmount, inputCurrencyBalance])
const onConfirm = useCallback(() => { const onConfirm = useCallback(() => {
// TODO: Send the tx to the connected wallet. // TODO: Send the tx to the connected wallet.
setMode(Mode.STATUS) setMode(Mode.STATUS)
......
...@@ -81,7 +81,7 @@ export default function Swap({ defaults }: SwapProps) { ...@@ -81,7 +81,7 @@ export default function Swap({ defaults }: SwapProps) {
<ReverseButton disabled={!active} /> <ReverseButton disabled={!active} />
<Output disabled={!active}> <Output disabled={!active}>
<Toolbar disabled={!active} /> <Toolbar disabled={!active} />
<SwapButton /> <SwapButton disabled={!account} />
</Output> </Output>
</BoundaryProvider> </BoundaryProvider>
</div> </div>
......
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