@dynamic-labs/sdk-react-core 4.35.0 → 4.36.0

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.
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  const CLIENT_SESSION_KEYS = 'dynamic_client_session_keys';
7
7
  const CLIENT_SESSION_KEYS_STORAGE_OPTIONS = {
8
- priority: ['secureStorage', 'sessionStorage'],
8
+ priority: ['secureStorage', 'localStorage'],
9
9
  };
10
10
  const SECURE_ENCLAVE_WALLET_SESSION_KEYS = 'dynamic_secure_enclave_session_keys';
11
11
  const SECURE_ENCLAVE_WALLET_SESSION_KEYS_STORAGE_OPTIONS = {
@@ -1,7 +1,7 @@
1
1
  'use client'
2
2
  const CLIENT_SESSION_KEYS = 'dynamic_client_session_keys';
3
3
  const CLIENT_SESSION_KEYS_STORAGE_OPTIONS = {
4
- priority: ['secureStorage', 'sessionStorage'],
4
+ priority: ['secureStorage', 'localStorage'],
5
5
  };
6
6
  const SECURE_ENCLAVE_WALLET_SESSION_KEYS = 'dynamic_secure_enclave_session_keys';
7
7
  const SECURE_ENCLAVE_WALLET_SESSION_KEYS_STORAGE_OPTIONS = {
@@ -98,8 +98,8 @@ require('../../../context/PasskeyContext/PasskeyContext.cjs');
98
98
  require('../../../context/OnrampContext/OnrampContext.cjs');
99
99
  var apiUrl = require('../../constants/waas/apiUrl.cjs');
100
100
  var useClientSessionKeys = require('../useClientSessionKeys/useClientSessionKeys.cjs');
101
- var useRefreshUser = require('../useRefreshUser/useRefreshUser.cjs');
102
101
  var useGetMfaToken = require('../useGetMfaToken/useGetMfaToken.cjs');
102
+ var useRefreshUser = require('../useRefreshUser/useRefreshUser.cjs');
103
103
  var constants = require('./constants.cjs');
104
104
  require('../../../store/state/sendBalances.cjs');
105
105
  require('../../../store/state/connectorsInitializing/connectorsInitializing.cjs');
@@ -366,6 +366,58 @@ const useDynamicWaas = () => {
366
366
  });
367
367
  }), [getWalletConnector]);
368
368
  const getWaasWallets = React.useCallback(() => userWallets.filter((w) => w.key === 'dynamicwaas'), [userWallets]);
369
+ const processSignOnWalletSettings = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
370
+ var _g;
371
+ if (!(user === null || user === void 0 ? void 0 : user.verifiedCredentials)) {
372
+ return;
373
+ }
374
+ const waasWallets = user.verifiedCredentials.filter((vc) => { var _a; return vc.walletName === 'dynamicwaas' && ((_a = vc.walletProperties) === null || _a === void 0 ? void 0 : _a.settings); });
375
+ for (const wallet of waasWallets) {
376
+ try {
377
+ const settings = (_g = wallet.walletProperties) === null || _g === void 0 ? void 0 : _g.settings;
378
+ const { address, chain } = wallet;
379
+ if (!settings || !address || !chain) {
380
+ continue;
381
+ }
382
+ const { shouldRefreshOnNextSignOn, reshareOnNextSignOn } = settings;
383
+ const chainName = values.VerifiedCredentialNameToChainEnum[chain];
384
+ const walletConnector = getWalletConnector(chainName);
385
+ if (!walletConnector) {
386
+ continue;
387
+ }
388
+ if (shouldRefreshOnNextSignOn) {
389
+ yield walletConnector.refreshWalletAccountShares({
390
+ accountAddress: address,
391
+ });
392
+ }
393
+ if (reshareOnNextSignOn) {
394
+ yield walletConnector.reshareWalletAccountShares({
395
+ accountAddress: address,
396
+ thresholdSignatureScheme: reshareOnNextSignOn,
397
+ });
398
+ }
399
+ }
400
+ catch (error) {
401
+ walletConnectorCore.logger.error('Failed to process wallet settings:', {
402
+ error,
403
+ wallet,
404
+ });
405
+ }
406
+ }
407
+ yield refresh();
408
+ }), [user, getWalletConnector, refresh]);
409
+ const needsSettingsProcessing = React.useMemo(() => {
410
+ if (!(user === null || user === void 0 ? void 0 : user.verifiedCredentials) || !dynamicWaasIsEnabled) {
411
+ return false;
412
+ }
413
+ return user.verifiedCredentials.some((vc) => {
414
+ var _a;
415
+ return vc.walletName === 'dynamicwaas' &&
416
+ ((_a = vc.walletProperties) === null || _a === void 0 ? void 0 : _a.settings) &&
417
+ (vc.walletProperties.settings.shouldRefreshOnNextSignOn ||
418
+ vc.walletProperties.settings.reshareOnNextSignOn);
419
+ });
420
+ }, [user, dynamicWaasIsEnabled]);
369
421
  return {
370
422
  createWalletAccount,
371
423
  delegateKeyShares,
@@ -374,6 +426,8 @@ const useDynamicWaas = () => {
374
426
  getWalletConnector,
375
427
  importPrivateKey,
376
428
  needsAutoCreateWalletChains,
429
+ needsSettingsProcessing,
430
+ processSignOnWalletSettings,
377
431
  upgradeToDynamicWaas,
378
432
  };
379
433
  };
