@rango-dev/widget-embedded 0.41.2-next.1 → 0.41.2-next.3

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 (53) hide show
  1. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  2. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  3. package/dist/components/ConfirmWalletsModal/WalletList.type.d.ts +1 -0
  4. package/dist/components/ConfirmWalletsModal/WalletList.type.d.ts.map +1 -1
  5. package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts +3 -0
  6. package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts.map +1 -1
  7. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
  8. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +3 -9
  9. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
  10. package/dist/components/WalletStatefulConnect/DerivationPath.d.ts.map +1 -1
  11. package/dist/components/WalletStatefulConnect/NamespaceListItem.d.ts +4 -0
  12. package/dist/components/WalletStatefulConnect/NamespaceListItem.d.ts.map +1 -0
  13. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
  14. package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts +647 -0
  15. package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts.map +1 -1
  16. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +21 -1
  17. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
  18. package/dist/components/WalletStatefulConnect/SupportedChainsList.d.ts +4 -0
  19. package/dist/components/WalletStatefulConnect/SupportedChainsList.d.ts.map +1 -0
  20. package/dist/components/WalletStatefulConnect/SupportedChainsList.styles.d.ts +323 -0
  21. package/dist/components/WalletStatefulConnect/SupportedChainsList.styles.d.ts.map +1 -0
  22. package/dist/components/WalletStatefulConnect/SupportedChainsList.types.d.ts +5 -0
  23. package/dist/components/WalletStatefulConnect/SupportedChainsList.types.d.ts.map +1 -0
  24. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
  25. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +2 -0
  26. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
  27. package/dist/index.js +2 -2
  28. package/dist/index.js.map +4 -4
  29. package/dist/utils/swap.d.ts.map +1 -1
  30. package/dist/utils/wallets.d.ts +1 -1
  31. package/dist/utils/wallets.d.ts.map +1 -1
  32. package/dist/widget-embedded.build.json +1 -1
  33. package/package.json +8 -8
  34. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +13 -11
  35. package/src/components/ConfirmWalletsModal/WalletList.tsx +3 -1
  36. package/src/components/ConfirmWalletsModal/WalletList.type.ts +1 -0
  37. package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +4 -0
  38. package/src/components/SwapDetails/SwapDetails.tsx +1 -1
  39. package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +17 -8
  40. package/src/components/SwapDetailsModal/SwapDetailsModal.tsx +2 -2
  41. package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +3 -8
  42. package/src/components/WalletStatefulConnect/DerivationPath.tsx +1 -13
  43. package/src/components/WalletStatefulConnect/NamespaceListItem.tsx +64 -0
  44. package/src/components/WalletStatefulConnect/Namespaces.styles.ts +55 -3
  45. package/src/components/WalletStatefulConnect/Namespaces.tsx +97 -50
  46. package/src/components/WalletStatefulConnect/Namespaces.types.tsx +29 -1
  47. package/src/components/WalletStatefulConnect/SupportedChainsList.styles.ts +25 -0
  48. package/src/components/WalletStatefulConnect/SupportedChainsList.tsx +58 -0
  49. package/src/components/WalletStatefulConnect/SupportedChainsList.types.ts +5 -0
  50. package/src/hooks/useStatefulConnect/useStatefulConnect.ts +49 -51
  51. package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +2 -0
  52. package/src/utils/swap.ts +8 -10
  53. package/src/utils/wallets.ts +8 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.41.2-next.1",
3
+ "version": "0.41.2-next.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -25,15 +25,15 @@
25
25
  "@lingui/core": "4.2.1",
26
26
  "@lingui/react": "4.2.1",
27
27
  "@rango-dev/logging-core": "^0.8.0",
28
- "@rango-dev/provider-all": "^0.44.1-next.1",
28
+ "@rango-dev/provider-all": "^0.44.1-next.2",
29
29
  "@rango-dev/queue-manager-core": "^0.29.0",
30
- "@rango-dev/queue-manager-rango-preset": "^0.44.1-next.0",
30
+ "@rango-dev/queue-manager-rango-preset": "^0.44.1-next.1",
31
31
  "@rango-dev/queue-manager-react": "^0.29.0",
32
32
  "@rango-dev/signer-solana": "^0.38.0",
33
- "@rango-dev/ui": "^0.45.1-next.0",
34
- "@rango-dev/wallets-core": "^0.42.1-next.0",
35
- "@rango-dev/wallets-react": "^0.29.1-next.1",
36
- "@rango-dev/wallets-shared": "^0.43.1-next.0",
33
+ "@rango-dev/ui": "^0.45.1-next.1",
34
+ "@rango-dev/wallets-core": "^0.42.1-next.1",
35
+ "@rango-dev/wallets-react": "^0.29.1-next.2",
36
+ "@rango-dev/wallets-shared": "^0.43.1-next.1",
37
37
  "bignumber.js": "^9.1.1",
38
38
  "copy-to-clipboard": "^3.3.3",
39
39
  "dayjs": "^1.11.7",
@@ -54,4 +54,4 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  }
57
- }
57
+ }
@@ -21,7 +21,7 @@ import { useAppStore } from '../../store/AppStore';
21
21
  import { useQuoteStore } from '../../store/quote';
22
22
  import { getBlockchainShortNameFor } from '../../utils/meta';
23
23
  import { isConfirmSwapDisabled } from '../../utils/swap';
24
- import { getQuoteWallets } from '../../utils/wallets';
24
+ import { getQuoteChains } from '../../utils/wallets';
25
25
  import { WatermarkedModal } from '../common/WatermarkedModal';
26
26
  import { CustomDestination } from '../CustomDestination/CustomDestination';
27
27
 
@@ -62,16 +62,16 @@ export function ConfirmWalletsModal(props: PropTypes) {
62
62
  !!customDestination
63
63
  );
64
64
 
65
- const quoteWallets = useMemo(
65
+ const quoteChains = useMemo(
66
66
  () =>
67
- getQuoteWallets({
67
+ getQuoteChains({
68
68
  filter: 'all',
69
69
  quote: selectedQuote,
70
70
  }),
71
71
  [selectedQuote]
72
72
  );
73
73
 
74
- const requiredWallets = getQuoteWallets({
74
+ const requiredChains = getQuoteChains({
75
75
  filter: 'required',
76
76
  quote: selectedQuote,
77
77
  });
@@ -82,17 +82,17 @@ export function ConfirmWalletsModal(props: PropTypes) {
82
82
  selectedQuote?.swaps[selectedQuote?.swaps.length - 1].to.blockchain
83
83
  );
84
84
  const isWalletRequiredFor = (blockchain: string) =>
85
- requiredWallets.includes(blockchain);
85
+ requiredChains.includes(blockchain);
86
86
 
87
87
  const getInitialSelectableWallets = useCallback(
88
88
  () =>
89
89
  connectedWallets.filter((connectedWallet) => {
90
90
  return (
91
91
  connectedWallet.selected &&
92
- quoteWallets.includes(connectedWallet.chain)
92
+ quoteChains.includes(connectedWallet.chain)
93
93
  );
94
94
  }),
95
- [connectedWallets, quoteWallets]
95
+ [connectedWallets, quoteChains]
96
96
  );
97
97
 
98
98
  const [selectableWallets, setSelectableWallets] = useState<ConnectedWallet[]>(
@@ -273,13 +273,13 @@ export function ConfirmWalletsModal(props: PropTypes) {
273
273
  return (
274
274
  !anyWalletSelected &&
275
275
  connectedWallet.selected &&
276
- quoteWallets.includes(connectedWallet.chain)
276
+ quoteChains.includes(connectedWallet.chain)
277
277
  );
278
278
  })
279
279
  );
280
280
  return nextState;
281
281
  });
282
- }, [connectedWallets, quoteWallets]);
282
+ }, [connectedWallets, quoteChains]);
283
283
 
284
284
  useEffect(() => {
285
285
  const nextState: typeof nextSelectedWallets = [];
@@ -391,6 +391,7 @@ export function ConfirmWalletsModal(props: PropTypes) {
391
391
  <div className={walletsListStyles()}>
392
392
  <WalletList
393
393
  chain={showMoreWalletFor}
394
+ quoteChains={quoteChains}
394
395
  isSelected={isSelected}
395
396
  selectWallet={onChange}
396
397
  onShowMore={() => setShowMoreWalletFor(showMoreWalletFor)}
@@ -410,13 +411,13 @@ export function ConfirmWalletsModal(props: PropTypes) {
410
411
  </>
411
412
  )}
412
413
  <Wallets>
413
- {quoteWallets.map((requiredWallet, index) => {
414
+ {quoteChains.map((requiredWallet, index) => {
414
415
  const blockchain = blockchains.find(
415
416
  (blockchain) => blockchain.name === requiredWallet
416
417
  );
417
418
 
418
419
  const key = `wallet-${index}`;
419
- const isLastWallet = index === quoteWallets.length - 1;
420
+ const isLastWallet = index === quoteChains.length - 1;
420
421
  const showCustomDestination =
421
422
  isLastWallet &&
422
423
  lastStepToBlockchain &&
@@ -444,6 +445,7 @@ export function ConfirmWalletsModal(props: PropTypes) {
444
445
  <ListContainer>
445
446
  <WalletList
446
447
  chain={requiredWallet}
448
+ quoteChains={quoteChains}
447
449
  isSelected={isSelected}
448
450
  selectWallet={onChange}
449
451
  limit={NUMBER_OF_WALLETS_TO_DISPLAY}
@@ -35,7 +35,8 @@ const ACCOUNT_ADDRESS_MAX_CHARACTERS = 7;
35
35
  const TIME_TO_CLOSE_MODAL = 3_000;
36
36
 
37
37
  export function WalletList(props: PropTypes) {
38
- const { chain, isSelected, selectWallet, limit, onShowMore } = props;
38
+ const { chain, quoteChains, isSelected, selectWallet, limit, onShowMore } =
39
+ props;
39
40
  const isActiveTab = useUiStore.use.isActiveTab();
40
41
 
41
42
  const { blockchains, connectedWallets } = useAppStore();
@@ -221,6 +222,7 @@ export function WalletList(props: PropTypes) {
221
222
  })}
222
223
  <StatefulConnectModal
223
224
  wallet={selectedWalletToConnect}
225
+ options={{ defaultSelectedChains: quoteChains || [chain] }}
224
226
  onClose={() => {
225
227
  setSelectedWalletToConnect(undefined);
226
228
  }}
@@ -2,6 +2,7 @@ import type { Wallet } from '../../types';
2
2
 
3
3
  export type PropTypes = {
4
4
  chain: string;
5
+ quoteChains?: string[];
5
6
  isSelected: (walletType: string, chain: string) => boolean;
6
7
  selectWallet: (wallet: Wallet) => void;
7
8
  limit?: number;
@@ -28,6 +28,9 @@ interface PropTypes {
28
28
  onClose: () => void;
29
29
  // When connecting wallet is executed **successfully**, this will be called afterwards.
30
30
  onConnect?: () => void;
31
+ options?: {
32
+ defaultSelectedChains?: string[];
33
+ };
31
34
  }
32
35
 
33
36
  export function StatefulConnectModal(props: PropTypes) {
@@ -122,6 +125,7 @@ export function StatefulConnectModal(props: PropTypes) {
122
125
  beforeConnecting();
123
126
  handleConnect(props.wallet, {
124
127
  disconnectIfConnected: true,
128
+ defaultSelectedChains: props.options?.defaultSelectedChains,
125
129
  })
126
130
  .then((result) => {
127
131
  const resultIsNeedMoreStepsToConnect = [
@@ -465,7 +465,7 @@ export function SwapDetails(props: SwapDetailsProps) {
465
465
  onCancel={onCancel}
466
466
  onDelete={onDelete}
467
467
  message={stepMessage.detailedMessage.content}
468
- currentStepWallet={currentStepWallet}
468
+ swap={swap}
469
469
  walletButtonDisabled={!isActiveTab}
470
470
  />
471
471
  <SwapDetailsCompleteModal
@@ -2,6 +2,10 @@ import type { WalletStateContentProps } from './SwapDetailsModal.types';
2
2
  import type { WalletInfoWithExtra } from '../../types';
3
3
 
4
4
  import { warn } from '@rango-dev/logging-core';
5
+ import {
6
+ getCurrentStep,
7
+ getRelatedWalletOrNull,
8
+ } from '@rango-dev/queue-manager-rango-preset';
5
9
  import { MessageBox, Wallet } from '@rango-dev/ui';
6
10
  import { useWallets } from '@rango-dev/wallets-react';
7
11
  import React, { useState } from 'react';
@@ -14,17 +18,17 @@ import { StatefulConnectModal } from '../StatefulConnectModal';
14
18
  import { WalletContainer } from './SwapDetailsModal.styles';
15
19
 
16
20
  export const WalletStateContent = (props: WalletStateContentProps) => {
17
- const {
18
- type,
19
- title,
20
- currentStepWallet,
21
- message,
22
- showWalletButton,
23
- walletButtonDisabled,
24
- } = props;
21
+ const { type, title, swap, message, showWalletButton, walletButtonDisabled } =
22
+ props;
25
23
  const [selectedWalletToConnect, setSelectedWalletToConnect] =
26
24
  useState<WalletInfoWithExtra>();
27
25
  const { getWalletInfo, state } = useWallets();
26
+
27
+ const currentStep = getCurrentStep(swap);
28
+ const currentStepWallet = currentStep
29
+ ? getRelatedWalletOrNull(swap, currentStep)
30
+ : null;
31
+ const currentStepFromBlockchain = currentStep?.fromBlockchain;
28
32
  const walletType = currentStepWallet?.walletType;
29
33
  const walletState = walletType
30
34
  ? mapStatusToWalletState(state(walletType))
@@ -73,6 +77,11 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
73
77
  onClose={() => {
74
78
  setSelectedWalletToConnect(undefined);
75
79
  }}
80
+ options={{
81
+ defaultSelectedChains: currentStepFromBlockchain
82
+ ? [currentStepFromBlockchain]
83
+ : undefined,
84
+ }}
76
85
  />
77
86
  </>
78
87
  );
@@ -17,7 +17,7 @@ export function SwapDetailsModal(props: ModalPropTypes) {
17
17
  onClose,
18
18
  onDelete,
19
19
  onCancel,
20
- currentStepWallet,
20
+ swap,
21
21
  message,
22
22
  walletButtonDisabled,
23
23
  } = props;
@@ -38,7 +38,7 @@ export function SwapDetailsModal(props: ModalPropTypes) {
38
38
  <WalletStateContent
39
39
  type={modalNetworkValues[state].type}
40
40
  title={modalNetworkValues[state].title}
41
- currentStepWallet={currentStepWallet}
41
+ swap={swap}
42
42
  message={message}
43
43
  walletButtonDisabled={walletButtonDisabled}
44
44
  showWalletButton={
@@ -1,21 +1,16 @@
1
- import type { WalletType } from '@rango-dev/wallets-shared';
2
- import type { PendingSwapNetworkStatus } from 'rango-types';
1
+ import type { PendingSwap, PendingSwapNetworkStatus } from 'rango-types';
3
2
 
4
3
  export type ModalState =
5
4
  | Exclude<PendingSwapNetworkStatus, PendingSwapNetworkStatus.WaitingForQueue>
6
5
  | 'delete'
7
6
  | 'cancel'
8
7
  | null;
9
- type WalletTypeAndAddress = {
10
- walletType: WalletType;
11
- address: string;
12
- };
13
8
  export interface ModalPropTypes {
14
9
  onClose: () => void;
15
10
  onCancel: () => void;
16
11
  onDelete: () => void;
17
12
  state: ModalState;
18
- currentStepWallet: WalletTypeAndAddress | null;
13
+ swap: PendingSwap;
19
14
  message: string;
20
15
  walletButtonDisabled: boolean;
21
16
  }
@@ -47,7 +42,7 @@ export interface ModalNetworkValueTypes {
47
42
  }
48
43
 
49
44
  export interface WalletStateContentProps extends ModalNetworkValueTypes {
50
- currentStepWallet: WalletTypeAndAddress | null;
45
+ swap: PendingSwap;
51
46
  message: string;
52
47
  showWalletButton: boolean;
53
48
  walletButtonDisabled: boolean;
@@ -12,11 +12,6 @@ import {
12
12
  } from '@rango-dev/ui';
13
13
  import React, { useEffect, useState } from 'react';
14
14
 
15
- import {
16
- LogoContainer,
17
- Spinner,
18
- WalletImageContainer,
19
- } from './ConnectStatus.styles';
20
15
  import {
21
16
  CUSTOM_DERIVATION_PATH,
22
17
  getDerivationPaths,
@@ -103,14 +98,7 @@ export function DerivationPath(props: PropTypes) {
103
98
  type,
104
99
  },
105
100
  })}
106
- icon={
107
- <LogoContainer>
108
- <WalletImageContainer>
109
- <Image src={image} size={45} />
110
- </WalletImageContainer>
111
- <Spinner />
112
- </LogoContainer>
113
- }
101
+ icon={<Image src={image} size={45} />}
114
102
  />
115
103
 
116
104
  <InputsContainer>
@@ -0,0 +1,64 @@
1
+ import type { NamespaceItemPropTypes } from './Namespaces.types';
2
+
3
+ import { i18n } from '@lingui/core';
4
+ import { Checkbox, Radio, Typography } from '@rango-dev/ui';
5
+ import React from 'react';
6
+
7
+ import { useAppStore } from '../../store/AppStore';
8
+
9
+ import { getBlockchainLogo } from './Namespaces.helpers';
10
+ import {
11
+ NamespaceItemContainer,
12
+ NamespaceItemContent,
13
+ NamespaceLogo,
14
+ NotSupportedNamespaceItemContent,
15
+ } from './Namespaces.styles';
16
+ import { SupportedChainsList } from './SupportedChainsList';
17
+
18
+ export function NamespaceListItem(props: NamespaceItemPropTypes) {
19
+ const { onClick, type, namespace } = props;
20
+ const blockchains = useAppStore().blockchains();
21
+
22
+ if (namespace.unsupported) {
23
+ return (
24
+ <NamespaceItemContainer unsupported>
25
+ <NamespaceLogo
26
+ src={getBlockchainLogo(blockchains, namespace.id)}
27
+ size={40}
28
+ disabled
29
+ />
30
+ <NotSupportedNamespaceItemContent>
31
+ <Typography variant="label" size="large">
32
+ {namespace.label}
33
+ </Typography>
34
+ <Typography variant="body" size="xsmall">
35
+ {i18n.t('(Currently not supported)')}
36
+ </Typography>
37
+ </NotSupportedNamespaceItemContent>
38
+ </NamespaceItemContainer>
39
+ );
40
+ }
41
+
42
+ const showSupportedChains = namespace.chains.length > 1;
43
+ return (
44
+ <NamespaceItemContainer onClick={onClick}>
45
+ <NamespaceLogo
46
+ src={getBlockchainLogo(blockchains, namespace.id)}
47
+ size={40}
48
+ />
49
+ <NamespaceItemContent showSupportedChains={showSupportedChains}>
50
+ <Typography variant="label" size="large">
51
+ {namespace.label}
52
+ </Typography>
53
+ {showSupportedChains && (
54
+ <SupportedChainsList chains={namespace.chains} />
55
+ )}
56
+ </NamespaceItemContent>
57
+ {type === 'radio' ? (
58
+ <Radio value={namespace.value} />
59
+ ) : (
60
+ <Checkbox checked={props.value} />
61
+ )}
62
+ </NamespaceItemContainer>
63
+ );
64
+ }
@@ -1,7 +1,59 @@
1
- import { styled } from '@rango-dev/ui';
1
+ import { Image, styled } from '@rango-dev/ui';
2
2
 
3
3
  export const NamespaceList = styled('ul', {
4
4
  padding: 0,
5
- paddingTop: '$4',
6
- paddingBottom: '$4',
5
+ });
6
+
7
+ export const NamespaceItemContainer = styled('li', {
8
+ backgroundColor: '$neutral200',
9
+ padding: '$16',
10
+ display: 'flex',
11
+ gap: '$8',
12
+ cursor: 'pointer',
13
+ borderRadius: '$sm',
14
+ alignItems: 'center',
15
+ variants: {
16
+ unsupported: {
17
+ true: {
18
+ cursor: 'not-allowed',
19
+ paddingTop: '$8',
20
+ paddingBottom: '$8',
21
+ },
22
+ },
23
+ },
24
+ });
25
+
26
+ export const NamespaceItemContent = styled('div', {
27
+ flex: '1',
28
+ display: 'flex',
29
+ flexDirection: 'column',
30
+ height: '$40',
31
+ variants: {
32
+ showSupportedChains: {
33
+ true: {
34
+ justifyContent: 'space-between',
35
+ },
36
+ false: {
37
+ justifyContent: 'center',
38
+ },
39
+ },
40
+ },
41
+ });
42
+
43
+ export const NotSupportedNamespaceItemContent = styled('div', {
44
+ flex: '1',
45
+ display: 'flex',
46
+ alignItems: 'center',
47
+ gap: '$4',
48
+ opacity: '0.5',
49
+ });
50
+
51
+ export const NamespaceLogo = styled(Image, {
52
+ variants: {
53
+ disabled: {
54
+ true: {
55
+ opacity: '0.5',
56
+ },
57
+ },
58
+ },
7
59
  });
@@ -3,22 +3,16 @@ import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
3
3
 
4
4
  import { i18n } from '@lingui/core';
5
5
  import {
6
+ Alert,
6
7
  Button,
7
- Checkbox,
8
8
  Divider,
9
9
  Image,
10
- ListItemButton,
11
10
  MessageBox,
12
- Radio,
13
11
  RadioRoot,
14
12
  } from '@rango-dev/ui';
15
- import React, { useState } from 'react';
13
+ import React, { useEffect, useMemo, useState } from 'react';
16
14
 
17
- import { useAppStore } from '../../store/AppStore';
18
- import { WalletImageContainer } from '../HeaderButtons/HeaderButtons.styles';
19
-
20
- import { LogoContainer, Spinner } from './ConnectStatus.styles';
21
- import { getBlockchainLogo } from './Namespaces.helpers';
15
+ import { NamespaceListItem } from './NamespaceListItem';
22
16
  import { NamespaceList } from './Namespaces.styles';
23
17
 
24
18
  export function Namespaces(props: PropTypes) {
@@ -27,8 +21,13 @@ export function Namespaces(props: PropTypes) {
27
21
  const providerImage = targetWallet.image;
28
22
 
29
23
  const [selectedNamespaces, setSelectedNamespaces] = useState<Namespace[]>([]);
30
-
31
- const blockchains = useAppStore().blockchains();
24
+ const supportedNamespaces = useMemo(
25
+ () =>
26
+ targetWallet.needsNamespace?.data.filter(
27
+ (namespace) => !namespace.unsupported
28
+ ),
29
+ [targetWallet?.type]
30
+ );
32
31
 
33
32
  const onSelect = (namespace: Namespace) => {
34
33
  if (singleNamespace) {
@@ -42,6 +41,23 @@ export function Namespaces(props: PropTypes) {
42
41
  }
43
42
  };
44
43
 
44
+ const allSupportedNamespacesSelected =
45
+ supportedNamespaces?.length === selectedNamespaces.length;
46
+
47
+ const onSelectAll = () => {
48
+ if (singleNamespace) {
49
+ throw new Error(
50
+ 'onSelectAll should not be called on single selection mode.'
51
+ );
52
+ } else if (allSupportedNamespacesSelected) {
53
+ setSelectedNamespaces([]);
54
+ } else if (supportedNamespaces) {
55
+ setSelectedNamespaces(
56
+ supportedNamespaces.map((namespace) => namespace.value)
57
+ );
58
+ }
59
+ };
60
+
45
61
  const wrapRadioRoot = (children: React.ReactNode) => {
46
62
  if (singleNamespace) {
47
63
  return <RadioRoot value={selectedNamespaces?.[0]}>{children}</RadioRoot>;
@@ -50,63 +66,94 @@ export function Namespaces(props: PropTypes) {
50
66
  return <>{children}</>;
51
67
  };
52
68
 
69
+ useEffect(() => {
70
+ // Initially select supported and required namespaces
71
+ if (!singleNamespace && supportedNamespaces) {
72
+ if (!!props.value.defaultSelectedChains?.length) {
73
+ const namespacesContainingDefaultSelectedChains =
74
+ supportedNamespaces.filter((namespace) =>
75
+ namespace.chains.some((chain) =>
76
+ props.value.defaultSelectedChains?.includes(chain.name)
77
+ )
78
+ );
79
+ setSelectedNamespaces(
80
+ namespacesContainingDefaultSelectedChains.map(
81
+ (namespace) => namespace.value
82
+ )
83
+ );
84
+ } else {
85
+ setSelectedNamespaces(
86
+ supportedNamespaces.map((namespace) => namespace.value)
87
+ );
88
+ }
89
+ }
90
+ }, []);
91
+
53
92
  return (
54
93
  <>
55
- <Divider size={20} />
56
94
  <MessageBox
57
95
  type="info"
58
- title={i18n.t('Select chain types')}
96
+ title={i18n.t(`Connect {wallet}`, {
97
+ wallet: targetWallet.title,
98
+ })}
59
99
  description={i18n.t(
60
- `This wallet supports multiple chains. Select which chain you'd like to connect to.`
100
+ "This wallet supports multiple chains. Choose which chains you'd like to connect to."
61
101
  )}
62
- icon={
63
- <LogoContainer>
64
- <WalletImageContainer>
65
- <Image src={providerImage} size={45} />
66
- </WalletImageContainer>
67
- <Spinner />
68
- </LogoContainer>
69
- }
102
+ icon={<Image src={providerImage} size={45} />}
70
103
  />
104
+ {singleNamespace ? (
105
+ <>
106
+ <Divider size={20} />
107
+ <Alert
108
+ variant="alarm"
109
+ type="info"
110
+ title={i18n.t(
111
+ 'This wallet can only connect to one chain at a time. '
112
+ )}
113
+ />
114
+ </>
115
+ ) : (
116
+ <>
117
+ <Divider size={30} />
118
+ <Button
119
+ style={{ marginLeft: 'auto' }}
120
+ id="widget-name-space-select-all-btn"
121
+ size="xsmall"
122
+ variant="ghost"
123
+ type="primary"
124
+ onClick={onSelectAll}>
125
+ {allSupportedNamespacesSelected
126
+ ? i18n.t('Deselect all')
127
+ : i18n.t('Select all')}
128
+ </Button>
129
+ </>
130
+ )}
71
131
  <NamespaceList>
72
132
  {wrapRadioRoot(
73
133
  <>
74
- {targetWallet.needsNamespace?.data.map((ns) => {
75
- return (
76
- <ListItemButton
77
- key={ns.id}
78
- id={ns.id}
79
- title={ns.label}
80
- hasDivider
81
- style={{ height: 60 }}
82
- onClick={() => onSelect(ns.value)}
83
- start={
84
- <Image
85
- src={getBlockchainLogo(blockchains, ns.id)}
86
- size={22}
87
- />
88
- }
89
- end={
90
- singleNamespace ? (
91
- <Radio value={ns.value} />
92
- ) : (
93
- <Checkbox
94
- checked={selectedNamespaces.includes(ns.value)}
95
- />
96
- )
97
- }
98
- />
99
- );
100
- })}
134
+ {targetWallet.needsNamespace?.data.map(
135
+ (namespace, index, array) => (
136
+ <React.Fragment key={namespace.id}>
137
+ <NamespaceListItem
138
+ value={selectedNamespaces.includes(namespace.value)}
139
+ namespace={namespace}
140
+ type={singleNamespace ? 'radio' : 'checkbox'}
141
+ onClick={() => onSelect(namespace.value)}
142
+ />
143
+ {index !== array.length - 1 && <Divider size={10} />}
144
+ </React.Fragment>
145
+ )
146
+ )}
101
147
  </>
102
148
  )}
103
149
  </NamespaceList>
150
+ <Divider size={20} />
104
151
  <Button
105
152
  id="widget-name-space-confirm-btn"
106
153
  type="primary"
107
154
  disabled={!selectedNamespaces.length}
108
155
  onClick={() => props.onConfirm(selectedNamespaces)}>
109
- {i18n.t('Confirm')}
156
+ {i18n.t('Connect')}
110
157
  </Button>
111
158
  </>
112
159
  );
@@ -1,7 +1,35 @@
1
1
  import type { NeedsNamespacesState } from '../../hooks/useStatefulConnect';
2
- import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
2
+ import type {
3
+ Chain,
4
+ Namespace,
5
+ } from '@rango-dev/wallets-core/namespaces/common';
3
6
 
4
7
  export interface PropTypes {
5
8
  onConfirm: (namespaces: Namespace[]) => void;
6
9
  value: NeedsNamespacesState;
7
10
  }
11
+
12
+ interface NamespaceItemSharedPropTypes {
13
+ onClick: () => void;
14
+ type: 'radio' | 'checkbox';
15
+ namespace: {
16
+ label: string;
17
+ id: string;
18
+ value: Namespace;
19
+ chains: Chain[];
20
+ unsupported?: boolean;
21
+ };
22
+ }
23
+
24
+ interface RadioNamespaceItemPropTypes extends NamespaceItemSharedPropTypes {
25
+ type: 'radio';
26
+ }
27
+
28
+ interface CheckboxNamespaceItemPropTypes extends NamespaceItemSharedPropTypes {
29
+ type: 'checkbox';
30
+ value: boolean;
31
+ }
32
+
33
+ export type NamespaceItemPropTypes =
34
+ | RadioNamespaceItemPropTypes
35
+ | CheckboxNamespaceItemPropTypes;