@dynamic-labs/sdk-react-core 4.48.2 → 4.50.1
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/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +12 -12
- package/src/index.cjs +6 -4
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -2
- package/src/lib/context/DynamicContext/DynamicContext.cjs +1 -1
- package/src/lib/context/DynamicContext/DynamicContext.js +1 -1
- package/src/lib/context/DynamicContext/hooks/useTieCallbacksToEvents/useTieCallbacksToEvents.cjs +10 -0
- package/src/lib/context/DynamicContext/hooks/useTieCallbacksToEvents/useTieCallbacksToEvents.js +10 -0
- package/src/lib/context/OnrampContext/OnrampContext.cjs +4 -2
- package/src/lib/context/OnrampContext/OnrampContext.d.ts +1 -0
- package/src/lib/context/OnrampContext/OnrampContext.js +4 -2
- package/src/lib/context/OnrampContext/types.d.ts +1 -0
- package/src/lib/context/OnrampContext/utils/getOnrampProviders.cjs +2 -1
- package/src/lib/context/OnrampContext/utils/getOnrampProviders.d.ts +1 -1
- package/src/lib/context/OnrampContext/utils/getOnrampProviders.js +2 -1
- package/src/lib/context/PhantomRedirectContext/PhantomRedirectContext.cjs +38 -6
- package/src/lib/context/PhantomRedirectContext/PhantomRedirectContext.d.ts +2 -2
- package/src/lib/context/PhantomRedirectContext/PhantomRedirectContext.js +39 -8
- package/src/lib/context/PhantomRedirectContext/useResponseHandlers.cjs +108 -16
- package/src/lib/context/PhantomRedirectContext/useResponseHandlers.js +108 -16
- package/src/lib/context/ViewContext/types/index.d.ts +1 -1
- package/src/lib/data/api/onramp/onramp.cjs +2 -1
- package/src/lib/data/api/onramp/onramp.d.ts +2 -1
- package/src/lib/data/api/onramp/onramp.js +2 -1
- package/src/lib/events/dynamicEvents.cjs +2 -0
- package/src/lib/events/dynamicEvents.d.ts +1 -1
- package/src/lib/events/dynamicEvents.js +2 -0
- package/src/lib/shared/assets/backup-waas.cjs +4 -4
- package/src/lib/shared/assets/backup-waas.js +4 -4
- package/src/lib/shared/types/dynamicEventsCallbacks.d.ts +4 -0
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/constants/authViewLayoutChecks.cjs +13 -0
- package/src/lib/utils/constants/authViewLayoutChecks.js +13 -0
- package/src/lib/utils/functions/generateMessages/index.cjs +11 -2
- package/src/lib/utils/functions/generateMessages/index.js +11 -2
- package/src/lib/utils/functions/getVerifyArgs/getVerifyArgs.cjs +27 -1
- package/src/lib/utils/functions/getVerifyArgs/getVerifyArgs.js +27 -1
- package/src/lib/utils/functions/index.d.ts +0 -1
- package/src/lib/utils/hooks/events/useDynamicEvents/useDynamicEvents.d.ts +1 -1
- package/src/lib/utils/hooks/index.d.ts +2 -0
- package/src/lib/utils/hooks/useAuthenticatePasskeyMFA/useAuthenticatePasskeyMFA.cjs +5 -1
- package/src/lib/utils/hooks/useAuthenticatePasskeyMFA/useAuthenticatePasskeyMFA.js +5 -1
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.cjs +35 -5
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.d.ts +1 -0
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.js +35 -5
- package/src/lib/utils/hooks/useFunding/useFunding.d.ts +1 -0
- package/src/lib/utils/hooks/useOnramp/useOnramp.cjs +14 -29
- package/src/lib/utils/hooks/useOnramp/useOnramp.d.ts +14 -18
- package/src/lib/utils/hooks/useOnramp/useOnramp.js +14 -29
- package/src/lib/utils/hooks/usePhantomRedirectEvents/index.d.ts +1 -0
- package/src/lib/utils/hooks/usePhantomRedirectEvents/usePhantomRedirectEvents.cjs +65 -0
- package/src/lib/utils/hooks/usePhantomRedirectEvents/usePhantomRedirectEvents.d.ts +36 -0
- package/src/lib/utils/hooks/usePhantomRedirectEvents/usePhantomRedirectEvents.js +61 -0
- package/src/lib/utils/hooks/useSetWalletConnectorFetchers/useSetWalletConnectorFetchers.cjs +17 -14
- package/src/lib/utils/hooks/useSetWalletConnectorFetchers/useSetWalletConnectorFetchers.js +17 -14
- package/src/lib/utils/hooks/useSignInWithPasskey/useSignInWithPasskey.cjs +106 -1
- package/src/lib/utils/hooks/useSignInWithPasskey/useSignInWithPasskey.js +106 -1
- package/src/lib/utils/hooks/useSmartWallets/useSmartWallets.cjs +1 -1
- package/src/lib/utils/hooks/useSmartWallets/useSmartWallets.js +1 -1
- package/src/lib/utils/hooks/useSyncDynamicWaas/useSyncDynamicWaas.cjs +1 -1
- package/src/lib/utils/hooks/useSyncDynamicWaas/useSyncDynamicWaas.js +1 -1
- package/src/lib/utils/hooks/useWalletBackup/index.d.ts +1 -0
- package/src/lib/utils/hooks/useWalletBackup/useWalletBackup.cjs +339 -0
- package/src/lib/utils/hooks/useWalletBackup/useWalletBackup.d.ts +49 -0
- package/src/lib/utils/hooks/useWalletBackup/useWalletBackup.js +332 -0
- package/src/lib/utils/hooks/useWalletDelegation/useWalletDelegation.cjs +2 -2
- package/src/lib/utils/hooks/useWalletDelegation/useWalletDelegation.js +2 -2
- package/src/lib/utils/hooks/useWalletItemActions/useHandleWalletItem/useHandleWalletItem.cjs +1 -0
- package/src/lib/utils/hooks/useWalletItemActions/useHandleWalletItem/useHandleWalletItem.js +1 -0
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.cjs +13 -0
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.js +14 -1
- package/src/lib/views/MfaDisplayBackupCodesView/MfaDisplayBackupCodesView.cjs +9 -6
- package/src/lib/views/MfaDisplayBackupCodesView/MfaDisplayBackupCodesView.js +9 -6
- package/src/lib/views/WalletUpgradeFlowView/WalletUpgradeFlowView.cjs +13 -0
- package/src/lib/views/WalletUpgradeFlowView/WalletUpgradeFlowView.js +14 -1
- package/src/lib/views/WalletUsedView/WalletUsedView.cjs +1 -0
- package/src/lib/views/WalletUsedView/WalletUsedView.js +1 -0
- package/src/lib/views/viewToComponentMap.cjs +15 -3
- package/src/lib/views/viewToComponentMap.d.ts +6 -0
- package/src/lib/views/viewToComponentMap.js +15 -3
- package/src/lib/widgets/DynamicWidget/components/ActiveWalletBalance/TokenBalanceItem/TokenBalanceItem.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/components/ActiveWalletBalance/TokenBalanceItem/TokenBalanceItem.js +1 -1
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetViews/mapViewToComponent.cjs +97 -3
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetViews/mapViewToComponent.js +97 -3
- package/src/lib/widgets/DynamicWidget/views/AccountAndSecuritySettingsView/EmbeddedWalletExportSection/EmbeddedWalletExportSection.cjs +16 -14
- package/src/lib/widgets/DynamicWidget/views/AccountAndSecuritySettingsView/EmbeddedWalletExportSection/EmbeddedWalletExportSection.js +16 -14
- package/src/lib/widgets/DynamicWidget/views/CryptoComOnramp/CryptoComOnramp.cjs +3 -1
- package/src/lib/widgets/DynamicWidget/views/CryptoComOnramp/CryptoComOnramp.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/views/CryptoComOnramp/CryptoComOnramp.js +3 -1
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/BackupStepper.cjs +37 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/BackupStepper.d.ts +7 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/BackupStepper.js +33 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupCloudProviderView.cjs +49 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupCloudProviderView.d.ts +2 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupCloudProviderView.js +45 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupDownloadView.cjs +53 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupDownloadView.d.ts +2 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupDownloadView.js +49 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupInfoView.cjs +9 -18
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupInfoView.js +10 -19
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupProgressView.cjs +52 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupProgressView.d.ts +2 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupProgressView.js +48 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupSuccessView.cjs +131 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupSuccessView.d.ts +5 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupSuccessView.js +127 -0
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupView.cjs +45 -104
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/WaasBackupView.js +47 -106
- package/src/lib/widgets/DynamicWidget/views/WaasBackupView/index.d.ts +6 -1
- package/src/lib/utils/functions/downloadFile/downloadFile.cjs +0 -15
- package/src/lib/utils/functions/downloadFile/downloadFile.d.ts +0 -1
- package/src/lib/utils/functions/downloadFile/downloadFile.js +0 -11
- package/src/lib/utils/functions/downloadFile/index.d.ts +0 -1
|
@@ -76,6 +76,7 @@ import 'qrcode';
|
|
|
76
76
|
import 'formik';
|
|
77
77
|
import '../useSubdomainCheck/useSubdomainCheck.js';
|
|
78
78
|
import '../../../context/WalletGroupContext/WalletGroupContext.js';
|
|
79
|
+
import { useDynamicWaas } from '../useDynamicWaas/useDynamicWaas.js';
|
|
79
80
|
import '../../../context/IpConfigurationContext/IpConfigurationContext.js';
|
|
80
81
|
import '../../../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
|
|
81
82
|
import '../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
|
|
@@ -89,7 +90,6 @@ import '../../../views/MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.js'
|
|
|
89
90
|
import '../../../context/PasskeyContext/PasskeyContext.js';
|
|
90
91
|
import '../../../context/OnrampContext/OnrampContext.js';
|
|
91
92
|
import { useWalletDelegation } from '../useWalletDelegation/useWalletDelegation.js';
|
|
92
|
-
import { useDynamicWaas } from '../useDynamicWaas/useDynamicWaas.js';
|
|
93
93
|
import '../../../store/state/sendBalances.js';
|
|
94
94
|
import '../../../store/state/connectorsInitializing/connectorsInitializing.js';
|
|
95
95
|
import '../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useWalletBackup, useBackupWallets, useDownloadKeyShares, isWalletBackedUp, type WalletToBackup, type WalletWithBackupStatus, type WalletBackupStatus, type WalletOperationState, } from './useWalletBackup';
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
9
|
+
require('@dynamic-labs-sdk/client/core');
|
|
10
|
+
require('../../../client/client.cjs');
|
|
11
|
+
require('@dynamic-labs-sdk/client');
|
|
12
|
+
require('../../../config/ApiEndpoint.cjs');
|
|
13
|
+
require('@dynamic-labs/iconic');
|
|
14
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
15
|
+
require('react/jsx-runtime');
|
|
16
|
+
var ViewContext = require('../../../context/ViewContext/ViewContext.cjs');
|
|
17
|
+
var logger = require('../../../shared/logger.cjs');
|
|
18
|
+
require('@dynamic-labs/wallet-book');
|
|
19
|
+
require('@dynamic-labs/utils');
|
|
20
|
+
require('../../constants/colors.cjs');
|
|
21
|
+
var values = require('../../constants/values.cjs');
|
|
22
|
+
require('../../../shared/consts/index.cjs');
|
|
23
|
+
var errors = require('../../constants/errors.cjs');
|
|
24
|
+
require('@dynamic-labs/multi-wallet');
|
|
25
|
+
require('react-international-phone');
|
|
26
|
+
require('../../../store/state/nonce/nonce.cjs');
|
|
27
|
+
require('@dynamic-labs/locale');
|
|
28
|
+
require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
|
|
29
|
+
require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
|
|
30
|
+
require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
|
|
31
|
+
require('../../../events/dynamicEvents.cjs');
|
|
32
|
+
var useUser = require('../../../client/extension/user/useUser/useUser.cjs');
|
|
33
|
+
require('../../../context/DynamicContext/DynamicContext.cjs');
|
|
34
|
+
require('../../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
|
|
35
|
+
require('../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
36
|
+
require('../../../context/ErrorContext/ErrorContext.cjs');
|
|
37
|
+
require('../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
38
|
+
require('../../../context/AccountExistsContext/AccountExistsContext.cjs');
|
|
39
|
+
require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
|
|
40
|
+
require('../../../store/state/authMode/authMode.cjs');
|
|
41
|
+
require('../../../context/VerificationContext/VerificationContext.cjs');
|
|
42
|
+
require('react-dom');
|
|
43
|
+
require('../../functions/compareChains/compareChains.cjs');
|
|
44
|
+
require('../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
|
|
45
|
+
require('../../../context/ThemeContext/ThemeContext.cjs');
|
|
46
|
+
require('../useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
|
|
47
|
+
require('bs58');
|
|
48
|
+
var useSocialAccounts = require('../useSocialAccounts/useSocialAccounts.cjs');
|
|
49
|
+
require('yup');
|
|
50
|
+
require('../../../context/MockContext/MockContext.cjs');
|
|
51
|
+
require('../../../views/CollectUserDataView/useFields.cjs');
|
|
52
|
+
require('../../../context/FieldsStateContext/FieldsStateContext.cjs');
|
|
53
|
+
require('../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
|
|
54
|
+
require('@dynamic-labs/rpc-providers');
|
|
55
|
+
require('../../../store/state/walletOptions/walletOptions.cjs');
|
|
56
|
+
require('react-i18next');
|
|
57
|
+
require('../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
|
|
58
|
+
require('../../../components/Alert/Alert.cjs');
|
|
59
|
+
require('../../../context/WalletContext/WalletContext.cjs');
|
|
60
|
+
require('../../../components/ShadowDOM/ShadowDOM.cjs');
|
|
61
|
+
require('../../../components/IconButton/IconButton.cjs');
|
|
62
|
+
require('../../../components/InlineWidget/InlineWidget.cjs');
|
|
63
|
+
require('../../../components/Input/Input.cjs');
|
|
64
|
+
require('../../../components/IsBrowser/IsBrowser.cjs');
|
|
65
|
+
require('../../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
66
|
+
require('../../../components/OverlayCard/OverlayCard.cjs');
|
|
67
|
+
require('../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
|
|
68
|
+
require('../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
|
|
69
|
+
require('../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
|
|
70
|
+
require('../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
|
|
71
|
+
require('../../../components/Popper/Popper/Popper.cjs');
|
|
72
|
+
require('../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
73
|
+
require('react-focus-lock');
|
|
74
|
+
require('qrcode');
|
|
75
|
+
require('formik');
|
|
76
|
+
require('../useSubdomainCheck/useSubdomainCheck.cjs');
|
|
77
|
+
require('../../../context/WalletGroupContext/WalletGroupContext.cjs');
|
|
78
|
+
var useDynamicWaas = require('../useDynamicWaas/useDynamicWaas.cjs');
|
|
79
|
+
var useRefreshUser = require('../useRefreshUser/useRefreshUser.cjs');
|
|
80
|
+
require('../../../context/IpConfigurationContext/IpConfigurationContext.cjs');
|
|
81
|
+
require('../../../context/SocialRedirectContext/SocialRedirectContext.cjs');
|
|
82
|
+
require('../../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
|
|
83
|
+
require('../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
|
|
84
|
+
require('@hcaptcha/react-hcaptcha');
|
|
85
|
+
require('../../../context/LoadingContext/LoadingContext.cjs');
|
|
86
|
+
require('../../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
|
|
87
|
+
require('../../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.cjs');
|
|
88
|
+
require('../../../views/ExchangeWhitelistWarning/ExchangeWhitelistWarning.cjs');
|
|
89
|
+
require('../../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
|
|
90
|
+
require('../../../context/FooterAnimationContext/index.cjs');
|
|
91
|
+
require('@dynamic-labs/types');
|
|
92
|
+
require('../useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs');
|
|
93
|
+
require('../../../views/MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.cjs');
|
|
94
|
+
require('../../../context/PasskeyContext/PasskeyContext.cjs');
|
|
95
|
+
require('../../../context/OnrampContext/OnrampContext.cjs');
|
|
96
|
+
require('../../../store/state/sendBalances.cjs');
|
|
97
|
+
require('../../../store/state/connectorsInitializing/connectorsInitializing.cjs');
|
|
98
|
+
require('../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs');
|
|
99
|
+
require('../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
|
|
100
|
+
require('../../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
|
|
101
|
+
require('../../../widgets/DynamicWidget/components/PasskeyCard/PasskeyCard.cjs');
|
|
102
|
+
require('../../../widgets/DynamicWidget/views/CryptoComOnramp/CryptoComOnramp.cjs');
|
|
103
|
+
require('../../../../index.cjs');
|
|
104
|
+
require('../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.cjs');
|
|
105
|
+
require('../../../store/state/tokenBalances.cjs');
|
|
106
|
+
require('../../../store/state/multichainBalances.cjs');
|
|
107
|
+
require('../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
|
|
108
|
+
var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
|
|
109
|
+
|
|
110
|
+
const isWalletBackedUp = (cred) => {
|
|
111
|
+
var _a;
|
|
112
|
+
const keyShares = (_a = cred.walletProperties) === null || _a === void 0 ? void 0 : _a.keyShares;
|
|
113
|
+
if (!keyShares || !Array.isArray(keyShares))
|
|
114
|
+
return false;
|
|
115
|
+
return keyShares.some((keyShare) => keyShare &&
|
|
116
|
+
typeof keyShare === 'object' &&
|
|
117
|
+
'backupLocation' in keyShare &&
|
|
118
|
+
keyShare.backupLocation === 'googleDrive');
|
|
119
|
+
};
|
|
120
|
+
const useWalletBackup = () => {
|
|
121
|
+
const { setShowAuthFlow } = useInternalDynamicContext.useInternalDynamicContext();
|
|
122
|
+
const { pushView } = ViewContext.useViewContext();
|
|
123
|
+
const user = useUser.useUser();
|
|
124
|
+
const refresh = useRefreshUser.useRefreshUser();
|
|
125
|
+
const { getWaasWalletConnector, getWaasWalletsByCredentials } = useDynamicWaas.useDynamicWaas();
|
|
126
|
+
const { linkSocialAccount, isLinked } = useSocialAccounts.useSocialAccounts();
|
|
127
|
+
const isGoogleLinked = React.useMemo(() => isLinked(sdkApiCore.ProviderEnum.Google), [isLinked]);
|
|
128
|
+
const [backupState, setBackupState] = React.useState({
|
|
129
|
+
currentIndex: 0,
|
|
130
|
+
failedIndex: null,
|
|
131
|
+
hasError: false,
|
|
132
|
+
isComplete: false,
|
|
133
|
+
isProcessing: false,
|
|
134
|
+
totalWallets: 0,
|
|
135
|
+
});
|
|
136
|
+
const timeoutRef = React.useRef(null);
|
|
137
|
+
React.useEffect(() => () => {
|
|
138
|
+
if (timeoutRef.current) {
|
|
139
|
+
clearTimeout(timeoutRef.current);
|
|
140
|
+
}
|
|
141
|
+
}, []);
|
|
142
|
+
const getWalletsBackupStatus = React.useCallback(() => getWaasWalletsByCredentials().map((cred) => ({
|
|
143
|
+
address: cred.address,
|
|
144
|
+
chain: values.VerifiedCredentialNameToChainEnum[cred.chain],
|
|
145
|
+
status: isWalletBackedUp(cred) ? 'backed-up' : 'pending',
|
|
146
|
+
})), [getWaasWalletsByCredentials]);
|
|
147
|
+
const getWalletsToBackup = React.useCallback(() => getWalletsBackupStatus()
|
|
148
|
+
.filter((wallet) => wallet.status === 'pending')
|
|
149
|
+
.map(({ address, chain }) => ({ address, chain })), [getWalletsBackupStatus]);
|
|
150
|
+
const areAllWalletsBackedUp = React.useMemo(() => {
|
|
151
|
+
const statuses = getWalletsBackupStatus();
|
|
152
|
+
return (statuses.length > 0 && statuses.every((w) => w.status === 'backed-up'));
|
|
153
|
+
}, [getWalletsBackupStatus]);
|
|
154
|
+
const ensureGoogleLinked = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
155
|
+
var _a;
|
|
156
|
+
if (isGoogleLinked) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
yield linkSocialAccount(sdkApiCore.ProviderEnum.Google, {
|
|
161
|
+
forcePopup: true,
|
|
162
|
+
showWidgetAfterConnection: false,
|
|
163
|
+
});
|
|
164
|
+
const updatedUser = yield refresh();
|
|
165
|
+
const isGoogleLinkedAfterRefresh = (_a = updatedUser === null || updatedUser === void 0 ? void 0 : updatedUser.verifiedCredentials) === null || _a === void 0 ? void 0 : _a.some((cred) => cred.format === 'oauth' && cred.oauthProvider === sdkApiCore.ProviderEnum.Google);
|
|
166
|
+
return Boolean(isGoogleLinkedAfterRefresh);
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
logger.logger.warn('Error linking Google account for backup', { error });
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}), [isGoogleLinked, linkSocialAccount, refresh]);
|
|
173
|
+
const backupWallet = React.useCallback((walletToBackup) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
174
|
+
try {
|
|
175
|
+
const waasConnector = getWaasWalletConnector(walletToBackup.chain);
|
|
176
|
+
if (!waasConnector) {
|
|
177
|
+
logger.logger.warn('No WaaS connector found for wallet', {
|
|
178
|
+
address: walletToBackup.address,
|
|
179
|
+
});
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
yield waasConnector.backupKeySharesToGoogleDrive({
|
|
183
|
+
accountAddress: walletToBackup.address,
|
|
184
|
+
});
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
logger.logger.warn('Error backing up wallet', {
|
|
189
|
+
address: walletToBackup.address,
|
|
190
|
+
error,
|
|
191
|
+
});
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}), [getWaasWalletConnector]);
|
|
195
|
+
const backupAllWallets = React.useCallback((wallets) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
196
|
+
const walletsToProcess = wallets !== null && wallets !== void 0 ? wallets : getWalletsToBackup();
|
|
197
|
+
for (const wallet of walletsToProcess) {
|
|
198
|
+
yield backupWallet(wallet);
|
|
199
|
+
}
|
|
200
|
+
yield refresh();
|
|
201
|
+
}), [getWalletsToBackup, backupWallet, refresh]);
|
|
202
|
+
const startBackup = React.useCallback((onComplete_1, ...args_1) => _tslib.__awaiter(void 0, [onComplete_1, ...args_1], void 0, function* (onComplete, fromIndex = 0) {
|
|
203
|
+
if (timeoutRef.current) {
|
|
204
|
+
clearTimeout(timeoutRef.current);
|
|
205
|
+
timeoutRef.current = null;
|
|
206
|
+
}
|
|
207
|
+
const walletsToBackup = getWalletsToBackup();
|
|
208
|
+
if (walletsToBackup.length === 0) {
|
|
209
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete();
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
setBackupState((prev) => (Object.assign(Object.assign({}, prev), { failedIndex: null, hasError: false, isProcessing: true, totalWallets: walletsToBackup.length })));
|
|
213
|
+
for (let i = fromIndex; i < walletsToBackup.length; i++) {
|
|
214
|
+
setBackupState((prev) => (Object.assign(Object.assign({}, prev), { currentIndex: i + 1 })));
|
|
215
|
+
const success = yield backupWallet(walletsToBackup[i]);
|
|
216
|
+
if (!success) {
|
|
217
|
+
setBackupState((prev) => (Object.assign(Object.assign({}, prev), { failedIndex: i, hasError: true, isProcessing: false })));
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
yield refresh();
|
|
222
|
+
setBackupState((prev) => (Object.assign(Object.assign({}, prev), { isComplete: true, isProcessing: false })));
|
|
223
|
+
if (onComplete) {
|
|
224
|
+
timeoutRef.current = setTimeout(onComplete, 1000);
|
|
225
|
+
}
|
|
226
|
+
}), [getWalletsToBackup, backupWallet, refresh]);
|
|
227
|
+
const initBackupProcess = React.useCallback(() => {
|
|
228
|
+
if (!user) {
|
|
229
|
+
throw new Error(errors.USER_NOT_LOGGED_IN);
|
|
230
|
+
}
|
|
231
|
+
setShowAuthFlow(true, {
|
|
232
|
+
ignoreIfIsEmbeddedWidget: false,
|
|
233
|
+
performMultiWalletChecks: false,
|
|
234
|
+
});
|
|
235
|
+
pushView('waas-backup-progress-view');
|
|
236
|
+
}, [setShowAuthFlow, pushView, user]);
|
|
237
|
+
return {
|
|
238
|
+
areAllWalletsBackedUp,
|
|
239
|
+
backupAllWallets,
|
|
240
|
+
backupState,
|
|
241
|
+
backupWallet,
|
|
242
|
+
ensureGoogleLinked,
|
|
243
|
+
getWalletsBackupStatus,
|
|
244
|
+
getWalletsToBackup,
|
|
245
|
+
initBackupProcess,
|
|
246
|
+
isGoogleLinked,
|
|
247
|
+
startBackup,
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
const useBackupWallets = (onComplete) => {
|
|
251
|
+
const { backupState, startBackup } = useWalletBackup();
|
|
252
|
+
const hasStartedRef = React.useRef(false);
|
|
253
|
+
const onCompleteRef = React.useRef(onComplete);
|
|
254
|
+
onCompleteRef.current = onComplete;
|
|
255
|
+
React.useEffect(() => {
|
|
256
|
+
if (hasStartedRef.current)
|
|
257
|
+
return;
|
|
258
|
+
hasStartedRef.current = true;
|
|
259
|
+
startBackup(() => onCompleteRef.current());
|
|
260
|
+
}, [startBackup]);
|
|
261
|
+
const retry = React.useCallback(() => {
|
|
262
|
+
var _a;
|
|
263
|
+
const fromIndex = (_a = backupState.failedIndex) !== null && _a !== void 0 ? _a : 0;
|
|
264
|
+
startBackup(() => onCompleteRef.current(), fromIndex);
|
|
265
|
+
}, [startBackup, backupState.failedIndex]);
|
|
266
|
+
return Object.assign(Object.assign({}, backupState), { retry });
|
|
267
|
+
};
|
|
268
|
+
const useDownloadKeyShares = (onComplete) => {
|
|
269
|
+
const { getWaasWalletConnector, getWaasWalletsByCredentials } = useDynamicWaas.useDynamicWaas();
|
|
270
|
+
const [downloadState, setDownloadState] = React.useState({
|
|
271
|
+
currentIndex: 0,
|
|
272
|
+
failedIndex: null,
|
|
273
|
+
hasError: false,
|
|
274
|
+
isComplete: false,
|
|
275
|
+
isProcessing: false,
|
|
276
|
+
totalWallets: 0,
|
|
277
|
+
});
|
|
278
|
+
const hasStartedRef = React.useRef(false);
|
|
279
|
+
const onCompleteRef = React.useRef(onComplete);
|
|
280
|
+
onCompleteRef.current = onComplete;
|
|
281
|
+
const walletsToDownload = React.useMemo(() => getWaasWalletsByCredentials().map((cred) => ({
|
|
282
|
+
address: cred.address,
|
|
283
|
+
chain: values.VerifiedCredentialNameToChainEnum[cred.chain],
|
|
284
|
+
})), [getWaasWalletsByCredentials]);
|
|
285
|
+
const downloadKeyShare = React.useCallback((walletToDownload) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
286
|
+
try {
|
|
287
|
+
const waasConnector = getWaasWalletConnector(walletToDownload.chain);
|
|
288
|
+
if (!waasConnector) {
|
|
289
|
+
logger.logger.warn('No WaaS connector found for wallet', {
|
|
290
|
+
address: walletToDownload.address,
|
|
291
|
+
});
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
yield waasConnector.exportClientKeyshares({
|
|
295
|
+
accountAddress: walletToDownload.address,
|
|
296
|
+
});
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
logger.logger.warn('Error downloading key share', {
|
|
301
|
+
address: walletToDownload.address,
|
|
302
|
+
error,
|
|
303
|
+
});
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
}), [getWaasWalletConnector]);
|
|
307
|
+
const startDownload = React.useCallback((...args_1) => _tslib.__awaiter(void 0, [...args_1], void 0, function* (fromIndex = 0) {
|
|
308
|
+
if (hasStartedRef.current || walletsToDownload.length === 0)
|
|
309
|
+
return;
|
|
310
|
+
hasStartedRef.current = true;
|
|
311
|
+
setDownloadState((prev) => (Object.assign(Object.assign({}, prev), { currentIndex: fromIndex, failedIndex: null, hasError: false, isComplete: false, isProcessing: true, totalWallets: walletsToDownload.length })));
|
|
312
|
+
for (let i = fromIndex; i < walletsToDownload.length; i++) {
|
|
313
|
+
setDownloadState((prev) => (Object.assign(Object.assign({}, prev), { currentIndex: i + 1 })));
|
|
314
|
+
const success = yield downloadKeyShare(walletsToDownload[i]);
|
|
315
|
+
if (!success) {
|
|
316
|
+
setDownloadState((prev) => (Object.assign(Object.assign({}, prev), { failedIndex: i, hasError: true, isProcessing: false })));
|
|
317
|
+
hasStartedRef.current = false;
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
setDownloadState((prev) => (Object.assign(Object.assign({}, prev), { isComplete: true, isProcessing: false })));
|
|
322
|
+
hasStartedRef.current = false;
|
|
323
|
+
if (onCompleteRef.current) {
|
|
324
|
+
const count = walletsToDownload.length;
|
|
325
|
+
setTimeout(() => { var _a; return (_a = onCompleteRef.current) === null || _a === void 0 ? void 0 : _a.call(onCompleteRef, count); }, 500);
|
|
326
|
+
}
|
|
327
|
+
}), [walletsToDownload, downloadKeyShare]);
|
|
328
|
+
const retry = React.useCallback(() => {
|
|
329
|
+
var _a;
|
|
330
|
+
const fromIndex = (_a = downloadState.failedIndex) !== null && _a !== void 0 ? _a : 0;
|
|
331
|
+
startDownload(fromIndex);
|
|
332
|
+
}, [startDownload, downloadState.failedIndex]);
|
|
333
|
+
return Object.assign(Object.assign({}, downloadState), { retry, startDownload: () => startDownload(0) });
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
exports.isWalletBackedUp = isWalletBackedUp;
|
|
337
|
+
exports.useBackupWallets = useBackupWallets;
|
|
338
|
+
exports.useDownloadKeyShares = useDownloadKeyShares;
|
|
339
|
+
exports.useWalletBackup = useWalletBackup;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ChainEnum, JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';
|
|
2
|
+
export type WalletBackupStatus = 'backed-up' | 'pending';
|
|
3
|
+
export interface WalletToBackup {
|
|
4
|
+
address: string;
|
|
5
|
+
chain: ChainEnum;
|
|
6
|
+
}
|
|
7
|
+
export interface WalletWithBackupStatus extends WalletToBackup {
|
|
8
|
+
status: WalletBackupStatus;
|
|
9
|
+
}
|
|
10
|
+
export interface WalletOperationState {
|
|
11
|
+
currentIndex: number;
|
|
12
|
+
failedIndex: number | null;
|
|
13
|
+
hasError: boolean;
|
|
14
|
+
isComplete: boolean;
|
|
15
|
+
isProcessing: boolean;
|
|
16
|
+
totalWallets: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const isWalletBackedUp: (cred: JwtVerifiedCredential) => boolean;
|
|
19
|
+
export declare const useWalletBackup: () => {
|
|
20
|
+
readonly areAllWalletsBackedUp: boolean;
|
|
21
|
+
readonly backupAllWallets: (wallets?: WalletToBackup[]) => Promise<void>;
|
|
22
|
+
readonly backupState: WalletOperationState;
|
|
23
|
+
readonly backupWallet: (walletToBackup: WalletToBackup) => Promise<boolean>;
|
|
24
|
+
readonly ensureGoogleLinked: () => Promise<boolean>;
|
|
25
|
+
readonly getWalletsBackupStatus: () => WalletWithBackupStatus[];
|
|
26
|
+
readonly getWalletsToBackup: () => WalletToBackup[];
|
|
27
|
+
readonly initBackupProcess: () => void;
|
|
28
|
+
readonly isGoogleLinked: boolean;
|
|
29
|
+
readonly startBackup: (onComplete?: () => void, fromIndex?: number) => Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
export declare const useBackupWallets: (onComplete: () => void) => {
|
|
32
|
+
retry: () => void;
|
|
33
|
+
currentIndex: number;
|
|
34
|
+
failedIndex: number | null;
|
|
35
|
+
hasError: boolean;
|
|
36
|
+
isComplete: boolean;
|
|
37
|
+
isProcessing: boolean;
|
|
38
|
+
totalWallets: number;
|
|
39
|
+
};
|
|
40
|
+
export declare const useDownloadKeyShares: (onComplete?: (walletCount: number) => void) => {
|
|
41
|
+
retry: () => void;
|
|
42
|
+
startDownload: () => Promise<void>;
|
|
43
|
+
currentIndex: number;
|
|
44
|
+
failedIndex: number | null;
|
|
45
|
+
hasError: boolean;
|
|
46
|
+
isComplete: boolean;
|
|
47
|
+
isProcessing: boolean;
|
|
48
|
+
totalWallets: number;
|
|
49
|
+
};
|