@@ -31,6 +31,8 @@ export declare const useDynamicWaas: () => {
31
31
  privateKey: string;
32
32
  }) => Promise<void>;
33
33
  needsAutoCreateWalletChains: ChainEnum[];
34
+ needsSettingsProcessing: boolean;
35
+ processSignOnWalletSettings: () => Promise<void>;
34
36
  upgradeToDynamicWaas: ({ privateKey, wallet, }: {
35
37
  privateKey: string;
36
38
  wallet: Wallet<WalletConnectorCore.WalletConnector>;
@@ -94,8 +94,8 @@ import '../../../context/PasskeyContext/PasskeyContext.js';
94
94
  import '../../../context/OnrampContext/OnrampContext.js';
95
95
  import { DEFAULT_WAAS_API_URL } from '../../constants/waas/apiUrl.js';
96
96
  import { useClientSessionKeys } from '../useClientSessionKeys/useClientSessionKeys.js';
97
- import { useRefreshUser } from '../useRefreshUser/useRefreshUser.js';
98
97
  import { useGetMfaToken } from '../useGetMfaToken/useGetMfaToken.js';
98
+ import { useRefreshUser } from '../useRefreshUser/useRefreshUser.js';
99
99
  import { DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR, NO_ENABLED_CHAINS_ERROR, INVALID_CHAINS_ERROR, WALLET_CREATION_FAILED_ERROR } from './constants.js';
100
100
  import '../../../store/state/sendBalances.js';
101
101
  import '../../../store/state/connectorsInitializing/connectorsInitializing.js';
@@ -362,6 +362,58 @@ const useDynamicWaas = () => {
362
362
  });
363
363
  }), [getWalletConnector]);
364
364
  const getWaasWallets = useCallback(() => userWallets.filter((w) => w.key === 'dynamicwaas'), [userWallets]);
