@dynamic-labs/sdk-react-core 4.8.2 → 4.8.3
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 +3 -0
- package/package.cjs +2 -2
- package/package.js +2 -2
- package/package.json +12 -12
- package/src/index.cjs +2 -0
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -0
- package/src/lib/components/SyncAuthFlow/SyncAuthFlow.cjs +2 -0
- package/src/lib/components/SyncAuthFlow/SyncAuthFlow.js +2 -0
- package/src/lib/locale/en/translation.cjs +2 -1
- package/src/lib/locale/en/translation.d.ts +2 -1
- package/src/lib/locale/en/translation.js +2 -1
- package/src/lib/store/state/dynamicContextProps/dynamicContextProps.cjs +2 -0
- package/src/lib/store/state/dynamicContextProps/dynamicContextProps.d.ts +2 -0
- package/src/lib/store/state/dynamicContextProps/dynamicContextProps.js +2 -1
- package/src/lib/utils/functions/coinbaseOnramp/formatCoinbaseOnrampUrl.cjs +2 -2
- package/src/lib/utils/functions/coinbaseOnramp/formatCoinbaseOnrampUrl.js +2 -2
- package/src/lib/utils/hooks/index.d.ts +2 -0
- package/src/lib/utils/hooks/useDynamicWaas/constants.cjs +10 -0
- package/src/lib/utils/hooks/useDynamicWaas/constants.d.ts +2 -0
- package/src/lib/utils/hooks/useDynamicWaas/constants.js +5 -0
- package/src/lib/utils/hooks/useDynamicWaas/index.d.ts +1 -0
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.cjs +220 -0
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.d.ts +21 -0
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.js +215 -0
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +9 -5
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +10 -6
- package/src/lib/utils/hooks/useSetWalletConnectorFetchers/useSetWalletConnectorFetchers.cjs +14 -1
- package/src/lib/utils/hooks/useSetWalletConnectorFetchers/useSetWalletConnectorFetchers.js +15 -2
- package/src/lib/utils/hooks/useSyncDynamicWaas/index.d.ts +1 -0
- package/src/lib/utils/hooks/useSyncDynamicWaas/useSyncDynamicWaas.cjs +145 -0
- package/src/lib/utils/hooks/useSyncDynamicWaas/useSyncDynamicWaas.d.ts +1 -0
- package/src/lib/utils/hooks/useSyncDynamicWaas/useSyncDynamicWaas.js +141 -0
- package/src/lib/views/UserDeleteAccountView/UserDeleteAccountView.cjs +6 -3
- package/src/lib/views/UserDeleteAccountView/UserDeleteAccountView.js +6 -3
- package/src/lib/widgets/DynamicWidget/views/AccountAndSecuritySettingsView/AccountAndSecuritySettingsView.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/views/AccountAndSecuritySettingsView/AccountAndSecuritySettingsView.js +1 -1
- package/src/lib/widgets/DynamicWidget/views/SettingsView/SettingsView.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/views/SettingsView/SettingsView.js +1 -1
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
|
+
import { useCallback, useMemo } from 'react';
|
|
4
|
+
import { EmbeddedWalletVersionEnum, JwtVerifiedCredentialFormatEnum, WalletProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
5
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
6
|
+
import '../../constants/values.js';
|
|
7
|
+
import '@dynamic-labs/multi-wallet';
|
|
8
|
+
import { getAuthToken } from '../../functions/getAuthToken/getAuthToken.js';
|
|
9
|
+
import '../../../shared/logger.js';
|
|
10
|
+
import '../../constants/colors.js';
|
|
11
|
+
import 'react-international-phone';
|
|
12
|
+
import '@dynamic-labs/iconic';
|
|
13
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
14
|
+
import 'react/jsx-runtime';
|
|
15
|
+
import '../../../context/ViewContext/ViewContext.js';
|
|
16
|
+
import '@dynamic-labs/wallet-book';
|
|
17
|
+
import '../../../shared/consts/index.js';
|
|
18
|
+
import '../../../store/state/nonce/nonce.js';
|
|
19
|
+
import { isCookieEnabled } from '../../functions/isCookieEnabled/isCookieEnabled.js';
|
|
20
|
+
import { useProjectSettings } from '../../../store/state/projectSettings/projectSettings.js';
|
|
21
|
+
import { updatePrimaryWalletId } from '../../functions/updatePrimaryWalletId/updatePrimaryWalletId.js';
|
|
22
|
+
import { useRefreshUser } from '../useRefreshUser/useRefreshUser.js';
|
|
23
|
+
import { useApiBaseUrl, useEnvironmentId } from '../../../store/state/dynamicContextProps/dynamicContextProps.js';
|
|
24
|
+
import { useUser } from '../../../store/state/user/user.js';
|
|
25
|
+
import { useWalletConnectorOptions } from '../../../store/state/walletOptions/walletOptions.js';
|
|
26
|
+
import '../../../context/DynamicContext/DynamicContext.js';
|
|
27
|
+
import '../../../events/dynamicEvents.js';
|
|
28
|
+
import '../../../context/CaptchaContext/CaptchaContext.js';
|
|
29
|
+
import '../../../context/ErrorContext/ErrorContext.js';
|
|
30
|
+
import '../../../context/AccessDeniedContext/AccessDeniedContext.js';
|
|
31
|
+
import '../../../context/AccountExistsContext/AccountExistsContext.js';
|
|
32
|
+
import '../../../context/UserWalletsContext/UserWalletsContext.js';
|
|
33
|
+
import '../../../config/ApiEndpoint.js';
|
|
34
|
+
import '../../../locale/locale.js';
|
|
35
|
+
import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
|
|
36
|
+
import '../../../context/VerificationContext/VerificationContext.js';
|
|
37
|
+
import 'react-dom';
|
|
38
|
+
import '../../functions/compareChains/compareChains.js';
|
|
39
|
+
import '../../../context/ThemeContext/ThemeContext.js';
|
|
40
|
+
import '../useUserUpdateRequest/useUpdateUser/userFieldsSchema.js';
|
|
41
|
+
import 'bs58';
|
|
42
|
+
import '@dynamic-labs/types';
|
|
43
|
+
import '../../../context/SocialRedirectContext/SocialRedirectContext.js';
|
|
44
|
+
import '../../../store/state/primaryWalletId/primaryWalletId.js';
|
|
45
|
+
import '../../../context/LoadingContext/LoadingContext.js';
|
|
46
|
+
import '../../../context/WalletContext/WalletContext.js';
|
|
47
|
+
import '../useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.js';
|
|
48
|
+
import 'yup';
|
|
49
|
+
import '../../../context/MockContext/MockContext.js';
|
|
50
|
+
import '../../../views/CollectUserDataView/useFields.js';
|
|
51
|
+
import '../../../context/FieldsStateContext/FieldsStateContext.js';
|
|
52
|
+
import '../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
|
|
53
|
+
import '@dynamic-labs/rpc-providers';
|
|
54
|
+
import '../../../store/state/loadingAndLifecycle.js';
|
|
55
|
+
import 'react-i18next';
|
|
56
|
+
import '../../../components/Accordion/components/AccordionItem/AccordionItem.js';
|
|
57
|
+
import '../../../components/Alert/Alert.js';
|
|
58
|
+
import '../../../components/ShadowDOM/ShadowDOM.js';
|
|
59
|
+
import '../../../components/IconButton/IconButton.js';
|
|
60
|
+
import '../../../components/InlineWidget/InlineWidget.js';
|
|
61
|
+
import '../../../components/Input/Input.js';
|
|
62
|
+
import '../../../components/IsBrowser/IsBrowser.js';
|
|
63
|
+
import '../../../components/MenuList/Dropdown/Dropdown.js';
|
|
64
|
+
import '../../../components/OverlayCard/OverlayCard.js';
|
|
65
|
+
import '../../../components/Transition/ZoomTransition/ZoomTransition.js';
|
|
66
|
+
import '../../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
|
|
67
|
+
import '../../../components/Transition/OpacityTransition/OpacityTransition.js';
|
|
68
|
+
import '../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js';
|
|
69
|
+
import '../../../components/Popper/Popper/Popper.js';
|
|
70
|
+
import '../../../components/Popper/PopperContext/PopperContext.js';
|
|
71
|
+
import 'react-focus-lock';
|
|
72
|
+
import 'qrcode';
|
|
73
|
+
import 'formik';
|
|
74
|
+
import '../useSubdomainCheck/useSubdomainCheck.js';
|
|
75
|
+
import '../../../context/WalletGroupContext/WalletGroupContext.js';
|
|
76
|
+
import '../../../context/IpConfigurationContext/IpConfigurationContext.js';
|
|
77
|
+
import '../../../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
|
|
78
|
+
import '../../../context/ConnectWithOtpContext/constants.js';
|
|
79
|
+
import '../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
|
|
80
|
+
import '@hcaptcha/react-hcaptcha';
|
|
81
|
+
import '../../../widgets/DynamicWidget/context/DynamicWidgetContext.js';
|
|
82
|
+
import '../../../context/FooterAnimationContext/index.js';
|
|
83
|
+
import '../../../context/ErrorContext/hooks/useErrorText/useErrorText.js';
|
|
84
|
+
import '../../../context/PasskeyContext/PasskeyContext.js';
|
|
85
|
+
import '../../../store/state/sendBalances.js';
|
|
86
|
+
import '../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.js';
|
|
87
|
+
import '../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js';
|
|
88
|
+
import '../../../views/TransactionConfirmationView/TransactionConfirmationView.js';
|
|
89
|
+
import '../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
|
|
90
|
+
import '../../../context/OnrampContext/OnrampContext.js';
|
|
91
|
+
import '../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.js';
|
|
92
|
+
import '../../../../index.js';
|
|
93
|
+
import { DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR, NO_ENABLED_CHAINS_ERROR } from './constants.js';
|
|
94
|
+
import '../../../store/state/tokenBalances.js';
|
|
95
|
+
import '../../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
|
|
96
|
+
import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.js';
|
|
97
|
+
|
|
98
|
+
const dynamicWaasKey = 'dynamicwaas';
|
|
99
|
+
const configWaasWalletConnector = ({ walletConnector, environmentId, apiBaseUrl, authToken, }) => {
|
|
100
|
+
walletConnector.setEnvironmentId(environmentId);
|
|
101
|
+
walletConnector.setBaseApiUrl(apiBaseUrl === null || apiBaseUrl === void 0 ? void 0 : apiBaseUrl.replace('/api/v0', ''));
|
|
102
|
+
walletConnector.setGetAuthTokenFunction(() => authToken !== null && authToken !== void 0 ? authToken : '');
|
|
103
|
+
return walletConnector;
|
|
104
|
+
};
|
|
105
|
+
const useDynamicWaas = () => {
|
|
106
|
+
var _a;
|
|
107
|
+
const { setShowAuthFlow } = useInternalDynamicContext();
|
|
108
|
+
const { user } = useUser();
|
|
109
|
+
const apiBaseUrl = useApiBaseUrl();
|
|
110
|
+
const projectSettings = useProjectSettings();
|
|
111
|
+
const environmentId = useEnvironmentId();
|
|
112
|
+
const walletConnectorOptions = useWalletConnectorOptions();
|
|
113
|
+
const refresh = useRefreshUser();
|
|
114
|
+
const embeddedWalletSettings = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets;
|
|
115
|
+
const enabledChains = (_a = embeddedWalletSettings === null || embeddedWalletSettings === void 0 ? void 0 : embeddedWalletSettings.chainConfigurations) === null || _a === void 0 ? void 0 : _a.filter((c) => c.enabled);
|
|
116
|
+
const primaryChain = enabledChains === null || enabledChains === void 0 ? void 0 : enabledChains.find((chain) => chain.primary);
|
|
117
|
+
const enabledChainNames = enabledChains === null || enabledChains === void 0 ? void 0 : enabledChains.map((chain) => chain.name);
|
|
118
|
+
const automaticEmbeddedWalletCreationEnabled = embeddedWalletSettings === null || embeddedWalletSettings === void 0 ? void 0 : embeddedWalletSettings.automaticEmbeddedWalletCreation;
|
|
119
|
+
const automaticEmbeddedWalletCreationForExternalEnabled = embeddedWalletSettings === null || embeddedWalletSettings === void 0 ? void 0 : embeddedWalletSettings.automaticEmbeddedWalletCreationForExternal;
|
|
120
|
+
const defaultWalletVersion = embeddedWalletSettings === null || embeddedWalletSettings === void 0 ? void 0 : embeddedWalletSettings.defaultWalletVersion;
|
|
121
|
+
const dynamicWaasIsEnabled = defaultWalletVersion === EmbeddedWalletVersionEnum.V3;
|
|
122
|
+
const authToken = getAuthToken();
|
|
123
|
+
const isCookieAuthEnabled = projectSettings && isCookieEnabled(projectSettings);
|
|
124
|
+
const getWalletConnector = useCallback((chainName) => {
|
|
125
|
+
var _a;
|
|
126
|
+
if (!isCookieAuthEnabled && !authToken) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
if (!walletConnectorOptions.length || !environmentId || !apiBaseUrl)
|
|
130
|
+
return undefined;
|
|
131
|
+
const connectorKey = chainName === 'EVM' ? dynamicWaasKey : `${dynamicWaasKey}-svm`;
|
|
132
|
+
const walletConnector = (_a = walletConnectorOptions.find((option) => option.key.includes(connectorKey))) === null || _a === void 0 ? void 0 : _a.walletConnector;
|
|
133
|
+
if (!walletConnector) {
|
|
134
|
+
throw new DynamicError(DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR);
|
|
135
|
+
}
|
|
136
|
+
const configuredWalletConnector = configWaasWalletConnector({
|
|
137
|
+
apiBaseUrl,
|
|
138
|
+
authToken,
|
|
139
|
+
environmentId,
|
|
140
|
+
walletConnector,
|
|
141
|
+
});
|
|
142
|
+
return configuredWalletConnector;
|
|
143
|
+
}, [
|
|
144
|
+
walletConnectorOptions,
|
|
145
|
+
environmentId,
|
|
146
|
+
authToken,
|
|
147
|
+
apiBaseUrl,
|
|
148
|
+
isCookieAuthEnabled,
|
|
149
|
+
]);
|
|
150
|
+
const createWalletAccount = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
|
+
if (!(enabledChainNames === null || enabledChainNames === void 0 ? void 0 : enabledChainNames.length)) {
|
|
152
|
+
throw new DynamicError(NO_ENABLED_CHAINS_ERROR);
|
|
153
|
+
}
|
|
154
|
+
const createdWalletAccounts = yield Promise.all(enabledChainNames === null || enabledChainNames === void 0 ? void 0 : enabledChainNames.map((chain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
155
|
+
const walletConnector = getWalletConnector(chain);
|
|
156
|
+
if (!walletConnector)
|
|
157
|
+
return undefined;
|
|
158
|
+
const createdWalletAccount = yield walletConnector.createWalletAccount();
|
|
159
|
+
return Object.assign(Object.assign({}, createdWalletAccount), { chainName: chain });
|
|
160
|
+
})));
|
|
161
|
+
const primaryWalletAccount = createdWalletAccounts === null || createdWalletAccounts === void 0 ? void 0 : createdWalletAccounts.find((wallet) => (wallet === null || wallet === void 0 ? void 0 : wallet.chainName) === (primaryChain === null || primaryChain === void 0 ? void 0 : primaryChain.name));
|
|
162
|
+
const refreshedUser = yield refresh();
|
|
163
|
+
const createdPrimaryWallet = refreshedUser === null || refreshedUser === void 0 ? void 0 : refreshedUser.verifiedCredentials.find((wallet) => {
|
|
164
|
+
var _a, _b, _c;
|
|
165
|
+
return ((_a = wallet.walletName) === null || _a === void 0 ? void 0 : _a.includes(dynamicWaasKey)) &&
|
|
166
|
+
((_b = wallet.address) === null || _b === void 0 ? void 0 : _b.toLowerCase()) ===
|
|
167
|
+
((_c = primaryWalletAccount === null || primaryWalletAccount === void 0 ? void 0 : primaryWalletAccount.accountAddress) === null || _c === void 0 ? void 0 : _c.toLowerCase());
|
|
168
|
+
});
|
|
169
|
+
if (createdPrimaryWallet) {
|
|
170
|
+
updatePrimaryWalletId(createdPrimaryWallet.id);
|
|
171
|
+
}
|
|
172
|
+
setShowAuthFlow(false, { performMultiWalletChecks: false }); // close email otp pin modal
|
|
173
|
+
return createdWalletAccounts;
|
|
174
|
+
}), [getWalletConnector, primaryChain, enabledChainNames, refresh]);
|
|
175
|
+
const shouldAutoCreateDynamicWaasWallet = useMemo(() => {
|
|
176
|
+
const hasDynamicWaasWallet = user === null || user === void 0 ? void 0 : user.verifiedCredentials.some((wallet) => { var _a; return (_a = wallet.walletName) === null || _a === void 0 ? void 0 : _a.includes('dynamicwaas'); });
|
|
177
|
+
if (!user ||
|
|
178
|
+
hasDynamicWaasWallet || // already has a dynamic waas wallet
|
|
179
|
+
!dynamicWaasIsEnabled || // dynamic waas is not enabled
|
|
180
|
+
!automaticEmbeddedWalletCreationEnabled // automatic embedded wallet creation is not enabled
|
|
181
|
+
)
|
|
182
|
+
return false;
|
|
183
|
+
const hasExternalWallet = user === null || user === void 0 ? void 0 : user.verifiedCredentials.some((vc) => vc.format === JwtVerifiedCredentialFormatEnum.Blockchain &&
|
|
184
|
+
vc.walletProvider !== WalletProviderEnum.EmbeddedWallet);
|
|
185
|
+
const shouldCreateDynamicWaasWallet = hasExternalWallet
|
|
186
|
+
? automaticEmbeddedWalletCreationForExternalEnabled
|
|
187
|
+
: true;
|
|
188
|
+
return shouldCreateDynamicWaasWallet;
|
|
189
|
+
}, [
|
|
190
|
+
user,
|
|
191
|
+
dynamicWaasIsEnabled,
|
|
192
|
+
automaticEmbeddedWalletCreationEnabled,
|
|
193
|
+
automaticEmbeddedWalletCreationForExternalEnabled,
|
|
194
|
+
walletConnectorOptions,
|
|
195
|
+
]);
|
|
196
|
+
const importPrivateKey = (_b) => __awaiter(void 0, [_b], void 0, function* ({ chainName, privateKey, }) {
|
|
197
|
+
const walletConnector = getWalletConnector(chainName);
|
|
198
|
+
if (!walletConnector)
|
|
199
|
+
return;
|
|
200
|
+
yield walletConnector.importPrivateKey({
|
|
201
|
+
chainName,
|
|
202
|
+
privateKey,
|
|
203
|
+
});
|
|
204
|
+
yield refresh();
|
|
205
|
+
});
|
|
206
|
+
return {
|
|
207
|
+
createWalletAccount,
|
|
208
|
+
dynamicWaasIsEnabled,
|
|
209
|
+
getWalletConnector,
|
|
210
|
+
importPrivateKey,
|
|
211
|
+
shouldAutoCreateDynamicWaasWallet,
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export { configWaasWalletConnector, useDynamicWaas };
|
|
@@ -160,19 +160,23 @@ const useEmbeddedWallet = () => {
|
|
|
160
160
|
});
|
|
161
161
|
const shouldPromptForKeyExport = React.useCallback(() => { var _a; return Boolean((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.promptForKeyExport); }, [projectSettings]);
|
|
162
162
|
const shouldAutoCreateEmbeddedWallet = React.useCallback((verifiedUser) => {
|
|
163
|
-
var _a, _b, _c, _d, _e;
|
|
163
|
+
var _a, _b, _c, _d, _e, _f;
|
|
164
164
|
const hasEmbeddedWalletProviderEnabled = isTurnkeyEnabled.isTurnkeyEnabled(projectSettings);
|
|
165
|
+
const defaultWalletVersion = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.defaultWalletVersion;
|
|
165
166
|
const hasPrimaryWallet = primaryWalletId.getPrimaryWalletId();
|
|
167
|
+
if (defaultWalletVersion === sdkApiCore.EmbeddedWalletVersionEnum.V3) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
166
170
|
if (!hasEmbeddedWalletProviderEnabled || hasPrimaryWallet) {
|
|
167
171
|
return false;
|
|
168
172
|
}
|
|
169
173
|
// Turnkey specific rules
|
|
170
174
|
if (verifiedUser) {
|
|
171
175
|
const primaryEmbeddedChain = findPrimaryEmbeddedChain.findPrimaryEmbeddedChain(projectSettings);
|
|
172
|
-
const embeddedWalletVerifiedCredentialId = (
|
|
176
|
+
const embeddedWalletVerifiedCredentialId = (_b = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(verifiedUser, [
|
|
173
177
|
primaryEmbeddedChain,
|
|
174
|
-
])) === null ||
|
|
175
|
-
const AAWalletCredentialId = (
|
|
178
|
+
])) === null || _b === void 0 ? void 0 : _b.id;
|
|
179
|
+
const AAWalletCredentialId = (_d = (_c = verifiedUser.verifiedCredentials) === null || _c === void 0 ? void 0 : _c.find((vc) => vc.walletProvider === sdkApiCore.WalletProviderEnum.SmartContractWallet)) === null || _d === void 0 ? void 0 : _d.id;
|
|
176
180
|
const targetPrimaryWalletId = AAWalletCredentialId
|
|
177
181
|
? AAWalletCredentialId
|
|
178
182
|
: embeddedWalletVerifiedCredentialId;
|
|
@@ -182,7 +186,7 @@ const useEmbeddedWallet = () => {
|
|
|
182
186
|
}
|
|
183
187
|
}
|
|
184
188
|
if (isTurnkeyEnabled.isTurnkeyEnabled(projectSettings) &&
|
|
185
|
-
!((
|
|
189
|
+
!((_f = (_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _e === void 0 ? void 0 : _e.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation)) {
|
|
186
190
|
return false;
|
|
187
191
|
}
|
|
188
192
|
return true;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
3
|
import { useCallback } from 'react';
|
|
4
|
-
import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
4
|
+
import { EmbeddedWalletVersionEnum, WalletProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
5
5
|
import { DynamicError } from '@dynamic-labs/utils';
|
|
6
6
|
import '../../../context/DynamicContext/DynamicContext.js';
|
|
7
7
|
import '../../../shared/logger.js';
|
|
@@ -156,19 +156,23 @@ const useEmbeddedWallet = () => {
|
|
|
156
156
|
});
|
|
157
157
|
const shouldPromptForKeyExport = useCallback(() => { var _a; return Boolean((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.promptForKeyExport); }, [projectSettings]);
|
|
158
158
|
const shouldAutoCreateEmbeddedWallet = useCallback((verifiedUser) => {
|
|
159
|
-
var _a, _b, _c, _d, _e;
|
|
159
|
+
var _a, _b, _c, _d, _e, _f;
|
|
160
160
|
const hasEmbeddedWalletProviderEnabled = isTurnkeyEnabled(projectSettings);
|
|
161
|
+
const defaultWalletVersion = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.defaultWalletVersion;
|
|
161
162
|
const hasPrimaryWallet = getPrimaryWalletId();
|
|
163
|
+
if (defaultWalletVersion === EmbeddedWalletVersionEnum.V3) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
162
166
|
if (!hasEmbeddedWalletProviderEnabled || hasPrimaryWallet) {
|
|
163
167
|
return false;
|
|
164
168
|
}
|
|
165
169
|
// Turnkey specific rules
|
|
166
170
|
if (verifiedUser) {
|
|
167
171
|
const primaryEmbeddedChain = findPrimaryEmbeddedChain(projectSettings);
|
|
168
|
-
const embeddedWalletVerifiedCredentialId = (
|
|
172
|
+
const embeddedWalletVerifiedCredentialId = (_b = findEmbeddedWalletFromVerifiedCredentials(verifiedUser, [
|
|
169
173
|
primaryEmbeddedChain,
|
|
170
|
-
])) === null ||
|
|
171
|
-
const AAWalletCredentialId = (
|
|
174
|
+
])) === null || _b === void 0 ? void 0 : _b.id;
|
|
175
|
+
const AAWalletCredentialId = (_d = (_c = verifiedUser.verifiedCredentials) === null || _c === void 0 ? void 0 : _c.find((vc) => vc.walletProvider === WalletProviderEnum.SmartContractWallet)) === null || _d === void 0 ? void 0 : _d.id;
|
|
172
176
|
const targetPrimaryWalletId = AAWalletCredentialId
|
|
173
177
|
? AAWalletCredentialId
|
|
174
178
|
: embeddedWalletVerifiedCredentialId;
|
|
@@ -178,7 +182,7 @@ const useEmbeddedWallet = () => {
|
|
|
178
182
|
}
|
|
179
183
|
}
|
|
180
184
|
if (isTurnkeyEnabled(projectSettings) &&
|
|
181
|
-
!((
|
|
185
|
+
!((_f = (_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _e === void 0 ? void 0 : _e.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation)) {
|
|
182
186
|
return false;
|
|
183
187
|
}
|
|
184
188
|
return true;
|
|
@@ -21,13 +21,14 @@ require('../../../shared/consts/index.cjs');
|
|
|
21
21
|
require('../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
22
22
|
require('../../../context/ErrorContext/ErrorContext.cjs');
|
|
23
23
|
require('@dynamic-labs/multi-wallet');
|
|
24
|
+
var getAuthToken = require('../../functions/getAuthToken/getAuthToken.cjs');
|
|
24
25
|
require('react-international-phone');
|
|
25
26
|
require('../../../store/state/nonce/nonce.cjs');
|
|
26
27
|
require('../../../store/state/projectSettings/projectSettings.cjs');
|
|
27
28
|
require('../../../config/ApiEndpoint.cjs');
|
|
28
29
|
require('../../../store/state/user/user.cjs');
|
|
29
30
|
require('../../../locale/locale.cjs');
|
|
30
|
-
require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
|
|
31
|
+
var dynamicContextProps = require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
|
|
31
32
|
require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
|
|
32
33
|
require('../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
33
34
|
require('../../../context/AccountExistsContext/AccountExistsContext.cjs');
|
|
@@ -91,10 +92,14 @@ require('../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCa
|
|
|
91
92
|
require('../../../context/OnrampContext/OnrampContext.cjs');
|
|
92
93
|
require('../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.cjs');
|
|
93
94
|
require('../../../../index.cjs');
|
|
95
|
+
var useDynamicWaas = require('../useDynamicWaas/useDynamicWaas.cjs');
|
|
94
96
|
require('../../../store/state/tokenBalances.cjs');
|
|
95
97
|
require('../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
|
|
96
98
|
|
|
99
|
+
const DEFAULT_API_BASE_URL = 'https://app.dynamicauth.com/api/v0';
|
|
97
100
|
const useSetWalletConnectorFetchers = (walletOptions, environmentId, projectSettings) => {
|
|
101
|
+
const apiBaseUrl = dynamicContextProps.useApiBaseUrl();
|
|
102
|
+
const authToken = getAuthToken.getAuthToken();
|
|
98
103
|
const { registerEmbeddedWalletSessionKey, removeSessionKey } = useEmbeddedWalletSessionKeys.useEmbeddedWalletSessionKeys({ environmentId, projectSettings });
|
|
99
104
|
if (!(walletOptions === null || walletOptions === void 0 ? void 0 : walletOptions.length))
|
|
100
105
|
return;
|
|
@@ -104,6 +109,14 @@ const useSetWalletConnectorFetchers = (walletOptions, environmentId, projectSett
|
|
|
104
109
|
(_a = walletOption.walletConnector) === null || _a === void 0 ? void 0 : _a.setSessionKeyFetcher(registerEmbeddedWalletSessionKey);
|
|
105
110
|
(_b = walletOption.walletConnector) === null || _b === void 0 ? void 0 : _b.setSessionKeyRemoveFunction(() => removeSessionKey());
|
|
106
111
|
}
|
|
112
|
+
else if (walletConnectorCore.isDynamicWaasConnector(walletOption.walletConnector)) {
|
|
113
|
+
useDynamicWaas.configWaasWalletConnector({
|
|
114
|
+
apiBaseUrl: apiBaseUrl !== null && apiBaseUrl !== void 0 ? apiBaseUrl : DEFAULT_API_BASE_URL,
|
|
115
|
+
authToken,
|
|
116
|
+
environmentId,
|
|
117
|
+
walletConnector: walletOption.walletConnector,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
107
120
|
});
|
|
108
121
|
};
|
|
109
122
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { isSessionKeyCompatibleWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { isSessionKeyCompatibleWalletConnector, isDynamicWaasConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
3
|
import 'react';
|
|
4
4
|
import '../../../events/dynamicEvents.js';
|
|
5
5
|
import '../../../../../_virtual/_tslib.js';
|
|
@@ -17,13 +17,14 @@ import '../../../shared/consts/index.js';
|
|
|
17
17
|
import '../../../context/CaptchaContext/CaptchaContext.js';
|
|
18
18
|
import '../../../context/ErrorContext/ErrorContext.js';
|
|
19
19
|
import '@dynamic-labs/multi-wallet';
|
|
20
|
+
import { getAuthToken } from '../../functions/getAuthToken/getAuthToken.js';
|
|
20
21
|
import 'react-international-phone';
|
|
21
22
|
import '../../../store/state/nonce/nonce.js';
|
|
22
23
|
import '../../../store/state/projectSettings/projectSettings.js';
|
|
23
24
|
import '../../../config/ApiEndpoint.js';
|
|
24
25
|
import '../../../store/state/user/user.js';
|
|
25
26
|
import '../../../locale/locale.js';
|
|
26
|
-
import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
|
|
27
|
+
import { useApiBaseUrl } from '../../../store/state/dynamicContextProps/dynamicContextProps.js';
|
|
27
28
|
import '../../../store/state/primaryWalletId/primaryWalletId.js';
|
|
28
29
|
import '../../../context/AccessDeniedContext/AccessDeniedContext.js';
|
|
29
30
|
import '../../../context/AccountExistsContext/AccountExistsContext.js';
|
|
@@ -87,10 +88,14 @@ import '../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCar
|
|
|
87
88
|
import '../../../context/OnrampContext/OnrampContext.js';
|
|
88
89
|
import '../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.js';
|
|
89
90
|
import '../../../../index.js';
|
|
91
|
+
import { configWaasWalletConnector } from '../useDynamicWaas/useDynamicWaas.js';
|
|
90
92
|
import '../../../store/state/tokenBalances.js';
|
|
91
93
|
import '../../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
|
|
92
94
|
|
|
95
|
+
const DEFAULT_API_BASE_URL = 'https://app.dynamicauth.com/api/v0';
|
|
93
96
|
const useSetWalletConnectorFetchers = (walletOptions, environmentId, projectSettings) => {
|
|
97
|
+
const apiBaseUrl = useApiBaseUrl();
|
|
98
|
+
const authToken = getAuthToken();
|
|
94
99
|
const { registerEmbeddedWalletSessionKey, removeSessionKey } = useEmbeddedWalletSessionKeys({ environmentId, projectSettings });
|
|
95
100
|
if (!(walletOptions === null || walletOptions === void 0 ? void 0 : walletOptions.length))
|
|
96
101
|
return;
|
|
@@ -100,6 +105,14 @@ const useSetWalletConnectorFetchers = (walletOptions, environmentId, projectSett
|
|
|
100
105
|
(_a = walletOption.walletConnector) === null || _a === void 0 ? void 0 : _a.setSessionKeyFetcher(registerEmbeddedWalletSessionKey);
|
|
101
106
|
(_b = walletOption.walletConnector) === null || _b === void 0 ? void 0 : _b.setSessionKeyRemoveFunction(() => removeSessionKey());
|
|
102
107
|
}
|
|
108
|
+
else if (isDynamicWaasConnector(walletOption.walletConnector)) {
|
|
109
|
+
configWaasWalletConnector({
|
|
110
|
+
apiBaseUrl: apiBaseUrl !== null && apiBaseUrl !== void 0 ? apiBaseUrl : DEFAULT_API_BASE_URL,
|
|
111
|
+
authToken,
|
|
112
|
+
environmentId,
|
|
113
|
+
walletConnector: walletOption.walletConnector,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
103
116
|
});
|
|
104
117
|
};
|
|
105
118
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useSyncDynamicWaas';
|
|
@@ -0,0 +1,145 @@
|
|
|
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
|
+
require('@dynamic-labs/sdk-api-core');
|
|
9
|
+
var logger = require('../../../shared/logger.cjs');
|
|
10
|
+
require('@dynamic-labs/iconic');
|
|
11
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
12
|
+
require('react/jsx-runtime');
|
|
13
|
+
require('../../../context/ViewContext/ViewContext.cjs');
|
|
14
|
+
require('@dynamic-labs/wallet-book');
|
|
15
|
+
require('@dynamic-labs/utils');
|
|
16
|
+
require('../../constants/colors.cjs');
|
|
17
|
+
require('../../constants/values.cjs');
|
|
18
|
+
require('../../../shared/consts/index.cjs');
|
|
19
|
+
require('../../../context/DynamicContext/DynamicContext.cjs');
|
|
20
|
+
var useDynamicEvents = require('../events/useDynamicEvents/useDynamicEvents.cjs');
|
|
21
|
+
require('../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
22
|
+
require('../../../context/ErrorContext/ErrorContext.cjs');
|
|
23
|
+
require('@dynamic-labs/multi-wallet');
|
|
24
|
+
require('react-international-phone');
|
|
25
|
+
require('../../../store/state/nonce/nonce.cjs');
|
|
26
|
+
var projectSettings = require('../../../store/state/projectSettings/projectSettings.cjs');
|
|
27
|
+
require('../../../config/ApiEndpoint.cjs');
|
|
28
|
+
var user = require('../../../store/state/user/user.cjs');
|
|
29
|
+
require('../../../locale/locale.cjs');
|
|
30
|
+
require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
|
|
31
|
+
require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
|
|
32
|
+
require('../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
33
|
+
require('../../../context/AccountExistsContext/AccountExistsContext.cjs');
|
|
34
|
+
require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
|
|
35
|
+
require('../../../events/dynamicEvents.cjs');
|
|
36
|
+
require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
|
|
37
|
+
require('../../../context/VerificationContext/VerificationContext.cjs');
|
|
38
|
+
require('react-dom');
|
|
39
|
+
require('../../functions/compareChains/compareChains.cjs');
|
|
40
|
+
require('../../../context/ThemeContext/ThemeContext.cjs');
|
|
41
|
+
require('../useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
|
|
42
|
+
require('bs58');
|
|
43
|
+
require('@dynamic-labs/types');
|
|
44
|
+
require('../../../context/SocialRedirectContext/SocialRedirectContext.cjs');
|
|
45
|
+
var LoadingContext = require('../../../context/LoadingContext/LoadingContext.cjs');
|
|
46
|
+
require('../../../context/WalletContext/WalletContext.cjs');
|
|
47
|
+
require('../useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs');
|
|
48
|
+
require('yup');
|
|
49
|
+
require('../../../context/MockContext/MockContext.cjs');
|
|
50
|
+
require('../../../views/CollectUserDataView/useFields.cjs');
|
|
51
|
+
require('../../../context/FieldsStateContext/FieldsStateContext.cjs');
|
|
52
|
+
require('../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
|
|
53
|
+
require('@dynamic-labs/rpc-providers');
|
|
54
|
+
require('../../../store/state/loadingAndLifecycle.cjs');
|
|
55
|
+
var walletOptions = 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('../../../components/ShadowDOM/ShadowDOM.cjs');
|
|
60
|
+
require('../../../components/IconButton/IconButton.cjs');
|
|
61
|
+
require('../../../components/InlineWidget/InlineWidget.cjs');
|
|
62
|
+
require('../../../components/Input/Input.cjs');
|
|
63
|
+
require('../../../components/IsBrowser/IsBrowser.cjs');
|
|
64
|
+
require('../../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
65
|
+
require('../../../components/OverlayCard/OverlayCard.cjs');
|
|
66
|
+
require('../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
|
|
67
|
+
require('../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
|
|
68
|
+
require('../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
|
|
69
|
+
require('../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
|
|
70
|
+
require('../../../components/Popper/Popper/Popper.cjs');
|
|
71
|
+
require('../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
72
|
+
require('react-focus-lock');
|
|
73
|
+
require('qrcode');
|
|
74
|
+
require('formik');
|
|
75
|
+
require('../useSubdomainCheck/useSubdomainCheck.cjs');
|
|
76
|
+
require('../../../context/WalletGroupContext/WalletGroupContext.cjs');
|
|
77
|
+
require('../../../context/IpConfigurationContext/IpConfigurationContext.cjs');
|
|
78
|
+
require('../../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
|
|
79
|
+
require('../../../context/ConnectWithOtpContext/constants.cjs');
|
|
80
|
+
require('../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
|
|
81
|
+
require('@hcaptcha/react-hcaptcha');
|
|
82
|
+
require('../../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
|
|
83
|
+
require('../../../context/FooterAnimationContext/index.cjs');
|
|
84
|
+
require('../../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
|
|
85
|
+
require('../../../context/PasskeyContext/PasskeyContext.cjs');
|
|
86
|
+
require('../../../store/state/sendBalances.cjs');
|
|
87
|
+
require('../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs');
|
|
88
|
+
require('../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
|
|
89
|
+
require('../../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
|
|
90
|
+
require('../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
|
|
91
|
+
require('../../../context/OnrampContext/OnrampContext.cjs');
|
|
92
|
+
require('../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.cjs');
|
|
93
|
+
require('../../../../index.cjs');
|
|
94
|
+
var useDynamicWaas = require('../useDynamicWaas/useDynamicWaas.cjs');
|
|
95
|
+
require('../../../store/state/tokenBalances.cjs');
|
|
96
|
+
require('../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
|
|
97
|
+
var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.cjs');
|
|
98
|
+
|
|
99
|
+
const useSyncDynamicWaas = () => {
|
|
100
|
+
const { primaryWallet, setShowAuthFlow } = useInternalDynamicContext.useInternalDynamicContext();
|
|
101
|
+
const { loading: globalLoading } = LoadingContext.useLoadingContext();
|
|
102
|
+
const { user: user$1 } = user.useUser();
|
|
103
|
+
const projectSettings$1 = projectSettings.useProjectSettings();
|
|
104
|
+
const walletConnectorOptions = walletOptions.useWalletConnectorOptions();
|
|
105
|
+
const { createWalletAccount, shouldAutoCreateDynamicWaasWallet } = useDynamicWaas.useDynamicWaas();
|
|
106
|
+
const triggeredCreate = React.useRef(false);
|
|
107
|
+
useDynamicEvents.useInternalDynamicEvents('logout', () => {
|
|
108
|
+
triggeredCreate.current = false;
|
|
109
|
+
});
|
|
110
|
+
// this is used to trigger createWalletAccount
|
|
111
|
+
// ** It must be an useEffect because some of the dependencies are async
|
|
112
|
+
React.useEffect(() => {
|
|
113
|
+
const syncDynamicWaas = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
try {
|
|
115
|
+
triggeredCreate.current = true;
|
|
116
|
+
yield createWalletAccount();
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
logger.logger.error('Error creating dynamic waas wallet', error);
|
|
120
|
+
setShowAuthFlow(false);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const shouldSyncCreateWallet = shouldAutoCreateDynamicWaasWallet && !triggeredCreate.current;
|
|
124
|
+
if (!shouldSyncCreateWallet ||
|
|
125
|
+
!user$1 ||
|
|
126
|
+
!projectSettings$1 ||
|
|
127
|
+
!walletConnectorOptions.length || // no connectors to use for the embedded wallet
|
|
128
|
+
globalLoading // this will be true if auth is in progress
|
|
129
|
+
) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
syncDynamicWaas();
|
|
133
|
+
}, [
|
|
134
|
+
user$1,
|
|
135
|
+
projectSettings$1,
|
|
136
|
+
walletConnectorOptions,
|
|
137
|
+
globalLoading,
|
|
138
|
+
shouldAutoCreateDynamicWaasWallet,
|
|
139
|
+
setShowAuthFlow,
|
|
140
|
+
createWalletAccount,
|
|
141
|
+
primaryWallet,
|
|
142
|
+
]);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
exports.useSyncDynamicWaas = useSyncDynamicWaas;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useSyncDynamicWaas: () => void;
|