@digitaldefiance/express-suite-react-components 2.5.3 → 2.5.5
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/README.md
CHANGED
|
@@ -362,6 +362,15 @@ MIT © Digital Defiance
|
|
|
362
362
|
|
|
363
363
|
## ChangeLog
|
|
364
364
|
|
|
365
|
+
### Version 2.5.5
|
|
366
|
+
|
|
367
|
+
- Fix /user/verify repeat calls
|
|
368
|
+
- Add toggleColorMode to authService
|
|
369
|
+
|
|
370
|
+
### Version 2.5.4
|
|
371
|
+
|
|
372
|
+
- Fix currency/session storage
|
|
373
|
+
|
|
365
374
|
### Version 2.5.3
|
|
366
375
|
|
|
367
376
|
- Update libs
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Member as FrontendMember, EmailString, IECIESConfig, SecureString } from '@digitaldefiance/ecies-lib';
|
|
2
|
-
import { CurrencyCode } from '@digitaldefiance/i18n-lib';
|
|
2
|
+
import { CurrencyCode, Timezone } from '@digitaldefiance/i18n-lib';
|
|
3
3
|
import { Wallet } from '@ethereumjs/wallet';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
import { ISuccessMessage, IRequestUserDTO, IConstants } from '@digitaldefiance/suite-core-lib';
|
|
6
|
+
import { PaletteMode } from '@mui/material';
|
|
6
7
|
export interface AuthContextData {
|
|
7
8
|
/**
|
|
8
9
|
* True if the user has a global admin role
|
|
@@ -47,7 +48,8 @@ export interface AuthContextData {
|
|
|
47
48
|
}>;
|
|
48
49
|
clearMnemonic: () => void;
|
|
49
50
|
clearWallet: () => void;
|
|
50
|
-
|
|
51
|
+
colorMode?: PaletteMode;
|
|
52
|
+
currencyCode?: CurrencyCode;
|
|
51
53
|
directLogin: (mnemonic: SecureString, username?: string, email?: EmailString, expireMnemonicSeconds?: number, expireWalletSeconds?: number) => Promise<{
|
|
52
54
|
token: string;
|
|
53
55
|
user: IRequestUserDTO;
|
|
@@ -103,7 +105,8 @@ export interface AuthContextData {
|
|
|
103
105
|
}>;
|
|
104
106
|
}>;
|
|
105
107
|
serverPublicKey: string | null;
|
|
106
|
-
|
|
108
|
+
setColorMode: (mode?: PaletteMode) => Promise<void>;
|
|
109
|
+
setCurrencyCode: (code?: CurrencyCode) => Promise<void>;
|
|
107
110
|
/**
|
|
108
111
|
* Gets the remaining time in seconds for the mnemonic expiration
|
|
109
112
|
* @returns Number of seconds remaining, or 0 if no mnemonic is set
|
|
@@ -117,6 +120,7 @@ export interface AuthContextData {
|
|
|
117
120
|
setLanguage: (lang: string) => Promise<void>;
|
|
118
121
|
setMnemonic: (mnemonic: SecureString, durationSeconds?: number) => void;
|
|
119
122
|
setMnemonicExpirationSeconds: (seconds: number) => void;
|
|
123
|
+
setTimezone: (timezone?: Timezone) => Promise<void>;
|
|
120
124
|
setWalletExpirationSeconds: (seconds: number) => void;
|
|
121
125
|
setUpPasswordLogin: (mnemonic: SecureString, password: SecureString, username?: string, email?: EmailString) => Promise<{
|
|
122
126
|
success: boolean;
|
|
@@ -127,8 +131,10 @@ export interface AuthContextData {
|
|
|
127
131
|
}>;
|
|
128
132
|
setUser: (user: IRequestUserDTO | null) => Promise<void>;
|
|
129
133
|
setWallet: (wallet: Wallet, durationSeconds?: number) => void;
|
|
134
|
+
toggleColorMode: () => Promise<void>;
|
|
130
135
|
user: FrontendMember | null;
|
|
131
136
|
userData: IRequestUserDTO | null;
|
|
137
|
+
timezone?: Timezone;
|
|
132
138
|
token: string | null;
|
|
133
139
|
wallet?: Wallet;
|
|
134
140
|
walletExpirationSeconds: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/contexts/AuthProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,cAAc,EAE/B,WAAW,EACX,YAAY,EACZ,YAAY,EAIb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,YAAY,
|
|
1
|
+
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/contexts/AuthProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,cAAc,EAE/B,WAAW,EACX,YAAY,EACZ,YAAY,EAIb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,YAAY,EAEZ,QAAQ,EACT,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAEL,SAAS,EAMV,MAAM,OAAO,CAAC;AAOf,OAAO,EAAE,eAAe,EAAE,eAAe,EAA4C,UAAU,EAAE,MAAM,iCAAiC,CAAC;AACzI,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;;;OAQG;IACH,eAAe,EAAE,CACf,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,eAAe,EAAE,OAAO,EACxB,WAAW,CAAC,EAAE,MAAM,KACjB,OAAO,CACR;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GACzE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CACrC,CAAC;IACF;;;OAGG;IACH,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB;;;;;OAKG;IACH,cAAc,EAAE,CACd,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,KAChB,OAAO,CACR,eAAe,GACf;QACE,KAAK,EAAE,MAAM,CAAC;QACd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AC;IACjC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uBAAuB,EAAE,MAAM,CAAC;IAChC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAClD;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,UAAU,CAAC;IACtB,WAAW,EAAE,YAAY,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,WAAW,0CAEvB,CAAC;AAolBF,eAAO,MAAM,YAAY,GAAI,yDAAyD,iBAAiB,4CAMtG,CAAC;AAEF,eAAO,MAAM,OAAO,uBAEnB,CAAC"}
|
|
@@ -15,7 +15,7 @@ const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
|
15
15
|
exports.AuthContext = (0, react_1.createContext)({});
|
|
16
16
|
const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout }) => {
|
|
17
17
|
const { changeLanguage, currentLanguage, t, tComponent } = (0, I18nProvider_1.useI18n)();
|
|
18
|
-
const { setColorMode } = (0, ThemeProvider_1.useTheme)();
|
|
18
|
+
const { setColorMode: themeSetPaletteMode } = (0, ThemeProvider_1.useTheme)();
|
|
19
19
|
const authService = (0, react_1.useMemo)(() => (0, authService_1.createAuthService)(constants, baseUrl, eciesConfig), [constants, baseUrl, eciesConfig]);
|
|
20
20
|
const authenticatedApi = (0, react_1.useMemo)(() => (0, authenticatedApi_1.createAuthenticatedApiClient)(baseUrl), [baseUrl]);
|
|
21
21
|
// Use the custom hooks for expiring values
|
|
@@ -34,9 +34,44 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
34
34
|
const [isCheckingAuth, setIsCheckingAuth] = (0, react_1.useState)(true);
|
|
35
35
|
const [token, setToken] = (0, react_1.useState)(null);
|
|
36
36
|
const [authState, setAuthState] = (0, react_1.useState)(0);
|
|
37
|
+
const [colorMode, setColorMode] = (0, react_1.useState)(() => {
|
|
38
|
+
return localStorage.getItem('colorMode') ?? 'light';
|
|
39
|
+
});
|
|
37
40
|
const [currencyCode, setCurrencyCode] = (0, react_1.useState)(() => {
|
|
38
41
|
return new i18n_lib_1.CurrencyCode(localStorage.getItem('currencyCode') ?? i18n_lib_1.DefaultCurrencyCode);
|
|
39
42
|
});
|
|
43
|
+
const [timezone, setTimezone] = (0, react_1.useState)(() => {
|
|
44
|
+
return new i18n_lib_1.Timezone(localStorage.getItem('timezone') ?? 'UTC');
|
|
45
|
+
});
|
|
46
|
+
const setColorModeAndUpdateStorage = (0, react_1.useCallback)(async (mode) => {
|
|
47
|
+
themeSetPaletteMode(mode ?? 'light');
|
|
48
|
+
setColorMode(mode ?? 'light');
|
|
49
|
+
if (!mode) {
|
|
50
|
+
localStorage.removeItem('colorMode');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
localStorage.setItem('colorMode', mode);
|
|
54
|
+
}, [themeSetPaletteMode]);
|
|
55
|
+
const setCurrencyCodeAndUpdateStorage = (0, react_1.useCallback)(async (code) => {
|
|
56
|
+
setCurrencyCode(code);
|
|
57
|
+
if (!code) {
|
|
58
|
+
localStorage.removeItem('currencyCode');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
localStorage.setItem('currencyCode', code.value);
|
|
62
|
+
}, []);
|
|
63
|
+
const setTimezoneAndUpdateStorage = (0, react_1.useCallback)(async (code) => {
|
|
64
|
+
setTimezone(code);
|
|
65
|
+
if (!code) {
|
|
66
|
+
localStorage.removeItem('timezone');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
localStorage.setItem('timezone', code.value);
|
|
70
|
+
}, []);
|
|
71
|
+
const toggleColorMode = (0, react_1.useCallback)(async () => {
|
|
72
|
+
const newMode = colorMode === 'light' ? 'dark' : 'light';
|
|
73
|
+
await setColorModeAndUpdateStorage(newMode);
|
|
74
|
+
}, [colorMode, setColorModeAndUpdateStorage]);
|
|
40
75
|
// Helper functions to calculate remaining time (now provided by the hooks)
|
|
41
76
|
const getMnemonicRemainingTime = mnemonicManager.getRemainingTime;
|
|
42
77
|
const getWalletRemainingTime = walletManager.getRemainingTime;
|
|
@@ -84,6 +119,9 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
84
119
|
setToken(null);
|
|
85
120
|
setFrontendUser(null);
|
|
86
121
|
setServerPublicKey(null);
|
|
122
|
+
setTimezone(undefined);
|
|
123
|
+
setCurrencyCode(undefined);
|
|
124
|
+
themeSetPaletteMode('light');
|
|
87
125
|
clearMnemonic();
|
|
88
126
|
clearWallet();
|
|
89
127
|
return;
|
|
@@ -100,7 +138,9 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
100
138
|
setIsAuthenticated(true);
|
|
101
139
|
setToken(token);
|
|
102
140
|
// Set theme based on user's darkMode preference
|
|
103
|
-
|
|
141
|
+
setColorModeAndUpdateStorage(userData.darkMode ? 'dark' : 'light');
|
|
142
|
+
setCurrencyCodeAndUpdateStorage(new i18n_lib_1.CurrencyCode(userData.currency));
|
|
143
|
+
setTimezoneAndUpdateStorage(new i18n_lib_1.Timezone(userData.timezone));
|
|
104
144
|
}
|
|
105
145
|
}
|
|
106
146
|
catch (error) {
|
|
@@ -113,7 +153,7 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
113
153
|
setLoading(false);
|
|
114
154
|
setIsCheckingAuth(false);
|
|
115
155
|
}
|
|
116
|
-
}, [authService, clearMnemonic, clearWallet,
|
|
156
|
+
}, [authService, clearMnemonic, clearWallet, setColorModeAndUpdateStorage, setCurrencyCodeAndUpdateStorage, setTimezoneAndUpdateStorage]);
|
|
117
157
|
(0, react_1.useEffect)(() => {
|
|
118
158
|
const token = localStorage.getItem('authToken');
|
|
119
159
|
if (token) {
|
|
@@ -142,11 +182,13 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
142
182
|
localStorage.setItem('authToken', loginResult.token);
|
|
143
183
|
localStorage.setItem('user', JSON.stringify(loginResult.user));
|
|
144
184
|
// Set theme based on user's darkMode preference
|
|
145
|
-
|
|
185
|
+
setColorModeAndUpdateStorage(loginResult.user.darkMode ? 'dark' : 'light');
|
|
186
|
+
setCurrencyCodeAndUpdateStorage(new i18n_lib_1.CurrencyCode(loginResult.user.currency));
|
|
187
|
+
setTimezoneAndUpdateStorage(new i18n_lib_1.Timezone(loginResult.user.timezone));
|
|
146
188
|
return loginResult;
|
|
147
189
|
}
|
|
148
190
|
return loginResult;
|
|
149
|
-
}, [authService, setMnemonic, setWallet,
|
|
191
|
+
}, [authService, setMnemonic, setWallet, setColorModeAndUpdateStorage, setCurrencyCodeAndUpdateStorage, setTimezoneAndUpdateStorage]);
|
|
150
192
|
const emailChallengeLogin = (0, react_1.useCallback)(async (mnemonic, token, username, email, expireMnemonicSeconds, expireWalletSeconds) => {
|
|
151
193
|
setLoading(true);
|
|
152
194
|
const loginResult = await authService.emailChallengeLogin(mnemonic, token, username, email);
|
|
@@ -163,11 +205,13 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
163
205
|
localStorage.setItem('authToken', loginResult.token);
|
|
164
206
|
localStorage.setItem('user', JSON.stringify(loginResult.user));
|
|
165
207
|
// Set theme based on user's darkMode preference
|
|
166
|
-
|
|
208
|
+
setColorModeAndUpdateStorage(loginResult.user.darkMode ? 'dark' : 'light');
|
|
209
|
+
setCurrencyCodeAndUpdateStorage(new i18n_lib_1.CurrencyCode(loginResult.user.currency));
|
|
210
|
+
setTimezoneAndUpdateStorage(new i18n_lib_1.Timezone(loginResult.user.timezone));
|
|
167
211
|
return loginResult;
|
|
168
212
|
}
|
|
169
213
|
return loginResult;
|
|
170
|
-
}, [authService, setMnemonic, setWallet,
|
|
214
|
+
}, [authService, setMnemonic, setWallet, setColorModeAndUpdateStorage, setCurrencyCodeAndUpdateStorage, setTimezoneAndUpdateStorage]);
|
|
171
215
|
const getPasswordLoginService = (0, react_1.useCallback)(() => {
|
|
172
216
|
const eciesService = new ecies_lib_1.ECIESService(eciesConfig);
|
|
173
217
|
return new ecies_lib_1.PasswordLoginService(eciesService, new ecies_lib_1.Pbkdf2Service(ecies_lib_1.Constants.PBKDF2_PROFILES, ecies_lib_1.Constants.ECIES, ecies_lib_1.Constants.PBKDF2));
|
|
@@ -189,10 +233,12 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
189
233
|
setMnemonic(mnemonic);
|
|
190
234
|
// Set theme based on user's darkMode preference if login succeeded
|
|
191
235
|
if ('user' in loginResult) {
|
|
192
|
-
|
|
236
|
+
setColorModeAndUpdateStorage(loginResult.user.darkMode ? 'dark' : 'light');
|
|
237
|
+
setCurrencyCodeAndUpdateStorage(new i18n_lib_1.CurrencyCode(loginResult.user.currency));
|
|
238
|
+
setTimezoneAndUpdateStorage(new i18n_lib_1.Timezone(loginResult.user.timezone));
|
|
193
239
|
}
|
|
194
240
|
return loginResult;
|
|
195
|
-
}, [authService, getPasswordLoginService, setMnemonic, setWallet, t, tComponent, isPasswordLoginAvailable,
|
|
241
|
+
}, [authService, getPasswordLoginService, setMnemonic, setWallet, t, tComponent, isPasswordLoginAvailable, setColorModeAndUpdateStorage, setCurrencyCodeAndUpdateStorage, setTimezoneAndUpdateStorage]);
|
|
196
242
|
const refreshToken = (0, react_1.useCallback)(async () => {
|
|
197
243
|
try {
|
|
198
244
|
const result = await authService.refreshToken();
|
|
@@ -245,7 +291,9 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
245
291
|
setUser(loginResult.user);
|
|
246
292
|
setIsAuthenticated(true);
|
|
247
293
|
// Set theme based on user's darkMode preference
|
|
248
|
-
|
|
294
|
+
setColorModeAndUpdateStorage(loginResult.user.darkMode ? 'dark' : 'light');
|
|
295
|
+
setCurrencyCodeAndUpdateStorage(new i18n_lib_1.CurrencyCode(loginResult.user.currency));
|
|
296
|
+
setTimezoneAndUpdateStorage(new i18n_lib_1.Timezone(loginResult.user.timezone));
|
|
249
297
|
}
|
|
250
298
|
setAuthState((prev) => prev + 1);
|
|
251
299
|
return {
|
|
@@ -256,7 +304,7 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
256
304
|
};
|
|
257
305
|
}
|
|
258
306
|
return loginResult;
|
|
259
|
-
}, [baseUrl,
|
|
307
|
+
}, [baseUrl, setColorModeAndUpdateStorage, setCurrencyCodeAndUpdateStorage, setTimezoneAndUpdateStorage]);
|
|
260
308
|
const logout = (0, react_1.useCallback)(async () => {
|
|
261
309
|
localStorage.removeItem('user');
|
|
262
310
|
localStorage.removeItem('authToken');
|
|
@@ -264,6 +312,9 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
264
312
|
setUser(null);
|
|
265
313
|
clearWallet();
|
|
266
314
|
setIsAuthenticated(false);
|
|
315
|
+
setColorMode('light');
|
|
316
|
+
setTimezone(undefined);
|
|
317
|
+
setCurrencyCode(undefined);
|
|
267
318
|
setAuthState((prev) => prev + 1);
|
|
268
319
|
// Call the optional navigation callback if provided
|
|
269
320
|
if (onLogout) {
|
|
@@ -274,6 +325,9 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
274
325
|
const requestUser = await authService.verifyToken(token);
|
|
275
326
|
if (typeof requestUser === 'object' && 'error' in requestUser) {
|
|
276
327
|
setIsAuthenticated(false);
|
|
328
|
+
setColorMode('light');
|
|
329
|
+
setTimezone(undefined);
|
|
330
|
+
setCurrencyCode(undefined);
|
|
277
331
|
return false;
|
|
278
332
|
}
|
|
279
333
|
else {
|
|
@@ -324,10 +378,6 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
324
378
|
}
|
|
325
379
|
}
|
|
326
380
|
};
|
|
327
|
-
const setCurrencyCodeAndUpdateStorage = async (code) => {
|
|
328
|
-
setCurrencyCode(code);
|
|
329
|
-
localStorage.setItem('currencyCode', code.value);
|
|
330
|
-
};
|
|
331
381
|
return {
|
|
332
382
|
admin: isGlobalAdmin,
|
|
333
383
|
authState,
|
|
@@ -336,6 +386,7 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
336
386
|
checkAuth,
|
|
337
387
|
clearMnemonic,
|
|
338
388
|
clearWallet,
|
|
389
|
+
colorMode,
|
|
339
390
|
currencyCode,
|
|
340
391
|
directLogin,
|
|
341
392
|
emailChallengeLogin,
|
|
@@ -354,14 +405,18 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
354
405
|
register,
|
|
355
406
|
requestEmailLogin,
|
|
356
407
|
serverPublicKey,
|
|
408
|
+
setColorMode: setColorModeAndUpdateStorage,
|
|
357
409
|
setCurrencyCode: setCurrencyCodeAndUpdateStorage,
|
|
358
410
|
setLanguage: setLanguageAndUpdateUser,
|
|
359
411
|
setMnemonic,
|
|
360
412
|
setMnemonicExpirationSeconds,
|
|
361
413
|
setUpPasswordLogin,
|
|
362
414
|
setUser: setUserAndLanguage,
|
|
415
|
+
setTimezone: setTimezoneAndUpdateStorage,
|
|
363
416
|
setWallet,
|
|
364
417
|
setWalletExpirationSeconds,
|
|
418
|
+
timezone,
|
|
419
|
+
toggleColorMode,
|
|
365
420
|
token,
|
|
366
421
|
user: frontendUser,
|
|
367
422
|
userData: user,
|
|
@@ -378,6 +433,7 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
378
433
|
checkAuth,
|
|
379
434
|
clearMnemonic,
|
|
380
435
|
clearWallet,
|
|
436
|
+
colorMode,
|
|
381
437
|
currencyCode,
|
|
382
438
|
currentLanguage,
|
|
383
439
|
directLogin,
|
|
@@ -398,11 +454,16 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
398
454
|
register,
|
|
399
455
|
requestEmailLogin,
|
|
400
456
|
serverPublicKey,
|
|
457
|
+
setColorModeAndUpdateStorage,
|
|
458
|
+
setCurrencyCodeAndUpdateStorage,
|
|
401
459
|
setMnemonic,
|
|
402
460
|
setMnemonicExpirationSeconds,
|
|
403
461
|
setUpPasswordLogin,
|
|
462
|
+
setTimezoneAndUpdateStorage,
|
|
404
463
|
setWallet,
|
|
405
464
|
setWalletExpirationSeconds,
|
|
465
|
+
timezone,
|
|
466
|
+
toggleColorMode,
|
|
406
467
|
token,
|
|
407
468
|
user,
|
|
408
469
|
verifyToken,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUserSettings.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/hooks/useUserSettings.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUserSettings.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-express-suite-react-components/src/hooks/useUserSettings.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACpC,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,cAAc,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC;QACtD,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;KACjB,GAAG;QACF,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC/C,CAAC,CAAC;IACH,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAED,eAAO,MAAM,eAAe,QAAO,qBA+FlC,CAAC"}
|
|
@@ -5,6 +5,7 @@ const react_1 = require("react");
|
|
|
5
5
|
const services_1 = require("../services");
|
|
6
6
|
const contexts_1 = require("../contexts");
|
|
7
7
|
const contexts_2 = require("../contexts");
|
|
8
|
+
const i18n_lib_1 = require("@digitaldefiance/i18n-lib");
|
|
8
9
|
const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
|
|
9
10
|
const useUserSettings = () => {
|
|
10
11
|
const { baseUrl } = (0, contexts_1.useSuiteConfig)();
|
|
@@ -63,7 +64,7 @@ const useUserSettings = () => {
|
|
|
63
64
|
const result = await api.post('/user/settings', values);
|
|
64
65
|
// Update context values
|
|
65
66
|
if (values.currency) {
|
|
66
|
-
await setCurrencyCode(values.currency);
|
|
67
|
+
await setCurrencyCode(new i18n_lib_1.CurrencyCode(values.currency));
|
|
67
68
|
}
|
|
68
69
|
if (values.siteLanguage) {
|
|
69
70
|
await setLanguage(values.siteLanguage);
|