@dynamic-labs/sdk-react-core 0.18.100-viem.2 → 0.18.100-viem.21
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 +179 -0
- package/package.cjs +3 -3
- package/package.js +3 -3
- package/package.json +10 -10
- package/src/index.cjs +3 -2
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -1
- package/src/lib/components/MenuList/Dropdown/Dropdown.cjs +1 -1
- package/src/lib/components/MenuList/Dropdown/Dropdown.js +1 -1
- package/src/lib/components/ModalHeaderBanner/ModalHeaderBanner.cjs +6 -2
- package/src/lib/components/ModalHeaderBanner/ModalHeaderBanner.d.ts +2 -1
- package/src/lib/components/ModalHeaderBanner/ModalHeaderBanner.js +6 -2
- package/src/lib/components/OTPVerificationView/OTPVerificationView.cjs +2 -2
- package/src/lib/components/OTPVerificationView/OTPVerificationView.d.ts +1 -0
- package/src/lib/components/OTPVerificationView/OTPVerificationView.js +2 -2
- package/src/lib/components/SignMessagePreview/SignMessagePreview.cjs +27 -0
- package/src/lib/components/SignMessagePreview/SignMessagePreview.d.ts +6 -0
- package/src/lib/components/SignMessagePreview/SignMessagePreview.js +23 -0
- package/src/lib/components/SignMessagePreview/SignMessagePreview.types.d.ts +8 -0
- package/src/lib/components/SignMessagePreview/components/SignTypedDataPreview/SignTypedDataPreview.cjs +44 -0
- package/src/lib/components/SignMessagePreview/components/SignTypedDataPreview/SignTypedDataPreview.d.ts +8 -0
- package/src/lib/components/SignMessagePreview/components/SignTypedDataPreview/SignTypedDataPreview.js +40 -0
- package/src/lib/components/SignMessagePreview/components/SignTypedDataPreview/index.d.ts +1 -0
- package/src/lib/components/SignMessagePreview/components/index.d.ts +1 -0
- package/src/lib/components/SignMessagePreview/index.d.ts +1 -0
- package/src/lib/components/SignMessagePreview/utils/index.d.ts +1 -0
- package/src/lib/components/SignMessagePreview/utils/isSignTypedData/index.d.ts +1 -0
- package/src/lib/components/SignMessagePreview/utils/isSignTypedData/isSignTypedData.cjs +17 -0
- package/src/lib/components/SignMessagePreview/utils/isSignTypedData/isSignTypedData.d.ts +2 -0
- package/src/lib/components/SignMessagePreview/utils/isSignTypedData/isSignTypedData.js +13 -0
- package/src/lib/components/Typography/Typography.cjs +1 -0
- package/src/lib/components/Typography/Typography.js +1 -0
- package/src/lib/components/Typography/Typography.types.d.ts +1 -1
- package/src/lib/components/UserProfile/UserProfile.cjs +1 -1
- package/src/lib/components/UserProfile/UserProfile.js +1 -1
- package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.cjs +1 -1
- package/src/lib/components/UserProfile/parts/UserProfileSocialAccount/UserProfileSocialAccount.js +1 -1
- package/src/lib/components/index.d.ts +1 -0
- package/src/lib/context/DynamicContext/DynamicContext.cjs +22 -7
- package/src/lib/context/DynamicContext/DynamicContext.d.ts +11 -1
- package/src/lib/context/DynamicContext/DynamicContext.js +23 -8
- package/src/lib/context/DynamicContext/helpers.cjs +42 -3
- package/src/lib/context/DynamicContext/helpers.d.ts +7 -1
- package/src/lib/context/DynamicContext/helpers.js +38 -4
- package/src/lib/context/DynamicContext/hooks/useSetShowAuthFlowWithInit/useSetShowAuthFlowWithInit.cjs +5 -2
- package/src/lib/context/DynamicContext/hooks/useSetShowAuthFlowWithInit/useSetShowAuthFlowWithInit.d.ts +4 -2
- package/src/lib/context/DynamicContext/hooks/useSetShowAuthFlowWithInit/useSetShowAuthFlowWithInit.js +5 -2
- package/src/lib/context/DynamicContext/internalEvents/index.d.ts +2 -0
- package/src/lib/context/DynamicContext/internalEvents/internalEvents.cjs +14 -0
- package/src/lib/context/DynamicContext/internalEvents/internalEvents.d.ts +8 -0
- package/src/lib/context/DynamicContext/internalEvents/internalEvents.js +6 -0
- package/src/lib/context/DynamicContext/types/index.d.ts +7 -1
- package/src/lib/context/DynamicContext/useDynamicContext.cjs +2 -1
- package/src/lib/context/DynamicContext/useDynamicContext.d.ts +1 -1
- package/src/lib/context/DynamicContext/useDynamicContext.js +2 -1
- package/src/lib/context/ErrorContext/ErrorContext.cjs +1 -0
- package/src/lib/context/ErrorContext/ErrorContext.js +1 -0
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.cjs +2 -1
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.js +2 -1
- package/src/lib/context/ViewContext/ViewContext.d.ts +1 -1
- package/src/lib/context/WalletContext/WalletContext.cjs +2 -16
- package/src/lib/context/WalletContext/WalletContext.js +2 -16
- package/src/lib/data/api.cjs +37 -13
- package/src/lib/data/api.d.ts +5 -3
- package/src/lib/data/api.js +37 -14
- package/src/lib/main.global.cjs +1 -1
- package/src/lib/main.global.js +1 -1
- package/src/lib/modals/SignMessageConfirmationModal/SignMessageConfirmationModal.cjs +2 -1
- package/src/lib/modals/SignMessageConfirmationModal/SignMessageConfirmationModal.js +2 -1
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.cjs +2 -1
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.js +2 -1
- package/src/lib/shared/types/index.d.ts +4 -0
- package/src/lib/shared/utils/hooks/usePreventPageScroll/usePreventPageScroll.cjs +28 -2
- package/src/lib/shared/utils/hooks/usePreventPageScroll/usePreventPageScroll.js +28 -2
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/constants/localStorage.cjs +4 -0
- package/src/lib/utils/constants/localStorage.d.ts +2 -0
- package/src/lib/utils/constants/localStorage.js +3 -1
- package/src/lib/utils/functions/createUserProfile/createUserProfile.cjs +1 -1
- package/src/lib/utils/functions/createUserProfile/createUserProfile.js +1 -1
- package/src/lib/utils/functions/digestSHA256/digestSHA256.cjs +11 -0
- package/src/lib/utils/functions/digestSHA256/digestSHA256.d.ts +1 -0
- package/src/lib/utils/functions/digestSHA256/digestSHA256.js +7 -0
- package/src/lib/utils/functions/digestSHA256/index.d.ts +1 -0
- package/src/lib/utils/functions/encodeBase64URL/encodeBase64URL.cjs +14 -0
- package/src/lib/utils/functions/encodeBase64URL/encodeBase64URL.d.ts +1 -0
- package/src/lib/utils/functions/encodeBase64URL/encodeBase64URL.js +10 -0
- package/src/lib/utils/functions/encodeBase64URL/index.d.ts +1 -0
- package/src/lib/utils/functions/getDynamicLayoutData/getDynamicLayoutData.cjs +6 -1
- package/src/lib/utils/functions/getDynamicLayoutData/getDynamicLayoutData.js +6 -1
- package/src/lib/utils/functions/getRedirectURIOrigin/getRedirectURIOrigin.cjs +33 -0
- package/src/lib/utils/functions/getRedirectURIOrigin/getRedirectURIOrigin.d.ts +1 -0
- package/src/lib/utils/functions/getRedirectURIOrigin/getRedirectURIOrigin.js +29 -0
- package/src/lib/utils/functions/getRedirectURIOrigin/index.d.ts +1 -0
- package/src/lib/utils/functions/index.d.ts +6 -0
- package/src/lib/utils/functions/randomString/index.d.ts +1 -0
- package/src/lib/utils/functions/randomString/randomString.cjs +14 -0
- package/src/lib/utils/functions/randomString/randomString.d.ts +1 -0
- package/src/lib/utils/functions/randomString/randomString.js +10 -0
- package/src/lib/utils/functions/sendTransactionWithAutoNonce/index.d.ts +1 -0
- package/src/lib/utils/functions/sendTransactionWithAutoNonce/sendTransactionWithAutoNonce.cjs +48 -0
- package/src/lib/utils/functions/sendTransactionWithAutoNonce/sendTransactionWithAutoNonce.d.ts +18 -0
- package/src/lib/utils/functions/sendTransactionWithAutoNonce/sendTransactionWithAutoNonce.js +43 -0
- package/src/lib/utils/functions/stringifyURIQuery/index.d.ts +1 -0
- package/src/lib/utils/functions/stringifyURIQuery/stringifyURIQuery.cjs +13 -0
- package/src/lib/utils/functions/stringifyURIQuery/stringifyURIQuery.d.ts +1 -0
- package/src/lib/utils/functions/stringifyURIQuery/stringifyURIQuery.js +9 -0
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +10 -5
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +10 -5
- package/src/lib/utils/hooks/authenticationHooks/useSignConnectOnlyUser/useSignConnectOnlyUser.cjs +6 -2
- package/src/lib/utils/hooks/authenticationHooks/useSignConnectOnlyUser/useSignConnectOnlyUser.js +6 -2
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.cjs +13 -4
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.d.ts +1 -19
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.js +13 -4
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +22 -32
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.d.ts +1 -2
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +23 -33
- package/src/lib/utils/hooks/useConnectedWalletsNetworkValidation/useConnectedWalletsNetworkValidation.cjs +7 -6
- package/src/lib/utils/hooks/useConnectedWalletsNetworkValidation/useConnectedWalletsNetworkValidation.js +7 -6
- package/src/lib/utils/hooks/useFetchProjectSettings/useFetchProjectSettings.cjs +10 -1
- package/src/lib/utils/hooks/useFetchProjectSettings/useFetchProjectSettings.js +10 -1
- package/src/lib/utils/hooks/useHandleWalletsToConnect/useHandleWalletsToConnect.cjs +15 -1
- package/src/lib/utils/hooks/useHandleWalletsToConnect/useHandleWalletsToConnect.js +15 -1
- package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.cjs +6 -2
- package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.d.ts +2 -1
- package/src/lib/utils/hooks/usePrimaryWalletId/usePrimaryWalletId.js +6 -2
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.cjs +132 -24
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.d.ts +5 -1
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.js +134 -26
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.cjs +13 -3
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.js +13 -3
- package/src/lib/utils/hooks/useWallets/useWallets.cjs +20 -26
- package/src/lib/utils/hooks/useWallets/useWallets.d.ts +3 -2
- package/src/lib/utils/hooks/useWallets/useWallets.js +21 -27
- package/src/lib/views/CollectUserDataView/OnboardingUserDataForm/OnboardingUserDataForm.cjs +3 -3
- package/src/lib/views/CollectUserDataView/OnboardingUserDataForm/OnboardingUserDataForm.js +3 -3
- package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.cjs +1 -1
- package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.js +1 -1
- package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.cjs +1 -1
- package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.js +1 -1
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +3 -2
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +3 -2
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.cjs +3 -2
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.js +3 -2
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.cjs +4 -10
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.js +4 -10
- package/src/lib/views/WalletGroupView/components/WalletGroupItem/WalletGroupItem.cjs +1 -0
- package/src/lib/views/WalletGroupView/components/WalletGroupItem/WalletGroupItem.js +1 -0
- package/src/lib/views/WalletList/WalletListItem/WalletListItem.cjs +1 -1
- package/src/lib/views/WalletList/WalletListItem/WalletListItem.js +1 -1
- package/src/lib/views/WalletList/data.cjs +2 -14
- package/src/lib/views/WalletList/data.d.ts +4 -2
- package/src/lib/views/WalletList/data.js +2 -13
- package/src/lib/views/viewToComponentMap.cjs +1 -0
- package/src/lib/views/viewToComponentMap.js +1 -0
- package/src/lib/widgets/DynamicBridgeWidget/views/EditProfileView/EditProfileView.cjs +3 -3
- package/src/lib/widgets/DynamicBridgeWidget/views/EditProfileView/EditProfileView.js +3 -3
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.cjs +7 -10
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.js +8 -11
- package/src/lib/widgets/DynamicWidget/hooks/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/hooks/useFetchCurrency/useFetchCurrency.cjs +4 -1
- package/src/lib/widgets/DynamicWidget/hooks/useFetchCurrency/useFetchCurrency.js +4 -1
- package/src/lib/widgets/DynamicWidget/hooks/useViewController/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/hooks/useViewController/useViewController.cjs +17 -0
- package/src/lib/widgets/DynamicWidget/hooks/useViewController/useViewController.d.ts +6 -0
- package/src/lib/widgets/DynamicWidget/hooks/useViewController/useViewController.js +13 -0
- package/src/lib/widgets/DynamicWidget/views/EditProfileView/EditProfileView.cjs +3 -3
- package/src/lib/widgets/DynamicWidget/views/EditProfileView/EditProfileView.js +3 -3
- package/src/lib/widgets/DynamicWidget/views/SendBalanceWidgetView/SendBalanceWidgetView.cjs +2 -3
- package/src/lib/widgets/DynamicWidget/views/SendBalanceWidgetView/SendBalanceWidgetView.js +2 -3
- package/src/lib/widgets/OAuthIFrameContainer/OAuthIFrameContainer.cjs +13 -0
- package/src/lib/widgets/OAuthIFrameContainer/OAuthIFrameContainer.d.ts +2 -0
- package/src/lib/widgets/OAuthIFrameContainer/OAuthIFrameContainer.js +9 -0
- package/src/lib/widgets/OAuthIFrameContainer/index.d.ts +1 -0
- package/src/lib/widgets/index.d.ts +1 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import '@dynamic-labs/sdk-api';
|
|
2
|
+
import { logger } from '../../../shared/logger.js';
|
|
3
|
+
import '@dynamic-labs/iconic';
|
|
4
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import 'react/jsx-runtime';
|
|
6
|
+
import '../../../context/ViewContext/ViewContext.js';
|
|
7
|
+
import 'react';
|
|
8
|
+
import '@dynamic-labs/wallet-book';
|
|
9
|
+
import '@dynamic-labs/utils';
|
|
10
|
+
import '../../constants/colors.js';
|
|
11
|
+
import '../../../shared/utils/classes/storage/localStorage.js';
|
|
12
|
+
import 'viem';
|
|
13
|
+
import '../../../shared/consts/index.js';
|
|
14
|
+
|
|
15
|
+
const getRedirectURIOrigin = (url) => {
|
|
16
|
+
var _a;
|
|
17
|
+
try {
|
|
18
|
+
const urlObj = new URL(url);
|
|
19
|
+
const redirectUriStr = (_a = urlObj.searchParams.get('redirect_uri')) !== null && _a !== void 0 ? _a : '';
|
|
20
|
+
const redirectUri = new URL(redirectUriStr);
|
|
21
|
+
return redirectUri.origin;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
logger.debug('Failed to get redirect uri origin', e);
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { getRedirectURIOrigin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getRedirectURIOrigin } from './getRedirectURIOrigin';
|
|
@@ -22,3 +22,9 @@ export * from './isOnrampProvider';
|
|
|
22
22
|
export * from './getWalletConnectorNetworks/getWalletConnectorNetworks';
|
|
23
23
|
export * from './isSocialKycEnabled';
|
|
24
24
|
export * from './isMagicConnector';
|
|
25
|
+
export * from './randomString';
|
|
26
|
+
export * from './stringifyURIQuery';
|
|
27
|
+
export * from './digestSHA256';
|
|
28
|
+
export * from './encodeBase64URL';
|
|
29
|
+
export * from './getRedirectURIOrigin';
|
|
30
|
+
export * from './sendTransactionWithAutoNonce';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { randomString } from './randomString';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const randomString = (length) => {
|
|
6
|
+
const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
7
|
+
let result = '';
|
|
8
|
+
for (let i = length; i > 0; --i) {
|
|
9
|
+
result += CHARS[Math.floor(Math.random() * CHARS.length)];
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.randomString = randomString;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const randomString: (length: number) => string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const randomString = (length) => {
|
|
2
|
+
const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
3
|
+
let result = '';
|
|
4
|
+
for (let i = length; i > 0; --i) {
|
|
5
|
+
result += CHARS[Math.floor(Math.random() * CHARS.length)];
|
|
6
|
+
}
|
|
7
|
+
return result;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { randomString };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { sendTransactionWithAutoNonce } from './sendTransactionWithAutoNonce';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
6
|
+
|
|
7
|
+
const MAGIC_COULD_NOT_REPLACE_TRANSACTION_ERROR_CODE = -32603;
|
|
8
|
+
/**
|
|
9
|
+
* Sends a transaction with an automatically determined nonce, if not provided.
|
|
10
|
+
*
|
|
11
|
+
* In Ethereum, each transaction sent from a particular address must have a unique nonce.
|
|
12
|
+
* If the transaction does not already have a nonce, this function helps to automatically set it.
|
|
13
|
+
* If a transaction with a particular nonce fails due to a "could not replace transaction" error,
|
|
14
|
+
* this function will automatically retry with the next nonce.
|
|
15
|
+
*
|
|
16
|
+
* @param connector - A Dynamic connector to interact with the Ethereum network.
|
|
17
|
+
* @param transaction - The transaction details.
|
|
18
|
+
* @param sendTransactionHandler - A handler function to send the transaction.
|
|
19
|
+
*
|
|
20
|
+
* @returns A promise that resolves to the transaction response.
|
|
21
|
+
*/
|
|
22
|
+
const sendTransactionWithAutoNonce = (connector, transaction, sendTransactionHandler) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
if (transaction.nonce !== undefined) {
|
|
24
|
+
return sendTransactionHandler(transaction);
|
|
25
|
+
}
|
|
26
|
+
const publicClient = yield connector.getRpcProvider();
|
|
27
|
+
const walletClient = yield connector.getSigner();
|
|
28
|
+
const [address] = yield walletClient.getAddresses();
|
|
29
|
+
const nonce = yield publicClient.getTransactionCount({
|
|
30
|
+
address,
|
|
31
|
+
});
|
|
32
|
+
const transactionWithNonce = Object.assign(Object.assign({}, transaction), { nonce });
|
|
33
|
+
try {
|
|
34
|
+
const response = yield sendTransactionHandler(transactionWithNonce);
|
|
35
|
+
return response;
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
if (err.code ===
|
|
39
|
+
MAGIC_COULD_NOT_REPLACE_TRANSACTION_ERROR_CODE) {
|
|
40
|
+
const transactionWithNextNonce = Object.assign(Object.assign({}, transaction), { nonce: nonce + 1 });
|
|
41
|
+
return sendTransactionHandler(transactionWithNextNonce);
|
|
42
|
+
}
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
exports.MAGIC_COULD_NOT_REPLACE_TRANSACTION_ERROR_CODE = MAGIC_COULD_NOT_REPLACE_TRANSACTION_ERROR_CODE;
|
|
48
|
+
exports.sendTransactionWithAutoNonce = sendTransactionWithAutoNonce;
|
package/src/lib/utils/functions/sendTransactionWithAutoNonce/sendTransactionWithAutoNonce.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TransactionRequest, Address } from 'viem';
|
|
2
|
+
import { WalletConnector } from '../../../..';
|
|
3
|
+
export declare const MAGIC_COULD_NOT_REPLACE_TRANSACTION_ERROR_CODE = -32603;
|
|
4
|
+
/**
|
|
5
|
+
* Sends a transaction with an automatically determined nonce, if not provided.
|
|
6
|
+
*
|
|
7
|
+
* In Ethereum, each transaction sent from a particular address must have a unique nonce.
|
|
8
|
+
* If the transaction does not already have a nonce, this function helps to automatically set it.
|
|
9
|
+
* If a transaction with a particular nonce fails due to a "could not replace transaction" error,
|
|
10
|
+
* this function will automatically retry with the next nonce.
|
|
11
|
+
*
|
|
12
|
+
* @param connector - A Dynamic connector to interact with the Ethereum network.
|
|
13
|
+
* @param transaction - The transaction details.
|
|
14
|
+
* @param sendTransactionHandler - A handler function to send the transaction.
|
|
15
|
+
*
|
|
16
|
+
* @returns A promise that resolves to the transaction response.
|
|
17
|
+
*/
|
|
18
|
+
export declare const sendTransactionWithAutoNonce: (connector: WalletConnector, transaction: TransactionRequest, sendTransactionHandler: (transaction: TransactionRequest) => Promise<Address>) => Promise<`0x${string}`>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
|
+
|
|
3
|
+
const MAGIC_COULD_NOT_REPLACE_TRANSACTION_ERROR_CODE = -32603;
|
|
4
|
+
/**
|
|
5
|
+
* Sends a transaction with an automatically determined nonce, if not provided.
|
|
6
|
+
*
|
|
7
|
+
* In Ethereum, each transaction sent from a particular address must have a unique nonce.
|
|
8
|
+
* If the transaction does not already have a nonce, this function helps to automatically set it.
|
|
9
|
+
* If a transaction with a particular nonce fails due to a "could not replace transaction" error,
|
|
10
|
+
* this function will automatically retry with the next nonce.
|
|
11
|
+
*
|
|
12
|
+
* @param connector - A Dynamic connector to interact with the Ethereum network.
|
|
13
|
+
* @param transaction - The transaction details.
|
|
14
|
+
* @param sendTransactionHandler - A handler function to send the transaction.
|
|
15
|
+
*
|
|
16
|
+
* @returns A promise that resolves to the transaction response.
|
|
17
|
+
*/
|
|
18
|
+
const sendTransactionWithAutoNonce = (connector, transaction, sendTransactionHandler) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
if (transaction.nonce !== undefined) {
|
|
20
|
+
return sendTransactionHandler(transaction);
|
|
21
|
+
}
|
|
22
|
+
const publicClient = yield connector.getRpcProvider();
|
|
23
|
+
const walletClient = yield connector.getSigner();
|
|
24
|
+
const [address] = yield walletClient.getAddresses();
|
|
25
|
+
const nonce = yield publicClient.getTransactionCount({
|
|
26
|
+
address,
|
|
27
|
+
});
|
|
28
|
+
const transactionWithNonce = Object.assign(Object.assign({}, transaction), { nonce });
|
|
29
|
+
try {
|
|
30
|
+
const response = yield sendTransactionHandler(transactionWithNonce);
|
|
31
|
+
return response;
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (err.code ===
|
|
35
|
+
MAGIC_COULD_NOT_REPLACE_TRANSACTION_ERROR_CODE) {
|
|
36
|
+
const transactionWithNextNonce = Object.assign(Object.assign({}, transaction), { nonce: nonce + 1 });
|
|
37
|
+
return sendTransactionHandler(transactionWithNextNonce);
|
|
38
|
+
}
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export { MAGIC_COULD_NOT_REPLACE_TRANSACTION_ERROR_CODE, sendTransactionWithAutoNonce };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { stringifyURIQuery } from './stringifyURIQuery';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const stringifyURIQuery = (obj) => {
|
|
6
|
+
const str = [];
|
|
7
|
+
for (const prop in obj) {
|
|
8
|
+
str.push(encodeURIComponent(prop) + '=' + encodeURIComponent(obj[prop]));
|
|
9
|
+
}
|
|
10
|
+
return str.join('&');
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
exports.stringifyURIQuery = stringifyURIQuery;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stringifyURIQuery: (obj: any) => string;
|
|
@@ -32,7 +32,7 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
32
32
|
const { setView, goToInitialView } = ViewContext.useViewContext();
|
|
33
33
|
const { setErrorMessage } = ErrorContext.useErrorContext();
|
|
34
34
|
const { captchaToken } = CaptchaContext.useCaptchaContext();
|
|
35
|
-
const { authMode, connectWallet, consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, user, walletUiUtils, setCallback, setIsVerificationInProgress, isFullyConnected, walletsToConnectByChain, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
35
|
+
const { authMode, connectWallet, consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, user, walletUiUtils, setCallback, setIsVerificationInProgress, isFullyConnected, walletsToConnectByChain = [], } = useInternalDynamicContext.useInternalDynamicContext();
|
|
36
36
|
const { handleWalletsToConnect } = useHandleWalletsToConnect.useHandleWalletsToConnect();
|
|
37
37
|
const verifyWallet = useVerifyWallet.useVerifyWallet({
|
|
38
38
|
consumeNonce,
|
|
@@ -75,7 +75,7 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
75
75
|
if (shouldUpdateWallets) {
|
|
76
76
|
handleWalletsToConnect();
|
|
77
77
|
}
|
|
78
|
-
if (!isFullyConnected ||
|
|
78
|
+
if (!isFullyConnected || walletsToConnectByChain.length) {
|
|
79
79
|
setCallback('connectSuccess');
|
|
80
80
|
}
|
|
81
81
|
return;
|
|
@@ -99,11 +99,16 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
catch (err) {
|
|
102
|
-
|
|
102
|
+
const userCancelled = (err === null || err === void 0 ? void 0 : err.code) === 'user-cancelled';
|
|
103
|
+
if (!userCancelled)
|
|
104
|
+
logger.logger.debug(err);
|
|
103
105
|
setErrorMessage((_b = err === null || err === void 0 ? void 0 : err.code) === null || _b === void 0 ? void 0 : _b.toString());
|
|
104
106
|
goToInitialView();
|
|
105
|
-
// Since auth failed,
|
|
106
|
-
|
|
107
|
+
// Since auth failed, clear verification flag
|
|
108
|
+
// But if user cancelled, clearStatesOnBackClick will have already cleared it. So avoid
|
|
109
|
+
// clearing again since that would trigger a warning
|
|
110
|
+
if (!userCancelled)
|
|
111
|
+
setIsVerificationInProgress(false);
|
|
107
112
|
return;
|
|
108
113
|
}
|
|
109
114
|
});
|
|
@@ -28,7 +28,7 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
28
28
|
const { setView, goToInitialView } = useViewContext();
|
|
29
29
|
const { setErrorMessage } = useErrorContext();
|
|
30
30
|
const { captchaToken } = useCaptchaContext();
|
|
31
|
-
const { authMode, connectWallet, consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, user, walletUiUtils, setCallback, setIsVerificationInProgress, isFullyConnected, walletsToConnectByChain, } = useInternalDynamicContext();
|
|
31
|
+
const { authMode, connectWallet, consumeNonce, displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, user, walletUiUtils, setCallback, setIsVerificationInProgress, isFullyConnected, walletsToConnectByChain = [], } = useInternalDynamicContext();
|
|
32
32
|
const { handleWalletsToConnect } = useHandleWalletsToConnect();
|
|
33
33
|
const verifyWallet = useVerifyWallet({
|
|
34
34
|
consumeNonce,
|
|
@@ -71,7 +71,7 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
71
71
|
if (shouldUpdateWallets) {
|
|
72
72
|
handleWalletsToConnect();
|
|
73
73
|
}
|
|
74
|
-
if (!isFullyConnected ||
|
|
74
|
+
if (!isFullyConnected || walletsToConnectByChain.length) {
|
|
75
75
|
setCallback('connectSuccess');
|
|
76
76
|
}
|
|
77
77
|
return;
|
|
@@ -95,11 +95,16 @@ const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = tr
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
catch (err) {
|
|
98
|
-
|
|
98
|
+
const userCancelled = (err === null || err === void 0 ? void 0 : err.code) === 'user-cancelled';
|
|
99
|
+
if (!userCancelled)
|
|
100
|
+
logger.debug(err);
|
|
99
101
|
setErrorMessage((_b = err === null || err === void 0 ? void 0 : err.code) === null || _b === void 0 ? void 0 : _b.toString());
|
|
100
102
|
goToInitialView();
|
|
101
|
-
// Since auth failed,
|
|
102
|
-
|
|
103
|
+
// Since auth failed, clear verification flag
|
|
104
|
+
// But if user cancelled, clearStatesOnBackClick will have already cleared it. So avoid
|
|
105
|
+
// clearing again since that would trigger a warning
|
|
106
|
+
if (!userCancelled)
|
|
107
|
+
setIsVerificationInProgress(false);
|
|
103
108
|
return;
|
|
104
109
|
}
|
|
105
110
|
});
|
package/src/lib/utils/hooks/authenticationHooks/useSignConnectOnlyUser/useSignConnectOnlyUser.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var _tslib = require('../../../../../../_virtual/_tslib.cjs');
|
|
6
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
6
7
|
var useInternalDynamicContext = require('../../../../context/DynamicContext/useInternalDynamicContext.cjs');
|
|
7
8
|
var ViewContext = require('../../../../context/ViewContext/ViewContext.cjs');
|
|
8
9
|
var ErrorContext = require('../../../../context/ErrorContext/ErrorContext.cjs');
|
|
@@ -10,7 +11,6 @@ var useVerifyWallet = require('../../useVerifyWallet/useVerifyWallet.cjs');
|
|
|
10
11
|
require('@dynamic-labs/sdk-api');
|
|
11
12
|
var logger = require('../../../../shared/logger.cjs');
|
|
12
13
|
require('@dynamic-labs/iconic');
|
|
13
|
-
require('@dynamic-labs/wallet-connector-core');
|
|
14
14
|
require('react/jsx-runtime');
|
|
15
15
|
require('react');
|
|
16
16
|
require('@dynamic-labs/wallet-book');
|
|
@@ -23,7 +23,7 @@ require('../../../../shared/consts/index.cjs');
|
|
|
23
23
|
const useSignConnectOnlyUser = () => {
|
|
24
24
|
const { setView } = ViewContext.useViewContext();
|
|
25
25
|
const { setErrorMessage } = ErrorContext.useErrorContext();
|
|
26
|
-
const { connectWallet, consumeNonce, displaySiweStatement, projectSettings, environmentId, setIsSingleWalletAccount, setShowAuthFlow, setSelectedWalletConnector, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
26
|
+
const { connectWallet, consumeNonce, displaySiweStatement, projectSettings, environmentId, setIsSingleWalletAccount, setShowAuthFlow, setSelectedWalletConnector, walletUiUtils, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
27
27
|
const verifyWallet = useVerifyWallet.useVerifyWallet({
|
|
28
28
|
consumeNonce,
|
|
29
29
|
displaySiweStatement,
|
|
@@ -33,6 +33,10 @@ const useSignConnectOnlyUser = () => {
|
|
|
33
33
|
});
|
|
34
34
|
return ({ walletConnector, fetchPublicAddressOpts = undefined, }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
35
35
|
try {
|
|
36
|
+
if (walletConnectorCore.isEmbeddedConnector(walletConnector) &&
|
|
37
|
+
!walletConnectorCore.isBloctoConnector(walletConnector)) {
|
|
38
|
+
walletUiUtils.disabledConfirmationOnce();
|
|
39
|
+
}
|
|
36
40
|
// Prepare states to show the pending signature view (without back button)
|
|
37
41
|
// We need this because in connect-only we don't want to show wallet-list
|
|
38
42
|
// We don't want to show the back button in the pending signature view
|
package/src/lib/utils/hooks/authenticationHooks/useSignConnectOnlyUser/useSignConnectOnlyUser.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from '../../../../../../_virtual/_tslib.js';
|
|
2
|
+
import { isEmbeddedConnector, isBloctoConnector } from '@dynamic-labs/wallet-connector-core';
|
|
2
3
|
import { useInternalDynamicContext } from '../../../../context/DynamicContext/useInternalDynamicContext.js';
|
|
3
4
|
import { useViewContext } from '../../../../context/ViewContext/ViewContext.js';
|
|
4
5
|
import { useErrorContext } from '../../../../context/ErrorContext/ErrorContext.js';
|
|
@@ -6,7 +7,6 @@ import { useVerifyWallet } from '../../useVerifyWallet/useVerifyWallet.js';
|
|
|
6
7
|
import '@dynamic-labs/sdk-api';
|
|
7
8
|
import { logger } from '../../../../shared/logger.js';
|
|
8
9
|
import '@dynamic-labs/iconic';
|
|
9
|
-
import '@dynamic-labs/wallet-connector-core';
|
|
10
10
|
import 'react/jsx-runtime';
|
|
11
11
|
import 'react';
|
|
12
12
|
import '@dynamic-labs/wallet-book';
|
|
@@ -19,7 +19,7 @@ import '../../../../shared/consts/index.js';
|
|
|
19
19
|
const useSignConnectOnlyUser = () => {
|
|
20
20
|
const { setView } = useViewContext();
|
|
21
21
|
const { setErrorMessage } = useErrorContext();
|
|
22
|
-
const { connectWallet, consumeNonce, displaySiweStatement, projectSettings, environmentId, setIsSingleWalletAccount, setShowAuthFlow, setSelectedWalletConnector, } = useInternalDynamicContext();
|
|
22
|
+
const { connectWallet, consumeNonce, displaySiweStatement, projectSettings, environmentId, setIsSingleWalletAccount, setShowAuthFlow, setSelectedWalletConnector, walletUiUtils, } = useInternalDynamicContext();
|
|
23
23
|
const verifyWallet = useVerifyWallet({
|
|
24
24
|
consumeNonce,
|
|
25
25
|
displaySiweStatement,
|
|
@@ -29,6 +29,10 @@ const useSignConnectOnlyUser = () => {
|
|
|
29
29
|
});
|
|
30
30
|
return ({ walletConnector, fetchPublicAddressOpts = undefined, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
31
|
try {
|
|
32
|
+
if (isEmbeddedConnector(walletConnector) &&
|
|
33
|
+
!isBloctoConnector(walletConnector)) {
|
|
34
|
+
walletUiUtils.disabledConfirmationOnce();
|
|
35
|
+
}
|
|
32
36
|
// Prepare states to show the pending signature view (without back button)
|
|
33
37
|
// We need this because in connect-only we don't want to show wallet-list
|
|
34
38
|
// We don't want to show the back button in the pending signature view
|
|
@@ -10,8 +10,8 @@ var ViewContext = require('../../../../context/ViewContext/ViewContext.cjs');
|
|
|
10
10
|
var useInternalDynamicContext = require('../../../../context/DynamicContext/useInternalDynamicContext.cjs');
|
|
11
11
|
var errors = require('../../../constants/errors.cjs');
|
|
12
12
|
|
|
13
|
-
const useSyncPrimaryWallet = (
|
|
14
|
-
const { setShowAuthFlow, isAuthenticated } = useInternalDynamicContext.useInternalDynamicContext();
|
|
13
|
+
const useSyncPrimaryWallet = (canSync = true) => {
|
|
14
|
+
const { setShowAuthFlow, isAuthenticated, authMode, computeConnectedStateForWallets, connectWallet, handleLogOut, multiWalletWidgetState, primaryWallet, secondaryWallets, setMultiWalletWidgetState, setPrimaryWallet, setShowWidgetStatePopup, showLockedWalletView, showWidgetStatePopup, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
15
15
|
const { setView } = ViewContext.useViewContext();
|
|
16
16
|
const handlePrimaryWalletNotActive = React.useCallback((connectedAddress) => {
|
|
17
17
|
if (!primaryWallet)
|
|
@@ -93,8 +93,16 @@ const useSyncPrimaryWallet = ({ connectWallet, computeConnectedStateForWallets,
|
|
|
93
93
|
}
|
|
94
94
|
// user is logged in (has valid jwt), but no wallet is connected
|
|
95
95
|
if (isAuthenticated && e.code === errors.MISSING_ADDRESS_ERROR) {
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
if (!primaryWallet.connector.isInstalledOnBrowser()) {
|
|
97
|
+
handleLogOut();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (showLockedWalletView) {
|
|
101
|
+
setShowAuthFlow(true);
|
|
102
|
+
setView('wallet-locked-view');
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
handleLogOut();
|
|
98
106
|
}
|
|
99
107
|
});
|
|
100
108
|
}, [
|
|
@@ -111,6 +119,7 @@ const useSyncPrimaryWallet = ({ connectWallet, computeConnectedStateForWallets,
|
|
|
111
119
|
setShowAuthFlow,
|
|
112
120
|
authMode,
|
|
113
121
|
isAuthenticated,
|
|
122
|
+
showLockedWalletView,
|
|
114
123
|
]);
|
|
115
124
|
};
|
|
116
125
|
|
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { FetchPublicAddressOpts, WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
-
import { AuthModeType, MultiWalletWidgetState, Wallet } from '../../../../shared/types';
|
|
4
|
-
import { MultiWalletWidgetStateSetter } from '../useMultiWalletWidgetState';
|
|
5
|
-
export type UseSyncPrimaryWalletArgs = {
|
|
6
|
-
canSync?: boolean;
|
|
7
|
-
connectWallet: (walletConnector: WalletConnector, fetchPublicAddressOpts?: FetchPublicAddressOpts, shouldCallCallback?: boolean) => Promise<string | undefined>;
|
|
8
|
-
computeConnectedStateForWallets: () => Promise<void>;
|
|
9
|
-
handleLogOut: () => Promise<void>;
|
|
10
|
-
multiWalletWidgetState: MultiWalletWidgetState;
|
|
11
|
-
primaryWallet: Wallet | null;
|
|
12
|
-
secondaryWallets: Wallet[];
|
|
13
|
-
setMultiWalletWidgetState: MultiWalletWidgetStateSetter;
|
|
14
|
-
setPrimaryWallet: (walletId: string) => Promise<void>;
|
|
15
|
-
setShowWidgetStatePopup: Dispatch<SetStateAction<boolean>>;
|
|
16
|
-
showWidgetStatePopup: boolean;
|
|
17
|
-
authMode: AuthModeType;
|
|
18
|
-
};
|
|
19
|
-
export declare const useSyncPrimaryWallet: ({ connectWallet, computeConnectedStateForWallets, handleLogOut, multiWalletWidgetState, primaryWallet, secondaryWallets, setMultiWalletWidgetState, setPrimaryWallet, setShowWidgetStatePopup, showWidgetStatePopup, canSync, authMode, }: UseSyncPrimaryWalletArgs) => void;
|
|
1
|
+
export declare const useSyncPrimaryWallet: (canSync?: boolean) => void;
|
|
@@ -6,8 +6,8 @@ import { useViewContext } from '../../../../context/ViewContext/ViewContext.js';
|
|
|
6
6
|
import { useInternalDynamicContext } from '../../../../context/DynamicContext/useInternalDynamicContext.js';
|
|
7
7
|
import { MISSING_ADDRESS_ERROR } from '../../../constants/errors.js';
|
|
8
8
|
|
|
9
|
-
const useSyncPrimaryWallet = (
|
|
10
|
-
const { setShowAuthFlow, isAuthenticated } = useInternalDynamicContext();
|
|
9
|
+
const useSyncPrimaryWallet = (canSync = true) => {
|
|
10
|
+
const { setShowAuthFlow, isAuthenticated, authMode, computeConnectedStateForWallets, connectWallet, handleLogOut, multiWalletWidgetState, primaryWallet, secondaryWallets, setMultiWalletWidgetState, setPrimaryWallet, setShowWidgetStatePopup, showLockedWalletView, showWidgetStatePopup, } = useInternalDynamicContext();
|
|
11
11
|
const { setView } = useViewContext();
|
|
12
12
|
const handlePrimaryWalletNotActive = useCallback((connectedAddress) => {
|
|
13
13
|
if (!primaryWallet)
|
|
@@ -89,8 +89,16 @@ const useSyncPrimaryWallet = ({ connectWallet, computeConnectedStateForWallets,
|
|
|
89
89
|
}
|
|
90
90
|
// user is logged in (has valid jwt), but no wallet is connected
|
|
91
91
|
if (isAuthenticated && e.code === MISSING_ADDRESS_ERROR) {
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
if (!primaryWallet.connector.isInstalledOnBrowser()) {
|
|
93
|
+
handleLogOut();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (showLockedWalletView) {
|
|
97
|
+
setShowAuthFlow(true);
|
|
98
|
+
setView('wallet-locked-view');
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
handleLogOut();
|
|
94
102
|
}
|
|
95
103
|
});
|
|
96
104
|
}, [
|
|
@@ -107,6 +115,7 @@ const useSyncPrimaryWallet = ({ connectWallet, computeConnectedStateForWallets,
|
|
|
107
115
|
setShowAuthFlow,
|
|
108
116
|
authMode,
|
|
109
117
|
isAuthenticated,
|
|
118
|
+
showLockedWalletView,
|
|
110
119
|
]);
|
|
111
120
|
};
|
|
112
121
|
|
|
@@ -47,12 +47,7 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
47
47
|
const walletNetwork = yield walletConnector.getNetwork();
|
|
48
48
|
const walletChain = walletConnector.connectedChain;
|
|
49
49
|
const walletObject = {
|
|
50
|
-
address:
|
|
51
|
-
// We use `storedConnectedWalletInfo.lastWalletAddress` as a workaround to Braavos issue
|
|
52
|
-
// Braavos during initialization returns an empty string as a wallet address
|
|
53
|
-
walletAddress ||
|
|
54
|
-
storedConnectedWalletInfo.lastWalletAddress ||
|
|
55
|
-
'',
|
|
50
|
+
address: walletAddress || '',
|
|
56
51
|
chain: walletChain || '',
|
|
57
52
|
connected: true,
|
|
58
53
|
connector: walletConnector,
|
|
@@ -89,11 +84,10 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
89
84
|
}, [connectedWallets]);
|
|
90
85
|
const connectedWallet = connectedWallets[0] || null;
|
|
91
86
|
// Keeps connected wallet data inside localStorage
|
|
92
|
-
const applyConnectedWalletToStore = ({ walletId,
|
|
87
|
+
const applyConnectedWalletToStore = ({ walletId, walletConnectorKey, walletChain, provider, }) => {
|
|
93
88
|
const nextConnectedWalletsInfo = [...connectedWalletsInfo];
|
|
94
89
|
nextConnectedWalletsInfo.push({
|
|
95
90
|
id: walletId,
|
|
96
|
-
lastWalletAddress: walletAddress,
|
|
97
91
|
provider,
|
|
98
92
|
walletChain,
|
|
99
93
|
walletConnectorKey,
|
|
@@ -120,18 +114,13 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
120
114
|
return;
|
|
121
115
|
}
|
|
122
116
|
}
|
|
123
|
-
|
|
124
|
-
walletConnectorCore.logger.error('Could not refresh the wallet. The wallet address is not available');
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const currentWalletConnectoNetwork = yield walletConnector.getNetwork();
|
|
117
|
+
const currentWalletConnectorNetwork = yield walletConnector.getNetwork();
|
|
128
118
|
updateConnectedWalletById(walletId, {
|
|
129
119
|
address: currentWalletConnectorAddress,
|
|
130
|
-
network:
|
|
120
|
+
network: currentWalletConnectorNetwork,
|
|
131
121
|
});
|
|
132
122
|
});
|
|
133
|
-
const shouldSkipCreatingVisit =
|
|
134
|
-
connectedWallet, [authMode, connectedWallet, enableVisitTrackingOnConnectOnly]);
|
|
123
|
+
const shouldSkipCreatingVisit = authMode === 'connect-only' && !enableVisitTrackingOnConnectOnly;
|
|
135
124
|
const connectWallet = (walletConnector, fetchPublicAddressOpts, shouldCallCallback = true) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
136
125
|
const publicWalletAddress = yield walletConnector.fetchPublicAddress(fetchPublicAddressOpts);
|
|
137
126
|
if (!publicWalletAddress) {
|
|
@@ -168,31 +157,32 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
168
157
|
walletConnectorKey: walletConnector.name,
|
|
169
158
|
walletId,
|
|
170
159
|
});
|
|
160
|
+
if (!shouldSkipCreatingVisit) {
|
|
161
|
+
// send information to backend to kick off background jobs
|
|
162
|
+
// so verify/sign on the next step could go by more quickly
|
|
163
|
+
// this is async work, but DO NOT AWAIT
|
|
164
|
+
api.createVisit({
|
|
165
|
+
authMode,
|
|
166
|
+
chain: walletChain || '',
|
|
167
|
+
environmentId,
|
|
168
|
+
publicWalletAddress,
|
|
169
|
+
walletName: walletConnector.name,
|
|
170
|
+
walletProvider: getWalletProvider.getWalletProvider(walletConnector),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
171
173
|
}
|
|
172
|
-
if (shouldSkipCreatingVisit) {
|
|
173
|
-
return Promise.resolve(publicWalletAddress);
|
|
174
|
-
}
|
|
175
|
-
// send information to backend to kick off background jobs
|
|
176
|
-
// so verify/sign on the next step could go by more quickly
|
|
177
|
-
// this is async work, but DO NOT AWAIT
|
|
178
|
-
api.createVisit({
|
|
179
|
-
authMode,
|
|
180
|
-
chain: walletChain || '',
|
|
181
|
-
environmentId,
|
|
182
|
-
publicWalletAddress,
|
|
183
|
-
walletName: walletConnector.name,
|
|
184
|
-
walletProvider: getWalletProvider.getWalletProvider(walletConnector),
|
|
185
|
-
});
|
|
186
174
|
return Promise.resolve(publicWalletAddress);
|
|
187
175
|
});
|
|
188
|
-
const unlinkConnectedWallet = (walletId) => {
|
|
176
|
+
const unlinkConnectedWallet = (walletId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
177
|
+
const connectedWalletToUnlink = connectedWallets.find((wallet) => wallet.id === walletId);
|
|
178
|
+
yield (connectedWalletToUnlink === null || connectedWalletToUnlink === void 0 ? void 0 : connectedWalletToUnlink.connector.endSession());
|
|
189
179
|
const filteredWallets = connectedWalletsInfo.filter((wallet) => wallet.id !== walletId);
|
|
190
180
|
if (walletId === primaryWalletId) {
|
|
191
181
|
clearPrimaryWalletId();
|
|
192
182
|
}
|
|
193
183
|
setConnectedWalletsInfo(filteredWallets);
|
|
194
184
|
onUnlink === null || onUnlink === void 0 ? void 0 : onUnlink(walletId, filteredWallets);
|
|
195
|
-
};
|
|
185
|
+
});
|
|
196
186
|
const getConnectedWalletById = React.useCallback((walletId) => connectedWallets.find((wallet) => wallet.id === walletId), [connectedWallets]);
|
|
197
187
|
return {
|
|
198
188
|
connectWallet,
|
|
@@ -6,7 +6,6 @@ export type ConnectedWalletConnectorType = {
|
|
|
6
6
|
walletChain?: Chain;
|
|
7
7
|
walletConnectorKey: string;
|
|
8
8
|
provider: string;
|
|
9
|
-
lastWalletAddress?: string;
|
|
10
9
|
};
|
|
11
10
|
type Props = {
|
|
12
11
|
authMode: AuthModeType;
|
|
@@ -28,6 +27,6 @@ export declare const useConnectWallet: ({ authMode, clearPrimaryWalletId, enable
|
|
|
28
27
|
getConnectedWalletById: (walletId: string) => Wallet | undefined;
|
|
29
28
|
refreshConnectedWallet: (walletId: string, walletConnector: WalletConnector) => Promise<void>;
|
|
30
29
|
removeConnectedWalletsInfo: () => void;
|
|
31
|
-
unlinkConnectedWallet: (walletId: string) => void
|
|
30
|
+
unlinkConnectedWallet: (walletId: string) => Promise<void>;
|
|
32
31
|
};
|
|
33
32
|
export {};
|