forked from DA0-DA0/dao-dao-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinbox.ts
241 lines (223 loc) · 5.65 KB
/
inbox.ts
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import { ComponentType, ReactNode } from 'react'
export type InboxState = {
loading: boolean
refreshing: boolean
items: InboxLoadedItemWithData[]
refresh: () => void
}
export type InboxLoadedItem = {
id: string
timestamp: string | undefined
chainId: string
data: unknown
}
export enum InboxItemType {
JoinedDao = 'joined_dao',
ProposalCreated = 'proposal_created',
ProposalExecuted = 'proposal_executed',
ProposalClosed = 'proposal_closed',
PendingProposalCreated = 'pending_proposal_created',
PendingProposalRejected = 'pending_proposal_rejected',
}
export type InboxItemTypeJoinedDaoData = {
chainId: string
dao: string
name: string
imageUrl: string | undefined
}
export type InboxItemTypeProposalCreatedData = {
chainId: string
dao: string
daoName: string
imageUrl: string | undefined
proposalId: string
proposalTitle: string
// Whether or not this is an approver-created proposal.
fromApprover?: boolean
}
export type InboxItemTypeProposalExecutedData =
InboxItemTypeProposalCreatedData & {
failed: boolean
// Winning option for a multiple choice proposal.
winningOption?: string
}
export type InboxItemTypeProposalClosedData = InboxItemTypeProposalCreatedData
export type InboxItemTypePendingProposalCreatedData = Omit<
InboxItemTypeProposalCreatedData,
'fromApprover'
>
export type InboxItemTypePendingProposalRejectedData =
InboxItemTypePendingProposalCreatedData
// Items from the inbox API.
export type InboxLoadedItemWithData = Omit<InboxLoadedItem, 'data'> &
(
| {
type: InboxItemType.JoinedDao
data: InboxItemTypeJoinedDaoData
}
| {
type: InboxItemType.ProposalCreated
data: InboxItemTypeProposalCreatedData
}
| {
type: InboxItemType.ProposalExecuted
data: InboxItemTypeProposalExecutedData
}
| {
type: InboxItemType.ProposalClosed
data: InboxItemTypeProposalClosedData
}
| {
type: InboxItemType.PendingProposalCreated
data: InboxItemTypePendingProposalCreatedData
}
| {
type: InboxItemType.PendingProposalRejected
data: InboxItemTypePendingProposalRejectedData
}
)
export enum InboxItemTypeMethod {
Website = 1 << 0,
Email = 1 << 1,
Push = 1 << 2,
}
export type InboxItemTypeMethodData = {
method: InboxItemTypeMethod
i18nKey: string
Icon: ComponentType<{ className?: string }>
}
export type InboxItemRendererProps<Data extends unknown> = {
item: InboxLoadedItemWithData
data: Data
clear: () => Promise<boolean>
/**
* Optionally style things a bit more compact. Used in the popup.
*/
compact?: boolean
}
export type InboxMainItemRendererProps = {
/**
* The loaded inbox item.
*/
item: InboxLoadedItemWithData
/**
* Whether or not this inbox item is checked. Checking refers to batch marking
* as cleared.
*/
checked: boolean
/**
* Check handler. Called with the item.
*/
onCheck: (item: InboxLoadedItem) => void
/**
* Optionally style things a bit more compact. Used in the popup.
*/
compact?: boolean
}
export type InboxUpdateConfig = {
// Update email. If empty or null, remove email.
email?: string | null
// Update notification settings per-type.
types?: Record<string, number | null>
// If present, verify email.
verify?: string
// If present, resend verification email.
resend?: boolean
// If present, update push settings.
push?:
| {
// Add subscription.
type: 'subscribe'
subscription: any
}
| {
// Check if subscribed or unsubscribe.
type: 'check' | 'unsubscribe'
p256dh: string
}
| {
// Unsubscribe all subscriptions.
type: 'unsubscribe_all'
}
}
export type PushSubscriptionManager = {
ready: boolean
supported: boolean
updating: boolean
subscribed: boolean
subscription: PushSubscription | undefined
subscribe: () => Promise<void>
unsubscribe: () => Promise<void>
unsubscribeAll: () => Promise<void>
}
export type InboxConfig = {
email: string | null
verified: boolean
types: Record<string, number | null>
// Number of registered push subscriptions.
pushSubscriptions: number
// If `push` is defined in the body, returns whether or not the push is now
// subscribed.
pushSubscribed?: boolean
// Allowed methods per type.
typeAllowedMethods: Record<InboxItemType, InboxItemTypeMethod[]>
}
export type InboxApi = {
ready: boolean
updating: boolean
clear: (
items: {
chainId: string
id: string
}[]
) => Promise<boolean>
loadConfig: () => Promise<boolean>
updateConfig: (
data: InboxUpdateConfig,
signatureType?: string
) => Promise<boolean>
resendVerificationEmail: () => Promise<boolean>
verify: (code: string) => Promise<boolean>
config: InboxConfig | undefined
push: PushSubscriptionManager
}
export type InboxApiWithUi = {
/**
* The inbox API.
*/
api: InboxApi
/**
* A map of inbox item ID to whether or not it is checked for removal.
*/
checked: Record<string, boolean>
/**
* The callback that toggles the checked status of an inbox item.
*/
onCheck: (item: InboxLoadedItem) => void
/**
* A function that uses the verification code in the URL query params and
* attempts to verify.
*/
verify: () => void
/**
* The buttons that perform various actions.
*/
buttons: {
/**
* Refresh the inbox.
*/
refresh: ReactNode
/**
* Clear the checked items, or clear all if none are checked.
*/
clear: ReactNode
/**
* Open the settings modal.
*/
settings: ReactNode
}
}
export enum InboxPageSlug {
Settings = 'settings',
Verify = 'verify',
}