-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnotificationsContainer.tsx
77 lines (66 loc) · 2.06 KB
/
notificationsContainer.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
72
73
74
75
76
77
import { CustomNotificationObject, UpdateNotification } from "bnc-notify";
import { List } from "immutable";
import { useEffect, useState } from "react";
import { createContainer } from "unstated-next";
import { Web3Container } from "./web3Container";
const useNotificationsContainer = () => {
const { notify } = Web3Container.useContainer();
const [notifications, setNotifications] = useState(
List<CustomNotificationObject>(),
);
// Process notification queue.
useEffect(() => {
if (!notify) {
return;
}
setNotifications(List());
notifications.forEach((notification) =>
notify.notification(notification),
);
}, [notify, notifications]);
const showSuccess = (message: string, autoDismiss?: number) =>
notify?.notification({
type: "success",
message,
autoDismiss,
}) || {
dismiss: () => {},
update: ((..._: any[]) => {}) as UpdateNotification,
};
const showError = (message: string, autoDismiss?: number) =>
notify?.notification({
type: "error",
message,
autoDismiss,
}) || {
dismiss: () => {},
update: ((..._: any[]) => {}) as UpdateNotification,
};
const showHint = (message: string, autoDismiss?: number) =>
notify?.notification({
type: "hint",
message,
autoDismiss,
}) || {
dismiss: () => {},
update: ((..._: any[]) => {}) as UpdateNotification,
};
const showPending = (message: string, autoDismiss?: number) =>
notify?.notification({
type: "pending",
message,
autoDismiss,
}) || {
dismiss: () => {},
update: ((..._: any[]) => {}) as UpdateNotification,
};
return {
showSuccess,
showError,
showHint,
showPending,
};
};
export const NotificationsContainer = createContainer(
useNotificationsContainer,
);