@@ -12,6 +12,11 @@ import { createBackgroundAsyncThunk } from "./utils"
12
12
import { UNIXTime } from "../types"
13
13
import { DEFAULT_AUTOLOCK_INTERVAL } from "../services/preferences/defaults"
14
14
import type { RootState } from "."
15
+ import {
16
+ CampaignIds ,
17
+ Campaigns ,
18
+ FilterCampaignsById ,
19
+ } from "../services/campaign/types"
15
20
16
21
export const defaultSettings = {
17
22
hideDust : false ,
@@ -24,15 +29,9 @@ export const defaultSettings = {
24
29
hideBanners : false ,
25
30
useFlashbots : false ,
26
31
autoLockInterval : DEFAULT_AUTOLOCK_INTERVAL ,
32
+ campaigns : { } ,
27
33
}
28
34
29
- export type MezoClaimStatus =
30
- | "not-eligible"
31
- | "eligible"
32
- | "claimed-sats"
33
- | "borrowed"
34
- | "campaign-complete"
35
-
36
35
export type UIState = {
37
36
selectedAccount : AddressOnNetwork
38
37
showingActivityDetailID : string | null
@@ -55,12 +54,15 @@ export type UIState = {
55
54
routeHistoryEntries ?: Partial < Location > [ ]
56
55
slippageTolerance : number
57
56
accountSignerSettings : AccountSignerSettings [ ]
58
- activeCampaigns : {
59
- "mezo-claim" ?: {
60
- dateFrom : string
61
- dateTo : string
62
- state : MezoClaimStatus
63
- }
57
+ // Active user campaigns
58
+ campaigns : {
59
+ /**
60
+ * Some hash used to invalidate cached data and update UI
61
+ */
62
+ [ campaignId in CampaignIds ] ?: FilterCampaignsById <
63
+ Campaigns ,
64
+ campaignId
65
+ > [ "data" ]
64
66
}
65
67
}
66
68
@@ -79,6 +81,7 @@ export type Events = {
79
81
addCustomNetworkResponse : [ string , boolean ]
80
82
updateAutoLockInterval : number
81
83
toggleShowTestNetworks : boolean
84
+ clearNotification : string
82
85
}
83
86
84
87
export const emitter = new Emittery < Events > ( )
@@ -94,7 +97,7 @@ export const initialState: UIState = {
94
97
snackbarMessage : "" ,
95
98
slippageTolerance : 0.01 ,
96
99
accountSignerSettings : [ ] ,
97
- activeCampaigns : { } ,
100
+ campaigns : { } ,
98
101
}
99
102
100
103
const uiSlice = createSlice ( {
@@ -239,21 +242,15 @@ const uiSlice = createSlice({
239
242
...state ,
240
243
settings : { ...state . settings , autoLockInterval : payload } ,
241
244
} ) ,
242
- updateCampaignState : < T extends keyof UIState [ "activeCampaigns" ] > (
245
+ updateCampaignsState : (
243
246
immerState : UIState ,
244
247
{
245
248
payload,
246
249
} : {
247
- payload : [ T , Partial < UIState [ "activeCampaigns" ] [ T ] > ]
250
+ payload : UIState [ "campaigns" ]
248
251
} ,
249
252
) => {
250
- const [ campaignId , update ] = payload
251
-
252
- immerState . activeCampaigns ??= { }
253
- immerState . activeCampaigns [ campaignId ] = {
254
- ...immerState . activeCampaigns [ campaignId ] ,
255
- ...update ,
256
- }
253
+ immerState . campaigns = payload
257
254
} ,
258
255
} ,
259
256
} )
@@ -279,7 +276,7 @@ export const {
279
276
setSlippageTolerance,
280
277
setAccountsSignerSettings,
281
278
setAutoLockInterval,
282
- updateCampaignState ,
279
+ updateCampaignsState ,
283
280
} = uiSlice . actions
284
281
285
282
export default uiSlice . reducer
@@ -307,6 +304,13 @@ export const deleteAnalyticsData = createBackgroundAsyncThunk(
307
304
} ,
308
305
)
309
306
307
+ export const clearNotification = createBackgroundAsyncThunk (
308
+ "ui/clearNotification" ,
309
+ async ( id : string ) => {
310
+ await emitter . emit ( "clearNotification" , id )
311
+ } ,
312
+ )
313
+
310
314
// Async thunk to bubble the setNewDefaultWalletValue action from store to emitter.
311
315
export const setNewDefaultWalletValue = createBackgroundAsyncThunk (
312
316
"ui/setNewDefaultWalletValue" ,
0 commit comments