@rango-dev/widget-embedded 0.43.0 → 0.43.1-next.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 (173) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +2 -5
  3. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
  4. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  5. package/dist/components/NoResult/NoResult.d.ts.map +1 -1
  6. package/dist/components/NoResult/NoResult.types.d.ts +1 -0
  7. package/dist/components/NoResult/NoResult.types.d.ts.map +1 -1
  8. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts.map +1 -1
  9. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts +5 -3
  10. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -1
  11. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts +440 -0
  12. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +1 -1
  13. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts +2 -0
  14. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts.map +1 -1
  15. package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts.map +1 -1
  16. package/dist/components/Slippage/Slippage.d.ts.map +1 -1
  17. package/dist/components/Slippage/Slippage.styles.d.ts +162 -0
  18. package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
  19. package/dist/components/SlippageWarningsAndErrors/SlippageWarningsAndErrors.d.ts +4 -0
  20. package/dist/components/SlippageWarningsAndErrors/SlippageWarningsAndErrors.d.ts.map +1 -0
  21. package/dist/components/SlippageWarningsAndErrors/SlippageWarningsAndErrors.helpers.d.ts +8 -0
  22. package/dist/components/SlippageWarningsAndErrors/SlippageWarningsAndErrors.helpers.d.ts.map +1 -0
  23. package/dist/components/SlippageWarningsAndErrors/SlippageWarningsAndErrors.types.d.ts +4 -0
  24. package/dist/components/SlippageWarningsAndErrors/SlippageWarningsAndErrors.types.d.ts.map +1 -0
  25. package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts.map +1 -1
  26. package/dist/components/StatefulConnectModal/helpers.d.ts +3 -0
  27. package/dist/components/StatefulConnectModal/helpers.d.ts.map +1 -1
  28. package/dist/components/StatefulConnectModal/index.d.ts +1 -1
  29. package/dist/components/StatefulConnectModal/index.d.ts.map +1 -1
  30. package/dist/components/SwapMetrics/SwapMetrics.constants.d.ts +5 -0
  31. package/dist/components/SwapMetrics/SwapMetrics.constants.d.ts.map +1 -0
  32. package/dist/components/SwapMetrics/SwapMetrics.d.ts +4 -0
  33. package/dist/components/SwapMetrics/SwapMetrics.d.ts.map +1 -0
  34. package/dist/components/SwapMetrics/SwapMetrics.helpers.d.ts +11 -0
  35. package/dist/components/SwapMetrics/SwapMetrics.helpers.d.ts.map +1 -0
  36. package/dist/components/SwapMetrics/SwapMetrics.styles.d.ts +482 -0
  37. package/dist/components/SwapMetrics/SwapMetrics.styles.d.ts.map +1 -0
  38. package/dist/components/SwapMetrics/SwapMetrics.types.d.ts +27 -0
  39. package/dist/components/SwapMetrics/SwapMetrics.types.d.ts.map +1 -0
  40. package/dist/components/SwapMetrics/index.d.ts +2 -0
  41. package/dist/components/SwapMetrics/index.d.ts.map +1 -0
  42. package/dist/components/WalletStatefulConnect/Detached.d.ts +4 -0
  43. package/dist/components/WalletStatefulConnect/Detached.d.ts.map +1 -0
  44. package/dist/components/WalletStatefulConnect/Detached.types.d.ts +8 -0
  45. package/dist/components/WalletStatefulConnect/Detached.types.d.ts.map +1 -0
  46. package/dist/components/WalletStatefulConnect/NamespaceDetachedItem.d.ts +4 -0
  47. package/dist/components/WalletStatefulConnect/NamespaceDetachedItem.d.ts.map +1 -0
  48. package/dist/components/WalletStatefulConnect/NamespaceListItem.d.ts.map +1 -1
  49. package/dist/components/WalletStatefulConnect/NamespaceUnsupportedItem.d.ts +4 -0
  50. package/dist/components/WalletStatefulConnect/NamespaceUnsupportedItem.d.ts.map +1 -0
  51. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
  52. package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts +805 -3
  53. package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts.map +1 -1
  54. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +11 -8
  55. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
  56. package/dist/components/WalletStatefulConnect/index.d.ts +1 -0
  57. package/dist/components/WalletStatefulConnect/index.d.ts.map +1 -1
  58. package/dist/constants/errors.d.ts.map +1 -1
  59. package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
  60. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  61. package/dist/containers/Wallets/Wallets.types.d.ts +5 -3
  62. package/dist/containers/Wallets/Wallets.types.d.ts.map +1 -1
  63. package/dist/containers/Wallets/useUpdates.d.ts +3 -3
  64. package/dist/containers/Wallets/useUpdates.d.ts.map +1 -1
  65. package/dist/hooks/useBootstrap/useBootstrap.d.ts.map +1 -1
  66. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
  67. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
  68. package/dist/hooks/useStatefulConnect/useStatefulConnect.state.d.ts +3 -1
  69. package/dist/hooks/useStatefulConnect/useStatefulConnect.state.d.ts.map +1 -1
  70. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +11 -2
  71. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
  72. package/dist/hooks/useSyncUrlAndStore/useSyncUrlAndStore.d.ts.map +1 -1
  73. package/dist/hooks/useWalletList.d.ts +2 -2
  74. package/dist/hooks/useWalletList.d.ts.map +1 -1
  75. package/dist/index.d.ts +4 -2
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +2 -2
  78. package/dist/index.js.map +4 -4
  79. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  80. package/dist/pages/Home.d.ts.map +1 -1
  81. package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
  82. package/dist/pages/WalletsPage.d.ts.map +1 -1
  83. package/dist/store/AppStore.d.ts +2 -0
  84. package/dist/store/AppStore.d.ts.map +1 -1
  85. package/dist/store/app.d.ts +2 -0
  86. package/dist/store/app.d.ts.map +1 -1
  87. package/dist/store/quote.d.ts +2 -0
  88. package/dist/store/quote.d.ts.map +1 -1
  89. package/dist/store/slices/settings.d.ts +3 -0
  90. package/dist/store/slices/settings.d.ts.map +1 -1
  91. package/dist/types/quote.d.ts +1 -0
  92. package/dist/types/quote.d.ts.map +1 -1
  93. package/dist/utils/colors.d.ts.map +1 -1
  94. package/dist/utils/numbers.d.ts +1 -0
  95. package/dist/utils/numbers.d.ts.map +1 -1
  96. package/dist/utils/sanitizers.d.ts +27 -0
  97. package/dist/utils/sanitizers.d.ts.map +1 -0
  98. package/dist/utils/sanitizers.test.d.ts +2 -0
  99. package/dist/utils/sanitizers.test.d.ts.map +1 -0
  100. package/dist/utils/settings.d.ts +2 -1
  101. package/dist/utils/settings.d.ts.map +1 -1
  102. package/dist/utils/validation.d.ts +26 -0
  103. package/dist/utils/validation.d.ts.map +1 -0
  104. package/dist/utils/validation.test.d.ts +2 -0
  105. package/dist/utils/validation.test.d.ts.map +1 -0
  106. package/dist/utils/wallets.d.ts +9 -1
  107. package/dist/utils/wallets.d.ts.map +1 -1
  108. package/dist/widget-embedded.build.json +1 -1
  109. package/package.json +8 -8
  110. package/src/components/ConfirmWalletsModal/ConfirmWallets.styles.ts +4 -47
  111. package/src/components/ConfirmWalletsModal/WalletList.tsx +35 -19
  112. package/src/components/NoResult/NoResult.tsx +4 -1
  113. package/src/components/NoResult/NoResult.types.ts +1 -0
  114. package/src/components/Quote/Quote.tsx +1 -1
  115. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +29 -4
  116. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.ts +10 -1
  117. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.tsx +38 -7
  118. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.ts +2 -0
  119. package/src/components/QuoteWarningsAndErrors/SlippageWariningModal.tsx +20 -21
  120. package/src/components/Slippage/Slippage.styles.ts +23 -0
  121. package/src/components/Slippage/Slippage.tsx +28 -22
  122. package/src/components/SlippageWarningsAndErrors/SlippageWarningsAndErrors.helpers.ts +33 -0
  123. package/src/components/SlippageWarningsAndErrors/SlippageWarningsAndErrors.tsx +48 -0
  124. package/src/components/SlippageWarningsAndErrors/SlippageWarningsAndErrors.types.ts +3 -0
  125. package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +19 -1
  126. package/src/components/StatefulConnectModal/helpers.ts +6 -0
  127. package/src/components/StatefulConnectModal/index.ts +1 -1
  128. package/src/components/SwapMetrics/SwapMetrics.constants.ts +4 -0
  129. package/src/components/SwapMetrics/SwapMetrics.helpers.ts +76 -0
  130. package/src/components/SwapMetrics/SwapMetrics.styles.ts +32 -0
  131. package/src/components/SwapMetrics/SwapMetrics.tsx +134 -0
  132. package/src/components/SwapMetrics/SwapMetrics.types.ts +26 -0
  133. package/src/components/SwapMetrics/index.ts +1 -0
  134. package/src/components/WalletStatefulConnect/Detached.tsx +53 -0
  135. package/src/components/WalletStatefulConnect/Detached.types.ts +8 -0
  136. package/src/components/WalletStatefulConnect/NamespaceDetachedItem.tsx +177 -0
  137. package/src/components/WalletStatefulConnect/NamespaceListItem.tsx +14 -33
  138. package/src/components/WalletStatefulConnect/NamespaceUnsupportedItem.tsx +42 -0
  139. package/src/components/WalletStatefulConnect/Namespaces.styles.ts +44 -6
  140. package/src/components/WalletStatefulConnect/Namespaces.tsx +12 -7
  141. package/src/components/WalletStatefulConnect/Namespaces.types.tsx +13 -11
  142. package/src/components/WalletStatefulConnect/index.ts +1 -0
  143. package/src/constants/errors.ts +6 -7
  144. package/src/containers/Inputs/Inputs.tsx +2 -0
  145. package/src/containers/Wallets/Wallets.tsx +6 -5
  146. package/src/containers/Wallets/Wallets.types.ts +5 -3
  147. package/src/containers/Wallets/useUpdates.ts +40 -32
  148. package/src/hooks/useBootstrap/useBootstrap.ts +33 -10
  149. package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +1 -0
  150. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +1 -1
  151. package/src/hooks/useStatefulConnect/useStatefulConnect.state.ts +11 -1
  152. package/src/hooks/useStatefulConnect/useStatefulConnect.ts +33 -4
  153. package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +13 -1
  154. package/src/hooks/useSwapInput.ts +1 -1
  155. package/src/hooks/useSyncUrlAndStore/useSyncUrlAndStore.ts +2 -0
  156. package/src/hooks/useWalletList.ts +3 -3
  157. package/src/index.ts +8 -1
  158. package/src/pages/ConfirmSwapPage.tsx +6 -1
  159. package/src/pages/Home.tsx +61 -12
  160. package/src/pages/LiquiditySourcePage.tsx +5 -3
  161. package/src/pages/WalletsPage.tsx +17 -1
  162. package/src/store/app.ts +1 -0
  163. package/src/store/quote.ts +23 -4
  164. package/src/store/slices/settings.ts +11 -0
  165. package/src/types/quote.ts +4 -1
  166. package/src/utils/colors.ts +3 -10
  167. package/src/utils/numbers.ts +11 -0
  168. package/src/utils/sanitizers.test.ts +122 -0
  169. package/src/utils/sanitizers.ts +41 -0
  170. package/src/utils/settings.ts +11 -4
  171. package/src/utils/validation.test.ts +121 -0
  172. package/src/utils/validation.ts +45 -0
  173. package/src/utils/wallets.ts +59 -14
@@ -1,6 +1,5 @@
1
1
  import type { NamespaceItemPropTypes } from './Namespaces.types';
2
2
 
3
- import { i18n } from '@lingui/core';
4
3
  import { Checkbox, Radio, Typography } from '@rango-dev/ui';
5
4
  import React from 'react';
6
5
 
@@ -10,8 +9,8 @@ import { getBlockchainLogo } from './Namespaces.helpers';
10
9
  import {
11
10
  NamespaceItemContainer,
12
11
  NamespaceItemContent,
12
+ NamespaceItemInnerContent,
13
13
  NamespaceLogo,
14
- NotSupportedNamespaceItemContent,
15
14
  } from './Namespaces.styles';
16
15
  import { SupportedChainsList } from './SupportedChainsList';
17
16
 
@@ -19,46 +18,28 @@ export function NamespaceListItem(props: NamespaceItemPropTypes) {
19
18
  const { onClick, type, namespace } = props;
20
19
  const blockchains = useAppStore().blockchains();
21
20
 
22
- if (namespace.unsupported) {
23
- return (
24
- <NamespaceItemContainer unsupported>
21
+ const showSupportedChains = namespace.chains.length > 1;
22
+ return (
23
+ <NamespaceItemContainer onClick={onClick} clickable>
24
+ <NamespaceItemContent>
25
25
  <NamespaceLogo
26
26
  src={getBlockchainLogo(blockchains, namespace.id)}
27
27
  size={40}
28
- disabled
29
28
  />
30
- <NotSupportedNamespaceItemContent>
29
+ <NamespaceItemInnerContent showSupportedChains={showSupportedChains}>
31
30
  <Typography variant="label" size="large">
32
31
  {namespace.label}
33
32
  </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} />
33
+ {showSupportedChains && (
34
+ <SupportedChainsList chains={namespace.chains} />
35
+ )}
36
+ </NamespaceItemInnerContent>
37
+ {type === 'radio' ? (
38
+ <Radio value={namespace.value} />
39
+ ) : (
40
+ <Checkbox checked={props.value} />
55
41
  )}
56
42
  </NamespaceItemContent>
57
- {type === 'radio' ? (
58
- <Radio value={namespace.value} />
59
- ) : (
60
- <Checkbox checked={props.value} />
61
- )}
62
43
  </NamespaceItemContainer>
63
44
  );
64
45
  }
@@ -0,0 +1,42 @@
1
+ import type { NamespaceUnsupportedItemPropTypes } from './Namespaces.types';
2
+
3
+ import { i18n } from '@lingui/core';
4
+ import { 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
+ UnsupportedNamespaceItemInnerContent,
15
+ } from './Namespaces.styles';
16
+
17
+ export function NamespaceUnsupportedItem(
18
+ props: NamespaceUnsupportedItemPropTypes
19
+ ) {
20
+ const { namespace } = props;
21
+ const blockchains = useAppStore().blockchains();
22
+
23
+ return (
24
+ <NamespaceItemContainer unsupported>
25
+ <NamespaceItemContent>
26
+ <NamespaceLogo
27
+ src={getBlockchainLogo(blockchains, namespace.id)}
28
+ size={40}
29
+ disabled
30
+ />
31
+ <UnsupportedNamespaceItemInnerContent>
32
+ <Typography variant="label" size="large">
33
+ {namespace.label}
34
+ </Typography>
35
+ <Typography variant="body" size="xsmall">
36
+ {i18n.t('(Currently not supported)')}
37
+ </Typography>
38
+ </UnsupportedNamespaceItemInnerContent>
39
+ </NamespaceItemContent>
40
+ </NamespaceItemContainer>
41
+ );
42
+ }
@@ -1,4 +1,4 @@
1
- import { Button, Image, styled } from '@rango-dev/ui';
1
+ import { Button, darkTheme, Image, styled, Typography } from '@rango-dev/ui';
2
2
 
3
3
  export const NamespaceList = styled('ul', {
4
4
  padding: 0,
@@ -10,12 +10,21 @@ export const NamespaceList = styled('ul', {
10
10
  export const NamespaceItemContainer = styled('li', {
11
11
  backgroundColor: '$neutral200',
12
12
  padding: '$16',
13
- display: 'flex',
14
- gap: '$8',
15
- cursor: 'pointer',
16
13
  borderRadius: '$sm',
17
- alignItems: 'center',
18
14
  variants: {
15
+ clickable: {
16
+ true: {
17
+ cursor: 'pointer',
18
+ },
19
+ },
20
+ hasError: {
21
+ true: {
22
+ background: '$error100 ',
23
+ [`.${darkTheme} &`]: {
24
+ backgroundColor: '$error700',
25
+ },
26
+ },
27
+ },
19
28
  unsupported: {
20
29
  true: {
21
30
  cursor: 'not-allowed',
@@ -27,9 +36,16 @@ export const NamespaceItemContainer = styled('li', {
27
36
  });
28
37
 
29
38
  export const NamespaceItemContent = styled('div', {
39
+ display: 'flex',
40
+ gap: '$8',
41
+ alignItems: 'center',
42
+ });
43
+
44
+ export const NamespaceItemInnerContent = styled('div', {
30
45
  flex: '1',
31
46
  display: 'flex',
32
47
  flexDirection: 'column',
48
+ justifyContent: 'space-between',
33
49
  height: '$40',
34
50
  variants: {
35
51
  showSupportedChains: {
@@ -43,7 +59,7 @@ export const NamespaceItemContent = styled('div', {
43
59
  },
44
60
  });
45
61
 
46
- export const NotSupportedNamespaceItemContent = styled('div', {
62
+ export const UnsupportedNamespaceItemInnerContent = styled('div', {
47
63
  flex: '1',
48
64
  display: 'flex',
49
65
  alignItems: 'center',
@@ -64,3 +80,25 @@ export const NamespaceLogo = styled(Image, {
64
80
  export const StyledButton = styled(Button, {
65
81
  minHeight: '$40',
66
82
  });
83
+
84
+ export const NamespaceAccountAddress = styled(Typography, {
85
+ maxWidth: '100px',
86
+ });
87
+
88
+ export const NamespaceItemError = styled('div', {
89
+ paddingLeft: '48px',
90
+ });
91
+
92
+ export const NamespaceItemErrorDropdownToggle = styled('div', {
93
+ display: 'flex',
94
+ gap: '2px',
95
+ cursor: 'pointer',
96
+ alignItems: 'center',
97
+ width: 'fit-content',
98
+ });
99
+
100
+ export const NamespaceDetachedItemInfo = styled('div', {
101
+ display: 'flex',
102
+ gap: '6px',
103
+ alignItems: 'center',
104
+ });
@@ -14,6 +14,7 @@ import React, { useEffect, useMemo, useState } from 'react';
14
14
 
15
15
  import { NamespaceListItem } from './NamespaceListItem';
16
16
  import { NamespaceList, StyledButton } from './Namespaces.styles';
17
+ import { NamespaceUnsupportedItem } from './NamespaceUnsupportedItem';
17
18
 
18
19
  export function Namespaces(props: PropTypes) {
19
20
  const { targetWallet } = props.value;
@@ -97,7 +98,7 @@ export function Namespaces(props: PropTypes) {
97
98
  wallet: targetWallet.title,
98
99
  })}
99
100
  description={i18n.t(
100
- "This wallet supports multiple chains. Choose which chains you'd like to connect to."
101
+ 'This wallet supports multiple chains. Choose which chains youd like to connect.'
101
102
  )}
102
103
  icon={<Image src={providerImage} size={45} />}
103
104
  />
@@ -134,12 +135,16 @@ export function Namespaces(props: PropTypes) {
134
135
  {targetWallet.needsNamespace?.data.map(
135
136
  (namespace, index, array) => (
136
137
  <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
- />
138
+ {namespace.unsupported ? (
139
+ <NamespaceUnsupportedItem namespace={namespace} />
140
+ ) : (
141
+ <NamespaceListItem
142
+ value={selectedNamespaces.includes(namespace.value)}
143
+ namespace={namespace}
144
+ type={singleNamespace ? 'radio' : 'checkbox'}
145
+ onClick={() => onSelect(namespace.value)}
146
+ />
147
+ )}
143
148
  {index !== array.length - 1 && <Divider size={10} />}
144
149
  </React.Fragment>
145
150
  )
@@ -1,8 +1,6 @@
1
1
  import type { NeedsNamespacesState } from '../../hooks/useStatefulConnect';
2
- import type {
3
- Chain,
4
- Namespace,
5
- } from '@rango-dev/wallets-core/namespaces/common';
2
+ import type { LegacyNamespaceMeta } from '@rango-dev/wallets-core/legacy';
3
+ import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
6
4
 
7
5
  export interface PropTypes {
8
6
  onConfirm: (namespaces: Namespace[]) => void;
@@ -12,13 +10,7 @@ export interface PropTypes {
12
10
  interface NamespaceItemSharedPropTypes {
13
11
  onClick: () => void;
14
12
  type: 'radio' | 'checkbox';
15
- namespace: {
16
- label: string;
17
- id: string;
18
- value: Namespace;
19
- chains: Chain[];
20
- unsupported?: boolean;
21
- };
13
+ namespace: LegacyNamespaceMeta;
22
14
  }
23
15
 
24
16
  interface RadioNamespaceItemPropTypes extends NamespaceItemSharedPropTypes {
@@ -33,3 +25,13 @@ interface CheckboxNamespaceItemPropTypes extends NamespaceItemSharedPropTypes {
33
25
  export type NamespaceItemPropTypes =
34
26
  | RadioNamespaceItemPropTypes
35
27
  | CheckboxNamespaceItemPropTypes;
28
+
29
+ export type NamespaceDetachedItemPropTypes = {
30
+ walletType: string;
31
+ initialConnect?: boolean;
32
+ namespace: LegacyNamespaceMeta;
33
+ };
34
+
35
+ export type NamespaceUnsupportedItemPropTypes = {
36
+ namespace: LegacyNamespaceMeta;
37
+ };
@@ -1,4 +1,5 @@
1
1
  export { Namespaces } from './Namespaces';
2
+ export { Detached } from './Detached';
2
3
  export { DerivationPath } from './DerivationPath';
3
4
  export { ConnectStatus } from './ConnectStatus';
4
5
  export { ExperimentalChain } from './ExperimentalChain';
@@ -52,12 +52,11 @@ export const errorMessages = () => {
52
52
  };
53
53
 
54
54
  export function getQuoteErrorMessage(error: QuoteError) {
55
- switch (error.type) {
56
- case QuoteErrorType.NO_RESULT:
57
- return error.diagnosisMessage ?? errorMessages().noResultError.title;
58
- case QuoteErrorType.REQUEST_FAILED:
59
- return errorMessages().genericServerError;
60
- default:
61
- return '';
55
+ if (error.type === QuoteErrorType.NO_RESULT) {
56
+ return error.diagnosisMessage ?? errorMessages().noResultError.title;
57
+ } else if (error.type === QuoteErrorType.REQUEST_FAILED) {
58
+ return error.diagnosisMessage ?? errorMessages().genericServerError;
62
59
  }
60
+
61
+ return '';
63
62
  }
@@ -34,6 +34,7 @@ export function Inputs(props: PropTypes) {
34
34
  toToken,
35
35
  toBlockchain,
36
36
  setInputAmount,
37
+ sanitizeInputAmount,
37
38
  inputAmount,
38
39
  inputUsdValue,
39
40
  outputAmount,
@@ -79,6 +80,7 @@ export function Inputs(props: PropTypes) {
79
80
  label={i18n.t('From')}
80
81
  mode="From"
81
82
  onInputChange={setInputAmount}
83
+ onInputBlur={sanitizeInputAmount}
82
84
  balance={fromTokenFormattedBalance}
83
85
  chain={{
84
86
  displayName: fromBlockchain?.displayName || '',
@@ -1,5 +1,6 @@
1
1
  import type {
2
- OnWalletConnectionChange,
2
+ OnWalletConnectHandler,
3
+ OnWalletDisconnectHandler,
3
4
  PropTypes,
4
5
  WidgetContextInterface,
5
6
  } from './Wallets.types';
@@ -45,8 +46,8 @@ function Main(props: PropsWithChildren<PropTypes>) {
45
46
  ?.walletConnectListedDesktopWalletLink,
46
47
  };
47
48
  const { providers } = useWalletProviders(config.wallets, walletOptions);
48
- const onConnectWalletHandler = useRef<OnWalletConnectionChange>();
49
- const onDisconnectWalletHandler = useRef<OnWalletConnectionChange>();
49
+ const onConnectWalletHandler = useRef<OnWalletConnectHandler>();
50
+ const onDisconnectWalletHandler = useRef<OnWalletDisconnectHandler>();
50
51
  const { handler: handleEvent } = useUpdates({
51
52
  onConnectWalletHandler,
52
53
  onDisconnectWalletHandler,
@@ -71,10 +72,10 @@ function Main(props: PropsWithChildren<PropTypes>) {
71
72
 
72
73
  const handlers = useMemo(
73
74
  () => ({
74
- onConnectWallet: (handler: OnWalletConnectionChange) => {
75
+ onConnectWallet: (handler: OnWalletConnectHandler) => {
75
76
  onConnectWalletHandler.current = handler;
76
77
  },
77
- onDisconnectWallet: (handler: OnWalletConnectionChange) => {
78
+ onDisconnectWallet: (handler: OnWalletDisconnectHandler) => {
78
79
  onDisconnectWalletHandler.current = handler;
79
80
  },
80
81
  }),
@@ -1,23 +1,25 @@
1
1
  import type { WidgetConfig } from '../../types';
2
+ import type { LastConnectedWallet } from '@rango-dev/queue-manager-rango-preset';
2
3
  import type {
3
4
  LegacyEventHandler as EventHandler,
4
5
  LegacyEvents,
5
6
  } from '@rango-dev/wallets-core/legacy';
6
7
 
7
- export type OnWalletConnectionChange = (key: string) => void;
8
+ export type OnWalletConnectHandler = (wallet: LastConnectedWallet) => void;
9
+ export type OnWalletDisconnectHandler = (walletType: string) => void;
8
10
  export interface WidgetContextInterface {
9
11
  /**
10
12
  * A wallet connection handler, utilized within the wallet provider,
11
13
  * is linked to the useBootstrap hook for synchronizing the state of the last connected wallet.
12
14
  * It's important not to override this handler in other locations.
13
15
  */
14
- onConnectWallet(handler: OnWalletConnectionChange): void;
16
+ onConnectWallet(handler: OnWalletConnectHandler): void;
15
17
  /**
16
18
  * A wallet disconnection handler, utilized within the wallet provider,
17
19
  * is linked to the useBootstrap hook for synchronizing the state of the last disconnected wallet.
18
20
  * It's important not to override this handler in other locations.
19
21
  */
20
- onDisconnectWallet(handler: OnWalletConnectionChange): void;
22
+ onDisconnectWallet(handler: OnWalletDisconnectHandler): void;
21
23
  }
22
24
 
23
25
  type EventHandlerParams = Parameters<EventHandler>;
@@ -1,4 +1,8 @@
1
- import type { OnWalletConnectionChange } from './Wallets.types';
1
+ import type {
2
+ OnWalletConnectHandler,
3
+ OnWalletDisconnectHandler,
4
+ } from './Wallets.types';
5
+ import type { LastConnectedWallet } from '@rango-dev/queue-manager-rango-preset';
2
6
  import type {
3
7
  LegacyEventHandler as EventHandler,
4
8
  LegacyEventHandler,
@@ -20,10 +24,10 @@ import {
20
24
 
21
25
  interface UseUpdatesParams {
22
26
  onConnectWalletHandler: React.MutableRefObject<
23
- OnWalletConnectionChange | undefined
27
+ OnWalletConnectHandler | undefined
24
28
  >;
25
29
  onDisconnectWalletHandler: React.MutableRefObject<
26
- OnWalletConnectionChange | undefined
30
+ OnWalletDisconnectHandler | undefined
27
31
  >;
28
32
  }
29
33
  interface UseUpdates {
@@ -51,7 +55,18 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
51
55
  supportedChainNames: Network[] | null;
52
56
  }
53
57
  ) => {
54
- const [type, , value, , info] = event;
58
+ const [type, , value, state, info] = event;
59
+
60
+ const walletFromEvent: LastConnectedWallet = {
61
+ walletType: type,
62
+ network: state.network ?? undefined,
63
+ accounts: value,
64
+ };
65
+ if (!!onConnectWalletHandler.current) {
66
+ onConnectWalletHandler.current(walletFromEvent);
67
+ } else {
68
+ console.warn(`onConnectWallet handler hasn't been set. Are you sure?`);
69
+ }
55
70
 
56
71
  const data = prepareAccountsForWalletStore(
57
72
  type,
@@ -85,16 +100,6 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
85
100
  }
86
101
  }
87
102
 
88
- if (event === Events.CONNECTED) {
89
- const key = `${type}-${state.network}-${value}`;
90
-
91
- if (!!onConnectWalletHandler.current) {
92
- onConnectWalletHandler.current(key);
93
- } else {
94
- console.warn(`onConnectWallet handler hasn't been set. Are you sure?`);
95
- }
96
- }
97
-
98
103
  if (event === Events.PROVIDER_DISCONNECTED) {
99
104
  disconnectWallet(type);
100
105
  if (!!onDisconnectWalletHandler.current) {
@@ -191,33 +196,36 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
191
196
  }
192
197
  }
193
198
  }
194
-
195
- /*
196
- * TODO: not sure why we used `Events.Acccounts` for detecting if a provider gets connected or not, if we can use `CONNCECTED` for the legacy
197
- * we can only rely Events.Connected and remove the legacy conidition
198
- */
199
- if (event === Events.ACCOUNTS && state.connected) {
200
- const key = `${type}-${state.network}-${value}`;
201
-
202
- if (!!onConnectWalletHandler.current) {
203
- onConnectWalletHandler.current(key);
204
- } else {
205
- console.warn(`onConnectWallet handler hasn't been set. Are you sure?`);
206
- }
207
- }
208
199
  };
209
200
 
210
201
  const handleUpdatesForBoth: EventHandler = (
211
202
  type,
212
203
  event,
213
- _value,
204
+ value,
214
205
  state,
215
206
  _info
216
207
  ) => {
217
- if (event === Events.NETWORK && state.network) {
218
- const key = `${type}-${state.network}`;
208
+ if (event === Events.CONNECTED && value) {
209
+ const walletFromEvent: LastConnectedWallet = {
210
+ walletType: type,
211
+ network: state.network ?? undefined,
212
+ accounts: state.accounts ?? undefined,
213
+ };
214
+ if (!!onConnectWalletHandler.current) {
215
+ onConnectWalletHandler.current(walletFromEvent);
216
+ } else {
217
+ console.warn(`onConnectWallet handler hasn't been set. Are you sure?`);
218
+ }
219
+ }
220
+
221
+ if (event === Events.NETWORK && value) {
222
+ const walletFromEvent: LastConnectedWallet = {
223
+ walletType: type,
224
+ network: value,
225
+ accounts: state.accounts ?? undefined,
226
+ };
219
227
  if (!!onConnectWalletHandler.current) {
220
- onConnectWalletHandler.current(key);
228
+ onConnectWalletHandler.current(walletFromEvent);
221
229
  } else {
222
230
  console.warn(`onConnectWallet handler hasn't been set. Are you sure?`);
223
231
  }
@@ -1,7 +1,7 @@
1
1
  import type { WalletType } from '../..';
2
+ import type { LastConnectedWallet } from '@rango-dev/queue-manager-rango-preset';
2
3
 
3
4
  import { useQueueManager } from '@rango-dev/queue-manager-rango-preset';
4
- import { splitWalletNetwork } from '@rango-dev/wallets-shared';
5
5
  import { isEvmBlockchain } from 'rango-sdk';
6
6
  import { useContext, useEffect, useState } from 'react';
7
7
 
@@ -24,8 +24,8 @@ export function useBootstrap() {
24
24
  useSyncNotifications();
25
25
  const blockchains = useAppStore().blockchains();
26
26
  const { canSwitchNetworkTo } = useWallets();
27
- const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
28
- useState('');
27
+ const [lastConnectedWallet, setLastConnectedWallet] =
28
+ useState<LastConnectedWallet | null>(null);
29
29
  const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
30
30
  const widgetContext = useContext(WidgetContext);
31
31
 
@@ -38,7 +38,7 @@ export function useBootstrap() {
38
38
 
39
39
  // At the moment, we only detect the disconnection of EVM wallets.
40
40
  useQueueManager({
41
- lastConnectedWallet: lastConnectedWalletWithNetwork,
41
+ lastConnectedWallet,
42
42
  clearDisconnectedWallet: () => {
43
43
  setDisconnectedWallet(undefined);
44
44
  },
@@ -63,14 +63,37 @@ export function useBootstrap() {
63
63
  * it the future we should add a safer soloution like considering array of handlers .
64
64
  * https://github.com/rango-exchange/rango-client/pull/630/files#r1518846728
65
65
  */
66
- widgetContext.onConnectWallet(setLastConnectedWalletWithNetwork);
66
+ widgetContext.onConnectWallet((walletFromEvent) => {
67
+ /*
68
+ * If no wallet was previously connected or the wallet type has changed,
69
+ * replace the last connected wallet with the new one from the event.
70
+ * Otherwise, merge updated `network` and `accounts` information from the new wallet
71
+ * into the existing last connected wallet without replacing the entire object.
72
+ */
73
+ setLastConnectedWallet((lastConnectedWallet) => {
74
+ if (
75
+ !lastConnectedWallet ||
76
+ lastConnectedWallet.walletType !== walletFromEvent.walletType
77
+ ) {
78
+ return walletFromEvent;
79
+ }
80
+ const lastConnectedWalletClone = { ...lastConnectedWallet };
81
+ if (walletFromEvent.network) {
82
+ lastConnectedWalletClone.network = walletFromEvent.network;
83
+ }
84
+ if (walletFromEvent.accounts) {
85
+ lastConnectedWalletClone.accounts = walletFromEvent.accounts;
86
+ }
87
+ return lastConnectedWalletClone;
88
+ });
89
+ });
67
90
  widgetContext.onDisconnectWallet((walletType) => {
68
91
  setDisconnectedWallet(walletType);
69
- if (
70
- walletType === splitWalletNetwork(lastConnectedWalletWithNetwork)?.[0]
71
- ) {
72
- setLastConnectedWalletWithNetwork('');
73
- }
92
+ setLastConnectedWallet((lastConnectedWallet) =>
93
+ walletType === lastConnectedWallet?.walletType
94
+ ? null
95
+ : lastConnectedWallet
96
+ );
74
97
  });
75
98
 
76
99
  void fetchApiConfig().catch(console.log);
@@ -158,6 +158,7 @@ export function handleQuoteErrors(error: any): ConfirmSwapFetchResult {
158
158
  swap: null,
159
159
  error: {
160
160
  type: QuoteErrorType.REQUEST_FAILED,
161
+ diagnosisMessage: error.message,
161
162
  },
162
163
  warnings: null,
163
164
  };
@@ -72,7 +72,7 @@ export function useConfirmSwap(): ConfirmSwap {
72
72
  const { result } = response;
73
73
 
74
74
  if (!result) {
75
- throw new Error('Error fetching updated route');
75
+ throw new Error(response.error ?? 'Error fetching updated quote');
76
76
  }
77
77
 
78
78
  throwErrorIfResponseIsNotValid({
@@ -3,17 +3,20 @@ import type {
3
3
  NeedsDerivationPathState,
4
4
  NeedsNamespacesState,
5
5
  } from './useStatefulConnect.types';
6
+ import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
6
7
 
7
8
  export interface State {
8
- status: 'init' | 'namespace' | 'derivationPath';
9
+ status: 'init' | 'namespace' | 'derivationPath' | 'detached';
9
10
  namespace: NeedsNamespacesState | null;
10
11
  derivationPath: NeedsDerivationPathState | null;
12
+ selectedNamespaces: Namespace[] | null;
11
13
  }
12
14
 
13
15
  export const initState: State = {
14
16
  status: 'init',
15
17
  namespace: null,
16
18
  derivationPath: null,
19
+ selectedNamespaces: null,
17
20
  };
18
21
 
19
22
  export function reducer(state: State, action: Actions): State {
@@ -31,6 +34,13 @@ export function reducer(state: State, action: Actions): State {
31
34
  status: 'derivationPath',
32
35
  derivationPath: action.payload,
33
36
  };
37
+ case 'detached':
38
+ return {
39
+ ...state,
40
+ status: 'detached',
41
+ namespace: { targetWallet: action.payload.targetWallet },
42
+ selectedNamespaces: action.payload.selectedNamespaces,
43
+ };
34
44
  case 'reset':
35
45
  return initState;
36
46
  case 'resetDerivation':