mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-12-19 10:38:03 -05:00
wip: WithdrawDialog migrated to Tauri IPC
This commit is contained in:
parent
92034a5be8
commit
47821cbe79
14 changed files with 185 additions and 166 deletions
|
|
@ -6,6 +6,7 @@ import { ReactNode, useEffect, useState } from "react";
|
|||
interface IpcInvokeButtonProps<T> {
|
||||
onSuccess?: (data: T) => void;
|
||||
onClick: () => Promise<T>;
|
||||
onPendingChange?: (bool) => void;
|
||||
isLoadingOverride?: boolean;
|
||||
isIconButton?: boolean;
|
||||
loadIcon?: ReactNode;
|
||||
|
|
@ -24,26 +25,22 @@ export default function PromiseInvokeButton<T>({
|
|||
isIconButton,
|
||||
displayErrorSnackbar,
|
||||
tooltipTitle,
|
||||
onPendingChange,
|
||||
...rest
|
||||
}: IpcInvokeButtonProps<T> & ButtonProps) {
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
const [hasMinLoadingTimePassed, setHasMinLoadingTimePassed] = useState(false);
|
||||
|
||||
const isLoading = (isPending && hasMinLoadingTimePassed) || isLoadingOverride;
|
||||
const isLoading = isPending || 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 {
|
||||
onPendingChange?.(true);
|
||||
setIsPending(true);
|
||||
let result = await onClick();
|
||||
onSuccess?.(result);
|
||||
|
|
@ -56,32 +53,23 @@ export default function PromiseInvokeButton<T>({
|
|||
}
|
||||
} finally {
|
||||
setIsPending(false);
|
||||
onPendingChange?.(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>
|
||||
return isIconButton ? (
|
||||
<IconButton onClick={handleClick} disabled={isDisabled} {...(rest as any)}>
|
||||
{actualEndIcon}
|
||||
</IconButton>
|
||||
) : (
|
||||
<Button
|
||||
onClick={handleClick}
|
||||
disabled={isDisabled}
|
||||
endIcon={actualEndIcon}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue