@dynamic-labs/legacy-embedded-wallet-migration 5.13.0 → 5.14.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.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,14 @@
1
1
 
2
+ ## [5.14.0](https://github.com/dynamic-labs/dynamic-auth/compare/v5.13.0...v5.14.0) (2026-10-30)
3
+
4
+
5
+ ### Features
6
+
7
+ * **bitcoin:** add allowedWitnessScripts to embedded wallet signPsbt ([#12575](https://github.com/dynamic-labs/dynamic-auth/issues/12575)) ([e7709bc](https://github.com/dynamic-labs/dynamic-auth/commit/e7709bc226bc78caa8c7aaae9b25858ca689176e)), closes [#1647](https://github.com/dynamic-labs/dynamic-auth/issues/1647) [#1648](https://github.com/dynamic-labs/dynamic-auth/issues/1648)
8
+ * **legacy-embedded-wallet-migration:** offer passkey recovery when export fails in upgrade flow ([#12640](https://github.com/dynamic-labs/dynamic-auth/issues/12640)) ([eda1d1a](https://github.com/dynamic-labs/dynamic-auth/commit/eda1d1a24f40c5850ae3ffd8049b4a9df45d489e))
9
+ * **webview:** forward policiesConsentLabels manifest field to SDK settings ([#12607](https://github.com/dynamic-labs/dynamic-auth/issues/12607)) ([ce3a9a0](https://github.com/dynamic-labs/dynamic-auth/commit/ce3a9a0840bd80c18401a94cd175c89ade5cc7cc))
10
+
11
+
2
12
  ## [5.13.0](https://github.com/dynamic-labs/dynamic-auth/compare/v5.12.4...v5.13.0) (2026-10-27)
3
13
 
4
14
 
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "5.13.0";
2
+ var version = "5.14.0";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/legacy-embedded-wallet-migration",
3
- "version": "5.13.0",
3
+ "version": "5.14.0",
4
4
  "license": "MIT",
5
5
  "main": "./src/index.js",
6
6
  "module": "./src/index.js",
@@ -17,15 +17,15 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@dynamic-labs-sdk/client": "1.47.0",
20
- "@dynamic-labs/assert-package-version": "5.13.0",
20
+ "@dynamic-labs/assert-package-version": "5.14.0",
21
21
  "@dynamic-labs/sdk-api-core": "0.136.0",
22
- "@dynamic-labs/utils": "5.13.0",
23
- "@dynamic-labs/wallet-connector-core": "5.13.0"
22
+ "@dynamic-labs/utils": "5.14.0",
23
+ "@dynamic-labs/wallet-connector-core": "5.14.0"
24
24
  },
25
25
  "peerDependencies": {
26
- "@dynamic-labs/sdk-react-core": "5.13.0",
26
+ "@dynamic-labs/sdk-react-core": "5.14.0",
27
27
  "react": ">=18.0.0 <20.0.0",
28
28
  "react-i18next": ">=13.0.0",
29
- "@dynamic-labs/types": "5.13.0"
29
+ "@dynamic-labs/types": "5.14.0"
30
30
  }
31
31
  }
@@ -4,12 +4,14 @@ export type EmbeddedWalletCurrentAction = {
4
4
  type: 'signMessage' | 'sendTransaction' | 'helpSession' | 'signTransaction' | 'reveal';
5
5
  settings?: {
6
6
  goBack?: () => void;
7
+ wallet?: Wallet;
7
8
  };
8
9
  };
9
10
  type InitAuthenticatorMethodProps = {
10
11
  authenticatorType: AuthenticatorType;
11
12
  iframeContainer: HTMLElement;
12
13
  currentAction?: EmbeddedWalletCurrentAction;
14
+ wallet?: Wallet | null;
13
15
  };
14
16
  type UseInitEmbeddedWalletAuthMethodProps = {
15
17
  user: UserProfile | undefined;
@@ -23,7 +25,7 @@ type UseInitEmbeddedWalletAuthMethodProps = {
23
25
  };
24
26
  export declare const useInitEmbeddedWalletAuthMethod: ({ user, wallet, sessionExpiration, onShowEmailBundle, onComplete, }: UseInitEmbeddedWalletAuthMethodProps) => {
25
27
  error: unknown;
26
- initAuthMethod: ({ authenticatorType, iframeContainer, currentAction, }: InitAuthenticatorMethodProps) => Promise<void>;
28
+ initAuthMethod: ({ authenticatorType, iframeContainer, currentAction, wallet: targetWallet, }: InitAuthenticatorMethodProps) => Promise<void>;
27
29
  isLoading: boolean;
28
30
  };
29
31
  export {};
@@ -9,11 +9,12 @@ import { initEmbeddedWalletSession } from '../initEmbeddedWalletSession/initEmbe
9
9
  const useInitEmbeddedWalletAuthMethod = ({ user, wallet, sessionExpiration, onShowEmailBundle, onComplete, }) => {
10
10
  const [isLoading, setIsLoading] = useState(false);
11
11
  const [error, setError] = useState();
12
- const initAuthMethod = (_a) => __awaiter(void 0, [_a], void 0, function* ({ authenticatorType, iframeContainer, currentAction, }) {
12
+ const initAuthMethod = (_a) => __awaiter(void 0, [_a], void 0, function* ({ authenticatorType, iframeContainer, currentAction, wallet: targetWallet, }) {
13
13
  setIsLoading(true);
14
+ const recoveryWallet = targetWallet !== null && targetWallet !== void 0 ? targetWallet : wallet;
14
15
  const showEmailBundle = authenticatorType === 'email' ||
15
- !wallet ||
16
- !wallet.connector
16
+ !recoveryWallet ||
17
+ !recoveryWallet.connector
17
18
  .getAuthenticatorHandler()
18
19
  .isSessionActive();
19
20
  try {
@@ -23,7 +24,7 @@ const useInitEmbeddedWalletAuthMethod = ({ user, wallet, sessionExpiration, onSh
23
24
  iframeElementId,
24
25
  sessionExpiration,
25
26
  user,
26
- wallet,
27
+ wallet: recoveryWallet,
27
28
  });
28
29
  if (showEmailBundle) {
29
30
  onShowEmailBundle({ authenticatorType, currentAction });
@@ -91,20 +91,25 @@ const usePasskeyRecovery = ({ user, wallet, primaryWallet, sessionKeyDuration, s
91
91
  return true;
92
92
  }), [wallet, isTurnkeyWalletWithoutAuthenticator, isSessionRestored]);
93
93
  const initPasskeyRecoveryProcess = useCallback((authenticatorType, currentAction) => __awaiter(void 0, void 0, void 0, function* () {
94
+ var _a, _b;
95
+ // Recovery can target a non-primary wallet (e.g. a later wallet in the
96
+ // upgrade flow); fall back to the configured wallet.
97
+ const recoveryWallet = (_b = (_a = currentAction === null || currentAction === void 0 ? void 0 : currentAction.settings) === null || _a === void 0 ? void 0 : _a.wallet) !== null && _b !== void 0 ? _b : wallet;
94
98
  if (!user) {
95
99
  throw new Error('User is not logged in');
96
100
  }
97
101
  if (!hasEmbeddedWalletCredential(user)) {
98
102
  throw new Error('Dynamic embedded wallet not found');
99
103
  }
100
- if (wallet && !isPasskeyWalletConnector(wallet.connector)) {
104
+ if (recoveryWallet &&
105
+ !isPasskeyWalletConnector(recoveryWallet.connector)) {
101
106
  throw new Error('Dynamic embedded wallet not found.');
102
107
  }
103
- const turnkeyRecoveryHandler = (wallet === null || wallet === void 0 ? void 0 : wallet.connector).getAuthenticatorHandler();
108
+ const turnkeyRecoveryHandler = (recoveryWallet === null || recoveryWallet === void 0 ? void 0 : recoveryWallet.connector).getAuthenticatorHandler();
104
109
  // email auth - session is still up, so create passkey authenticator using the same session
105
110
  if (authenticatorType === 'passkey' &&
106
111
  turnkeyRecoveryHandler.isSessionActive()) {
107
- yield addNewPasskeyAuthenticator({ user, wallet });
112
+ yield addNewPasskeyAuthenticator({ user, wallet: recoveryWallet });
108
113
  onAuthMethodComplete();
109
114
  return;
110
115
  }
@@ -130,6 +135,7 @@ const usePasskeyRecovery = ({ user, wallet, primaryWallet, sessionKeyDuration, s
130
135
  authenticatorType: nextAuthenticatorType,
131
136
  currentAction,
132
137
  iframeContainer: iframeContainer,
138
+ wallet: recoveryWallet,
133
139
  });
134
140
  }), [
135
141
  wallet,
@@ -143,7 +149,7 @@ const usePasskeyRecovery = ({ user, wallet, primaryWallet, sessionKeyDuration, s
143
149
  iframeContainer,
144
150
  ]);
145
151
  const updateUserProfile = (emailInput) => __awaiter(void 0, void 0, void 0, function* () {
146
- var _a;
152
+ var _c;
147
153
  try {
148
154
  const client = getDefaultClient();
149
155
  const core = getCore(client);
@@ -158,7 +164,7 @@ const usePasskeyRecovery = ({ user, wallet, primaryWallet, sessionKeyDuration, s
158
164
  }
159
165
  const verified = yield awaitEmailVerification({
160
166
  email: emailInput,
161
- verificationUUID: (_a = response.emailVerification) === null || _a === void 0 ? void 0 : _a.verificationUUID,
167
+ verificationUUID: (_c = response.emailVerification) === null || _c === void 0 ? void 0 : _c.verificationUUID,
162
168
  });
163
169
  if (!verified) {
164
170
  throw new Error('Failed to verify email');
@@ -2,5 +2,6 @@ import { FC } from 'react';
2
2
  import { Wallet, WalletConnectorCore } from '@dynamic-labs/wallet-connector-core';
3
3
  export type LegacyEmbeddedWalletExportProps = {
4
4
  wallet: Wallet<WalletConnectorCore.WalletConnector>;
5
+ onExportFailed?: (error: unknown) => void;
5
6
  };
6
7
  export declare const LegacyEmbeddedWalletExport: FC<LegacyEmbeddedWalletExportProps>;
@@ -41,7 +41,7 @@ const skeletonLineStyle = {
41
41
  width: '100%',
42
42
  };
43
43
  const skeletonLineShortStyle = Object.assign(Object.assign({}, skeletonLineStyle), { width: '60%' });
44
- const LegacyEmbeddedWalletExport = ({ wallet }) => {
44
+ const LegacyEmbeddedWalletExport = ({ wallet, onExportFailed }) => {
45
45
  const { user } = useDynamicContext();
46
46
  const setTurnkeyConnectorFetchers = useSetTurnkeyConnectorFetchers({
47
47
  wallet,
@@ -49,6 +49,9 @@ const LegacyEmbeddedWalletExport = ({ wallet }) => {
49
49
  const containerRef = useRef(null);
50
50
  const isExportingRef = useRef(false);
51
51
  const [revealed, setRevealed] = useState(false);
52
+ const [failed, setFailed] = useState(false);
53
+ const onExportFailedRef = useRef(onExportFailed);
54
+ onExportFailedRef.current = onExportFailed;
52
55
  const setContainerRef = (element) => {
53
56
  containerRef.current = element;
54
57
  };
@@ -63,7 +66,7 @@ const LegacyEmbeddedWalletExport = ({ wallet }) => {
63
66
  // re-entry if React re-fires the effect due to reference changes.
64
67
  useEffect(() => {
65
68
  const run = () => __awaiter(void 0, void 0, void 0, function* () {
66
- var _a, _b, _c;
69
+ var _a, _b, _c, _d;
67
70
  const iframeContainer = containerRef.current;
68
71
  if (!iframeContainer || iframeContainer.children.length > 0) {
69
72
  return;
@@ -100,6 +103,8 @@ const LegacyEmbeddedWalletExport = ({ wallet }) => {
100
103
  }
101
104
  catch (error) {
102
105
  logger.error('LegacyEmbeddedWalletExport: export flow failed', error);
106
+ setFailed(true);
107
+ (_d = onExportFailedRef.current) === null || _d === void 0 ? void 0 : _d.call(onExportFailedRef, error);
103
108
  }
104
109
  finally {
105
110
  isExportingRef.current = false;
@@ -116,7 +121,7 @@ const LegacyEmbeddedWalletExport = ({ wallet }) => {
116
121
  },
117
122
  // eslint-disable-next-line react-hooks/exhaustive-deps
118
123
  []);
119
- return (jsxs("div", { style: credentialContainerStyle, children: [jsx("div", { id: iframeContainerId, ref: setContainerRef, style: revealed ? iframeContainerStyle : hiddenIframeContainerStyle }), !revealed && (jsxs("div", { style: skeletonContainerStyle, children: [jsx("div", { style: skeletonLineStyle, "data-testid": 'private-key-skeleton' }), jsx("div", { style: skeletonLineStyle }), jsx("div", { style: skeletonLineShortStyle })] }))] }));
124
+ return (jsxs("div", { style: credentialContainerStyle, children: [jsx("div", { id: iframeContainerId, ref: setContainerRef, style: revealed ? iframeContainerStyle : hiddenIframeContainerStyle }), !revealed && !failed && (jsxs("div", { style: skeletonContainerStyle, children: [jsx("div", { style: skeletonLineStyle, "data-testid": 'private-key-skeleton' }), jsx("div", { style: skeletonLineStyle }), jsx("div", { style: skeletonLineShortStyle })] }))] }));
120
125
  };
121
126
 
122
127
  export { LegacyEmbeddedWalletExport };
@@ -1,8 +1,11 @@
1
1
  import { FC, ReactNode } from 'react';
2
- import { AuthenticatorType } from '@dynamic-labs/wallet-connector-core';
3
- import { usePasskeyRecovery } from '../../recovery';
2
+ import { AuthenticatorType, Wallet } from '@dynamic-labs/wallet-connector-core';
3
+ import { EmbeddedWalletCurrentAction, usePasskeyRecovery } from '../../recovery';
4
4
  type RecoveryHandlers = ReturnType<typeof usePasskeyRecovery>;
5
- export type LegacyWalletMigrationRecoveryContextType = RecoveryHandlers & {
5
+ export type LegacyWalletMigrationRecoveryContextType = Omit<RecoveryHandlers, 'initPasskeyRecoveryProcess'> & {
6
+ initPasskeyRecoveryProcess: (authenticatorType?: AuthenticatorType, currentAction?: EmbeddedWalletCurrentAction, wallet?: Wallet) => Promise<void>;
7
+ upgradeWalletIndex: number;
8
+ setUpgradeWalletIndex: (index: number) => void;
6
9
  iframeContainer: HTMLDivElement | null;
7
10
  supportedAuthenticators: AuthenticatorType[];
8
11
  resolveEmailVerification: (wasSuccessful: boolean) => void;
@@ -52,6 +52,10 @@ const LegacyWalletMigrationRecoveryProvider = ({ children }) => {
52
52
  return (_c = legacyWallets[0]) !== null && _c !== void 0 ? _c : primaryWallet;
53
53
  }, [primaryWallet, legacyWallets]);
54
54
  const [iframeContainer, setIframeContainer] = useState(null);
55
+ // Wallet the in-flight recovery session targets; set when recovery is
56
+ // initiated for a specific (possibly non-primary) wallet.
57
+ const [recoverySessionWallet, setRecoverySessionWallet] = useState();
58
+ const [upgradeWalletIndex, setUpgradeWalletIndex] = useState(0);
55
59
  const [recoveryAuthenticatorType, setRecoveryAuthenticatorType] = useState();
56
60
  const [isValidatingBundle, setIsValidatingBundle] = useState(false);
57
61
  const [bundleValidationError, setBundleValidationError] = useState();
@@ -113,7 +117,7 @@ const LegacyWalletMigrationRecoveryProvider = ({ children }) => {
113
117
  yield passkeyRecoveryBundleValidation({
114
118
  bundleInput,
115
119
  user,
116
- wallet: recoveryWallet,
120
+ wallet: recoverySessionWallet !== null && recoverySessionWallet !== void 0 ? recoverySessionWallet : recoveryWallet,
117
121
  });
118
122
  if (recoveryAuthenticatorType === 'passkey') {
119
123
  goToStep('passkey-recovery-complete');
@@ -130,7 +134,13 @@ const LegacyWalletMigrationRecoveryProvider = ({ children }) => {
130
134
  finally {
131
135
  setIsValidatingBundle(false);
132
136
  }
133
- }), [user, recoveryWallet, recoveryAuthenticatorType, goToStep]);
137
+ }), [
138
+ user,
139
+ recoveryWallet,
140
+ recoverySessionWallet,
141
+ recoveryAuthenticatorType,
142
+ goToStep,
143
+ ]);
134
144
  const resendRecoveryEmail = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
135
145
  if (!recoveryAuthenticatorType)
136
146
  return;
@@ -138,18 +148,21 @@ const LegacyWalletMigrationRecoveryProvider = ({ children }) => {
138
148
  yield resentRecoveryEmail({
139
149
  authenticatorType: recoveryAuthenticatorType,
140
150
  user,
141
- wallet: recoveryWallet,
151
+ wallet: recoverySessionWallet !== null && recoverySessionWallet !== void 0 ? recoverySessionWallet : recoveryWallet,
142
152
  });
143
153
  }
144
154
  catch (err) {
145
155
  logger.error('Failed to resend recovery email', err);
146
156
  }
147
- }), [recoveryAuthenticatorType, user, recoveryWallet]);
157
+ }), [recoveryAuthenticatorType, user, recoveryWallet, recoverySessionWallet]);
148
158
  const completeRecovery = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
149
159
  setIsCompletingRecovery(true);
150
160
  setCompleteRecoveryError(undefined);
151
161
  try {
152
- yield completePasskeyRecovery({ user, wallet: recoveryWallet });
162
+ yield completePasskeyRecovery({
163
+ user,
164
+ wallet: recoverySessionWallet !== null && recoverySessionWallet !== void 0 ? recoverySessionWallet : recoveryWallet,
165
+ });
153
166
  goToStep('upgrade');
154
167
  }
155
168
  catch (err) {
@@ -159,7 +172,7 @@ const LegacyWalletMigrationRecoveryProvider = ({ children }) => {
159
172
  finally {
160
173
  setIsCompletingRecovery(false);
161
174
  }
162
- }), [user, recoveryWallet, goToStep]);
175
+ }), [user, recoveryWallet, recoverySessionWallet, goToStep]);
163
176
  const recovery = usePasskeyRecovery({
164
177
  awaitEmailVerification,
165
178
  hasRecoveryEmail,
@@ -176,21 +189,32 @@ const LegacyWalletMigrationRecoveryProvider = ({ children }) => {
176
189
  user,
177
190
  wallet: recoveryWallet,
178
191
  });
192
+ // Pins the recovery session to the wallet that triggered it and forwards it
193
+ // to the hook via currentAction.settings.wallet.
194
+ const initPasskeyRecoveryProcess = useCallback((authenticatorType, currentAction, wallet) => {
195
+ setRecoverySessionWallet(wallet);
196
+ return recovery.initPasskeyRecoveryProcess(authenticatorType, wallet
197
+ ? Object.assign(Object.assign({}, (currentAction !== null && currentAction !== void 0 ? currentAction : { type: 'helpSession' })), { settings: Object.assign(Object.assign({}, currentAction === null || currentAction === void 0 ? void 0 : currentAction.settings), { wallet }) }) : currentAction);
198
+ }, [recovery]);
179
199
  const value = useMemo(() => (Object.assign(Object.assign({}, recovery), { bundleValidationError,
180
200
  completeRecovery,
181
201
  completeRecoveryError,
182
202
  iframeContainer,
203
+ initPasskeyRecoveryProcess,
183
204
  isCompletingRecovery,
184
205
  isValidatingBundle,
185
206
  recoveryAuthenticatorType, recoveryEmail: user === null || user === void 0 ? void 0 : user.email, resendRecoveryEmail,
186
207
  resolveEmailVerification,
208
+ setUpgradeWalletIndex,
187
209
  supportedAuthenticators,
210
+ upgradeWalletIndex,
188
211
  validateRecoveryBundle })), [
189
212
  recovery,
190
213
  bundleValidationError,
191
214
  completeRecovery,
192
215
  completeRecoveryError,
193
216
  iframeContainer,
217
+ initPasskeyRecoveryProcess,
194
218
  isCompletingRecovery,
195
219
  isValidatingBundle,
196
220
  recoveryAuthenticatorType,
@@ -198,6 +222,7 @@ const LegacyWalletMigrationRecoveryProvider = ({ children }) => {
198
222
  resendRecoveryEmail,
199
223
  resolveEmailVerification,
200
224
  supportedAuthenticators,
225
+ upgradeWalletIndex,
201
226
  validateRecoveryBundle,
202
227
  ]);
203
228
  return (jsxs(LegacyWalletMigrationRecoveryContext.Provider, { value: value, children: [jsx("div", { id: iframeContainerId, ref: setIframeContainer, style: iframeHostStyle, "data-testid": 'legacy-wallet-migration-recovery-iframe-container' }), children] }));
@@ -1,11 +1,12 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../_virtual/_tslib.js';
3
3
  import { jsxs, jsx } from 'react/jsx-runtime';
4
- import { useState } from 'react';
4
+ import { useState, useMemo } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
- import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
7
- import { ModalHeader, Typography, ErrorContainer, Textarea, TypographyButton } from '@dynamic-labs/sdk-react-core/components';
6
+ import { useDynamicContext, getProperErrorMessage } from '@dynamic-labs/sdk-react-core';
7
+ import { ModalHeader, Typography, ErrorContainer, Textarea, TextButton, TypographyButton } from '@dynamic-labs/sdk-react-core/components';
8
8
  import { LegacyEmbeddedWalletExport } from '../LegacyEmbeddedWalletExport/LegacyEmbeddedWalletExport.js';
9
+ import { useLegacyWalletMigrationRecovery } from '../LegacyWalletMigrationRecoveryContext/LegacyWalletMigrationRecoveryContext.js';
9
10
 
10
11
  const containerStyle = {
11
12
  display: 'flex',
@@ -52,6 +53,17 @@ const actionsStyle = {
52
53
  gap: 12,
53
54
  padding: '0 24px 24px 24px',
54
55
  };
56
+ const needHelpStyle = {
57
+ alignItems: 'center',
58
+ display: 'flex',
59
+ flexDirection: 'column',
60
+ gap: 4,
61
+ };
62
+ const supportLinkStyle = {
63
+ color: 'var(--dynamic-link-color, var(--dynamic-brand-primary-color))',
64
+ fontSize: 14,
65
+ fontWeight: 600,
66
+ };
55
67
  const baseStepIndicatorStyle = {
56
68
  alignItems: 'center',
57
69
  borderRadius: '50%',
@@ -71,13 +83,31 @@ const getStepIndicatorStyle = (current, completed) => {
71
83
  return Object.assign(Object.assign({}, baseStepIndicatorStyle), { background: 'transparent', borderColor: 'var(--dynamic-border-color)', color: 'var(--dynamic-text-secondary)' });
72
84
  };
73
85
  const WalletUpgradeFlowView = ({ wallets, onUpgrade, onFinish, }) => {
74
- const { i18nSDKInstance } = useDynamicContext();
86
+ const { i18nSDKInstance, user } = useDynamicContext();
75
87
  const { t } = useTranslation('translation', { i18n: i18nSDKInstance });
76
- const [currentIndex, setCurrentIndex] = useState(0);
88
+ const { initPasskeyRecoveryProcess, setUpgradeWalletIndex, supportedAuthenticators, upgradeWalletIndex, } = useLegacyWalletMigrationRecovery();
89
+ const supportButtonKey = 'dyn_need_help_section.help_button';
90
+ // Kept in context too so the flow resumes on the same wallet after a
91
+ // recovery step unmounts this view.
92
+ const [currentIndex, setCurrentIndex] = useState(upgradeWalletIndex);
77
93
  const [privateKeyInput, setPrivateKeyInput] = useState('');
78
94
  const [isUpgrading, setIsUpgrading] = useState(false);
79
95
  const [errorMessage, setErrorMessage] = useState(null);
96
+ const [exportError, setExportError] = useState();
80
97
  const currentWallet = wallets[currentIndex];
98
+ // Map the raw export failure (e.g. a rejected WebAuthn ceremony) to the
99
+ // same user-facing copy the main widget export view shows.
100
+ const exportErrorText = useMemo(() => {
101
+ if (exportError === undefined) {
102
+ return undefined;
103
+ }
104
+ try {
105
+ return getProperErrorMessage(exportError, user);
106
+ }
107
+ catch (_a) {
108
+ return t('dyn_wallet_upgrade_flow.export_failed');
109
+ }
110
+ }, [exportError, t, user]);
81
111
  if (!currentWallet) {
82
112
  return null;
83
113
  }
@@ -93,11 +123,17 @@ const WalletUpgradeFlowView = ({ wallets, onUpgrade, onFinish, }) => {
93
123
  wallet: currentWallet,
94
124
  });
95
125
  setPrivateKeyInput('');
126
+ // Clear a previous wallet's failed export so its error and recovery
127
+ // link don't carry over to the next wallet.
128
+ setExportError(undefined);
96
129
  if (isLastWallet) {
130
+ setUpgradeWalletIndex(0);
97
131
  onFinish();
98
132
  }
99
133
  else {
100
- setCurrentIndex((previous) => previous + 1);
134
+ const nextIndex = currentIndex + 1;
135
+ setUpgradeWalletIndex(nextIndex);
136
+ setCurrentIndex(nextIndex);
101
137
  }
102
138
  }
103
139
  catch (error) {
@@ -120,7 +156,7 @@ const WalletUpgradeFlowView = ({ wallets, onUpgrade, onFinish, }) => {
120
156
  : {}), { children: completed ? '✓' : index + 1 })), jsx(Typography, { variant: 'body_small', color: index <= currentIndex ? 'primary' : 'secondary', children: t('dyn_wallet_upgrade_flow.step_wallet_upgrade', {
121
157
  walletName: (_a = wallet.chain) !== null && _a !== void 0 ? _a : 'Wallet',
122
158
  }) }), index < totalSteps - 1 && jsx("div", { style: stepSeparatorStyle })] }, (_b = wallet.id) !== null && _b !== void 0 ? _b : index));
123
- }) })) }), jsxs("div", { style: contentStyle, children: [errorMessage && jsx(ErrorContainer, { children: errorMessage }), jsxs("div", { style: titleSectionStyle, children: [jsx(Typography, { as: 'h1', variant: 'title', color: 'primary', children: t('dyn_wallet_upgrade_flow.title') }), jsx(Typography, { color: 'secondary', children: t('dyn_wallet_upgrade_flow.copy_private_key_subtitle') })] }), jsxs("div", { style: sectionStyle, children: [jsx(Typography, { variant: 'body_normal', weight: 'bold', color: 'primary', children: t('dyn_wallet_upgrade_flow.copy_private_key_title') }), jsx(LegacyEmbeddedWalletExport, { wallet: currentWallet }, `wallet-export-${currentIndex}-${currentWallet.id}`)] }), jsxs("div", { style: sectionStyle, children: [jsx(Typography, { variant: 'body_normal', weight: 'bold', color: 'primary', children: t('dyn_wallet_upgrade_flow.step_2_upgrade_description') }), jsx(Textarea, { id: 'wallet-upgrade-flow-private-key', value: privateKeyInput, onChange: (event) => setPrivateKeyInput(event.target.value), variant: 'regular', label: '', "data-testid": 'paste-private-key-input' })] })] }), jsx("div", { style: actionsStyle, children: jsx(TypographyButton, { buttonVariant: 'brand-primary', onClick: handleUpgrade, disabled: !trimmedPrivateKey || isUpgrading, loading: isUpgrading, expanded: true, dataTestId: 'wallet-upgrade-flow-upgrade-button', typographyProps: { color: 'inherit' }, children: t('dyn_wallet_upgrade_flow.upgrade_wallet') }) })] }));
159
+ }) })) }), jsxs("div", { style: contentStyle, children: [errorMessage && jsx(ErrorContainer, { children: errorMessage }), exportErrorText && jsx(ErrorContainer, { children: exportErrorText }), jsxs("div", { style: titleSectionStyle, children: [jsx(Typography, { as: 'h1', variant: 'title', color: 'primary', children: t('dyn_wallet_upgrade_flow.title') }), jsx(Typography, { color: 'secondary', children: t('dyn_wallet_upgrade_flow.copy_private_key_subtitle') })] }), jsxs("div", { style: sectionStyle, children: [jsx(Typography, { variant: 'body_normal', weight: 'bold', color: 'primary', children: t('dyn_wallet_upgrade_flow.copy_private_key_title') }), jsx(LegacyEmbeddedWalletExport, { wallet: currentWallet, onExportFailed: setExportError }, `wallet-export-${currentIndex}-${currentWallet.id}`)] }), jsxs("div", { style: sectionStyle, children: [jsx(Typography, { variant: 'body_normal', weight: 'bold', color: 'primary', children: t('dyn_wallet_upgrade_flow.step_2_upgrade_description') }), jsx(Textarea, { id: 'wallet-upgrade-flow-private-key', value: privateKeyInput, onChange: (event) => setPrivateKeyInput(event.target.value), variant: 'regular', label: '', "data-testid": 'paste-private-key-input' })] }), exportError !== undefined && supportedAuthenticators.length > 0 && (jsxs("div", { style: needHelpStyle, "data-testid": 'wallet-upgrade-flow-need-help', children: [jsx(Typography, { variant: 'body_small', color: 'secondary', children: t('dyn_need_help_section.info.v1') }), jsx(TextButton, { type: 'button', style: supportLinkStyle, copykey: supportButtonKey, onClick: () => initPasskeyRecoveryProcess(undefined, undefined, currentWallet), "data-testid": 'wallet-upgrade-flow-support-button', children: t(supportButtonKey) })] }))] }), jsx("div", { style: actionsStyle, children: jsx(TypographyButton, { buttonVariant: 'brand-primary', onClick: handleUpgrade, disabled: !trimmedPrivateKey || isUpgrading, loading: isUpgrading, expanded: true, dataTestId: 'wallet-upgrade-flow-upgrade-button', typographyProps: { color: 'inherit' }, children: t('dyn_wallet_upgrade_flow.upgrade_wallet') }) })] }));
124
160
  };
125
161
 
126
162
  export { WalletUpgradeFlowView };