@dynamic-labs/sdk-react-core 0.17.0-RC.22 → 0.17.0-RC.23

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 (46) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +7 -7
  5. package/src/index.cjs +0 -2
  6. package/src/index.js +0 -1
  7. package/src/lib/components/Chip/Chip.cjs +13 -0
  8. package/src/lib/components/Chip/Chip.d.ts +7 -0
  9. package/src/lib/components/Chip/Chip.js +9 -0
  10. package/src/lib/components/Chip/index.d.ts +1 -0
  11. package/src/lib/components/SendBalancePageLayout/SendBalancePageLayout.cjs +3 -2
  12. package/src/lib/components/SendBalancePageLayout/SendBalancePageLayout.d.ts +3 -1
  13. package/src/lib/components/SendBalancePageLayout/SendBalancePageLayout.js +3 -2
  14. package/src/lib/components/index.d.ts +1 -0
  15. package/src/lib/context/DynamicContext/DynamicContext.cjs +4 -3
  16. package/src/lib/context/DynamicContext/DynamicContext.js +4 -3
  17. package/src/lib/shared/utils/hooks/index.d.ts +0 -1
  18. package/src/lib/styles/index.shadow.cjs +1 -1
  19. package/src/lib/styles/index.shadow.js +1 -1
  20. package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.cjs +4 -1
  21. package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.d.ts +3 -3
  22. package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.js +4 -1
  23. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.cjs +23 -67
  24. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.d.ts +2 -1
  25. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.js +24 -68
  26. package/src/lib/utils/hooks/useWalletConnectors/utils/createLinkedWalletsFromWalletOptions/createLinkedWalletsFromWalletOptions.cjs +55 -0
  27. package/src/lib/utils/hooks/useWalletConnectors/utils/createLinkedWalletsFromWalletOptions/createLinkedWalletsFromWalletOptions.d.ts +8 -0
  28. package/src/lib/utils/hooks/useWalletConnectors/utils/createLinkedWalletsFromWalletOptions/createLinkedWalletsFromWalletOptions.js +51 -0
  29. package/src/lib/utils/hooks/useWalletConnectors/utils/createLinkedWalletsFromWalletOptions/index.d.ts +1 -0
  30. package/src/lib/utils/hooks/useWalletConnectors/utils/index.d.ts +2 -0
  31. package/src/lib/utils/hooks/useWalletConnectors/utils/primaryWalletIdValidator/index.d.ts +1 -0
  32. package/src/lib/utils/hooks/useWalletConnectors/utils/primaryWalletIdValidator/primaryWalletIdValidator.cjs +7 -0
  33. package/src/lib/utils/hooks/useWalletConnectors/utils/primaryWalletIdValidator/primaryWalletIdValidator.d.ts +1 -0
  34. package/src/lib/utils/hooks/useWalletConnectors/utils/primaryWalletIdValidator/primaryWalletIdValidator.js +3 -0
  35. package/src/lib/utils/hooks/useWalletsConnectionState/index.d.ts +1 -0
  36. package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.cjs +42 -0
  37. package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.d.ts +11 -0
  38. package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.js +38 -0
  39. package/src/lib/views/SendBalanceView/SendBalanceView.cjs +10 -4
  40. package/src/lib/views/SendBalanceView/SendBalanceView.js +10 -4
  41. package/src/lib/widgets/DynamicWidget/components/Wallet/Wallet.cjs +4 -4
  42. package/src/lib/widgets/DynamicWidget/components/Wallet/Wallet.js +4 -4
  43. package/src/lib/shared/utils/hooks/useIsMounted/index.d.ts +0 -1
  44. package/src/lib/shared/utils/hooks/useIsMounted/useIsMounted.cjs +0 -18
  45. package/src/lib/shared/utils/hooks/useIsMounted/useIsMounted.d.ts +0 -1
  46. package/src/lib/shared/utils/hooks/useIsMounted/useIsMounted.js +0 -14
@@ -1,8 +1,8 @@
1
1
  import { __awaiter } from '../../../../../_virtual/_tslib.js';
2
- import { useState, useCallback, useEffect } from 'react';
2
+ import { useState, useMemo, useEffect, useCallback } from 'react';
3
3
  import { isEmailWalletConnector, isSocialWalletConnector } from '@dynamic-labs/wallet-connector-core';
4
4
  import { DynamicError } from '@dynamic-labs/utils';
5
- import { decodeJwt } from '../../../shared/utils/functions/decodeJwt/decodeJwt.js';
5
+ import '@dynamic-labs/sdk-api';
6
6
  import { logger } from '../../../shared/logger.js';
7
7
  import '@dynamic-labs/iconic';
8
8
  import 'react/jsx-runtime';
@@ -12,80 +12,35 @@ import '../../constants/colors.js';
12
12
  import 'ethers';
13
13
  import { useLocalStorage } from '../../../shared/utils/hooks/useLocalStorage/useLocalStorage.js';
14
14
  import '../../../shared/consts/index.js';
15
- import { isWalletConnected } from '../../functions/isWalletConnected/isWalletConnected.js';
16
15
  import { isSameWalletName } from '../../functions/isSameWalletName/isSameWalletName.js';
17
- import '@dynamic-labs/multi-wallet';
18
- import '@dynamic-labs/sdk-api';
19
- import { shouldManuallyReconnectOnRefresh } from '../../functions/shouldManuallyReconnectOnRefresh/shouldManuallyReconnectOnRefresh.js';
16
+ import { useWalletsConnectionState } from '../useWalletsConnectionState/useWalletsConnectionState.js';
17
+ import { primaryWalletIdValidator } from './utils/primaryWalletIdValidator/primaryWalletIdValidator.js';
18
+ import { createLinkedWalletsFromWalletOptions } from './utils/createLinkedWalletsFromWalletOptions/createLinkedWalletsFromWalletOptions.js';
20
19
  import { reconnectSocialWallet } from './reconnectSocialWallet.js';
21
20
 
22
21
  const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWalletWidgetState, setDesktopUri, setMultiWalletWidgetState, setQrcodeUri, }) => {
23
22
  const [showQrcodeModal, setShowQrcodeModal] = useState(false);
24
- const [wallets, setWallets] = useState([]);
25
- const [primaryWalletId, setPrimaryWalletIdState, clearPrimaryWalletId] = useLocalStorage(PRIMARY_WALLET_ID, undefined, (value) => typeof value === 'string' || typeof value === 'undefined');
23
+ const [primaryWalletId, setPrimaryWalletIdState, clearPrimaryWalletId] = useLocalStorage(PRIMARY_WALLET_ID, undefined, primaryWalletIdValidator);
24
+ const linkedWallets = useMemo(() => {
25
+ if (!authToken) {
26
+ return [];
27
+ }
28
+ return createLinkedWalletsFromWalletOptions({
29
+ authToken,
30
+ primaryWalletId,
31
+ walletOptions: availableWallets,
32
+ });
33
+ }, [availableWallets, primaryWalletId, authToken]);
34
+ const { connectedWalletMap, computeConnectedStateForWallets, didConnectedStateLoad, } = useWalletsConnectionState(linkedWallets);
35
+ const wallets = useMemo(() => linkedWallets.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletMap[wallet.id]) }))), [connectedWalletMap, linkedWallets]);
36
+ useEffect(() => {
37
+ computeConnectedStateForWallets();
38
+ }, [primaryWalletId, computeConnectedStateForWallets]);
26
39
  const setPrimaryWalletId = useCallback((walletId) => {
27
40
  setPrimaryWalletIdState(walletId);
28
41
  }, [setPrimaryWalletIdState]);
29
- const clearWalletStates = useCallback(() => {
30
- setWallets([]);
31
- clearPrimaryWalletId();
32
- }, [clearPrimaryWalletId]);
33
- const getPrimaryWallet = useCallback(() => {
34
- const primaryWallet = wallets.find((wallet) => wallet.id === primaryWalletId);
35
- if (!primaryWallet) {
36
- return null;
37
- }
38
- return primaryWallet;
39
- }, [primaryWalletId, wallets]);
42
+ const getPrimaryWallet = useCallback(() => { var _a; return (_a = wallets.find((wallet) => wallet.id === primaryWalletId)) !== null && _a !== void 0 ? _a : null; }, [primaryWalletId, wallets]);
40
43
  const getSecondaryWallets = useCallback(() => wallets.filter((wallet) => wallet.id !== primaryWalletId), [primaryWalletId, wallets]);
41
- useEffect(() => {
42
- const decodedJwt = decodeJwt(authToken);
43
- // wallet state should be null while loading all the wallets or when there is no user
44
- if (!availableWallets || !decodedJwt) {
45
- setWallets([]);
46
- return;
47
- }
48
- Promise.all(decodedJwt.verifiedCredentials.map((account) => __awaiter(void 0, void 0, void 0, function* () {
49
- const wallet = availableWallets.find((wallet) => account.walletName &&
50
- isSameWalletName(wallet.name, account.walletName));
51
- // this probably shouldn't happen. this would mean that the user has an account linked
52
- // with wallet W, but the customer has toggled off wallet W or the chain that
53
- // supports wallet W
54
- /* istanbul ignore next */
55
- if (!wallet)
56
- return null;
57
- if (account.id === primaryWalletId &&
58
- shouldManuallyReconnectOnRefresh(wallet.walletConnector)) {
59
- yield wallet.walletConnector.connect();
60
- }
61
- if (account.address && account.chain) {
62
- return {
63
- address: account.address,
64
- chain: account.chain,
65
- connected: yield isWalletConnected({
66
- address: account.address,
67
- chain: account.chain,
68
- connector: wallet.walletConnector,
69
- }),
70
- connector: wallet.walletConnector,
71
- id: account.id,
72
- };
73
- }
74
- return null;
75
- }))).then((result) => {
76
- setWallets(result.filter((wc) => wc !== null));
77
- return null;
78
- });
79
- }, [availableWallets, primaryWalletId, authToken]);
80
- const computeConnectedStateForWallets = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
81
- if (!primaryWalletId)
82
- return;
83
- const connectionMap = {};
84
- for (const wallet of wallets) {
85
- connectionMap[wallet.id] = yield isWalletConnected(wallet);
86
- }
87
- setWallets((currentWallets) => currentWallets.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: connectionMap[wallet.id] }))));
88
- }), [primaryWalletId, wallets]);
89
44
  const getSelectedWallet = useCallback((walletId) => __awaiter(void 0, void 0, void 0, function* () {
90
45
  const newWallet = wallets.find(({ id }) => id === walletId);
91
46
  if (!newWallet) {
@@ -181,8 +136,9 @@ const useWalletConnectors = ({ authToken, wallets: availableWallets, multiWallet
181
136
  ]);
182
137
  const walletConnectors = wallets.map((wallet) => wallet.connector);
183
138
  return {
184
- clearWalletStates,
139
+ clearPrimaryWalletId,
185
140
  computeConnectedStateForWallets,
141
+ didConnectedStateLoad,
186
142
  getPrimaryWallet,
187
143
  getSecondaryWallets,
188
144
  primaryWallet: getPrimaryWallet(),
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var decodeJwt = require('../../../../../shared/utils/functions/decodeJwt/decodeJwt.cjs');
6
+ require('../../../../../shared/logger.cjs');
7
+ require('@dynamic-labs/iconic');
8
+ require('@dynamic-labs/wallet-connector-core');
9
+ require('react/jsx-runtime');
10
+ require('../../../../../context/ViewContext/ViewContext.cjs');
11
+ require('react');
12
+ require('@dynamic-labs/utils');
13
+ require('../../../../constants/colors.cjs');
14
+ require('ethers');
15
+ require('../../../../../shared/consts/index.cjs');
16
+ var isSameWalletName = require('../../../../functions/isSameWalletName/isSameWalletName.cjs');
17
+ require('@dynamic-labs/multi-wallet');
18
+ require('@dynamic-labs/sdk-api');
19
+ var shouldManuallyReconnectOnRefresh = require('../../../../functions/shouldManuallyReconnectOnRefresh/shouldManuallyReconnectOnRefresh.cjs');
20
+
21
+ const createLinkedWalletsFromWalletOptions = ({ authToken, walletOptions, primaryWalletId, }) => {
22
+ const decodedJwt = decodeJwt.decodeJwt(authToken);
23
+ // wallet state should be null while loading all the wallets or when there is no user
24
+ if (!walletOptions || !decodedJwt) {
25
+ return [];
26
+ }
27
+ return decodedJwt.verifiedCredentials
28
+ .map((account) => {
29
+ const wallet = walletOptions.find((wallet) => account.walletName &&
30
+ isSameWalletName.isSameWalletName(wallet.name, account.walletName));
31
+ // this probably shouldn't happen. this would mean that the user has an account linked
32
+ // with wallet W, but the customer has toggled off wallet W or the chain that
33
+ // supports wallet W
34
+ /* istanbul ignore next */
35
+ if (!wallet)
36
+ return null;
37
+ if (account.id === primaryWalletId &&
38
+ shouldManuallyReconnectOnRefresh.shouldManuallyReconnectOnRefresh(wallet.walletConnector)) {
39
+ wallet.walletConnector.connect();
40
+ }
41
+ if (account.address && account.chain) {
42
+ return {
43
+ address: account.address,
44
+ chain: account.chain,
45
+ connected: false,
46
+ connector: wallet.walletConnector,
47
+ id: account.id,
48
+ };
49
+ }
50
+ return null;
51
+ })
52
+ .filter((wc) => wc !== null);
53
+ };
54
+
55
+ exports.createLinkedWalletsFromWalletOptions = createLinkedWalletsFromWalletOptions;
@@ -0,0 +1,8 @@
1
+ import { Wallet, WalletOption } from '../../../../../shared';
2
+ type CreateWalletsFromWalletOptionsProps = {
3
+ authToken: string;
4
+ primaryWalletId: string | undefined;
5
+ walletOptions: WalletOption[] | undefined;
6
+ };
7
+ export declare const createLinkedWalletsFromWalletOptions: ({ authToken, walletOptions, primaryWalletId, }: CreateWalletsFromWalletOptionsProps) => Wallet[];
8
+ export {};
@@ -0,0 +1,51 @@
1
+ import { decodeJwt } from '../../../../../shared/utils/functions/decodeJwt/decodeJwt.js';
2
+ import '../../../../../shared/logger.js';
3
+ import '@dynamic-labs/iconic';
4
+ import '@dynamic-labs/wallet-connector-core';
5
+ import 'react/jsx-runtime';
6
+ import '../../../../../context/ViewContext/ViewContext.js';
7
+ import 'react';
8
+ import '@dynamic-labs/utils';
9
+ import '../../../../constants/colors.js';
10
+ import 'ethers';
11
+ import '../../../../../shared/consts/index.js';
12
+ import { isSameWalletName } from '../../../../functions/isSameWalletName/isSameWalletName.js';
13
+ import '@dynamic-labs/multi-wallet';
14
+ import '@dynamic-labs/sdk-api';
15
+ import { shouldManuallyReconnectOnRefresh } from '../../../../functions/shouldManuallyReconnectOnRefresh/shouldManuallyReconnectOnRefresh.js';
16
+
17
+ const createLinkedWalletsFromWalletOptions = ({ authToken, walletOptions, primaryWalletId, }) => {
18
+ const decodedJwt = decodeJwt(authToken);
19
+ // wallet state should be null while loading all the wallets or when there is no user
20
+ if (!walletOptions || !decodedJwt) {
21
+ return [];
22
+ }
23
+ return decodedJwt.verifiedCredentials
24
+ .map((account) => {
25
+ const wallet = walletOptions.find((wallet) => account.walletName &&
26
+ isSameWalletName(wallet.name, account.walletName));
27
+ // this probably shouldn't happen. this would mean that the user has an account linked
28
+ // with wallet W, but the customer has toggled off wallet W or the chain that
29
+ // supports wallet W
30
+ /* istanbul ignore next */
31
+ if (!wallet)
32
+ return null;
33
+ if (account.id === primaryWalletId &&
34
+ shouldManuallyReconnectOnRefresh(wallet.walletConnector)) {
35
+ wallet.walletConnector.connect();
36
+ }
37
+ if (account.address && account.chain) {
38
+ return {
39
+ address: account.address,
40
+ chain: account.chain,
41
+ connected: false,
42
+ connector: wallet.walletConnector,
43
+ id: account.id,
44
+ };
45
+ }
46
+ return null;
47
+ })
48
+ .filter((wc) => wc !== null);
49
+ };
50
+
51
+ export { createLinkedWalletsFromWalletOptions };
@@ -0,0 +1 @@
1
+ export { createLinkedWalletsFromWalletOptions } from './createLinkedWalletsFromWalletOptions';
@@ -0,0 +1,2 @@
1
+ export * from './primaryWalletIdValidator';
2
+ export * from './createLinkedWalletsFromWalletOptions';
@@ -0,0 +1 @@
1
+ export { primaryWalletIdValidator } from './primaryWalletIdValidator';
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const primaryWalletIdValidator = (value) => typeof value === 'string' || typeof value === 'undefined';
6
+
7
+ exports.primaryWalletIdValidator = primaryWalletIdValidator;
@@ -0,0 +1 @@
1
+ export declare const primaryWalletIdValidator: (value: string | unknown) => value is string | undefined;
@@ -0,0 +1,3 @@
1
+ const primaryWalletIdValidator = (value) => typeof value === 'string' || typeof value === 'undefined';
2
+
3
+ export { primaryWalletIdValidator };
@@ -0,0 +1 @@
1
+ export { useWalletsConnectionState } from './useWalletsConnectionState';
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../../../../_virtual/_tslib.cjs');
6
+ var React = require('react');
7
+ require('../../constants/colors.cjs');
8
+ require('@dynamic-labs/multi-wallet');
9
+ require('@dynamic-labs/utils');
10
+ require('@dynamic-labs/sdk-api');
11
+ require('../../../shared/logger.cjs');
12
+ require('@dynamic-labs/iconic');
13
+ require('@dynamic-labs/wallet-connector-core');
14
+ require('react/jsx-runtime');
15
+ require('../../../context/ViewContext/ViewContext.cjs');
16
+ require('ethers');
17
+ var isWalletConnected = require('../../functions/isWalletConnected/isWalletConnected.cjs');
18
+ require('../../../shared/consts/index.cjs');
19
+
20
+ const useWalletsConnectionState = (linkedWallets) => {
21
+ const [connectedWalletMap, setConnectedWalletMap] = React.useState();
22
+ const computeConnectedStateForWallets = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
23
+ const connectedWalletIds = (yield Promise.all(linkedWallets.map((wallet) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
24
+ const isConnected = yield isWalletConnected.isWalletConnected(wallet);
25
+ if (isConnected) {
26
+ return wallet.id;
27
+ }
28
+ else {
29
+ return undefined;
30
+ }
31
+ })))).filter((connectedWalletId) => connectedWalletId !== undefined);
32
+ const newConnectedStateByWalletIdMap = connectedWalletIds.reduce((result, walletId) => (Object.assign(Object.assign({}, result), { [walletId]: true })), {});
33
+ setConnectedWalletMap(newConnectedStateByWalletIdMap);
34
+ }), [linkedWallets, setConnectedWalletMap]);
35
+ return {
36
+ computeConnectedStateForWallets,
37
+ connectedWalletMap: connectedWalletMap !== null && connectedWalletMap !== void 0 ? connectedWalletMap : {},
38
+ didConnectedStateLoad: Boolean(connectedWalletMap),
39
+ };
40
+ };
41
+
42
+ exports.useWalletsConnectionState = useWalletsConnectionState;
@@ -0,0 +1,11 @@
1
+ import { Wallet } from '../../../shared';
2
+ type ConnectedWalletsMap = {
3
+ [address: string]: boolean;
4
+ };
5
+ type WalletsConnectionStateHook = (wallets: Wallet[]) => {
6
+ computeConnectedStateForWallets: () => Promise<void>;
7
+ connectedWalletMap: ConnectedWalletsMap;
8
+ didConnectedStateLoad: boolean;
9
+ };
10
+ export declare const useWalletsConnectionState: WalletsConnectionStateHook;
11
+ export {};
@@ -0,0 +1,38 @@
1
+ import { __awaiter } from '../../../../../_virtual/_tslib.js';
2
+ import { useState, useCallback } from 'react';
3
+ import '../../constants/colors.js';
4
+ import '@dynamic-labs/multi-wallet';
5
+ import '@dynamic-labs/utils';
6
+ import '@dynamic-labs/sdk-api';
7
+ import '../../../shared/logger.js';
8
+ import '@dynamic-labs/iconic';
9
+ import '@dynamic-labs/wallet-connector-core';
10
+ import 'react/jsx-runtime';
11
+ import '../../../context/ViewContext/ViewContext.js';
12
+ import 'ethers';
13
+ import { isWalletConnected } from '../../functions/isWalletConnected/isWalletConnected.js';
14
+ import '../../../shared/consts/index.js';
15
+
16
+ const useWalletsConnectionState = (linkedWallets) => {
17
+ const [connectedWalletMap, setConnectedWalletMap] = useState();
18
+ const computeConnectedStateForWallets = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
19
+ const connectedWalletIds = (yield Promise.all(linkedWallets.map((wallet) => __awaiter(void 0, void 0, void 0, function* () {
20
+ const isConnected = yield isWalletConnected(wallet);
21
+ if (isConnected) {
22
+ return wallet.id;
23
+ }
24
+ else {
25
+ return undefined;
26
+ }
27
+ })))).filter((connectedWalletId) => connectedWalletId !== undefined);
28
+ const newConnectedStateByWalletIdMap = connectedWalletIds.reduce((result, walletId) => (Object.assign(Object.assign({}, result), { [walletId]: true })), {});
29
+ setConnectedWalletMap(newConnectedStateByWalletIdMap);
30
+ }), [linkedWallets, setConnectedWalletMap]);
31
+ return {
32
+ computeConnectedStateForWallets,
33
+ connectedWalletMap: connectedWalletMap !== null && connectedWalletMap !== void 0 ? connectedWalletMap : {},
34
+ didConnectedStateLoad: Boolean(connectedWalletMap),
35
+ };
36
+ };
37
+
38
+ export { useWalletsConnectionState };
@@ -39,15 +39,15 @@ require('../../components/Popper/PopperContext/PopperContext.cjs');
39
39
  var SendBalancePageLayout = require('../../components/SendBalancePageLayout/SendBalancePageLayout.cjs');
40
40
  var TransactionConfirmationView = require('../TransactionConfirmationView/TransactionConfirmationView.cjs');
41
41
  var TransactionStatusLayout = require('../../components/TransactionStatusLayout/TransactionStatusLayout.cjs');
42
+ var useFetchCurrency = require('../../widgets/DynamicWidget/hooks/useFetchCurrency/useFetchCurrency.cjs');
42
43
  require('../../context/MockContext/MockContext.cjs');
43
44
  require('../../context/CaptchaContext/CaptchaContext.cjs');
44
45
  var usePromise = require('../../utils/hooks/usePromise/usePromise.cjs');
45
46
  require('../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.cjs');
46
47
 
47
48
  const SendBalanceView = ({ initialRecipientAddress = '', initialValue, onClickBack, onClickClose, onError, onSuccess, onDone, displayPoweredByDynamicFooter = false, }) => {
48
- var _a;
49
49
  const [stage, setStage] = React.useState('form');
50
- const { primaryWallet, walletUiUtils } = useInternalDynamicContext.useInternalDynamicContext();
50
+ const { primaryWallet, walletUiUtils, network } = useInternalDynamicContext.useInternalDynamicContext();
51
51
  const [value, setValue] = React.useState(initialValue !== null && initialValue !== void 0 ? initialValue : null);
52
52
  const [recipientAddress, setRecipientAddress] = React.useState(initialRecipientAddress);
53
53
  const transactionRef = React.useRef(null);
@@ -56,14 +56,20 @@ const SendBalanceView = ({ initialRecipientAddress = '', initialValue, onClickBa
56
56
  }
57
57
  const { data: balance } = usePromise.usePromise(() => primaryWallet.connector.getBalance(), [primaryWallet]);
58
58
  const { data: provider } = usePromise.usePromise(() => primaryWallet.connector.getWeb3Provider(), [primaryWallet]);
59
+ const evmNetworks = ((primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector) &&
60
+ primaryWallet.connector.evmNetworks) ||
61
+ [];
62
+ const evmNetwork = evmNetworks.find((evmNetwork) => evmNetwork.chainId === network);
63
+ const networkIcon = evmNetwork && (jsxRuntime.jsx("img", { src: evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.iconUrls[0], alt: `${evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.name} icon` }));
64
+ const networkName = (evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.vanityName) || (evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.name);
59
65
  const ChainIconComponent = getChainIcon.getChainIcon(primaryWallet.chain);
60
66
  const chainInfo = walletConnectorCore.getChainInfo(primaryWallet.chain);
61
67
  const chainIcon = (jsxRuntime.jsx(Icon.Icon, Object.assign({ size: 'small' }, { children: jsxRuntime.jsx(ChainIconComponent, {}) })));
62
- const currencySymbol = (_a = chainInfo === null || chainInfo === void 0 ? void 0 : chainInfo.symbol) !== null && _a !== void 0 ? _a : '';
68
+ const [currencySymbol = ''] = useFetchCurrency.useFetchCurrency(primaryWallet.connector);
63
69
  const buildFormStage = () => (jsxRuntime.jsx(SendBalancePageLayout.SendBalancePageLayout, { initialValues: {
64
70
  amount: value === null ? '' : formatBigNumber.formatBigNumber(value),
65
71
  recipient: recipientAddress,
66
- }, balance: balance, onClickBack: onClickBack, chain: primaryWallet.chain, currencySymbol: currencySymbol, isLoading: false, walletAddress: shortenWalletAddress.shortenWalletAddress(primaryWallet.address, 3, 3), walletName: primaryWallet.connector.name, onClickClose: onClickClose, displayPoweredByDynamicFooter: displayPoweredByDynamicFooter, onSubmit: (data) => {
72
+ }, balance: balance, onClickBack: onClickBack, chain: primaryWallet.chain, networkName: networkName, networkIcon: networkIcon, currencySymbol: currencySymbol, isLoading: false, walletAddress: shortenWalletAddress.shortenWalletAddress(primaryWallet.address, 3, 3), walletName: primaryWallet.connector.name, onClickClose: onClickClose, displayPoweredByDynamicFooter: displayPoweredByDynamicFooter, onSubmit: (data) => {
67
73
  setValue(ethers.utils.parseEther(data.amount));
68
74
  setRecipientAddress(data.recipient);
69
75
  setStage('confirmation');
@@ -35,15 +35,15 @@ import '../../components/Popper/PopperContext/PopperContext.js';
35
35
  import { SendBalancePageLayout } from '../../components/SendBalancePageLayout/SendBalancePageLayout.js';
36
36
  import { TransactionConfirmationView } from '../TransactionConfirmationView/TransactionConfirmationView.js';
37
37
  import { TransactionStatusLayout } from '../../components/TransactionStatusLayout/TransactionStatusLayout.js';
38
+ import { useFetchCurrency } from '../../widgets/DynamicWidget/hooks/useFetchCurrency/useFetchCurrency.js';
38
39
  import '../../context/MockContext/MockContext.js';
39
40
  import '../../context/CaptchaContext/CaptchaContext.js';
40
41
  import { usePromise } from '../../utils/hooks/usePromise/usePromise.js';
41
42
  import '../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.js';
42
43
 
43
44
  const SendBalanceView = ({ initialRecipientAddress = '', initialValue, onClickBack, onClickClose, onError, onSuccess, onDone, displayPoweredByDynamicFooter = false, }) => {
44
- var _a;
45
45
  const [stage, setStage] = useState('form');
46
- const { primaryWallet, walletUiUtils } = useInternalDynamicContext();
46
+ const { primaryWallet, walletUiUtils, network } = useInternalDynamicContext();
47
47
  const [value, setValue] = useState(initialValue !== null && initialValue !== void 0 ? initialValue : null);
48
48
  const [recipientAddress, setRecipientAddress] = useState(initialRecipientAddress);
49
49
  const transactionRef = useRef(null);
@@ -52,14 +52,20 @@ const SendBalanceView = ({ initialRecipientAddress = '', initialValue, onClickBa
52
52
  }
53
53
  const { data: balance } = usePromise(() => primaryWallet.connector.getBalance(), [primaryWallet]);
54
54
  const { data: provider } = usePromise(() => primaryWallet.connector.getWeb3Provider(), [primaryWallet]);
55
+ const evmNetworks = ((primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector) &&
56
+ primaryWallet.connector.evmNetworks) ||
57
+ [];
58
+ const evmNetwork = evmNetworks.find((evmNetwork) => evmNetwork.chainId === network);
59
+ const networkIcon = evmNetwork && (jsx("img", { src: evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.iconUrls[0], alt: `${evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.name} icon` }));
60
+ const networkName = (evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.vanityName) || (evmNetwork === null || evmNetwork === void 0 ? void 0 : evmNetwork.name);
55
61
  const ChainIconComponent = getChainIcon(primaryWallet.chain);
56
62
  const chainInfo = getChainInfo(primaryWallet.chain);
57
63
  const chainIcon = (jsx(Icon, Object.assign({ size: 'small' }, { children: jsx(ChainIconComponent, {}) })));
58
- const currencySymbol = (_a = chainInfo === null || chainInfo === void 0 ? void 0 : chainInfo.symbol) !== null && _a !== void 0 ? _a : '';
64
+ const [currencySymbol = ''] = useFetchCurrency(primaryWallet.connector);
59
65
  const buildFormStage = () => (jsx(SendBalancePageLayout, { initialValues: {
60
66
  amount: value === null ? '' : formatBigNumber(value),
61
67
  recipient: recipientAddress,
62
- }, balance: balance, onClickBack: onClickBack, chain: primaryWallet.chain, currencySymbol: currencySymbol, isLoading: false, walletAddress: shortenWalletAddress(primaryWallet.address, 3, 3), walletName: primaryWallet.connector.name, onClickClose: onClickClose, displayPoweredByDynamicFooter: displayPoweredByDynamicFooter, onSubmit: (data) => {
68
+ }, balance: balance, onClickBack: onClickBack, chain: primaryWallet.chain, networkName: networkName, networkIcon: networkIcon, currencySymbol: currencySymbol, isLoading: false, walletAddress: shortenWalletAddress(primaryWallet.address, 3, 3), walletName: primaryWallet.connector.name, onClickClose: onClickClose, displayPoweredByDynamicFooter: displayPoweredByDynamicFooter, onSubmit: (data) => {
63
69
  setValue(utils.parseEther(data.amount));
64
70
  setRecipientAddress(data.recipient);
65
71
  setStage('confirmation');
@@ -47,7 +47,7 @@ var WalletOrSocialMagicIcon = require('../../../../components/WalletOrSocialMagi
47
47
 
48
48
  const Wallet = ({ wallet, ens }) => {
49
49
  const { id: walletId, connector, address } = wallet;
50
- const { computeConnectedStateForWallets, setPrimaryWallet, setSelectedWalletConnector, setShowWidgetStatePopup, setSelectedWalletWithAction, authToken, } = useInternalDynamicContext.useInternalDynamicContext();
50
+ const { computeConnectedStateForWallets, setPrimaryWallet, setSelectedWalletConnector, setShowWidgetStatePopup, setSelectedWalletWithAction, authToken, primaryWallet, } = useInternalDynamicContext.useInternalDynamicContext();
51
51
  const iconSize = 20;
52
52
  const options = [
53
53
  {
@@ -76,9 +76,9 @@ const Wallet = ({ wallet, ens }) => {
76
76
  });
77
77
  }
78
78
  const onSelectWalletClick = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
79
- var _a;
80
- if (connector.connectedChain === 'FLOW') {
81
- (_a = connector.endSession) === null || _a === void 0 ? void 0 : _a.call(connector);
79
+ if ((primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain) === 'flow' &&
80
+ connector.connectedChain === 'FLOW') {
81
+ yield connector.endSession();
82
82
  }
83
83
  setShowWidgetStatePopup(true);
84
84
  setSelectedWalletWithAction({ action: 'select', wallet });
@@ -43,7 +43,7 @@ import { WalletOrSocialMagicIcon } from '../../../../components/WalletOrSocialMa
43
43
 
44
44
  const Wallet = ({ wallet, ens }) => {
45
45
  const { id: walletId, connector, address } = wallet;
46
- const { computeConnectedStateForWallets, setPrimaryWallet, setSelectedWalletConnector, setShowWidgetStatePopup, setSelectedWalletWithAction, authToken, } = useInternalDynamicContext();
46
+ const { computeConnectedStateForWallets, setPrimaryWallet, setSelectedWalletConnector, setShowWidgetStatePopup, setSelectedWalletWithAction, authToken, primaryWallet, } = useInternalDynamicContext();
47
47
  const iconSize = 20;
48
48
  const options = [
49
49
  {
@@ -72,9 +72,9 @@ const Wallet = ({ wallet, ens }) => {
72
72
  });
73
73
  }
74
74
  const onSelectWalletClick = () => __awaiter(void 0, void 0, void 0, function* () {
75
- var _a;
76
- if (connector.connectedChain === 'FLOW') {
77
- (_a = connector.endSession) === null || _a === void 0 ? void 0 : _a.call(connector);
75
+ if ((primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain) === 'flow' &&
76
+ connector.connectedChain === 'FLOW') {
77
+ yield connector.endSession();
78
78
  }
79
79
  setShowWidgetStatePopup(true);
80
80
  setSelectedWalletWithAction({ action: 'select', wallet });
@@ -1 +0,0 @@
1
- export { useIsMounted } from './useIsMounted';
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var React = require('react');
6
-
7
- const useIsMounted = () => {
8
- const isMounted = React.useRef(false);
9
- React.useEffect(() => {
10
- isMounted.current = true;
11
- return () => {
12
- isMounted.current = false;
13
- };
14
- }, []);
15
- return React.useCallback(() => isMounted.current, []);
16
- };
17
-
18
- exports.useIsMounted = useIsMounted;
@@ -1 +0,0 @@
1
- export declare const useIsMounted: () => () => boolean;
@@ -1,14 +0,0 @@
1
- import { useRef, useEffect, useCallback } from 'react';
2
-
3
- const useIsMounted = () => {
4
- const isMounted = useRef(false);
5
- useEffect(() => {
6
- isMounted.current = true;
7
- return () => {
8
- isMounted.current = false;
9
- };
10
- }, []);
11
- return useCallback(() => isMounted.current, []);
12
- };
13
-
14
- export { useIsMounted };