@dynamic-labs/sdk-react-core 0.19.0-alpha.0 → 0.19.0-alpha.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.
Files changed (131) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/package.cjs +3 -3
  3. package/package.js +3 -3
  4. package/package.json +11 -10
  5. package/src/index.cjs +2 -0
  6. package/src/index.js +1 -0
  7. package/src/lib/Main.cjs +5 -0
  8. package/src/lib/Main.js +5 -0
  9. package/src/lib/components/AuthProviderIcon/AuthProviderIcon.cjs +9 -6
  10. package/src/lib/components/AuthProviderIcon/AuthProviderIcon.js +9 -6
  11. package/src/lib/components/Button/Button.cjs +10 -7
  12. package/src/lib/components/Button/Button.d.ts +3 -3
  13. package/src/lib/components/Button/Button.js +10 -7
  14. package/src/lib/components/DynamicConnectButton/components/ConnectButton.cjs +1 -1
  15. package/src/lib/components/DynamicConnectButton/components/ConnectButton.js +1 -1
  16. package/src/lib/components/Icon/Icon.cjs +1 -0
  17. package/src/lib/components/Icon/Icon.js +1 -0
  18. package/src/lib/components/Icon/Icon.types.d.ts +1 -1
  19. package/src/lib/components/IconWithSpinner/IconWithSpinner.d.ts +1 -1
  20. package/src/lib/components/ListTile/ListTile.cjs +1 -1
  21. package/src/lib/components/ListTile/ListTile.js +1 -1
  22. package/src/lib/components/ListTile/ListTile.types.d.ts +1 -0
  23. package/src/lib/components/ModalHeader/ModalHeader.cjs +2 -2
  24. package/src/lib/components/ModalHeader/ModalHeader.js +2 -2
  25. package/src/lib/components/ModalHeader/ModalHeader.types.d.ts +2 -1
  26. package/src/lib/components/NetworkPicker/NetworkPicker.cjs +1 -1
  27. package/src/lib/components/NetworkPicker/NetworkPicker.js +1 -1
  28. package/src/lib/components/OTPVerificationView/OTPVerificationView.cjs +5 -3
  29. package/src/lib/components/OTPVerificationView/OTPVerificationView.d.ts +1 -0
  30. package/src/lib/components/OTPVerificationView/OTPVerificationView.js +5 -3
  31. package/src/lib/components/PoweredByDynamic/PoweredByDynamic.cjs +6 -2
  32. package/src/lib/components/PoweredByDynamic/PoweredByDynamic.d.ts +1 -0
  33. package/src/lib/components/PoweredByDynamic/PoweredByDynamic.js +6 -2
  34. package/src/lib/components/UserProfileForm/UserProfileForm.cjs +26 -14
  35. package/src/lib/components/UserProfileForm/UserProfileForm.d.ts +14 -3
  36. package/src/lib/components/UserProfileForm/UserProfileForm.js +27 -15
  37. package/src/lib/components/UserProfileForm/index.d.ts +1 -0
  38. package/src/lib/context/DynamicContext/DynamicContext.cjs +9 -3
  39. package/src/lib/context/DynamicContext/DynamicContext.js +10 -4
  40. package/src/lib/context/ViewContext/ViewContext.d.ts +1 -1
  41. package/src/lib/data/api.cjs +16 -0
  42. package/src/lib/data/api.d.ts +1 -0
  43. package/src/lib/data/api.js +18 -3
  44. package/src/lib/layout/DynamicAuthLayout/Header/header.cjs +10 -2
  45. package/src/lib/layout/DynamicAuthLayout/Header/header.js +10 -2
  46. package/src/lib/shared/assets/double-arrow-right.cjs +53 -0
  47. package/src/lib/shared/assets/double-arrow-right.js +29 -0
  48. package/src/lib/shared/assets/index.d.ts +1 -0
  49. package/src/lib/styles/index.shadow.cjs +1 -1
  50. package/src/lib/styles/index.shadow.js +1 -1
  51. package/src/lib/utils/constants/index.d.ts +1 -1
  52. package/src/lib/utils/constants/localStorage.cjs +3 -1
  53. package/src/lib/utils/constants/localStorage.d.ts +1 -0
  54. package/src/lib/utils/constants/localStorage.js +3 -2
  55. package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.cjs +14 -2
  56. package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.d.ts +3 -2
  57. package/src/lib/utils/functions/getUserProfileFields/getUserProfileFields.js +14 -2
  58. package/src/lib/utils/functions/getUserProfileFields/index.d.ts +1 -0
  59. package/src/lib/utils/functions/index.d.ts +2 -0
  60. package/src/lib/utils/functions/isMagicConnector/index.d.ts +1 -0
  61. package/src/lib/utils/functions/isMagicConnector/isMagicConnector.d.ts +2 -0
  62. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +6 -4
  63. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.d.ts +3 -1
  64. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +6 -4
  65. package/src/lib/utils/hooks/index.d.ts +4 -1
  66. package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.cjs +19 -3
  67. package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.d.ts +1 -2
  68. package/src/lib/utils/hooks/multiWallet/useMultiWallet/useMultiWallet.js +20 -4
  69. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +2 -1
  70. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +2 -1
  71. package/src/lib/utils/hooks/useFindSocialIcon/index.d.ts +1 -0
  72. package/src/lib/utils/hooks/{useGetSocialIcon/useGetSocialIcon.cjs → useFindSocialIcon/useFindSocialIcon.cjs} +3 -3
  73. package/src/lib/utils/hooks/useFindSocialIcon/useFindSocialIcon.d.ts +3 -0
  74. package/src/lib/utils/hooks/useFindSocialIcon/useFindSocialIcon.js +10 -0
  75. package/src/lib/utils/hooks/useTransactionEstimatedGas/index.d.ts +1 -0
  76. package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.cjs +61 -0
  77. package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.d.ts +20 -0
  78. package/src/lib/utils/hooks/useTransactionEstimatedGas/useTransactionEstimatedGas.js +57 -0
  79. package/src/lib/utils/hooks/useTransactionWithGasPrice/index.d.ts +1 -0
  80. package/src/lib/utils/hooks/useTransactionWithGasPrice/useTransactionWithGasPrice.d.ts +32 -0
  81. package/src/lib/utils/hooks/useWalletConnectorEvent/index.d.ts +1 -0
  82. package/src/lib/utils/hooks/useWalletConnectorEvent/useWalletConnectorEvent.cjs +42 -0
  83. package/src/lib/utils/hooks/useWalletConnectorEvent/useWalletConnectorEvent.d.ts +12 -0
  84. package/src/lib/utils/hooks/useWalletConnectorEvent/useWalletConnectorEvent.js +38 -0
  85. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.cjs +12 -0
  86. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.js +12 -0
  87. package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.cjs +91 -136
  88. package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.js +92 -137
  89. package/src/lib/views/AccountExistsView/AccountExistsView.cjs +3 -3
  90. package/src/lib/views/AccountExistsView/AccountExistsView.js +3 -3
  91. package/src/lib/views/CollectUserDataView/UserDataFields/index.cjs +4 -0
  92. package/src/lib/views/CollectUserDataView/UserDataFields/index.js +4 -0
  93. package/src/lib/views/EmailUpdate/EmailUpdate.cjs +8 -2
  94. package/src/lib/views/EmailUpdate/EmailUpdate.js +8 -2
  95. package/src/lib/views/EmailVerification/EmailVerification.cjs +13 -4
  96. package/src/lib/views/EmailVerification/EmailVerification.js +15 -6
  97. package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.cjs +3 -2
  98. package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.js +3 -2
  99. package/src/lib/views/LoginWithEmailView/components/LoginWithEmailForm/LoginWithEmailForm.cjs +5 -3
  100. package/src/lib/views/LoginWithEmailView/components/LoginWithEmailForm/LoginWithEmailForm.js +6 -4
  101. package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.cjs +3 -3
  102. package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.js +3 -3
  103. package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.cjs +107 -0
  104. package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.d.ts +2 -0
  105. package/src/lib/views/MergeUserAccountsView/MergeUserAccountsView.js +103 -0
  106. package/src/lib/views/MergeUserAccountsView/index.d.ts +1 -0
  107. package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +13 -3
  108. package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +13 -3
  109. package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.cjs +14 -4
  110. package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.js +14 -4
  111. package/src/lib/views/SocialRedirectView/SocialRedirectView.cjs +3 -3
  112. package/src/lib/views/SocialRedirectView/SocialRedirectView.js +3 -3
  113. package/src/lib/views/SocialWrongAccountView/SocialWrongAccountView.cjs +3 -3
  114. package/src/lib/views/SocialWrongAccountView/SocialWrongAccountView.js +3 -3
  115. package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.cjs +2 -8
  116. package/src/lib/views/TransactionConfirmationView/hooks/useTransactionData/useTransactionData.js +3 -9
  117. package/src/lib/views/viewToComponentMap.cjs +2 -0
  118. package/src/lib/views/viewToComponentMap.js +2 -0
  119. package/src/lib/widgets/DynamicBridgeWidget/views/WalletsView/WalletsView.cjs +1 -1
  120. package/src/lib/widgets/DynamicBridgeWidget/views/WalletsView/WalletsView.js +1 -1
  121. package/src/lib/widgets/DynamicWidget/components/DynamicNav/DynamicNav.cjs +2 -1
  122. package/src/lib/widgets/DynamicWidget/components/DynamicNav/DynamicNav.js +2 -1
  123. package/src/lib/widgets/DynamicWidget/components/DynamicWidgetFooter/DynamicWidgetFooter.cjs +1 -1
  124. package/src/lib/widgets/DynamicWidget/components/DynamicWidgetFooter/DynamicWidgetFooter.js +1 -1
  125. package/src/lib/widgets/DynamicWidget/views/ProfileView/ProfileView.cjs +1 -1
  126. package/src/lib/widgets/DynamicWidget/views/ProfileView/ProfileView.js +1 -1
  127. package/src/lib/widgets/DynamicWidget/views/WalletsView/WalletsView.cjs +1 -1
  128. package/src/lib/widgets/DynamicWidget/views/WalletsView/WalletsView.js +1 -1
  129. package/src/lib/utils/hooks/useGetSocialIcon/index.d.ts +0 -1
  130. package/src/lib/utils/hooks/useGetSocialIcon/useGetSocialIcon.d.ts +0 -2
  131. package/src/lib/utils/hooks/useGetSocialIcon/useGetSocialIcon.js +0 -10
