@fadyshawky/react-native-magic 2.0.4 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/App.tsx +28 -19
- package/template/ios/reactnativemagic/AppDelegate.mm +5 -0
- package/template/src/common/components/Background.tsx +6 -4
- package/template/src/common/components/Container.tsx +6 -9
- package/template/src/common/components/OTPInput.tsx +3 -2
- package/template/src/common/components/PrimaryButton.tsx +23 -23
- package/template/src/common/components/PrimaryTextInput.tsx +189 -199
- package/template/src/common/components/RadioIcon.tsx +4 -4
- package/template/src/common/components/SafeText.tsx +41 -0
- package/template/src/common/components/SearchBar.tsx +19 -17
- package/template/src/common/components/TryAgain.tsx +3 -3
- package/template/src/common/localization/LocalizationProvider.tsx +14 -17
- package/template/src/common/localization/RTLInitializer.tsx +90 -0
- package/template/src/common/localization/localization.ts +8 -0
- package/template/src/common/localization/translations/commonLocalization.ts +33 -6
- package/template/src/common/localization/translations/emptyLocalization.ts +6 -2
- package/template/src/common/localization/translations/errorsLocalization.ts +33 -13
- package/template/src/common/localization/translations/homeLocalization.ts +6 -2
- package/template/src/common/localization/translations/loginLocalization.ts +32 -9
- package/template/src/common/localization/translations/mainNavigationLocalization.ts +30 -0
- package/template/src/common/localization/translations/navigationLocalization.ts +48 -0
- package/template/src/common/localization/translations/onboardingLocalization.ts +40 -9
- package/template/src/common/localization/translations/otpLocalization.ts +28 -0
- package/template/src/common/localization/translations/pagesLocalization.ts +13 -1
- package/template/src/common/localization/translations/passwordLocalization.ts +54 -0
- package/template/src/common/localization/translations/profileLocalization.ts +4 -4
- package/template/src/common/utils/FeesCaalculation.tsx +37 -0
- package/template/src/common/utils/index.tsx +11 -0
- package/template/src/common/utils/printData.tsx +161 -0
- package/template/src/common/validations/errorValidations.ts +3 -2
- package/template/src/core/api/serverHeaders.ts +62 -1
- package/template/src/core/store/Categories/categoryActions.ts +33 -0
- package/template/src/core/store/Categories/categorySlice.ts +75 -0
- package/template/src/core/store/Categories/categoryState.ts +41 -0
- package/template/src/core/store/Providers/providersActions.ts +102 -0
- package/template/src/core/store/Providers/providersSlice.ts +136 -0
- package/template/src/core/store/Providers/providersState.ts +37 -0
- package/template/src/core/store/Services/servicesActions.ts +191 -0
- package/template/src/core/store/Services/servicesSlice.ts +205 -0
- package/template/src/core/store/Services/servicesState.ts +466 -0
- package/template/src/core/store/app/appSlice.ts +13 -5
- package/template/src/core/store/app/appState.ts +10 -2
- package/template/src/core/store/rootReducer.ts +6 -1
- package/template/src/core/store/store.tsx +55 -2
- package/template/src/core/store/user/userActions.ts +164 -26
- package/template/src/core/store/user/userSlice.ts +193 -21
- package/template/src/core/store/user/userState.ts +148 -25
- package/template/src/core/theme/colors.ts +12 -0
- package/template/src/core/theme/themes.ts +1 -1
- package/template/src/core/utils/stringUtils.ts +114 -0
- package/template/src/navigation/AuthStack.tsx +8 -0
- package/template/src/navigation/HeaderComponents.tsx +52 -1
- package/template/src/navigation/MainNavigation.tsx +3 -1
- package/template/src/navigation/MainStack.tsx +39 -56
- package/template/src/navigation/TabBar.tsx +111 -59
- package/template/src/navigation/types.ts +24 -0
- package/template/src/screens/Login/Login.tsx +83 -85
- package/template/src/screens/OTP/OTPScreen.tsx +169 -0
- package/template/src/screens/home/Components/PayByCode.tsx +129 -0
- package/template/src/screens/home/HomeScreen.tsx +1 -103
- package/template/src/screens/home/hooks/useHomeData.ts +32 -38
- package/template/src/screens/index.tsx +24 -0
- package/template/src/common/components/Stepper.tsx +0 -153
- package/template/src/common/components/Svg.tsx +0 -25
- package/template/src/common/hooks/useDebounce.ts +0 -17
- package/template/src/common/hooks/usePrevious.ts +0 -11
- package/template/src/common/urls/emailUrl.ts +0 -20
- package/template/src/common/urls/mapUrl.ts +0 -22
- package/template/src/common/utils/listHandlers.ts +0 -30
- package/template/src/common/utils/serializeQueryParams.ts +0 -10
- package/template/src/common/validations/hooks/useDatesError.ts +0 -40
- package/template/src/common/validations/profileValidations.ts +0 -30
- package/template/src/navigation/TopTabBar.tsx +0 -77
- package/template/src/screens/Settings/Settings.tsx +0 -5
- package/template/src/screens/home/components/CarouselSection.tsx +0 -79
- package/template/src/screens/home/components/FeaturedCarousel.tsx +0 -128
- package/template/src/screens/main/Main.tsx +0 -5
- package/template/src/screens/registration/RegistrationScreen.tsx +0 -198
- package/template/src/screens/resetPassword/ForgotPasswordScreen.tsx +0 -129
|
@@ -1,74 +1,212 @@
|
|
|
1
1
|
import {createAsyncThunk} from '@reduxjs/toolkit';
|
|
2
2
|
import {handleFetchJsonResponse} from '../../api/responseHandlers';
|
|
3
3
|
import {post} from '../../api/serverHeaders';
|
|
4
|
+
import {RootState} from '../rootReducer';
|
|
5
|
+
import {extractServerError} from '../../api/errorHandler';
|
|
6
|
+
import {ensureString} from '../../utils/stringUtils';
|
|
4
7
|
|
|
5
8
|
export const userLogin = createAsyncThunk(
|
|
6
9
|
'user/login',
|
|
7
10
|
async (
|
|
8
|
-
{
|
|
11
|
+
{phone, password}: {phone: string; password: string},
|
|
9
12
|
{rejectWithValue, getState, dispatch}: any,
|
|
10
13
|
) => {
|
|
11
14
|
try {
|
|
12
|
-
const data: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
const data: {
|
|
16
|
+
mobile_number: string;
|
|
17
|
+
mpin: string;
|
|
18
|
+
scheme_id: number;
|
|
19
|
+
} = {
|
|
20
|
+
mobile_number: phone,
|
|
21
|
+
mpin: password,
|
|
22
|
+
scheme_id: 1,
|
|
15
23
|
};
|
|
16
|
-
|
|
17
24
|
const response = await post({
|
|
18
|
-
url: '/login',
|
|
25
|
+
url: 'wallet_users/login',
|
|
19
26
|
data,
|
|
20
27
|
});
|
|
21
28
|
|
|
22
29
|
return handleFetchJsonResponse(response);
|
|
23
30
|
} catch (e: any) {
|
|
24
|
-
|
|
31
|
+
const serverError = extractServerError(e);
|
|
32
|
+
|
|
33
|
+
return rejectWithValue({
|
|
34
|
+
...serverError,
|
|
35
|
+
message: ensureString(serverError.message),
|
|
36
|
+
});
|
|
25
37
|
}
|
|
26
38
|
},
|
|
27
39
|
);
|
|
28
40
|
|
|
29
|
-
export const
|
|
30
|
-
'user/
|
|
41
|
+
export const verifyOTP = createAsyncThunk(
|
|
42
|
+
'user/verifyOTP',
|
|
31
43
|
async (
|
|
32
44
|
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
45
|
+
verification_code,
|
|
46
|
+
mobile_number,
|
|
47
|
+
device_token,
|
|
48
|
+
scheme_id,
|
|
36
49
|
}: {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
verification_code: string;
|
|
51
|
+
mobile_number: string;
|
|
52
|
+
device_token?: string;
|
|
53
|
+
scheme_id: number;
|
|
40
54
|
},
|
|
41
|
-
{rejectWithValue},
|
|
55
|
+
{rejectWithValue, getState, dispatch}: any,
|
|
42
56
|
) => {
|
|
43
57
|
try {
|
|
58
|
+
const data: {
|
|
59
|
+
mobile_number: string;
|
|
60
|
+
verification_code: string;
|
|
61
|
+
device_token?: string;
|
|
62
|
+
scheme_id: number;
|
|
63
|
+
} = {
|
|
64
|
+
mobile_number,
|
|
65
|
+
verification_code,
|
|
66
|
+
device_token: undefined,
|
|
67
|
+
scheme_id: 1,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const token = (getState() as RootState).user.tempToken;
|
|
71
|
+
|
|
72
|
+
const response = await post({
|
|
73
|
+
url: 'wallet_users/verifylogin',
|
|
74
|
+
data,
|
|
75
|
+
config: {
|
|
76
|
+
headers: {
|
|
77
|
+
Authorization: `${token}`,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return handleFetchJsonResponse(response);
|
|
83
|
+
} catch (e: any) {
|
|
84
|
+
const serverError = extractServerError(e);
|
|
85
|
+
|
|
86
|
+
return rejectWithValue({
|
|
87
|
+
...serverError,
|
|
88
|
+
message: ensureString(serverError.message),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
export const getBalance = createAsyncThunk(
|
|
95
|
+
'user/getBalance',
|
|
96
|
+
async (_, {rejectWithValue, getState, dispatch}: any) => {
|
|
97
|
+
try {
|
|
98
|
+
const token = (getState() as RootState).user.accessToken;
|
|
99
|
+
|
|
44
100
|
const response = await post({
|
|
45
|
-
url: '/
|
|
46
|
-
data: {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
101
|
+
url: 'wallet_users/getbalance',
|
|
102
|
+
data: {},
|
|
103
|
+
config: {
|
|
104
|
+
headers: {
|
|
105
|
+
Authorization: `${token}`,
|
|
106
|
+
},
|
|
50
107
|
},
|
|
51
108
|
});
|
|
52
109
|
|
|
53
110
|
return handleFetchJsonResponse(response);
|
|
54
111
|
} catch (e: any) {
|
|
55
|
-
|
|
112
|
+
const serverError = extractServerError(e);
|
|
113
|
+
|
|
114
|
+
return rejectWithValue({
|
|
115
|
+
...serverError,
|
|
116
|
+
message: ensureString(serverError.message),
|
|
117
|
+
});
|
|
56
118
|
}
|
|
57
119
|
},
|
|
58
120
|
);
|
|
59
121
|
|
|
60
122
|
export const resetPassword = createAsyncThunk(
|
|
61
123
|
'user/resetPassword',
|
|
62
|
-
async (
|
|
124
|
+
async (
|
|
125
|
+
{
|
|
126
|
+
mpin,
|
|
127
|
+
new_mpin,
|
|
128
|
+
confirm_mpin,
|
|
129
|
+
}: {mpin: string; new_mpin: string; confirm_mpin: string},
|
|
130
|
+
{rejectWithValue, getState},
|
|
131
|
+
) => {
|
|
63
132
|
try {
|
|
133
|
+
const token = (getState() as RootState).user.accessToken;
|
|
134
|
+
|
|
64
135
|
const response = await post({
|
|
65
|
-
url: '/
|
|
66
|
-
data: {
|
|
136
|
+
url: 'wallet_users/force-update-mpin',
|
|
137
|
+
data: {mpin, new_mpin, confirm_mpin},
|
|
138
|
+
config: {
|
|
139
|
+
headers: {
|
|
140
|
+
Authorization: `${token}`,
|
|
141
|
+
},
|
|
142
|
+
},
|
|
67
143
|
});
|
|
68
144
|
|
|
69
145
|
return handleFetchJsonResponse(response);
|
|
70
146
|
} catch (e: any) {
|
|
71
|
-
|
|
147
|
+
const serverError = extractServerError(e);
|
|
148
|
+
|
|
149
|
+
return rejectWithValue({
|
|
150
|
+
...serverError,
|
|
151
|
+
message: ensureString(serverError.message),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
export const fetchHistory = createAsyncThunk(
|
|
158
|
+
'user/fetchHistory',
|
|
159
|
+
async (
|
|
160
|
+
{data}: {data: {page: number; limit: number}},
|
|
161
|
+
{rejectWithValue, getState},
|
|
162
|
+
) => {
|
|
163
|
+
try {
|
|
164
|
+
const token = (getState() as RootState).user.accessToken;
|
|
165
|
+
const response = await post({
|
|
166
|
+
url: 'wallet_users/history',
|
|
167
|
+
data: {page: data.page, limit: data.limit},
|
|
168
|
+
config: {
|
|
169
|
+
headers: {
|
|
170
|
+
Authorization: `${token}`,
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return handleFetchJsonResponse(response);
|
|
176
|
+
} catch (e: any) {
|
|
177
|
+
const serverError = extractServerError(e);
|
|
178
|
+
|
|
179
|
+
return rejectWithValue({
|
|
180
|
+
...serverError,
|
|
181
|
+
message: ensureString(serverError.message),
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
export const fetchHistoryDetails = createAsyncThunk(
|
|
188
|
+
'user/fetchHistoryDetails',
|
|
189
|
+
async ({trxRef}: {trxRef: string}, {rejectWithValue, getState}) => {
|
|
190
|
+
try {
|
|
191
|
+
const token = (getState() as RootState).user.accessToken;
|
|
192
|
+
|
|
193
|
+
const response = await post({
|
|
194
|
+
url: 'wallet_users/history/details',
|
|
195
|
+
data: {trxRef},
|
|
196
|
+
config: {
|
|
197
|
+
headers: {
|
|
198
|
+
Authorization: `${token}`,
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
return handleFetchJsonResponse(response);
|
|
204
|
+
} catch (e: any) {
|
|
205
|
+
const serverError = extractServerError(e);
|
|
206
|
+
return rejectWithValue({
|
|
207
|
+
...serverError,
|
|
208
|
+
message: ensureString(serverError.message),
|
|
209
|
+
});
|
|
72
210
|
}
|
|
73
211
|
},
|
|
74
212
|
);
|
|
@@ -2,13 +2,20 @@ import {createSlice} from '@reduxjs/toolkit';
|
|
|
2
2
|
import {LoadState} from '../../../../types';
|
|
3
3
|
import {newState} from '../../../common/utils/newState';
|
|
4
4
|
import {handleErrorResponse} from '../../api/responseHandlers';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
resetPassword,
|
|
7
|
+
userLogin,
|
|
8
|
+
getBalance,
|
|
9
|
+
verifyOTP,
|
|
10
|
+
fetchHistoryDetails,
|
|
11
|
+
fetchHistory,
|
|
12
|
+
} from './userActions';
|
|
6
13
|
import {UserInitialState, UserPayload, UserState} from './userState';
|
|
14
|
+
import {cloneDeep, uniqBy} from 'lodash';
|
|
7
15
|
|
|
8
16
|
function loginHandler(state: UserState, payload: {payload: UserPayload}) {
|
|
9
17
|
return newState(state, {
|
|
10
|
-
|
|
11
|
-
accessToken: payload.payload.token,
|
|
18
|
+
tempToken: payload.payload.token,
|
|
12
19
|
loginLoading: LoadState['allIsLoaded'],
|
|
13
20
|
});
|
|
14
21
|
}
|
|
@@ -20,12 +27,49 @@ function loginLoadingHandler(state: UserState) {
|
|
|
20
27
|
|
|
21
28
|
function loginErrorHandler(
|
|
22
29
|
state: UserState,
|
|
23
|
-
payload: {payload: string
|
|
30
|
+
payload: {payload: {message: string}},
|
|
31
|
+
) {
|
|
32
|
+
console.error('payload: ', JSON.stringify(payload));
|
|
33
|
+
handleErrorResponse((payload.payload.message as string) || 'Login failed');
|
|
34
|
+
return newState(state, {
|
|
35
|
+
loginLoading: LoadState['error'],
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function verifyOTPHandler(state: UserState, payload: {payload: UserPayload}) {
|
|
40
|
+
return newState(state, {
|
|
41
|
+
user: {
|
|
42
|
+
type: payload.payload.type,
|
|
43
|
+
mobile_number: payload.payload.mobile_number,
|
|
44
|
+
full_name: payload.payload.fullname,
|
|
45
|
+
merchantStore: payload.payload.merchantStore,
|
|
46
|
+
status: payload.payload.status,
|
|
47
|
+
},
|
|
48
|
+
accessToken: payload.payload.token,
|
|
49
|
+
loginLoading: LoadState['allIsLoaded'],
|
|
50
|
+
current_balance: payload?.payload?.current_balance?.find(
|
|
51
|
+
i => i.name === 'Deposit',
|
|
52
|
+
)?.value,
|
|
53
|
+
daily_commission: payload?.payload?.current_balance?.find(
|
|
54
|
+
i => i.name === 'Daily Commission',
|
|
55
|
+
)?.value,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function verifyOTPLoadingHandler(state: UserState) {
|
|
59
|
+
return newState(state, {
|
|
60
|
+
loginLoading: LoadState['pullToRefresh'],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function verifyOTPErrorHandler(
|
|
65
|
+
state: UserState,
|
|
66
|
+
payload: {payload: {message: string}},
|
|
24
67
|
) {
|
|
25
|
-
handleErrorResponse(
|
|
68
|
+
handleErrorResponse(
|
|
69
|
+
(payload.payload.message as string) || 'Verify OTP failed',
|
|
70
|
+
);
|
|
26
71
|
return newState(state, {
|
|
27
72
|
loginLoading: LoadState['error'],
|
|
28
|
-
accessToken: 'kl;hadjlcnaidojp8989y4hrkn4w3r89',
|
|
29
73
|
});
|
|
30
74
|
}
|
|
31
75
|
|
|
@@ -38,8 +82,10 @@ function resetPasswordHandler(
|
|
|
38
82
|
payload: {payload: UserPayload},
|
|
39
83
|
) {
|
|
40
84
|
return newState(state, {
|
|
41
|
-
user:
|
|
42
|
-
|
|
85
|
+
user: {
|
|
86
|
+
...state.user,
|
|
87
|
+
status: payload.payload.status,
|
|
88
|
+
},
|
|
43
89
|
loginLoading: LoadState['allIsLoaded'],
|
|
44
90
|
});
|
|
45
91
|
}
|
|
@@ -50,25 +96,28 @@ function resetPasswordLoadingHandler(state: UserState) {
|
|
|
50
96
|
});
|
|
51
97
|
}
|
|
52
98
|
|
|
53
|
-
function
|
|
99
|
+
function getBalanceHandler(state: UserState, payload: {payload: UserPayload}) {
|
|
54
100
|
return newState(state, {
|
|
55
|
-
|
|
56
|
-
|
|
101
|
+
current_balance: payload?.payload?.balance?.find(i => i.name === 'Deposit')
|
|
102
|
+
?.value,
|
|
103
|
+
daily_commission: payload?.payload?.balance?.find(
|
|
104
|
+
i => i.name === 'Daily Commission',
|
|
105
|
+
)?.value,
|
|
57
106
|
loginLoading: LoadState['allIsLoaded'],
|
|
58
107
|
});
|
|
59
108
|
}
|
|
60
109
|
|
|
61
|
-
function
|
|
110
|
+
function getBalanceLoadingHandler(state: UserState) {
|
|
62
111
|
return newState(state, {
|
|
63
112
|
loginLoading: LoadState['pullToRefresh'],
|
|
64
113
|
});
|
|
65
114
|
}
|
|
66
115
|
|
|
67
|
-
function
|
|
116
|
+
function getBalanceErrorHandler(
|
|
68
117
|
state: UserState,
|
|
69
|
-
payload: {payload: string
|
|
118
|
+
payload: {payload: {message: string}},
|
|
70
119
|
) {
|
|
71
|
-
handleErrorResponse((payload.payload as string) || 'Register failed');
|
|
120
|
+
handleErrorResponse((payload.payload.message as string) || 'Register failed');
|
|
72
121
|
return newState(state, {
|
|
73
122
|
loginLoading: LoadState['error'],
|
|
74
123
|
});
|
|
@@ -85,14 +134,115 @@ function updateHandler(state: UserState, payload: any) {
|
|
|
85
134
|
|
|
86
135
|
function resetPasswordErrorHandler(
|
|
87
136
|
state: UserState,
|
|
88
|
-
payload: {payload: string
|
|
137
|
+
payload: {payload: {message: string}},
|
|
89
138
|
) {
|
|
90
|
-
handleErrorResponse(
|
|
139
|
+
handleErrorResponse(
|
|
140
|
+
(payload.payload.message as string) || 'Password reset failed',
|
|
141
|
+
);
|
|
91
142
|
return newState(state, {
|
|
92
143
|
loginLoading: LoadState['error'],
|
|
93
144
|
});
|
|
94
145
|
}
|
|
95
146
|
|
|
147
|
+
function setFavoriteCategoriesHandler(
|
|
148
|
+
state: UserState,
|
|
149
|
+
payload: {payload: number},
|
|
150
|
+
) {
|
|
151
|
+
if (!state.favoriteCategories) {
|
|
152
|
+
state.favoriteCategories = [];
|
|
153
|
+
}
|
|
154
|
+
state.favoriteCategories.push(payload.payload);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function setFavoriteProvidersHandler(
|
|
158
|
+
state: UserState,
|
|
159
|
+
payload: {payload: number},
|
|
160
|
+
) {
|
|
161
|
+
if (!state.favoriteProviders) {
|
|
162
|
+
state.favoriteProviders = [];
|
|
163
|
+
}
|
|
164
|
+
state.favoriteProviders.push(payload.payload);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function removeFavoriteCategoriesHandler(
|
|
168
|
+
state: UserState,
|
|
169
|
+
payload: {payload: number},
|
|
170
|
+
) {
|
|
171
|
+
if (state.favoriteCategories) {
|
|
172
|
+
state.favoriteCategories = state.favoriteCategories.filter(
|
|
173
|
+
id => id !== payload.payload,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function removeFavoriteProvidersHandler(
|
|
179
|
+
state: UserState,
|
|
180
|
+
payload: {payload: number},
|
|
181
|
+
) {
|
|
182
|
+
if (state.favoriteProviders) {
|
|
183
|
+
state.favoriteProviders = state.favoriteProviders.filter(
|
|
184
|
+
id => id !== payload.payload,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function fetchHistoryHandler(
|
|
190
|
+
state: UserState,
|
|
191
|
+
payload: {payload: UserPayload},
|
|
192
|
+
) {
|
|
193
|
+
let tmp = cloneDeep(state.history);
|
|
194
|
+
tmp = [...tmp, ...payload.payload.requests];
|
|
195
|
+
tmp = uniqBy(tmp, 'transaction_reference_num');
|
|
196
|
+
return newState(state, {
|
|
197
|
+
history: tmp,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function fetchHistoryLoadingHandler(state: UserState) {
|
|
202
|
+
return newState(state, {
|
|
203
|
+
loginLoading: LoadState['pullToRefresh'],
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function fetchHistoryErrorHandler(
|
|
208
|
+
state: UserState,
|
|
209
|
+
payload: {payload: {message: string}},
|
|
210
|
+
) {
|
|
211
|
+
handleErrorResponse(
|
|
212
|
+
(payload.payload.message as string) || 'Fetch history failed',
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function fetchHistoryDetailsHandler(
|
|
217
|
+
state: UserState,
|
|
218
|
+
payload: {payload: UserPayload},
|
|
219
|
+
) {
|
|
220
|
+
return newState(state, {
|
|
221
|
+
historyDetails: payload.payload.data,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function fetchHistoryDetailsLoadingHandler(state: UserState) {
|
|
226
|
+
return newState(state, {
|
|
227
|
+
loginLoading: LoadState['pullToRefresh'],
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function fetchHistoryDetailsErrorHandler(
|
|
232
|
+
state: UserState,
|
|
233
|
+
payload: {payload: {message: string}},
|
|
234
|
+
) {
|
|
235
|
+
handleErrorResponse(
|
|
236
|
+
(payload.payload.message as string) || 'Fetch history details failed',
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function clearHistoryHandler(state: UserState) {
|
|
241
|
+
return newState(state, {
|
|
242
|
+
history: UserInitialState.history,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
96
246
|
export const {reducer: UserReducer, actions} = createSlice({
|
|
97
247
|
name: 'user',
|
|
98
248
|
initialState: UserInitialState,
|
|
@@ -102,6 +252,11 @@ export const {reducer: UserReducer, actions} = createSlice({
|
|
|
102
252
|
setLoginError: loginLoadingHandler,
|
|
103
253
|
setLogout: logoutHandler,
|
|
104
254
|
setUpdate: updateHandler,
|
|
255
|
+
setFavoriteCategories: setFavoriteCategoriesHandler,
|
|
256
|
+
setFavoriteProviders: setFavoriteProvidersHandler,
|
|
257
|
+
removeFavoriteCategories: removeFavoriteCategoriesHandler,
|
|
258
|
+
removeFavoriteProviders: removeFavoriteProvidersHandler,
|
|
259
|
+
clearHistory: clearHistoryHandler,
|
|
105
260
|
},
|
|
106
261
|
extraReducers: builder => {
|
|
107
262
|
builder
|
|
@@ -111,10 +266,27 @@ export const {reducer: UserReducer, actions} = createSlice({
|
|
|
111
266
|
.addCase(resetPassword.fulfilled, resetPasswordHandler)
|
|
112
267
|
.addCase(resetPassword.rejected, resetPasswordErrorHandler)
|
|
113
268
|
.addCase(resetPassword.pending, resetPasswordLoadingHandler)
|
|
114
|
-
.addCase(
|
|
115
|
-
.addCase(
|
|
116
|
-
.addCase(
|
|
269
|
+
.addCase(getBalance.fulfilled, getBalanceHandler)
|
|
270
|
+
.addCase(getBalance.rejected, getBalanceErrorHandler)
|
|
271
|
+
.addCase(getBalance.pending, getBalanceLoadingHandler)
|
|
272
|
+
.addCase(verifyOTP.fulfilled, verifyOTPHandler)
|
|
273
|
+
.addCase(verifyOTP.rejected, verifyOTPErrorHandler)
|
|
274
|
+
.addCase(verifyOTP.pending, verifyOTPLoadingHandler)
|
|
275
|
+
.addCase(fetchHistory.fulfilled, fetchHistoryHandler)
|
|
276
|
+
.addCase(fetchHistory.rejected, fetchHistoryErrorHandler)
|
|
277
|
+
.addCase(fetchHistory.pending, fetchHistoryLoadingHandler)
|
|
278
|
+
.addCase(fetchHistoryDetails.fulfilled, fetchHistoryDetailsHandler)
|
|
279
|
+
.addCase(fetchHistoryDetails.rejected, fetchHistoryDetailsErrorHandler)
|
|
280
|
+
.addCase(fetchHistoryDetails.pending, fetchHistoryDetailsLoadingHandler);
|
|
117
281
|
},
|
|
118
282
|
});
|
|
119
283
|
|
|
120
|
-
export const {
|
|
284
|
+
export const {
|
|
285
|
+
setLogout,
|
|
286
|
+
setUpdate,
|
|
287
|
+
setFavoriteCategories,
|
|
288
|
+
setFavoriteProviders,
|
|
289
|
+
removeFavoriteCategories,
|
|
290
|
+
removeFavoriteProviders,
|
|
291
|
+
clearHistory,
|
|
292
|
+
} = actions;
|