-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransactionDialog.tsx
More file actions
61 lines (56 loc) · 1.63 KB
/
TransactionDialog.tsx
File metadata and controls
61 lines (56 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { txStore } from '@/lib/transactions/store';
import clsx from 'clsx';
import { Loader2Icon } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { useStoreWithEqualityFn } from 'zustand/traditional';
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from '../ui/dialog';
import { TxList } from './TxList';
export const TransactionDialogProvider = () => {
const { t } = useTranslation('tx');
const [isOpen, isReady] = useStoreWithEqualityFn(
txStore,
(state) => [state.isFetching || state.isReady, state.isReady] as const,
);
const onClose = (open: boolean) => {
if (!open) {
txStore.getState().reset();
}
};
const handleEscapes = (e: Event) => {
if (!isReady) {
txStore.getState().reset();
return;
}
e.preventDefault();
};
return (
<Dialog open={isOpen} onOpenChange={onClose}>
<DialogContent
className={clsx(!isReady && 'w-64 h-64')}
onInteractOutside={handleEscapes}
onEscapeKeyDown={handleEscapes}
>
{isReady ? (
<TxList />
) : (
<>
<DialogHeader className="sr-only">
<DialogTitle>{t(($) => $.title)}</DialogTitle>
<DialogDescription>{t(($) => $.description)}</DialogDescription>
</DialogHeader>
<div className="flex flex-col justify-center items-center gap-4">
<Loader2Icon className="mr-2 animate-spin" size={48} />
<p className="text-sm">{t(($) => $.preparing)}</p>
</div>
</>
)}
</DialogContent>
</Dialog>
);
};