@dynamic-labs/sdk-react-core 4.92.3 → 4.93.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/package.cjs +5 -5
  3. package/package.js +5 -5
  4. package/package.json +16 -16
  5. package/src/lib/components/SendBalanceForm/SendBalanceForm.cjs +28 -4
  6. package/src/lib/components/SendBalanceForm/SendBalanceForm.js +28 -4
  7. package/src/lib/context/CaptchaContext/CaptchaContext.cjs +10 -2
  8. package/src/lib/context/CaptchaContext/CaptchaContext.d.ts +2 -1
  9. package/src/lib/context/CaptchaContext/CaptchaContext.js +10 -2
  10. package/src/lib/context/DynamicContext/types/DynamicContextProps.d.ts +1 -1
  11. package/src/lib/store/state/dynamicContextProps/defaultDynamicSettings.cjs +1 -1
  12. package/src/lib/store/state/dynamicContextProps/defaultDynamicSettings.d.ts +1 -1
  13. package/src/lib/store/state/dynamicContextProps/defaultDynamicSettings.js +1 -1
  14. package/src/lib/utils/functions/getEmbeddedBitcoinActiveAddress/getEmbeddedBitcoinActiveAddress.cjs +24 -0
  15. package/src/lib/utils/functions/getEmbeddedBitcoinActiveAddress/getEmbeddedBitcoinActiveAddress.d.ts +11 -0
  16. package/src/lib/utils/functions/getEmbeddedBitcoinActiveAddress/getEmbeddedBitcoinActiveAddress.js +20 -0
  17. package/src/lib/utils/functions/getEmbeddedBitcoinActiveAddress/index.d.ts +1 -0
  18. package/src/lib/utils/functions/getTransactionLink/blockExplorerPatterns.cjs +12 -0
  19. package/src/lib/utils/functions/getTransactionLink/blockExplorerPatterns.js +12 -0
  20. package/src/lib/utils/functions/getWalletAdditionalAddressByType/getWalletAdditionalAddressByType.cjs +16 -3
  21. package/src/lib/utils/functions/getWalletAdditionalAddressByType/getWalletAdditionalAddressByType.d.ts +8 -1
  22. package/src/lib/utils/functions/getWalletAdditionalAddressByType/getWalletAdditionalAddressByType.js +16 -3
  23. package/src/lib/utils/functions/index.d.ts +1 -0
  24. package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.cjs +50 -2
  25. package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.js +50 -2
  26. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +12 -0
  27. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +12 -0
  28. package/src/lib/utils/hooks/useTokenBalances/useTokenBalances.cjs +9 -5
  29. package/src/lib/utils/hooks/useTokenBalances/useTokenBalances.js +9 -5
  30. package/src/lib/utils/hooks/useWalletItemActions/useHandleWalletItem/useHandleWalletItem.cjs +6 -1
  31. package/src/lib/utils/hooks/useWalletItemActions/useHandleWalletItem/useHandleWalletItem.js +6 -1
  32. package/src/lib/widgets/DynamicWidget/components/ActiveMidnightWalletBalance/ActiveMidnightWalletBalance.cjs +40 -8
  33. package/src/lib/widgets/DynamicWidget/components/ActiveMidnightWalletBalance/ActiveMidnightWalletBalance.js +41 -9
  34. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveMidnightWalletAddresses/ActiveMidnightWalletAddresses.cjs +20 -6
  35. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveMidnightWalletAddresses/ActiveMidnightWalletAddresses.d.ts +7 -1
  36. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveMidnightWalletAddresses/ActiveMidnightWalletAddresses.js +20 -6
  37. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletAddress/ActiveWalletAddress.cjs +5 -2
  38. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletAddress/ActiveWalletAddress.js +5 -2
  39. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.cjs +17 -9
  40. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.js +18 -10
  41. package/src/lib/widgets/DynamicWidget/views/DepositView/DepositView.cjs +21 -6
  42. package/src/lib/widgets/DynamicWidget/views/DepositView/DepositView.js +22 -7
@@ -124,12 +124,26 @@ const MIDNIGHT_ADDRESS_TYPE_UNSHIELDED = 'midnight_unshielded';
124
124
  const MIDNIGHT_ADDRESS_TYPE_DUST = 'midnight_dust';
125
125
  const MIDNIGHT_ADDRESS_TYPE_SHIELDED = 'midnight_shielded';
126
126
  /**
127
- * Gets a Midnight address from the wallet's additional addresses by type.
127
+ * Gets a Midnight address from the wallet's additional addresses by type,
128
+ * preferring the variant tagged with the selected network.
129
+ *
130
+ * Midnight stores one address per (type, network) — e.g. unshielded has both a
131
+ * mainnet and a preview encoding of the same key. When the user switches the
132
+ * network picker we surface the address tagged with that network. Legacy wallets
133
+ * created before per-network tagging have no `network`, so we fall back to the
134
+ * first address of the requested type.
135
+ *
128
136
  * @param type - The address type to find
137
+ * @param network - The selected network tag ('mainnet' | 'preview')
129
138
  * @param wallet - The wallet containing additional addresses
130
139
  * @returns The address string or undefined if not found
131
140
  */
132
- const getMidnightAddressByType = (type, wallet) => { var _a, _b; return (_b = (_a = wallet === null || wallet === void 0 ? void 0 : wallet.additionalAddresses) === null || _a === void 0 ? void 0 : _a.find((addr) => addr.type === type)) === null || _b === void 0 ? void 0 : _b.address; };
141
+ const getMidnightAddressByType = (type, network, wallet) => {
142
+ var _a, _b, _c;
143
+ const matches = (_b = (_a = wallet === null || wallet === void 0 ? void 0 : wallet.additionalAddresses) === null || _a === void 0 ? void 0 : _a.filter((addr) => addr.type === type)) !== null && _b !== void 0 ? _b : [];
144
+ const networkMatch = matches.find((addr) => addr.network === network);
145
+ return (_c = (networkMatch !== null && networkMatch !== void 0 ? networkMatch : matches[0])) === null || _c === void 0 ? void 0 : _c.address;
146
+ };
133
147
  /**
134
148
  * Component for displaying Midnight wallet addresses.
135
149
  * Midnight supports multiple address types:
@@ -137,12 +151,12 @@ const getMidnightAddressByType = (type, wallet) => { var _a, _b; return (_b = (_
137
151
  * - Dust: For gas/fee management
138
152
  * - Shielded: For private transfers (Phase 2)
139
153
  */
140
- const ActiveMidnightWalletAddresses = ({ menuOption, wallet, }) => {
154
+ const ActiveMidnightWalletAddresses = ({ menuOption, wallet, network, }) => {
141
155
  var _a;
142
156
  const { t } = useTranslation();
143
- const unshieldedAddress = (_a = getMidnightAddressByType(MIDNIGHT_ADDRESS_TYPE_UNSHIELDED, wallet)) !== null && _a !== void 0 ? _a : wallet === null || wallet === void 0 ? void 0 : wallet.address;
144
- const dustAddress = getMidnightAddressByType(MIDNIGHT_ADDRESS_TYPE_DUST, wallet);
145
- const shieldedAddress = getMidnightAddressByType(MIDNIGHT_ADDRESS_TYPE_SHIELDED, wallet);
157
+ const unshieldedAddress = (_a = getMidnightAddressByType(MIDNIGHT_ADDRESS_TYPE_UNSHIELDED, network, wallet)) !== null && _a !== void 0 ? _a : wallet === null || wallet === void 0 ? void 0 : wallet.address;
158
+ const dustAddress = getMidnightAddressByType(MIDNIGHT_ADDRESS_TYPE_DUST, network, wallet);
159
+ const shieldedAddress = getMidnightAddressByType(MIDNIGHT_ADDRESS_TYPE_SHIELDED, network, wallet);
146
160
  // Collapse dust + shielded behind a toggle so the header shows only the
147
161
  // primary (unshielded) address by default — the user reveals the rest on
148
162
  // click, instead of all three being shown at once.
@@ -152,8 +152,11 @@ const ActiveWalletAddress = ({ wallet, nameServiceName, menuOption, fullWidth =
152
152
  }, [setShowMenu]);
153
153
  const iconRef = React.useRef(null);
154
154
  const { data: address } = usePromise.usePromise(() => {
155
- // COSMOS wallet address changes based on which network is selected
156
- if ((wallet === null || wallet === void 0 ? void 0 : wallet.connector.connectedChain) === 'COSMOS') {
155
+ // COSMOS wallet address changes based on which network is selected;
156
+ // embedded Bitcoin wallets expose a per-network payment address too
157
+ if ((wallet === null || wallet === void 0 ? void 0 : wallet.connector.connectedChain) === 'COSMOS' ||
158
+ ((wallet === null || wallet === void 0 ? void 0 : wallet.connector.connectedChain) === 'BTC' &&
159
+ (wallet === null || wallet === void 0 ? void 0 : wallet.connector.isEmbeddedWallet))) {
157
160
  return wallet === null || wallet === void 0 ? void 0 : wallet.connector.getAddress();
158
161
  }
159
162
  return wallet === null || wallet === void 0 ? void 0 : wallet.address;
@@ -148,8 +148,11 @@ const ActiveWalletAddress = ({ wallet, nameServiceName, menuOption, fullWidth =
148
148
  }, [setShowMenu]);
149
149
  const iconRef = useRef(null);
150
150
  const { data: address } = usePromise(() => {
151
- // COSMOS wallet address changes based on which network is selected
152
- if ((wallet === null || wallet === void 0 ? void 0 : wallet.connector.connectedChain) === 'COSMOS') {
151
+ // COSMOS wallet address changes based on which network is selected;
152
+ // embedded Bitcoin wallets expose a per-network payment address too
153
+ if ((wallet === null || wallet === void 0 ? void 0 : wallet.connector.connectedChain) === 'COSMOS' ||
154
+ ((wallet === null || wallet === void 0 ? void 0 : wallet.connector.connectedChain) === 'BTC' &&
155
+ (wallet === null || wallet === void 0 ? void 0 : wallet.connector.isEmbeddedWallet))) {
153
156
  return wallet === null || wallet === void 0 ? void 0 : wallet.connector.getAddress();
154
157
  }
155
158
  return wallet === null || wallet === void 0 ? void 0 : wallet.address;
@@ -7,6 +7,7 @@ var _tslib = require('../../../../../../_virtual/_tslib.cjs');
7
7
  var jsxRuntime = require('react/jsx-runtime');
8
8
  var React = require('react');
9
9
  var reactI18next = require('react-i18next');
10
+ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
10
11
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
11
12
  require('../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
12
13
  var copy = require('../../../../shared/assets/copy.cjs');
@@ -22,7 +23,6 @@ require('@dynamic-labs/wallet-book');
22
23
  require('@dynamic-labs/utils');
23
24
  require('../../../../utils/constants/colors.cjs');
24
25
  require('../../../../utils/constants/values.cjs');
25
- require('@dynamic-labs/sdk-api-core');
26
26
  require('../../../../shared/consts/index.cjs');
27
27
  var Alert = require('../../../../components/Alert/Alert.cjs');
28
28
  require('../../../../events/dynamicEvents.cjs');
@@ -39,6 +39,8 @@ require('eventemitter3');
39
39
  require('@dynamic-labs-sdk/client');
40
40
  require('../../../../config/ApiEndpoint.cjs');
41
41
  var useProjectSettings = require('../../../../client/extension/projectSettings/useProjectSettings/useProjectSettings.cjs');
42
+ var getEmbeddedBitcoinActiveAddress = require('../../../../utils/functions/getEmbeddedBitcoinActiveAddress/getEmbeddedBitcoinActiveAddress.cjs');
43
+ var getWalletAdditionalAddressByType = require('../../../../utils/functions/getWalletAdditionalAddressByType/getWalletAdditionalAddressByType.cjs');
42
44
  require('@dynamic-labs/locale');
43
45
  require('../../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
44
46
  var primaryWalletId = require('../../../../store/state/primaryWalletId/primaryWalletId.cjs');
@@ -139,7 +141,7 @@ var ActiveWalletAddress = require('./ActiveWalletAddress/ActiveWalletAddress.cjs
139
141
  const ICON_SIZE = 32;
140
142
  const DROPDOWN_ICON_SIZE = 16;
141
143
  const ActiveWalletInformation = ({ isLoading = false, }) => {
142
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
144
+ var _a, _b, _c, _d, _e;
143
145
  const { t } = reactI18next.useTranslation();
144
146
  const [detailsCardOpen, setDetailsCardOpen] = React.useState(false);
145
147
  const { primaryWallet, network, user, removeWallet } = useInternalDynamicContext.useInternalDynamicContext();
@@ -148,17 +150,23 @@ const ActiveWalletInformation = ({ isLoading = false, }) => {
148
150
  const projectSettings = useProjectSettings.useProjectSettings();
149
151
  const { setDynamicWidgetView, headerAlert } = DynamicWidgetContext.useWidgetContext();
150
152
  const { isTurnkeyWalletWithoutAuthenticator } = useIsTurnkeyWallet.useIsTurnkeyWallet();
151
- const address = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address;
153
+ // Per-network address: embedded Bitcoin swaps its active address on network
154
+ // switch (context `network` changes re-render this component).
155
+ const address = (_a = getEmbeddedBitcoinActiveAddress.getEmbeddedBitcoinActiveAddress(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector)) !== null && _a !== void 0 ? _a : primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address;
152
156
  const nameService = useFetchNameService.useFetchNameService(primaryWallet !== null && primaryWallet !== void 0 ? primaryWallet : undefined);
153
157
  const { getEOAWallet } = useSmartWallets.useSmartWallets();
154
158
  const { data: testnet } = usePromise.usePromise(() => _tslib.__awaiter(void 0, void 0, void 0, function* () { return Boolean(yield (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.isTestnet())); }), { deps: [network], initialData: false });
155
159
  const exportKeysOption = helpers.getExportKeysOption(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
156
160
  const { showAlert } = PasskeyContext.usePasskeyContext();
157
- const wallet = (_a = (primaryWallet && getEOAWallet(primaryWallet))) !== null && _a !== void 0 ? _a : primaryWallet;
161
+ const wallet = (_b = (primaryWallet && getEOAWallet(primaryWallet))) !== null && _b !== void 0 ? _b : primaryWallet;
158
162
  const isBitcoin = primaryWallet && walletConnectorCore.isBitcoinConnector(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector);
159
163
  const isMidnight = primaryWallet && walletConnectorCore.isMidnightConnector(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector);
164
+ // Midnight is one wallet (one MPC key) exposing a per-network address for
165
+ // each type. The connector resolves the selected network to the address tag
166
+ // ('mainnet' | 'preview'). Recomputed on every switch since `network` changes.
167
+ const midnightNetworkTag = walletConnectorCore.getMidnightNetworkTag(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector);
160
168
  const isWaasWallet = primaryWallet && walletConnectorCore.isDynamicWaasConnector(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector);
161
- const isEmbeddedWallet = Boolean(wallet && ((_c = (_b = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _b === void 0 ? void 0 : _b.key) === null || _c === void 0 ? void 0 : _c.startsWith('turnkey')));
169
+ const isEmbeddedWallet = Boolean(wallet && ((_d = (_c = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _c === void 0 ? void 0 : _c.key) === null || _d === void 0 ? void 0 : _d.startsWith('turnkey')));
162
170
  const openDetailsCard = React.useCallback(() => {
163
171
  setTimeout(() => setDetailsCardOpen(true), 0);
164
172
  }, []);
@@ -220,7 +228,7 @@ const ActiveWalletInformation = ({ isLoading = false, }) => {
220
228
  // Midnight wallets (WaaS and external/injected alike) expose multiple
221
229
  // address types (Unshielded, Dust, Shielded) via additionalAddresses.
222
230
  if (isMidnight) {
223
- return (jsxRuntime.jsx(ActiveMidnightWalletAddresses.ActiveMidnightWalletAddresses, { wallet: primaryWallet, menuOption: options }));
231
+ return (jsxRuntime.jsx(ActiveMidnightWalletAddresses.ActiveMidnightWalletAddresses, { wallet: primaryWallet, menuOption: options, network: midnightNetworkTag }));
224
232
  }
225
233
  return (jsxRuntime.jsx(ActiveWalletAddress.ActiveWalletAddress, { wallet: primaryWallet, nameServiceName: (nameService === null || nameService === void 0 ? void 0 : nameService.name) || (user === null || user === void 0 ? void 0 : user.email), menuOption: options, isLoading: isLoading, fullWidth: shouldHideNetwork, addressTypeLabel: getWaasAddressTypeLabel.getWaasAddressTypeLabel((primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain) || (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.connectedChain), Boolean(isWaasWallet), address) }));
226
234
  };
@@ -231,9 +239,9 @@ const ActiveWalletInformation = ({ isLoading = false, }) => {
231
239
  'active-wallet-information__addresses-container--centered': !(nameService === null || nameService === void 0 ? void 0 : nameService.name),
232
240
  }), children: activeWalletAddress() }), address && (jsxRuntime.jsx(WalletDetailsCard.WalletDetailsCard, { open: detailsCardOpen, address: address, onClose: () => setDetailsCardOpen(false), midnightAddresses: isMidnight
233
241
  ? {
234
- dust: (_e = (_d = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.additionalAddresses) === null || _d === void 0 ? void 0 : _d.find((a) => a.type === 'midnight_dust')) === null || _e === void 0 ? void 0 : _e.address,
235
- shielded: (_g = (_f = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.additionalAddresses) === null || _f === void 0 ? void 0 : _f.find((a) => a.type === 'midnight_shielded')) === null || _g === void 0 ? void 0 : _g.address,
236
- unshielded: (_k = (_j = (_h = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.additionalAddresses) === null || _h === void 0 ? void 0 : _h.find((a) => a.type === 'midnight_unshielded')) === null || _j === void 0 ? void 0 : _j.address) !== null && _k !== void 0 ? _k : address,
242
+ dust: getWalletAdditionalAddressByType.getWalletAdditionalAddressByType(sdkApiCore.WalletAddressType.MidnightDust, primaryWallet, midnightNetworkTag),
243
+ shielded: getWalletAdditionalAddressByType.getWalletAdditionalAddressByType(sdkApiCore.WalletAddressType.MidnightShielded, primaryWallet, midnightNetworkTag),
244
+ unshielded: (_e = getWalletAdditionalAddressByType.getWalletAdditionalAddressByType(sdkApiCore.WalletAddressType.MidnightUnshielded, primaryWallet, midnightNetworkTag)) !== null && _e !== void 0 ? _e : address,
237
245
  }
238
246
  : undefined })), !shouldHideNetwork && (jsxRuntime.jsx(NetworkPicker.NetworkPicker, { currentNetwork: network, connector: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, mainClassName: 'active-wallet-information__network-picker', buttonClassName: 'active-wallet-information__network-picker-button', showNetworkName: true, isLoading: isLoading }))] })] }), headerAlert && (jsxRuntime.jsx(Alert.Alert, { variant: headerAlert.variant, children: headerAlert.content })), showTestnetAlert && (jsxRuntime.jsx(Alert.Alert, { variant: 'warning', copykey: 'dyn_active_wallet_info.testnet_warning', children: t('dyn_active_wallet_info.testnet_warning') }))] }), isMidnight ? jsxRuntime.jsx(ActiveMidnightWalletBalance.ActiveMidnightWalletBalance, {}) : jsxRuntime.jsx(ActiveWalletBalance.ActiveWalletBalance, {})] }));
239
247
  };
@@ -3,7 +3,8 @@ import { __awaiter } from '../../../../../../_virtual/_tslib.js';
3
3
  import { jsx, jsxs } from 'react/jsx-runtime';
4
4
  import { useState, useCallback } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
- import { isBitcoinConnector, isMidnightConnector, isDynamicWaasConnector } from '@dynamic-labs/wallet-connector-core';
6
+ import { WalletAddressType } from '@dynamic-labs/sdk-api-core';
7
+ import { isBitcoinConnector, isMidnightConnector, getMidnightNetworkTag, isDynamicWaasConnector } from '@dynamic-labs/wallet-connector-core';
7
8
  import '../../../../components/Accordion/components/AccordionItem/AccordionItem.js';
8
9
  import { ReactComponent as SvgCopy } from '../../../../shared/assets/copy.js';
9
10
  import { ReactComponent as SvgEyeOutline } from '../../../../shared/assets/eye-outline.js';
@@ -18,7 +19,6 @@ import '@dynamic-labs/wallet-book';
18
19
  import '@dynamic-labs/utils';
19
20
  import '../../../../utils/constants/colors.js';
20
21
  import '../../../../utils/constants/values.js';
21
- import '@dynamic-labs/sdk-api-core';
22
22
  import '../../../../shared/consts/index.js';
23
23
  import { Alert } from '../../../../components/Alert/Alert.js';
24
24
  import '../../../../events/dynamicEvents.js';
@@ -35,6 +35,8 @@ import 'eventemitter3';
35
35
  import '@dynamic-labs-sdk/client';
36
36
  import '../../../../config/ApiEndpoint.js';
37
37
  import { useProjectSettings } from '../../../../client/extension/projectSettings/useProjectSettings/useProjectSettings.js';
38
+ import { getEmbeddedBitcoinActiveAddress } from '../../../../utils/functions/getEmbeddedBitcoinActiveAddress/getEmbeddedBitcoinActiveAddress.js';
39
+ import { getWalletAdditionalAddressByType } from '../../../../utils/functions/getWalletAdditionalAddressByType/getWalletAdditionalAddressByType.js';
38
40
  import '@dynamic-labs/locale';
39
41
  import '../../../../store/state/dynamicContextProps/dynamicContextProps.js';
40
42
  import { getPrimaryWalletId } from '../../../../store/state/primaryWalletId/primaryWalletId.js';
@@ -135,7 +137,7 @@ import { ActiveWalletAddress } from './ActiveWalletAddress/ActiveWalletAddress.j
135
137
  const ICON_SIZE = 32;
136
138
  const DROPDOWN_ICON_SIZE = 16;
137
139
  const ActiveWalletInformation = ({ isLoading = false, }) => {
138
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
140
+ var _a, _b, _c, _d, _e;
139
141
  const { t } = useTranslation();
140
142
  const [detailsCardOpen, setDetailsCardOpen] = useState(false);
141
143
  const { primaryWallet, network, user, removeWallet } = useInternalDynamicContext();
@@ -144,17 +146,23 @@ const ActiveWalletInformation = ({ isLoading = false, }) => {
144
146
  const projectSettings = useProjectSettings();
145
147
  const { setDynamicWidgetView, headerAlert } = useWidgetContext();
146
148
  const { isTurnkeyWalletWithoutAuthenticator } = useIsTurnkeyWallet();
147
- const address = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address;
149
+ // Per-network address: embedded Bitcoin swaps its active address on network
150
+ // switch (context `network` changes re-render this component).
151
+ const address = (_a = getEmbeddedBitcoinActiveAddress(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector)) !== null && _a !== void 0 ? _a : primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address;
148
152
  const nameService = useFetchNameService(primaryWallet !== null && primaryWallet !== void 0 ? primaryWallet : undefined);
149
153
  const { getEOAWallet } = useSmartWallets();
150
154
  const { data: testnet } = usePromise(() => __awaiter(void 0, void 0, void 0, function* () { return Boolean(yield (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.isTestnet())); }), { deps: [network], initialData: false });
151
155
  const exportKeysOption = getExportKeysOption(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
152
156
  const { showAlert } = usePasskeyContext();
153
- const wallet = (_a = (primaryWallet && getEOAWallet(primaryWallet))) !== null && _a !== void 0 ? _a : primaryWallet;
157
+ const wallet = (_b = (primaryWallet && getEOAWallet(primaryWallet))) !== null && _b !== void 0 ? _b : primaryWallet;
154
158
  const isBitcoin = primaryWallet && isBitcoinConnector(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector);
155
159
  const isMidnight = primaryWallet && isMidnightConnector(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector);
160
+ // Midnight is one wallet (one MPC key) exposing a per-network address for
161
+ // each type. The connector resolves the selected network to the address tag
162
+ // ('mainnet' | 'preview'). Recomputed on every switch since `network` changes.
163
+ const midnightNetworkTag = getMidnightNetworkTag(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector);
156
164
  const isWaasWallet = primaryWallet && isDynamicWaasConnector(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector);
157
- const isEmbeddedWallet = Boolean(wallet && ((_c = (_b = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _b === void 0 ? void 0 : _b.key) === null || _c === void 0 ? void 0 : _c.startsWith('turnkey')));
165
+ const isEmbeddedWallet = Boolean(wallet && ((_d = (_c = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _c === void 0 ? void 0 : _c.key) === null || _d === void 0 ? void 0 : _d.startsWith('turnkey')));
158
166
  const openDetailsCard = useCallback(() => {
159
167
  setTimeout(() => setDetailsCardOpen(true), 0);
160
168
  }, []);
@@ -216,7 +224,7 @@ const ActiveWalletInformation = ({ isLoading = false, }) => {
216
224
  // Midnight wallets (WaaS and external/injected alike) expose multiple
217
225
  // address types (Unshielded, Dust, Shielded) via additionalAddresses.
218
226
  if (isMidnight) {
219
- return (jsx(ActiveMidnightWalletAddresses, { wallet: primaryWallet, menuOption: options }));
227
+ return (jsx(ActiveMidnightWalletAddresses, { wallet: primaryWallet, menuOption: options, network: midnightNetworkTag }));
220
228
  }
221
229
  return (jsx(ActiveWalletAddress, { wallet: primaryWallet, nameServiceName: (nameService === null || nameService === void 0 ? void 0 : nameService.name) || (user === null || user === void 0 ? void 0 : user.email), menuOption: options, isLoading: isLoading, fullWidth: shouldHideNetwork, addressTypeLabel: getWaasAddressTypeLabel((primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain) || (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.connectedChain), Boolean(isWaasWallet), address) }));
222
230
  };
@@ -227,9 +235,9 @@ const ActiveWalletInformation = ({ isLoading = false, }) => {
227
235
  'active-wallet-information__addresses-container--centered': !(nameService === null || nameService === void 0 ? void 0 : nameService.name),
228
236
  }), children: activeWalletAddress() }), address && (jsx(WalletDetailsCard, { open: detailsCardOpen, address: address, onClose: () => setDetailsCardOpen(false), midnightAddresses: isMidnight
229
237
  ? {
230
- dust: (_e = (_d = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.additionalAddresses) === null || _d === void 0 ? void 0 : _d.find((a) => a.type === 'midnight_dust')) === null || _e === void 0 ? void 0 : _e.address,
231
- shielded: (_g = (_f = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.additionalAddresses) === null || _f === void 0 ? void 0 : _f.find((a) => a.type === 'midnight_shielded')) === null || _g === void 0 ? void 0 : _g.address,
232
- unshielded: (_k = (_j = (_h = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.additionalAddresses) === null || _h === void 0 ? void 0 : _h.find((a) => a.type === 'midnight_unshielded')) === null || _j === void 0 ? void 0 : _j.address) !== null && _k !== void 0 ? _k : address,
238
+ dust: getWalletAdditionalAddressByType(WalletAddressType.MidnightDust, primaryWallet, midnightNetworkTag),
239
+ shielded: getWalletAdditionalAddressByType(WalletAddressType.MidnightShielded, primaryWallet, midnightNetworkTag),
240
+ unshielded: (_e = getWalletAdditionalAddressByType(WalletAddressType.MidnightUnshielded, primaryWallet, midnightNetworkTag)) !== null && _e !== void 0 ? _e : address,
233
241
  }
234
242
  : undefined })), !shouldHideNetwork && (jsx(NetworkPicker, { currentNetwork: network, connector: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, mainClassName: 'active-wallet-information__network-picker', buttonClassName: 'active-wallet-information__network-picker-button', showNetworkName: true, isLoading: isLoading }))] })] }), headerAlert && (jsx(Alert, { variant: headerAlert.variant, children: headerAlert.content })), showTestnetAlert && (jsx(Alert, { variant: 'warning', copykey: 'dyn_active_wallet_info.testnet_warning', children: t('dyn_active_wallet_info.testnet_warning') }))] }), isMidnight ? jsx(ActiveMidnightWalletBalance, {}) : jsx(ActiveWalletBalance, {})] }));
235
243
  };
@@ -22,31 +22,46 @@ require('@dynamic-labs/iconic');
22
22
  require('../../../../context/ViewContext/ViewContext.cjs');
23
23
  var shortenWalletAddress = require('../../../../shared/utils/functions/shortenWalletAddress/shortenWalletAddress.cjs');
24
24
  var classNames = require('../../../../utils/functions/classNames/classNames.cjs');
25
+ var getEmbeddedBitcoinActiveAddress = require('../../../../utils/functions/getEmbeddedBitcoinActiveAddress/getEmbeddedBitcoinActiveAddress.cjs');
25
26
  var getWalletAdditionalAddressByType = require('../../../../utils/functions/getWalletAdditionalAddressByType/getWalletAdditionalAddressByType.cjs');
26
27
  var usePromise = require('../../../../utils/hooks/usePromise/usePromise.cjs');
27
28
  var DynamicWidgetContext = require('../../context/DynamicWidgetContext.cjs');
28
29
  var useFetchChain = require('../../hooks/useFetchChain/useFetchChain.cjs');
