@dynamic-labs/sdk-react-core 0.18.100-viem.0 → 0.18.100-viem.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -1
- package/package.cjs +2 -2
- package/package.js +2 -2
- package/package.json +9 -9
- package/src/index.cjs +2 -0
- package/src/index.js +1 -0
- package/src/lib/Main.cjs +5 -0
- package/src/lib/Main.js +5 -0
- package/src/lib/components/Button/Button.cjs +10 -7
- package/src/lib/components/Button/Button.js +10 -7
- package/src/lib/components/DynamicConnectButton/components/ConnectButton.cjs +1 -1
- package/src/lib/components/DynamicConnectButton/components/ConnectButton.js +1 -1
- package/src/lib/components/ErrorContainer/ErrorContainer.d.ts +1 -1
- package/src/lib/components/ListTile/ListTile.cjs +1 -1
- package/src/lib/components/ListTile/ListTile.js +1 -1
- package/src/lib/components/ListTile/ListTile.types.d.ts +1 -0
- package/src/lib/components/OTPVerificationView/OTPVerificationView.cjs +5 -3
- package/src/lib/components/OTPVerificationView/OTPVerificationView.d.ts +1 -0
- package/src/lib/components/OTPVerificationView/OTPVerificationView.js +5 -3
- package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.cjs +3 -1
- package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.js +3 -1
- package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.cjs +2 -2
- package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.js +2 -2
- package/src/lib/context/DynamicContext/DynamicContext.cjs +7 -2
- package/src/lib/context/DynamicContext/DynamicContext.js +8 -3
- package/src/lib/context/DynamicContext/hooks/useVerificationInProgress/useVerificationInProgress.cjs +13 -3
- package/src/lib/context/DynamicContext/hooks/useVerificationInProgress/useVerificationInProgress.js +13 -3
- package/src/lib/context/DynamicContext/types/index.d.ts +2 -2
- package/src/lib/context/SendBalanceContext/SendBalanceContext.types.d.ts +2 -2
- package/src/lib/context/ViewContext/ViewContext.d.ts +1 -1
- package/src/lib/data/api.cjs +16 -0
- package/src/lib/data/api.d.ts +1 -0
- package/src/lib/data/api.js +18 -3
- package/src/lib/layout/DynamicAuthLayout/Header/header.cjs +10 -2
- package/src/lib/layout/DynamicAuthLayout/Header/header.js +10 -2
- package/src/lib/modals/SendBalanceModal/SendBalanceModal.d.ts +2 -2
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.cjs +10 -2
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.js +10 -2
- package/src/lib/modals/TransactionConfirmationModal/TransactionConfirmationModal.types.d.ts +6 -3
- package/src/lib/shared/assets/double-arrow-right.cjs +53 -0
- package/src/lib/shared/assets/double-arrow-right.js +29 -0
- package/src/lib/shared/assets/index.d.ts +1 -0
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/constants/errors.cjs +7 -0
- package/src/lib/utils/constants/errors.d.ts +1 -0
- package/src/lib/utils/constants/errors.js +3 -0
- package/src/lib/utils/constants/index.d.ts +1 -1
- package/src/lib/utils/constants/localStorage.cjs +2 -0
- package/src/lib/utils/constants/localStorage.d.ts +1 -0
- package/src/lib/utils/constants/localStorage.js +2 -1
- package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.cjs +14 -2
- package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.d.ts +3 -2
- package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.js +14 -2
- package/src/lib/utils/functions/index.d.ts +1 -0
- package/src/lib/utils/functions/isMagicConnector/index.d.ts +1 -0
- package/src/lib/utils/functions/isMagicConnector/isMagicConnector.cjs +10 -0
- package/src/lib/utils/functions/isMagicConnector/isMagicConnector.d.ts +2 -0
- package/src/lib/utils/functions/isMagicConnector/isMagicConnector.js +6 -0
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +2 -2
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.d.ts +2 -1
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +2 -2
- package/src/lib/utils/hooks/index.d.ts +2 -0
- package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.cjs +19 -3
- package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.d.ts +1 -2
- package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.js +20 -4
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.cjs +11 -9
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.d.ts +1 -1
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.js +11 -9
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +2 -1
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +2 -1
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +2 -2
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.d.ts +1 -1
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +2 -2
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/useFetchNetworkConfigurations.cjs +2 -7
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/useFetchNetworkConfigurations.js +2 -7
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/index.d.ts +1 -0
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/mergeCustomerEvmNetworksWithServerNetworks/index.d.ts +1 -0
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/mergeCustomerEvmNetworksWithServerNetworks/mergeCustomerEvmNetworksWithServerNetworks.cjs +16 -0
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/mergeCustomerEvmNetworksWithServerNetworks/mergeCustomerEvmNetworksWithServerNetworks.d.ts +2 -0
- package/src/lib/utils/hooks/useFetchNetworkConfigurations/utils/mergeCustomerEvmNetworksWithServerNetworks/mergeCustomerEvmNetworksWithServerNetworks.js +12 -0
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.cjs +22 -4
- package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.js +22 -4
- package/src/lib/utils/hooks/useTransactionEstimatedGas/index.d.ts +1 -0
- package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.cjs +31 -0
- package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.d.ts +20 -0
- package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.js +27 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/index.d.ts +1 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.cjs +56 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.d.ts +32 -0
- package/src/lib/utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.js +52 -0
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.cjs +1 -0
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.js +1 -0
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.d.ts +1 -1
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.cjs +2 -2
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.d.ts +5 -1
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.js +2 -2
- package/src/lib/utils/hooks/useWallets/useWallets.d.ts +2 -2
- package/src/lib/views/CollectUserDataView/UserDataFields/index.cjs +4 -0
- package/src/lib/views/CollectUserDataView/UserDataFields/index.js +4 -0
- package/src/lib/views/EmailUpdate/EmailUpdate.cjs +13 -4
- package/src/lib/views/EmailUpdate/EmailUpdate.js +13 -4
- package/src/lib/views/EmailVerification/EmailVerification.cjs +12 -1
- package/src/lib/views/EmailVerification/EmailVerification.js +14 -3
- package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.cjs +3 -2
- package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.js +3 -2
- package/src/lib/views/LoginWithEmailView/components/LoginWithEmailWalletList/LoginWithEmailWalletList.cjs +4 -1
- package/src/lib/views/LoginWithEmailView/components/LoginWithEmailWalletList/LoginWithEmailWalletList.js +4 -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/MergeUserAccountsView/MergeUserAccountsView.cjs +111 -0
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.d.ts +2 -0
- package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.js +107 -0
- package/src/lib/views/MergeUserAccountsView/index.d.ts +1 -0
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +1 -0
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +1 -0
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.cjs +1 -0
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.js +1 -0
- package/src/lib/views/SendBalanceView/SendBalanceView.cjs +14 -35
- package/src/lib/views/SendBalanceView/SendBalanceView.d.ts +2 -2
- package/src/lib/views/SendBalanceView/SendBalanceView.js +15 -36
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.cjs +73 -0
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.d.ts +8 -0
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.js +69 -0
- package/src/lib/views/SendBalanceView/components/TransactionStage/index.d.ts +1 -0
- package/src/lib/views/SendBalanceView/components/index.d.ts +1 -0
- package/src/lib/views/SocialRedirectView/SocialRedirectView.cjs +1 -2
- package/src/lib/views/SocialRedirectView/SocialRedirectView.js +1 -2
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.cjs +31 -8
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.d.ts +4 -3
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.js +32 -9
- package/src/lib/views/TransactionConfirmationView/hooks/index.d.ts +2 -1
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/index.d.ts +1 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/useTransactionGas.cjs +69 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/useTransactionGas.d.ts +11 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/useTransactionGas.js +65 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionTotal/index.d.ts +1 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionTotal/useTransactionTotal.cjs +14 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionTotal/useTransactionTotal.d.ts +6 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionTotal/useTransactionTotal.js +10 -0
- package/src/lib/views/WalletList/WalletList.cjs +4 -1
- package/src/lib/views/WalletList/WalletList.js +4 -1
- package/src/lib/views/WalletLockedView/WalletLockedView.cjs +20 -4
- package/src/lib/views/WalletLockedView/WalletLockedView.js +20 -4
- package/src/lib/views/viewToComponentMap.cjs +2 -0
- package/src/lib/views/viewToComponentMap.js +2 -0
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/index.d.ts +0 -1
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.cjs +0 -104
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.d.ts +0 -17
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.js +0 -100
|
@@ -3,7 +3,8 @@ type Props = {
|
|
|
3
3
|
fetchPublicAddressOpts?: FetchPublicAddressOpts;
|
|
4
4
|
walletConnector: WalletConnector;
|
|
5
5
|
};
|
|
6
|
-
export declare const useConnectAndSign: ({ shouldUpdateWallets }?: {
|
|
6
|
+
export declare const useConnectAndSign: ({ shouldUpdateWallets, shouldCallCallback, }?: {
|
|
7
7
|
shouldUpdateWallets?: boolean | undefined;
|
|
8
|
+
shouldCallCallback?: boolean | undefined;
|
|
8
9
|
}) => ({ walletConnector, fetchPublicAddressOpts, }: Props) => Promise<void>;
|
|
9
10
|
export {};
|
|
@@ -24,7 +24,7 @@ import '@dynamic-labs/multi-wallet';
|
|
|
24
24
|
import { isSupportedNetwork } from '../../../functions/isSupportedNetwork/isSupportedNetwork.js';
|
|
25
25
|
import { isProgrammableNetworkSwitchSupported } from '../../../functions/isProgrammableNetworkSwitchSupported/isProgrammableNetworkSwitchSupported.js';
|
|
26
26
|
|
|
27
|
-
const useConnectAndSign = ({ shouldUpdateWallets = true } = {}) => {
|
|
27
|
+
const useConnectAndSign = ({ shouldUpdateWallets = true, shouldCallCallback = true, } = {}) => {
|
|
28
28
|
const { setView, goToInitialView } = useViewContext();
|
|
29
29
|
const { setErrorMessage } = useErrorContext();
|
|
30
30
|
const { captchaToken } = useCaptchaContext();
|
|
@@ -51,7 +51,7 @@ const useConnectAndSign = ({ shouldUpdateWallets = true } = {}) => {
|
|
|
51
51
|
setView('wait-for-email-confirmation-view');
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
const publicWalletAddress = yield connectWallet(walletConnector, fetchPublicAddressOpts);
|
|
54
|
+
const publicWalletAddress = yield connectWallet(walletConnector, fetchPublicAddressOpts, shouldCallCallback);
|
|
55
55
|
if (!publicWalletAddress) {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
@@ -31,3 +31,5 @@ export { useCountdown } from './useCountdown/useCountdown';
|
|
|
31
31
|
export { useValidateSession } from './useValidateSession';
|
|
32
32
|
export { useEventListener } from './useEventListener';
|
|
33
33
|
export { useWalletConnectorEvent } from './useWalletConnectorEvent';
|
|
34
|
+
export { useTransactionWithGasPrice } from './useTransactionWithGasPrice';
|
|
35
|
+
export { useTransactionEstimatedGas } from './useTransactionEstimatedGas';
|
|
@@ -3,13 +3,29 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
|
+
require('@dynamic-labs/sdk-api');
|
|
7
|
+
require('../../../../shared/logger.cjs');
|
|
8
|
+
require('@dynamic-labs/iconic');
|
|
9
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
10
|
+
require('react/jsx-runtime');
|
|
11
|
+
require('../../../../context/ViewContext/ViewContext.cjs');
|
|
12
|
+
require('@dynamic-labs/wallet-book');
|
|
13
|
+
require('@dynamic-labs/utils');
|
|
14
|
+
var localStorage = require('../../../constants/localStorage.cjs');
|
|
15
|
+
require('../../../constants/colors.cjs');
|
|
16
|
+
require('../../../../shared/utils/classes/storage/localStorage.cjs');
|
|
17
|
+
require('viem');
|
|
18
|
+
var useLocalStorage = require('../../../../shared/utils/hooks/useLocalStorage/useLocalStorage.cjs');
|
|
19
|
+
require('../../../../shared/consts/index.cjs');
|
|
6
20
|
|
|
7
21
|
const useMultiWallet = (multiWalletSettings) => {
|
|
8
22
|
const isMultiWalletEnabled = multiWalletSettings !== null && multiWalletSettings !== void 0 ? multiWalletSettings : false;
|
|
9
|
-
const [multiWallet, setMultiWallet] =
|
|
23
|
+
const [multiWallet, setMultiWallet] = useLocalStorage.useLocalStorage(localStorage.IS_MULTI_WALLET_ENABLED, isMultiWalletEnabled);
|
|
10
24
|
React.useEffect(() => {
|
|
11
|
-
|
|
12
|
-
|
|
25
|
+
if (multiWalletSettings) {
|
|
26
|
+
setMultiWallet(multiWalletSettings);
|
|
27
|
+
}
|
|
28
|
+
}, [multiWalletSettings]);
|
|
13
29
|
return { multiWallet, setMultiWallet };
|
|
14
30
|
};
|
|
15
31
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export declare const useMultiWallet: (multiWalletSettings?: boolean) => {
|
|
3
2
|
multiWallet: boolean;
|
|
4
|
-
setMultiWallet:
|
|
3
|
+
setMultiWallet: (value: boolean | ((val: boolean) => boolean)) => void;
|
|
5
4
|
};
|
|
@@ -1,11 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import '@dynamic-labs/sdk-api';
|
|
3
|
+
import '../../../../shared/logger.js';
|
|
4
|
+
import '@dynamic-labs/iconic';
|
|
5
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
6
|
+
import 'react/jsx-runtime';
|
|
7
|
+
import '../../../../context/ViewContext/ViewContext.js';
|
|
8
|
+
import '@dynamic-labs/wallet-book';
|
|
9
|
+
import '@dynamic-labs/utils';
|
|
10
|
+
import { IS_MULTI_WALLET_ENABLED } from '../../../constants/localStorage.js';
|
|
11
|
+
import '../../../constants/colors.js';
|
|
12
|
+
import '../../../../shared/utils/classes/storage/localStorage.js';
|
|
13
|
+
import 'viem';
|
|
14
|
+
import { useLocalStorage } from '../../../../shared/utils/hooks/useLocalStorage/useLocalStorage.js';
|
|
15
|
+
import '../../../../shared/consts/index.js';
|
|
2
16
|
|
|
3
17
|
const useMultiWallet = (multiWalletSettings) => {
|
|
4
18
|
const isMultiWalletEnabled = multiWalletSettings !== null && multiWalletSettings !== void 0 ? multiWalletSettings : false;
|
|
5
|
-
const [multiWallet, setMultiWallet] =
|
|
19
|
+
const [multiWallet, setMultiWallet] = useLocalStorage(IS_MULTI_WALLET_ENABLED, isMultiWalletEnabled);
|
|
6
20
|
useEffect(() => {
|
|
7
|
-
|
|
8
|
-
|
|
21
|
+
if (multiWalletSettings) {
|
|
22
|
+
setMultiWallet(multiWalletSettings);
|
|
23
|
+
}
|
|
24
|
+
}, [multiWalletSettings]);
|
|
9
25
|
return { multiWallet, setMultiWallet };
|
|
10
26
|
};
|
|
11
27
|
|
|
@@ -4,15 +4,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
7
8
|
var isWalletLinked = require('../../../functions/isWalletLinked/isWalletLinked.cjs');
|
|
8
9
|
var ViewContext = require('../../../../context/ViewContext/ViewContext.cjs');
|
|
9
|
-
var AccountExistsContext = require('../../../../context/AccountExistsContext/AccountExistsContext.cjs');
|
|
10
10
|
var useInternalDynamicContext = require('../../../../context/DynamicContext/useInternalDynamicContext.cjs');
|
|
11
|
+
var errors = require('../../../constants/errors.cjs');
|
|
11
12
|
|
|
12
13
|
const useSyncPrimaryWallet = ({ connectWallet, computeConnectedStateForWallets, handleLogOut, multiWalletWidgetState, primaryWallet, secondaryWallets, setMultiWalletWidgetState, setPrimaryWallet, setShowWidgetStatePopup, showWidgetStatePopup, canSync = true, authMode, }) => {
|
|
13
|
-
const { setShowAuthFlow } = useInternalDynamicContext.useInternalDynamicContext();
|
|
14
|
+
const { setShowAuthFlow, isAuthenticated } = useInternalDynamicContext.useInternalDynamicContext();
|
|
14
15
|
const { setView } = ViewContext.useViewContext();
|
|
15
|
-
const { existentAccountData } = AccountExistsContext.useAccountExistsContext();
|
|
16
16
|
const handlePrimaryWalletNotActive = React.useCallback((connectedAddress) => {
|
|
17
17
|
if (!primaryWallet)
|
|
18
18
|
return;
|
|
@@ -76,23 +76,24 @@ const useSyncPrimaryWallet = ({ connectWallet, computeConnectedStateForWallets,
|
|
|
76
76
|
.getConnectedAccounts()
|
|
77
77
|
.then((accounts) => {
|
|
78
78
|
const [connectedAddress] = accounts;
|
|
79
|
+
if (!connectedAddress) {
|
|
80
|
+
throw new utils.DynamicError('Missing wallet address', errors.MISSING_ADDRESS_ERROR);
|
|
81
|
+
}
|
|
79
82
|
if (walletConnectorCore.isSameAddress(connectedAddress, primaryWallet.address, primaryWallet.chain)) {
|
|
80
83
|
return;
|
|
81
84
|
}
|
|
82
85
|
handlePrimaryWalletNotActive(connectedAddress);
|
|
83
86
|
})
|
|
84
|
-
.catch(() => {
|
|
87
|
+
.catch((e) => {
|
|
85
88
|
const connectedSecondaryWallet = secondaryWallets.find((wallet) => wallet.connected);
|
|
86
89
|
if (connectedSecondaryWallet) {
|
|
87
90
|
setPrimaryWallet(connectedSecondaryWallet.id);
|
|
88
91
|
computeConnectedStateForWallets();
|
|
89
92
|
return;
|
|
90
93
|
}
|
|
91
|
-
// no wallet is connected
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// doesn't overwrite 'account-exists' view
|
|
95
|
-
if (!existentAccountData) {
|
|
94
|
+
// user is logged in (has valid jwt), but no wallet is connected
|
|
95
|
+
if (isAuthenticated && e.code === errors.MISSING_ADDRESS_ERROR) {
|
|
96
|
+
setShowAuthFlow(true);
|
|
96
97
|
setView('wallet-locked-view');
|
|
97
98
|
}
|
|
98
99
|
});
|
|
@@ -109,6 +110,7 @@ const useSyncPrimaryWallet = ({ connectWallet, computeConnectedStateForWallets,
|
|
|
109
110
|
setView,
|
|
110
111
|
setShowAuthFlow,
|
|
111
112
|
authMode,
|
|
113
|
+
isAuthenticated,
|
|
112
114
|
]);
|
|
113
115
|
};
|
|
114
116
|
|
|
@@ -4,7 +4,7 @@ import { AuthModeType, MultiWalletWidgetState, Wallet } from '../../../../shared
|
|
|
4
4
|
import { MultiWalletWidgetStateSetter } from '../useMultiWalletWidgetState';
|
|
5
5
|
export type UseSyncPrimaryWalletArgs = {
|
|
6
6
|
canSync?: boolean;
|
|
7
|
-
connectWallet: (walletConnector: WalletConnector, fetchPublicAddressOpts?: FetchPublicAddressOpts) => Promise<string | undefined>;
|
|
7
|
+
connectWallet: (walletConnector: WalletConnector, fetchPublicAddressOpts?: FetchPublicAddressOpts, shouldCallCallback?: boolean) => Promise<string | undefined>;
|
|
8
8
|
computeConnectedStateForWallets: () => Promise<void>;
|
|
9
9
|
handleLogOut: () => Promise<void>;
|
|
10
10
|
multiWalletWidgetState: MultiWalletWidgetState;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { useCallback, useEffect } from 'react';
|
|
2
2
|
import { isSameAddress } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
3
4
|
import { isWalletLinked } from '../../../functions/isWalletLinked/isWalletLinked.js';
|
|
4
5
|
import { useViewContext } from '../../../../context/ViewContext/ViewContext.js';
|
|
5
|
-
import { useAccountExistsContext } from '../../../../context/AccountExistsContext/AccountExistsContext.js';
|
|
6
6
|
import { useInternalDynamicContext } from '../../../../context/DynamicContext/useInternalDynamicContext.js';
|
|
7
|
+
import { MISSING_ADDRESS_ERROR } from '../../../constants/errors.js';
|
|
7
8
|
|
|
8
9
|
const useSyncPrimaryWallet = ({ connectWallet, computeConnectedStateForWallets, handleLogOut, multiWalletWidgetState, primaryWallet, secondaryWallets, setMultiWalletWidgetState, setPrimaryWallet, setShowWidgetStatePopup, showWidgetStatePopup, canSync = true, authMode, }) => {
|
|
9
|
-
const { setShowAuthFlow } = useInternalDynamicContext();
|
|
10
|
+
const { setShowAuthFlow, isAuthenticated } = useInternalDynamicContext();
|
|
10
11
|
const { setView } = useViewContext();
|
|
11
|
-
const { existentAccountData } = useAccountExistsContext();
|
|
12
12
|
const handlePrimaryWalletNotActive = useCallback((connectedAddress) => {
|
|
13
13
|
if (!primaryWallet)
|
|
14
14
|
return;
|
|
@@ -72,23 +72,24 @@ const useSyncPrimaryWallet = ({ connectWallet, computeConnectedStateForWallets,
|
|
|
72
72
|
.getConnectedAccounts()
|
|
73
73
|
.then((accounts) => {
|
|
74
74
|
const [connectedAddress] = accounts;
|
|
75
|
+
if (!connectedAddress) {
|
|
76
|
+
throw new DynamicError('Missing wallet address', MISSING_ADDRESS_ERROR);
|
|
77
|
+
}
|
|
75
78
|
if (isSameAddress(connectedAddress, primaryWallet.address, primaryWallet.chain)) {
|
|
76
79
|
return;
|
|
77
80
|
}
|
|
78
81
|
handlePrimaryWalletNotActive(connectedAddress);
|
|
79
82
|
})
|
|
80
|
-
.catch(() => {
|
|
83
|
+
.catch((e) => {
|
|
81
84
|
const connectedSecondaryWallet = secondaryWallets.find((wallet) => wallet.connected);
|
|
82
85
|
if (connectedSecondaryWallet) {
|
|
83
86
|
setPrimaryWallet(connectedSecondaryWallet.id);
|
|
84
87
|
computeConnectedStateForWallets();
|
|
85
88
|
return;
|
|
86
89
|
}
|
|
87
|
-
// no wallet is connected
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
// doesn't overwrite 'account-exists' view
|
|
91
|
-
if (!existentAccountData) {
|
|
90
|
+
// user is logged in (has valid jwt), but no wallet is connected
|
|
91
|
+
if (isAuthenticated && e.code === MISSING_ADDRESS_ERROR) {
|
|
92
|
+
setShowAuthFlow(true);
|
|
92
93
|
setView('wallet-locked-view');
|
|
93
94
|
}
|
|
94
95
|
});
|
|
@@ -105,6 +106,7 @@ const useSyncPrimaryWallet = ({ connectWallet, computeConnectedStateForWallets,
|
|
|
105
106
|
setView,
|
|
106
107
|
setShowAuthFlow,
|
|
107
108
|
authMode,
|
|
109
|
+
isAuthenticated,
|
|
108
110
|
]);
|
|
109
111
|
};
|
|
110
112
|
|
|
@@ -68,7 +68,8 @@ const useAuthLayoutChecks = (walletConnector) => {
|
|
|
68
68
|
view === 'login-with-email-or-wallet-full-wallet-list' ||
|
|
69
69
|
view === 'wallet-group' ||
|
|
70
70
|
view === 'pending-connect' ||
|
|
71
|
-
view === 'account-exists'
|
|
71
|
+
view === 'account-exists' ||
|
|
72
|
+
(view === 'merge-user-accounts' && !user);
|
|
72
73
|
const showQrCodePreHeader = view === 'qr-code' && showQrCodeMessage && !showQrCodeImage;
|
|
73
74
|
return {
|
|
74
75
|
isWalletListTypeView,
|
|
@@ -64,7 +64,8 @@ const useAuthLayoutChecks = (walletConnector) => {
|
|
|
64
64
|
view === 'login-with-email-or-wallet-full-wallet-list' ||
|
|
65
65
|
view === 'wallet-group' ||
|
|
66
66
|
view === 'pending-connect' ||
|
|
67
|
-
view === 'account-exists'
|
|
67
|
+
view === 'account-exists' ||
|
|
68
|
+
(view === 'merge-user-accounts' && !user);
|
|
68
69
|
const showQrCodePreHeader = view === 'qr-code' && showQrCodeMessage && !showQrCodeImage;
|
|
69
70
|
return {
|
|
70
71
|
isWalletListTypeView,
|
|
@@ -132,14 +132,14 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
132
132
|
});
|
|
133
133
|
const shouldSkipCreatingVisit = React.useMemo(() => (authMode === 'connect-only' && !enableVisitTrackingOnConnectOnly) ||
|
|
134
134
|
connectedWallet, [authMode, connectedWallet, enableVisitTrackingOnConnectOnly]);
|
|
135
|
-
const connectWallet = (walletConnector, fetchPublicAddressOpts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
+
const connectWallet = (walletConnector, fetchPublicAddressOpts, shouldCallCallback = true) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
136
136
|
const publicWalletAddress = yield walletConnector.fetchPublicAddress(fetchPublicAddressOpts);
|
|
137
137
|
if (!publicWalletAddress) {
|
|
138
138
|
const error = new Error();
|
|
139
139
|
error.code = 'missing-public-address';
|
|
140
140
|
throw error;
|
|
141
141
|
}
|
|
142
|
-
if (onBeforeConnectSuccessConfirmation) {
|
|
142
|
+
if (onBeforeConnectSuccessConfirmation && shouldCallCallback) {
|
|
143
143
|
const shouldProceedWithConnection = yield onBeforeConnectSuccessConfirmation({
|
|
144
144
|
address: publicWalletAddress,
|
|
145
145
|
chain: walletConnector.connectedChain,
|
|
@@ -21,7 +21,7 @@ type Props = {
|
|
|
21
21
|
setShowAuthFlow: Dispatch<SetStateAction<boolean>>;
|
|
22
22
|
};
|
|
23
23
|
export declare const useConnectWallet: ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets, onUnlink, onBeforeConnectSuccessConfirmation, setShowAuthFlow, }: Props) => {
|
|
24
|
-
connectWallet: (walletConnector: WalletConnector, fetchPublicAddressOpts?: FetchPublicAddressOpts) => Promise<string | undefined>;
|
|
24
|
+
connectWallet: (walletConnector: WalletConnector, fetchPublicAddressOpts?: FetchPublicAddressOpts, shouldCallCallback?: boolean) => Promise<string | undefined>;
|
|
25
25
|
connectedWallet: Wallet;
|
|
26
26
|
connectedWallets: Wallet[];
|
|
27
27
|
connectedWalletsInfo: ConnectedWalletConnectorType[] | [];
|
|
@@ -128,14 +128,14 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
|
|
|
128
128
|
});
|
|
129
129
|
const shouldSkipCreatingVisit = useMemo(() => (authMode === 'connect-only' && !enableVisitTrackingOnConnectOnly) ||
|
|
130
130
|
connectedWallet, [authMode, connectedWallet, enableVisitTrackingOnConnectOnly]);
|
|
131
|
-
const connectWallet = (walletConnector, fetchPublicAddressOpts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
131
|
+
const connectWallet = (walletConnector, fetchPublicAddressOpts, shouldCallCallback = true) => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
132
|
const publicWalletAddress = yield walletConnector.fetchPublicAddress(fetchPublicAddressOpts);
|
|
133
133
|
if (!publicWalletAddress) {
|
|
134
134
|
const error = new Error();
|
|
135
135
|
error.code = 'missing-public-address';
|
|
136
136
|
throw error;
|
|
137
137
|
}
|
|
138
|
-
if (onBeforeConnectSuccessConfirmation) {
|
|
138
|
+
if (onBeforeConnectSuccessConfirmation && shouldCallCallback) {
|
|
139
139
|
const shouldProceedWithConnection = yield onBeforeConnectSuccessConfirmation({
|
|
140
140
|
address: publicWalletAddress,
|
|
141
141
|
chain: walletConnector.connectedChain,
|
|
@@ -19,6 +19,7 @@ require('viem');
|
|
|
19
19
|
var useLocalStorage = require('../../../shared/utils/hooks/useLocalStorage/useLocalStorage.cjs');
|
|
20
20
|
require('../../../shared/consts/index.cjs');
|
|
21
21
|
var validators = require('../../../context/DynamicContext/validators.cjs');
|
|
22
|
+
var mergeCustomerEvmNetworksWithServerNetworks = require('./utils/mergeCustomerEvmNetworksWithServerNetworks/mergeCustomerEvmNetworksWithServerNetworks.cjs');
|
|
22
23
|
|
|
23
24
|
const MAX_RETRIES = 2;
|
|
24
25
|
const useFetchNetworkConfigurations = ({ authToken, environmentId, evmNetworks: customerEvmNetworks, maxRetries = MAX_RETRIES, }) => {
|
|
@@ -113,13 +114,7 @@ const useFetchNetworkConfigurations = ({ authToken, environmentId, evmNetworks:
|
|
|
113
114
|
serverNetworks.length &&
|
|
114
115
|
customerEvmNetworks !== undefined &&
|
|
115
116
|
customerEvmNetworks.length) {
|
|
116
|
-
mergedEvmNetworks =
|
|
117
|
-
serverNetworks.forEach((network) => {
|
|
118
|
-
const existingNetwork = mergedEvmNetworks === null || mergedEvmNetworks === void 0 ? void 0 : mergedEvmNetworks.find((item) => item.chainId === network.chainId);
|
|
119
|
-
if (!existingNetwork) {
|
|
120
|
-
mergedEvmNetworks === null || mergedEvmNetworks === void 0 ? void 0 : mergedEvmNetworks.push(network);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
117
|
+
mergedEvmNetworks = mergeCustomerEvmNetworksWithServerNetworks.mergeCustomerEvmNetworksWithServerNetworks(customerEvmNetworks, serverNetworks);
|
|
123
118
|
}
|
|
124
119
|
setLsNetworks({
|
|
125
120
|
configurations: {
|
|
@@ -15,6 +15,7 @@ import 'viem';
|
|
|
15
15
|
import { useLocalStorage } from '../../../shared/utils/hooks/useLocalStorage/useLocalStorage.js';
|
|
16
16
|
import '../../../shared/consts/index.js';
|
|
17
17
|
import { validateLocalStorageExpiry } from '../../../context/DynamicContext/validators.js';
|
|
18
|
+
import { mergeCustomerEvmNetworksWithServerNetworks } from './utils/mergeCustomerEvmNetworksWithServerNetworks/mergeCustomerEvmNetworksWithServerNetworks.js';
|
|
18
19
|
|
|
19
20
|
const MAX_RETRIES = 2;
|
|
20
21
|
const useFetchNetworkConfigurations = ({ authToken, environmentId, evmNetworks: customerEvmNetworks, maxRetries = MAX_RETRIES, }) => {
|
|
@@ -109,13 +110,7 @@ const useFetchNetworkConfigurations = ({ authToken, environmentId, evmNetworks:
|
|
|
109
110
|
serverNetworks.length &&
|
|
110
111
|
customerEvmNetworks !== undefined &&
|
|
111
112
|
customerEvmNetworks.length) {
|
|
112
|
-
mergedEvmNetworks = customerEvmNetworks
|
|
113
|
-
serverNetworks.forEach((network) => {
|
|
114
|
-
const existingNetwork = mergedEvmNetworks === null || mergedEvmNetworks === void 0 ? void 0 : mergedEvmNetworks.find((item) => item.chainId === network.chainId);
|
|
115
|
-
if (!existingNetwork) {
|
|
116
|
-
mergedEvmNetworks === null || mergedEvmNetworks === void 0 ? void 0 : mergedEvmNetworks.push(network);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
113
|
+
mergedEvmNetworks = mergeCustomerEvmNetworksWithServerNetworks(customerEvmNetworks, serverNetworks);
|
|
119
114
|
}
|
|
120
115
|
setLsNetworks({
|
|
121
116
|
configurations: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mergeCustomerEvmNetworksWithServerNetworks';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { mergeCustomerEvmNetworksWithServerNetworks } from './mergeCustomerEvmNetworksWithServerNetworks';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const mergeCustomerEvmNetworksWithServerNetworks = (customerEvmNetworks, serverNetworks) => {
|
|
6
|
+
const evmNetworks = [...customerEvmNetworks];
|
|
7
|
+
serverNetworks.forEach((network) => {
|
|
8
|
+
const existingNetwork = evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.find((item) => item.chainId === network.chainId);
|
|
9
|
+
if (!existingNetwork) {
|
|
10
|
+
evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.unshift(network);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
return evmNetworks;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.mergeCustomerEvmNetworksWithServerNetworks = mergeCustomerEvmNetworksWithServerNetworks;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const mergeCustomerEvmNetworksWithServerNetworks = (customerEvmNetworks, serverNetworks) => {
|
|
2
|
+
const evmNetworks = [...customerEvmNetworks];
|
|
3
|
+
serverNetworks.forEach((network) => {
|
|
4
|
+
const existingNetwork = evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.find((item) => item.chainId === network.chainId);
|
|
5
|
+
if (!existingNetwork) {
|
|
6
|
+
evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.unshift(network);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
return evmNetworks;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { mergeCustomerEvmNetworksWithServerNetworks };
|
|
@@ -24,6 +24,15 @@ var getAuthToken = require('../../functions/getAuthToken/getAuthToken.cjs');
|
|
|
24
24
|
var index = require('../../functions/getEnabledOAuthProviders/index.cjs');
|
|
25
25
|
var isSocialKycEnabled = require('../../functions/isSocialKycEnabled/isSocialKycEnabled.cjs');
|
|
26
26
|
|
|
27
|
+
const socialProviders = [
|
|
28
|
+
'discord',
|
|
29
|
+
'facebook',
|
|
30
|
+
'github',
|
|
31
|
+
'google',
|
|
32
|
+
'instagram',
|
|
33
|
+
'twitch',
|
|
34
|
+
'twitter',
|
|
35
|
+
];
|
|
27
36
|
const useSocialAccounts = () => {
|
|
28
37
|
var _a;
|
|
29
38
|
const { environmentId, user, projectSettings, onboardingOnlyJwt } = useInternalDynamicContext.useInternalDynamicContext();
|
|
@@ -48,6 +57,17 @@ const useSocialAccounts = () => {
|
|
|
48
57
|
setIsProcessing(false);
|
|
49
58
|
setError(message);
|
|
50
59
|
};
|
|
60
|
+
const checkValidProvider = (provider) => {
|
|
61
|
+
if (!provider) {
|
|
62
|
+
handleError('Provider is required');
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
if (!socialProviders.includes(provider)) {
|
|
66
|
+
handleError(`Invalid social provider. Valid providers are: ${socialProviders.join(', ')}`);
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
};
|
|
51
71
|
const linkSocialAccount = (provider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
52
72
|
setError(undefined);
|
|
53
73
|
setIsProcessing(true);
|
|
@@ -55,8 +75,7 @@ const useSocialAccounts = () => {
|
|
|
55
75
|
handleError('Social linking is not enabled on the dashboard');
|
|
56
76
|
return;
|
|
57
77
|
}
|
|
58
|
-
if (!provider) {
|
|
59
|
-
handleError('Provider is required');
|
|
78
|
+
if (!checkValidProvider(provider)) {
|
|
60
79
|
return;
|
|
61
80
|
}
|
|
62
81
|
const verifiedCredential = verifiedOAuthCredentialsMap[provider];
|
|
@@ -103,8 +122,7 @@ const useSocialAccounts = () => {
|
|
|
103
122
|
var _e;
|
|
104
123
|
setError(undefined);
|
|
105
124
|
setIsProcessing(true);
|
|
106
|
-
if (!provider) {
|
|
107
|
-
handleError('Provider is required');
|
|
125
|
+
if (!checkValidProvider(provider)) {
|
|
108
126
|
return;
|
|
109
127
|
}
|
|
110
128
|
const verifiedCredential = verifiedOAuthCredentialsMap[provider];
|
|
@@ -20,6 +20,15 @@ import { getAuthToken } from '../../functions/getAuthToken/getAuthToken.js';
|
|
|
20
20
|
import { getEnabledOAuthProviders } from '../../functions/getEnabledOAuthProviders/index.js';
|
|
21
21
|
import { isSocialKycEnabled } from '../../functions/isSocialKycEnabled/isSocialKycEnabled.js';
|
|
22
22
|
|
|
23
|
+
const socialProviders = [
|
|
24
|
+
'discord',
|
|
25
|
+
'facebook',
|
|
26
|
+
'github',
|
|
27
|
+
'google',
|
|
28
|
+
'instagram',
|
|
29
|
+
'twitch',
|
|
30
|
+
'twitter',
|
|
31
|
+
];
|
|
23
32
|
const useSocialAccounts = () => {
|
|
24
33
|
var _a;
|
|
25
34
|
const { environmentId, user, projectSettings, onboardingOnlyJwt } = useInternalDynamicContext();
|
|
@@ -44,6 +53,17 @@ const useSocialAccounts = () => {
|
|
|
44
53
|
setIsProcessing(false);
|
|
45
54
|
setError(message);
|
|
46
55
|
};
|
|
56
|
+
const checkValidProvider = (provider) => {
|
|
57
|
+
if (!provider) {
|
|
58
|
+
handleError('Provider is required');
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (!socialProviders.includes(provider)) {
|
|
62
|
+
handleError(`Invalid social provider. Valid providers are: ${socialProviders.join(', ')}`);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
47
67
|
const linkSocialAccount = (provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
68
|
setError(undefined);
|
|
49
69
|
setIsProcessing(true);
|
|
@@ -51,8 +71,7 @@ const useSocialAccounts = () => {
|
|
|
51
71
|
handleError('Social linking is not enabled on the dashboard');
|
|
52
72
|
return;
|
|
53
73
|
}
|
|
54
|
-
if (!provider) {
|
|
55
|
-
handleError('Provider is required');
|
|
74
|
+
if (!checkValidProvider(provider)) {
|
|
56
75
|
return;
|
|
57
76
|
}
|
|
58
77
|
const verifiedCredential = verifiedOAuthCredentialsMap[provider];
|
|
@@ -99,8 +118,7 @@ const useSocialAccounts = () => {
|
|
|
99
118
|
var _e;
|
|
100
119
|
setError(undefined);
|
|
101
120
|
setIsProcessing(true);
|
|
102
|
-
if (!provider) {
|
|
103
|
-
handleError('Provider is required');
|
|
121
|
+
if (!checkValidProvider(provider)) {
|
|
104
122
|
return;
|
|
105
123
|
}
|
|
106
124
|
const verifiedCredential = verifiedOAuthCredentialsMap[provider];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTransactionEstimatedGas } from './useTransactionEstimatedGas';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
6
|
+
var usePromise = require('../usePromise/usePromise.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hook to estimate the gas required for a transaction.
|
|
10
|
+
*
|
|
11
|
+
* This hook uses the `usePromise` hook to asynchronously estimate the gas required for a transaction.
|
|
12
|
+
* It first tries to estimate the gas without the 'from' field in the transaction, as the Alchemy API
|
|
13
|
+
* checks the origin address funds and can return an error if the origin wallet has no funds for the transaction.
|
|
14
|
+
* If the error 'UNPREDICTABLE_GAS_LIMIT' is encountered, it tries to estimate the gas again with the
|
|
15
|
+
* original transaction.
|
|
16
|
+
*
|
|
17
|
+
* @see {@link https://docs.alchemy.com/reference/eth-estimategas}
|
|
18
|
+
* @see {@link https://docs.ethers.org/v5/troubleshooting/errors/#help-UNPREDICTABLE_GAS_LIMIT}
|
|
19
|
+
*
|
|
20
|
+
* @param {ethers.providers.Web3Provider} provider - The Web3 provider to use for estimating the gas.
|
|
21
|
+
* @param {ethers.utils.Deferrable<ethers.providers.TransactionRequest>} transaction - The transaction for
|
|
22
|
+
* which to estimate the gas.
|
|
23
|
+
*
|
|
24
|
+
* @returns {PromiseState<ethers.BigNumber>} A promise that resolves to the estimated gas for the transaction.
|
|
25
|
+
*/
|
|
26
|
+
const useTransactionEstimatedGas = (provider, transaction) => usePromise.usePromise(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const { from } = transaction, transactionWithoutFrom = _tslib.__rest(transaction, ["from"]);
|
|
28
|
+
return provider.estimateGas(Object.assign(Object.assign({}, transactionWithoutFrom), { account: from }));
|
|
29
|
+
}), { deps: [transaction, provider] });
|
|
30
|
+
|
|
31
|
+
exports.useTransactionEstimatedGas = useTransactionEstimatedGas;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PublicClient, TransactionRequest } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to estimate the gas required for a transaction.
|
|
4
|
+
*
|
|
5
|
+
* This hook uses the `usePromise` hook to asynchronously estimate the gas required for a transaction.
|
|
6
|
+
* It first tries to estimate the gas without the 'from' field in the transaction, as the Alchemy API
|
|
7
|
+
* checks the origin address funds and can return an error if the origin wallet has no funds for the transaction.
|
|
8
|
+
* If the error 'UNPREDICTABLE_GAS_LIMIT' is encountered, it tries to estimate the gas again with the
|
|
9
|
+
* original transaction.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://docs.alchemy.com/reference/eth-estimategas}
|
|
12
|
+
* @see {@link https://docs.ethers.org/v5/troubleshooting/errors/#help-UNPREDICTABLE_GAS_LIMIT}
|
|
13
|
+
*
|
|
14
|
+
* @param {ethers.providers.Web3Provider} provider - The Web3 provider to use for estimating the gas.
|
|
15
|
+
* @param {ethers.utils.Deferrable<ethers.providers.TransactionRequest>} transaction - The transaction for
|
|
16
|
+
* which to estimate the gas.
|
|
17
|
+
*
|
|
18
|
+
* @returns {PromiseState<ethers.BigNumber>} A promise that resolves to the estimated gas for the transaction.
|
|
19
|
+
*/
|
|
20
|
+
export declare const useTransactionEstimatedGas: (provider: PublicClient, transaction: TransactionRequest) => import("../usePromise").PromiseState<bigint, Error>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { __awaiter, __rest } from '../../../../../_virtual/_tslib.js';
|
|
2
|
+
import { usePromise } from '../usePromise/usePromise.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Hook to estimate the gas required for a transaction.
|
|
6
|
+
*
|
|
7
|
+
* This hook uses the `usePromise` hook to asynchronously estimate the gas required for a transaction.
|
|
8
|
+
* It first tries to estimate the gas without the 'from' field in the transaction, as the Alchemy API
|
|
9
|
+
* checks the origin address funds and can return an error if the origin wallet has no funds for the transaction.
|
|
10
|
+
* If the error 'UNPREDICTABLE_GAS_LIMIT' is encountered, it tries to estimate the gas again with the
|
|
11
|
+
* original transaction.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://docs.alchemy.com/reference/eth-estimategas}
|
|
14
|
+
* @see {@link https://docs.ethers.org/v5/troubleshooting/errors/#help-UNPREDICTABLE_GAS_LIMIT}
|
|
15
|
+
*
|
|
16
|
+
* @param {ethers.providers.Web3Provider} provider - The Web3 provider to use for estimating the gas.
|
|
17
|
+
* @param {ethers.utils.Deferrable<ethers.providers.TransactionRequest>} transaction - The transaction for
|
|
18
|
+
* which to estimate the gas.
|
|
19
|
+
*
|
|
20
|
+
* @returns {PromiseState<ethers.BigNumber>} A promise that resolves to the estimated gas for the transaction.
|
|
21
|
+
*/
|
|
22
|
+
const useTransactionEstimatedGas = (provider, transaction) => usePromise(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
const { from } = transaction, transactionWithoutFrom = __rest(transaction, ["from"]);
|
|
24
|
+
return provider.estimateGas(Object.assign(Object.assign({}, transactionWithoutFrom), { account: from }));
|
|
25
|
+
}), { deps: [transaction, provider] });
|
|
26
|
+
|
|
27
|
+
export { useTransactionEstimatedGas };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTransactionWithGasPrice } from './useTransactionWithGasPrice';
|