@digitaldefiance/express-suite-react-components 2.5.2 → 2.5.4
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitaldefiance/express-suite-react-components",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.4",
|
|
4
4
|
"description": "React MUI components for Digital Defiance Express Suite",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"react-router-dom": "6.29.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@digitaldefiance/i18n-lib": "3.6.
|
|
29
|
-
"@digitaldefiance/suite-core-lib": "^2.2.
|
|
28
|
+
"@digitaldefiance/i18n-lib": "3.6.3",
|
|
29
|
+
"@digitaldefiance/suite-core-lib": "^2.2.20",
|
|
30
30
|
"@emotion/react": "^11.14.0",
|
|
31
31
|
"@emotion/styled": "^11.14.0",
|
|
32
32
|
"@mui/icons-material": "^7.0.2",
|
|
@@ -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;
|
|
@@ -129,6 +133,7 @@ export interface AuthContextData {
|
|
|
129
133
|
setWallet: (wallet: Wallet, durationSeconds?: number) => void;
|
|
130
134
|
user: FrontendMember | null;
|
|
131
135
|
userData: IRequestUserDTO | null;
|
|
136
|
+
timezone?: Timezone;
|
|
132
137
|
token: string | null;
|
|
133
138
|
wallet?: Wallet;
|
|
134
139
|
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,SA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EAAE,MAAM,KAAK,IAAI,CAAC;IAC9D,IAAI,EAAE,cAAc,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;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;AA4kBF,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,40 @@ 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 = 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
|
+
};
|
|
55
|
+
const setCurrencyCodeAndUpdateStorage = 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 = async (code) => {
|
|
64
|
+
setTimezone(code);
|
|
65
|
+
if (!code) {
|
|
66
|
+
localStorage.removeItem('timezone');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
localStorage.setItem('timezone', code.value);
|
|
70
|
+
};
|
|
40
71
|
// Helper functions to calculate remaining time (now provided by the hooks)
|
|
41
72
|
const getMnemonicRemainingTime = mnemonicManager.getRemainingTime;
|
|
42
73
|
const getWalletRemainingTime = walletManager.getRemainingTime;
|
|
@@ -84,6 +115,9 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
84
115
|
setToken(null);
|
|
85
116
|
setFrontendUser(null);
|
|
86
117
|
setServerPublicKey(null);
|
|
118
|
+
setTimezone(undefined);
|
|
119
|
+
setCurrencyCode(undefined);
|
|
120
|
+
themeSetPaletteMode('light');
|
|
87
121
|
clearMnemonic();
|
|
88
122
|
clearWallet();
|
|
89
123
|
return;
|
|
@@ -100,7 +134,9 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
100
134
|
setIsAuthenticated(true);
|
|
101
135
|
setToken(token);
|
|
102
136
|
// Set theme based on user's darkMode preference
|
|
103
|
-
|
|
137
|
+
setColorModeAndUpdateStorage(userData.darkMode ? 'dark' : 'light');
|
|
138
|
+
setCurrencyCodeAndUpdateStorage(new i18n_lib_1.CurrencyCode(userData.currency));
|
|
139
|
+
setTimezoneAndUpdateStorage(new i18n_lib_1.Timezone(userData.timezone));
|
|
104
140
|
}
|
|
105
141
|
}
|
|
106
142
|
catch (error) {
|
|
@@ -113,7 +149,7 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
113
149
|
setLoading(false);
|
|
114
150
|
setIsCheckingAuth(false);
|
|
115
151
|
}
|
|
116
|
-
}, [authService, clearMnemonic, clearWallet,
|
|
152
|
+
}, [authService, clearMnemonic, clearWallet, setColorModeAndUpdateStorage, setCurrencyCodeAndUpdateStorage, setTimezoneAndUpdateStorage]);
|
|
117
153
|
(0, react_1.useEffect)(() => {
|
|
118
154
|
const token = localStorage.getItem('authToken');
|
|
119
155
|
if (token) {
|
|
@@ -142,11 +178,13 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
142
178
|
localStorage.setItem('authToken', loginResult.token);
|
|
143
179
|
localStorage.setItem('user', JSON.stringify(loginResult.user));
|
|
144
180
|
// Set theme based on user's darkMode preference
|
|
145
|
-
|
|
181
|
+
setColorModeAndUpdateStorage(loginResult.user.darkMode ? 'dark' : 'light');
|
|
182
|
+
setCurrencyCodeAndUpdateStorage(new i18n_lib_1.CurrencyCode(loginResult.user.currency));
|
|
183
|
+
setTimezoneAndUpdateStorage(new i18n_lib_1.Timezone(loginResult.user.timezone));
|
|
146
184
|
return loginResult;
|
|
147
185
|
}
|
|
148
186
|
return loginResult;
|
|
149
|
-
}, [authService, setMnemonic, setWallet,
|
|
187
|
+
}, [authService, setMnemonic, setWallet, setColorModeAndUpdateStorage, setCurrencyCodeAndUpdateStorage, setTimezoneAndUpdateStorage]);
|
|
150
188
|
const emailChallengeLogin = (0, react_1.useCallback)(async (mnemonic, token, username, email, expireMnemonicSeconds, expireWalletSeconds) => {
|
|
151
189
|
setLoading(true);
|
|
152
190
|
const loginResult = await authService.emailChallengeLogin(mnemonic, token, username, email);
|
|
@@ -163,11 +201,13 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
163
201
|
localStorage.setItem('authToken', loginResult.token);
|
|
164
202
|
localStorage.setItem('user', JSON.stringify(loginResult.user));
|
|
165
203
|
// Set theme based on user's darkMode preference
|
|
166
|
-
|
|
204
|
+
setColorModeAndUpdateStorage(loginResult.user.darkMode ? 'dark' : 'light');
|
|
205
|
+
setCurrencyCodeAndUpdateStorage(new i18n_lib_1.CurrencyCode(loginResult.user.currency));
|
|
206
|
+
setTimezoneAndUpdateStorage(new i18n_lib_1.Timezone(loginResult.user.timezone));
|
|
167
207
|
return loginResult;
|
|
168
208
|
}
|
|
169
209
|
return loginResult;
|
|
170
|
-
}, [authService, setMnemonic, setWallet,
|
|
210
|
+
}, [authService, setMnemonic, setWallet, setColorModeAndUpdateStorage, setCurrencyCodeAndUpdateStorage, setTimezoneAndUpdateStorage]);
|
|
171
211
|
const getPasswordLoginService = (0, react_1.useCallback)(() => {
|
|
172
212
|
const eciesService = new ecies_lib_1.ECIESService(eciesConfig);
|
|
173
213
|
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 +229,12 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
189
229
|
setMnemonic(mnemonic);
|
|
190
230
|
// Set theme based on user's darkMode preference if login succeeded
|
|
191
231
|
if ('user' in loginResult) {
|
|
192
|
-
|
|
232
|
+
setColorModeAndUpdateStorage(loginResult.user.darkMode ? 'dark' : 'light');
|
|
233
|
+
setCurrencyCodeAndUpdateStorage(new i18n_lib_1.CurrencyCode(loginResult.user.currency));
|
|
234
|
+
setTimezoneAndUpdateStorage(new i18n_lib_1.Timezone(loginResult.user.timezone));
|
|
193
235
|
}
|
|
194
236
|
return loginResult;
|
|
195
|
-
}, [authService, getPasswordLoginService, setMnemonic, setWallet, t, tComponent, isPasswordLoginAvailable,
|
|
237
|
+
}, [authService, getPasswordLoginService, setMnemonic, setWallet, t, tComponent, isPasswordLoginAvailable, setColorModeAndUpdateStorage, setCurrencyCodeAndUpdateStorage, setTimezoneAndUpdateStorage]);
|
|
196
238
|
const refreshToken = (0, react_1.useCallback)(async () => {
|
|
197
239
|
try {
|
|
198
240
|
const result = await authService.refreshToken();
|
|
@@ -245,7 +287,9 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
245
287
|
setUser(loginResult.user);
|
|
246
288
|
setIsAuthenticated(true);
|
|
247
289
|
// Set theme based on user's darkMode preference
|
|
248
|
-
|
|
290
|
+
setColorModeAndUpdateStorage(loginResult.user.darkMode ? 'dark' : 'light');
|
|
291
|
+
setCurrencyCodeAndUpdateStorage(new i18n_lib_1.CurrencyCode(loginResult.user.currency));
|
|
292
|
+
setTimezoneAndUpdateStorage(new i18n_lib_1.Timezone(loginResult.user.timezone));
|
|
249
293
|
}
|
|
250
294
|
setAuthState((prev) => prev + 1);
|
|
251
295
|
return {
|
|
@@ -256,7 +300,7 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
256
300
|
};
|
|
257
301
|
}
|
|
258
302
|
return loginResult;
|
|
259
|
-
}, [baseUrl,
|
|
303
|
+
}, [baseUrl, setColorModeAndUpdateStorage, setCurrencyCodeAndUpdateStorage, setTimezoneAndUpdateStorage]);
|
|
260
304
|
const logout = (0, react_1.useCallback)(async () => {
|
|
261
305
|
localStorage.removeItem('user');
|
|
262
306
|
localStorage.removeItem('authToken');
|
|
@@ -264,6 +308,9 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
264
308
|
setUser(null);
|
|
265
309
|
clearWallet();
|
|
266
310
|
setIsAuthenticated(false);
|
|
311
|
+
setColorMode('light');
|
|
312
|
+
setTimezone(undefined);
|
|
313
|
+
setCurrencyCode(undefined);
|
|
267
314
|
setAuthState((prev) => prev + 1);
|
|
268
315
|
// Call the optional navigation callback if provided
|
|
269
316
|
if (onLogout) {
|
|
@@ -274,6 +321,9 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
274
321
|
const requestUser = await authService.verifyToken(token);
|
|
275
322
|
if (typeof requestUser === 'object' && 'error' in requestUser) {
|
|
276
323
|
setIsAuthenticated(false);
|
|
324
|
+
setColorMode('light');
|
|
325
|
+
setTimezone(undefined);
|
|
326
|
+
setCurrencyCode(undefined);
|
|
277
327
|
return false;
|
|
278
328
|
}
|
|
279
329
|
else {
|
|
@@ -324,10 +374,6 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
324
374
|
}
|
|
325
375
|
}
|
|
326
376
|
};
|
|
327
|
-
const setCurrencyCodeAndUpdateStorage = async (code) => {
|
|
328
|
-
setCurrencyCode(code);
|
|
329
|
-
localStorage.setItem('currencyCode', code.value);
|
|
330
|
-
};
|
|
331
377
|
return {
|
|
332
378
|
admin: isGlobalAdmin,
|
|
333
379
|
authState,
|
|
@@ -336,6 +382,7 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
336
382
|
checkAuth,
|
|
337
383
|
clearMnemonic,
|
|
338
384
|
clearWallet,
|
|
385
|
+
colorMode,
|
|
339
386
|
currencyCode,
|
|
340
387
|
directLogin,
|
|
341
388
|
emailChallengeLogin,
|
|
@@ -354,14 +401,17 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
354
401
|
register,
|
|
355
402
|
requestEmailLogin,
|
|
356
403
|
serverPublicKey,
|
|
404
|
+
setColorMode: setColorModeAndUpdateStorage,
|
|
357
405
|
setCurrencyCode: setCurrencyCodeAndUpdateStorage,
|
|
358
406
|
setLanguage: setLanguageAndUpdateUser,
|
|
359
407
|
setMnemonic,
|
|
360
408
|
setMnemonicExpirationSeconds,
|
|
361
409
|
setUpPasswordLogin,
|
|
362
410
|
setUser: setUserAndLanguage,
|
|
411
|
+
setTimezone: setTimezoneAndUpdateStorage,
|
|
363
412
|
setWallet,
|
|
364
413
|
setWalletExpirationSeconds,
|
|
414
|
+
timezone,
|
|
365
415
|
token,
|
|
366
416
|
user: frontendUser,
|
|
367
417
|
userData: user,
|
|
@@ -378,6 +428,7 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
378
428
|
checkAuth,
|
|
379
429
|
clearMnemonic,
|
|
380
430
|
clearWallet,
|
|
431
|
+
colorMode,
|
|
381
432
|
currencyCode,
|
|
382
433
|
currentLanguage,
|
|
383
434
|
directLogin,
|
|
@@ -398,11 +449,14 @@ const AuthProviderInner = ({ children, baseUrl, constants, eciesConfig, onLogout
|
|
|
398
449
|
register,
|
|
399
450
|
requestEmailLogin,
|
|
400
451
|
serverPublicKey,
|
|
452
|
+
setColorMode, ,
|
|
401
453
|
setMnemonic,
|
|
402
454
|
setMnemonicExpirationSeconds,
|
|
403
455
|
setUpPasswordLogin,
|
|
456
|
+
setTimezone,
|
|
404
457
|
setWallet,
|
|
405
458
|
setWalletExpirationSeconds,
|
|
459
|
+
timezone,
|
|
406
460
|
token,
|
|
407
461
|
user,
|
|
408
462
|
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);
|