mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-05-03 15:24:53 -04:00
refactor(gui): Make WithdrawDialog logic explicit
This commit is contained in:
parent
453c842d37
commit
b95b178dd8
1 changed files with 15 additions and 13 deletions
|
@ -19,6 +19,8 @@ export default function WithdrawDialog({
|
||||||
const [withdrawAddressValid, setWithdrawAddressValid] = useState(false);
|
const [withdrawAddressValid, setWithdrawAddressValid] = useState(false);
|
||||||
const [withdrawAddress, setWithdrawAddress] = useState<string>("");
|
const [withdrawAddress, setWithdrawAddress] = useState<string>("");
|
||||||
|
|
||||||
|
const haveFundsBeenWithdrawn = withdrawTxId !== null;
|
||||||
|
|
||||||
function onCancel() {
|
function onCancel() {
|
||||||
if (!pending) {
|
if (!pending) {
|
||||||
setWithdrawTxId(null);
|
setWithdrawTxId(null);
|
||||||
|
@ -31,34 +33,34 @@ export default function WithdrawDialog({
|
||||||
<Dialog open={open} onClose={onCancel} maxWidth="sm" fullWidth>
|
<Dialog open={open} onClose={onCancel} maxWidth="sm" fullWidth>
|
||||||
<DialogHeader title="Withdraw Bitcoin" />
|
<DialogHeader title="Withdraw Bitcoin" />
|
||||||
<WithdrawDialogContent isPending={pending} withdrawTxId={withdrawTxId}>
|
<WithdrawDialogContent isPending={pending} withdrawTxId={withdrawTxId}>
|
||||||
{withdrawTxId === null ? (
|
{haveFundsBeenWithdrawn ? (
|
||||||
|
<BtcTxInMempoolPageContent withdrawTxId={withdrawTxId} />
|
||||||
|
) : (
|
||||||
<AddressInputPage
|
<AddressInputPage
|
||||||
setWithdrawAddress={setWithdrawAddress}
|
setWithdrawAddress={setWithdrawAddress}
|
||||||
withdrawAddress={withdrawAddress}
|
withdrawAddress={withdrawAddress}
|
||||||
setWithdrawAddressValid={setWithdrawAddressValid}
|
setWithdrawAddressValid={setWithdrawAddressValid}
|
||||||
/>
|
/>
|
||||||
) : (
|
|
||||||
<BtcTxInMempoolPageContent withdrawTxId={withdrawTxId} />
|
|
||||||
)}
|
)}
|
||||||
</WithdrawDialogContent>
|
</WithdrawDialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={onCancel} color="primary" disabled={pending}>
|
<Button
|
||||||
{withdrawTxId === null ? "Cancel" : "Done"}
|
onClick={onCancel}
|
||||||
|
color="primary"
|
||||||
|
disabled={pending}
|
||||||
|
variant={haveFundsBeenWithdrawn ? "contained" : "text"}
|
||||||
|
>
|
||||||
|
{haveFundsBeenWithdrawn ? "Done" : "Close"}
|
||||||
</Button>
|
</Button>
|
||||||
{withdrawTxId === null && (
|
{!haveFundsBeenWithdrawn && (
|
||||||
<PromiseInvokeButton
|
<PromiseInvokeButton
|
||||||
displayErrorSnackbar
|
displayErrorSnackbar
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
disabled={!withdrawAddressValid}
|
disabled={!withdrawAddressValid}
|
||||||
onInvoke={() => withdrawBtc(withdrawAddress)}
|
onInvoke={() => withdrawBtc(withdrawAddress)}
|
||||||
onPendingChange={(pending) => {
|
onPendingChange={setPending}
|
||||||
console.log("pending", pending);
|
onSuccess={setWithdrawTxId}
|
||||||
setPending(pending);
|
|
||||||
}}
|
|
||||||
onSuccess={(txId) => {
|
|
||||||
setWithdrawTxId(txId);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
Withdraw
|
Withdraw
|
||||||
</PromiseInvokeButton>
|
</PromiseInvokeButton>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue