@dynamic-labs/legacy-embedded-wallet-migration 5.19.0 → 5.21.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 +27 -0
- package/README.md +61 -0
- package/package.js +1 -1
- package/package.json +8 -8
- package/src/index.d.ts +2 -2
- package/src/index.js +1 -1
- package/src/lib/constants.d.ts +3 -0
- package/src/lib/constants.js +4 -1
- package/src/lib/ui/LegacyWalletMigrationContext/LegacyWalletMigrationContext.d.ts +35 -2
- package/src/lib/ui/LegacyWalletMigrationContext/LegacyWalletMigrationContext.js +101 -6
- package/src/lib/ui/LegacyWalletMigrationContext/index.d.ts +1 -1
- package/src/lib/ui/LegacyWalletMigrationModal/LegacyWalletMigrationModal.d.ts +8 -0
- package/src/lib/ui/LegacyWalletMigrationModal/LegacyWalletMigrationModal.js +9 -2
- package/src/lib/useLegacyWalletsToMigrate/index.d.ts +1 -1
- package/src/lib/useLegacyWalletsToMigrate/useLegacyWalletsToMigrate.d.ts +5 -0
- package/src/lib/useLegacyWalletsToMigrate/useLegacyWalletsToMigrate.js +5 -1
- package/src/lib/useUpgradeToDynamicWaas/useUpgradeToDynamicWaas.d.ts +3 -0
- package/src/lib/useUpgradeToDynamicWaas/useUpgradeToDynamicWaas.js +11 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
|
|
2
|
+
## [5.21.0](https://github.com/dynamic-labs/dynamic-auth/compare/v5.20.0...v5.21.0) (2026-11-26)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* **sdk-react-core:** export hasElevatedAccessToken ([#12835](https://github.com/dynamic-labs/dynamic-auth/issues/12835)) ([671c52f](https://github.com/dynamic-labs/dynamic-auth/commit/671c52f8f2d7c715de30c2b6daa714f293b947bc))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* **aleo:** pin [@provablehq](https://github.com/provablehq) packages to matching 1.0.0 set ([#12445](https://github.com/dynamic-labs/dynamic-auth/issues/12445)) ([ad73fb3](https://github.com/dynamic-labs/dynamic-auth/commit/ad73fb33a1ed911bb3f629861499c2f87c7a13f4))
|
|
13
|
+
* **sdk-react-core:** match wallet connectors by name with the chain suffix ([#12836](https://github.com/dynamic-labs/dynamic-auth/issues/12836)) ([9366ab7](https://github.com/dynamic-labs/dynamic-auth/commit/9366ab7d25f2e7bd501073d96c44b1244faf2b4c))
|
|
14
|
+
|
|
15
|
+
## [5.20.0](https://github.com/dynamic-labs/dynamic-auth/compare/v5.19.0...v5.20.0) (2026-11-20)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* **webview:** add Tron connectors (WaaS + external) to the webview controller ([#12548](https://github.com/dynamic-labs/dynamic-auth/issues/12548)) ([526e2e0](https://github.com/dynamic-labs/dynamic-auth/commit/526e2e098a2290979897c7b6694c898d3dda78c4))
|
|
21
|
+
* **webview:** add Tron support to the webview bridge ([#12547](https://github.com/dynamic-labs/dynamic-auth/issues/12547)) ([8e1c25b](https://github.com/dynamic-labs/dynamic-auth/commit/8e1c25b9b438b5e0b5c3906b5a5b6af42a358a81))
|
|
22
|
+
* **webview:** reveal a named wallet's key from the native SDKs ([#12819](https://github.com/dynamic-labs/dynamic-auth/issues/12819)) ([ddd552e](https://github.com/dynamic-labs/dynamic-auth/commit/ddd552e6af5180657ddaca3c1c6bcb1291e0a594))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* **sdk-react-core:** emit embeddedWalletRevealFailed instead of throwing in EmbeddedRevealView ([#12820](https://github.com/dynamic-labs/dynamic-auth/issues/12820)) ([b9d8804](https://github.com/dynamic-labs/dynamic-auth/commit/b9d8804f318ba1de9664e85b3c05175be24f186b))
|
|
28
|
+
|
|
2
29
|
## [5.19.0](https://github.com/dynamic-labs/dynamic-auth/compare/v5.18.0...v5.19.0) (2026-11-18)
|
|
3
30
|
|
|
4
31
|
|
package/README.md
CHANGED
|
@@ -3,3 +3,64 @@
|
|
|
3
3
|
Utilities for migrating legacy Turnkey embedded wallets to Dynamic WaaS wallets.
|
|
4
4
|
|
|
5
5
|
In v5, Turnkey-specific embedded wallet logic no longer ships in `@dynamic-labs/sdk-react-core`. Applications that still have users on legacy Turnkey embedded wallets should import the migration helpers from this package to upgrade those users to WaaS wallets.
|
|
6
|
+
|
|
7
|
+
## Quick start
|
|
8
|
+
|
|
9
|
+
### With the built-in modal
|
|
10
|
+
|
|
11
|
+
Wrap your app (inside `DynamicContextProvider`) with `LegacyWalletMigrationProvider`. The modal opens by itself when the user has a legacy wallet, and the project must use V3 embedded wallets as the default.
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { LegacyWalletMigrationProvider } from '@dynamic-labs/legacy-embedded-wallet-migration';
|
|
15
|
+
|
|
16
|
+
<LegacyWalletMigrationProvider
|
|
17
|
+
onClose={(reason) => console.log('migration modal closed', reason)}
|
|
18
|
+
onError={(error) => console.error(error.code, error.message)}
|
|
19
|
+
>
|
|
20
|
+
<App />
|
|
21
|
+
</LegacyWalletMigrationProvider>;
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Provider props:
|
|
25
|
+
|
|
26
|
+
| Prop | Description |
|
|
27
|
+
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
28
|
+
| `autoOpen` | Open the modal when a legacy wallet is detected. Defaults to `true`. |
|
|
29
|
+
| `onClose(reason)` | Called once per close. `reason` is `'completed'`, `'cancelled'` or `'error'`. |
|
|
30
|
+
| `onError(error)` | Called with a `DynamicError` for a failed upgrade (`legacy_wallet_upgrade_failed`), a failed recovery check (`legacy_wallet_recovery_failed`) or an auto-open skipped because V3 is not the project default (`legacy_wallet_migration_v3_not_enabled`). An error thrown by the upgrade keeps its own code, e.g. `wallet_connector_not_found`. |
|
|
31
|
+
| `onUpgrade` | Replaces the upgrade handler. Defaults to `useUpgradeToDynamicWaas().upgradeToDynamicWaas`. |
|
|
32
|
+
|
|
33
|
+
Read and drive the flow with `useLegacyWalletMigration()`: `isOpen`, `status` (`'idle' | 'in_progress' | 'completed' | 'failed'`), `step`, `startUpgrade()`, `close()` and `goToStep()`.
|
|
34
|
+
|
|
35
|
+
### Headless
|
|
36
|
+
|
|
37
|
+
Set `autoOpen={false}` and build your own UI.
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import {
|
|
41
|
+
useHasLegacyWalletsToMigrate,
|
|
42
|
+
useLegacyWalletsToMigrate,
|
|
43
|
+
useUpgradeToDynamicWaas,
|
|
44
|
+
} from '@dynamic-labs/legacy-embedded-wallet-migration';
|
|
45
|
+
|
|
46
|
+
const hasLegacyWallets = useHasLegacyWalletsToMigrate();
|
|
47
|
+
const wallets = useLegacyWalletsToMigrate();
|
|
48
|
+
const { upgradeToDynamicWaas, isUpgradeInProgress } = useUpgradeToDynamicWaas();
|
|
49
|
+
|
|
50
|
+
await upgradeToDynamicWaas({ wallet: wallets[0], privateKey });
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- `useLegacyWalletsToMigrate()` returns the user's legacy Turnkey wallets.
|
|
54
|
+
- `useHasLegacyWalletsToMigrate()` returns whether there are any.
|
|
55
|
+
- `isLegacyWallet(wallet)` tells whether a single wallet is a legacy one.
|
|
56
|
+
- `isUpgradeInProgress` is state that re-renders; `isUpgrading` is a ref that does not.
|
|
57
|
+
|
|
58
|
+
## Modal behavior
|
|
59
|
+
|
|
60
|
+
- While legacy wallets remain, backdrop click and Escape do nothing. The user leaves by finishing the flow, or your app calls `close()`.
|
|
61
|
+
- `close()` resets the modal even mid-upgrade. `onClose` reports `'error'` if the last upgrade failed.
|
|
62
|
+
|
|
63
|
+
## Theming and copy
|
|
64
|
+
|
|
65
|
+
- The modal root has the class `legacy-wallet-migration-modal`. Target it with `settings.cssOverrides` on `DynamicContextProvider`.
|
|
66
|
+
- Text comes from the `dyn_upgrade_wallet.*` and `dyn_wallet_upgrade_flow.*` keys (for example `dyn_upgrade_wallet.title`, `dyn_wallet_upgrade_flow.upgrade_failed`). Override them with the `locale` prop on `DynamicContextProvider`.
|
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/legacy-embedded-wallet-migration",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.21.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"module": "./src/index.js",
|
|
@@ -16,16 +16,16 @@
|
|
|
16
16
|
"./package.json": "./package.json"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@dynamic-labs-sdk/client": "1.
|
|
20
|
-
"@dynamic-labs/assert-package-version": "5.
|
|
21
|
-
"@dynamic-labs/sdk-api-core": "0.
|
|
22
|
-
"@dynamic-labs/utils": "5.
|
|
23
|
-
"@dynamic-labs/wallet-connector-core": "5.
|
|
19
|
+
"@dynamic-labs-sdk/client": "1.55.0",
|
|
20
|
+
"@dynamic-labs/assert-package-version": "5.21.0",
|
|
21
|
+
"@dynamic-labs/sdk-api-core": "0.187.0",
|
|
22
|
+
"@dynamic-labs/utils": "5.21.0",
|
|
23
|
+
"@dynamic-labs/wallet-connector-core": "5.21.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@dynamic-labs/sdk-react-core": "5.
|
|
26
|
+
"@dynamic-labs/sdk-react-core": "5.21.0",
|
|
27
27
|
"react": ">=18.0.0 <20.0.0",
|
|
28
28
|
"react-i18next": ">=13.0.0",
|
|
29
|
-
"@dynamic-labs/types": "5.
|
|
29
|
+
"@dynamic-labs/types": "5.21.0"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ export { softDeleteEmbeddedWallet } from './lib/softDeleteEmbeddedWallet';
|
|
|
3
3
|
export { upgradeToDynamicWaas } from './lib/upgradeToDynamicWaas';
|
|
4
4
|
export { useUpgradeToDynamicWaas } from './lib/useUpgradeToDynamicWaas';
|
|
5
5
|
export { useHasLegacyWalletsToMigrate } from './lib/useLegacyWalletsToMigrate';
|
|
6
|
-
export { useLegacyWalletsToMigrate } from './lib/useLegacyWalletsToMigrate';
|
|
6
|
+
export { isLegacyWallet, useLegacyWalletsToMigrate, } from './lib/useLegacyWalletsToMigrate';
|
|
7
7
|
export { LegacyEmbeddedWalletExport, type LegacyEmbeddedWalletExportProps, } from './lib/ui/LegacyEmbeddedWalletExport';
|
|
8
8
|
export { LegacyWalletExportSheet, type LegacyWalletExportSheetProps, } from './lib/ui/LegacyWalletExportSheet';
|
|
9
9
|
export { useLegacyWalletExport, type RevealLegacyWalletKeyParams, } from './lib/ui/useLegacyWalletExport';
|
|
10
|
-
export { LegacyWalletMigrationProvider, useLegacyWalletMigration, type LegacyWalletMigrationContextType, type LegacyWalletMigrationProviderProps, } from './lib/ui/LegacyWalletMigrationContext';
|
|
10
|
+
export { LegacyWalletMigrationProvider, useLegacyWalletMigration, type LegacyWalletMigrationCloseReason, type LegacyWalletMigrationContextType, type LegacyWalletMigrationStatus, type LegacyWalletMigrationProviderProps, type StartUpgradeArgs, } from './lib/ui/LegacyWalletMigrationContext';
|
|
11
11
|
export { LegacyWalletMigrationModal, type LegacyWalletMigrationModalProps, type LegacyWalletMigrationOnUpgrade, type LegacyWalletMigrationStep, } from './lib/ui/LegacyWalletMigrationModal';
|
package/src/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { softDeleteEmbeddedWallet } from './lib/softDeleteEmbeddedWallet/softDel
|
|
|
6
6
|
export { upgradeToDynamicWaas } from './lib/upgradeToDynamicWaas/upgradeToDynamicWaas.js';
|
|
7
7
|
export { useUpgradeToDynamicWaas } from './lib/useUpgradeToDynamicWaas/useUpgradeToDynamicWaas.js';
|
|
8
8
|
export { useHasLegacyWalletsToMigrate } from './lib/useLegacyWalletsToMigrate/useHasLegacyWalletsToMigrate.js';
|
|
9
|
-
export { useLegacyWalletsToMigrate } from './lib/useLegacyWalletsToMigrate/useLegacyWalletsToMigrate.js';
|
|
9
|
+
export { isLegacyWallet, useLegacyWalletsToMigrate } from './lib/useLegacyWalletsToMigrate/useLegacyWalletsToMigrate.js';
|
|
10
10
|
export { LegacyEmbeddedWalletExport } from './lib/ui/LegacyEmbeddedWalletExport/LegacyEmbeddedWalletExport.js';
|
|
11
11
|
export { LegacyWalletExportSheet } from './lib/ui/LegacyWalletExportSheet/LegacyWalletExportSheet.js';
|
|
12
12
|
export { useLegacyWalletExport } from './lib/ui/useLegacyWalletExport/useLegacyWalletExport.js';
|
package/src/lib/constants.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ export declare const iframeElementId = "dyn-turnkey-export-element-id";
|
|
|
4
4
|
export declare const ERROR_PROCESSING_REVEAL_REQUEST = "error_processing_reveal_request";
|
|
5
5
|
export declare const INVALID_WALLET_DATA = "invalid_wallet";
|
|
6
6
|
export declare const USER_NOT_LOGGED_IN = "user_not_logged_in";
|
|
7
|
+
export declare const LEGACY_MIGRATION_UPGRADE_FAILED = "legacy_wallet_upgrade_failed";
|
|
8
|
+
export declare const LEGACY_MIGRATION_RECOVERY_FAILED = "legacy_wallet_recovery_failed";
|
|
9
|
+
export declare const LEGACY_MIGRATION_V3_NOT_ENABLED = "legacy_wallet_migration_v3_not_enabled";
|
|
7
10
|
export declare const SECURE_ENCLAVE_WALLET_SESSION_KEYS = "dynamic_secure_enclave_session_keys";
|
|
8
11
|
export declare const UPGRADE_TO_WAAS_MESSAGES: {
|
|
9
12
|
readonly completed: "Upgrade to WaaS - migration completed";
|
package/src/lib/constants.js
CHANGED
|
@@ -4,6 +4,9 @@ const iframeElementId = 'dyn-turnkey-export-element-id';
|
|
|
4
4
|
const ERROR_PROCESSING_REVEAL_REQUEST = 'error_processing_reveal_request';
|
|
5
5
|
const INVALID_WALLET_DATA = 'invalid_wallet';
|
|
6
6
|
const USER_NOT_LOGGED_IN = 'user_not_logged_in';
|
|
7
|
+
const LEGACY_MIGRATION_UPGRADE_FAILED = 'legacy_wallet_upgrade_failed';
|
|
8
|
+
const LEGACY_MIGRATION_RECOVERY_FAILED = 'legacy_wallet_recovery_failed';
|
|
9
|
+
const LEGACY_MIGRATION_V3_NOT_ENABLED = 'legacy_wallet_migration_v3_not_enabled';
|
|
7
10
|
const SECURE_ENCLAVE_WALLET_SESSION_KEYS = 'dynamic_secure_enclave_session_keys';
|
|
8
11
|
const UPGRADE_TO_WAAS_MESSAGES = {
|
|
9
12
|
completed: 'Upgrade to WaaS - migration completed',
|
|
@@ -21,4 +24,4 @@ const SECURE_ENCLAVE_WALLET_SESSION_KEYS_STORAGE_OPTIONS = {
|
|
|
21
24
|
priority: ['secureStorage', 'localStorage'],
|
|
22
25
|
};
|
|
23
26
|
|
|
24
|
-
export { ERROR_PROCESSING_REVEAL_REQUEST, INVALID_WALLET_DATA, SECURE_ENCLAVE_WALLET_SESSION_KEYS, SECURE_ENCLAVE_WALLET_SESSION_KEYS_STORAGE_OPTIONS, UPGRADE_TO_WAAS_KEYS, UPGRADE_TO_WAAS_MESSAGES, USER_NOT_LOGGED_IN, iframeContainerId, iframeElementId };
|
|
27
|
+
export { ERROR_PROCESSING_REVEAL_REQUEST, INVALID_WALLET_DATA, LEGACY_MIGRATION_RECOVERY_FAILED, LEGACY_MIGRATION_UPGRADE_FAILED, LEGACY_MIGRATION_V3_NOT_ENABLED, SECURE_ENCLAVE_WALLET_SESSION_KEYS, SECURE_ENCLAVE_WALLET_SESSION_KEYS_STORAGE_OPTIONS, UPGRADE_TO_WAAS_KEYS, UPGRADE_TO_WAAS_MESSAGES, USER_NOT_LOGGED_IN, iframeContainerId, iframeElementId };
|
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
import { FC, ReactNode } from 'react';
|
|
2
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
2
3
|
import { Wallet, WalletConnectorCore } from '@dynamic-labs/wallet-connector-core';
|
|
3
4
|
import { type LegacyWalletMigrationOnUpgrade, type LegacyWalletMigrationStep } from '../LegacyWalletMigrationModal';
|
|
4
|
-
type StartUpgradeArgs = {
|
|
5
|
+
export type StartUpgradeArgs = {
|
|
6
|
+
/** Wallets to migrate; defaults to the user's detected legacy wallets. */
|
|
5
7
|
wallets?: Wallet<WalletConnectorCore.WalletConnector>[];
|
|
8
|
+
/** Called when the user finishes the flow, right before the modal closes. */
|
|
6
9
|
onComplete?: () => void;
|
|
7
10
|
};
|
|
11
|
+
export type LegacyWalletMigrationCloseReason = 'completed' | 'cancelled' | 'error';
|
|
12
|
+
export type LegacyWalletMigrationStatus = 'idle' | 'in_progress' | 'completed' | 'failed';
|
|
8
13
|
export type LegacyWalletMigrationContextType = {
|
|
14
|
+
/** `true` while the migration modal is visible. */
|
|
9
15
|
isOpen: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Outcome of the latest migration flow; resets to `in_progress` on the
|
|
18
|
+
* next `startUpgrade()`.
|
|
19
|
+
*/
|
|
20
|
+
status: LegacyWalletMigrationStatus;
|
|
21
|
+
/** Current screen of the modal flow. */
|
|
10
22
|
step: LegacyWalletMigrationStep;
|
|
23
|
+
/** Opens the modal at the first step. */
|
|
11
24
|
startUpgrade: (args?: StartUpgradeArgs) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Closes the modal and resets its state, even mid-upgrade; it is also the
|
|
27
|
+
* only way out while legacy wallets remain, since backdrop click and Escape
|
|
28
|
+
* are ignored.
|
|
29
|
+
*/
|
|
12
30
|
close: () => void;
|
|
31
|
+
/** Jumps to another screen of the flow. */
|
|
13
32
|
goToStep: (step: LegacyWalletMigrationStep) => void;
|
|
14
33
|
};
|
|
15
34
|
export declare const LegacyWalletMigrationContext: import("react").Context<LegacyWalletMigrationContextType | undefined>;
|
|
@@ -36,7 +55,21 @@ export type LegacyWalletMigrationProviderProps = {
|
|
|
36
55
|
* does not throw, and `startUpgrade()` can still be called manually.
|
|
37
56
|
*/
|
|
38
57
|
autoOpen?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Called once each time the modal closes, whether the user finished,
|
|
60
|
+
* cancelled, or the app called `close()`. `reason` is `'completed'` when the
|
|
61
|
+
* user finishes the flow and `'error'` when an upgrade failed and was not
|
|
62
|
+
* retried successfully.
|
|
63
|
+
*/
|
|
64
|
+
onClose?: (reason: LegacyWalletMigrationCloseReason) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Called when an upgrade or the recovery check fails, or when auto-open is
|
|
67
|
+
* skipped because V3 is not the project default. `error.code` is one of
|
|
68
|
+
* `legacy_wallet_upgrade_failed`, `legacy_wallet_recovery_failed`,
|
|
69
|
+
* `legacy_wallet_migration_v3_not_enabled`, or the code of the
|
|
70
|
+
* `DynamicError` thrown by the upgrade (e.g. `wallet_connector_not_found`).
|
|
71
|
+
*/
|
|
72
|
+
onError?: (error: DynamicError) => void;
|
|
39
73
|
};
|
|
40
74
|
export declare const LegacyWalletMigrationProvider: FC<LegacyWalletMigrationProviderProps>;
|
|
41
75
|
export declare const useLegacyWalletMigration: () => LegacyWalletMigrationContextType;
|
|
42
|
-
export {};
|
|
@@ -1,19 +1,44 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
2
3
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { createContext, useState, useRef,
|
|
4
|
+
import { createContext, useState, useRef, useCallback, useEffect, useMemo, useContext } from 'react';
|
|
4
5
|
import { EmbeddedWalletVersionEnum } from '@dynamic-labs/sdk-api-core';
|
|
5
6
|
import { useProjectSettings, setLegacyMigrationProviderMounted } from '@dynamic-labs/sdk-react-core';
|
|
7
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
6
8
|
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
9
|
+
import { LEGACY_MIGRATION_V3_NOT_ENABLED, LEGACY_MIGRATION_RECOVERY_FAILED, LEGACY_MIGRATION_UPGRADE_FAILED } from '../../constants.js';
|
|
7
10
|
import { useLegacyWalletsToMigrate } from '../../useLegacyWalletsToMigrate/useLegacyWalletsToMigrate.js';
|
|
8
11
|
import { useUpgradeToDynamicWaas } from '../../useUpgradeToDynamicWaas/useUpgradeToDynamicWaas.js';
|
|
9
12
|
import { LegacyWalletMigrationModal } from '../LegacyWalletMigrationModal/LegacyWalletMigrationModal.js';
|
|
10
13
|
import { LegacyWalletMigrationRecoveryProvider } from '../LegacyWalletMigrationRecoveryContext/LegacyWalletMigrationRecoveryContext.js';
|
|
11
14
|
|
|
12
15
|
const LegacyWalletMigrationContext = createContext(undefined);
|
|
16
|
+
const STATUS_AFTER_CLOSE = {
|
|
17
|
+
cancelled: 'idle',
|
|
18
|
+
completed: 'completed',
|
|
19
|
+
error: 'failed',
|
|
20
|
+
};
|
|
21
|
+
const getCloseReason = (hasCompleted, hasFailed) => {
|
|
22
|
+
if (hasCompleted)
|
|
23
|
+
return 'completed';
|
|
24
|
+
if (hasFailed)
|
|
25
|
+
return 'error';
|
|
26
|
+
return 'cancelled';
|
|
27
|
+
};
|
|
13
28
|
const CLOSED_STATE = { open: false, step: 'select' };
|
|
14
|
-
const LegacyWalletMigrationProvider = ({ children, onUpgrade, autoOpen = true }) => {
|
|
29
|
+
const LegacyWalletMigrationProvider = ({ children, onUpgrade, autoOpen = true, onClose, onError }) => {
|
|
15
30
|
var _a, _b;
|
|
16
31
|
const [state, setState] = useState(CLOSED_STATE);
|
|
32
|
+
const [status, setStatusState] = useState('idle');
|
|
33
|
+
const statusRef = useRef('idle');
|
|
34
|
+
const isOpenRef = useRef(false);
|
|
35
|
+
// Bumped on every open and close so late results from a previous flow are ignored.
|
|
36
|
+
const flowIdRef = useRef(0);
|
|
37
|
+
const hasCompletedRef = useRef(false);
|
|
38
|
+
const onCloseRef = useRef(onClose);
|
|
39
|
+
onCloseRef.current = onClose;
|
|
40
|
+
const onErrorRef = useRef(onError);
|
|
41
|
+
onErrorRef.current = onError;
|
|
17
42
|
const legacyWallets = useLegacyWalletsToMigrate();
|
|
18
43
|
const projectSettings = useProjectSettings();
|
|
19
44
|
const hasAutoOpenedRef = useRef(false);
|
|
@@ -21,6 +46,23 @@ const LegacyWalletMigrationProvider = ({ children, onUpgrade, autoOpen = true })
|
|
|
21
46
|
const effectiveOnUpgrade = onUpgrade !== null && onUpgrade !== void 0 ? onUpgrade : upgradeToDynamicWaas;
|
|
22
47
|
const isV3EmbeddedWalletEnabled = ((_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _a === void 0 ? void 0 : _a.embeddedWallets) === null || _b === void 0 ? void 0 : _b.defaultWalletVersion) ===
|
|
23
48
|
EmbeddedWalletVersionEnum.V3;
|
|
49
|
+
// `useProjectSettings` is undefined until the settings have loaded.
|
|
50
|
+
const isProjectSettingsLoaded = Boolean(projectSettings);
|
|
51
|
+
const setStatus = useCallback((next) => {
|
|
52
|
+
statusRef.current = next;
|
|
53
|
+
setStatusState(next);
|
|
54
|
+
}, []);
|
|
55
|
+
const reportError = useCallback((error, code, fallbackMessage) => {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const isDynamicError = error instanceof DynamicError;
|
|
58
|
+
if (isDynamicError) {
|
|
59
|
+
(_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef, error);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const isNativeError = error instanceof Error;
|
|
63
|
+
const message = isNativeError ? error.message : fallbackMessage;
|
|
64
|
+
(_b = onErrorRef.current) === null || _b === void 0 ? void 0 : _b.call(onErrorRef, new DynamicError(message, code));
|
|
65
|
+
}, []);
|
|
24
66
|
// Advertise to sdk-react-core that the migration provider is mounted so
|
|
25
67
|
// its `useEnforceLegacyMigrationProvider` does not throw when a legacy
|
|
26
68
|
// Turnkey wallet is loaded.
|
|
@@ -30,6 +72,10 @@ const LegacyWalletMigrationProvider = ({ children, onUpgrade, autoOpen = true })
|
|
|
30
72
|
}, []);
|
|
31
73
|
const startUpgrade = useCallback((args) => {
|
|
32
74
|
var _a;
|
|
75
|
+
flowIdRef.current += 1;
|
|
76
|
+
isOpenRef.current = true;
|
|
77
|
+
hasCompletedRef.current = false;
|
|
78
|
+
setStatus('in_progress');
|
|
33
79
|
setState({
|
|
34
80
|
onComplete: args === null || args === void 0 ? void 0 : args.onComplete,
|
|
35
81
|
open: true,
|
|
@@ -39,7 +85,7 @@ const LegacyWalletMigrationProvider = ({ children, onUpgrade, autoOpen = true })
|
|
|
39
85
|
// `useLegacyWalletsToMigrate()` themselves.
|
|
40
86
|
wallets: (_a = args === null || args === void 0 ? void 0 : args.wallets) !== null && _a !== void 0 ? _a : legacyWallets,
|
|
41
87
|
});
|
|
42
|
-
}, [legacyWallets]);
|
|
88
|
+
}, [legacyWallets, setStatus]);
|
|
43
89
|
// Auto-open the migration modal the first time we observe a legacy Turnkey
|
|
44
90
|
// wallet on the user. Legacy wallets have no supported runtime path other
|
|
45
91
|
// than migration, so we force the flow open without requiring the consumer
|
|
@@ -66,10 +112,13 @@ const LegacyWalletMigrationProvider = ({ children, onUpgrade, autoOpen = true })
|
|
|
66
112
|
}
|
|
67
113
|
if (hasAutoOpenedRef.current)
|
|
68
114
|
return;
|
|
115
|
+
if (!isProjectSettingsLoaded)
|
|
116
|
+
return;
|
|
69
117
|
if (!isV3EmbeddedWalletEnabled) {
|
|
70
118
|
logger.error('Legacy embedded wallet detected, but `defaultWalletVersion` is not V3 in project settings. ' +
|
|
71
119
|
'Migration requires V3 to be the configured default. Skipping auto-open of the migration modal.');
|
|
72
120
|
hasAutoOpenedRef.current = true;
|
|
121
|
+
reportError(undefined, LEGACY_MIGRATION_V3_NOT_ENABLED, 'Legacy wallet migration requires `defaultWalletVersion` to be V3 in project settings.');
|
|
73
122
|
return;
|
|
74
123
|
}
|
|
75
124
|
hasAutoOpenedRef.current = true;
|
|
@@ -81,11 +130,56 @@ const LegacyWalletMigrationProvider = ({ children, onUpgrade, autoOpen = true })
|
|
|
81
130
|
legacyWallets,
|
|
82
131
|
state.open,
|
|
83
132
|
startUpgrade,
|
|
133
|
+
isProjectSettingsLoaded,
|
|
84
134
|
isV3EmbeddedWalletEnabled,
|
|
135
|
+
reportError,
|
|
85
136
|
]);
|
|
137
|
+
// Guarded by a ref so the finish + backdrop paths can't fire `onClose` twice.
|
|
86
138
|
const close = useCallback(() => {
|
|
139
|
+
var _a;
|
|
140
|
+
if (!isOpenRef.current)
|
|
141
|
+
return;
|
|
142
|
+
isOpenRef.current = false;
|
|
143
|
+
flowIdRef.current += 1;
|
|
144
|
+
const hasFailed = statusRef.current === 'failed';
|
|
145
|
+
const reason = getCloseReason(hasCompletedRef.current, hasFailed);
|
|
87
146
|
setState(CLOSED_STATE);
|
|
88
|
-
|
|
147
|
+
setStatus(STATUS_AFTER_CLOSE[reason]);
|
|
148
|
+
(_a = onCloseRef.current) === null || _a === void 0 ? void 0 : _a.call(onCloseRef, reason);
|
|
149
|
+
}, [setStatus]);
|
|
150
|
+
const handleUpgrade = useCallback((args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
|
+
const flowId = flowIdRef.current;
|
|
152
|
+
setStatus('in_progress');
|
|
153
|
+
try {
|
|
154
|
+
yield effectiveOnUpgrade(args);
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
// The flow may have been closed or restarted while the upgrade ran.
|
|
158
|
+
const isCurrentFlow = flowIdRef.current === flowId;
|
|
159
|
+
if (isCurrentFlow) {
|
|
160
|
+
setStatus('failed');
|
|
161
|
+
reportError(error, LEGACY_MIGRATION_UPGRADE_FAILED, 'Failed to upgrade wallet');
|
|
162
|
+
}
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}), [effectiveOnUpgrade, reportError, setStatus]);
|
|
166
|
+
const handleModalError = useCallback((error) => {
|
|
167
|
+
if (!isOpenRef.current)
|
|
168
|
+
return;
|
|
169
|
+
setStatus('failed');
|
|
170
|
+
reportError(error, LEGACY_MIGRATION_RECOVERY_FAILED, 'Failed to check wallet recovery');
|
|
171
|
+
}, [reportError, setStatus]);
|
|
172
|
+
const handleRecoveryCheckPassed = useCallback(() => {
|
|
173
|
+
const hasFailed = statusRef.current === 'failed';
|
|
174
|
+
if (!isOpenRef.current || !hasFailed)
|
|
175
|
+
return;
|
|
176
|
+
setStatus('in_progress');
|
|
177
|
+
}, [setStatus]);
|
|
178
|
+
const handleComplete = useCallback(() => {
|
|
179
|
+
var _a;
|
|
180
|
+
hasCompletedRef.current = true;
|
|
181
|
+
(_a = state.onComplete) === null || _a === void 0 ? void 0 : _a.call(state);
|
|
182
|
+
}, [state]);
|
|
89
183
|
const goToStep = useCallback((step) => {
|
|
90
184
|
setState((previous) => (Object.assign(Object.assign({}, previous), { step })));
|
|
91
185
|
}, []);
|
|
@@ -94,9 +188,10 @@ const LegacyWalletMigrationProvider = ({ children, onUpgrade, autoOpen = true })
|
|
|
94
188
|
goToStep,
|
|
95
189
|
isOpen: state.open,
|
|
96
190
|
startUpgrade,
|
|
191
|
+
status,
|
|
97
192
|
step: state.step,
|
|
98
|
-
}), [close, goToStep, startUpgrade, state.open, state.step]);
|
|
99
|
-
return (jsxs(LegacyWalletMigrationContext.Provider, { value: value, children: [children, jsx(LegacyWalletMigrationRecoveryProvider, { children: jsx(LegacyWalletMigrationModal, { open: state.open, step: state.step, onClose: close, onStepChange: goToStep, onComplete:
|
|
193
|
+
}), [close, goToStep, startUpgrade, state.open, state.step, status]);
|
|
194
|
+
return (jsxs(LegacyWalletMigrationContext.Provider, { value: value, children: [children, jsx(LegacyWalletMigrationRecoveryProvider, { children: jsx(LegacyWalletMigrationModal, { open: state.open, step: state.step, onClose: close, onStepChange: goToStep, onComplete: handleComplete, onError: handleModalError, onRecoveryCheckPassed: handleRecoveryCheckPassed, onUpgrade: handleUpgrade, wallets: state.wallets }) })] }));
|
|
100
195
|
};
|
|
101
196
|
const useLegacyWalletMigration = () => {
|
|
102
197
|
const context = useContext(LegacyWalletMigrationContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { LegacyWalletMigrationContext, LegacyWalletMigrationProvider, useLegacyWalletMigration, type LegacyWalletMigrationContextType, type LegacyWalletMigrationProviderProps, } from './LegacyWalletMigrationContext';
|
|
1
|
+
export { LegacyWalletMigrationContext, LegacyWalletMigrationProvider, useLegacyWalletMigration, type LegacyWalletMigrationCloseReason, type LegacyWalletMigrationContextType, type LegacyWalletMigrationStatus, type LegacyWalletMigrationProviderProps, type StartUpgradeArgs, } from './LegacyWalletMigrationContext';
|
|
@@ -9,7 +9,15 @@ export type LegacyWalletMigrationModalProps = {
|
|
|
9
9
|
onClose: () => void;
|
|
10
10
|
onStepChange: (step: LegacyWalletMigrationStep) => void;
|
|
11
11
|
onComplete?: () => void;
|
|
12
|
+
/** Reports failures that otherwise only reach the console, such as the recovery check. */
|
|
13
|
+
onError?: (error: unknown) => void;
|
|
14
|
+
/** Called when the recovery check succeeds, before the next step opens. */
|
|
15
|
+
onRecoveryCheckPassed?: () => void;
|
|
12
16
|
onUpgrade: LegacyWalletMigrationOnUpgrade;
|
|
13
17
|
wallets?: Wallet<WalletConnectorCore.WalletConnector>[];
|
|
14
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Migration modal rendered by `LegacyWalletMigrationProvider`; while legacy
|
|
21
|
+
* wallets remain, backdrop click and Escape do nothing so the user must finish.
|
|
22
|
+
*/
|
|
15
23
|
export declare const LegacyWalletMigrationModal: FC<LegacyWalletMigrationModalProps>;
|
|
@@ -13,13 +13,19 @@ import { LegacyEmbeddedAuthChoiceView } from '../recovery/LegacyEmbeddedAuthChoi
|
|
|
13
13
|
import { WalletUpgradeFlowView } from '../WalletUpgradeFlowView/WalletUpgradeFlowView.js';
|
|
14
14
|
import { WaasUpgradeView } from '../WaasUpgradeView/WaasUpgradeView.js';
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Migration modal rendered by `LegacyWalletMigrationProvider`; while legacy
|
|
18
|
+
* wallets remain, backdrop click and Escape do nothing so the user must finish.
|
|
19
|
+
*/
|
|
20
|
+
const LegacyWalletMigrationModal = ({ open, step, onClose, onStepChange, onComplete, onError, onRecoveryCheckPassed, onUpgrade, wallets, }) => {
|
|
17
21
|
const { addRecoveryEmail, bundleValidationError, completeRecovery, completeRecoveryError, initPasskeyRecoveryProcess, isCompletingRecovery, isValidatingBundle, recoveryEmail, resendRecoveryEmail, shouldInitRecovery, supportedAuthenticators, validateRecoveryBundle, } = useLegacyWalletMigrationRecovery();
|
|
18
22
|
const [isGatingUpgrade, setIsGatingUpgrade] = useState(false);
|
|
19
23
|
const goToUpgrade = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
24
|
setIsGatingUpgrade(true);
|
|
21
25
|
try {
|
|
22
|
-
|
|
26
|
+
const isRecoveryNeeded = yield shouldInitRecovery();
|
|
27
|
+
onRecoveryCheckPassed === null || onRecoveryCheckPassed === void 0 ? void 0 : onRecoveryCheckPassed();
|
|
28
|
+
if (isRecoveryNeeded) {
|
|
23
29
|
yield initPasskeyRecoveryProcess();
|
|
24
30
|
return;
|
|
25
31
|
}
|
|
@@ -27,6 +33,7 @@ const LegacyWalletMigrationModal = ({ open, step, onClose, onStepChange, onCompl
|
|
|
27
33
|
}
|
|
28
34
|
catch (err) {
|
|
29
35
|
logger.error('Failed to gate upgrade on recovery', err);
|
|
36
|
+
onError === null || onError === void 0 ? void 0 : onError(err);
|
|
30
37
|
}
|
|
31
38
|
finally {
|
|
32
39
|
setIsGatingUpgrade(false);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { useHasLegacyWalletsToMigrate } from './useHasLegacyWalletsToMigrate';
|
|
2
|
-
export { useLegacyWalletsToMigrate } from './useLegacyWalletsToMigrate';
|
|
2
|
+
export { isLegacyWallet, useLegacyWalletsToMigrate, } from './useLegacyWalletsToMigrate';
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { Wallet, WalletConnectorCore } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
/**
|
|
3
|
+
* Returns `true` for a legacy V1/V2 Turnkey wallet; useful to filter wallets
|
|
4
|
+
* yourself without calling `useLegacyWalletsToMigrate()`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const isLegacyWallet: (wallet: Wallet | undefined) => wallet is Wallet<WalletConnectorCore.WalletConnector>;
|
|
2
7
|
/**
|
|
3
8
|
* Returns the list of legacy V1/V2 Turnkey wallets on the current user that
|
|
4
9
|
* need to be migrated to V3 WaaS. Returns an empty array if there are none.
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
import { useUserWallets, useSmartWallets } from '@dynamic-labs/sdk-react-core';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Returns `true` for a legacy V1/V2 Turnkey wallet; useful to filter wallets
|
|
7
|
+
* yourself without calling `useLegacyWalletsToMigrate()`.
|
|
8
|
+
*/
|
|
5
9
|
const isLegacyWallet = (wallet) => Boolean(wallet === null || wallet === void 0 ? void 0 : wallet.connector.key.startsWith('turnkey'));
|
|
6
10
|
/**
|
|
7
11
|
* Returns the list of legacy V1/V2 Turnkey wallets on the current user that
|
|
@@ -29,4 +33,4 @@ const useLegacyWalletsToMigrate = () => {
|
|
|
29
33
|
}, [getEOAWallet, userWallets]);
|
|
30
34
|
};
|
|
31
35
|
|
|
32
|
-
export { useLegacyWalletsToMigrate };
|
|
36
|
+
export { isLegacyWallet, useLegacyWalletsToMigrate };
|
|
@@ -14,6 +14,9 @@ type UseUpgradeToDynamicWaasProps = {
|
|
|
14
14
|
onRestore?: () => Promise<unknown> | unknown;
|
|
15
15
|
};
|
|
16
16
|
export declare const useUpgradeToDynamicWaas: (props?: UseUpgradeToDynamicWaasProps) => {
|
|
17
|
+
/** `true` while an upgrade is running; re-renders the caller on change. */
|
|
18
|
+
isUpgradeInProgress: boolean;
|
|
19
|
+
/** Ref that never re-renders; read `isUpgradeInProgress` to drive UI. */
|
|
17
20
|
isUpgrading: import("react").MutableRefObject<boolean>;
|
|
18
21
|
upgradeToDynamicWaas: ({ privateKey, wallet, password }: UpgradeToDynamicWaasArgs) => Promise<void>;
|
|
19
22
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
-
import { useRef, useCallback } from 'react';
|
|
3
|
+
import { useRef, useState, useCallback } from 'react';
|
|
4
4
|
import { useDynamicWaas, useRefreshAuth } from '@dynamic-labs/sdk-react-core';
|
|
5
5
|
import { DynamicError } from '@dynamic-labs/utils';
|
|
6
6
|
import { upgradeToDynamicWaas } from '../upgradeToDynamicWaas/upgradeToDynamicWaas.js';
|
|
@@ -11,8 +11,10 @@ const useUpgradeToDynamicWaas = (props = {}) => {
|
|
|
11
11
|
const refreshAuth = useRefreshAuth();
|
|
12
12
|
const onRestore = (_a = props.onRestore) !== null && _a !== void 0 ? _a : refreshAuth;
|
|
13
13
|
const isUpgrading = useRef(false);
|
|
14
|
+
const [isUpgradeInProgress, setIsUpgradeInProgress] = useState(false);
|
|
14
15
|
const upgrade = useCallback((_b) => __awaiter(void 0, [_b], void 0, function* ({ privateKey, wallet, password }) {
|
|
15
16
|
isUpgrading.current = true;
|
|
17
|
+
setIsUpgradeInProgress(true);
|
|
16
18
|
try {
|
|
17
19
|
const chainName = wallet.chain;
|
|
18
20
|
const walletConnector = getWaasWalletConnector(chainName);
|
|
@@ -36,9 +38,16 @@ const useUpgradeToDynamicWaas = (props = {}) => {
|
|
|
36
38
|
}
|
|
37
39
|
finally {
|
|
38
40
|
isUpgrading.current = false;
|
|
41
|
+
setIsUpgradeInProgress(false);
|
|
39
42
|
}
|
|
40
43
|
}), [getWaasWalletConnector, onRestore, refreshAuth]);
|
|
41
|
-
return {
|
|
44
|
+
return {
|
|
45
|
+
/** `true` while an upgrade is running; re-renders the caller on change. */
|
|
46
|
+
isUpgradeInProgress,
|
|
47
|
+
/** Ref that never re-renders; read `isUpgradeInProgress` to drive UI. */
|
|
48
|
+
isUpgrading,
|
|
49
|
+
upgradeToDynamicWaas: upgrade,
|
|
50
|
+
};
|
|
42
51
|
};
|
|
43
52
|
|
|
44
53
|
export { useUpgradeToDynamicWaas };
|