mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-07-29 17:48:43 -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 RefreshIcon from '@material-ui/icons/Refresh';
|
||||
import IpcInvokeButton from '../../IpcInvokeButton';
|
||||
import { checkBitcoinBalance } from 'renderer/rpc';
|
||||
import { Button, CircularProgress, IconButton } from "@material-ui/core";
|
||||
import RefreshIcon from "@material-ui/icons/Refresh";
|
||||
import IpcInvokeButton from "../../IpcInvokeButton";
|
||||
import { checkBitcoinBalance } from "renderer/rpc";
|
||||
import PromiseInvokeButton from "renderer/components/PromiseInvokeButton";
|
||||
|
||||
export default function WalletRefreshButton() {
|
||||
return <IconButton onClick={() => checkBitcoinBalance(true)}>
|
||||
<RefreshIcon />
|
||||
</IconButton>
|
||||
return (
|
||||
<PromiseInvokeButton
|
||||
endIcon={<RefreshIcon />}
|
||||
isIconButton
|
||||
onClick={() => checkBitcoinBalance()}
|
||||
size="small"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue