/
Dialogs.tsx
71 lines (64 loc) · 1.71 KB
/
Dialogs.tsx
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
62
63
64
65
66
67
68
69
70
71
import { logError } from '@metamask/snaps-utils';
import { FunctionComponent } from 'react';
import { Button, ButtonGroup } from 'react-bootstrap';
import { useInvokeMutation } from '../../../api';
import { Result, Snap } from '../../../components';
import { getSnapId } from '../../../utils';
import { DIALOGS_SNAP_ID, DIALOGS_SNAP_PORT } from './constants';
export const Dialogs: FunctionComponent = () => {
const [invokeSnap, { isLoading, data }] = useInvokeMutation();
const snapId = getSnapId(DIALOGS_SNAP_ID, DIALOGS_SNAP_PORT);
const handleSubmitAlert = () => {
invokeSnap({
snapId,
method: 'showAlert',
}).catch(logError);
};
const handleSubmitConfirmation = () => {
invokeSnap({
snapId,
method: 'showConfirmation',
}).catch(logError);
};
const handleSubmitPrompt = () => {
invokeSnap({
snapId,
method: 'showPrompt',
}).catch(logError);
};
return (
<Snap
name="Dialogs Snap"
snapId={DIALOGS_SNAP_ID}
port={DIALOGS_SNAP_PORT}
testId="dialogs"
>
<ButtonGroup className="mb-3">
<Button
id="sendAlertButton"
onClick={handleSubmitAlert}
disabled={isLoading}
>
Alert
</Button>
<Button
id="sendConfirmationButton"
onClick={handleSubmitConfirmation}
disabled={isLoading}
>
Confirmation
</Button>
<Button
id="sendPromptButton"
onClick={handleSubmitPrompt}
disabled={isLoading}
>
Prompt
</Button>
</ButtonGroup>
<Result>
<span id="dialogResult">{JSON.stringify(data, null, 2)}</span>
</Result>
</Snap>
);
};