365
+ const processSignOnWalletSettings = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
366
+ var _g;
367
+ if (!(user === null || user === void 0 ? void 0 : user.verifiedCredentials)) {
368
+ return;
369
+ }
370
+ const waasWallets = user.verifiedCredentials.filter((vc) => { var _a; return vc.walletName === 'dynamicwaas' && ((_a = vc.walletProperties) === null || _a === void 0 ? void 0 : _a.settings); });
371
+ for (const wallet of waasWallets) {
372
+ try {
373
+ const settings = (_g = wallet.walletProperties) === null || _g === void 0 ? void 0 : _g.settings;
374
+ const { address, chain } = wallet;
375
+ if (!settings || !address || !chain) {
376
+ continue;
377
+ }
378
+ const { shouldRefreshOnNextSignOn, reshareOnNextSignOn } = settings;
379
+ const chainName = VerifiedCredentialNameToChainEnum[chain];
380
+ const walletConnector = getWalletConnector(chainName);
381
+ if (!walletConnector) {
382
+ continue;
383
+ }
384
+ if (shouldRefreshOnNextSignOn) {
385
+ yield walletConnector.refreshWalletAccountShares({
386
+ accountAddress: address,
387
+ });
388
+ }
389
+ if (reshareOnNextSignOn) {
390
+ yield walletConnector.reshareWalletAccountShares({
391
+ accountAddress: address,
392
+ thresholdSignatureScheme: reshareOnNextSignOn,
393
+ });
394
+ }
395
+ }
396
+ catch (error) {
397
+ logger.error('Failed to process wallet settings:', {
398
+ error,
399
+ wallet,
400
+ });
401
+ }
402
+ }
403
+ yield refresh();
404
+ }), [user, getWalletConnector, refresh]);
405
+ const needsSettingsProcessing = useMemo(() => {
406
+ if (!(user === null || user === void 0 ? void 0 : user.verifiedCredentials) || !dynamicWaasIsEnabled) {
407
+ return false;
408
+ }
409
+ return user.verifiedCredentials.some((vc) => {
410
+ var _a;
411
+ return vc.walletName === 'dynamicwaas' &&
412
+ ((_a = vc.walletProperties) === null || _a === void 0 ? void 0 : _a.settings) &&
413
+ (vc.walletProperties.settings.shouldRefreshOnNextSignOn ||
414
+ vc.walletProperties.settings.reshareOnNextSignOn);
415
+ });
416
+ }, [user, dynamicWaasIsEnabled]);
365
417
  return {
366
418
  createWalletAccount,
367
419
  delegateKeyShares,
@@ -370,6 +422,8 @@ const useDynamicWaas = () => {
370
422
  getWalletConnector,
371
423
  importPrivateKey,
372
424
  needsAutoCreateWalletChains,
425
+ needsSettingsProcessing,
426
+ processSignOnWalletSettings,
373
427
  upgradeToDynamicWaas,
374
428
  };
375
429
  };
