mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-07 05:52:31 -04:00
feat(gui, swap): allow change-address to be omitted and default to internal wallet (#68)
This PR: - allows --change-address to be omitted and default to internal wallet address (https://github.com/comit-network/xmr-btc-swap/pull/1709). This is a change that is merged from upstream into our fork - adds the necessary components for the tauri integration and the ui components to allow toggling between internal vs external refund address Co-authored-by: binarybaron <86064887+binarybaron@users.noreply.github.com> Co-authored-by: Einliterflasche <81313171+Einliterflasche@users.noreply.github.com> Co-authored-by: Byron Hambly <byron@hambly.dev>
This commit is contained in:
parent
91482f1e16
commit
063f9dbf9b
8 changed files with 118 additions and 50 deletions
|
@ -1,4 +1,11 @@
|
|||
import { Box, DialogContentText, makeStyles } from "@material-ui/core";
|
||||
import {
|
||||
Box,
|
||||
makeStyles,
|
||||
Paper,
|
||||
Tab,
|
||||
Tabs,
|
||||
Typography,
|
||||
} from "@material-ui/core";
|
||||
import PlayArrowIcon from "@material-ui/icons/PlayArrow";
|
||||
import { useState } from "react";
|
||||
import BitcoinAddressTextField from "renderer/components/inputs/BitcoinAddressTextField";
|
||||
|
@ -21,61 +28,90 @@ const useStyles = makeStyles((theme) => ({
|
|||
|
||||
export default function InitPage() {
|
||||
const classes = useStyles();
|
||||
|
||||
const [redeemAddress, setRedeemAddress] = useState("");
|
||||
const [refundAddress, setRefundAddress] = useState("");
|
||||
const [useExternalRefundAddress, setUseExternalRefundAddress] =
|
||||
useState(false);
|
||||
|
||||
const [redeemAddressValid, setRedeemAddressValid] = useState(false);
|
||||
const [refundAddressValid, setRefundAddressValid] = useState(false);
|
||||
|
||||
const selectedProvider = useAppSelector(
|
||||
(state) => state.providers.selectedProvider,
|
||||
);
|
||||
|
||||
async function init() {
|
||||
await buyXmr(selectedProvider, refundAddress, redeemAddress);
|
||||
await buyXmr(
|
||||
selectedProvider,
|
||||
useExternalRefundAddress ? refundAddress : null,
|
||||
redeemAddress,
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<RemainingFundsWillBeUsedAlert />
|
||||
<DialogContentText>
|
||||
Please specify the address to which the Monero should be sent upon
|
||||
completion of the swap and the address for receiving a Bitcoin refund if
|
||||
the swap fails.
|
||||
</DialogContentText>
|
||||
|
||||
<Box className={classes.fieldsOuter}>
|
||||
<MoneroAddressTextField
|
||||
label="Monero redeem address"
|
||||
address={redeemAddress}
|
||||
onAddressChange={setRedeemAddress}
|
||||
onAddressValidityChange={setRedeemAddressValid}
|
||||
helperText="The monero will be sent to this address"
|
||||
helperText="The monero will be sent to this address if the swap is successful."
|
||||
fullWidth
|
||||
/>
|
||||
|
||||
<BitcoinAddressTextField
|
||||
label="Bitcoin refund address"
|
||||
address={refundAddress}
|
||||
onAddressChange={setRefundAddress}
|
||||
onAddressValidityChange={setRefundAddressValid}
|
||||
helperText="In case something goes terribly wrong, all Bitcoin will be refunded to this address"
|
||||
fullWidth
|
||||
/>
|
||||
<Paper variant="outlined" style={{}}>
|
||||
<Tabs
|
||||
value={useExternalRefundAddress ? 1 : 0}
|
||||
indicatorColor="primary"
|
||||
variant="fullWidth"
|
||||
onChange={(_, newValue) =>
|
||||
setUseExternalRefundAddress(newValue === 1)
|
||||
}
|
||||
>
|
||||
<Tab label="Refund to internal Bitcoin wallet" value={0} />
|
||||
<Tab label="Refund to external Bitcoin address" value={1} />
|
||||
</Tabs>
|
||||
<Box style={{ padding: "16px" }}>
|
||||
{useExternalRefundAddress ? (
|
||||
<BitcoinAddressTextField
|
||||
label="External Bitcoin refund address"
|
||||
address={refundAddress}
|
||||
onAddressChange={setRefundAddress}
|
||||
onAddressValidityChange={setRefundAddressValid}
|
||||
helperText="In case something goes wrong, the Bitcoin will be refunded to this address."
|
||||
fullWidth
|
||||
/>
|
||||
) : (
|
||||
<Typography variant="caption">
|
||||
In case something goes wrong, the Bitcoin will be refunded to
|
||||
the internal Bitcoin wallet of the GUI. You can then withdraw
|
||||
them from there or use them for another swap directly.
|
||||
</Typography>
|
||||
)}
|
||||
</Box>
|
||||
</Paper>
|
||||
</Box>
|
||||
<Box style={{ display: "flex", justifyContent: "center" }}>
|
||||
<PromiseInvokeButton
|
||||
disabled={
|
||||
(!refundAddressValid && useExternalRefundAddress) ||
|
||||
!redeemAddressValid ||
|
||||
!selectedProvider
|
||||
}
|
||||
variant="contained"
|
||||
color="primary"
|
||||
size="large"
|
||||
className={classes.initButton}
|
||||
endIcon={<PlayArrowIcon />}
|
||||
onInvoke={init}
|
||||
displayErrorSnackbar
|
||||
>
|
||||
Request quote and start swap
|
||||
</PromiseInvokeButton>
|
||||
</Box>
|
||||
|
||||
<PromiseInvokeButton
|
||||
disabled={
|
||||
!refundAddressValid || !redeemAddressValid || !selectedProvider
|
||||
}
|
||||
variant="contained"
|
||||
color="primary"
|
||||
size="large"
|
||||
className={classes.initButton}
|
||||
endIcon={<PlayArrowIcon />}
|
||||
onInvoke={init}
|
||||
displayErrorSnackbar
|
||||
>
|
||||
Start swap
|
||||
</PromiseInvokeButton>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -89,14 +89,22 @@ export async function withdrawBtc(address: string): Promise<string> {
|
|||
|
||||
export async function buyXmr(
|
||||
seller: Provider,
|
||||
bitcoin_change_address: string,
|
||||
bitcoin_change_address: string | null,
|
||||
monero_receive_address: string,
|
||||
) {
|
||||
await invoke<BuyXmrArgs, BuyXmrResponse>("buy_xmr", {
|
||||
seller: providerToConcatenatedMultiAddr(seller),
|
||||
bitcoin_change_address,
|
||||
monero_receive_address,
|
||||
});
|
||||
await invoke<BuyXmrArgs, BuyXmrResponse>(
|
||||
"buy_xmr",
|
||||
bitcoin_change_address == null
|
||||
? {
|
||||
seller: providerToConcatenatedMultiAddr(seller),
|
||||
monero_receive_address,
|
||||
}
|
||||
: {
|
||||
seller: providerToConcatenatedMultiAddr(seller),
|
||||
monero_receive_address,
|
||||
bitcoin_change_address,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export async function resumeSwap(swapId: string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue