@dynamic-labs/sdk-react-core 4.5.1 → 4.5.2
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 +15 -0
- package/package.cjs +2 -2
- package/package.js +2 -2
- package/package.json +12 -12
- package/src/lib/components/NetworkPicker/NetworkPicker.cjs +11 -40
- package/src/lib/components/NetworkPicker/NetworkPicker.d.ts +2 -6
- package/src/lib/components/NetworkPicker/NetworkPicker.js +12 -41
- package/src/lib/components/NetworkPicker/components/NetworkControl/NetworkControl.cjs +6 -8
- package/src/lib/components/NetworkPicker/components/NetworkControl/NetworkControl.d.ts +2 -4
- package/src/lib/components/NetworkPicker/components/NetworkControl/NetworkControl.js +6 -8
- package/src/lib/components/NetworkPicker/components/NetworkDropdown/NetworkDropdown.cjs +67 -0
- package/src/lib/components/NetworkPicker/components/NetworkDropdown/NetworkDropdown.d.ts +14 -0
- package/src/lib/components/NetworkPicker/components/NetworkDropdown/NetworkDropdown.js +63 -0
- package/src/lib/components/NetworkPicker/components/NetworkDropdown/index.d.ts +1 -0
- package/src/lib/components/NetworkPicker/components/{EvmNetworkControl/EvmNetworkControl.cjs → NetworkSwitchControl/NetworkSwitchControl.cjs} +27 -36
- package/src/lib/components/NetworkPicker/components/NetworkSwitchControl/NetworkSwitchControl.d.ts +16 -0
- package/src/lib/components/NetworkPicker/components/{EvmNetworkControl/EvmNetworkControl.js → NetworkSwitchControl/NetworkSwitchControl.js} +27 -35
- package/src/lib/components/NetworkPicker/components/NetworkSwitchControl/index.d.ts +1 -0
- package/src/lib/components/Portal/Portal.cjs +3 -2
- package/src/lib/components/Portal/Portal.js +3 -2
- package/src/lib/locale/en/translation.cjs +13 -29
- package/src/lib/locale/en/translation.d.ts +11 -27
- package/src/lib/locale/en/translation.js +13 -29
- package/src/lib/shared/assets/index.d.ts +1 -0
- package/src/lib/shared/assets/{currency.cjs → wallet-with-sunglasses.cjs} +14 -26
- package/src/lib/shared/assets/wallet-with-sunglasses.js +34 -0
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/functions/isNetworkUnsupported/isNetworkUnsupported.cjs +2 -4
- package/src/lib/utils/functions/isNetworkUnsupported/isNetworkUnsupported.d.ts +2 -2
- package/src/lib/utils/functions/isNetworkUnsupported/isNetworkUnsupported.js +2 -4
- package/src/lib/views/CollectUserDataView/CollectUserDataView.cjs +2 -4
- package/src/lib/views/CollectUserDataView/CollectUserDataView.js +2 -4
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +3 -4
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +3 -4
- package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.cjs +6 -9
- package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.js +7 -10
- package/src/lib/widgets/DynamicWidget/components/DynamicNav/DynamicNav.cjs +2 -6
- package/src/lib/widgets/DynamicWidget/components/DynamicNav/DynamicNav.js +2 -6
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/ReceiveExternalWalletFunds.cjs +98 -49
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/ReceiveExternalWalletFunds.js +94 -45
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/TokenSelectScreen/TokenOption/TokenOption.cjs +21 -10
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/TokenSelectScreen/TokenOption/TokenOption.d.ts +2 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/TokenSelectScreen/TokenOption/TokenOption.js +21 -10
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/TokenSelectScreen/TokenSelectScreen.cjs +3 -3
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/TokenSelectScreen/TokenSelectScreen.d.ts +2 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/TokenSelectScreen/TokenSelectScreen.js +3 -3
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/types.d.ts +2 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/calculateFiatBalance/calculateFiatBalance.cjs +27 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/calculateFiatBalance/calculateFiatBalance.d.ts +2 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/calculateFiatBalance/calculateFiatBalance.js +23 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/calculateFiatBalance/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/convert/convert.cjs +4 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/convert/convert.js +4 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/convertScientificToDecimal/convertScientificToDecimal.cjs +33 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/convertScientificToDecimal/convertScientificToDecimal.d.ts +8 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/convertScientificToDecimal/convertScientificToDecimal.js +29 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/convertScientificToDecimal/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/formatValue.cjs +26 -27
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/formatValue.d.ts +6 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/formatValue/formatValue.js +26 -27
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/isFiatToken/isFiatToken.cjs +2 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/isFiatToken/isFiatToken.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/isFiatToken/isFiatToken.js +2 -1
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/useExchangeRatesForFunding/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/useExchangeRatesForFunding/useExchangeRatesForFunding.cjs +32 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/useExchangeRatesForFunding/useExchangeRatesForFunding.d.ts +9 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/useExchangeRatesForFunding/useExchangeRatesForFunding.js +28 -0
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/useTokensForFunding/useTokensForFunding.cjs +27 -15
- package/src/lib/widgets/DynamicWidget/views/ReceiveExternalWalletFunds/utils/useTokensForFunding/useTokensForFunding.js +27 -15
- package/src/lib/widgets/DynamicWidget/views/SettingsView/EmptyScreen/EmptyScreen.cjs +20 -0
- package/src/lib/widgets/DynamicWidget/views/SettingsView/EmptyScreen/EmptyScreen.d.ts +2 -0
- package/src/lib/widgets/DynamicWidget/views/SettingsView/EmptyScreen/EmptyScreen.js +16 -0
- package/src/lib/widgets/DynamicWidget/views/SettingsView/EmptyScreen/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/views/SettingsView/SettingsView.cjs +3 -6
- package/src/lib/widgets/DynamicWidget/views/SettingsView/SettingsView.js +3 -6
- package/src/lib/components/NetworkPicker/components/EvmNetworkControl/EvmNetworkControl.d.ts +0 -23
- package/src/lib/components/NetworkPicker/components/EvmNetworkControl/index.d.ts +0 -1
- package/src/lib/shared/assets/currency.js +0 -46
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.5.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.5.1...v4.5.2) (2025-02-08)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add getEnabledNetworks method to wallet connectors ([#8000](https://github.com/dynamic-labs/dynamic-auth/issues/8000)) ([450cdcd](https://github.com/dynamic-labs/dynamic-auth/commit/450cdcd98b11c734fb9c9d97bb1813cf5538e85e))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* add fallback for exchange rate lookup failure ([#7994](https://github.com/dynamic-labs/dynamic-auth/issues/7994)) ([1359724](https://github.com/dynamic-labs/dynamic-auth/commit/1359724ec2931c61324bfe8d73110d862ebc016f))
|
|
13
|
+
* add USDT and USDC as hardcoded to 1 ([#8012](https://github.com/dynamic-labs/dynamic-auth/issues/8012)) ([92dcd2f](https://github.com/dynamic-labs/dynamic-auth/commit/92dcd2f6a90e8eeca034edf1682336896180281e))
|
|
14
|
+
* underflow bigint issue with small sol transfers ([#8006](https://github.com/dynamic-labs/dynamic-auth/issues/8006)) ([3fd00c2](https://github.com/dynamic-labs/dynamic-auth/commit/3fd00c2f0d0e10333f0206cb80197375de836003))
|
|
15
|
+
* view address react 17 compatibility ([#8002](https://github.com/dynamic-labs/dynamic-auth/issues/8002)) ([782e0f3](https://github.com/dynamic-labs/dynamic-auth/commit/782e0f323f388cac1d0773420ae45595aa806c26))
|
|
16
|
+
|
|
2
17
|
### [4.5.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.5.0...v4.5.1) (2025-02-05)
|
|
3
18
|
|
|
4
19
|
|
package/package.cjs
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var version = "4.5.
|
|
6
|
+
var version = "4.5.2";
|
|
7
7
|
var dependencies = {
|
|
8
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
8
|
+
"@dynamic-labs/sdk-api-core": "0.0.613",
|
|
9
9
|
"@hcaptcha/react-hcaptcha": "1.4.4",
|
|
10
10
|
"@thumbmarkjs/thumbmarkjs": "0.16.0",
|
|
11
11
|
"country-list": "2.3.0",
|
package/package.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
var version = "4.5.
|
|
2
|
+
var version = "4.5.2";
|
|
3
3
|
var dependencies = {
|
|
4
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
4
|
+
"@dynamic-labs/sdk-api-core": "0.0.613",
|
|
5
5
|
"@hcaptcha/react-hcaptcha": "1.4.4",
|
|
6
6
|
"@thumbmarkjs/thumbmarkjs": "0.16.0",
|
|
7
7
|
"country-list": "2.3.0",
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sdk-react-core",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.2",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
5
|
+
"@dynamic-labs/sdk-api-core": "0.0.613",
|
|
6
6
|
"@hcaptcha/react-hcaptcha": "1.4.4",
|
|
7
7
|
"@thumbmarkjs/thumbmarkjs": "0.16.0",
|
|
8
8
|
"country-list": "2.3.0",
|
|
@@ -14,16 +14,16 @@
|
|
|
14
14
|
"yup": "0.32.11",
|
|
15
15
|
"react-international-phone": "4.2.5",
|
|
16
16
|
"bs58": "5.0.0",
|
|
17
|
-
"@dynamic-labs/assert-package-version": "4.5.
|
|
18
|
-
"@dynamic-labs/iconic": "4.5.
|
|
19
|
-
"@dynamic-labs/logger": "4.5.
|
|
20
|
-
"@dynamic-labs/multi-wallet": "4.5.
|
|
21
|
-
"@dynamic-labs/rpc-providers": "4.5.
|
|
22
|
-
"@dynamic-labs/store": "4.5.
|
|
23
|
-
"@dynamic-labs/types": "4.5.
|
|
24
|
-
"@dynamic-labs/utils": "4.5.
|
|
25
|
-
"@dynamic-labs/wallet-book": "4.5.
|
|
26
|
-
"@dynamic-labs/wallet-connector-core": "4.5.
|
|
17
|
+
"@dynamic-labs/assert-package-version": "4.5.2",
|
|
18
|
+
"@dynamic-labs/iconic": "4.5.2",
|
|
19
|
+
"@dynamic-labs/logger": "4.5.2",
|
|
20
|
+
"@dynamic-labs/multi-wallet": "4.5.2",
|
|
21
|
+
"@dynamic-labs/rpc-providers": "4.5.2",
|
|
22
|
+
"@dynamic-labs/store": "4.5.2",
|
|
23
|
+
"@dynamic-labs/types": "4.5.2",
|
|
24
|
+
"@dynamic-labs/utils": "4.5.2",
|
|
25
|
+
"@dynamic-labs/wallet-book": "4.5.2",
|
|
26
|
+
"@dynamic-labs/wallet-connector-core": "4.5.2",
|
|
27
27
|
"eventemitter3": "5.0.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
7
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
7
|
var React = require('react');
|
|
9
|
-
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
10
8
|
require('../../context/DynamicContext/DynamicContext.cjs');
|
|
11
9
|
require('@dynamic-labs/sdk-api-core');
|
|
12
|
-
|
|
10
|
+
require('../../shared/logger.cjs');
|
|
13
11
|
require('@dynamic-labs/iconic');
|
|
12
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
14
13
|
require('../../context/ViewContext/ViewContext.cjs');
|
|
15
14
|
require('@dynamic-labs/wallet-book');
|
|
16
15
|
require('@dynamic-labs/utils');
|
|
@@ -18,12 +17,12 @@ require('../../utils/constants/colors.cjs');
|
|
|
18
17
|
require('../../utils/constants/values.cjs');
|
|
19
18
|
require('../../shared/consts/index.cjs');
|
|
20
19
|
require('../../events/dynamicEvents.cjs');
|
|
20
|
+
require('../../../../_virtual/_tslib.cjs');
|
|
21
21
|
require('../../context/CaptchaContext/CaptchaContext.cjs');
|
|
22
22
|
require('../../context/ErrorContext/ErrorContext.cjs');
|
|
23
23
|
require('@dynamic-labs/multi-wallet');
|
|
24
24
|
require('react-international-phone');
|
|
25
25
|
require('../../store/state/nonce/nonce.cjs');
|
|
26
|
-
var isNetworkUnsupported = require('../../utils/functions/isNetworkUnsupported/isNetworkUnsupported.cjs');
|
|
27
26
|
require('../../store/state/projectSettings/projectSettings.cjs');
|
|
28
27
|
require('../../config/ApiEndpoint.cjs');
|
|
29
28
|
require('../../store/state/user/user.cjs');
|
|
@@ -39,7 +38,6 @@ require('../../utils/functions/compareChains/compareChains.cjs');
|
|
|
39
38
|
require('../../context/ThemeContext/ThemeContext.cjs');
|
|
40
39
|
require('../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
|
|
41
40
|
require('bs58');
|
|
42
|
-
var usePromise = require('../../utils/hooks/usePromise/usePromise.cjs');
|
|
43
41
|
require('@dynamic-labs/types');
|
|
44
42
|
require('../../context/SocialRedirectContext/SocialRedirectContext.cjs');
|
|
45
43
|
require('../../context/LoadingContext/LoadingContext.cjs');
|
|
@@ -63,18 +61,17 @@ require('../InlineWidget/InlineWidget.cjs');
|
|
|
63
61
|
require('../Input/Input.cjs');
|
|
64
62
|
require('../IsBrowser/IsBrowser.cjs');
|
|
65
63
|
require('../MenuList/Dropdown/Dropdown.cjs');
|
|
66
|
-
|
|
64
|
+
require('../OverlayCard/OverlayCard.cjs');
|
|
67
65
|
require('../Transition/ZoomTransition/ZoomTransition.cjs');
|
|
68
66
|
require('../Transition/SlideInUpTransition/SlideInUpTransition.cjs');
|
|
69
67
|
require('../Transition/OpacityTransition/OpacityTransition.cjs');
|
|
70
|
-
require('../OverlayCard/OverlayCard.cjs');
|
|
71
68
|
require('../PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
|
|
72
69
|
require('../Popper/Popper/Popper.cjs');
|
|
73
70
|
require('../Popper/PopperContext/PopperContext.cjs');
|
|
74
71
|
require('react-focus-lock');
|
|
75
72
|
require('qrcode');
|
|
76
|
-
var NetworkAction = require('./components/NetworkAction/NetworkAction.cjs');
|
|
77
73
|
var NetworkControl = require('./components/NetworkControl/NetworkControl.cjs');
|
|
74
|
+
var NetworkDropdown = require('./components/NetworkDropdown/NetworkDropdown.cjs');
|
|
78
75
|
require('formik');
|
|
79
76
|
require('../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs');
|
|
80
77
|
require('../../context/WalletGroupContext/WalletGroupContext.cjs');
|
|
@@ -98,42 +95,16 @@ require('../../store/state/tokenBalances.cjs');
|
|
|
98
95
|
require('../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
|
|
99
96
|
var useInternalDynamicContext = require('../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.cjs');
|
|
100
97
|
|
|
101
|
-
const NetworkPicker = ({ activeClassName = '', buttonClassName = '', checkboxClassName = '', connector,
|
|
98
|
+
const NetworkPicker = ({ activeClassName = '', buttonClassName = '', checkboxClassName = '', connector, listClassName = '', mainClassName = '', showNetworkName, customCallbackOnSuccess, currentNetwork, isLoading = false, }) => {
|
|
99
|
+
const [isNetworkPickerOpen, setIsNetworkPickerOpen] = React.useState(false);
|
|
102
100
|
const pickerRef = React.useRef(null);
|
|
103
|
-
const [newNetworkId, setNewNetworkId] = React.useState(undefined);
|
|
104
101
|
const { loadingNetwork } = useInternalDynamicContext.useInternalDynamicContext();
|
|
105
|
-
const { data: supportedWalletNetworks } = usePromise.usePromise(() => walletConnectorCore.isWalletConnectConnector(connector)
|
|
106
|
-
? connector.getSupportedNetworks()
|
|
107
|
-
: Promise.resolve(evmNetworks.map(({ networkId }) => `${networkId}`)), {
|
|
108
|
-
deps: [connector, evmNetworks, isNetworkPickerOpen],
|
|
109
|
-
initialData: undefined,
|
|
110
|
-
});
|
|
111
|
-
const shouldAllowOpenDropdown = isNetworkUnsupported.isNetworkUnsupported(currentNetwork, evmNetworks) ||
|
|
112
|
-
(evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.length) > 1;
|
|
113
102
|
// Ref to anchor popper to
|
|
114
103
|
const anchorRef = React.useRef(null);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
networkChainId: networkId,
|
|
120
|
-
}));
|
|
121
|
-
customCallbackOnSuccess === null || customCallbackOnSuccess === void 0 ? void 0 : customCallbackOnSuccess();
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
/* istanbul ignore next */
|
|
125
|
-
logger.logger.debug(error);
|
|
126
|
-
}
|
|
127
|
-
finally {
|
|
128
|
-
setNewNetworkId(undefined);
|
|
129
|
-
setIsNetworkPickerOpen(false);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
return (jsxRuntime.jsxs("div", { className: classNames.classNames('non-widget-network-picker', mainClassName), ref: pickerRef, "data-testid": 'network-picker', children: [jsxRuntime.jsxs("div", { className: 'network-picker-network-control', children: [jsxRuntime.jsx(NetworkControl.NetworkControl, { evmNetworks: evmNetworks, activeClassName: activeClassName, network: currentNetwork, loading: loadingNetwork || isLoading, isOpen: isNetworkPickerOpen, setIsOpen: setIsNetworkPickerOpen, walletConnector: connector, showNetworkName: showNetworkName, buttonClassName: buttonClassName }), jsxRuntime.jsx("div", { ref: anchorRef, className: 'network-picker-network-control__anchor' })] }), shouldAllowOpenDropdown && (jsxRuntime.jsx(MenuList.MenuList, { className: listClassName, isOpen: isNetworkPickerOpen, onClickClose: () => setIsNetworkPickerOpen(false), popperProps: {
|
|
133
|
-
anchorOrigin: 'bottom-left',
|
|
134
|
-
anchorRef,
|
|
135
|
-
}, mobileTitle: 'Select network', children: evmNetworks.map(({ name, networkId, vanityName, iconUrls }) => (jsxRuntime.jsx(NetworkAction.NetworkAction, { iconUrl: iconUrls === null || iconUrls === void 0 ? void 0 : iconUrls[0], networkId: networkId, networkName: vanityName || name, network: currentNetwork, onClick: handleNetworkChange, checkboxClassName: checkboxClassName, newNetworkId: newNetworkId, notSupported: supportedWalletNetworks &&
|
|
136
|
-
!supportedWalletNetworks.includes(`${networkId}`) }, networkId))) }))] }));
|
|
104
|
+
if (!connector) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return (jsxRuntime.jsxs("div", { className: classNames.classNames('non-widget-network-picker', mainClassName), ref: pickerRef, "data-testid": 'network-picker', children: [jsxRuntime.jsxs("div", { className: 'network-picker-network-control', children: [jsxRuntime.jsx(NetworkControl.NetworkControl, { activeClassName: activeClassName, network: currentNetwork, loading: loadingNetwork || isLoading, isOpen: isNetworkPickerOpen, setIsOpen: setIsNetworkPickerOpen, walletConnector: connector, showNetworkName: showNetworkName, buttonClassName: buttonClassName }), jsxRuntime.jsx("div", { ref: anchorRef, className: 'network-picker-network-control__anchor' })] }), jsxRuntime.jsx(NetworkDropdown.NetworkDropdown, { anchorRef: anchorRef, customCallbackOnSuccess: customCallbackOnSuccess, connector: connector, className: listClassName, checkboxClassName: checkboxClassName, isNetworkPickerOpen: isNetworkPickerOpen, setIsNetworkPickerOpen: setIsNetworkPickerOpen, currentNetwork: currentNetwork })] }));
|
|
137
108
|
};
|
|
138
109
|
|
|
139
110
|
exports.NetworkPicker = NetworkPicker;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { EvmNetwork } from '@dynamic-labs/types';
|
|
1
|
+
/// <reference types="react" />
|
|
3
2
|
import { WalletConnector } from '../../..';
|
|
4
3
|
type Props = {
|
|
5
4
|
activeClassName?: string;
|
|
@@ -7,14 +6,11 @@ type Props = {
|
|
|
7
6
|
checkboxClassName?: string;
|
|
8
7
|
connector: WalletConnector | undefined;
|
|
9
8
|
customCallbackOnSuccess?: () => void;
|
|
10
|
-
evmNetworks: EvmNetwork[];
|
|
11
|
-
isNetworkPickerOpen: boolean;
|
|
12
9
|
listClassName?: string;
|
|
13
10
|
mainClassName?: string;
|
|
14
|
-
setIsNetworkPickerOpen: Dispatch<SetStateAction<boolean>>;
|
|
15
11
|
showNetworkName?: boolean;
|
|
16
12
|
currentNetwork: string | number | undefined;
|
|
17
13
|
isLoading?: boolean;
|
|
18
14
|
};
|
|
19
|
-
export declare const NetworkPicker: ({ activeClassName, buttonClassName, checkboxClassName, connector,
|
|
15
|
+
export declare const NetworkPicker: ({ activeClassName, buttonClassName, checkboxClassName, connector, listClassName, mainClassName, showNetworkName, customCallbackOnSuccess, currentNetwork, isLoading, }: Props) => JSX.Element | null;
|
|
20
16
|
export {};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
3
2
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
4
|
-
import {
|
|
5
|
-
import { isWalletConnectConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { useState, useRef } from 'react';
|
|
6
4
|
import '../../context/DynamicContext/DynamicContext.js';
|
|
7
5
|
import '@dynamic-labs/sdk-api-core';
|
|
8
|
-
import
|
|
6
|
+
import '../../shared/logger.js';
|
|
9
7
|
import '@dynamic-labs/iconic';
|
|
8
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
10
9
|
import '../../context/ViewContext/ViewContext.js';
|
|
11
10
|
import '@dynamic-labs/wallet-book';
|
|
12
11
|
import '@dynamic-labs/utils';
|
|
@@ -14,12 +13,12 @@ import '../../utils/constants/colors.js';
|
|
|
14
13
|
import '../../utils/constants/values.js';
|
|
15
14
|
import '../../shared/consts/index.js';
|
|
16
15
|
import '../../events/dynamicEvents.js';
|
|
16
|
+
import '../../../../_virtual/_tslib.js';
|
|
17
17
|
import '../../context/CaptchaContext/CaptchaContext.js';
|
|
18
18
|
import '../../context/ErrorContext/ErrorContext.js';
|
|
19
19
|
import '@dynamic-labs/multi-wallet';
|
|
20
20
|
import 'react-international-phone';
|
|
21
21
|
import '../../store/state/nonce/nonce.js';
|
|
22
|
-
import { isNetworkUnsupported } from '../../utils/functions/isNetworkUnsupported/isNetworkUnsupported.js';
|
|
23
22
|
import '../../store/state/projectSettings/projectSettings.js';
|
|
24
23
|
import '../../config/ApiEndpoint.js';
|
|
25
24
|
import '../../store/state/user/user.js';
|
|
@@ -35,7 +34,6 @@ import '../../utils/functions/compareChains/compareChains.js';
|
|
|
35
34
|
import '../../context/ThemeContext/ThemeContext.js';
|
|
36
35
|
import '../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.js';
|
|
37
36
|
import 'bs58';
|
|
38
|
-
import { usePromise } from '../../utils/hooks/usePromise/usePromise.js';
|
|
39
37
|
import '@dynamic-labs/types';
|
|
40
38
|
import '../../context/SocialRedirectContext/SocialRedirectContext.js';
|
|
41
39
|
import '../../context/LoadingContext/LoadingContext.js';
|
|
@@ -59,18 +57,17 @@ import '../InlineWidget/InlineWidget.js';
|
|
|
59
57
|
import '../Input/Input.js';
|
|
60
58
|
import '../IsBrowser/IsBrowser.js';
|
|
61
59
|
import '../MenuList/Dropdown/Dropdown.js';
|
|
62
|
-
import
|
|
60
|
+
import '../OverlayCard/OverlayCard.js';
|
|
63
61
|
import '../Transition/ZoomTransition/ZoomTransition.js';
|
|
64
62
|
import '../Transition/SlideInUpTransition/SlideInUpTransition.js';
|
|
65
63
|
import '../Transition/OpacityTransition/OpacityTransition.js';
|
|
66
|
-
import '../OverlayCard/OverlayCard.js';
|
|
67
64
|
import '../PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js';
|
|
68
65
|
import '../Popper/Popper/Popper.js';
|
|
69
66
|
import '../Popper/PopperContext/PopperContext.js';
|
|
70
67
|
import 'react-focus-lock';
|
|
71
68
|
import 'qrcode';
|
|
72
|
-
import { NetworkAction } from './components/NetworkAction/NetworkAction.js';
|
|
73
69
|
import { NetworkControl } from './components/NetworkControl/NetworkControl.js';
|
|
70
|
+
import { NetworkDropdown } from './components/NetworkDropdown/NetworkDropdown.js';
|
|
74
71
|
import 'formik';
|
|
75
72
|
import '../../utils/hooks/useSubdomainCheck/useSubdomainCheck.js';
|
|
76
73
|
import '../../context/WalletGroupContext/WalletGroupContext.js';
|
|
@@ -94,42 +91,16 @@ import '../../store/state/tokenBalances.js';
|
|
|
94
91
|
import '../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
|
|
95
92
|
import { useInternalDynamicContext } from '../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.js';
|
|
96
93
|
|
|
97
|
-
const NetworkPicker = ({ activeClassName = '', buttonClassName = '', checkboxClassName = '', connector,
|
|
94
|
+
const NetworkPicker = ({ activeClassName = '', buttonClassName = '', checkboxClassName = '', connector, listClassName = '', mainClassName = '', showNetworkName, customCallbackOnSuccess, currentNetwork, isLoading = false, }) => {
|
|
95
|
+
const [isNetworkPickerOpen, setIsNetworkPickerOpen] = useState(false);
|
|
98
96
|
const pickerRef = useRef(null);
|
|
99
|
-
const [newNetworkId, setNewNetworkId] = useState(undefined);
|
|
100
97
|
const { loadingNetwork } = useInternalDynamicContext();
|
|
101
|
-
const { data: supportedWalletNetworks } = usePromise(() => isWalletConnectConnector(connector)
|
|
102
|
-
? connector.getSupportedNetworks()
|
|
103
|
-
: Promise.resolve(evmNetworks.map(({ networkId }) => `${networkId}`)), {
|
|
104
|
-
deps: [connector, evmNetworks, isNetworkPickerOpen],
|
|
105
|
-
initialData: undefined,
|
|
106
|
-
});
|
|
107
|
-
const shouldAllowOpenDropdown = isNetworkUnsupported(currentNetwork, evmNetworks) ||
|
|
108
|
-
(evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.length) > 1;
|
|
109
98
|
// Ref to anchor popper to
|
|
110
99
|
const anchorRef = useRef(null);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
networkChainId: networkId,
|
|
116
|
-
}));
|
|
117
|
-
customCallbackOnSuccess === null || customCallbackOnSuccess === void 0 ? void 0 : customCallbackOnSuccess();
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
/* istanbul ignore next */
|
|
121
|
-
logger.debug(error);
|
|
122
|
-
}
|
|
123
|
-
finally {
|
|
124
|
-
setNewNetworkId(undefined);
|
|
125
|
-
setIsNetworkPickerOpen(false);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
return (jsxs("div", { className: classNames('non-widget-network-picker', mainClassName), ref: pickerRef, "data-testid": 'network-picker', children: [jsxs("div", { className: 'network-picker-network-control', children: [jsx(NetworkControl, { evmNetworks: evmNetworks, activeClassName: activeClassName, network: currentNetwork, loading: loadingNetwork || isLoading, isOpen: isNetworkPickerOpen, setIsOpen: setIsNetworkPickerOpen, walletConnector: connector, showNetworkName: showNetworkName, buttonClassName: buttonClassName }), jsx("div", { ref: anchorRef, className: 'network-picker-network-control__anchor' })] }), shouldAllowOpenDropdown && (jsx(MenuList, { className: listClassName, isOpen: isNetworkPickerOpen, onClickClose: () => setIsNetworkPickerOpen(false), popperProps: {
|
|
129
|
-
anchorOrigin: 'bottom-left',
|
|
130
|
-
anchorRef,
|
|
131
|
-
}, mobileTitle: 'Select network', children: evmNetworks.map(({ name, networkId, vanityName, iconUrls }) => (jsx(NetworkAction, { iconUrl: iconUrls === null || iconUrls === void 0 ? void 0 : iconUrls[0], networkId: networkId, networkName: vanityName || name, network: currentNetwork, onClick: handleNetworkChange, checkboxClassName: checkboxClassName, newNetworkId: newNetworkId, notSupported: supportedWalletNetworks &&
|
|
132
|
-
!supportedWalletNetworks.includes(`${networkId}`) }, networkId))) }))] }));
|
|
100
|
+
if (!connector) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return (jsxs("div", { className: classNames('non-widget-network-picker', mainClassName), ref: pickerRef, "data-testid": 'network-picker', children: [jsxs("div", { className: 'network-picker-network-control', children: [jsx(NetworkControl, { activeClassName: activeClassName, network: currentNetwork, loading: loadingNetwork || isLoading, isOpen: isNetworkPickerOpen, setIsOpen: setIsNetworkPickerOpen, walletConnector: connector, showNetworkName: showNetworkName, buttonClassName: buttonClassName }), jsx("div", { ref: anchorRef, className: 'network-picker-network-control__anchor' })] }), jsx(NetworkDropdown, { anchorRef: anchorRef, customCallbackOnSuccess: customCallbackOnSuccess, connector: connector, className: listClassName, checkboxClassName: checkboxClassName, isNetworkPickerOpen: isNetworkPickerOpen, setIsNetworkPickerOpen: setIsNetworkPickerOpen, currentNetwork: currentNetwork })] }));
|
|
133
104
|
};
|
|
134
105
|
|
|
135
106
|
export { NetworkPicker };
|
|
@@ -5,26 +5,24 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
8
|
-
var
|
|
8
|
+
var NetworkSwitchControl = require('../NetworkSwitchControl/NetworkSwitchControl.cjs');
|
|
9
9
|
var NetworkControlSkeleton = require('../NetworkControlSkeleton/NetworkControlSkeleton.cjs');
|
|
10
10
|
var NonNetworkSwitchingSupportedControl = require('../NonNetworkSwitchingSupportedControl/NonNetworkSwitchingSupportedControl.cjs');
|
|
11
11
|
|
|
12
|
-
const NetworkControl = ({ loading, walletConnector, buttonClassName, network,
|
|
12
|
+
const NetworkControl = ({ loading, walletConnector, buttonClassName, network, activeClassName, isOpen, setIsOpen, showNetworkName, }) => {
|
|
13
|
+
const enabledNetworks = walletConnector.getEnabledNetworks();
|
|
13
14
|
// Checks when switching to EVM if the network is still loading.
|
|
14
15
|
// if network is a string the user is switching chains
|
|
15
16
|
// this prevents the network control from flickering
|
|
16
|
-
const chainSwitchLoading =
|
|
17
|
+
const chainSwitchLoading = walletConnector.connectedChain === sdkApiCore.ChainEnum.Evm &&
|
|
17
18
|
typeof network === 'string';
|
|
18
19
|
if (loading || chainSwitchLoading) {
|
|
19
20
|
return jsxRuntime.jsx(NetworkControlSkeleton.NetworkControlSkeleton, { className: buttonClassName });
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
!walletConnector.supportsNetworkSwitching()) {
|
|
22
|
+
if (!walletConnector.supportsNetworkSwitching()) {
|
|
23
23
|
return (jsxRuntime.jsx(NonNetworkSwitchingSupportedControl.NonNetworkSwitchingSupportedControl, { className: buttonClassName, showNetworkName: showNetworkName, walletConnector: walletConnector }));
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
return (jsxRuntime.jsx(EvmNetworkControl.EvmNetworkControl, { showNetworkName: showNetworkName, evmNetworks: evmNetworks, activeClassName: activeClassName, className: buttonClassName, network: network, loading: loading, isOpen: isOpen, walletConnector: walletConnector, setIsOpen: setIsOpen }));
|
|
27
|
-
}
|
|
25
|
+
return (jsxRuntime.jsx(NetworkSwitchControl.NetworkSwitchControl, { showNetworkName: showNetworkName, enabledNetworks: enabledNetworks, activeClassName: activeClassName, className: buttonClassName, network: network, loading: loading, isOpen: isOpen, walletConnector: walletConnector, setIsOpen: setIsOpen }));
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
exports.NetworkControl = NetworkControl;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
import { EvmNetwork } from '@dynamic-labs/types';
|
|
3
2
|
import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
3
|
type Props = {
|
|
5
4
|
activeClassName?: string;
|
|
6
5
|
buttonClassName?: string;
|
|
7
|
-
evmNetworks?: EvmNetwork[];
|
|
8
6
|
isOpen: boolean;
|
|
9
7
|
loading: boolean;
|
|
10
8
|
network: number | string | undefined;
|
|
11
9
|
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
|
12
10
|
showNetworkName?: boolean;
|
|
13
|
-
walletConnector: WalletConnector
|
|
11
|
+
walletConnector: WalletConnector;
|
|
14
12
|
};
|
|
15
|
-
export declare const NetworkControl: ({ loading, walletConnector, buttonClassName, network,
|
|
13
|
+
export declare const NetworkControl: ({ loading, walletConnector, buttonClassName, network, activeClassName, isOpen, setIsOpen, showNetworkName, }: Props) => JSX.Element;
|
|
16
14
|
export {};
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { ChainEnum } from '@dynamic-labs/sdk-api-core';
|
|
4
|
-
import {
|
|
4
|
+
import { NetworkSwitchControl } from '../NetworkSwitchControl/NetworkSwitchControl.js';
|
|
5
5
|
import { NetworkControlSkeleton } from '../NetworkControlSkeleton/NetworkControlSkeleton.js';
|
|
6
6
|
import { NonNetworkSwitchingSupportedControl } from '../NonNetworkSwitchingSupportedControl/NonNetworkSwitchingSupportedControl.js';
|
|
7
7
|
|
|
8
|
-
const NetworkControl = ({ loading, walletConnector, buttonClassName, network,
|
|
8
|
+
const NetworkControl = ({ loading, walletConnector, buttonClassName, network, activeClassName, isOpen, setIsOpen, showNetworkName, }) => {
|
|
9
|
+
const enabledNetworks = walletConnector.getEnabledNetworks();
|
|
9
10
|
// Checks when switching to EVM if the network is still loading.
|
|
10
11
|
// if network is a string the user is switching chains
|
|
11
12
|
// this prevents the network control from flickering
|
|
12
|
-
const chainSwitchLoading =
|
|
13
|
+
const chainSwitchLoading = walletConnector.connectedChain === ChainEnum.Evm &&
|
|
13
14
|
typeof network === 'string';
|
|
14
15
|
if (loading || chainSwitchLoading) {
|
|
15
16
|
return jsx(NetworkControlSkeleton, { className: buttonClassName });
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
!walletConnector.supportsNetworkSwitching()) {
|
|
18
|
+
if (!walletConnector.supportsNetworkSwitching()) {
|
|
19
19
|
return (jsx(NonNetworkSwitchingSupportedControl, { className: buttonClassName, showNetworkName: showNetworkName, walletConnector: walletConnector }));
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
return (jsx(EvmNetworkControl, { showNetworkName: showNetworkName, evmNetworks: evmNetworks, activeClassName: activeClassName, className: buttonClassName, network: network, loading: loading, isOpen: isOpen, walletConnector: walletConnector, setIsOpen: setIsOpen }));
|
|
23
|
-
}
|
|
21
|
+
return (jsx(NetworkSwitchControl, { showNetworkName: showNetworkName, enabledNetworks: enabledNetworks, activeClassName: activeClassName, className: buttonClassName, network: network, loading: loading, isOpen: isOpen, walletConnector: walletConnector, setIsOpen: setIsOpen }));
|
|
24
22
|
};
|
|
25
23
|
|
|
26
24
|
export { NetworkControl };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../../../../_virtual/_tslib.cjs');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var React = require('react');
|
|
9
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
10
|
+
require('../../../MenuList/Dropdown/Dropdown.cjs');
|
|
11
|
+
var MenuList = require('../../../MenuList/MenuList/MenuList.cjs');
|
|
12
|
+
var NetworkAction = require('../NetworkAction/NetworkAction.cjs');
|
|
13
|
+
var isNetworkUnsupported = require('../../../../utils/functions/isNetworkUnsupported/isNetworkUnsupported.cjs');
|
|
14
|
+
var usePromise = require('../../../../utils/hooks/usePromise/usePromise.cjs');
|
|
15
|
+
require('@dynamic-labs/sdk-api-core');
|
|
16
|
+
var logger = require('../../../../shared/logger.cjs');
|
|
17
|
+
require('@dynamic-labs/iconic');
|
|
18
|
+
require('../../../../context/ViewContext/ViewContext.cjs');
|
|
19
|
+
require('@dynamic-labs/wallet-book');
|
|
20
|
+
require('@dynamic-labs/utils');
|
|
21
|
+
require('../../../../utils/constants/colors.cjs');
|
|
22
|
+
require('../../../../utils/constants/values.cjs');
|
|
23
|
+
require('../../../../shared/consts/index.cjs');
|
|
24
|
+
|
|
25
|
+
const NetworkDropdown = ({ anchorRef, connector, customCallbackOnSuccess, setIsNetworkPickerOpen, isNetworkPickerOpen, currentNetwork, className, checkboxClassName, }) => {
|
|
26
|
+
const [newNetworkId, setNewNetworkId] = React.useState(undefined);
|
|
27
|
+
const { data: wcSupportedWalletNetworks } = usePromise.usePromise(() => walletConnectorCore.isWalletConnectConnector(connector)
|
|
28
|
+
? connector === null || connector === void 0 ? void 0 : connector.getSupportedNetworks()
|
|
29
|
+
: Promise.resolve(undefined), {
|
|
30
|
+
deps: [connector, isNetworkPickerOpen],
|
|
31
|
+
enabled: connector.isWalletConnect,
|
|
32
|
+
initialData: undefined,
|
|
33
|
+
});
|
|
34
|
+
if (!connector) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const enabledNetworks = connector.getEnabledNetworks();
|
|
38
|
+
const shouldAllowOpenDropdown = isNetworkUnsupported.isNetworkUnsupported(currentNetwork, enabledNetworks) ||
|
|
39
|
+
enabledNetworks.length > 1;
|
|
40
|
+
if (!shouldAllowOpenDropdown) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const handleNetworkChange = (networkId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
setNewNetworkId(networkId);
|
|
45
|
+
try {
|
|
46
|
+
yield connector.switchNetwork({
|
|
47
|
+
networkChainId: networkId,
|
|
48
|
+
});
|
|
49
|
+
customCallbackOnSuccess === null || customCallbackOnSuccess === void 0 ? void 0 : customCallbackOnSuccess();
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
/* istanbul ignore next */
|
|
53
|
+
logger.logger.debug(error);
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
setNewNetworkId(undefined);
|
|
57
|
+
setIsNetworkPickerOpen(false);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return (jsxRuntime.jsx(MenuList.MenuList, { className: className, isOpen: isNetworkPickerOpen, onClickClose: () => setIsNetworkPickerOpen(false), popperProps: {
|
|
61
|
+
anchorOrigin: 'bottom-left',
|
|
62
|
+
anchorRef,
|
|
63
|
+
}, mobileTitle: 'Select network', children: enabledNetworks.map(({ name, networkId, vanityName, iconUrls }) => (jsxRuntime.jsx(NetworkAction.NetworkAction, { iconUrl: iconUrls === null || iconUrls === void 0 ? void 0 : iconUrls[0], networkId: networkId, networkName: vanityName || name, network: currentNetwork, onClick: handleNetworkChange, checkboxClassName: checkboxClassName, newNetworkId: newNetworkId, notSupported: wcSupportedWalletNetworks &&
|
|
64
|
+
!wcSupportedWalletNetworks.includes(`${networkId}`) }, networkId))) }));
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
exports.NetworkDropdown = NetworkDropdown;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Dispatch, RefObject, SetStateAction } from 'react';
|
|
2
|
+
import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
type NetworkDropdownProps = {
|
|
4
|
+
anchorRef: RefObject<HTMLDivElement>;
|
|
5
|
+
connector: WalletConnector;
|
|
6
|
+
customCallbackOnSuccess?: () => void;
|
|
7
|
+
setIsNetworkPickerOpen: Dispatch<SetStateAction<boolean>>;
|
|
8
|
+
isNetworkPickerOpen: boolean;
|
|
9
|
+
className?: string;
|
|
10
|
+
checkboxClassName?: string;
|
|
11
|
+
currentNetwork: string | number | undefined;
|
|
12
|
+
};
|
|
13
|
+
export declare const NetworkDropdown: ({ anchorRef, connector, customCallbackOnSuccess, setIsNetworkPickerOpen, isNetworkPickerOpen, currentNetwork, className, checkboxClassName, }: NetworkDropdownProps) => JSX.Element | null;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../../../../_virtual/_tslib.js';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import { isWalletConnectConnector } from '@dynamic-labs/wallet-connector-core';
|
|
6
|
+
import '../../../MenuList/Dropdown/Dropdown.js';
|
|
7
|
+
import { MenuList } from '../../../MenuList/MenuList/MenuList.js';
|
|
8
|
+
import { NetworkAction } from '../NetworkAction/NetworkAction.js';
|
|
9
|
+
import { isNetworkUnsupported } from '../../../../utils/functions/isNetworkUnsupported/isNetworkUnsupported.js';
|
|
10
|
+
import { usePromise } from '../../../../utils/hooks/usePromise/usePromise.js';
|
|
11
|
+
import '@dynamic-labs/sdk-api-core';
|
|
12
|
+
import { logger } from '../../../../shared/logger.js';
|
|
13
|
+
import '@dynamic-labs/iconic';
|
|
14
|
+
import '../../../../context/ViewContext/ViewContext.js';
|
|
15
|
+
import '@dynamic-labs/wallet-book';
|
|
16
|
+
import '@dynamic-labs/utils';
|
|
17
|
+
import '../../../../utils/constants/colors.js';
|
|
18
|
+
import '../../../../utils/constants/values.js';
|
|
19
|
+
import '../../../../shared/consts/index.js';
|
|
20
|
+
|
|
21
|
+
const NetworkDropdown = ({ anchorRef, connector, customCallbackOnSuccess, setIsNetworkPickerOpen, isNetworkPickerOpen, currentNetwork, className, checkboxClassName, }) => {
|
|
22
|
+
const [newNetworkId, setNewNetworkId] = useState(undefined);
|
|
23
|
+
const { data: wcSupportedWalletNetworks } = usePromise(() => isWalletConnectConnector(connector)
|
|
24
|
+
? connector === null || connector === void 0 ? void 0 : connector.getSupportedNetworks()
|
|
25
|
+
: Promise.resolve(undefined), {
|
|
26
|
+
deps: [connector, isNetworkPickerOpen],
|
|
27
|
+
enabled: connector.isWalletConnect,
|
|
28
|
+
initialData: undefined,
|
|
29
|
+
});
|
|
30
|
+
if (!connector) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const enabledNetworks = connector.getEnabledNetworks();
|
|
34
|
+
const shouldAllowOpenDropdown = isNetworkUnsupported(currentNetwork, enabledNetworks) ||
|
|
35
|
+
enabledNetworks.length > 1;
|
|
36
|
+
if (!shouldAllowOpenDropdown) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const handleNetworkChange = (networkId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
setNewNetworkId(networkId);
|
|
41
|
+
try {
|
|
42
|
+
yield connector.switchNetwork({
|
|
43
|
+
networkChainId: networkId,
|
|
44
|
+
});
|
|
45
|
+
customCallbackOnSuccess === null || customCallbackOnSuccess === void 0 ? void 0 : customCallbackOnSuccess();
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
/* istanbul ignore next */
|
|
49
|
+
logger.debug(error);
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
setNewNetworkId(undefined);
|
|
53
|
+
setIsNetworkPickerOpen(false);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return (jsx(MenuList, { className: className, isOpen: isNetworkPickerOpen, onClickClose: () => setIsNetworkPickerOpen(false), popperProps: {
|
|
57
|
+
anchorOrigin: 'bottom-left',
|
|
58
|
+
anchorRef,
|
|
59
|
+
}, mobileTitle: 'Select network', children: enabledNetworks.map(({ name, networkId, vanityName, iconUrls }) => (jsx(NetworkAction, { iconUrl: iconUrls === null || iconUrls === void 0 ? void 0 : iconUrls[0], networkId: networkId, networkName: vanityName || name, network: currentNetwork, onClick: handleNetworkChange, checkboxClassName: checkboxClassName, newNetworkId: newNetworkId, notSupported: wcSupportedWalletNetworks &&
|
|
60
|
+
!wcSupportedWalletNetworks.includes(`${networkId}`) }, networkId))) }));
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export { NetworkDropdown };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './NetworkDropdown';
|