29
30
 
30
31
  const DepositView = () => {
31
- var _a;
32
+ var _a, _b;
32
33
  const { t } = reactI18next.useTranslation();
33
- const { primaryWallet, getNameService } = useInternalDynamicContext.useInternalDynamicContext();
34
+ // Per-network address: embedded Bitcoin swaps its active address on network
35
+ // switch (context `network` changes re-render this view).
36
+ const { primaryWallet, getNameService, network } = useInternalDynamicContext.useInternalDynamicContext();
34
37
  const walletConnector = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector;
35
38
  const { chain } = useFetchChain.useFetchChain(walletConnector);
36
39
  const { setDynamicWidgetView } = DynamicWidgetContext.useWidgetContext();
37
40
  const [midnightAddressType, setMidnightAddressType] = React.useState('unshielded');
38
- const { data: ens } = usePromise.usePromise(() => getNameService(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address), { deps: [primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address], initialData: undefined });
41
+ const { data: ens } = usePromise.usePromise(() => getNameService(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address), { deps: [primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address, network], initialData: undefined });
39
42
  const ensName = (_a = ens === null || ens === void 0 ? void 0 : ens.name) !== null && _a !== void 0 ? _a : null;
40
43
  if (!primaryWallet) {
41
44
  return null;
42
45
  }
43
- const shieldedAddress = walletConnectorCore.isMidnightWallet(primaryWallet)
44
- ? getWalletAdditionalAddressByType.getWalletAdditionalAddressByType(sdkApiCore.WalletAddressType.MidnightShielded, primaryWallet)
46
+ // Midnight is one wallet exposing a per-network address for each type. The
47
+ // connector resolves the selected network so the deposit QR/address matches
48
+ // the chosen network — depositing to the wrong network's encoding would
49
+ // strand funds. `network` from context drives re-render on switch.
50
+ const isMidnight = walletConnectorCore.isMidnightWallet(primaryWallet);
51
+ const midnightNetworkTag = walletConnectorCore.getMidnightNetworkTag(primaryWallet.connector);
52
+ const shieldedAddress = isMidnight
53
+ ? getWalletAdditionalAddressByType.getWalletAdditionalAddressByType(sdkApiCore.WalletAddressType.MidnightShielded, primaryWallet, midnightNetworkTag)
45
54
  : undefined;
55
+ const unshieldedAddress = isMidnight
56
+ ? (_b = getWalletAdditionalAddressByType.getWalletAdditionalAddressByType(sdkApiCore.WalletAddressType.MidnightUnshielded, primaryWallet, midnightNetworkTag)) !== null && _b !== void 0 ? _b : primaryWallet.address
57
+ : primaryWallet.address;
46
58
  const showMidnightToggle = Boolean(shieldedAddress);
59
+ // Per-network address: the deposit QR/address must match the selected
60
+ // network — depositing to the wrong network's encoding would strand funds.
61
+ const bitcoinActiveAddress = getEmbeddedBitcoinActiveAddress.getEmbeddedBitcoinActiveAddress(primaryWallet.connector);
47
62
  const depositAddress = showMidnightToggle && midnightAddressType === 'shielded' && shieldedAddress
48
63
  ? shieldedAddress
49
- : primaryWallet.address;
64
+ : bitcoinActiveAddress !== null && bitcoinActiveAddress !== void 0 ? bitcoinActiveAddress : unshieldedAddress;
50
65
  const backButton = (jsxRuntime.jsx(IconButton.IconButton, { type: 'button', id: 'back-button', "data-testid": 'back-button', onClick: () => setDynamicWidgetView('choose-wallet-funding-method'), children: jsxRuntime.jsx(arrowLeft.ReactComponent, {}) }));
51
66
  return (jsxRuntime.jsxs("div", { className: 'deposit-view', children: [jsxRuntime.jsx(ModalHeader.ModalHeader, { leading: backButton, children: jsxRuntime.jsx(Typography.Typography, { variant: 'title', copykey: 'dyn_deposit.title', children: t('dyn_deposit.title') }) }), jsxRuntime.jsxs("div", { className: 'deposit-view__content', children: [showMidnightToggle && (jsxRuntime.jsxs("div", { className: 'deposit-view__content__toggle', children: [jsxRuntime.jsx("button", { type: 'button', "data-testid": 'deposit-toggle-unshielded', className: classNames.classNames('deposit-view__content__toggle__option', {
52
67
  'deposit-view__content__toggle__option--active': midnightAddressType === 'unshielded',
@@ -3,7 +3,7 @@ import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import { useState } from 'react';
4
4
  import { useTranslation } from 'react-i18next';
5
5
  import { WalletAddressType } from '@dynamic-labs/sdk-api-core';
6
- import { isMidnightWallet } from '@dynamic-labs/wallet-connector-core';
6
+ import { isMidnightWallet, getMidnightNetworkTag } from '@dynamic-labs/wallet-connector-core';
7
7
  import { CopyButton } from '../../../../components/CopyButton/CopyButton.js';
8
8
  import { IconButton } from '../../../../components/IconButton/IconButton.js';
9
9
  import { ModalHeader } from '../../../../components/ModalHeader/ModalHeader.js';
@@ -18,31 +18,46 @@ import '@dynamic-labs/iconic';
18
18
  import '../../../../context/ViewContext/ViewContext.js';
19
19
  import { shortenWalletAddress } from '../../../../shared/utils/functions/shortenWalletAddress/shortenWalletAddress.js';
20
20
  import { classNames } from '../../../../utils/functions/classNames/classNames.js';
21
+ import { getEmbeddedBitcoinActiveAddress } from '../../../../utils/functions/getEmbeddedBitcoinActiveAddress/getEmbeddedBitcoinActiveAddress.js';
21
22
  import { getWalletAdditionalAddressByType } from '../../../../utils/functions/getWalletAdditionalAddressByType/getWalletAdditionalAddressByType.js';
22
23
  import { usePromise } from '../../../../utils/hooks/usePromise/usePromise.js';
23
24
  import { useWidgetContext } from '../../context/DynamicWidgetContext.js';
24
25
  import { useFetchChain } from '../../hooks/useFetchChain/useFetchChain.js';
25
26
 
26
27
  const DepositView = () => {
27
- var _a;
28
+ var _a, _b;
28
29
  const { t } = useTranslation();
29
- const { primaryWallet, getNameService } = useInternalDynamicContext();
30
+ // Per-network address: embedded Bitcoin swaps its active address on network
31
+ // switch (context `network` changes re-render this view).
32
+ const { primaryWallet, getNameService, network } = useInternalDynamicContext();
30
33
  const walletConnector = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector;
31
34
  const { chain } = useFetchChain(walletConnector);
32
35
  const { setDynamicWidgetView } = useWidgetContext();
33
36
  const [midnightAddressType, setMidnightAddressType] = useState('unshielded');
34
- const { data: ens } = usePromise(() => getNameService(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address), { deps: [primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address], initialData: undefined });
37
+ const { data: ens } = usePromise(() => getNameService(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address), { deps: [primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address, network], initialData: undefined });
35
38
  const ensName = (_a = ens === null || ens === void 0 ? void 0 : ens.name) !== null && _a !== void 0 ? _a : null;
36
39
  if (!primaryWallet) {
37
40
  return null;
38
41
  }
39
- const shieldedAddress = isMidnightWallet(primaryWallet)
40
- ? getWalletAdditionalAddressByType(WalletAddressType.MidnightShielded, primaryWallet)
42
+ // Midnight is one wallet exposing a per-network address for each type. The
43
+ // connector resolves the selected network so the deposit QR/address matches
44
+ // the chosen network — depositing to the wrong network's encoding would
45
+ // strand funds. `network` from context drives re-render on switch.
46
+ const isMidnight = isMidnightWallet(primaryWallet);
47
+ const midnightNetworkTag = getMidnightNetworkTag(primaryWallet.connector);
48
+ const shieldedAddress = isMidnight
49
+ ? getWalletAdditionalAddressByType(WalletAddressType.MidnightShielded, primaryWallet, midnightNetworkTag)
41
50
  : undefined;
51
+ const unshieldedAddress = isMidnight
52
+ ? (_b = getWalletAdditionalAddressByType(WalletAddressType.MidnightUnshielded, primaryWallet, midnightNetworkTag)) !== null && _b !== void 0 ? _b : primaryWallet.address
53
+ : primaryWallet.address;
42
54
  const showMidnightToggle = Boolean(shieldedAddress);
55
+ // Per-network address: the deposit QR/address must match the selected
56
+ // network — depositing to the wrong network's encoding would strand funds.
57
+ const bitcoinActiveAddress = getEmbeddedBitcoinActiveAddress(primaryWallet.connector);
43
58
  const depositAddress = showMidnightToggle && midnightAddressType === 'shielded' && shieldedAddress
44
59
  ? shieldedAddress
45
- : primaryWallet.address;
60
+ : bitcoinActiveAddress !== null && bitcoinActiveAddress !== void 0 ? bitcoinActiveAddress : unshieldedAddress;
46
61
  const backButton = (jsx(IconButton, { type: 'button', id: 'back-button', "data-testid": 'back-button', onClick: () => setDynamicWidgetView('choose-wallet-funding-method'), children: jsx(SvgArrowLeft, {}) }));
47
62
  return (jsxs("div", { className: 'deposit-view', children: [jsx(ModalHeader, { leading: backButton, children: jsx(Typography, { variant: 'title', copykey: 'dyn_deposit.title', children: t('dyn_deposit.title') }) }), jsxs("div", { className: 'deposit-view__content', children: [showMidnightToggle && (jsxs("div", { className: 'deposit-view__content__toggle', children: [jsx("button", { type: 'button', "data-testid": 'deposit-toggle-unshielded', className: classNames('deposit-view__content__toggle__option', {
48
63
  'deposit-view__content__toggle__option--active': midnightAddressType === 'unshielded',