1 import { createSlice } from '@reduxjs/toolkit';
3 import type { ModelState } from '@proton/account';
4 import { getInitialModelState } from '@proton/account';
5 import { createAsyncModelThunk, handleAsyncModel, previousSelector } from '@proton/redux-utilities';
7 import type { WalletThunkArguments } from '../thunk';
9 const name = 'user_eligibility' as const;
11 export interface UserEligibilityState {
12 [name]: ModelState<boolean>;
15 type SliceState = UserEligibilityState[typeof name];
16 type Model = NonNullable<SliceState['value']>;
18 export const selectUserEligibility = (state: UserEligibilityState) => {
22 const modelThunk = createAsyncModelThunk<Model, UserEligibilityState, WalletThunkArguments>(`${name}/fetch`, {
23 miss: async ({ extraArgument }) => {
24 const isEligible = await extraArgument.walletApi
26 .settings.getUserWalletEligibility()
27 .then((data) => Boolean(data))
32 previous: previousSelector(selectUserEligibility),
35 const initialState = getInitialModelState<Model>();
37 const slice = createSlice({
41 extraReducers: (builder) => {
42 handleAsyncModel(builder, modelThunk);
46 export const userEligibilityReducer = { [name]: slice.reducer };
47 export const userEligibilityThunk = modelThunk.thunk;