mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-06-20 04:44:10 -04:00
chore: Add description to Cargo.toml for GUI
This commit is contained in:
parent
8cb1e8aff0
commit
630f4c6f23
5 changed files with 109 additions and 17 deletions
87
src-gui/src/renderer/components/PromiseInvokeButton.tsx
Normal file
87
src-gui/src/renderer/components/PromiseInvokeButton.tsx
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
import { Button, ButtonProps, IconButton, Tooltip } from "@material-ui/core";
|
||||||
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
|
import { useSnackbar } from "notistack";
|
||||||
|
import { ReactNode, useEffect, useState } from "react";
|
||||||
|
|
||||||
|
interface IpcInvokeButtonProps<T> {
|
||||||
|
onSuccess?: (data: T) => void;
|
||||||
|
onClick: () => Promise<T>;
|
||||||
|
isLoadingOverride?: boolean;
|
||||||
|
isIconButton?: boolean;
|
||||||
|
loadIcon?: ReactNode;
|
||||||
|
disabled?: boolean;
|
||||||
|
displayErrorSnackbar?: boolean;
|
||||||
|
tooltipTitle?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function PromiseInvokeButton<T>({
|
||||||
|
disabled,
|
||||||
|
onSuccess,
|
||||||
|
onClick,
|
||||||
|
endIcon,
|
||||||
|
loadIcon,
|
||||||
|
isLoadingOverride,
|
||||||
|
isIconButton,
|
||||||
|
displayErrorSnackbar,
|
||||||
|
tooltipTitle,
|
||||||
|
...rest
|
||||||
|
}: IpcInvokeButtonProps<T> & ButtonProps) {
|
||||||
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
|
const [isPending, setIsPending] = useState(false);
|
||||||
|
const [hasMinLoadingTimePassed, setHasMinLoadingTimePassed] = useState(false);
|
||||||
|
|
||||||
|
const isLoading = (isPending && hasMinLoadingTimePassed) || isLoadingOverride;
|
||||||
|
const actualEndIcon = isLoading
|
||||||
|
? loadIcon || <CircularProgress size="1em" />
|
||||||
|
: endIcon;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setHasMinLoadingTimePassed(false);
|
||||||
|
setTimeout(() => setHasMinLoadingTimePassed(true), 100);
|
||||||
|
}, [isPending]);
|
||||||
|
|
||||||
|
async function handleClick(event: React.MouseEvent<HTMLButtonElement>) {
|
||||||
|
if (!isPending) {
|
||||||
|
try {
|
||||||
|
setIsPending(true);
|
||||||
|
let result = await onClick();
|
||||||
|
onSuccess?.(result);
|
||||||
|
} catch (e: unknown) {
|
||||||
|
if (displayErrorSnackbar) {
|
||||||
|
enqueueSnackbar((e as Error).message, {
|
||||||
|
autoHideDuration: 60 * 1000,
|
||||||
|
variant: "error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setIsPending(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const isDisabled = disabled || isLoading;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip title={tooltipTitle}>
|
||||||
|
<span>
|
||||||
|
{isIconButton ? (
|
||||||
|
<IconButton
|
||||||
|
onClick={handleClick}
|
||||||
|
disabled={isDisabled}
|
||||||
|
{...(rest as any)}
|
||||||
|
>
|
||||||
|
{actualEndIcon}
|
||||||
|
</IconButton>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
onClick={handleClick}
|
||||||
|
disabled={isDisabled}
|
||||||
|
endIcon={actualEndIcon}
|
||||||
|
{...rest}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,10 +1,16 @@
|
||||||
import { Button, CircularProgress, IconButton } from '@material-ui/core';
|
import { Button, CircularProgress, IconButton } from "@material-ui/core";
|
||||||
import RefreshIcon from '@material-ui/icons/Refresh';
|
import RefreshIcon from "@material-ui/icons/Refresh";
|
||||||
import IpcInvokeButton from '../../IpcInvokeButton';
|
import IpcInvokeButton from "../../IpcInvokeButton";
|
||||||
import { checkBitcoinBalance } from 'renderer/rpc';
|
import { checkBitcoinBalance } from "renderer/rpc";
|
||||||
|
import PromiseInvokeButton from "renderer/components/PromiseInvokeButton";
|
||||||
|
|
||||||
export default function WalletRefreshButton() {
|
export default function WalletRefreshButton() {
|
||||||
return <IconButton onClick={() => checkBitcoinBalance(true)}>
|
return (
|
||||||
<RefreshIcon />
|
<PromiseInvokeButton
|
||||||
</IconButton>
|
endIcon={<RefreshIcon />}
|
||||||
|
isIconButton
|
||||||
|
onClick={() => checkBitcoinBalance()}
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ authors = [ "binarybaron", "einliterflasche", "unstoppableswap" ]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
description = "A Tauri App"
|
description = "GUI for XMR<>BTC Atomic Swaps written in Rust"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "unstoppableswap_gui_rs_lib"
|
name = "unstoppableswap_gui_rs_lib"
|
||||||
|
|
|
@ -77,6 +77,7 @@ fn setup<'a>(app: &'a mut tauri::App) -> Result<(), Box<dyn std::error::Error>>
|
||||||
.set(Arc::new(context))
|
.set(Arc::new(context))
|
||||||
.expect("Failed to initialize cli context");
|
.expect("Failed to initialize cli context");
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,8 @@
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use crate::{
|
use crate::cli::command::{parse_args_and_apply_defaults, ParseResult};
|
||||||
cli::command::{parse_args_and_apply_defaults, ParseResult},
|
use crate::common::check_latest_version;
|
||||||
common::check_latest_version,
|
|
||||||
};
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue