@dynamic-labs/sdk-react-core 4.37.1 → 4.37.2

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.
Files changed (26) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/package.cjs +3 -3
  3. package/package.js +3 -3
  4. package/package.json +13 -13
  5. package/src/lib/client/extension/deprecated/mfa/verifyTotpMfaDevice/verifyTotpMfaDevice.d.ts +1 -1
  6. package/src/lib/data/api/waas/index.d.ts +1 -0
  7. package/src/lib/data/api/waas/waas.cjs +37 -0
  8. package/src/lib/data/api/waas/waas.d.ts +2 -0
  9. package/src/lib/data/api/waas/waas.js +33 -0
  10. package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.cjs +54 -19
  11. package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.d.ts +7 -2
  12. package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.js +54 -19
  13. package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.cjs +5 -0
  14. package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.d.ts +1 -0
  15. package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.js +5 -0
  16. package/src/lib/utils/hooks/useWalletDelegation/useWalletDelegation.cjs +106 -34
  17. package/src/lib/utils/hooks/useWalletDelegation/useWalletDelegation.d.ts +4 -0
  18. package/src/lib/utils/hooks/useWalletDelegation/useWalletDelegation.js +106 -34
  19. package/src/lib/utils/hooks/useWalletOptions/useWalletOptions.d.ts +2 -2
  20. package/src/lib/views/WaasUpgradeView/WaasUpgradeView.cjs +7 -7
  21. package/src/lib/views/WaasUpgradeView/WaasUpgradeView.js +7 -7
  22. package/src/lib/views/WalletDelegation/WalletDelegationView/WalletDelegationView.cjs +51 -52
  23. package/src/lib/views/WalletDelegation/WalletDelegationView/WalletDelegationView.js +52 -53
  24. package/src/lib/views/WalletList/data.d.ts +1 -1
  25. package/src/lib/views/WalletUpgradeFlowView/WalletUpgradeFlowView.cjs +1 -1
  26. package/src/lib/views/WalletUpgradeFlowView/WalletUpgradeFlowView.js +1 -1
@@ -6,18 +6,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
6
6
  var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
7
  var React = require('react');
8
8
  var utils = require('@dynamic-labs/utils');
9
+ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
9
10
  require('../../../context/DynamicContext/DynamicContext.cjs');
10
11
  require('../../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
11
12
  require('@dynamic-labs/iconic');
12
13
  require('@dynamic-labs/wallet-connector-core');
13
14
  require('react/jsx-runtime');
14
15
  var ViewContext = require('../../../context/ViewContext/ViewContext.cjs');
15
- require('../../../shared/logger.cjs');
16
+ var logger = require('../../../shared/logger.cjs');
16
17
  require('@dynamic-labs/wallet-book');
17
18
  var localStorage = require('../../constants/localStorage.cjs');
18
19
  require('../../constants/colors.cjs');
19
20
  require('../../constants/values.cjs');
20
- require('@dynamic-labs/sdk-api-core');
21
21
  require('../../../shared/consts/index.cjs');
22
22
  var dynamicEvents = require('../../../events/dynamicEvents.cjs');
23
23
  require('../../../context/CaptchaContext/CaptchaContext.cjs');
@@ -30,9 +30,10 @@ require('@dynamic-labs-sdk/client/core');
30
30
  require('../../../client/client.cjs');
31
31
  require('@dynamic-labs-sdk/client');
32
32
  require('../../../config/ApiEndpoint.cjs');
33
+ var useUser = require('../../../client/extension/user/useUser/useUser.cjs');
33
34
  var useProjectSettings = require('../../../client/extension/projectSettings/useProjectSettings/useProjectSettings.cjs');
34
35
  require('../../../locale/locale.cjs');
35
- require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
36
+ var dynamicContextProps = require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
36
37
  require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
37
38
  require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
38
39
  require('../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
@@ -91,6 +92,8 @@ require('../../../context/FooterAnimationContext/index.cjs');
91
92
  require('../../../views/MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.cjs');
92
93
  require('../../../context/PasskeyContext/PasskeyContext.cjs');
93
94
  require('../../../context/OnrampContext/OnrampContext.cjs');
95
+ var useRefreshUser = require('../useRefreshUser/useRefreshUser.cjs');
96
+ var waas = require('../../../data/api/waas/waas.cjs');
94
97
  require('../../../store/state/sendBalances.cjs');
95
98
  require('../../../store/state/connectorsInitializing/connectorsInitializing.cjs');
96
99
  require('../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs');
@@ -107,37 +110,45 @@ var useInternalDynamicContext = require('../../../context/DynamicContext/useDyna
107
110
  // Hook to trigger wallet delegation modal
108
111
  const useWalletDelegation = () => {
109
112
  var _a, _b, _c;
110
- const { primaryWallet, user, setShowAuthFlow } = useInternalDynamicContext.useInternalDynamicContext();
113
+ const { setShowAuthFlow } = useInternalDynamicContext.useInternalDynamicContext();
111
114
  const { userWallets } = UserWalletsContext.useInternalUserWallets();
112
115
  const { pushView } = ViewContext.useViewContext();
113
116
  const projectSettings = useProjectSettings.useProjectSettings();
117
+ const user = useUser.useUser();
118
+ const environmentId = dynamicContextProps.useEnvironmentId();
119
+ const refresh = useRefreshUser.useRefreshUser();
114
120
  const waasSettings = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.waas;
115
121
  const delegatedAccessEnabled = (_a = waasSettings === null || waasSettings === void 0 ? void 0 : waasSettings.delegatedAccess) === null || _a === void 0 ? void 0 : _a.enabled;
116
122
  const promptUsersOnSignIn = (_b = waasSettings === null || waasSettings === void 0 ? void 0 : waasSettings.delegatedAccess) === null || _b === void 0 ? void 0 : _b.promptUsersOnSignIn;
117
123
  const requiresDelegation = (_c = waasSettings === null || waasSettings === void 0 ? void 0 : waasSettings.delegatedAccess) === null || _c === void 0 ? void 0 : _c.requiresDelegation;
118
124
  const shouldPromptWalletDelegation = React.useCallback(() => {
119
- var _a, _b;
120
- if (!delegatedAccessEnabled || !promptUsersOnSignIn) {
125
+ if (!delegatedAccessEnabled ||
126
+ !promptUsersOnSignIn ||
127
+ !(user === null || user === void 0 ? void 0 : user.verifiedCredentials)) {
121
128
  return false;
122
129
  }
123
- // If the prompt was dismissed, do not show again until logout
124
- // Unified state first, then legacy dismissed flag
125
- const state = utils.StorageService.getItem(localStorage.DELEGATION_STATE);
126
- const dismissed = state === null || state === void 0 ? void 0 : state.dismissed;
127
- if (dismissed) {
130
+ // Check session UI state
131
+ const sessionState = utils.StorageService.getItem(localStorage.DELEGATION_STATE);
132
+ if (sessionState === null || sessionState === void 0 ? void 0 : sessionState.dismissed) {
128
133
  return false;
129
134
  }
130
- const userId = (user === null || user === void 0 ? void 0 : user.userId) || 'anonymous';
131
- const deniedForUser = new Set(((_a = state === null || state === void 0 ? void 0 : state.denied) === null || _a === void 0 ? void 0 : _a[userId]) || []);
132
- const completedForUser = new Set(((_b = state === null || state === void 0 ? void 0 : state.completed) === null || _b === void 0 ? void 0 : _b[userId]) || []);
133
- const waasWallets = userWallets.filter((wallet) => wallet.connector.key.startsWith('dynamicwaas'));
134
- const hasUndeniedWaasWallet = waasWallets.some((wallet) => !deniedForUser.has(wallet.id) && !completedForUser.has(wallet.id));
135
- return hasUndeniedWaasWallet;
136
- }, [user === null || user === void 0 ? void 0 : user.userId, userWallets, delegatedAccessEnabled, promptUsersOnSignIn]);
135
+ // Check if any waas wallet needs delegation
136
+ const waasCredentials = user.verifiedCredentials.filter((vc) => vc.walletName === 'dynamicwaas' &&
137
+ vc.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.Blockchain);
138
+ const hasWalletNeedingDelegation = waasCredentials.some((vc) => {
139
+ var _a, _b, _c, _d, _e;
140
+ // Check if already delegated (has delegated keyShare)
141
+ const hasDelegatedKeyShare = (_b = (_a = vc.walletProperties) === null || _a === void 0 ? void 0 : _a.keyShares) === null || _b === void 0 ? void 0 : _b.some((keyShare) => keyShare.backupLocation === 'delegated');
142
+ // Check if denied
143
+ const hasDeniedAccess = ((_d = (_c = vc.walletProperties) === null || _c === void 0 ? void 0 : _c.settings) === null || _d === void 0 ? void 0 : _d.hasDeniedDelegatedAccess) === true;
144
+ // Check if dismissed this session
145
+ const isDismissedThisSession = (_e = sessionState === null || sessionState === void 0 ? void 0 : sessionState.dismissedWallets) === null || _e === void 0 ? void 0 : _e.includes(vc.id);
146
+ // Needs delegation if: not delegated, not denied, and not dismissed this session
147
+ return (!hasDelegatedKeyShare && !hasDeniedAccess && !isDismissedThisSession);
148
+ });
149
+ return hasWalletNeedingDelegation;
150
+ }, [user === null || user === void 0 ? void 0 : user.verifiedCredentials, delegatedAccessEnabled, promptUsersOnSignIn]);
137
151
  const initDelegationProcess = React.useCallback((options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
138
- if (!primaryWallet) {
139
- throw new Error('No primary wallet');
140
- }
141
152
  if (!user) {
142
153
  throw new Error(errors.USER_NOT_LOGGED_IN);
143
154
  }
@@ -154,29 +165,90 @@ const useWalletDelegation = () => {
154
165
  dynamicEvents.dynamicEvents.once('embeddedWalletDelegationCompleted', () => resolve());
155
166
  dynamicEvents.dynamicEvents.once('embeddedWalletDelegationFailed', (error) => reject(error));
156
167
  });
157
- }), [primaryWallet, setShowAuthFlow, pushView, user]);
168
+ }), [setShowAuthFlow, pushView, user]);
158
169
  const getWalletsDelegatedStatus = React.useCallback(() => {
159
- var _a, _b;
160
- if (!primaryWallet) {
170
+ if (!(user === null || user === void 0 ? void 0 : user.verifiedCredentials)) {
161
171
  return [];
162
172
  }
163
- const state = utils.StorageService.getItem(localStorage.DELEGATION_STATE);
164
- const userId = (user === null || user === void 0 ? void 0 : user.userId) || 'anonymous';
165
- const completedForUser = new Set(((_a = state === null || state === void 0 ? void 0 : state.completed) === null || _a === void 0 ? void 0 : _a[userId]) || []);
166
- const deniedForUser = new Set(((_b = state === null || state === void 0 ? void 0 : state.denied) === null || _b === void 0 ? void 0 : _b[userId]) || []);
167
- return userWallets.map((wallet) => {
173
+ // Get session UI state
174
+ const sessionState = utils.StorageService.getItem(localStorage.DELEGATION_STATE);
175
+ // Get waas credentials
176
+ const waasCredentials = user.verifiedCredentials.filter((vc) => vc.walletName === 'dynamicwaas' &&
177
+ vc.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.Blockchain);
178
+ // Map credentials to wallets with status
179
+ return waasCredentials
180
+ .map((vc) => {
181
+ var _a, _b, _c, _d, _e;
168
182
  let status = 'pending';
169
- if (completedForUser.has(wallet.id)) {
183
+ // Check if wallet has delegated keyShare
184
+ const hasDelegatedKeyShare = (_b = (_a = vc.walletProperties) === null || _a === void 0 ? void 0 : _a.keyShares) === null || _b === void 0 ? void 0 : _b.some((keyShare) => keyShare.backupLocation === 'delegated');
185
+ // Check if user has denied delegation
186
+ const hasDeniedAccess = ((_d = (_c = vc.walletProperties) === null || _c === void 0 ? void 0 : _c.settings) === null || _d === void 0 ? void 0 : _d.hasDeniedDelegatedAccess) === true;
187
+ if (hasDelegatedKeyShare) {
170
188
  status = 'delegated';
171
189
  }
172
- else if (deniedForUser.has(wallet.id)) {
190
+ else if (hasDeniedAccess) {
173
191
  status = 'denied';
174
192
  }
175
- return Object.assign(Object.assign({}, wallet), { status });
176
- });
177
- }, [primaryWallet, user === null || user === void 0 ? void 0 : user.userId, userWallets]);
193
+ // Check if dismissed this session (UI state only)
194
+ const isDismissedThisSession = (_e = sessionState === null || sessionState === void 0 ? void 0 : sessionState.dismissedWallets) === null || _e === void 0 ? void 0 : _e.includes(vc.id);
195
+ // Find corresponding wallet from userWallets
196
+ const wallet = userWallets.find((w) => w.address === vc.address);
197
+ if (!wallet) {
198
+ logger.logger.warn('Wallet not found for verified credential', {
199
+ address: vc.address,
200
+ vcId: vc.id,
201
+ });
202
+ return null;
203
+ }
204
+ return Object.assign(Object.assign({}, wallet), { isDismissedThisSession,
205
+ status });
206
+ })
207
+ .filter((wallet) => wallet !== null);
208
+ }, [user === null || user === void 0 ? void 0 : user.verifiedCredentials, userWallets]);
209
+ const denyWalletDelegation = React.useCallback((walletId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
210
+ try {
211
+ // Update backend - permanent denial
212
+ yield waas.updateWaasWalletSettings(environmentId, walletId, {
213
+ hasDeniedDelegatedAccess: true,
214
+ });
215
+ // Refresh user to get updated wallet properties
216
+ yield refresh();
217
+ // Clear any session UI state for this wallet
218
+ const sessionState = utils.StorageService.getItem(localStorage.DELEGATION_STATE) || {};
219
+ if (sessionState.dismissedWallets) {
220
+ sessionState.dismissedWallets = sessionState.dismissedWallets.filter((id) => id !== walletId);
221
+ utils.StorageService.setItem(localStorage.DELEGATION_STATE, sessionState);
222
+ }
223
+ }
224
+ catch (error) {
225
+ logger.logger.error('Failed to deny wallet delegation', error);
226
+ throw error;
227
+ }
228
+ }), [environmentId, refresh]);
229
+ const dismissDelegationPrompt = React.useCallback((walletId) => {
230
+ const sessionState = utils.StorageService.getItem(localStorage.DELEGATION_STATE) || {};
231
+ if (walletId) {
232
+ // Dismiss specific wallet
233
+ sessionState.dismissedWallets = [
234
+ ...(sessionState.dismissedWallets || []),
235
+ walletId,
236
+ ];
237
+ }
238
+ else {
239
+ // Dismiss all (global dismiss)
240
+ sessionState.dismissed = true;
241
+ }
242
+ utils.StorageService.setItem(localStorage.DELEGATION_STATE, sessionState);
243
+ }, []);
244
+ const clearDelegationSessionState = React.useCallback(() => {
245
+ utils.StorageService.removeItem(localStorage.DELEGATION_STATE);
246
+ }, []);
178
247
  return {
248
+ clearDelegationSessionState,
179
249
  delegatedAccessEnabled,
250
+ denyWalletDelegation,
251
+ dismissDelegationPrompt,
180
252
  getWalletsDelegatedStatus,
181
253
  initDelegationProcess,
182
254
  requiresDelegation,
@@ -2,9 +2,13 @@ import { Wallet } from '../../../shared';
2
2
  export type WalletDelegationStatus = 'delegated' | 'denied' | 'pending';
3
3
  export type WalletWithStatus = Wallet & {
4
4
  status: WalletDelegationStatus;
5
+ isDismissedThisSession?: boolean;
5
6
  };
6
7
  export declare const useWalletDelegation: () => {
8
+ readonly clearDelegationSessionState: () => void;
7
9
  readonly delegatedAccessEnabled: boolean | undefined;
10
+ readonly denyWalletDelegation: (walletId: string) => Promise<void>;
11
+ readonly dismissDelegationPrompt: (walletId?: string) => void;
8
12
  readonly getWalletsDelegatedStatus: () => WalletWithStatus[];
9
13
  readonly initDelegationProcess: (options?: {
10
14
  wallets?: Wallet[];
@@ -2,18 +2,18 @@
2
2
  import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
3
  import { useCallback } from 'react';
4
4
  import { StorageService } from '@dynamic-labs/utils';
5
+ import { JwtVerifiedCredentialFormatEnum } from '@dynamic-labs/sdk-api-core';
5
6
  import '../../../context/DynamicContext/DynamicContext.js';
6
7
  import '../../../store/state/loadingAndLifecycle/loadingAndLifecycle.js';
7
8
  import '@dynamic-labs/iconic';
8
9
  import '@dynamic-labs/wallet-connector-core';
9
10
  import 'react/jsx-runtime';
10
11
  import { useViewContext } from '../../../context/ViewContext/ViewContext.js';
11
- import '../../../shared/logger.js';
12
+ import { logger } from '../../../shared/logger.js';
12
13
  import '@dynamic-labs/wallet-book';
13
14
  import { DELEGATION_STATE } from '../../constants/localStorage.js';
14
15
  import '../../constants/colors.js';
15
16
  import '../../constants/values.js';
16
- import '@dynamic-labs/sdk-api-core';
17
17
  import '../../../shared/consts/index.js';
18
18
  import { dynamicEvents } from '../../../events/dynamicEvents.js';
19
19
  import '../../../context/CaptchaContext/CaptchaContext.js';
@@ -26,9 +26,10 @@ import '@dynamic-labs-sdk/client/core';
26
26
  import '../../../client/client.js';
27
27
  import '@dynamic-labs-sdk/client';
28
28
  import '../../../config/ApiEndpoint.js';
29
+ import { useUser } from '../../../client/extension/user/useUser/useUser.js';
29
30
  import { useProjectSettings } from '../../../client/extension/projectSettings/useProjectSettings/useProjectSettings.js';
30
31
  import '../../../locale/locale.js';
31
- import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
32
+ import { useEnvironmentId } from '../../../store/state/dynamicContextProps/dynamicContextProps.js';
32
33
  import '../../../store/state/primaryWalletId/primaryWalletId.js';
33
34
  import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
34
35
  import '../../../context/AccessDeniedContext/AccessDeniedContext.js';
@@ -87,6 +88,8 @@ import '../../../context/FooterAnimationContext/index.js';
87
88
  import '../../../views/MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.js';
88
89
  import '../../../context/PasskeyContext/PasskeyContext.js';
89
90
  import '../../../context/OnrampContext/OnrampContext.js';
91
+ import { useRefreshUser } from '../useRefreshUser/useRefreshUser.js';
92
+ import { updateWaasWalletSettings } from '../../../data/api/waas/waas.js';
90
93
  import '../../../store/state/sendBalances.js';
91
94
  import '../../../store/state/connectorsInitializing/connectorsInitializing.js';
92
95
  import '../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.js';
@@ -103,37 +106,45 @@ import { useInternalDynamicContext } from '../../../context/DynamicContext/useDy
103
106
  // Hook to trigger wallet delegation modal
104
107
  const useWalletDelegation = () => {
105
108
  var _a, _b, _c;
106
- const { primaryWallet, user, setShowAuthFlow } = useInternalDynamicContext();
109
+ const { setShowAuthFlow } = useInternalDynamicContext();
107
110
  const { userWallets } = useInternalUserWallets();
108
111
  const { pushView } = useViewContext();
109
112
  const projectSettings = useProjectSettings();
113
+ const user = useUser();
114
+ const environmentId = useEnvironmentId();
115
+ const refresh = useRefreshUser();
110
116
  const waasSettings = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.waas;
111
117
  const delegatedAccessEnabled = (_a = waasSettings === null || waasSettings === void 0 ? void 0 : waasSettings.delegatedAccess) === null || _a === void 0 ? void 0 : _a.enabled;
112
118
  const promptUsersOnSignIn = (_b = waasSettings === null || waasSettings === void 0 ? void 0 : waasSettings.delegatedAccess) === null || _b === void 0 ? void 0 : _b.promptUsersOnSignIn;
113
119
  const requiresDelegation = (_c = waasSettings === null || waasSettings === void 0 ? void 0 : waasSettings.delegatedAccess) === null || _c === void 0 ? void 0 : _c.requiresDelegation;
114
120
  const shouldPromptWalletDelegation = useCallback(() => {
115
- var _a, _b;
116
- if (!delegatedAccessEnabled || !promptUsersOnSignIn) {
121
+ if (!delegatedAccessEnabled ||
122
+ !promptUsersOnSignIn ||
123
+ !(user === null || user === void 0 ? void 0 : user.verifiedCredentials)) {
117
124
  return false;
118
125
  }
119
- // If the prompt was dismissed, do not show again until logout
120
- // Unified state first, then legacy dismissed flag
121
- const state = StorageService.getItem(DELEGATION_STATE);
122
- const dismissed = state === null || state === void 0 ? void 0 : state.dismissed;
123
- if (dismissed) {
126
+ // Check session UI state
127
+ const sessionState = StorageService.getItem(DELEGATION_STATE);
128
+ if (sessionState === null || sessionState === void 0 ? void 0 : sessionState.dismissed) {
124
129
  return false;
125
130
  }
126
- const userId = (user === null || user === void 0 ? void 0 : user.userId) || 'anonymous';
127
- const deniedForUser = new Set(((_a = state === null || state === void 0 ? void 0 : state.denied) === null || _a === void 0 ? void 0 : _a[userId]) || []);
128
- const completedForUser = new Set(((_b = state === null || state === void 0 ? void 0 : state.completed) === null || _b === void 0 ? void 0 : _b[userId]) || []);
129
- const waasWallets = userWallets.filter((wallet) => wallet.connector.key.startsWith('dynamicwaas'));
130
- const hasUndeniedWaasWallet = waasWallets.some((wallet) => !deniedForUser.has(wallet.id) && !completedForUser.has(wallet.id));
131
- return hasUndeniedWaasWallet;
132
- }, [user === null || user === void 0 ? void 0 : user.userId, userWallets, delegatedAccessEnabled, promptUsersOnSignIn]);
131
+ // Check if any waas wallet needs delegation
132
+ const waasCredentials = user.verifiedCredentials.filter((vc) => vc.walletName === 'dynamicwaas' &&
133
+ vc.format === JwtVerifiedCredentialFormatEnum.Blockchain);
134
+ const hasWalletNeedingDelegation = waasCredentials.some((vc) => {
135
+ var _a, _b, _c, _d, _e;
136
+ // Check if already delegated (has delegated keyShare)
137
+ const hasDelegatedKeyShare = (_b = (_a = vc.walletProperties) === null || _a === void 0 ? void 0 : _a.keyShares) === null || _b === void 0 ? void 0 : _b.some((keyShare) => keyShare.backupLocation === 'delegated');
138
+ // Check if denied
139
+ const hasDeniedAccess = ((_d = (_c = vc.walletProperties) === null || _c === void 0 ? void 0 : _c.settings) === null || _d === void 0 ? void 0 : _d.hasDeniedDelegatedAccess) === true;
140
+ // Check if dismissed this session
141
+ const isDismissedThisSession = (_e = sessionState === null || sessionState === void 0 ? void 0 : sessionState.dismissedWallets) === null || _e === void 0 ? void 0 : _e.includes(vc.id);
142
+ // Needs delegation if: not delegated, not denied, and not dismissed this session
143
+ return (!hasDelegatedKeyShare && !hasDeniedAccess && !isDismissedThisSession);
144
+ });
145
+ return hasWalletNeedingDelegation;
146
+ }, [user === null || user === void 0 ? void 0 : user.verifiedCredentials, delegatedAccessEnabled, promptUsersOnSignIn]);
133
147
  const initDelegationProcess = useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
134
- if (!primaryWallet) {
135
- throw new Error('No primary wallet');
136
- }
137
148
  if (!user) {
138
149
  throw new Error(USER_NOT_LOGGED_IN);
139
150
  }
@@ -150,29 +161,90 @@ const useWalletDelegation = () => {
150
161
  dynamicEvents.once('embeddedWalletDelegationCompleted', () => resolve());
151
162
  dynamicEvents.once('embeddedWalletDelegationFailed', (error) => reject(error));
152
163
  });
153
- }), [primaryWallet, setShowAuthFlow, pushView, user]);
164
+ }), [setShowAuthFlow, pushView, user]);
154
165
  const getWalletsDelegatedStatus = useCallback(() => {
155
- var _a, _b;
156
- if (!primaryWallet) {
166
+ if (!(user === null || user === void 0 ? void 0 : user.verifiedCredentials)) {
157
167
  return [];
158
168
  }
159
- const state = StorageService.getItem(DELEGATION_STATE);
160
- const userId = (user === null || user === void 0 ? void 0 : user.userId) || 'anonymous';
161
- const completedForUser = new Set(((_a = state === null || state === void 0 ? void 0 : state.completed) === null || _a === void 0 ? void 0 : _a[userId]) || []);
162
- const deniedForUser = new Set(((_b = state === null || state === void 0 ? void 0 : state.denied) === null || _b === void 0 ? void 0 : _b[userId]) || []);
163
- return userWallets.map((wallet) => {
169
+ // Get session UI state
170
+ const sessionState = StorageService.getItem(DELEGATION_STATE);
171
+ // Get waas credentials
172
+ const waasCredentials = user.verifiedCredentials.filter((vc) => vc.walletName === 'dynamicwaas' &&
173
+ vc.format === JwtVerifiedCredentialFormatEnum.Blockchain);
174
+ // Map credentials to wallets with status
175
+ return waasCredentials
176
+ .map((vc) => {
177
+ var _a, _b, _c, _d, _e;
164
178
  let status = 'pending';
165
- if (completedForUser.has(wallet.id)) {
179
+ // Check if wallet has delegated keyShare
180
+ const hasDelegatedKeyShare = (_b = (_a = vc.walletProperties) === null || _a === void 0 ? void 0 : _a.keyShares) === null || _b === void 0 ? void 0 : _b.some((keyShare) => keyShare.backupLocation === 'delegated');
181
+ // Check if user has denied delegation
182
+ const hasDeniedAccess = ((_d = (_c = vc.walletProperties) === null || _c === void 0 ? void 0 : _c.settings) === null || _d === void 0 ? void 0 : _d.hasDeniedDelegatedAccess) === true;
183
+ if (hasDelegatedKeyShare) {
166
184
  status = 'delegated';
167
185
  }
168
- else if (deniedForUser.has(wallet.id)) {
186
+ else if (hasDeniedAccess) {
169
187
  status = 'denied';
170
188
  }
171
- return Object.assign(Object.assign({}, wallet), { status });
172
- });
173
- }, [primaryWallet, user === null || user === void 0 ? void 0 : user.userId, userWallets]);
189
+ // Check if dismissed this session (UI state only)
190
+ const isDismissedThisSession = (_e = sessionState === null || sessionState === void 0 ? void 0 : sessionState.dismissedWallets) === null || _e === void 0 ? void 0 : _e.includes(vc.id);
191
+ // Find corresponding wallet from userWallets
192
+ const wallet = userWallets.find((w) => w.address === vc.address);
193
+ if (!wallet) {
194
+ logger.warn('Wallet not found for verified credential', {
195
+ address: vc.address,
196
+ vcId: vc.id,
197
+ });
198
+ return null;
199
+ }
200
+ return Object.assign(Object.assign({}, wallet), { isDismissedThisSession,
201
+ status });
202
+ })
203
+ .filter((wallet) => wallet !== null);
204
+ }, [user === null || user === void 0 ? void 0 : user.verifiedCredentials, userWallets]);
205
+ const denyWalletDelegation = useCallback((walletId) => __awaiter(void 0, void 0, void 0, function* () {
206
+ try {
207
+ // Update backend - permanent denial
208
+ yield updateWaasWalletSettings(environmentId, walletId, {
209
+ hasDeniedDelegatedAccess: true,
210
+ });
211
+ // Refresh user to get updated wallet properties
212
+ yield refresh();
213
+ // Clear any session UI state for this wallet
214
+ const sessionState = StorageService.getItem(DELEGATION_STATE) || {};
215
+ if (sessionState.dismissedWallets) {
216
+ sessionState.dismissedWallets = sessionState.dismissedWallets.filter((id) => id !== walletId);
217
+ StorageService.setItem(DELEGATION_STATE, sessionState);
218
+ }
219
+ }
220
+ catch (error) {
221
+ logger.error('Failed to deny wallet delegation', error);
222
+ throw error;
223
+ }
224
+ }), [environmentId, refresh]);
225
+ const dismissDelegationPrompt = useCallback((walletId) => {
226
+ const sessionState = StorageService.getItem(DELEGATION_STATE) || {};
227
+ if (walletId) {
228
+ // Dismiss specific wallet
229
+ sessionState.dismissedWallets = [
230
+ ...(sessionState.dismissedWallets || []),
231
+ walletId,
232
+ ];
233
+ }
234
+ else {
235
+ // Dismiss all (global dismiss)
236
+ sessionState.dismissed = true;
237
+ }
238
+ StorageService.setItem(DELEGATION_STATE, sessionState);
239
+ }, []);
240
+ const clearDelegationSessionState = useCallback(() => {
241
+ StorageService.removeItem(DELEGATION_STATE);
242
+ }, []);
174
243
  return {
244
+ clearDelegationSessionState,
175
245
  delegatedAccessEnabled,
246
+ denyWalletDelegation,
247
+ dismissDelegationPrompt,
176
248
  getWalletsDelegatedStatus,
177
249
  initDelegationProcess,
178
250
  requiresDelegation,
@@ -2,7 +2,7 @@ import { Wallet } from '@dynamic-labs/wallet-connector-core';
2
2
  import { WalletOption } from '../../../shared';
3
3
  export declare const useWalletOptions: () => {
4
4
  getFilteredWalletOptions: (filter: (options: WalletOption[]) => WalletOption[]) => {
5
- chain: "ETH" | "FLOW" | "SOL" | "EVM" | "ALGO" | "STARK" | "ATOM" | "COSMOS" | "BTC" | "ECLIPSE" | "SUI" | "SPARK" | "TRON";
5
+ chain: "ALGO" | "APTOS" | "ATOM" | "BTC" | "COSMOS" | "ECLIPSE" | "ETH" | "EVM" | "FLOW" | "SOL" | "SPARK" | "STARK" | "SUI" | "TRON";
6
6
  group: string | undefined;
7
7
  groupName: string | undefined;
8
8
  isInstalledOnBrowser: boolean;
@@ -13,7 +13,7 @@ export declare const useWalletOptions: () => {
13
13
  }[];
14
14
  selectWalletOption: (walletKey: string, selectGroupIfAvailable?: boolean, skipAllSelectionUi?: boolean) => Promise<Wallet<import("@dynamic-labs/wallet-connector-core").WalletConnectorCore.WalletConnector>>;
15
15
  walletOptions: {
16
- chain: "ETH" | "FLOW" | "SOL" | "EVM" | "ALGO" | "STARK" | "ATOM" | "COSMOS" | "BTC" | "ECLIPSE" | "SUI" | "SPARK" | "TRON";
16
+ chain: "ALGO" | "APTOS" | "ATOM" | "BTC" | "COSMOS" | "ECLIPSE" | "ETH" | "EVM" | "FLOW" | "SOL" | "SPARK" | "STARK" | "SUI" | "TRON";
17
17
  group: string | undefined;
18
18
  groupName: string | undefined;
19
19
  isInstalledOnBrowser: boolean;
@@ -22,7 +22,7 @@ require('../../shared/consts/index.cjs');
22
22
  require('../../components/Alert/Alert.cjs');
23
23
  require('../../events/dynamicEvents.cjs');
24
24
  var useDynamicContext = require('../../context/DynamicContext/useDynamicContext/useDynamicContext.cjs');
25
- var useInternalDynamicContext = require('../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
25
+ require('../../context/DynamicContext/DynamicContext.cjs');
26
26
  require('../../context/CaptchaContext/CaptchaContext.cjs');
27
27
  require('../../context/ErrorContext/ErrorContext.cjs');
28
28
  require('@dynamic-labs/multi-wallet');
@@ -38,7 +38,7 @@ require('../../store/state/primaryWalletId/primaryWalletId.cjs');
38
38
  require('../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
39
39
  require('../../context/AccessDeniedContext/AccessDeniedContext.cjs');
40
40
  require('../../context/AccountExistsContext/AccountExistsContext.cjs');
41
- require('../../context/UserWalletsContext/UserWalletsContext.cjs');
41
+ var UserWalletsContext = require('../../context/UserWalletsContext/UserWalletsContext.cjs');
42
42
  require('../../store/state/authMode/authMode.cjs');
43
43
  require('../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
44
44
  require('../../context/VerificationContext/VerificationContext.cjs');
@@ -110,9 +110,9 @@ require('../../components/Popper/PopperContext/PopperContext.cjs');
110
110
  const enableNewWalletCreation = false;
111
111
  const WaasUpgradeView = ({ onUpgrade }) => {
112
112
  const { pushView } = ViewContext.useViewContext();
113
- const { primaryWallet, secondaryWallets } = useInternalDynamicContext.useInternalDynamicContext();
113
+ const { userWallets: allUserWallets } = UserWalletsContext.useInternalUserWallets();
114
114
  const { getEOAWallet } = useSmartWallets.useSmartWallets();
115
- const userWallets = [primaryWallet, ...secondaryWallets].reduce((acc, wallet) => {
115
+ const turnkeyWallets = allUserWallets.reduce((acc, wallet) => {
116
116
  if (!wallet)
117
117
  return acc;
118
118
  // Check if the wallet itself is a Turnkey wallet
@@ -132,14 +132,14 @@ const WaasUpgradeView = ({ onUpgrade }) => {
132
132
  }, []);
133
133
  const { t } = reactI18next.useTranslation();
134
134
  const { setShowAuthFlow } = useDynamicContext.useDynamicContext();
135
- const [selectedWallets] = React.useState(userWallets.map((w) => { var _a; return (_a = w === null || w === void 0 ? void 0 : w.id) !== null && _a !== void 0 ? _a : ''; }));
135
+ const [selectedWallets] = React.useState(turnkeyWallets.map((w) => w.id));
136
136
  const [upgradeOption, setUpgradeOption] = React.useState('keep');
137
137
  const handleUpgrade = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
138
138
  if (selectedWallets.length === 0)
139
139
  return;
140
140
  if (upgradeOption === 'keep') {
141
141
  const walletsToUpgrade = selectedWallets
142
- .map((walletId) => userWallets.find((w) => (w === null || w === void 0 ? void 0 : w.id) === walletId))
142
+ .map((walletId) => turnkeyWallets.find((w) => w.id === walletId))
143
143
  .filter((w) => w !== undefined && w !== null);
144
144
  pushView('wallet-upgrade-flow-view', {
145
145
  method: 'existing',
@@ -148,7 +148,7 @@ const WaasUpgradeView = ({ onUpgrade }) => {
148
148
  }
149
149
  onUpgrade === null || onUpgrade === void 0 ? void 0 : onUpgrade(selectedWallets, upgradeOption);
150
150
  });
151
- return (jsxRuntime.jsxs("div", { className: 'waas-upgrade-view', children: [jsxRuntime.jsx(ModalHeader.ModalHeader, { children: jsxRuntime.jsx(Typography.Typography, { as: 'h1', variant: 'title', color: 'primary', children: t('dyn_upgrade_wallet.title') }) }), jsxRuntime.jsxs("div", { className: 'waas-upgrade-view__content', children: [jsxRuntime.jsx("div", { className: 'waas-upgrade-view__illustration', children: jsxRuntime.jsx(upgrade.ReactComponent, {}) }), jsxRuntime.jsx(Typography.Typography, { as: 'p', variant: 'body_normal', className: 'waas-upgrade-view__new-version-message', children: t('dyn_upgrade_wallet.description') }), jsxRuntime.jsxs("div", { className: 'waas-upgrade-view__wallets-section', children: [jsxRuntime.jsx("div", { className: 'waas-upgrade-view__section-header', children: jsxRuntime.jsx(Typography.Typography, { color: 'primary', children: t('dyn_upgrade_wallet.eligible_wallets') }) }), jsxRuntime.jsx("div", { className: 'waas-upgrade-view__wallets-list', children: userWallets.map((wallet) => (jsxRuntime.jsx("div", { className: 'waas-upgrade-view__wallet-item', children: jsxRuntime.jsx("div", { className: 'waas-upgrade-view__wallet-info', children: jsxRuntime.jsxs("div", { className: 'waas-upgrade-view__wallet-details', children: [jsxRuntime.jsx(Typography.Typography, { color: 'primary', children: wallet.chain }), jsxRuntime.jsxs(Typography.Typography, { color: 'primary', children: [wallet.address.slice(0, 6), "...", wallet.address.slice(-4)] })] }) }) }, wallet.id))) })] }), enableNewWalletCreation , jsxRuntime.jsxs("div", { className: 'waas-upgrade-view__actions', children: [jsxRuntime.jsx(TypographyButton.TypographyButton, { buttonVariant: 'brand-primary', onClick: handleUpgrade, disabled: selectedWallets.length === 0, copykey: 'dyn_upgrade_wallet.upgrade', typographyProps: {
151
+ return (jsxRuntime.jsxs("div", { className: 'waas-upgrade-view', children: [jsxRuntime.jsx(ModalHeader.ModalHeader, { children: jsxRuntime.jsx(Typography.Typography, { as: 'h1', variant: 'title', color: 'primary', children: t('dyn_upgrade_wallet.title') }) }), jsxRuntime.jsxs("div", { className: 'waas-upgrade-view__content', children: [jsxRuntime.jsx("div", { className: 'waas-upgrade-view__illustration', children: jsxRuntime.jsx(upgrade.ReactComponent, {}) }), jsxRuntime.jsx(Typography.Typography, { as: 'p', variant: 'body_normal', className: 'waas-upgrade-view__new-version-message', children: t('dyn_upgrade_wallet.description') }), jsxRuntime.jsxs("div", { className: 'waas-upgrade-view__wallets-section', children: [jsxRuntime.jsx("div", { className: 'waas-upgrade-view__section-header', children: jsxRuntime.jsx(Typography.Typography, { color: 'primary', children: t('dyn_upgrade_wallet.eligible_wallets') }) }), jsxRuntime.jsx("div", { className: 'waas-upgrade-view__wallets-list', children: turnkeyWallets.map((wallet) => (jsxRuntime.jsx("div", { className: 'waas-upgrade-view__wallet-item', children: jsxRuntime.jsx("div", { className: 'waas-upgrade-view__wallet-info', children: jsxRuntime.jsxs("div", { className: 'waas-upgrade-view__wallet-details', children: [jsxRuntime.jsx(Typography.Typography, { color: 'primary', children: wallet.chain }), jsxRuntime.jsxs(Typography.Typography, { color: 'primary', children: [wallet.address.slice(0, 6), "...", wallet.address.slice(-4)] })] }) }) }, wallet.id))) })] }), enableNewWalletCreation , jsxRuntime.jsxs("div", { className: 'waas-upgrade-view__actions', children: [jsxRuntime.jsx(TypographyButton.TypographyButton, { buttonVariant: 'brand-primary', onClick: handleUpgrade, disabled: selectedWallets.length === 0, copykey: 'dyn_upgrade_wallet.upgrade', typographyProps: {
152
152
  color: 'inherit',
153
153
  }, children: t('dyn_upgrade_wallet.upgrade') }), jsxRuntime.jsx(TypographyButton.TypographyButton, { buttonVariant: 'tertiary', onClick: () => {
154
154
  setShowAuthFlow(false);
@@ -18,7 +18,7 @@ import '../../shared/consts/index.js';
18
18
  import '../../components/Alert/Alert.js';
19
19
  import '../../events/dynamicEvents.js';
20
20
  import { useDynamicContext } from '../../context/DynamicContext/useDynamicContext/useDynamicContext.js';
21
- import { useInternalDynamicContext } from '../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js';
21
+ import '../../context/DynamicContext/DynamicContext.js';
22
22
  import '../../context/CaptchaContext/CaptchaContext.js';
23
23
  import '../../context/ErrorContext/ErrorContext.js';
24
24
  import '@dynamic-labs/multi-wallet';
@@ -34,7 +34,7 @@ import '../../store/state/primaryWalletId/primaryWalletId.js';
34
34
  import '../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
35
35
  import '../../context/AccessDeniedContext/AccessDeniedContext.js';
36
36
  import '../../context/AccountExistsContext/AccountExistsContext.js';
37
- import '../../context/UserWalletsContext/UserWalletsContext.js';
37
+ import { useInternalUserWallets } from '../../context/UserWalletsContext/UserWalletsContext.js';
38
38
  import '../../store/state/authMode/authMode.js';
39
39
  import '../../store/state/loadingAndLifecycle/loadingAndLifecycle.js';
40
40
  import '../../context/VerificationContext/VerificationContext.js';
@@ -106,9 +106,9 @@ import '../../components/Popper/PopperContext/PopperContext.js';
106
106
  const enableNewWalletCreation = false;
107
107
  const WaasUpgradeView = ({ onUpgrade }) => {
108
108
  const { pushView } = useViewContext();
109
- const { primaryWallet, secondaryWallets } = useInternalDynamicContext();
109
+ const { userWallets: allUserWallets } = useInternalUserWallets();
110
110
  const { getEOAWallet } = useSmartWallets();
111
- const userWallets = [primaryWallet, ...secondaryWallets].reduce((acc, wallet) => {
111
+ const turnkeyWallets = allUserWallets.reduce((acc, wallet) => {
112
112
  if (!wallet)
113
113
  return acc;
114
114
  // Check if the wallet itself is a Turnkey wallet
@@ -128,14 +128,14 @@ const WaasUpgradeView = ({ onUpgrade }) => {
128
128
  }, []);
129
129
  const { t } = useTranslation();
130
130
  const { setShowAuthFlow } = useDynamicContext();
131
- const [selectedWallets] = useState(userWallets.map((w) => { var _a; return (_a = w === null || w === void 0 ? void 0 : w.id) !== null && _a !== void 0 ? _a : ''; }));
131
+ const [selectedWallets] = useState(turnkeyWallets.map((w) => w.id));
132
132
  const [upgradeOption, setUpgradeOption] = useState('keep');
133
133
  const handleUpgrade = () => __awaiter(void 0, void 0, void 0, function* () {
134
134
  if (selectedWallets.length === 0)
135
135
  return;
136
136
  if (upgradeOption === 'keep') {
137
137
  const walletsToUpgrade = selectedWallets
138
- .map((walletId) => userWallets.find((w) => (w === null || w === void 0 ? void 0 : w.id) === walletId))
138
+ .map((walletId) => turnkeyWallets.find((w) => w.id === walletId))
139
139
  .filter((w) => w !== undefined && w !== null);
140
140
  pushView('wallet-upgrade-flow-view', {
141
141
  method: 'existing',
@@ -144,7 +144,7 @@ const WaasUpgradeView = ({ onUpgrade }) => {
144
144
  }
145
145
  onUpgrade === null || onUpgrade === void 0 ? void 0 : onUpgrade(selectedWallets, upgradeOption);
146
146
  });
147
- return (jsxs("div", { className: 'waas-upgrade-view', children: [jsx(ModalHeader, { children: jsx(Typography, { as: 'h1', variant: 'title', color: 'primary', children: t('dyn_upgrade_wallet.title') }) }), jsxs("div", { className: 'waas-upgrade-view__content', children: [jsx("div", { className: 'waas-upgrade-view__illustration', children: jsx(SvgUpgrade, {}) }), jsx(Typography, { as: 'p', variant: 'body_normal', className: 'waas-upgrade-view__new-version-message', children: t('dyn_upgrade_wallet.description') }), jsxs("div", { className: 'waas-upgrade-view__wallets-section', children: [jsx("div", { className: 'waas-upgrade-view__section-header', children: jsx(Typography, { color: 'primary', children: t('dyn_upgrade_wallet.eligible_wallets') }) }), jsx("div", { className: 'waas-upgrade-view__wallets-list', children: userWallets.map((wallet) => (jsx("div", { className: 'waas-upgrade-view__wallet-item', children: jsx("div", { className: 'waas-upgrade-view__wallet-info', children: jsxs("div", { className: 'waas-upgrade-view__wallet-details', children: [jsx(Typography, { color: 'primary', children: wallet.chain }), jsxs(Typography, { color: 'primary', children: [wallet.address.slice(0, 6), "...", wallet.address.slice(-4)] })] }) }) }, wallet.id))) })] }), enableNewWalletCreation , jsxs("div", { className: 'waas-upgrade-view__actions', children: [jsx(TypographyButton, { buttonVariant: 'brand-primary', onClick: handleUpgrade, disabled: selectedWallets.length === 0, copykey: 'dyn_upgrade_wallet.upgrade', typographyProps: {
147
+ return (jsxs("div", { className: 'waas-upgrade-view', children: [jsx(ModalHeader, { children: jsx(Typography, { as: 'h1', variant: 'title', color: 'primary', children: t('dyn_upgrade_wallet.title') }) }), jsxs("div", { className: 'waas-upgrade-view__content', children: [jsx("div", { className: 'waas-upgrade-view__illustration', children: jsx(SvgUpgrade, {}) }), jsx(Typography, { as: 'p', variant: 'body_normal', className: 'waas-upgrade-view__new-version-message', children: t('dyn_upgrade_wallet.description') }), jsxs("div", { className: 'waas-upgrade-view__wallets-section', children: [jsx("div", { className: 'waas-upgrade-view__section-header', children: jsx(Typography, { color: 'primary', children: t('dyn_upgrade_wallet.eligible_wallets') }) }), jsx("div", { className: 'waas-upgrade-view__wallets-list', children: turnkeyWallets.map((wallet) => (jsx("div", { className: 'waas-upgrade-view__wallet-item', children: jsx("div", { className: 'waas-upgrade-view__wallet-info', children: jsxs("div", { className: 'waas-upgrade-view__wallet-details', children: [jsx(Typography, { color: 'primary', children: wallet.chain }), jsxs(Typography, { color: 'primary', children: [wallet.address.slice(0, 6), "...", wallet.address.slice(-4)] })] }) }) }, wallet.id))) })] }), enableNewWalletCreation , jsxs("div", { className: 'waas-upgrade-view__actions', children: [jsx(TypographyButton, { buttonVariant: 'brand-primary', onClick: handleUpgrade, disabled: selectedWallets.length === 0, copykey: 'dyn_upgrade_wallet.upgrade', typographyProps: {
148
148
  color: 'inherit',
149
149
  }, children: t('dyn_upgrade_wallet.upgrade') }), jsx(TypographyButton, { buttonVariant: 'tertiary', onClick: () => {
150
150
  setShowAuthFlow(false);