@@ -24,11 +24,11 @@ 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 = () => {
27
+ const useConnectAndSign = ({ shouldUpdateWallets = true } = {}) => {
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, } = 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,
@@ -68,8 +68,10 @@ const useConnectAndSign = () => {
68
68
  }
69
69
  if (isConnectOnly(user, authMode)) {
70
70
  LocalStorage.setToLS(LAST_USED_WALLET, walletConnector.name);
71
- handleWalletsToConnect();
72
- if (!isFullyConnected) {
71
+ if (shouldUpdateWallets) {
72
+ handleWalletsToConnect();
73
+ }
74
+ if (!isFullyConnected || (walletsToConnectByChain === null || walletsToConnectByChain === void 0 ? void 0 : walletsToConnectByChain.length)) {
73
75
  setCallback('connectSuccess');
74
76
  }
75
77
  return;
@@ -21,7 +21,7 @@ export { usePromise } from './usePromise';
21
21
  export { useMutation } from './useMutation';
22
22
  export { useUserUpdateRequest } from './useUserUpdateRequest/useUserUpdateRequest';
23
23
  export { useColorSchemePreference } from './useColorSchemePreference';
24
- export { useGetSocialIcon } from './useGetSocialIcon';
24
+ export { useFindSocialIcon } from './useFindSocialIcon';
25
25
  export { useIconThemeVariant } from './useIconThemeVariant';
26
26
  export type { IconThemeVariant } from './useIconThemeVariant';
27
27
  export { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';
@@ -30,3 +30,6 @@ export { useInterval } from './useInterval/useInterval';
30
30
  export { useCountdown } from './useCountdown/useCountdown';
31
31
  export { useValidateSession } from './useValidateSession';
32
32
  export { useEventListener } from './useEventListener';
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('ethers');
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] = React.useState(isMultiWalletEnabled);
23
+ const [multiWallet, setMultiWallet] = useLocalStorage.useLocalStorage(localStorage.IS_MULTI_WALLET_ENABLED, isMultiWalletEnabled);
10
24
  React.useEffect(() => {
11
- setMultiWallet(isMultiWalletEnabled);
12
- }, [isMultiWalletEnabled]);
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: import("react").Dispatch<import("react").SetStateAction<boolean>>;
3
+ setMultiWallet: (value: boolean | ((val: boolean) => boolean)) => void;
5
4
  };
@@ -1,11 +1,27 @@
1
- import { useState, useEffect } from 'react';
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 'ethers';
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] = useState(isMultiWalletEnabled);
19
+ const [multiWallet, setMultiWallet] = useLocalStorage(IS_MULTI_WALLET_ENABLED, isMultiWalletEnabled);
6
20
  useEffect(() => {
7
- setMultiWallet(isMultiWalletEnabled);
8
- }, [isMultiWalletEnabled]);
21
+ if (multiWalletSettings) {
22
+ setMultiWallet(multiWalletSettings);
23
+ }
24
+ }, [multiWalletSettings]);
9
25
  return { multiWallet, setMultiWallet };
10
26
  };
11
27
 
@@ -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';
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';
68
69
  const showQrCodePreHeader = view === 'qr-code' && showQrCodeMessage && !showQrCodeImage;
69
70
  return {
70
71
  isWalletListTypeView,
@@ -0,0 +1 @@
1
+ export * from './useFindSocialIcon';
@@ -6,9 +6,9 @@ var React = require('react');
6
6
  var iconic = require('@dynamic-labs/iconic');
7
7
  var useIconThemeVariant = require('../useIconThemeVariant/useIconThemeVariant.cjs');
8
8
 
9
- const useGetSocialIcon = () => {
9
+ const useFindSocialIcon = () => {
10
10
  const variant = useIconThemeVariant.useIconThemeVariant();
11
- return React.useCallback((provider) => iconic.getSocialIcon(provider, variant), [variant]);
11
+ return React.useCallback((provider) => iconic.findSocialIcon(provider, variant), [variant]);
12
12
  };
13
13
 
14
- exports.useGetSocialIcon = useGetSocialIcon;
14
+ exports.useFindSocialIcon = useFindSocialIcon;
@@ -0,0 +1,3 @@
1
+ import { Iconic } from '@dynamic-labs/iconic';
2
+ import { SocialProvider } from '@dynamic-labs/wallet-connector-core';
3
+ export declare const useFindSocialIcon: () => (provider: SocialProvider) => Iconic | null;
@@ -0,0 +1,10 @@
1
+ import { useCallback } from 'react';
2
+ import { findSocialIcon } from '@dynamic-labs/iconic';
3
+ import { useIconThemeVariant } from '../useIconThemeVariant/useIconThemeVariant.js';
4
+
5
+ const useFindSocialIcon = () => {
6
+ const variant = useIconThemeVariant();
7
+ return useCallback((provider) => findSocialIcon(provider, variant), [variant]);
8
+ };
9
+
10
+ export { useFindSocialIcon };
@@ -0,0 +1 @@
1
+ export { useTransactionEstimatedGas } from './useTransactionEstimatedGas';
@@ -0,0 +1,61 @@
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
+ require('@dynamic-labs/sdk-api');
8
+ var logger = require('../../../shared/logger.cjs');
9
+ require('@dynamic-labs/iconic');
10
+ require('@dynamic-labs/wallet-connector-core');
11
+ require('react/jsx-runtime');
12
+ require('../../../context/ViewContext/ViewContext.cjs');
13
+ require('react');
14
+ require('@dynamic-labs/wallet-book');
15
+ require('@dynamic-labs/utils');
16
+ require('../../constants/colors.cjs');
17
+ require('../../../shared/utils/classes/storage/localStorage.cjs');
18
+ require('ethers');
19
+ require('../../../shared/consts/index.cjs');
20
+
21
+ /**
22
+ * Hook to estimate the gas required for a transaction.
23
+ *
24
+ * This hook uses the `usePromise` hook to asynchronously estimate the gas required for a transaction.
25
+ * It first tries to estimate the gas without the 'from' field in the transaction, as the Alchemy API
26
+ * checks the origin address funds and can return an error if the origin wallet has no funds for the transaction.
27
+ * If the error 'UNPREDICTABLE_GAS_LIMIT' is encountered, it tries to estimate the gas again with the
28
+ * original transaction.
29
+ *
30
+ * @see {@link https://docs.alchemy.com/reference/eth-estimategas}
31
+ * @see {@link https://docs.ethers.org/v5/troubleshooting/errors/#help-UNPREDICTABLE_GAS_LIMIT}
32
+ *
33
+ * @param {ethers.providers.Web3Provider} provider - The Web3 provider to use for estimating the gas.
34
+ * @param {ethers.utils.Deferrable<ethers.providers.TransactionRequest>} transaction - The transaction for
35
+ * which to estimate the gas.
36
+ *
37
+ * @returns {PromiseState<ethers.BigNumber>} A promise that resolves to the estimated gas for the transaction.
38
+ */
39
+ const useTransactionEstimatedGas = (provider, transaction) => usePromise.usePromise(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
40
+ // To safely run estimateGas using alchemy, we need to remove the from address
41
+ // because alchemy checks the origin address funds and can return an error if
42
+ // origin wallet has no funds for the transaction
43
+ // https://docs.alchemy.com/reference/eth-estimategas
44
+ const transactionWithNoOrigin = _tslib.__rest(transaction, ["from"]);
45
+ try {
46
+ return yield provider.estimateGas(transactionWithNoOrigin);
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ }
49
+ catch (err) {
50
+ logger.logger.error(err);
51
+ // If the error is UNPREDICTABLE_GAS_LIMIT, we try to estimate gas again
52
+ // with original transaction
53
+ // https://docs.ethers.org/v5/troubleshooting/errors/#help-UNPREDICTABLE_GAS_LIMIT
54
+ if (err.code === 'UNPREDICTABLE_GAS_LIMIT') {
55
+ return provider.estimateGas(transaction);
56
+ }
57
+ throw err;
58
+ }
59
+ }), { deps: [transaction, provider] });
60
+
61
+ exports.useTransactionEstimatedGas = useTransactionEstimatedGas;
@@ -0,0 +1,20 @@
1
+ import { ethers } from 'ethers';
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: ethers.providers.Web3Provider, transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>) => import("../usePromise").PromiseState<ethers.BigNumber, Error>;
@@ -0,0 +1,57 @@
1
+ import { __awaiter, __rest } from '../../../../../_virtual/_tslib.js';
2
+ import { usePromise } from '../usePromise/usePromise.js';
3
+ import '@dynamic-labs/sdk-api';
4
+ import { logger } from '../../../shared/logger.js';
5
+ import '@dynamic-labs/iconic';
6
+ import '@dynamic-labs/wallet-connector-core';
7
+ import 'react/jsx-runtime';
8
+ import '../../../context/ViewContext/ViewContext.js';
9
+ import 'react';
10
+ import '@dynamic-labs/wallet-book';
11
+ import '@dynamic-labs/utils';
12
+ import '../../constants/colors.js';
13
+ import '../../../shared/utils/classes/storage/localStorage.js';
14
+ import 'ethers';
15
+ import '../../../shared/consts/index.js';
16
+
17
+ /**
18
+ * Hook to estimate the gas required for a transaction.
19
+ *
20
+ * This hook uses the `usePromise` hook to asynchronously estimate the gas required for a transaction.
21
+ * It first tries to estimate the gas without the 'from' field in the transaction, as the Alchemy API
22
+ * checks the origin address funds and can return an error if the origin wallet has no funds for the transaction.
23
+ * If the error 'UNPREDICTABLE_GAS_LIMIT' is encountered, it tries to estimate the gas again with the
24
+ * original transaction.
25
+ *
26
+ * @see {@link https://docs.alchemy.com/reference/eth-estimategas}
27
+ * @see {@link https://docs.ethers.org/v5/troubleshooting/errors/#help-UNPREDICTABLE_GAS_LIMIT}
28
+ *
29
+ * @param {ethers.providers.Web3Provider} provider - The Web3 provider to use for estimating the gas.
30
+ * @param {ethers.utils.Deferrable<ethers.providers.TransactionRequest>} transaction - The transaction for
31
+ * which to estimate the gas.
32
+ *
33
+ * @returns {PromiseState<ethers.BigNumber>} A promise that resolves to the estimated gas for the transaction.
34
+ */
35
+ const useTransactionEstimatedGas = (provider, transaction) => usePromise(() => __awaiter(void 0, void 0, void 0, function* () {
36
+ // To safely run estimateGas using alchemy, we need to remove the from address
37
+ // because alchemy checks the origin address funds and can return an error if
38
+ // origin wallet has no funds for the transaction
39
+ // https://docs.alchemy.com/reference/eth-estimategas
40
+ const transactionWithNoOrigin = __rest(transaction, ["from"]);
41
+ try {
42
+ return yield provider.estimateGas(transactionWithNoOrigin);
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ }
45
+ catch (err) {
46
+ logger.error(err);
47
+ // If the error is UNPREDICTABLE_GAS_LIMIT, we try to estimate gas again
48
+ // with original transaction
49
+ // https://docs.ethers.org/v5/troubleshooting/errors/#help-UNPREDICTABLE_GAS_LIMIT
50
+ if (err.code === 'UNPREDICTABLE_GAS_LIMIT') {
51
+ return provider.estimateGas(transaction);
52
+ }
53
+ throw err;
54
+ }
55
+ }), { deps: [transaction, provider] });
56
+
57
+ export { useTransactionEstimatedGas };
@@ -0,0 +1 @@
1
+ export { useTransactionWithGasPrice } from './useTransactionWithGasPrice';
@@ -0,0 +1,32 @@
1
+ import { ethers } from 'ethers';
2
+ type UseTransactionWithGasPriceProps = {
3
+ provider: ethers.providers.Provider;
4
+ transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>;
5
+ increasePercentage?: number;
6
+ enabled?: boolean;
7
+ };
8
+ /**
9
+ * A React Hook that returns a transaction object with the gas price set to the current gas price from the provider.
10
+ * The gas price is increased by a certain percentage specified by the user. The hook also allows the user to enable
11
+ * or disable this functionality.
12
+ *
13
+ * @param {Object} props - The properties for the hook.
14
+ * @param {ethers.providers.Provider} props.provider - The provider to use for getting the current gas price.
15
+ * @param {ethers.utils.Deferrable<ethers.providers.TransactionRequest>} props.transaction - The transaction object.
16
+ * @param {number} props.increasePercentage - The percentage by which to increase the current gas price.
17
+ * @param {boolean} [props.enabled=true] - A flag to enable or disable the gas price increase functionality.
18
+ *
19
+ * @returns {ethers.utils.Deferrable<ethers.providers.TransactionRequest>} A new transaction object with the gas price.
20
+ * If the `enabled` flag is set to false, or if the gas price is not available, or if the transaction already has a
21
+ * gas price set, the original transaction object is returned.
22
+ *
23
+ * @example
24
+ * const updatedTransaction = useTransactionWithGasPrice({
25
+ * provider: myProvider,
26
+ * transaction: myTransaction,
27
+ * increasePercentage: 10,
28
+ * enabled: true,
29
+ * });
30
+ */
31
+ export declare const useTransactionWithGasPrice: ({ increasePercentage, provider, transaction, enabled, }: UseTransactionWithGasPriceProps) => ethers.utils.Deferrable<ethers.providers.TransactionRequest>;
32
+ export {};
@@ -0,0 +1 @@
1
+ export { useWalletConnectorEvent } from './useWalletConnectorEvent';
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var useIsomorphicLayoutEffect = require('../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs');
7
+
8
+ const useWalletConnectorEvent = (eventEmitters, eventName, handler) => {
9
+ const callbackRef = React.useRef(handler);
10
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
11
+ callbackRef.current = handler;
12
+ }, [handler]);
13
+ React.useEffect(() => {
14
+ if (!eventEmitters)
15
+ return;
16
+ const eventEmittersArray = Array.isArray(eventEmitters)
17
+ ? eventEmitters
18
+ : [eventEmitters];
19
+ /**
20
+ * Initialize the event listeners for the wallet connectors
21
+ * to ensure they were initialized before listening to events
22
+ *
23
+ * This will be removed when all wallets are migrated to
24
+ * use the event emitter "emit" method
25
+ *
26
+ * Ticket todo - QNTM-88
27
+ */
28
+ eventEmittersArray.forEach((connector) => connector.initEventListener());
29
+ const uniqueEventEmitters = Array.from(new Set(eventEmittersArray));
30
+ const unsubscribeCallbacks = uniqueEventEmitters.map((emitter) => {
31
+ const callback = (...args) => {
32
+ callbackRef.current(emitter, ...args);
33
+ };
34
+ emitter.on(eventName, callback);
35
+ return () => emitter.off(eventName, callback);
36
+ });
37
+ return () => unsubscribeCallbacks.forEach((unsubscribe) => unsubscribe());
38
+ // eslint-disable-next-line react-hooks/exhaustive-deps
39
+ }, [eventEmitters, eventName]);
40
+ };
41
+
42
+ exports.useWalletConnectorEvent = useWalletConnectorEvent;
@@ -0,0 +1,12 @@
1
+ import { WalletConnector, WalletConnectorEventTypes } from '@dynamic-labs/wallet-connector-core';
2
+ /**
3
+ * This type is a copy of the ArgumentMap type from eventemitter3 package.
4
+ * Is used extract the arguments from a event type.
5
+ * Then we can use the arguments to reconstruct the callback we want
6
+ */
7
+ type ArgumentMap<T extends object> = {
8
+ [K in keyof T]: T[K] extends (...args: any[]) => void ? Parameters<T[K]> : T[K] extends any[] ? T[K] : any[];
9
+ };
10
+ type EventArg<Event extends keyof WalletConnectorEventTypes> = ArgumentMap<WalletConnectorEventTypes>[Extract<Event, keyof WalletConnectorEventTypes>];
11
+ export declare const useWalletConnectorEvent: <Event_1 extends keyof WalletConnectorEventTypes = keyof WalletConnectorEventTypes>(eventEmitters: WalletConnector | WalletConnector[] | undefined, eventName: Event_1, handler: (connector: WalletConnector, ...args: EventArg<Event_1>) => void) => void;
12
+ export {};
@@ -0,0 +1,38 @@
1
+ import { useRef, useEffect } from 'react';
2
+ import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js';
3
+
4
+ const useWalletConnectorEvent = (eventEmitters, eventName, handler) => {
5
+ const callbackRef = useRef(handler);
6
+ useIsomorphicLayoutEffect(() => {
7
+ callbackRef.current = handler;
8
+ }, [handler]);
9
+ useEffect(() => {
10
+ if (!eventEmitters)
11
+ return;
12
+ const eventEmittersArray = Array.isArray(eventEmitters)
13
+ ? eventEmitters
14
+ : [eventEmitters];
15
+ /**
16
+ * Initialize the event listeners for the wallet connectors
17
+ * to ensure they were initialized before listening to events
18
+ *
19
+ * This will be removed when all wallets are migrated to
20
+ * use the event emitter "emit" method
21
+ *
22
+ * Ticket todo - QNTM-88
23
+ */
24
+ eventEmittersArray.forEach((connector) => connector.initEventListener());
25
+ const uniqueEventEmitters = Array.from(new Set(eventEmittersArray));
26
+ const unsubscribeCallbacks = uniqueEventEmitters.map((emitter) => {
27
+ const callback = (...args) => {
28
+ callbackRef.current(emitter, ...args);
29
+ };
30
+ emitter.on(eventName, callback);
31
+ return () => emitter.off(eventName, callback);
32
+ });
33
+ return () => unsubscribeCallbacks.forEach((unsubscribe) => unsubscribe());
34
+ // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ }, [eventEmitters, eventName]);
36
+ };
37
+
38
+ export { useWalletConnectorEvent };
@@ -44,6 +44,18 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, wallets: a
44
44
  }
45
45
  return connectedWallets;
46
46
  }, [authMode, connectedWallets, linkedWallets, user, onboardingOnlyJwt]);
47
+ /**
48
+ * This useEffect is temporary.
49
+ * While the wallet connectors don't use the event emitter, we need to manually
50
+ * initialize the bridge between the old event listeners and the new event emitter.
51
+ * When the wallet connectors are migrated to the new event emitter, there will be no
52
+ * need to initialize or teardown event listeners, then we can remove this useEffect.
53
+ * @todo remove this useEffect
54
+ * Ticket todo - QNTM-88
55
+ */
56
+ React.useEffect(() => walletsBasedOnAuthMode.forEach((wallet) => {
57
+ wallet.connector.initEventListener();
58
+ }), [walletsBasedOnAuthMode]);
47
59
  const { connectedWalletMap, computeConnectedStateForWallets, didConnectedStateLoad, } = useWalletsConnectionState.useWalletsConnectionState(walletsBasedOnAuthMode);
48
60
  const wallets = React.useMemo(() => walletsBasedOnAuthMode.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletMap[wallet.id]) }))), [connectedWalletMap, walletsBasedOnAuthMode]);
49
61
  React.useEffect(() => {
@@ -40,6 +40,18 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, wallets: a
40
40
  }
41
41
  return connectedWallets;
42
42
  }, [authMode, connectedWallets, linkedWallets, user, onboardingOnlyJwt]);
43
+ /**
44
+ * This useEffect is temporary.
45
+ * While the wallet connectors don't use the event emitter, we need to manually
46
+ * initialize the bridge between the old event listeners and the new event emitter.
47
+ * When the wallet connectors are migrated to the new event emitter, there will be no
48
+ * need to initialize or teardown event listeners, then we can remove this useEffect.
49
+ * @todo remove this useEffect
50
+ * Ticket todo - QNTM-88
51
+ */
52
+ useEffect(() => walletsBasedOnAuthMode.forEach((wallet) => {
53
+ wallet.connector.initEventListener();
54
+ }), [walletsBasedOnAuthMode]);
43
55
  const { connectedWalletMap, computeConnectedStateForWallets, didConnectedStateLoad, } = useWalletsConnectionState(walletsBasedOnAuthMode);
44
56
  const wallets = useMemo(() => walletsBasedOnAuthMode.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletMap[wallet.id]) }))), [connectedWalletMap, walletsBasedOnAuthMode]);
45
57
  useEffect(() => {