mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-24 09:53:09 -05:00
feat(gui): Redeem to internal Monero wallet (#448)
* fmt * remove old stuff * refactor
This commit is contained in:
parent
293ff2cdf3
commit
7b67dce140
21 changed files with 160 additions and 127 deletions
|
|
@ -1,65 +0,0 @@
|
|||
import { Box, Dialog, DialogActions, DialogContent } from "@mui/material";
|
||||
import { useState } from "react";
|
||||
import { useAppSelector } from "store/hooks";
|
||||
import DebugPage from "./pages/DebugPage";
|
||||
import SwapStatePage from "renderer/components/pages/swap/swap/SwapStatePage";
|
||||
import SwapDialogTitle from "./SwapDialogTitle";
|
||||
import SwapStateStepper from "./SwapStateStepper";
|
||||
import CancelButton from "renderer/components/pages/swap/swap/CancelButton";
|
||||
|
||||
export default function SwapDialog({
|
||||
open,
|
||||
onClose,
|
||||
}: {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const swap = useAppSelector((state) => state.swap);
|
||||
const [debug, setDebug] = useState(false);
|
||||
|
||||
// This prevents an issue where the Dialog is shown for a split second without a present swap state
|
||||
if (!open) return null;
|
||||
|
||||
return (
|
||||
<Dialog open={open} onClose={onClose} maxWidth="md" fullWidth>
|
||||
<SwapDialogTitle
|
||||
debug={debug}
|
||||
setDebug={setDebug}
|
||||
title="Swap Bitcoin for Monero"
|
||||
/>
|
||||
|
||||
<DialogContent
|
||||
dividers
|
||||
sx={{
|
||||
minHeight: "25rem",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
justifyContent: "space-between",
|
||||
flex: 1,
|
||||
gap: "1rem",
|
||||
}}
|
||||
>
|
||||
{debug ? (
|
||||
<DebugPage />
|
||||
) : (
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: 2,
|
||||
justifyContent: "space-between",
|
||||
flex: 1,
|
||||
}}
|
||||
>
|
||||
<SwapStatePage state={swap.state} />
|
||||
<SwapStateStepper state={swap.state} />
|
||||
</Box>
|
||||
)}
|
||||
</DialogContent>
|
||||
|
||||
<DialogActions>
|
||||
<CancelButton />
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
@ -9,14 +9,16 @@ export default function TruncatedText({
|
|||
ellipsis?: string;
|
||||
truncateMiddle?: boolean;
|
||||
}) {
|
||||
let finalChildren = children ?? "";
|
||||
|
||||
const truncatedText =
|
||||
children.length > limit
|
||||
finalChildren.length > limit
|
||||
? truncateMiddle
|
||||
? children.slice(0, Math.floor(limit / 2)) +
|
||||
? finalChildren.slice(0, Math.floor(limit / 2)) +
|
||||
ellipsis +
|
||||
children.slice(children.length - Math.floor(limit / 2))
|
||||
: children.slice(0, limit) + ellipsis
|
||||
: children;
|
||||
finalChildren.slice(finalChildren.length - Math.floor(limit / 2))
|
||||
: finalChildren.slice(0, limit) + ellipsis
|
||||
: finalChildren;
|
||||
|
||||
return <span>{truncatedText}</span>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import { Box, DialogContentText } from "@mui/material";
|
|||
import { TauriSwapProgressEventContent } from "models/tauriModelExt";
|
||||
import { formatConfirmations } from "utils/formatUtils";
|
||||
import MoneroTransactionInfoBox from "../components/MoneroTransactionInfoBox";
|
||||
import CancelButton from "../CancelButton";
|
||||
|
||||
export default function XmrLockTxInMempoolPage({
|
||||
xmr_lock_tx_confirmations,
|
||||
|
|
@ -24,8 +23,6 @@ export default function XmrLockTxInMempoolPage({
|
|||
additionalContent={additionalContent}
|
||||
loading
|
||||
/>
|
||||
|
||||
<CancelButton />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ export default function InitPage() {
|
|||
const [refundAddress, setRefundAddress] = useState("");
|
||||
const [useExternalRefundAddress, setUseExternalRefundAddress] =
|
||||
useState(false);
|
||||
const [useExternalRedeemAddress, setUseExternalRedeemAddress] =
|
||||
useState(false);
|
||||
|
||||
const [redeemAddressValid, setRedeemAddressValid] = useState(false);
|
||||
const [refundAddressValid, setRefundAddressValid] = useState(false);
|
||||
|
|
@ -21,7 +23,7 @@ export default function InitPage() {
|
|||
async function init() {
|
||||
await buyXmr(
|
||||
useExternalRefundAddress ? refundAddress : null,
|
||||
redeemAddress,
|
||||
useExternalRedeemAddress ? redeemAddress : null,
|
||||
donationRatio,
|
||||
);
|
||||
}
|
||||
|
|
@ -35,14 +37,36 @@ export default function InitPage() {
|
|||
gap: 1.5,
|
||||
}}
|
||||
>
|
||||
<MoneroAddressTextField
|
||||
label="Monero redeem address"
|
||||
address={redeemAddress}
|
||||
onAddressChange={setRedeemAddress}
|
||||
onAddressValidityChange={setRedeemAddressValid}
|
||||
helperText="The monero will be sent to this address if the swap is successful."
|
||||
fullWidth
|
||||
/>
|
||||
<Paper variant="outlined" style={{}}>
|
||||
<Tabs
|
||||
value={useExternalRedeemAddress ? 1 : 0}
|
||||
indicatorColor="primary"
|
||||
variant="fullWidth"
|
||||
onChange={(_, newValue) =>
|
||||
setUseExternalRedeemAddress(newValue === 1)
|
||||
}
|
||||
>
|
||||
<Tab label="Redeem to internal Monero wallet" value={0} />
|
||||
<Tab label="Redeem to external Monero address" value={1} />
|
||||
</Tabs>
|
||||
<Box style={{ padding: "16px" }}>
|
||||
{useExternalRedeemAddress ? (
|
||||
<MoneroAddressTextField
|
||||
label="External Monero redeem address"
|
||||
address={redeemAddress}
|
||||
onAddressChange={setRedeemAddress}
|
||||
onAddressValidityChange={setRedeemAddressValid}
|
||||
helperText="The monero will be sent to this address if the swap is successful."
|
||||
fullWidth
|
||||
/>
|
||||
) : (
|
||||
<Typography variant="caption">
|
||||
The Monero will be sent to the internal Monero wallet of the GUI.
|
||||
You can then withdraw them from there or use them for another swap directly.
|
||||
</Typography>
|
||||
)}
|
||||
</Box>
|
||||
</Paper>
|
||||
|
||||
<Paper variant="outlined" style={{}}>
|
||||
<Tabs
|
||||
|
|
@ -80,7 +104,7 @@ export default function InitPage() {
|
|||
<PromiseInvokeButton
|
||||
disabled={
|
||||
(!refundAddressValid && useExternalRefundAddress) ||
|
||||
!redeemAddressValid
|
||||
(!redeemAddressValid && useExternalRedeemAddress)
|
||||
}
|
||||
variant="contained"
|
||||
color="primary"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue