@dynamic-labs/sdk-react-core 2.1.0-alpha.10 → 2.1.0-alpha.12
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 +20 -0
- package/package.cjs +2 -2
- package/package.js +2 -2
- package/package.json +13 -13
- package/src/index.cjs +2 -0
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -0
- package/src/lib/components/CopyButton/CopyButton.cjs +3 -3
- package/src/lib/components/CopyButton/CopyButton.d.ts +1 -1
- package/src/lib/components/CopyButton/CopyButton.js +3 -3
- package/src/lib/components/LoadingQrCode/LoadingQrCode.cjs +11 -0
- package/src/lib/components/LoadingQrCode/LoadingQrCode.d.ts +8 -0
- package/src/lib/components/LoadingQrCode/LoadingQrCode.js +7 -0
- package/src/lib/components/LoadingQrCode/index.d.ts +1 -0
- package/src/lib/components/QrCodeWrapper/QrCodeContainer/QrCodeContainer.cjs +2 -1
- package/src/lib/components/QrCodeWrapper/QrCodeContainer/QrCodeContainer.js +2 -1
- package/src/lib/components/QrCodeWrapper/QrCodeWrapper.cjs +5 -1
- package/src/lib/components/QrCodeWrapper/QrCodeWrapper.js +5 -1
- package/src/lib/data/api/chains/balances.cjs +38 -0
- package/src/lib/data/api/chains/balances.d.ts +8 -0
- package/src/lib/data/api/chains/balances.js +34 -0
- package/src/lib/data/api/chains/index.d.ts +1 -0
- package/src/lib/shared/types/general.d.ts +1 -0
- package/src/lib/utils/constants/errors.cjs +2 -0
- package/src/lib/utils/constants/errors.d.ts +1 -0
- package/src/lib/utils/constants/errors.js +2 -1
- package/src/lib/utils/hooks/index.d.ts +1 -0
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +34 -3
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.d.ts +18 -9
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +34 -3
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useMPCEmbeddedWallet.cjs +5 -1
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useMPCEmbeddedWallet.d.ts +1 -0
- package/src/lib/utils/hooks/useEmbeddedWallet/useMPCEmbeddedWallet/useMPCEmbeddedWallet.js +5 -1
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs +4 -0
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.d.ts +2 -0
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.js +3 -1
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.cjs +68 -28
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.d.ts +11 -6
- package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.js +70 -30
- package/src/lib/utils/hooks/useTokenBalances/index.d.ts +1 -0
- package/src/lib/utils/hooks/useTokenBalances/useTokenBalances.cjs +141 -0
- package/src/lib/utils/hooks/useTokenBalances/useTokenBalances.d.ts +12 -0
- package/src/lib/utils/hooks/useTokenBalances/useTokenBalances.js +137 -0
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.cjs +1 -1
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.js +1 -1
- package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.cjs +5 -4
- package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.js +5 -4
- package/src/lib/views/FarcasterQrCodeView/FarcasterQrCodeView.cjs +103 -0
- package/src/lib/views/FarcasterQrCodeView/FarcasterQrCodeView.d.ts +6 -0
- package/src/lib/views/FarcasterQrCodeView/FarcasterQrCodeView.js +99 -0
- package/src/lib/views/FarcasterQrCodeView/index.d.ts +1 -0
- package/src/lib/views/LoginView/LoginView.cjs +9 -1
- package/src/lib/views/LoginView/LoginView.js +9 -1
- package/src/lib/views/LoginView/utils/showFarcasterQrCodeView/index.d.ts +1 -0
- package/src/lib/views/LoginView/utils/showFarcasterQrCodeView/showFarcasterQrCodeView.cjs +14 -0
- package/src/lib/views/LoginView/utils/showFarcasterQrCodeView/showFarcasterQrCodeView.d.ts +2 -0
- package/src/lib/views/LoginView/utils/showFarcasterQrCodeView/showFarcasterQrCodeView.js +10 -0
|
@@ -43,13 +43,14 @@ import '../../../../context/VerificationContext/VerificationContext.js';
|
|
|
43
43
|
import 'react-dom';
|
|
44
44
|
import { useElementById } from '../../useElementById/useElementById.js';
|
|
45
45
|
import { useWalletContext } from '../../../../context/WalletContext/WalletContext.js';
|
|
46
|
+
import { useIsTurnkeyWallet } from '../../useIsTurnkeyWallet/useIsTurnkeyWallet.js';
|
|
46
47
|
import { validateUserIsLoggedIn } from '../../../validations/validateUserIsLoggedIn/validateUserIsLoggedIn.js';
|
|
47
48
|
import { validateTurnkeyProviderEnabled } from '../../../validations/validateTurnkeyProviderEnabled/validateTurnkeyProviderEnabled.js';
|
|
48
|
-
import { ACTIVE_SESSION, SESSION_RESTORED, INVALID_REQUEST, INVALID_WALLET_DATA, SESSION_CREATED, ERROR_SENDING_CODE, CODE_SENT } from '../../../constants/errors.js';
|
|
49
|
-
import { useIsTurnkeyWallet } from '../../useIsTurnkeyWallet/useIsTurnkeyWallet.js';
|
|
49
|
+
import { ACTIVE_SESSION, SESSION_RESTORED, INVALID_REQUEST, INVALID_WALLET_DATA, SESSION_CREATED, USER_NOT_LOGGED_IN, ERROR_SENDING_CODE, CODE_SENT } from '../../../constants/errors.js';
|
|
50
50
|
import { canRestoreEmbeddedWalletSession, restoreEmbeddedWalletSession } from '../../../../views/Passkey/utils/passkeyRecovery/passkeyRecovery.js';
|
|
51
|
+
import { cleanupExport, initExport, exportCredential } from '../../../../views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.js';
|
|
51
52
|
import { useTurnkey } from './useTurnkey/useTurnkey.js';
|
|
52
|
-
import { iframeContainerId, iframeElementId } from './constants.js';
|
|
53
|
+
import { iframeContainerId, iframeElementId, revealIframeElementId, revealIframeContainerId } from './constants.js';
|
|
53
54
|
import '../../../../context/ThemeContext/ThemeContext.js';
|
|
54
55
|
import '@dynamic-labs/types';
|
|
55
56
|
import 'yup';
|
|
@@ -101,20 +102,21 @@ import { useInternalDynamicContext } from '../../../../context/DynamicContext/us
|
|
|
101
102
|
* getPasskeys, - gets all passkeys for the user
|
|
102
103
|
* isLoadingEmbeddedWallet, - loading state of the embedded wallet
|
|
103
104
|
* isSessionActive, - checks if the embedded wallet session is active
|
|
105
|
+
* revealEmbeddedWalletKey - export the recovery phrase or private key of the embedded wallet
|
|
104
106
|
* sendOneTimeCode, - sends a one-time code to the user so they can create a session or add a new passkey
|
|
105
107
|
* userHasEmbeddedWallet, - checks if the user has an embedded wallet
|
|
106
108
|
* }
|
|
107
109
|
*/
|
|
108
110
|
const useSecureEnclaveEmbeddedWallet = () => {
|
|
109
111
|
var _a, _b, _c, _d;
|
|
110
|
-
const { projectSettings, onboardingOnlyJwt, primaryWallet, user, environmentId, walletConnectorOptions, setUser, } = useInternalDynamicContext();
|
|
112
|
+
const { projectSettings, authToken, onboardingOnlyJwt, primaryWallet, user, environmentId, walletConnectorOptions, setUser, } = useInternalDynamicContext();
|
|
111
113
|
const { createTurnkeyWallet } = useTurnkey();
|
|
112
114
|
const { hasRecoveryEmail } = useIsTurnkeyWallet();
|
|
113
115
|
const { createRootElement } = useElementById();
|
|
114
116
|
const { isLoadingEmbeddedWallet, setIsLoadingEmbeddedWallet } = useWalletContext();
|
|
115
117
|
const wallet = getEOAWallet(primaryWallet, (user === null || user === void 0 ? void 0 : user.verifiedCredentials) || []);
|
|
116
118
|
/**
|
|
117
|
-
* Checks if the user has
|
|
119
|
+
* Checks if the user has a secure enclave embedded wallet or not
|
|
118
120
|
* @returns boolean
|
|
119
121
|
*/
|
|
120
122
|
const userHasEmbeddedWallet = useCallback(() => hasEmbeddedWallet(getAuthToken() || onboardingOnlyJwt, 'turnkey'), [onboardingOnlyJwt]);
|
|
@@ -155,9 +157,9 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
155
157
|
* @param oneTimeCode - optional one-time code parameter. If not informed it tries to restore a session
|
|
156
158
|
* @returns Promise<'session_created' | 'session_restored'> - returns a string indicating the status of the session
|
|
157
159
|
*/
|
|
158
|
-
const createOrRestoreSession = useCallback((
|
|
159
|
-
var _h, _j, _k, _l, _m, _o
|
|
160
|
-
const jwt = (
|
|
160
|
+
const createOrRestoreSession = useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
+
var _g, _h, _j, _k, _l, _m, _o;
|
|
162
|
+
const jwt = (_g = getAuthToken()) !== null && _g !== void 0 ? _g : onboardingOnlyJwt;
|
|
161
163
|
const { decodedJwt } = validateUserIsLoggedIn(jwt);
|
|
162
164
|
const turnkeyRecoveryHandler = getEmbeddedWalletAuthHandler(wallet === null || wallet === void 0 ? void 0 : wallet.connector);
|
|
163
165
|
if (turnkeyRecoveryHandler.isSessionActive()) {
|
|
@@ -165,13 +167,13 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
165
167
|
}
|
|
166
168
|
const turnkeyAuthIframeContainerRef = createRootElement(iframeContainerId);
|
|
167
169
|
// try to restore session if possible
|
|
168
|
-
if (canRestoreEmbeddedWalletSession((
|
|
170
|
+
if (canRestoreEmbeddedWalletSession((_h = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _h === void 0 ? void 0 : _h.sessionKeyDuration)) {
|
|
169
171
|
try {
|
|
170
172
|
const sessionRestored = yield restoreEmbeddedWalletSession({
|
|
171
173
|
authToken: jwt,
|
|
172
174
|
iframeContainer: turnkeyAuthIframeContainerRef.current,
|
|
173
175
|
iframeElementId,
|
|
174
|
-
sessionExpiration: getEmbeddedWalletSessionExpiration((
|
|
176
|
+
sessionExpiration: getEmbeddedWalletSessionExpiration((_k = (_j = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _j === void 0 ? void 0 : _j.embeddedWallets) === null || _k === void 0 ? void 0 : _k.sessionKeyDuration),
|
|
175
177
|
wallet: primaryWallet,
|
|
176
178
|
});
|
|
177
179
|
if (sessionRestored)
|
|
@@ -181,7 +183,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
181
183
|
logger.error('Failed to restore embedded wallet', err);
|
|
182
184
|
}
|
|
183
185
|
}
|
|
184
|
-
if (!oneTimeCode) {
|
|
186
|
+
if (!(options === null || options === void 0 ? void 0 : options.oneTimeCode)) {
|
|
185
187
|
throw new DynamicError('One-time code is required to create a session.', INVALID_REQUEST);
|
|
186
188
|
}
|
|
187
189
|
// tries to create a new session with the informed one-time code
|
|
@@ -189,11 +191,11 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
189
191
|
if (!userHasEmbeddedWallet() || !hasRecoveryEmail) {
|
|
190
192
|
throw new DynamicError('User does not have a secure enclave wallet or a verified email', INVALID_WALLET_DATA);
|
|
191
193
|
}
|
|
192
|
-
const organizationId = (
|
|
193
|
-
yield turnkeyRecoveryHandler.verifyRecoveryCode(oneTimeCode, organizationId);
|
|
194
|
+
const organizationId = (_o = (_m = (_l = decodedJwt.verifiedCredentials) === null || _l === void 0 ? void 0 : _l.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'))) === null || _m === void 0 ? void 0 : _m.walletProperties) === null || _o === void 0 ? void 0 : _o.turnkeySubOrganizationId;
|
|
195
|
+
yield turnkeyRecoveryHandler.verifyRecoveryCode(options.oneTimeCode, organizationId);
|
|
194
196
|
const sessionSettings = {
|
|
195
197
|
createdAt: new Date().getTime(),
|
|
196
|
-
emailCode: oneTimeCode,
|
|
198
|
+
emailCode: options.oneTimeCode,
|
|
197
199
|
userId: turnkeyRecoveryHandler.recoveryUserId,
|
|
198
200
|
};
|
|
199
201
|
LocalStorage.setToLS(EMBEDDED_WALLET_SESSION_SETTINGS, sessionSettings);
|
|
@@ -209,15 +211,14 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
209
211
|
]);
|
|
210
212
|
/**
|
|
211
213
|
* Creates a new passkey both for an existing wallet or a wallet to be created
|
|
212
|
-
* @param
|
|
213
|
-
*
|
|
214
|
+
* @param options - optional parameter to inform a one-time code to create a session,
|
|
214
215
|
* @returns Promise<WebAuthnAttestation>
|
|
215
216
|
*/
|
|
216
|
-
const createPasskey = useCallback((
|
|
217
|
-
var
|
|
217
|
+
const createPasskey = useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
218
|
+
var _p, _q;
|
|
218
219
|
const { decodedJwt, jwt } = validateUserIsLoggedIn(getAuthToken() || onboardingOnlyJwt);
|
|
219
220
|
validateTurnkeyProviderEnabled(projectSettings);
|
|
220
|
-
const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (
|
|
221
|
+
const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_p = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _p === void 0 ? void 0 : _p.chainConfigurations, decodedJwt.verifiedCredentials);
|
|
221
222
|
if (!(turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletConnector)) {
|
|
222
223
|
throw new DynamicError('Wallet connector not found', INVALID_WALLET_DATA);
|
|
223
224
|
}
|
|
@@ -232,13 +233,13 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
232
233
|
if (!('id' in turnkeyWallet) || !hasEmailVC) {
|
|
233
234
|
return walletConnector.getWebAuthnAttestation();
|
|
234
235
|
}
|
|
235
|
-
const organizationId = (
|
|
236
|
+
const organizationId = (_q = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _q === void 0 ? void 0 : _q.turnkeySubOrganizationId;
|
|
236
237
|
if (!organizationId) {
|
|
237
238
|
throw new DynamicError('No sub organization id found for the wallet', INVALID_WALLET_DATA);
|
|
238
239
|
}
|
|
239
240
|
const turnkAuthenticatorHandler = getEmbeddedWalletAuthHandler(walletConnector);
|
|
240
241
|
// add new passkey to the wallet through an active session
|
|
241
|
-
yield createOrRestoreSession(
|
|
242
|
+
yield createOrRestoreSession(options);
|
|
242
243
|
const { attestation, challenge, displayName } = yield walletConnector.getWebAuthnAttestation();
|
|
243
244
|
yield turnkAuthenticatorHandler.addPasskeyAuthenticator({
|
|
244
245
|
attestation,
|
|
@@ -261,9 +262,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
261
262
|
onboardingOnlyJwt,
|
|
262
263
|
projectSettings,
|
|
263
264
|
setUser,
|
|
264
|
-
user
|
|
265
|
-
user === null || user === void 0 ? void 0 : user.phoneNumber,
|
|
266
|
-
user === null || user === void 0 ? void 0 : user.verifiedCredentials,
|
|
265
|
+
user,
|
|
267
266
|
walletConnectorOptions,
|
|
268
267
|
]);
|
|
269
268
|
/**
|
|
@@ -271,8 +270,8 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
271
270
|
* @returns Promise<Passkey[]>
|
|
272
271
|
*/
|
|
273
272
|
const getPasskeys = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
274
|
-
var
|
|
275
|
-
const { jwt } = validateUserIsLoggedIn((
|
|
273
|
+
var _r;
|
|
274
|
+
const { jwt } = validateUserIsLoggedIn((_r = getAuthToken()) !== null && _r !== void 0 ? _r : onboardingOnlyJwt);
|
|
276
275
|
const data = yield getUserPasskeys({
|
|
277
276
|
environmentId: environmentId,
|
|
278
277
|
userJwt: jwt,
|
|
@@ -286,15 +285,55 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
286
285
|
const isSessionActive = (_d = ((wallet === null || wallet === void 0 ? void 0 : wallet.connector) &&
|
|
287
286
|
'getAuthenticatorHandler' in wallet.connector &&
|
|
288
287
|
((_c = getEmbeddedWalletAuthHandler(wallet.connector)) === null || _c === void 0 ? void 0 : _c.isSessionActive()))) !== null && _d !== void 0 ? _d : false;
|
|
288
|
+
/**
|
|
289
|
+
* export the recovery phrase or private key of the embedded wallet
|
|
290
|
+
* @param options - optional parameter object containing the type of key to reveal 'recoveryPhrase' | 'privateKey'
|
|
291
|
+
* and the html container id to render the iframe into
|
|
292
|
+
* @returns Promise<string> - returns the embedded wallet recovery phrase or private key
|
|
293
|
+
*/
|
|
294
|
+
const revealEmbeddedWalletKey = (_s) => __awaiter(void 0, [_s], void 0, function* ({ type, htmlContainerId, }) {
|
|
295
|
+
var _t, _u;
|
|
296
|
+
if (!user) {
|
|
297
|
+
throw new DynamicError('User is not logged in', USER_NOT_LOGGED_IN);
|
|
298
|
+
}
|
|
299
|
+
yield cleanupExport({
|
|
300
|
+
wallet,
|
|
301
|
+
});
|
|
302
|
+
const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_t = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _t === void 0 ? void 0 : _t.chainConfigurations, user === null || user === void 0 ? void 0 : user.verifiedCredentials);
|
|
303
|
+
const turnkeyHDWalletId = (_u = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _u === void 0 ? void 0 : _u.turnkeyHDWalletId;
|
|
304
|
+
if (type === 'recoveryPhrase' && !turnkeyHDWalletId) {
|
|
305
|
+
type = 'privateKey';
|
|
306
|
+
}
|
|
307
|
+
const iframeContainerElement = createRootElement(revealIframeElementId, htmlContainerId || revealIframeContainerId);
|
|
308
|
+
// hide the iframe container until the export is done
|
|
309
|
+
// since it will show unrelated turnkey content
|
|
310
|
+
iframeContainerElement.current.style.display = 'none';
|
|
311
|
+
yield initExport({
|
|
312
|
+
iframeContainer: iframeContainerElement.current,
|
|
313
|
+
iframeElementId: revealIframeElementId,
|
|
314
|
+
wallet,
|
|
315
|
+
});
|
|
316
|
+
yield exportCredential({
|
|
317
|
+
address: type === 'privateKey' ? wallet === null || wallet === void 0 ? void 0 : wallet.address : undefined,
|
|
318
|
+
authToken,
|
|
319
|
+
environmentId,
|
|
320
|
+
userEmail: user === null || user === void 0 ? void 0 : user.email,
|
|
321
|
+
wallet,
|
|
322
|
+
});
|
|
323
|
+
// show the iframe container after the export is done
|
|
324
|
+
// to show the exported content only
|
|
325
|
+
iframeContainerElement.current.style.display = 'block';
|
|
326
|
+
return true;
|
|
327
|
+
});
|
|
289
328
|
/**
|
|
290
329
|
* Sends a one-time code to the user so they can create a session or add a new passkey
|
|
291
330
|
* @returns Promise<'code_sent'>
|
|
292
331
|
*/
|
|
293
332
|
const sendOneTimeCode = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
294
|
-
var
|
|
295
|
-
const { jwt, decodedJwt } = validateUserIsLoggedIn((
|
|
333
|
+
var _v, _w, _x;
|
|
334
|
+
const { jwt, decodedJwt } = validateUserIsLoggedIn((_v = getAuthToken()) !== null && _v !== void 0 ? _v : onboardingOnlyJwt);
|
|
296
335
|
validateTurnkeyProviderEnabled(projectSettings);
|
|
297
|
-
const targetTurnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (
|
|
336
|
+
const targetTurnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_w = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _w === void 0 ? void 0 : _w.chainConfigurations, decodedJwt.verifiedCredentials);
|
|
298
337
|
if (!targetTurnkeyWallet || !('id' in targetTurnkeyWallet)) {
|
|
299
338
|
throw new DynamicError('User does not have a valid secure enclave wallet', INVALID_WALLET_DATA);
|
|
300
339
|
}
|
|
@@ -305,7 +344,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
305
344
|
throw new DynamicError('Session is active. No need to create a new one', ACTIVE_SESSION);
|
|
306
345
|
}
|
|
307
346
|
const turnkeyAuthIframeContainerRef = createRootElement(iframeContainerId);
|
|
308
|
-
const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, iframeElementId, getEmbeddedWalletSessionExpiration((
|
|
347
|
+
const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, iframeElementId, getEmbeddedWalletSessionExpiration((_x = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _x === void 0 ? void 0 : _x.sessionKeyDuration));
|
|
309
348
|
if (!publicKey) {
|
|
310
349
|
throw new DynamicError(ERROR_SENDING_CODE);
|
|
311
350
|
}
|
|
@@ -332,6 +371,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
|
|
|
332
371
|
getPasskeys,
|
|
333
372
|
isLoadingEmbeddedWallet,
|
|
334
373
|
isSessionActive,
|
|
374
|
+
revealEmbeddedWalletKey,
|
|
335
375
|
sendOneTimeCode,
|
|
336
376
|
userHasEmbeddedWallet,
|
|
337
377
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTokenBalances } from './useTokenBalances';
|
|
@@ -0,0 +1,141 @@
|
|
|
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/wallet-connector-core');
|
|
10
|
+
require('../../../shared/logger.cjs');
|
|
11
|
+
require('@dynamic-labs/iconic');
|
|
12
|
+
require('react/jsx-runtime');
|
|
13
|
+
require('../../../context/ViewContext/ViewContext.cjs');
|
|
14
|
+
require('@dynamic-labs/wallet-book');
|
|
15
|
+
require('../../constants/colors.cjs');
|
|
16
|
+
require('../../constants/values.cjs');
|
|
17
|
+
require('../../../shared/utils/classes/storage/localStorage.cjs');
|
|
18
|
+
require('@dynamic-labs/utils');
|
|
19
|
+
require('../../../shared/consts/index.cjs');
|
|
20
|
+
require('@dynamic-labs/multi-wallet');
|
|
21
|
+
var getAuthToken = require('../../functions/getAuthToken/getAuthToken.cjs');
|
|
22
|
+
require('react-international-phone');
|
|
23
|
+
require('viem');
|
|
24
|
+
require('viem/chains');
|
|
25
|
+
require('../../../config/ApiEndpoint.cjs');
|
|
26
|
+
require('../../../locale/locale.cjs');
|
|
27
|
+
var balances = require('../../../data/api/chains/balances.cjs');
|
|
28
|
+
require('../../../context/DynamicContext/DynamicContext.cjs');
|
|
29
|
+
require('../../../events/dynamicEvents.cjs');
|
|
30
|
+
require('../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
31
|
+
require('../../../context/ErrorContext/ErrorContext.cjs');
|
|
32
|
+
require('../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
33
|
+
require('../../../context/AccountExistsContext/AccountExistsContext.cjs');
|
|
34
|
+
require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
|
|
35
|
+
require('../../../context/VerificationContext/VerificationContext.cjs');
|
|
36
|
+
require('react-dom');
|
|
37
|
+
require('../../../context/WalletContext/WalletContext.cjs');
|
|
38
|
+
require('../../../context/ThemeContext/ThemeContext.cjs');
|
|
39
|
+
require('@dynamic-labs/types');
|
|
40
|
+
require('yup');
|
|
41
|
+
require('../../../context/MockContext/MockContext.cjs');
|
|
42
|
+
require('react-i18next');
|
|
43
|
+
require('../../../context/FieldsStateContext/FieldsStateContext.cjs');
|
|
44
|
+
require('../useUserUpdateRequest/useUpdateUser/useUpdateUser.cjs');
|
|
45
|
+
require('../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
|
|
46
|
+
require('@dynamic-labs/rpc-providers');
|
|
47
|
+
require('../../../components/Alert/Alert.cjs');
|
|
48
|
+
require('../../../components/ShadowDOM/ShadowDOM.cjs');
|
|
49
|
+
require('../../../components/IconButton/IconButton.cjs');
|
|
50
|
+
require('../../../components/InlineWidget/InlineWidget.cjs');
|
|
51
|
+
require('../../../components/Input/Input.cjs');
|
|
52
|
+
require('../../../components/IsBrowser/IsBrowser.cjs');
|
|
53
|
+
require('../../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
54
|
+
require('../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
|
|
55
|
+
require('../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
|
|
56
|
+
require('../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
|
|
57
|
+
require('../../../components/OverlayCard/OverlayCardTarget/OverlayCardTarget.cjs');
|
|
58
|
+
require('../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
|
|
59
|
+
require('../../../components/Popper/Popper/Popper.cjs');
|
|
60
|
+
require('../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
61
|
+
require('react-focus-lock');
|
|
62
|
+
require('qrcode');
|
|
63
|
+
require('formik');
|
|
64
|
+
require('../../../views/WalletList/WalletList.cjs');
|
|
65
|
+
require('../../../context/SocialRedirectContext/SocialRedirectContext.cjs');
|
|
66
|
+
require('../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
|
|
67
|
+
require('@hcaptcha/react-hcaptcha');
|
|
68
|
+
require('../../../context/LoadingContext/LoadingContext.cjs');
|
|
69
|
+
require('../../../context/FooterAnimationContext/index.cjs');
|
|
70
|
+
require('../../../views/LoginView/sections/PhoneNumberSignInSection/PhoneNumberSignInSection.cjs');
|
|
71
|
+
require('../../../context/WalletGroupContext/WalletGroupContext.cjs');
|
|
72
|
+
require('../../../context/PasskeyContext/PasskeyContext.cjs');
|
|
73
|
+
require('../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
|
|
74
|
+
require('../../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
|
|
75
|
+
require('../../../views/TransactionConfirmationView/helpers/transactionErrorMessage.cjs');
|
|
76
|
+
require('../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
|
|
77
|
+
var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.cjs');
|
|
78
|
+
|
|
79
|
+
// Hook exposed to customers and used internally to fetch account balances
|
|
80
|
+
const useTokenBalances = ({ accountAddress, networkId, chainName = sdkApiCore.ChainEnum.Evm, tokenAddresses, } = {}) => {
|
|
81
|
+
const [tokenBalancesData, setTokenBalancesData] = React.useState(undefined);
|
|
82
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
83
|
+
const [error, setError] = React.useState(undefined);
|
|
84
|
+
const { primaryWallet, environmentId, network, walletConnector } = useInternalDynamicContext.useInternalDynamicContext();
|
|
85
|
+
const requestChainName = chainName !== null && chainName !== void 0 ? chainName : walletConnector === null || walletConnector === void 0 ? void 0 : walletConnector.connectedChain;
|
|
86
|
+
const requestAccount = accountAddress !== null && accountAddress !== void 0 ? accountAddress : primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address;
|
|
87
|
+
const requestNetwork = networkId !== null && networkId !== void 0 ? networkId : network;
|
|
88
|
+
const fetchAccountBalances = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
const jwt = getAuthToken.getAuthToken();
|
|
90
|
+
if (!jwt) {
|
|
91
|
+
setError('User is not logged in');
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (requestChainName !== sdkApiCore.ChainEnum.Evm) {
|
|
95
|
+
setError(`Chain ${requestChainName} is not supported for token balances`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (!isLoading &&
|
|
99
|
+
requestAccount &&
|
|
100
|
+
requestNetwork &&
|
|
101
|
+
Object.values(sdkApiCore.GetAccountBalancesNetworkIdEnum).includes(requestNetwork)) {
|
|
102
|
+
setIsLoading(true);
|
|
103
|
+
balances.getAccountTokenBalances({
|
|
104
|
+
accountAddress: requestAccount,
|
|
105
|
+
chainName: requestChainName,
|
|
106
|
+
environmentId,
|
|
107
|
+
networkId: Number(requestNetwork),
|
|
108
|
+
userJwt: jwt,
|
|
109
|
+
})
|
|
110
|
+
.then((response) => {
|
|
111
|
+
if (response) {
|
|
112
|
+
setTokenBalancesData(response);
|
|
113
|
+
setError(undefined);
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
.catch((e) => {
|
|
117
|
+
setError(e.message);
|
|
118
|
+
})
|
|
119
|
+
.finally(() => {
|
|
120
|
+
setIsLoading(false);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}), [
|
|
124
|
+
isLoading,
|
|
125
|
+
requestAccount,
|
|
126
|
+
requestNetwork,
|
|
127
|
+
requestChainName,
|
|
128
|
+
environmentId,
|
|
129
|
+
]);
|
|
130
|
+
React.useEffect(() => {
|
|
131
|
+
fetchAccountBalances();
|
|
132
|
+
}, [requestAccount, requestNetwork]);
|
|
133
|
+
let tokenBalances = tokenBalancesData;
|
|
134
|
+
if (tokenAddresses) {
|
|
135
|
+
const lowerTokenAddresses = tokenAddresses === null || tokenAddresses === void 0 ? void 0 : tokenAddresses.map((address) => address.toLowerCase());
|
|
136
|
+
tokenBalances = tokenBalancesData === null || tokenBalancesData === void 0 ? void 0 : tokenBalancesData.filter((token) => lowerTokenAddresses === null || lowerTokenAddresses === void 0 ? void 0 : lowerTokenAddresses.includes(token.address.toLowerCase()));
|
|
137
|
+
}
|
|
138
|
+
return { error, isError: Boolean(error), isLoading, tokenBalances };
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
exports.useTokenBalances = useTokenBalances;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChainEnum, TokenBalance } from '@dynamic-labs/sdk-api-core';
|
|
2
|
+
export declare const useTokenBalances: ({ accountAddress, networkId, chainName, tokenAddresses, }?: {
|
|
3
|
+
accountAddress?: string;
|
|
4
|
+
networkId?: number;
|
|
5
|
+
chainName?: ChainEnum;
|
|
6
|
+
tokenAddresses?: string[];
|
|
7
|
+
}) => {
|
|
8
|
+
error: string | undefined;
|
|
9
|
+
isError: boolean;
|
|
10
|
+
isLoading: boolean;
|
|
11
|
+
tokenBalances: TokenBalance[] | undefined;
|
|
12
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
4
|
+
import { ChainEnum, GetAccountBalancesNetworkIdEnum } from '@dynamic-labs/sdk-api-core';
|
|
5
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
6
|
+
import '../../../shared/logger.js';
|
|
7
|
+
import '@dynamic-labs/iconic';
|
|
8
|
+
import 'react/jsx-runtime';
|
|
9
|
+
import '../../../context/ViewContext/ViewContext.js';
|
|
10
|
+
import '@dynamic-labs/wallet-book';
|
|
11
|
+
import '../../constants/colors.js';
|
|
12
|
+
import '../../constants/values.js';
|
|
13
|
+
import '../../../shared/utils/classes/storage/localStorage.js';
|
|
14
|
+
import '@dynamic-labs/utils';
|
|
15
|
+
import '../../../shared/consts/index.js';
|
|
16
|
+
import '@dynamic-labs/multi-wallet';
|
|
17
|
+
import { getAuthToken } from '../../functions/getAuthToken/getAuthToken.js';
|
|
18
|
+
import 'react-international-phone';
|
|
19
|
+
import 'viem';
|
|
20
|
+
import 'viem/chains';
|
|
21
|
+
import '../../../config/ApiEndpoint.js';
|
|
22
|
+
import '../../../locale/locale.js';
|
|
23
|
+
import { getAccountTokenBalances } from '../../../data/api/chains/balances.js';
|
|
24
|
+
import '../../../context/DynamicContext/DynamicContext.js';
|
|
25
|
+
import '../../../events/dynamicEvents.js';
|
|
26
|
+
import '../../../context/CaptchaContext/CaptchaContext.js';
|
|
27
|
+
import '../../../context/ErrorContext/ErrorContext.js';
|
|
28
|
+
import '../../../context/AccessDeniedContext/AccessDeniedContext.js';
|
|
29
|
+
import '../../../context/AccountExistsContext/AccountExistsContext.js';
|
|
30
|
+
import '../../../context/UserWalletsContext/UserWalletsContext.js';
|
|
31
|
+
import '../../../context/VerificationContext/VerificationContext.js';
|
|
32
|
+
import 'react-dom';
|
|
33
|
+
import '../../../context/WalletContext/WalletContext.js';
|
|
34
|
+
import '../../../context/ThemeContext/ThemeContext.js';
|
|
35
|
+
import '@dynamic-labs/types';
|
|
36
|
+
import 'yup';
|
|
37
|
+
import '../../../context/MockContext/MockContext.js';
|
|
38
|
+
import 'react-i18next';
|
|
39
|
+
import '../../../context/FieldsStateContext/FieldsStateContext.js';
|
|
40
|
+
import '../useUserUpdateRequest/useUpdateUser/useUpdateUser.js';
|
|
41
|
+
import '../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
|
|
42
|
+
import '@dynamic-labs/rpc-providers';
|
|
43
|
+
import '../../../components/Alert/Alert.js';
|
|
44
|
+
import '../../../components/ShadowDOM/ShadowDOM.js';
|
|
45
|
+
import '../../../components/IconButton/IconButton.js';
|
|
46
|
+
import '../../../components/InlineWidget/InlineWidget.js';
|
|
47
|
+
import '../../../components/Input/Input.js';
|
|
48
|
+
import '../../../components/IsBrowser/IsBrowser.js';
|
|
49
|
+
import '../../../components/MenuList/Dropdown/Dropdown.js';
|
|
50
|
+
import '../../../components/Transition/ZoomTransition/ZoomTransition.js';
|
|
51
|
+
import '../../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
|
|
52
|
+
import '../../../components/Transition/OpacityTransition/OpacityTransition.js';
|
|
53
|
+
import '../../../components/OverlayCard/OverlayCardTarget/OverlayCardTarget.js';
|
|
54
|
+
import '../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js';
|
|
55
|
+
import '../../../components/Popper/Popper/Popper.js';
|
|
56
|
+
import '../../../components/Popper/PopperContext/PopperContext.js';
|
|
57
|
+
import 'react-focus-lock';
|
|
58
|
+
import 'qrcode';
|
|
59
|
+
import 'formik';
|
|
60
|
+
import '../../../views/WalletList/WalletList.js';
|
|
61
|
+
import '../../../context/SocialRedirectContext/SocialRedirectContext.js';
|
|
62
|
+
import '../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
|
|
63
|
+
import '@hcaptcha/react-hcaptcha';
|
|
64
|
+
import '../../../context/LoadingContext/LoadingContext.js';
|
|
65
|
+
import '../../../context/FooterAnimationContext/index.js';
|
|
66
|
+
import '../../../views/LoginView/sections/PhoneNumberSignInSection/PhoneNumberSignInSection.js';
|
|
67
|
+
import '../../../context/WalletGroupContext/WalletGroupContext.js';
|
|
68
|
+
import '../../../context/PasskeyContext/PasskeyContext.js';
|
|
69
|
+
import '../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js';
|
|
70
|
+
import '../../../widgets/DynamicWidget/context/DynamicWidgetContext.js';
|
|
71
|
+
import '../../../views/TransactionConfirmationView/helpers/transactionErrorMessage.js';
|
|
72
|
+
import '../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
|
|
73
|
+
import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.js';
|
|
74
|
+
|
|
75
|
+
// Hook exposed to customers and used internally to fetch account balances
|
|
76
|
+
const useTokenBalances = ({ accountAddress, networkId, chainName = ChainEnum.Evm, tokenAddresses, } = {}) => {
|
|
77
|
+
const [tokenBalancesData, setTokenBalancesData] = useState(undefined);
|
|
78
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
79
|
+
const [error, setError] = useState(undefined);
|
|
80
|
+
const { primaryWallet, environmentId, network, walletConnector } = useInternalDynamicContext();
|
|
81
|
+
const requestChainName = chainName !== null && chainName !== void 0 ? chainName : walletConnector === null || walletConnector === void 0 ? void 0 : walletConnector.connectedChain;
|
|
82
|
+
const requestAccount = accountAddress !== null && accountAddress !== void 0 ? accountAddress : primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address;
|
|
83
|
+
const requestNetwork = networkId !== null && networkId !== void 0 ? networkId : network;
|
|
84
|
+
const fetchAccountBalances = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
+
const jwt = getAuthToken();
|
|
86
|
+
if (!jwt) {
|
|
87
|
+
setError('User is not logged in');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (requestChainName !== ChainEnum.Evm) {
|
|
91
|
+
setError(`Chain ${requestChainName} is not supported for token balances`);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!isLoading &&
|
|
95
|
+
requestAccount &&
|
|
96
|
+
requestNetwork &&
|
|
97
|
+
Object.values(GetAccountBalancesNetworkIdEnum).includes(requestNetwork)) {
|
|
98
|
+
setIsLoading(true);
|
|
99
|
+
getAccountTokenBalances({
|
|
100
|
+
accountAddress: requestAccount,
|
|
101
|
+
chainName: requestChainName,
|
|
102
|
+
environmentId,
|
|
103
|
+
networkId: Number(requestNetwork),
|
|
104
|
+
userJwt: jwt,
|
|
105
|
+
})
|
|
106
|
+
.then((response) => {
|
|
107
|
+
if (response) {
|
|
108
|
+
setTokenBalancesData(response);
|
|
109
|
+
setError(undefined);
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
.catch((e) => {
|
|
113
|
+
setError(e.message);
|
|
114
|
+
})
|
|
115
|
+
.finally(() => {
|
|
116
|
+
setIsLoading(false);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}), [
|
|
120
|
+
isLoading,
|
|
121
|
+
requestAccount,
|
|
122
|
+
requestNetwork,
|
|
123
|
+
requestChainName,
|
|
124
|
+
environmentId,
|
|
125
|
+
]);
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
fetchAccountBalances();
|
|
128
|
+
}, [requestAccount, requestNetwork]);
|
|
129
|
+
let tokenBalances = tokenBalancesData;
|
|
130
|
+
if (tokenAddresses) {
|
|
131
|
+
const lowerTokenAddresses = tokenAddresses === null || tokenAddresses === void 0 ? void 0 : tokenAddresses.map((address) => address.toLowerCase());
|
|
132
|
+
tokenBalances = tokenBalancesData === null || tokenBalancesData === void 0 ? void 0 : tokenBalancesData.filter((token) => lowerTokenAddresses === null || lowerTokenAddresses === void 0 ? void 0 : lowerTokenAddresses.includes(token.address.toLowerCase()));
|
|
133
|
+
}
|
|
134
|
+
return { error, isError: Boolean(error), isLoading, tokenBalances };
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export { useTokenBalances };
|
|
@@ -43,6 +43,7 @@ require('../../../context/VerificationContext/VerificationContext.cjs');
|
|
|
43
43
|
require('react-dom');
|
|
44
44
|
require('../../../context/WalletContext/WalletContext.cjs');
|
|
45
45
|
var useIsTurnkeyWallet = require('../../../utils/hooks/useIsTurnkeyWallet/useIsTurnkeyWallet.cjs');
|
|
46
|
+
var turnkeyExport = require('../utils/turnkeyExport/turnkeyExport.cjs');
|
|
46
47
|
var usePromise = require('../../../utils/hooks/usePromise/usePromise.cjs');
|
|
47
48
|
require('../../../context/ThemeContext/ThemeContext.cjs');
|
|
48
49
|
var useMutation = require('../../../utils/hooks/useMutation/useMutation.cjs');
|
|
@@ -88,7 +89,6 @@ require('qrcode');
|
|
|
88
89
|
require('../../WalletList/WalletList.cjs');
|
|
89
90
|
require('../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
|
|
90
91
|
require('@hcaptcha/react-hcaptcha');
|
|
91
|
-
var turnkeyExport = require('../utils/turnkeyExport/turnkeyExport.cjs');
|
|
92
92
|
var constants = require('../constants.cjs');
|
|
93
93
|
require('../../LoginView/sections/PhoneNumberSignInSection/PhoneNumberSignInSection.cjs');
|
|
94
94
|
|
|
@@ -39,6 +39,7 @@ import '../../../context/VerificationContext/VerificationContext.js';
|
|
|
39
39
|
import 'react-dom';
|
|
40
40
|
import '../../../context/WalletContext/WalletContext.js';
|
|
41
41
|
import { useIsTurnkeyWallet } from '../../../utils/hooks/useIsTurnkeyWallet/useIsTurnkeyWallet.js';
|
|
42
|
+
import { cleanupExport, exportCredential, initExport } from '../utils/turnkeyExport/turnkeyExport.js';
|
|
42
43
|
import { usePromise } from '../../../utils/hooks/usePromise/usePromise.js';
|
|
43
44
|
import '../../../context/ThemeContext/ThemeContext.js';
|
|
44
45
|
import { useMutation } from '../../../utils/hooks/useMutation/useMutation.js';
|
|
@@ -84,7 +85,6 @@ import 'qrcode';
|
|
|
84
85
|
import '../../WalletList/WalletList.js';
|
|
85
86
|
import '../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
|
|
86
87
|
import '@hcaptcha/react-hcaptcha';
|
|
87
|
-
import { cleanupExport, exportCredential, initExport } from '../utils/turnkeyExport/turnkeyExport.js';
|
|
88
88
|
import { iframeContainerId, iframeElementId } from '../constants.js';
|
|
89
89
|
import '../../LoginView/sections/PhoneNumberSignInSection/PhoneNumberSignInSection.js';
|
|
90
90
|
|
|
@@ -21,18 +21,19 @@ require('../../../../shared/consts/index.cjs');
|
|
|
21
21
|
require('../../../../config/ApiEndpoint.cjs');
|
|
22
22
|
var embeddedWallets = require('../../../../data/api/embeddedWallets/embeddedWallets.cjs');
|
|
23
23
|
require('../../../../locale/locale.cjs');
|
|
24
|
+
var errors = require('../../../../utils/constants/errors.cjs');
|
|
24
25
|
|
|
25
26
|
const initExport = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ iframeContainer, iframeElementId, wallet, }) {
|
|
26
27
|
var _b;
|
|
27
28
|
if (!(wallet === null || wallet === void 0 ? void 0 : wallet.connector) ||
|
|
28
29
|
!(wallet === null || wallet === void 0 ? void 0 : wallet.id) ||
|
|
29
30
|
!walletConnectorCore.isPasskeyWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
|
|
30
|
-
throw new utils.DynamicError('Connector is missing. Please make sure you added EthereumWalletConnectors and/or SolanaWalletConnectors to DynamicProvider settings');
|
|
31
|
+
throw new utils.DynamicError('Connector is missing. Please make sure you added EthereumWalletConnectors and/or SolanaWalletConnectors to DynamicProvider settings', errors.INVALID_WALLET_DATA);
|
|
31
32
|
}
|
|
32
33
|
const turnkeyExportHandler = (_b = wallet.connector) === null || _b === void 0 ? void 0 : _b.getExportHandler();
|
|
33
34
|
const publicKey = yield turnkeyExportHandler.initExport(iframeContainer, iframeElementId);
|
|
34
35
|
if (!publicKey) {
|
|
35
|
-
throw new utils.DynamicError('Something went wrong');
|
|
36
|
+
throw new utils.DynamicError('Something went wrong', errors.ERROR_PROCESSING_REVEAL_REQUEST);
|
|
36
37
|
}
|
|
37
38
|
return turnkeyExportHandler;
|
|
38
39
|
});
|
|
@@ -86,7 +87,7 @@ const exportCredential = (_c) => _tslib.__awaiter(void 0, [_c], void 0, function
|
|
|
86
87
|
const turnkeyExportHandler = connector.getExportHandler();
|
|
87
88
|
const targetPublicKey = turnkeyExportHandler.publicKey;
|
|
88
89
|
if (!targetPublicKey) {
|
|
89
|
-
throw new utils.DynamicError('Must initialize export first');
|
|
90
|
+
throw new utils.DynamicError('Must initialize export first', errors.ERROR_PROCESSING_REVEAL_REQUEST);
|
|
90
91
|
}
|
|
91
92
|
// calls turnkey export api
|
|
92
93
|
let newActivity;
|
|
@@ -123,7 +124,7 @@ const exportCredential = (_c) => _tslib.__awaiter(void 0, [_c], void 0, function
|
|
|
123
124
|
exportBundle = res === null || res === void 0 ? void 0 : res.exportBundle;
|
|
124
125
|
}
|
|
125
126
|
if (!exportBundle) {
|
|
126
|
-
throw new utils.DynamicError('Invalid export response');
|
|
127
|
+
throw new utils.DynamicError('Invalid export response', errors.ERROR_PROCESSING_REVEAL_REQUEST);
|
|
127
128
|
}
|
|
128
129
|
if (address || privateKeyId) {
|
|
129
130
|
return turnkeyExportHandler.verifyExportPrivateKey(exportBundle);
|