@@ -191,7 +191,7 @@ const useSocialAccounts = () => {
191
191
  const response = yield oauth.unlinkOAuth({
192
192
  environmentId,
193
193
  primaryWalletId: primaryWalletId$1,
194
- verifiedCrentialId: (_b = verifiedCredential.id) !== null && _b !== void 0 ? _b : '',
194
+ verifiedCredentialId: (_b = verifiedCredential.id) !== null && _b !== void 0 ? _b : '',
195
195
  });
196
196
  if (!response) {
197
197
  handleError(provider, types.SocialOAuthErrorCode.UNLINK_ERROR, `Failed to unlink social account: ${provider} | ${verifiedCredential.id}`, { raiseAuthFailure: false });
@@ -187,7 +187,7 @@ const useSocialAccounts = () => {
187
187
  const response = yield unlinkOAuth({
188
188
  environmentId,
189
189
  primaryWalletId,
190
- verifiedCrentialId: (_b = verifiedCredential.id) !== null && _b !== void 0 ? _b : '',
190
+ verifiedCredentialId: (_b = verifiedCredential.id) !== null && _b !== void 0 ? _b : '',
191
191
  });
192
192
  if (!response) {
193
193
  handleError(provider, SocialOAuthErrorCode.UNLINK_ERROR, `Failed to unlink social account: ${provider} | ${verifiedCredential.id}`, { raiseAuthFailure: false });
@@ -163,7 +163,6 @@ const useWalletCreation = () => {
163
163
  }
164
164
  catch (error) {
165
165
  const duration = Date.now() - startTime;
166
- // Log failed wallet creation to DataDog
167
166
  logger.logger.instrument('Auto wallet creation failed', {
168
167
  chainCount: chains.length,
169
168
  chains: chains.join(','),
@@ -183,6 +182,16 @@ const useWalletCreation = () => {
183
182
  },
184
183
  });
185
184
  };
185
+ const useWalletSettingsProcessor = () => {
186
+ const { processSignOnWalletSettings } = useDynamicWaas.useDynamicWaas();
187
+ return useMutation.useMutation(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
188
+ yield processSignOnWalletSettings();
189
+ }), {
190
+ onFailure: (error) => {
191
+ logger.logger.error('Error processing wallet settings', error);
192
+ },
193
+ });
194
+ };
186
195
  /**
187
196
  * Hook that synchronizes Dynamic WaaS wallet creation based on user state and configuration.
188
197
  *
@@ -195,15 +204,16 @@ const useWalletCreation = () => {
195
204
  * The hook ensures wallet creation only happens once per session until logout.
196
205
  */
197
206
  const useSyncDynamicWaas = () => {
198
- const { needsAutoCreateWalletChains } = useDynamicWaas.useDynamicWaas();
207
+ const { needsAutoCreateWalletChains, needsSettingsProcessing } = useDynamicWaas.useDynamicWaas();
199
208
  const validateWalletCreation = useWalletCreationValidation();
200
209
  const { mutate: createWallets, isLoading: isCreatingWallets } = useWalletCreation();
210
+ const { mutate: processSettings, isLoading: isProcessingSettings } = useWalletSettingsProcessor();
201
211
  const triggeredCreate = React.useRef(false);
202
- // Reset the trigger flag on logout
212
+ const triggeredSettingsProcessing = React.useRef(false);
203
213
  useDynamicEvents.useInternalDynamicEvents('logout', () => {
204
214
  triggeredCreate.current = false;
215
+ triggeredSettingsProcessing.current = false;
205
216
  });
206
- // Determine if wallet creation should be triggered
207
217
  const shouldCreateWallets = React.useCallback(() => {
208
218
  if (triggeredCreate.current || isCreatingWallets) {
209
219
  return false;
@@ -214,7 +224,28 @@ const useSyncDynamicWaas = () => {
214
224
  const validation = validateWalletCreation();
215
225
  return validation.isValid;
216
226
  }, [needsAutoCreateWalletChains, validateWalletCreation, isCreatingWallets]);
217
- // Handle the wallet creation process
227
+ const shouldProcessSettings = React.useCallback(() => {
228
+ if (triggeredSettingsProcessing.current || isProcessingSettings) {
229
+ return false;
230
+ }
231
+ if (!needsSettingsProcessing) {
232
+ return false;
233
+ }
234
+ const validation = validateWalletCreation();
235
+ return validation.isValid;
236
+ }, [needsSettingsProcessing, validateWalletCreation, isProcessingSettings]);
237
+ const handleSettingsProcessing = React.useCallback(() => {
238
+ if (!shouldProcessSettings()) {
239
+ return;
240
+ }
241
+ processSettings();
242
+ triggeredSettingsProcessing.current = true;
243
+ }, [shouldProcessSettings, processSettings]);
244
+ React.useEffect(() => {
245
+ if (shouldProcessSettings()) {
246
+ handleSettingsProcessing();
247
+ }
248
+ }, [shouldProcessSettings, handleSettingsProcessing]);
218
249
  const handleWalletCreation = React.useCallback(() => {
219
250
  if (!shouldCreateWallets() || !needsAutoCreateWalletChains) {
220
251
  return;
@@ -228,7 +259,6 @@ const useSyncDynamicWaas = () => {
228
259
  // Set the flag immediately to prevent duplicate calls
229
260
  triggeredCreate.current = true;
230
261
  }, [shouldCreateWallets, needsAutoCreateWalletChains, createWallets]);
231
- // Effect to trigger wallet creation when conditions are met
232
262
  React.useEffect(() => {
233
263
  if (shouldCreateWallets()) {
234
264
  handleWalletCreation();
@@ -159,7 +159,6 @@ const useWalletCreation = () => {
159
159
  }
160
160
  catch (error) {
161
161
  const duration = Date.now() - startTime;
162
- // Log failed wallet creation to DataDog
163
162
  logger.instrument('Auto wallet creation failed', {
164
163
  chainCount: chains.length,
165
164
  chains: chains.join(','),
@@ -179,6 +178,16 @@ const useWalletCreation = () => {
179
178
  },
180
179
  });
181
180
  };
181
+ const useWalletSettingsProcessor = () => {
182
+ const { processSignOnWalletSettings } = useDynamicWaas();
183
+ return useMutation(() => __awaiter(void 0, void 0, void 0, function* () {
184
+ yield processSignOnWalletSettings();
185
+ }), {
186
+ onFailure: (error) => {
187
+ logger.error('Error processing wallet settings', error);
188
+ },
189
+ });
190
+ };
182
191
  /**
183
192
  * Hook that synchronizes Dynamic WaaS wallet creation based on user state and configuration.
184
193
  *
@@ -191,15 +200,16 @@ const useWalletCreation = () => {
191
200
  * The hook ensures wallet creation only happens once per session until logout.
192
201
  */
193
202
  const useSyncDynamicWaas = () => {
194
- const { needsAutoCreateWalletChains } = useDynamicWaas();
203
+ const { needsAutoCreateWalletChains, needsSettingsProcessing } = useDynamicWaas();
195
204
  const validateWalletCreation = useWalletCreationValidation();
196
205
  const { mutate: createWallets, isLoading: isCreatingWallets } = useWalletCreation();
206
+ const { mutate: processSettings, isLoading: isProcessingSettings } = useWalletSettingsProcessor();
197
207
  const triggeredCreate = useRef(false);
198
- // Reset the trigger flag on logout
208
+ const triggeredSettingsProcessing = useRef(false);
199
209
  useInternalDynamicEvents('logout', () => {
200
210
  triggeredCreate.current = false;
211
+ triggeredSettingsProcessing.current = false;
201
212
  });
202
- // Determine if wallet creation should be triggered
203
213
  const shouldCreateWallets = useCallback(() => {
204
214
  if (triggeredCreate.current || isCreatingWallets) {
205
215
  return false;
@@ -210,7 +220,28 @@ const useSyncDynamicWaas = () => {
210
220
  const validation = validateWalletCreation();
211
221
  return validation.isValid;
212
222
  }, [needsAutoCreateWalletChains, validateWalletCreation, isCreatingWallets]);
213
- // Handle the wallet creation process
223
+ const shouldProcessSettings = useCallback(() => {
224
+ if (triggeredSettingsProcessing.current || isProcessingSettings) {
225
+ return false;
226
+ }
227
+ if (!needsSettingsProcessing) {
228
+ return false;
229
+ }
230
+ const validation = validateWalletCreation();
231
+ return validation.isValid;
232
+ }, [needsSettingsProcessing, validateWalletCreation, isProcessingSettings]);
233
+ const handleSettingsProcessing = useCallback(() => {
234
+ if (!shouldProcessSettings()) {
235
+ return;
236
+ }
237
+ processSettings();
238
+ triggeredSettingsProcessing.current = true;
239
+ }, [shouldProcessSettings, processSettings]);
240
+ useEffect(() => {
241
+ if (shouldProcessSettings()) {
242
+ handleSettingsProcessing();
243
+ }
244
+ }, [shouldProcessSettings, handleSettingsProcessing]);
214
245
  const handleWalletCreation = useCallback(() => {
215
246
  if (!shouldCreateWallets() || !needsAutoCreateWalletChains) {
216
247
  return;
@@ -224,7 +255,6 @@ const useSyncDynamicWaas = () => {
224
255
  // Set the flag immediately to prevent duplicate calls
225
256
  triggeredCreate.current = true;
226
257
  }, [shouldCreateWallets, needsAutoCreateWalletChains, createWallets]);
227
- // Effect to trigger wallet creation when conditions are met
228
258
  useEffect(() => {
229
259
  if (shouldCreateWallets()) {
230
260
  handleWalletCreation();