@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
@@ -0,0 +1,25 @@
1
+ import { styled } from '@rango-dev/ui';
2
+
3
+ export const SupportedChainsContainer = styled('div', {
4
+ display: 'flex',
5
+ alignItems: 'center',
6
+ padding: 0,
7
+ margin: 0,
8
+ });
9
+
10
+ export const SupportedChainItem = styled('div', {
11
+ marginLeft: '-5px',
12
+ listStyleType: 'none',
13
+ backgroundColor: '$background',
14
+ borderRadius: '$lg',
15
+ minWidth: '15px',
16
+ height: '15px',
17
+ variants: {
18
+ firstItem: {
19
+ true: { marginLeft: 0 },
20
+ },
21
+ },
22
+ display: 'flex',
23
+ alignItems: 'center',
24
+ justifyContent: 'center',
25
+ });
@@ -0,0 +1,58 @@
1
+ import type { PropTypes } from './SupportedChainsList.types';
2
+
3
+ import { Image, Tooltip, Typography } from '@rango-dev/ui';
4
+ import React from 'react';
5
+
6
+ import { getContainer } from '../../utils/common';
7
+
8
+ import {
9
+ SupportedChainItem,
10
+ SupportedChainsContainer,
11
+ } from './SupportedChainsList.styles';
12
+
13
+ const SUPPORTED_CHAINS_MAX_DISPLAYED_NUMBER = 3;
14
+
15
+ export function SupportedChainsList(props: PropTypes) {
16
+ const { chains } = props;
17
+ return (
18
+ <SupportedChainsContainer>
19
+ {chains
20
+ .slice(0, SUPPORTED_CHAINS_MAX_DISPLAYED_NUMBER)
21
+ .map((chain, index) => (
22
+ <Tooltip
23
+ key={chain.name}
24
+ container={getContainer()}
25
+ side="bottom"
26
+ align="start"
27
+ content={chain.name}
28
+ sideOffset={4}>
29
+ <SupportedChainItem firstItem={index === 0}>
30
+ <Image src={chain.logo} size={15} />
31
+ </SupportedChainItem>
32
+ </Tooltip>
33
+ ))}
34
+ {chains.length > SUPPORTED_CHAINS_MAX_DISPLAYED_NUMBER && (
35
+ <Tooltip
36
+ container={getContainer()}
37
+ side="bottom"
38
+ align="start"
39
+ sideOffset={4}
40
+ content={
41
+ <SupportedChainsContainer>
42
+ {chains.map((chain, index) => (
43
+ <SupportedChainItem key={chain.name} firstItem={index === 0}>
44
+ <Image src={chain.logo} size={15} />
45
+ </SupportedChainItem>
46
+ ))}
47
+ </SupportedChainsContainer>
48
+ }>
49
+ <SupportedChainItem>
50
+ <Typography variant="body" size="xsmall">
51
+ +{chains.length - SUPPORTED_CHAINS_MAX_DISPLAYED_NUMBER}
52
+ </Typography>
53
+ </SupportedChainItem>
54
+ </Tooltip>
55
+ )}
56
+ </SupportedChainsContainer>
57
+ );
58
+ }
@@ -0,0 +1,5 @@
1
+ import type { Chain } from '@rango-dev/wallets-core/dist/namespaces/common/types';
2
+
3
+ export type PropTypes = {
4
+ chains: Chain[];
5
+ };
@@ -85,72 +85,70 @@ export function useStatefulConnect(): UseStatefulConnect {
85
85
  const isDisconnected = wallet.state === WalletState.DISCONNECTED;
86
86
 
87
87
  if (isDisconnected) {
88
- // Legacy and hub have different structure to check wether we need to show namespace or not.
89
-
90
- // Hub
91
- const isHub = !!wallet.isHub;
92
- if (isHub) {
93
- const detachedInstances = wallet.properties?.find(
94
- (item) => item.name === 'detached'
95
- );
96
- const needsNamespace =
97
- detachedInstances && wallet.state !== 'connected';
98
-
99
- if (needsNamespace) {
100
- dispatch({
101
- type: 'needsNamespace',
102
- payload: {
103
- targetWallet: wallet,
104
- },
105
- });
106
- return { status: ResultStatus.Namespace };
107
- }
108
- }
109
-
110
88
  /*
111
- * Legacy
112
- *
113
- * For legacy there are 3 states:
114
- * 1. a wallet doesn't have any namespace defined, we call the connect.
115
- * 2. a wallet has more than two namespaces, we should show namepsace modal, and in that place user will be checked to needs derivation path or not.
116
- * 3. a wallet has exactly one namespacesape, in this case we check if that needs derivation or not, if it needs we will do it here by dispatching the action accordingly.
89
+ * Currently, handling connect should be covered for 3 different types of target wallet:
90
+ * 1. Target wallet does not contain any namespaces, in this situation we should just try to connect to the related provider.
91
+ * 2. Target wallet contains more than one namespace, in this situation we should display namespaces modal to allow the user to choose from available namespaces.
92
+ * 3. Target wallet contains only one namespace, in this situation we should check if that namespace needs derivation path and based on that, try to connect to the related provider or display derivation path modal.
117
93
  */
118
- if (!wallet.needsNamespace) {
94
+
95
+ // Legacy and hub have different structure to handle each situation.
96
+ const isHub = !!wallet.isHub;
97
+ const detachedInstances = wallet.properties?.find(
98
+ (item) => item.name === 'detached'
99
+ )?.value;
100
+
101
+ // 1. Target wallet does not contain any namespaces
102
+ if (
103
+ (isHub && !detachedInstances?.length) ||
104
+ (!isHub && !wallet.needsNamespace)
105
+ ) {
119
106
  return await runConnect(wallet.type, undefined, options);
120
107
  }
121
108
 
122
- const needsNamespace = wallet.needsNamespace.data.length > 1;
123
- const needsDerivationPath = wallet.needsDerivationPath;
124
-
125
- if (needsNamespace) {
109
+ // 2. Target wallet contains more than one namespace
110
+ if (
111
+ (isHub && detachedInstances?.length && detachedInstances.length > 1) ||
112
+ (!isHub &&
113
+ wallet.needsNamespace?.data.length &&
114
+ wallet.needsNamespace.data.length > 1)
115
+ ) {
126
116
  dispatch({
127
117
  type: 'needsNamespace',
128
118
  payload: {
129
119
  targetWallet: wallet,
120
+ defaultSelectedChains: options?.defaultSelectedChains,
130
121
  },
131
122
  });
132
123
  return { status: ResultStatus.Namespace };
133
- } else if (needsDerivationPath) {
134
- const namespace = wallet.needsNamespace.data[0];
124
+ }
135
125
 
136
- dispatch({
137
- type: 'needsDerivationPath',
138
- payload: {
139
- providerType: wallet.type,
140
- providerImage: wallet.image,
126
+ // 3. Target wallet contains only one namespace
127
+ if (
128
+ (isHub && detachedInstances?.length === 1) ||
129
+ (!isHub && wallet.needsNamespace?.data.length === 1)
130
+ ) {
131
+ if (wallet.needsNamespace && wallet.needsDerivationPath) {
132
+ const namespace = wallet.needsNamespace.data[0];
133
+
134
+ dispatch({
135
+ type: 'needsDerivationPath',
136
+ payload: {
137
+ providerType: wallet.type,
138
+ providerImage: wallet.image,
139
+ namespace: namespace.value,
140
+ },
141
+ });
142
+ return { status: ResultStatus.DerivationPath };
143
+ }
144
+ return await runConnect(
145
+ wallet.type,
146
+ wallet.needsNamespace?.data.map((namespace) => ({
141
147
  namespace: namespace.value,
142
- },
143
- });
144
- return { status: ResultStatus.DerivationPath };
148
+ })),
149
+ options
150
+ );
145
151
  }
146
-
147
- return await runConnect(
148
- wallet.type,
149
- wallet.needsNamespace?.data.map((namespace) => ({
150
- namespace: namespace.value,
151
- })),
152
- options
153
- );
154
152
  }
155
153
 
156
154
  if (options?.disconnectIfConnected) {
@@ -4,10 +4,12 @@ import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
4
4
  export interface HandleConnectOptions {
5
5
  // To have a switch between connect and disconnect when user is clicking on a button, this option can be helpful.
6
6
  disconnectIfConnected?: boolean;
7
+ defaultSelectedChains?: string[];
7
8
  }
8
9
 
9
10
  export interface NeedsNamespacesState {
10
11
  targetWallet: ExtendedModalWalletInfo;
12
+ defaultSelectedChains?: string[];
11
13
  }
12
14
 
13
15
  export interface NeedsDerivationPathState {
package/src/utils/swap.ts CHANGED
@@ -50,7 +50,7 @@ import {
50
50
  import { getBlockchainShortNameFor, isValidTokenAddress } from './meta';
51
51
  import { numberToString } from './numbers';
52
52
  import { getRequiredBalanceOfWallet } from './quote';
53
- import { getQuoteWallets } from './wallets';
53
+ import { getQuoteChains } from './wallets';
54
54
 
55
55
  export function getOutputRatio(
56
56
  inputUsdValue: BigNumber | null,
@@ -601,7 +601,7 @@ export function generateBalanceWarnings(
601
601
  blockchains: BlockchainMeta[]
602
602
  ) {
603
603
  const fee = quote.validationStatus;
604
- const requiredWallets = getQuoteWallets({ filter: 'required', quote });
604
+ const requiredWallets = getQuoteChains({ filter: 'required', quote });
605
605
  const walletsSortedByRequiredWallets = selectedWallets.sort(
606
606
  (selectedWallet1, selectedWallet2) =>
607
607
  requiredWallets.indexOf(selectedWallet1.chain) -
@@ -751,18 +751,16 @@ export function isConfirmSwapDisabled(
751
751
  return true;
752
752
  }
753
753
 
754
- const allWallets = getQuoteWallets({ filter: 'all', quote });
754
+ const allChains = getQuoteChains({ filter: 'all', quote });
755
755
 
756
- const requiredWallets = getQuoteWallets({ filter: 'required', quote });
756
+ const requiredChains = getQuoteChains({ filter: 'required', quote });
757
757
 
758
- const everyWalletSelected = allWallets.every((blockchain) =>
759
- selectedWallets.some(
760
- (selectedWallet) => selectedWallet.chain === blockchain
761
- )
758
+ const everyWalletSelected = allChains.every((chain) =>
759
+ selectedWallets.some((selectedWallet) => selectedWallet.chain === chain)
762
760
  );
763
761
 
764
- const everyRequiredWalletSelected = requiredWallets.every((wallet) =>
765
- selectedWallets.some((selectedWallet) => selectedWallet.chain === wallet)
762
+ const everyRequiredWalletSelected = requiredChains.every((chain) =>
763
+ selectedWallets.some((selectedWallet) => selectedWallet.chain === chain)
766
764
  );
767
765
 
768
766
  const customDestinationIsValid =
@@ -45,18 +45,14 @@ export type ExtendedModalWalletInfo = WalletInfoWithExtra &
45
45
  Pick<ExtendedWalletInfo, 'properties' | 'isHub'>;
46
46
 
47
47
  export function mapStatusToWalletState(state: WalletState): WalletStatus {
48
- // TODO: refactor
49
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
50
- switch (true) {
51
- case state.connected:
52
- return WalletStatus.CONNECTED;
53
- case state.connecting:
54
- return WalletStatus.CONNECTING;
55
- case !state.installed:
56
- return WalletStatus.NOT_INSTALLED;
57
- default:
58
- return WalletStatus.DISCONNECTED;
48
+ if (state.connected) {
49
+ return WalletStatus.CONNECTED;
50
+ } else if (state.connecting) {
51
+ return WalletStatus.CONNECTING;
52
+ } else if (!state.installed) {
53
+ return WalletStatus.NOT_INSTALLED;
59
54
  }
55
+ return WalletStatus.DISCONNECTED;
60
56
  }
61
57
 
62
58
  export function mapWalletTypesToWalletInfo(
@@ -225,7 +221,7 @@ export function prepareAccountsForWalletStore(
225
221
  return result;
226
222
  }
227
223
 
228
- export function getQuoteWallets(params: {
224
+ export function getQuoteChains(params: {
229
225
  filter: 'all' | 'required';
230
226
  quote: SelectedQuote | null;
231
227
  }): string[] {