@dynamic-labs/sdk-react-core 4.19.6 → 4.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/package.cjs +2 -1
- package/package.js +2 -1
- package/package.json +12 -11
- package/src/functions.d.ts +1 -0
- package/src/lib/client/client.cjs +19 -0
- package/src/lib/client/client.d.ts +8 -0
- package/src/lib/client/client.js +11 -0
- package/src/lib/client/extension/constants.cjs +12 -0
- package/src/lib/client/extension/constants.d.ts +5 -0
- package/src/lib/client/extension/constants.js +8 -0
- package/src/lib/client/extension/index.d.ts +1 -0
- package/src/lib/client/extension/useInitializeSdkClient/fetchOverride/MockedFetchError.cjs +14 -0
- package/src/lib/client/extension/useInitializeSdkClient/fetchOverride/MockedFetchError.d.ts +4 -0
- package/src/lib/client/extension/useInitializeSdkClient/fetchOverride/MockedFetchError.js +10 -0
- package/src/lib/client/extension/useInitializeSdkClient/fetchOverride/fetchOverride.cjs +29 -0
- package/src/lib/client/extension/useInitializeSdkClient/fetchOverride/fetchOverride.d.ts +7 -0
- package/src/lib/client/extension/useInitializeSdkClient/fetchOverride/fetchOverride.js +25 -0
- package/src/lib/client/extension/useInitializeSdkClient/fetchOverride/index.d.ts +1 -0
- package/src/lib/client/extension/useInitializeSdkClient/index.d.ts +1 -0
- package/src/lib/client/extension/useInitializeSdkClient/useInitializeSdkClient.cjs +30 -0
- package/src/lib/client/extension/useInitializeSdkClient/useInitializeSdkClient.d.ts +2 -0
- package/src/lib/client/extension/useInitializeSdkClient/useInitializeSdkClient.js +26 -0
- package/src/lib/client/extension/utils/useClientState/index.d.ts +1 -0
- package/src/lib/client/extension/utils/useClientState/useClientState.d.ts +2 -0
- package/src/lib/context/DynamicContext/DynamicContext.cjs +3 -0
- package/src/lib/context/DynamicContext/DynamicContext.js +3 -0
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/functions/getSessionInformation/getSessionInformation.cjs +13 -2
- package/src/lib/utils/functions/getSessionInformation/getSessionInformation.d.ts +2 -0
- package/src/lib/utils/functions/getSessionInformation/getSessionInformation.js +13 -2
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/unsetInitialWalletVerificationFlag/unsetInitialWalletVerificationFlag.cjs +9 -6
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/unsetInitialWalletVerificationFlag/unsetInitialWalletVerificationFlag.d.ts +8 -0
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/unsetInitialWalletVerificationFlag/unsetInitialWalletVerificationFlag.js +8 -7
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +3 -2
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +4 -3
- package/src/lib/utils/hooks/useDynamicWaas/constants.cjs +2 -0
- package/src/lib/utils/hooks/useDynamicWaas/constants.d.ts +1 -0
- package/src/lib/utils/hooks/useDynamicWaas/constants.js +2 -1
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.cjs +11 -3
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.d.ts +4 -2
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.js +12 -4
- package/src/lib/utils/types/SessionInformation.d.ts +6 -1
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.cjs +15 -88
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.js +15 -88
|
@@ -20,8 +20,19 @@ const getSessionInformationExpiration = (session) => {
|
|
|
20
20
|
};
|
|
21
21
|
/** Returns the spending limit of the session in ETH */
|
|
22
22
|
const getSessionInformationSpendingLimit = (session) => {
|
|
23
|
-
|
|
24
|
-
const
|
|
23
|
+
var _a, _b;
|
|
24
|
+
const policies = session.session.transferPolicies;
|
|
25
|
+
if (!policies) {
|
|
26
|
+
return '0 ETH';
|
|
27
|
+
}
|
|
28
|
+
let limit = BigInt(0);
|
|
29
|
+
for (const policy of policies) {
|
|
30
|
+
limit += (_b = (_a = policy.valueLimit) === null || _a === void 0 ? void 0 : _a.limit) !== null && _b !== void 0 ? _b : BigInt(0);
|
|
31
|
+
}
|
|
32
|
+
const formatter = new Intl.NumberFormat(undefined, {
|
|
33
|
+
maximumFractionDigits: 6,
|
|
34
|
+
});
|
|
35
|
+
const ethString = formatter.format(Number(limit) / Math.pow(10, 18));
|
|
25
36
|
return `~${ethString} ETH`;
|
|
26
37
|
};
|
|
27
38
|
/** Exports the session information as a JSON string with a helper to process bigints */
|
|
@@ -7,5 +7,7 @@ export declare const getSessionInformationTimeSinceCreation: (session: SessionIn
|
|
|
7
7
|
export declare const getSessionInformationExpiration: (session: SessionInformation) => string;
|
|
8
8
|
/** Returns the spending limit of the session in ETH */
|
|
9
9
|
export declare const getSessionInformationSpendingLimit: (session: SessionInformation) => string;
|
|
10
|
+
/** Returns the fee limit of the session in ETH */
|
|
11
|
+
export declare const getSessionInformationFeeLimit: (session: SessionInformation) => string;
|
|
10
12
|
/** Exports the session information as a JSON string with a helper to process bigints */
|
|
11
13
|
export declare const getSessionInformationJson: (session: SessionInformation) => string;
|
|
@@ -16,8 +16,19 @@ const getSessionInformationExpiration = (session) => {
|
|
|
16
16
|
};
|
|
17
17
|
/** Returns the spending limit of the session in ETH */
|
|
18
18
|
const getSessionInformationSpendingLimit = (session) => {
|
|
19
|
-
|
|
20
|
-
const
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const policies = session.session.transferPolicies;
|
|
21
|
+
if (!policies) {
|
|
22
|
+
return '0 ETH';
|
|
23
|
+
}
|
|
24
|
+
let limit = BigInt(0);
|
|
25
|
+
for (const policy of policies) {
|
|
26
|
+
limit += (_b = (_a = policy.valueLimit) === null || _a === void 0 ? void 0 : _a.limit) !== null && _b !== void 0 ? _b : BigInt(0);
|
|
27
|
+
}
|
|
28
|
+
const formatter = new Intl.NumberFormat(undefined, {
|
|
29
|
+
maximumFractionDigits: 6,
|
|
30
|
+
});
|
|
31
|
+
const ethString = formatter.format(Number(limit) / Math.pow(10, 18));
|
|
21
32
|
return `~${ethString} ETH`;
|
|
22
33
|
};
|
|
23
34
|
/** Exports the session information as a JSON string with a helper to process bigints */
|
|
@@ -14,13 +14,16 @@ var loadingAndLifecycle = require('../../../../../store/state/loadingAndLifecycl
|
|
|
14
14
|
*/
|
|
15
15
|
const UNSET_TIMEOUT = 5500;
|
|
16
16
|
const unsetInitialWalletVerificationFlag = () => {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
loadingAndLifecycle.setIsInitialWalletVerificationInProgress(false);
|
|
18
|
+
};
|
|
19
|
+
const unsetInitialWalletVerificationFlagWithTimeout = () => {
|
|
20
|
+
const timeout = setTimeout(() => {
|
|
21
|
+
unsetInitialWalletVerificationFlag();
|
|
19
22
|
clearTimeout(timeout);
|
|
20
|
-
dynamicEvents.dynamicEvents.removeListener('walletAdded',
|
|
21
|
-
};
|
|
22
|
-
const timeout = setTimeout(resolve, UNSET_TIMEOUT);
|
|
23
|
-
dynamicEvents.dynamicEvents.once('walletAdded', resolve);
|
|
23
|
+
dynamicEvents.dynamicEvents.removeListener('walletAdded', unsetInitialWalletVerificationFlag);
|
|
24
|
+
}, UNSET_TIMEOUT);
|
|
24
25
|
};
|
|
25
26
|
|
|
27
|
+
exports.UNSET_TIMEOUT = UNSET_TIMEOUT;
|
|
26
28
|
exports.unsetInitialWalletVerificationFlag = unsetInitialWalletVerificationFlag;
|
|
29
|
+
exports.unsetInitialWalletVerificationFlagWithTimeout = unsetInitialWalletVerificationFlagWithTimeout;
|
|
@@ -1 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The max time the SDK will wait before unsetting the initial wallet verification flag.
|
|
3
|
+
* If the corresponding walletAdded event is triggered before this timeout, the flag will be unset immediately.
|
|
4
|
+
*
|
|
5
|
+
* See justification for this in comments where it is being called.
|
|
6
|
+
*/
|
|
7
|
+
export declare const UNSET_TIMEOUT = 5500;
|
|
1
8
|
export declare const unsetInitialWalletVerificationFlag: () => void;
|
|
9
|
+
export declare const unsetInitialWalletVerificationFlagWithTimeout: () => void;
|
|
@@ -10,13 +10,14 @@ import { setIsInitialWalletVerificationInProgress } from '../../../../../store/s
|
|
|
10
10
|
*/
|
|
11
11
|
const UNSET_TIMEOUT = 5500;
|
|
12
12
|
const unsetInitialWalletVerificationFlag = () => {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
setIsInitialWalletVerificationInProgress(false);
|
|
14
|
+
};
|
|
15
|
+
const unsetInitialWalletVerificationFlagWithTimeout = () => {
|
|
16
|
+
const timeout = setTimeout(() => {
|
|
17
|
+
unsetInitialWalletVerificationFlag();
|
|
15
18
|
clearTimeout(timeout);
|
|
16
|
-
dynamicEvents.removeListener('walletAdded',
|
|
17
|
-
};
|
|
18
|
-
const timeout = setTimeout(resolve, UNSET_TIMEOUT);
|
|
19
|
-
dynamicEvents.once('walletAdded', resolve);
|
|
19
|
+
dynamicEvents.removeListener('walletAdded', unsetInitialWalletVerificationFlag);
|
|
20
|
+
}, UNSET_TIMEOUT);
|
|
20
21
|
};
|
|
21
22
|
|
|
22
|
-
export { unsetInitialWalletVerificationFlag };
|
|
23
|
+
export { UNSET_TIMEOUT, unsetInitialWalletVerificationFlag, unsetInitialWalletVerificationFlagWithTimeout };
|
|
@@ -20,7 +20,7 @@ var localStorage = require('../../../constants/localStorage.cjs');
|
|
|
20
20
|
require('../../../constants/colors.cjs');
|
|
21
21
|
require('../../../constants/values.cjs');
|
|
22
22
|
require('../../../../shared/consts/index.cjs');
|
|
23
|
-
require('../../../../events/dynamicEvents.cjs');
|
|
23
|
+
var dynamicEvents = require('../../../../events/dynamicEvents.cjs');
|
|
24
24
|
var ErrorContext = require('../../../../context/ErrorContext/ErrorContext.cjs');
|
|
25
25
|
require('@dynamic-labs/multi-wallet');
|
|
26
26
|
require('react-international-phone');
|
|
@@ -161,6 +161,7 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
161
161
|
// Lock the variable that indicates that the login wallet verification is in progress
|
|
162
162
|
// Read UserWalletsContext.tsx explanation for more context
|
|
163
163
|
loadingAndLifecycle.setIsInitialWalletVerificationInProgress(true);
|
|
164
|
+
dynamicEvents.dynamicEvents.once('walletAdded', unsetInitialWalletVerificationFlag.unsetInitialWalletVerificationFlag);
|
|
164
165
|
yield showPendingConnectView.showPendingConnectView(walletConnector, pushView);
|
|
165
166
|
if (walletConnectorCore.isEmailWalletConnector(walletConnector)) {
|
|
166
167
|
if (walletConnectorCore.isEmailOTPWalletConnector(walletConnector)) {
|
|
@@ -238,7 +239,7 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
238
239
|
// 2. Add a useEffect somewhere that does primaryWallet.switchNetwork() and depends on primaryWallet
|
|
239
240
|
// 3. The SDK will enter a broken state. Try signing a message with wagmi.
|
|
240
241
|
// You can also add a "pause on exception" breakpoint in the debugger and see what happens during verification.
|
|
241
|
-
unsetInitialWalletVerificationFlag.
|
|
242
|
+
unsetInitialWalletVerificationFlag.unsetInitialWalletVerificationFlagWithTimeout();
|
|
242
243
|
}
|
|
243
244
|
});
|
|
244
245
|
};
|
|
@@ -16,7 +16,7 @@ import { LAST_USED_WALLET } from '../../../constants/localStorage.js';
|
|
|
16
16
|
import '../../../constants/colors.js';
|
|
17
17
|
import '../../../constants/values.js';
|
|
18
18
|
import '../../../../shared/consts/index.js';
|
|
19
|
-
import '../../../../events/dynamicEvents.js';
|
|
19
|
+
import { dynamicEvents } from '../../../../events/dynamicEvents.js';
|
|
20
20
|
import { useErrorContext } from '../../../../context/ErrorContext/ErrorContext.js';
|
|
21
21
|
import '@dynamic-labs/multi-wallet';
|
|
22
22
|
import 'react-international-phone';
|
|
@@ -34,7 +34,7 @@ import { useHandleWalletsToConnect } from '../../useHandleWalletsToConnect/useHa
|
|
|
34
34
|
import { useVerifyWallet } from '../../useVerifyWallet/useVerifyWallet.js';
|
|
35
35
|
import { showPendingConnectView } from '../helpers/showPendingConnectView.js';
|
|
36
36
|
import { isConnectOnly } from '../helpers/isConnectOnly.js';
|
|
37
|
-
import { unsetInitialWalletVerificationFlag } from './unsetInitialWalletVerificationFlag/unsetInitialWalletVerificationFlag.js';
|
|
37
|
+
import { unsetInitialWalletVerificationFlag, unsetInitialWalletVerificationFlagWithTimeout } from './unsetInitialWalletVerificationFlag/unsetInitialWalletVerificationFlag.js';
|
|
38
38
|
import '../../../../context/VerificationContext/VerificationContext.js';
|
|
39
39
|
import 'react-dom';
|
|
40
40
|
import '../../../functions/compareChains/compareChains.js';
|
|
@@ -157,6 +157,7 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
157
157
|
// Lock the variable that indicates that the login wallet verification is in progress
|
|
158
158
|
// Read UserWalletsContext.tsx explanation for more context
|
|
159
159
|
setIsInitialWalletVerificationInProgress(true);
|
|
160
|
+
dynamicEvents.once('walletAdded', unsetInitialWalletVerificationFlag);
|
|
160
161
|
yield showPendingConnectView(walletConnector, pushView);
|
|
161
162
|
if (isEmailWalletConnector(walletConnector)) {
|
|
162
163
|
if (isEmailOTPWalletConnector(walletConnector)) {
|
|
@@ -234,7 +235,7 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
234
235
|
// 2. Add a useEffect somewhere that does primaryWallet.switchNetwork() and depends on primaryWallet
|
|
235
236
|
// 3. The SDK will enter a broken state. Try signing a message with wagmi.
|
|
236
237
|
// You can also add a "pause on exception" breakpoint in the debugger and see what happens during verification.
|
|
237
|
-
|
|
238
|
+
unsetInitialWalletVerificationFlagWithTimeout();
|
|
238
239
|
}
|
|
239
240
|
});
|
|
240
241
|
};
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
const NO_ENABLED_CHAINS_ERROR = 'No enabled embedded wallet chains';
|
|
7
7
|
const DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR = 'Dynamic Waas connector not found';
|
|
8
|
+
const INVALID_CHAINS_ERROR = 'The following chains are not enabled for embedded wallets';
|
|
8
9
|
|
|
9
10
|
exports.DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR = DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR;
|
|
11
|
+
exports.INVALID_CHAINS_ERROR = INVALID_CHAINS_ERROR;
|
|
10
12
|
exports.NO_ENABLED_CHAINS_ERROR = NO_ENABLED_CHAINS_ERROR;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare const NO_ENABLED_CHAINS_ERROR = "No enabled embedded wallet chains";
|
|
2
2
|
export declare const DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR = "Dynamic Waas connector not found";
|
|
3
|
+
export declare const INVALID_CHAINS_ERROR = "The following chains are not enabled for embedded wallets";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
const NO_ENABLED_CHAINS_ERROR = 'No enabled embedded wallet chains';
|
|
3
3
|
const DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR = 'Dynamic Waas connector not found';
|
|
4
|
+
const INVALID_CHAINS_ERROR = 'The following chains are not enabled for embedded wallets';
|
|
4
5
|
|
|
5
|
-
export { DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR, NO_ENABLED_CHAINS_ERROR };
|
|
6
|
+
export { DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR, INVALID_CHAINS_ERROR, NO_ENABLED_CHAINS_ERROR };
|
|
@@ -7,6 +7,7 @@ var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
9
9
|
var utils = require('@dynamic-labs/utils');
|
|
10
|
+
var UserWalletsContext = require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
|
|
10
11
|
require('../../constants/values.cjs');
|
|
11
12
|
require('@dynamic-labs/multi-wallet');
|
|
12
13
|
var getAuthToken = require('../../functions/getAuthToken/getAuthToken.cjs');
|
|
@@ -36,7 +37,6 @@ require('../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
|
36
37
|
require('../../../context/ErrorContext/ErrorContext.cjs');
|
|
37
38
|
require('../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
38
39
|
require('../../../context/AccountExistsContext/AccountExistsContext.cjs');
|
|
39
|
-
require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
|
|
40
40
|
require('../../../config/ApiEndpoint.cjs');
|
|
41
41
|
require('../../../locale/locale.cjs');
|
|
42
42
|
require('../../../store/state/authMode/authMode.cjs');
|
|
@@ -122,6 +122,7 @@ const useDynamicWaas = () => {
|
|
|
122
122
|
const walletConnectorOptions = walletOptions.useWalletConnectorOptions();
|
|
123
123
|
const refresh = useRefreshUser.useRefreshUser();
|
|
124
124
|
const relayUrl = (_b = (_a = projectSettings$1 === null || projectSettings$1 === void 0 ? void 0 : projectSettings$1.sdk) === null || _a === void 0 ? void 0 : _a.waas) === null || _b === void 0 ? void 0 : _b.relayUrl;
|
|
125
|
+
const userWallets = UserWalletsContext.useUserWallets();
|
|
125
126
|
const embeddedWalletSettings = projectSettings$1 === null || projectSettings$1 === void 0 ? void 0 : projectSettings$1.sdk.embeddedWallets;
|
|
126
127
|
const enabledChains = (_c = embeddedWalletSettings === null || embeddedWalletSettings === void 0 ? void 0 : embeddedWalletSettings.chainConfigurations) === null || _c === void 0 ? void 0 : _c.filter((c) => c.enabled);
|
|
127
128
|
const primaryChain = enabledChains === null || enabledChains === void 0 ? void 0 : enabledChains.find((chain) => chain.primary);
|
|
@@ -159,11 +160,16 @@ const useDynamicWaas = () => {
|
|
|
159
160
|
apiBaseUrl,
|
|
160
161
|
isCookieAuthEnabled,
|
|
161
162
|
]);
|
|
162
|
-
const createWalletAccount = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
163
|
+
const createWalletAccount = React.useCallback((chainNames) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
163
164
|
if (!(enabledChainNames === null || enabledChainNames === void 0 ? void 0 : enabledChainNames.length)) {
|
|
164
165
|
throw new utils.DynamicError(constants.NO_ENABLED_CHAINS_ERROR);
|
|
165
166
|
}
|
|
166
|
-
const
|
|
167
|
+
const invalidChains = chainNames === null || chainNames === void 0 ? void 0 : chainNames.filter((chain) => !enabledChainNames.includes(chain));
|
|
168
|
+
if (invalidChains && invalidChains.length) {
|
|
169
|
+
throw new utils.DynamicError(`${constants.INVALID_CHAINS_ERROR}: ${invalidChains.join(', ')}`);
|
|
170
|
+
}
|
|
171
|
+
const chainsToCreate = chainNames ? chainNames : enabledChainNames;
|
|
172
|
+
const createdWalletAccounts = yield Promise.all(chainsToCreate === null || chainsToCreate === void 0 ? void 0 : chainsToCreate.map((chain) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
167
173
|
const walletConnector = getWalletConnector(chain);
|
|
168
174
|
if (!walletConnector)
|
|
169
175
|
return undefined;
|
|
@@ -225,9 +231,11 @@ const useDynamicWaas = () => {
|
|
|
225
231
|
});
|
|
226
232
|
yield refresh();
|
|
227
233
|
});
|
|
234
|
+
const getWaasWallets = React.useCallback(() => userWallets.filter((w) => w.key === 'dynamicwaas'), [userWallets]);
|
|
228
235
|
return {
|
|
229
236
|
createWalletAccount,
|
|
230
237
|
dynamicWaasIsEnabled,
|
|
238
|
+
getWaasWallets,
|
|
231
239
|
getWalletConnector,
|
|
232
240
|
importPrivateKey,
|
|
233
241
|
shouldAutoCreateDynamicWaasWallet,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IDynamicWaasConnector } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { ChainEnum } from '@dynamic-labs/sdk-api-core';
|
|
2
3
|
export declare const configWaasWalletConnector: ({ walletConnector, environmentId, apiBaseUrl, authToken, relayUrl, }: {
|
|
3
4
|
walletConnector: IDynamicWaasConnector;
|
|
4
5
|
environmentId: string;
|
|
@@ -7,16 +8,17 @@ export declare const configWaasWalletConnector: ({ walletConnector, environmentI
|
|
|
7
8
|
relayUrl: string;
|
|
8
9
|
}) => IDynamicWaasConnector;
|
|
9
10
|
export declare const useDynamicWaas: () => {
|
|
10
|
-
createWalletAccount: () => Promise<({
|
|
11
|
+
createWalletAccount: (chainNames?: ChainEnum[]) => Promise<({
|
|
11
12
|
chainName: string;
|
|
12
13
|
accountAddress: string;
|
|
13
14
|
publicKeyHex: string;
|
|
14
15
|
rawPublicKey: string | Uint8Array | undefined;
|
|
15
16
|
} | undefined)[]>;
|
|
16
17
|
dynamicWaasIsEnabled: boolean;
|
|
18
|
+
getWaasWallets: () => import("@dynamic-labs/wallet-connector-core").Wallet<import("@dynamic-labs/wallet-connector-core").WalletConnectorCore.WalletConnector>[];
|
|
17
19
|
getWalletConnector: (chainName: string) => IDynamicWaasConnector | undefined;
|
|
18
20
|
importPrivateKey: ({ chainName, privateKey, }: {
|
|
19
|
-
chainName:
|
|
21
|
+
chainName: ChainEnum;
|
|
20
22
|
privateKey: string;
|
|
21
23
|
}) => Promise<void>;
|
|
22
24
|
shouldAutoCreateDynamicWaasWallet: boolean | undefined;
|
|
@@ -3,6 +3,7 @@ import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
|
3
3
|
import { useCallback, useMemo } from 'react';
|
|
4
4
|
import { EmbeddedWalletVersionEnum, JwtVerifiedCredentialFormatEnum, WalletProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
5
5
|
import { DynamicError } from '@dynamic-labs/utils';
|
|
6
|
+
import { useUserWallets } from '../../../context/UserWalletsContext/UserWalletsContext.js';
|
|
6
7
|
import '../../constants/values.js';
|
|
7
8
|
import '@dynamic-labs/multi-wallet';
|
|
8
9
|
import { getAuthToken } from '../../functions/getAuthToken/getAuthToken.js';
|
|
@@ -32,7 +33,6 @@ import '../../../context/CaptchaContext/CaptchaContext.js';
|
|
|
32
33
|
import '../../../context/ErrorContext/ErrorContext.js';
|
|
33
34
|
import '../../../context/AccessDeniedContext/AccessDeniedContext.js';
|
|
34
35
|
import '../../../context/AccountExistsContext/AccountExistsContext.js';
|
|
35
|
-
import '../../../context/UserWalletsContext/UserWalletsContext.js';
|
|
36
36
|
import '../../../config/ApiEndpoint.js';
|
|
37
37
|
import '../../../locale/locale.js';
|
|
38
38
|
import '../../../store/state/authMode/authMode.js';
|
|
@@ -94,7 +94,7 @@ import '../../../context/OnrampContext/OnrampContext.js';
|
|
|
94
94
|
import '../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.js';
|
|
95
95
|
import '../../../../index.js';
|
|
96
96
|
import { DEFAULT_WAAS_API_URL } from '../../constants/waas/apiUrl.js';
|
|
97
|
-
import { DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR, NO_ENABLED_CHAINS_ERROR } from './constants.js';
|
|
97
|
+
import { DYNAMIC_WAAS_CONNECTOR_NOT_FOUND_ERROR, NO_ENABLED_CHAINS_ERROR, INVALID_CHAINS_ERROR } from './constants.js';
|
|
98
98
|
import '../../../store/state/tokenBalances.js';
|
|
99
99
|
import '../../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
|
|
100
100
|
import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js';
|
|
@@ -118,6 +118,7 @@ const useDynamicWaas = () => {
|
|
|
118
118
|
const walletConnectorOptions = useWalletConnectorOptions();
|
|
119
119
|
const refresh = useRefreshUser();
|
|
120
120
|
const relayUrl = (_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _a === void 0 ? void 0 : _a.waas) === null || _b === void 0 ? void 0 : _b.relayUrl;
|
|
121
|
+
const userWallets = useUserWallets();
|
|
121
122
|
const embeddedWalletSettings = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets;
|
|
122
123
|
const enabledChains = (_c = embeddedWalletSettings === null || embeddedWalletSettings === void 0 ? void 0 : embeddedWalletSettings.chainConfigurations) === null || _c === void 0 ? void 0 : _c.filter((c) => c.enabled);
|
|
123
124
|
const primaryChain = enabledChains === null || enabledChains === void 0 ? void 0 : enabledChains.find((chain) => chain.primary);
|
|
@@ -155,11 +156,16 @@ const useDynamicWaas = () => {
|
|
|
155
156
|
apiBaseUrl,
|
|
156
157
|
isCookieAuthEnabled,
|
|
157
158
|
]);
|
|
158
|
-
const createWalletAccount = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
159
|
+
const createWalletAccount = useCallback((chainNames) => __awaiter(void 0, void 0, void 0, function* () {
|
|
159
160
|
if (!(enabledChainNames === null || enabledChainNames === void 0 ? void 0 : enabledChainNames.length)) {
|
|
160
161
|
throw new DynamicError(NO_ENABLED_CHAINS_ERROR);
|
|
161
162
|
}
|
|
162
|
-
const
|
|
163
|
+
const invalidChains = chainNames === null || chainNames === void 0 ? void 0 : chainNames.filter((chain) => !enabledChainNames.includes(chain));
|
|
164
|
+
if (invalidChains && invalidChains.length) {
|
|
165
|
+
throw new DynamicError(`${INVALID_CHAINS_ERROR}: ${invalidChains.join(', ')}`);
|
|
166
|
+
}
|
|
167
|
+
const chainsToCreate = chainNames ? chainNames : enabledChainNames;
|
|
168
|
+
const createdWalletAccounts = yield Promise.all(chainsToCreate === null || chainsToCreate === void 0 ? void 0 : chainsToCreate.map((chain) => __awaiter(void 0, void 0, void 0, function* () {
|
|
163
169
|
const walletConnector = getWalletConnector(chain);
|
|
164
170
|
if (!walletConnector)
|
|
165
171
|
return undefined;
|
|
@@ -221,9 +227,11 @@ const useDynamicWaas = () => {
|
|
|
221
227
|
});
|
|
222
228
|
yield refresh();
|
|
223
229
|
});
|
|
230
|
+
const getWaasWallets = useCallback(() => userWallets.filter((w) => w.key === 'dynamicwaas'), [userWallets]);
|
|
224
231
|
return {
|
|
225
232
|
createWalletAccount,
|
|
226
233
|
dynamicWaasIsEnabled,
|
|
234
|
+
getWaasWallets,
|
|
227
235
|
getWalletConnector,
|
|
228
236
|
importPrivateKey,
|
|
229
237
|
shouldAutoCreateDynamicWaasWallet,
|
|
@@ -11,7 +11,7 @@ export type SessionConfig = {
|
|
|
11
11
|
expiresAt: bigint;
|
|
12
12
|
feeLimit: Limit;
|
|
13
13
|
callPolicies: unknown[];
|
|
14
|
-
transferPolicies:
|
|
14
|
+
transferPolicies: TransferPolicy[];
|
|
15
15
|
};
|
|
16
16
|
export type Limit = {
|
|
17
17
|
limitType: LimitType;
|
|
@@ -23,3 +23,8 @@ export declare enum LimitType {
|
|
|
23
23
|
Lifetime = 1,
|
|
24
24
|
Allowance = 2
|
|
25
25
|
}
|
|
26
|
+
export type TransferPolicy = {
|
|
27
|
+
target: string;
|
|
28
|
+
maxValuePerUse: bigint;
|
|
29
|
+
valueLimit: Limit;
|
|
30
|
+
};
|
|
@@ -120,16 +120,11 @@ require('../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
|
|
|
120
120
|
var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
|
|
121
121
|
|
|
122
122
|
const EmbeddedRevealView = ({ exportPrivateKey, isPromptForExport = false, }) => {
|
|
123
|
-
var _a, _b, _c
|
|
123
|
+
var _a, _b, _c;
|
|
124
124
|
const { primaryWallet, user, setShowAuthFlow, environmentId } = useInternalDynamicContext.useInternalDynamicContext();
|
|
125
125
|
const { handleAcknowledgeExportPrompt } = useSyncEmbeddedWalletFlow.useSyncEmbeddedWalletFlow();
|
|
126
126
|
const { isTurnkeyWallet } = useIsTurnkeyWallet.useIsTurnkeyWallet();
|
|
127
|
-
//should use useIsWaasWallet hook
|
|
128
127
|
const isWaasWallet = user === null || user === void 0 ? void 0 : user.verifiedCredentials.find((vc) => { var _a; return (_a = vc.walletName) === null || _a === void 0 ? void 0 : _a.startsWith('dynamicwaas'); });
|
|
129
|
-
// Check if it's a Sui wallet
|
|
130
|
-
const isSuiWallet = ((_a = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector) === null || _a === void 0 ? void 0 : _a.connectedChain) === 'SUI';
|
|
131
|
-
// Check if it's a SOL wallet
|
|
132
|
-
const isSolWallet = ((_b = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector) === null || _b === void 0 ? void 0 : _b.connectedChain) === 'SOL';
|
|
133
128
|
const { setDynamicWidgetView } = DynamicWidgetContext.useWidgetContext();
|
|
134
129
|
const { pushView } = ViewContext.useViewContext();
|
|
135
130
|
const { getEOAWallet, isSmartWallet } = useSmartWallets.useSmartWallets();
|
|
@@ -145,9 +140,9 @@ const EmbeddedRevealView = ({ exportPrivateKey, isPromptForExport = false, }) =>
|
|
|
145
140
|
catch (error) {
|
|
146
141
|
// waas wallet
|
|
147
142
|
}
|
|
148
|
-
const walletProperties = (
|
|
143
|
+
const walletProperties = (_b = (_a = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _a === void 0 ? void 0 : _a.find(({ walletName, id }) => (walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey')) && id === primaryTurnkeyWalletId)) === null || _b === void 0 ? void 0 : _b.walletProperties;
|
|
149
144
|
const isTurnkeyHDWallet = walletProperties === null || walletProperties === void 0 ? void 0 : walletProperties.turnkeyHDWalletId;
|
|
150
|
-
const wallet = (
|
|
145
|
+
const wallet = (_c = (primaryWallet && getEOAWallet(primaryWallet))) !== null && _c !== void 0 ? _c : primaryWallet;
|
|
151
146
|
const [showSkeleton, setShowSkeleton] = React.useState(false);
|
|
152
147
|
// eslint-disable-next-line arrow-body-style
|
|
153
148
|
React.useEffect(() => {
|
|
@@ -167,14 +162,14 @@ const EmbeddedRevealView = ({ exportPrivateKey, isPromptForExport = false, }) =>
|
|
|
167
162
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
168
163
|
}, []);
|
|
169
164
|
const { isLoading: exportLoading } = usePromise.usePromise(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
170
|
-
var
|
|
165
|
+
var _d, _e;
|
|
171
166
|
const iframeContainerElement = iframeContainerRef.current;
|
|
172
167
|
if (!iframeContainerElement ||
|
|
173
|
-
((
|
|
168
|
+
((_d = iframeContainerElement === null || iframeContainerElement === void 0 ? void 0 : iframeContainerElement.children) === null || _d === void 0 ? void 0 : _d.length) > 0) {
|
|
174
169
|
return;
|
|
175
170
|
}
|
|
176
171
|
if (walletConnectorCore.isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
|
|
177
|
-
yield ((
|
|
172
|
+
yield ((_e = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _e === void 0 ? void 0 : _e.createOrRestoreSession());
|
|
178
173
|
}
|
|
179
174
|
if (isTurnkeyWallet) {
|
|
180
175
|
return turnkeyExport.initExport({
|
|
@@ -186,7 +181,7 @@ const EmbeddedRevealView = ({ exportPrivateKey, isPromptForExport = false, }) =>
|
|
|
186
181
|
return;
|
|
187
182
|
}));
|
|
188
183
|
const { mutate: handleExportWallet, isLoading, error, data, } = useMutation.useMutation(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
189
|
-
var
|
|
184
|
+
var _f, _g, _h;
|
|
190
185
|
handleAcknowledgeExportPrompt();
|
|
191
186
|
if (isTurnkeyWallet) {
|
|
192
187
|
try {
|
|
@@ -197,11 +192,11 @@ const EmbeddedRevealView = ({ exportPrivateKey, isPromptForExport = false, }) =>
|
|
|
197
192
|
wallet: wallet,
|
|
198
193
|
});
|
|
199
194
|
}
|
|
200
|
-
catch (
|
|
195
|
+
catch (_j) {
|
|
201
196
|
if (walletConnectorCore.isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector) &&
|
|
202
|
-
((
|
|
203
|
-
yield ((
|
|
204
|
-
yield ((
|
|
197
|
+
((_f = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _f === void 0 ? void 0 : _f.removeSessionKeys)) {
|
|
198
|
+
yield ((_g = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _g === void 0 ? void 0 : _g.removeSessionKeys());
|
|
199
|
+
yield ((_h = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _h === void 0 ? void 0 : _h.createOrRestoreSession({
|
|
205
200
|
ignoreRestore: true,
|
|
206
201
|
}));
|
|
207
202
|
}
|
|
@@ -222,7 +217,7 @@ const EmbeddedRevealView = ({ exportPrivateKey, isPromptForExport = false, }) =>
|
|
|
222
217
|
wallet: wallet,
|
|
223
218
|
});
|
|
224
219
|
}
|
|
225
|
-
catch (
|
|
220
|
+
catch (_k) {
|
|
226
221
|
return undefined;
|
|
227
222
|
}
|
|
228
223
|
}
|
|
@@ -259,44 +254,6 @@ const EmbeddedRevealView = ({ exportPrivateKey, isPromptForExport = false, }) =>
|
|
|
259
254
|
setShowAuthFlow(false);
|
|
260
255
|
setDynamicWidgetView('send-balance');
|
|
261
256
|
}, className: 'embedded-reveal-view__zerodev-warning__link-button', children: jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', weight: 'regular', color: 'primary', className: 'underline', copykey: 'dyn_embedded_reveal.aa_warning.button', children: t('dyn_embedded_reveal.aa_warning.button') }) })] })] })), jsxRuntime.jsx("div", { className: 'embedded-reveal-view__body__description', children: !(!isLoading && data && !error) && (jsxRuntime.jsx("div", { className: 'embedded-reveal-view__header', children: jsxRuntime.jsx("div", { className: 'embedded-reveal-view__header__hero', children: jsxRuntime.jsx(exportEmbeddedHero.ReactComponent, {}) }) })) })] }));
|
|
262
|
-
React.useEffect(() => {
|
|
263
|
-
var _a;
|
|
264
|
-
if (((_a = iframeContainerRef === null || iframeContainerRef === void 0 ? void 0 : iframeContainerRef.current) === null || _a === void 0 ? void 0 : _a.children) && data) {
|
|
265
|
-
// eslint-disable-next-line prefer-destructuring
|
|
266
|
-
const iframeElement = iframeContainerRef.current.children[0];
|
|
267
|
-
let height = '88px';
|
|
268
|
-
let minHeight = '88px';
|
|
269
|
-
// Determine height based on wallet type and other conditions
|
|
270
|
-
if (!isTurnkeyHDWallet || exportPrivateKey) {
|
|
271
|
-
if (isSolWallet) {
|
|
272
|
-
height = '140px';
|
|
273
|
-
minHeight = '140px';
|
|
274
|
-
}
|
|
275
|
-
else if (isSuiWallet) {
|
|
276
|
-
height = '100px';
|
|
277
|
-
minHeight = '100px';
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
height = '88px';
|
|
281
|
-
minHeight = '88px';
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
// Turnkey HD wallet case
|
|
286
|
-
height = '120px';
|
|
287
|
-
minHeight = '120px';
|
|
288
|
-
}
|
|
289
|
-
iframeElement === null || iframeElement === void 0 ? void 0 : iframeElement.setAttribute('style', `height: ${height}; min-height: ${minHeight}; width: 100%; border: none; background: transparent; overflow: hidden;`);
|
|
290
|
-
}
|
|
291
|
-
}, [
|
|
292
|
-
iframeContainerRef,
|
|
293
|
-
data,
|
|
294
|
-
isTurnkeyHDWallet,
|
|
295
|
-
isWaasWallet,
|
|
296
|
-
exportPrivateKey,
|
|
297
|
-
isSuiWallet,
|
|
298
|
-
isSolWallet,
|
|
299
|
-
]);
|
|
300
257
|
React.useEffect(() => {
|
|
301
258
|
if (data) {
|
|
302
259
|
// Show skeleton first
|
|
@@ -343,14 +300,7 @@ const EmbeddedRevealView = ({ exportPrivateKey, isPromptForExport = false, }) =>
|
|
|
343
300
|
return `${baseClass} ${baseClass}--hidden`;
|
|
344
301
|
}
|
|
345
302
|
if (isWaasWallet) {
|
|
346
|
-
|
|
347
|
-
if (isSuiWallet) {
|
|
348
|
-
return `${waasClass} ${baseClass}--sui`;
|
|
349
|
-
}
|
|
350
|
-
if (isSolWallet) {
|
|
351
|
-
return `${waasClass} ${baseClass}--sol`;
|
|
352
|
-
}
|
|
353
|
-
return waasClass;
|
|
303
|
+
return `${baseClass} ${baseClass}--waas`;
|
|
354
304
|
}
|
|
355
305
|
return baseClass;
|
|
356
306
|
};
|
|
@@ -362,29 +312,10 @@ const EmbeddedRevealView = ({ exportPrivateKey, isPromptForExport = false, }) =>
|
|
|
362
312
|
if (showSkeleton) {
|
|
363
313
|
return `${baseClass} ${baseClass}--invisible`;
|
|
364
314
|
}
|
|
365
|
-
if (isWaasWallet) {
|
|
366
|
-
if (isSuiWallet) {
|
|
367
|
-
return `${baseClass} ${baseClass}--sui`;
|
|
368
|
-
}
|
|
369
|
-
if (isSolWallet) {
|
|
370
|
-
return `${baseClass} ${baseClass}--sol`;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
315
|
return baseClass;
|
|
374
316
|
};
|
|
375
317
|
const getSkeletonLines = () => {
|
|
376
|
-
|
|
377
|
-
if (isWaasWallet) {
|
|
378
|
-
if (isSolWallet) {
|
|
379
|
-
lineCount = 7; // For 140px height
|
|
380
|
-
}
|
|
381
|
-
else if (isSuiWallet) {
|
|
382
|
-
lineCount = 5; // For 100px height
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
else if (isTurnkeyHDWallet && !exportPrivateKey) {
|
|
386
|
-
lineCount = 6; // For 120px height
|
|
387
|
-
}
|
|
318
|
+
const lineCount = 5; // Updated for 110px height
|
|
388
319
|
const lines = [];
|
|
389
320
|
for (let i = 0; i < lineCount; i++) {
|
|
390
321
|
const isLastLine = i === lineCount - 1;
|
|
@@ -398,11 +329,7 @@ const EmbeddedRevealView = ({ exportPrivateKey, isPromptForExport = false, }) =>
|
|
|
398
329
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(ModalHeader.ModalHeader, { trailing: isPromptForExport ? null : closeButton, children: jsxRuntime.jsx(Typography.Typography, { as: 'h1', variant: 'title', color: 'primary', "data-testid": 'dynamic-auth-modal-heading', className: 'header__typography', children: title }) }), jsxRuntime.jsx("div", { className: 'embedded-reveal-view', children: jsxRuntime.jsxs("div", { className: getBodyClassName(), children: [(!isWaasWallet ||
|
|
399
330
|
!hasInjectedCredential ||
|
|
400
331
|
title !== credentialTitle) &&
|
|
401
|
-
contentHeader, isTurnkeyWallet || isWaasWallet ? (jsxRuntime.jsxs("div", { className: getCredentialContainerClassName(), children: [jsxRuntime.jsx("div", { id: constants.iframeContainerId, className: getIframeContainerClassName(), ref: iframeContainerRef }), showSkeleton && data && (jsxRuntime.jsx("div", { className:
|
|
402
|
-
? ' embedded-reveal-view__body__skeleton-container--sui'
|
|
403
|
-
: isWaasWallet && isSolWallet
|
|
404
|
-
? ' embedded-reveal-view__body__skeleton-container--sol'
|
|
405
|
-
: ''}`, children: getSkeletonLines() }))] })) : null, hasInjectedCredential ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(TypographyButton.TypographyButton, { buttonPadding: 'medium', buttonVariant: 'brand-primary', onClick: () => {
|
|
332
|
+
contentHeader, isTurnkeyWallet || isWaasWallet ? (jsxRuntime.jsxs("div", { className: getCredentialContainerClassName(), children: [jsxRuntime.jsx("div", { id: constants.iframeContainerId, className: getIframeContainerClassName(), ref: iframeContainerRef }), showSkeleton && data && (jsxRuntime.jsx("div", { className: 'embedded-reveal-view__body__skeleton-container', children: getSkeletonLines() }))] })) : null, hasInjectedCredential ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(TypographyButton.TypographyButton, { buttonPadding: 'medium', buttonVariant: 'brand-primary', onClick: () => {
|
|
406
333
|
setShowAuthFlow(false);
|
|
407
334
|
}, loading: isLoading, copykey: 'dyn_embedded_reveal.done_button_label', typographyProps: {
|
|
408
335
|
color: 'inherit',
|