@rango-dev/widget-embedded 0.32.0 → 0.32.2-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 (130) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  3. package/dist/components/Slippage/Slippage.d.ts.map +1 -1
  4. package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts +11 -0
  5. package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts.map +1 -0
  6. package/dist/components/StatefulConnectModal/helpers.d.ts +10 -0
  7. package/dist/components/StatefulConnectModal/helpers.d.ts.map +1 -0
  8. package/dist/components/StatefulConnectModal/index.d.ts +2 -0
  9. package/dist/components/StatefulConnectModal/index.d.ts.map +1 -0
  10. package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
  11. package/dist/components/WalletStatefulConnect/ConnectStatus.d.ts +4 -0
  12. package/dist/components/WalletStatefulConnect/ConnectStatus.d.ts.map +1 -0
  13. package/dist/components/{WalletModal/WalletModalContent.styles.d.ts → WalletStatefulConnect/ConnectStatus.styles.d.ts} +1 -1
  14. package/dist/components/{WalletModal/WalletModalContent.styles.d.ts.map → WalletStatefulConnect/ConnectStatus.styles.d.ts.map} +1 -1
  15. package/dist/components/WalletStatefulConnect/ConnectStatus.types.d.ts +8 -0
  16. package/dist/components/WalletStatefulConnect/ConnectStatus.types.d.ts.map +1 -0
  17. package/dist/components/WalletStatefulConnect/DerivationPath.d.ts +4 -0
  18. package/dist/components/WalletStatefulConnect/DerivationPath.d.ts.map +1 -0
  19. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +4 -0
  20. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -0
  21. package/dist/components/{WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts → WalletStatefulConnect/DerivationPath.styles.d.ts} +1 -1
  22. package/dist/components/WalletStatefulConnect/DerivationPath.styles.d.ts.map +1 -0
  23. package/dist/components/WalletStatefulConnect/DerivationPath.types.d.ts +6 -0
  24. package/dist/components/WalletStatefulConnect/DerivationPath.types.d.ts.map +1 -0
  25. package/dist/components/WalletStatefulConnect/ExperimentalChain.d.ts +8 -0
  26. package/dist/components/WalletStatefulConnect/ExperimentalChain.d.ts.map +1 -0
  27. package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.d.ts +4 -0
  28. package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.d.ts.map +1 -0
  29. package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.helpers.d.ts +8 -0
  30. package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.helpers.d.ts.map +1 -0
  31. package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.types.d.ts +6 -0
  32. package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.types.d.ts.map +1 -0
  33. package/dist/components/WalletStatefulConnect/Namespaces.d.ts +4 -0
  34. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -0
  35. package/dist/components/WalletStatefulConnect/Namespaces.helpers.d.ts +3 -0
  36. package/dist/components/WalletStatefulConnect/Namespaces.helpers.d.ts.map +1 -0
  37. package/dist/components/{WalletNamespacesModal/WalletNamespacesModal.styles.d.ts → WalletStatefulConnect/Namespaces.styles.d.ts} +1 -1
  38. package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts.map +1 -0
  39. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +7 -0
  40. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -0
  41. package/dist/components/WalletStatefulConnect/index.d.ts +5 -0
  42. package/dist/components/WalletStatefulConnect/index.d.ts.map +1 -0
  43. package/dist/containers/Wallets/Wallets.types.d.ts +1 -1
  44. package/dist/containers/Wallets/Wallets.types.d.ts.map +1 -1
  45. package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts +1 -1
  46. package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts.map +1 -1
  47. package/dist/hooks/useStatefulConnect/index.d.ts +5 -0
  48. package/dist/hooks/useStatefulConnect/index.d.ts.map +1 -0
  49. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +25 -0
  50. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -0
  51. package/dist/hooks/useStatefulConnect/useStatefulConnect.helpers.d.ts +8 -0
  52. package/dist/hooks/useStatefulConnect/useStatefulConnect.helpers.d.ts.map +1 -0
  53. package/dist/hooks/useStatefulConnect/useStatefulConnect.state.d.ts +9 -0
  54. package/dist/hooks/useStatefulConnect/useStatefulConnect.state.d.ts.map +1 -0
  55. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +43 -0
  56. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -0
  57. package/dist/hooks/useWalletList.d.ts +11 -14
  58. package/dist/hooks/useWalletList.d.ts.map +1 -1
  59. package/dist/index.d.ts +5 -3
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +2 -2
  62. package/dist/index.js.map +4 -4
  63. package/dist/pages/WalletsPage.d.ts +0 -2
  64. package/dist/pages/WalletsPage.d.ts.map +1 -1
  65. package/dist/widget-embedded.build.json +1 -1
  66. package/package.json +8 -7
  67. package/src/components/ConfirmWalletsModal/WalletList.tsx +52 -243
  68. package/src/components/HeaderButtons/WalletButton.tsx +1 -1
  69. package/src/components/Slippage/Slippage.tsx +3 -0
  70. package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +168 -0
  71. package/src/components/StatefulConnectModal/helpers.ts +23 -0
  72. package/src/components/StatefulConnectModal/index.ts +1 -0
  73. package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +23 -113
  74. package/src/components/{WalletModal/WalletModalContent.tsx → WalletStatefulConnect/ConnectStatus.tsx} +13 -5
  75. package/src/components/WalletStatefulConnect/ConnectStatus.types.ts +11 -0
  76. package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +23 -0
  77. package/src/components/{WalletDerivationPathModal/WalletDerivationPathModal.tsx → WalletStatefulConnect/DerivationPath.tsx} +18 -36
  78. package/src/components/WalletStatefulConnect/DerivationPath.types.ts +6 -0
  79. package/src/components/WalletStatefulConnect/ExperimentalChain.tsx +36 -0
  80. package/src/components/WalletStatefulConnect/ExperimentalChainStatus.helpers.ts +53 -0
  81. package/src/components/WalletStatefulConnect/ExperimentalChainStatus.tsx +35 -0
  82. package/src/components/WalletStatefulConnect/ExperimentalChainStatus.types.ts +5 -0
  83. package/src/components/WalletStatefulConnect/Namespaces.helpers.ts +9 -0
  84. package/src/components/{WalletNamespacesModal/WalletNamespacesModal.tsx → WalletStatefulConnect/Namespaces.tsx} +9 -27
  85. package/src/components/{WalletNamespacesModal/WalletNamespacesModal.types.tsx → WalletStatefulConnect/Namespaces.types.tsx} +2 -5
  86. package/src/components/WalletStatefulConnect/index.ts +4 -0
  87. package/src/containers/Wallets/Wallets.tsx +1 -1
  88. package/src/containers/Wallets/Wallets.types.ts +1 -1
  89. package/src/containers/WidgetProvider/WidgetProvider.types.ts +1 -1
  90. package/src/hooks/useStatefulConnect/index.ts +9 -0
  91. package/src/hooks/useStatefulConnect/useStatefulConnect.helpers.ts +13 -0
  92. package/src/hooks/useStatefulConnect/useStatefulConnect.state.ts +45 -0
  93. package/src/hooks/useStatefulConnect/useStatefulConnect.ts +232 -0
  94. package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +56 -0
  95. package/src/hooks/useWalletList.ts +22 -53
  96. package/src/index.ts +7 -8
  97. package/src/pages/WalletsPage.tsx +10 -162
  98. package/src/store/wallets.ts +1 -1
  99. package/src/utils/wallets.ts +1 -1
  100. package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts +0 -4
  101. package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts.map +0 -1
  102. package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts.map +0 -1
  103. package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts +0 -10
  104. package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts.map +0 -1
  105. package/dist/components/WalletDerivationPathModal/index.d.ts +0 -2
  106. package/dist/components/WalletDerivationPathModal/index.d.ts.map +0 -1
  107. package/dist/components/WalletModal/WalletModal.d.ts +0 -4
  108. package/dist/components/WalletModal/WalletModal.d.ts.map +0 -1
  109. package/dist/components/WalletModal/WalletModal.types.d.ts +0 -10
  110. package/dist/components/WalletModal/WalletModal.types.d.ts.map +0 -1
  111. package/dist/components/WalletModal/WalletModalContent.d.ts +0 -4
  112. package/dist/components/WalletModal/WalletModalContent.d.ts.map +0 -1
  113. package/dist/components/WalletModal/index.d.ts +0 -2
  114. package/dist/components/WalletModal/index.d.ts.map +0 -1
  115. package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts +0 -4
  116. package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts.map +0 -1
  117. package/dist/components/WalletNamespacesModal/WalletNamespacesModal.styles.d.ts.map +0 -1
  118. package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts +0 -10
  119. package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts.map +0 -1
  120. package/dist/components/WalletNamespacesModal/index.d.ts +0 -2
  121. package/dist/components/WalletNamespacesModal/index.d.ts.map +0 -1
  122. package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.types.tsx +0 -10
  123. package/src/components/WalletDerivationPathModal/index.ts +0 -1
  124. package/src/components/WalletModal/WalletModal.tsx +0 -25
  125. package/src/components/WalletModal/WalletModal.types.ts +0 -11
  126. package/src/components/WalletModal/index.ts +0 -1
  127. package/src/components/WalletNamespacesModal/index.ts +0 -1
  128. /package/src/components/{WalletModal/WalletModalContent.styles.ts → WalletStatefulConnect/ConnectStatus.styles.ts} +0 -0
  129. /package/src/components/{WalletDerivationPathModal/WalletDerivationPathModal.styles.ts → WalletStatefulConnect/DerivationPath.styles.ts} +0 -0
  130. /package/src/components/{WalletNamespacesModal/WalletNamespacesModal.styles.ts → WalletStatefulConnect/Namespaces.styles.ts} +0 -0
@@ -1,33 +1,18 @@
1
1
  import type { WalletStateContentProps } from './SwapDetailsModal.types';
2
- import type { Namespace } from '@rango-dev/wallets-shared';
2
+ import type { WalletInfoWithExtra } from '../../types';
3
3
 
4
- import { debug } from '@rango-dev/logging-core';
4
+ import { warn } from '@rango-dev/logging-core';
5
5
  import { MessageBox, Wallet } from '@rango-dev/ui';
6
6
  import { useWallets } from '@rango-dev/wallets-react';
7
7
  import React, { useState } from 'react';
8
8
 
9
+ import { useWalletList } from '../../hooks/useWalletList';
9
10
  import { getContainer } from '../../utils/common';
10
11
  import { mapStatusToWalletState } from '../../utils/wallets';
11
- import { WalletDerivationPathModal } from '../WalletDerivationPathModal';
12
- import { WalletNamespacesModal } from '../WalletNamespacesModal';
12
+ import { StatefulConnectModal } from '../StatefulConnectModal';
13
13
 
14
14
  import { WalletContainer } from './SwapDetailsModal.styles';
15
15
 
16
- interface NamespacesModalState {
17
- open: boolean;
18
- providerType: string;
19
- providerImage: string;
20
- availableNamespaces?: Namespace[];
21
- singleNamespace?: boolean;
22
- }
23
-
24
- interface DerivationPathModalState {
25
- open: boolean;
26
- providerType: string;
27
- providerImage: string;
28
- namespace: Namespace;
29
- }
30
-
31
16
  export const WalletStateContent = (props: WalletStateContentProps) => {
32
17
  const {
33
18
  type,
@@ -37,11 +22,9 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
37
22
  showWalletButton,
38
23
  walletButtonDisabled,
39
24
  } = props;
40
- const { connect, getWalletInfo, state } = useWallets();
41
- const [namespacesModalState, setNamespacesModalState] =
42
- useState<NamespacesModalState | null>(null);
43
- const [derivationPathModalState, setDerivationPathModalState] =
44
- useState<DerivationPathModalState | null>(null);
25
+ const [selectedWalletToConnect, setSelectedWalletToConnect] =
26
+ useState<WalletInfoWithExtra>();
27
+ const { getWalletInfo, state } = useWallets();
45
28
  const walletType = currentStepWallet?.walletType;
46
29
  const walletState = walletType
47
30
  ? mapStatusToWalletState(state(walletType))
@@ -49,87 +32,24 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
49
32
  const walletInfo = walletType ? getWalletInfo(walletType) : null;
50
33
  const shouldShowWallet =
51
34
  showWalletButton && !!walletType && !!walletState && !!walletInfo;
52
-
53
- const handleCloseNamespaceModal = () => {
54
- if (namespacesModalState) {
55
- setNamespacesModalState({
56
- ...namespacesModalState,
57
- open: false,
58
- });
59
- }
60
- };
61
-
62
- const handleCloseDerivationPathModal = () => {
63
- if (derivationPathModalState) {
64
- setDerivationPathModalState({
65
- ...derivationPathModalState,
66
- open: false,
67
- });
68
- }
69
- };
35
+ const { list } = useWalletList();
70
36
 
71
37
  const handleWalletItemClick = () => {
72
- if (!!walletType && !!walletInfo) {
73
- if (!!walletInfo.namespaces?.length) {
74
- if (walletInfo.namespaces.length > 1) {
75
- setNamespacesModalState({
76
- open: true,
77
- providerType: walletType,
78
- providerImage: walletInfo.img,
79
- availableNamespaces: walletInfo.namespaces,
80
- singleNamespace: walletInfo.singleNamespace,
81
- });
82
- } else if (walletInfo.needsDerivationPath) {
83
- setDerivationPathModalState({
84
- open: true,
85
- providerType: walletType,
86
- providerImage: walletInfo.img,
87
- namespace: walletInfo.namespaces[0],
88
- });
89
- } else {
90
- connect(walletType).catch((error) => debug(error));
91
- }
38
+ if (!!walletType) {
39
+ const wallet = list.find((wallet) => wallet.type === walletType);
40
+
41
+ if (wallet) {
42
+ setSelectedWalletToConnect(wallet);
92
43
  } else {
93
- connect(walletType).catch((error) => debug(error));
44
+ warn(
45
+ new Error(
46
+ `It seems requested wallet to be connected is not available in the list. requested wallet: ${wallet}`
47
+ )
48
+ );
94
49
  }
95
50
  }
96
51
  };
97
52
 
98
- const handleConfirmNamespaces = (selectedNamespaces: Namespace[]) => {
99
- if (
100
- !!walletInfo?.needsDerivationPath &&
101
- walletInfo?.singleNamespace &&
102
- selectedNamespaces[0] &&
103
- walletType
104
- ) {
105
- setDerivationPathModalState({
106
- open: true,
107
- providerType: walletType,
108
- providerImage: walletInfo.img,
109
- namespace: selectedNamespaces[0],
110
- });
111
- } else {
112
- connect(
113
- namespacesModalState?.providerType as string,
114
- undefined,
115
- selectedNamespaces.map((namespace) => ({
116
- namespace,
117
- }))
118
- ).catch((error) => debug(error));
119
- }
120
- handleCloseNamespaceModal();
121
- };
122
-
123
- const handleDerivationPathConfirm = (derivationPath: string) => {
124
- if (derivationPath && derivationPathModalState?.namespace) {
125
- connect(derivationPathModalState?.providerType, undefined, [
126
- { namespace: derivationPathModalState.namespace, derivationPath },
127
- ]).catch((error) => debug(error));
128
- }
129
-
130
- handleCloseDerivationPathModal();
131
- };
132
-
133
53
  return (
134
54
  <>
135
55
  <MessageBox type={type} title={title} description={message} />
@@ -148,21 +68,11 @@ export const WalletStateContent = (props: WalletStateContentProps) => {
148
68
  />
149
69
  </WalletContainer>
150
70
  )}
151
- <WalletNamespacesModal
152
- open={!!namespacesModalState?.open}
153
- onClose={handleCloseNamespaceModal}
154
- onConfirm={handleConfirmNamespaces}
155
- image={namespacesModalState?.providerImage}
156
- availableNamespaces={namespacesModalState?.availableNamespaces}
157
- singleNamespace={namespacesModalState?.singleNamespace}
158
- />
159
- <WalletDerivationPathModal
160
- open={!!derivationPathModalState?.open}
161
- selectedNamespace={derivationPathModalState?.namespace}
162
- type={derivationPathModalState?.providerType}
163
- image={derivationPathModalState?.providerImage}
164
- onClose={handleCloseDerivationPathModal}
165
- onConfirm={handleDerivationPathConfirm}
71
+ <StatefulConnectModal
72
+ wallet={selectedWalletToConnect}
73
+ onClose={() => {
74
+ setSelectedWalletToConnect(undefined);
75
+ }}
166
76
  />
167
77
  </>
168
78
  );
@@ -1,18 +1,26 @@
1
- import type { ModalContentProps } from './WalletModal.types';
1
+ import type { ConnectStatusProps } from './ConnectStatus.types';
2
2
 
3
3
  import { i18n } from '@lingui/core';
4
4
  import { Image, MessageBox, WalletState } from '@rango-dev/ui';
5
+ import { useWallets } from '@rango-dev/wallets-react';
5
6
  import React from 'react';
6
7
 
8
+ import { mapStatusToWalletState } from '../../utils/wallets';
9
+
7
10
  import {
8
11
  LogoContainer,
9
12
  Spinner,
10
13
  WalletImageContainer,
11
- } from './WalletModalContent.styles';
14
+ } from './ConnectStatus.styles';
15
+
16
+ export function ConnectStatus(props: ConnectStatusProps) {
17
+ // See `wallet` notes on its type definition
18
+ const { wallet, error } = props;
19
+ const { type, image } = wallet;
20
+ const { state } = useWallets();
21
+ const walletState = mapStatusToWalletState(state(type));
12
22
 
13
- export function ModalContent(props: ModalContentProps) {
14
- const { state, image, error } = props;
15
- if (state === WalletState.CONNECTED) {
23
+ if (walletState === WalletState.CONNECTED) {
16
24
  return (
17
25
  <MessageBox
18
26
  type="success"
@@ -0,0 +1,11 @@
1
+ export interface ConnectStatusProps {
2
+ /*
3
+ * We can not use `WalletInfoWithExtra` because the inside state will be stale in some cases.
4
+ * We should directly use `useWallets` to make sure we have a correct state.
5
+ */
6
+ wallet: {
7
+ type: string;
8
+ image: string;
9
+ };
10
+ error?: string;
11
+ }
@@ -0,0 +1,23 @@
1
+ import type { DerivationPath, Namespace } from '@rango-dev/wallets-shared';
2
+
3
+ import { namespaces } from '@rango-dev/wallets-shared';
4
+
5
+ export const CUSTOM_DERIVATION_PATH: DerivationPath = {
6
+ id: 'custom',
7
+ label: 'Custom',
8
+ generateDerivationPath: (index: string) => index,
9
+ };
10
+
11
+ export function getDerivationPaths(
12
+ selectedNamespace?: Namespace
13
+ ): DerivationPath[] {
14
+ const selectedNamespaceDerivationPaths = selectedNamespace
15
+ ? namespaces[selectedNamespace].derivationPaths
16
+ : null;
17
+
18
+ const derivationPaths: DerivationPath[] = !!selectedNamespaceDerivationPaths
19
+ ? [...selectedNamespaceDerivationPaths, CUSTOM_DERIVATION_PATH]
20
+ : [];
21
+
22
+ return derivationPaths;
23
+ }
@@ -1,5 +1,5 @@
1
- import type { PropTypes } from './WalletDerivationPathModal.types';
2
- import type { DerivationPath, Namespace } from '@rango-dev/wallets-shared';
1
+ import type { PropTypes } from './DerivationPath.types';
2
+ import type { DerivationPath } from '@rango-dev/wallets-shared';
3
3
 
4
4
  import { i18n } from '@lingui/core';
5
5
  import {
@@ -10,43 +10,30 @@ import {
10
10
  Select,
11
11
  TextField,
12
12
  } from '@rango-dev/ui';
13
- import { namespaces } from '@rango-dev/wallets-shared';
14
13
  import React, { useEffect, useState } from 'react';
15
14
 
16
- import { WIDGET_UI_ID } from '../../constants';
17
- import { WatermarkedModal } from '../common/WatermarkedModal';
18
15
  import {
19
16
  LogoContainer,
20
17
  Spinner,
21
18
  WalletImageContainer,
22
- } from '../WalletModal/WalletModalContent.styles';
23
-
19
+ } from './ConnectStatus.styles';
20
+ import {
21
+ CUSTOM_DERIVATION_PATH,
22
+ getDerivationPaths,
23
+ } from './DerivationPath.helpers';
24
24
  import {
25
25
  derivationPathInputStyles,
26
26
  InputLabel,
27
27
  InputsContainer,
28
- } from './WalletDerivationPathModal.styles';
29
-
30
- const customDerivationPath: DerivationPath = {
31
- id: 'custom',
32
- label: 'Custom',
33
- generateDerivationPath: (index: string) => index,
34
- };
35
-
36
- function getDerivationPaths(selectedNamespace?: Namespace) {
37
- const selectedNamespaceDerivationPaths = selectedNamespace
38
- ? namespaces[selectedNamespace].derivationPaths
39
- : null;
40
-
41
- const derivationPaths: DerivationPath[] = !!selectedNamespaceDerivationPaths
42
- ? [...selectedNamespaceDerivationPaths, customDerivationPath]
43
- : [];
44
-
45
- return derivationPaths;
46
- }
28
+ } from './DerivationPath.styles';
47
29
 
48
- export function WalletDerivationPathModal(props: PropTypes) {
49
- const { onClose, onConfirm, selectedNamespace, image, type, open } = props;
30
+ export function DerivationPath(props: PropTypes) {
31
+ const { onConfirm } = props;
32
+ const {
33
+ namespace: selectedNamespace,
34
+ providerImage: image,
35
+ providerType: type,
36
+ } = props.value;
50
37
 
51
38
  const [selectedDerivationPathId, setSelectedDerivationPathId] = useState<
52
39
  string | null
@@ -54,7 +41,7 @@ export function WalletDerivationPathModal(props: PropTypes) {
54
41
  const [derivationPathIndex, setDerivationPathIndex] = useState('0');
55
42
 
56
43
  const isCustomOptionSelected =
57
- selectedDerivationPathId === customDerivationPath.id;
44
+ selectedDerivationPathId === CUSTOM_DERIVATION_PATH.id;
58
45
 
59
46
  const derivationPaths = getDerivationPaths(selectedNamespace);
60
47
 
@@ -89,12 +76,7 @@ export function WalletDerivationPathModal(props: PropTypes) {
89
76
  }, [selectedNamespace]);
90
77
 
91
78
  return (
92
- <WatermarkedModal
93
- open={open}
94
- onClose={onClose}
95
- container={
96
- document.getElementById(WIDGET_UI_ID.SWAP_BOX_ID) || document.body
97
- }>
79
+ <>
98
80
  <Divider size={20} />
99
81
  <MessageBox
100
82
  type="info"
@@ -149,6 +131,6 @@ export function WalletDerivationPathModal(props: PropTypes) {
149
131
  }>
150
132
  {i18n.t('Confirm')}
151
133
  </Button>
152
- </WatermarkedModal>
134
+ </>
153
135
  );
154
136
  }
@@ -0,0 +1,6 @@
1
+ import type { NeedsDerivationPathState } from '../../hooks/useStatefulConnect';
2
+
3
+ export interface PropTypes {
4
+ value: NeedsDerivationPathState;
5
+ onConfirm: (path: string) => void;
6
+ }
@@ -0,0 +1,36 @@
1
+ import { i18n } from '@lingui/core';
2
+ import { Button, Divider, MessageBox } from '@rango-dev/ui';
3
+ import React from 'react';
4
+
5
+ interface PropTypes {
6
+ displayName?: string;
7
+ onConfirm: () => void;
8
+ }
9
+
10
+ export function ExperimentalChain(props: PropTypes) {
11
+ const { displayName, onConfirm } = props;
12
+
13
+ return (
14
+ <MessageBox
15
+ title={i18n.t({
16
+ id: 'Add {blockchainDisplayName} Chain',
17
+ values: { blockchainDisplayName: displayName },
18
+ })}
19
+ type="warning"
20
+ description={i18n.t({
21
+ id: 'You should connect a {blockchainDisplayName} supported wallet or choose a different {blockchainDisplayName} address',
22
+ values: { blockchainDisplayName: displayName },
23
+ })}>
24
+ <Divider size={18} />
25
+ <Divider size={32} />
26
+ <Button
27
+ onClick={onConfirm}
28
+ variant="outlined"
29
+ type="primary"
30
+ fullWidth
31
+ size="large">
32
+ {i18n.t('Confirm')}
33
+ </Button>
34
+ </MessageBox>
35
+ );
36
+ }
@@ -0,0 +1,53 @@
1
+ import type { PropTypes } from './ExperimentalChainStatus.types';
2
+ import type { MessageType } from '@rango-dev/ui';
3
+
4
+ import { i18n } from '@lingui/core';
5
+
6
+ export function generateMessageByStatus(
7
+ status: PropTypes['status'],
8
+ blockchainDisplayName: string | undefined
9
+ ): {
10
+ type: MessageType;
11
+ title: string;
12
+ description: string;
13
+ } {
14
+ switch (status) {
15
+ case 'in-progress':
16
+ return {
17
+ type: 'loading',
18
+ title: i18n.t({
19
+ id: 'Add {blockchainDisplayName} Chain',
20
+ values: { blockchainDisplayName },
21
+ }),
22
+ description: i18n.t({
23
+ id: 'You should connect a {blockchainDisplayName} supported wallet or choose a different {blockchainDisplayName} address',
24
+ values: { blockchainDisplayName },
25
+ }),
26
+ };
27
+ case 'completed':
28
+ return {
29
+ type: 'success',
30
+ title: i18n.t({
31
+ id: '{blockchainDisplayName} Chain Added',
32
+ values: { blockchainDisplayName },
33
+ }),
34
+ description: i18n.t({
35
+ id: 'You should connect a {blockchainDisplayName} supported wallet or choose a different {blockchainDisplayName} address',
36
+ values: { blockchainDisplayName },
37
+ }),
38
+ };
39
+ case 'rejected':
40
+ return {
41
+ type: 'error',
42
+ title: i18n.t('Request Rejected'),
43
+ description: i18n.t({
44
+ id: "You've rejected adding {blockchainDisplayName} chain to your wallet.",
45
+ values: { blockchainDisplayName },
46
+ }),
47
+ };
48
+ default:
49
+ throw new Error(
50
+ `Showing information about an experimentation chain status needs to be defined first. status: ${status}`
51
+ );
52
+ }
53
+ }
@@ -0,0 +1,35 @@
1
+ import type { PropTypes } from './ExperimentalChainStatus.types';
2
+
3
+ import { Image, MessageBox, Spinner } from '@rango-dev/ui';
4
+ import React from 'react';
5
+
6
+ import {
7
+ LogoContainer,
8
+ WalletImageContainer,
9
+ } from '../ConfirmWalletsModal/WalletList.styles';
10
+
11
+ import { generateMessageByStatus } from './ExperimentalChainStatus.helpers';
12
+
13
+ export function ExperimentalChainStatus(props: PropTypes) {
14
+ const { status, displayName, image } = props;
15
+ const data = generateMessageByStatus(status, displayName);
16
+ const hasImage = status == 'in-progress';
17
+
18
+ return (
19
+ <MessageBox
20
+ type={data.type}
21
+ title={data.title}
22
+ description={data.description}
23
+ icon={
24
+ hasImage ? (
25
+ <LogoContainer>
26
+ <WalletImageContainer>
27
+ <Image src={image} size={45} />
28
+ </WalletImageContainer>
29
+ <Spinner />
30
+ </LogoContainer>
31
+ ) : undefined
32
+ }
33
+ />
34
+ );
35
+ }
@@ -0,0 +1,5 @@
1
+ export interface PropTypes {
2
+ displayName?: string;
3
+ status: 'in-progress' | 'completed' | 'rejected';
4
+ image: string;
5
+ }
@@ -0,0 +1,9 @@
1
+ import type { BlockchainMeta } from 'rango-types';
2
+
3
+ export function getBlockchainLogo(
4
+ blockchains: BlockchainMeta[],
5
+ blockchainName: string
6
+ ) {
7
+ return blockchains.find((blockchain) => blockchain.name === blockchainName)
8
+ ?.logo;
9
+ }
@@ -1,6 +1,5 @@
1
- import type { PropTypes } from './WalletNamespacesModal.types';
1
+ import type { PropTypes } from './Namespaces.types';
2
2
  import type { Namespace } from '@rango-dev/wallets-shared';
3
- import type { BlockchainMeta } from 'rango-sdk';
4
3
 
5
4
  import { i18n } from '@lingui/core';
6
5
  import {
@@ -16,27 +15,15 @@ import {
16
15
  import { namespaces } from '@rango-dev/wallets-shared';
17
16
  import React, { useMemo, useState } from 'react';
18
17
 
19
- import { WIDGET_UI_ID } from '../../constants';
20
18
  import { useAppStore } from '../../store/AppStore';
21
- import { WatermarkedModal } from '../common/WatermarkedModal';
22
19
  import { WalletImageContainer } from '../HeaderButtons/HeaderButtons.styles';
23
- import {
24
- LogoContainer,
25
- Spinner,
26
- } from '../WalletModal/WalletModalContent.styles';
27
-
28
- import { NamespaceList } from './WalletNamespacesModal.styles';
29
20
 
30
- const getBlockchainLogo = (
31
- blockchains: BlockchainMeta[],
32
- blockchainName: string
33
- ) => {
34
- return blockchains.find((blockchain) => blockchain.name === blockchainName)
35
- ?.logo;
36
- };
21
+ import { LogoContainer, Spinner } from './ConnectStatus.styles';
22
+ import { getBlockchainLogo } from './Namespaces.helpers';
23
+ import { NamespaceList } from './Namespaces.styles';
37
24
 
38
- export function WalletNamespacesModal(props: PropTypes) {
39
- const { singleNamespace, availableNamespaces } = props;
25
+ export function Namespaces(props: PropTypes) {
26
+ const { singleNamespace, availableNamespaces, providerImage } = props.value;
40
27
 
41
28
  const [selectedNamespaces, setSelectedNamespaces] = useState<Namespace[]>([]);
42
29
 
@@ -76,12 +63,7 @@ export function WalletNamespacesModal(props: PropTypes) {
76
63
  };
77
64
 
78
65
  return (
79
- <WatermarkedModal
80
- open={props.open}
81
- onClose={props.onClose}
82
- container={
83
- document.getElementById(WIDGET_UI_ID.SWAP_BOX_ID) || document.body
84
- }>
66
+ <>
85
67
  <Divider size={20} />
86
68
  <MessageBox
87
69
  type="info"
@@ -92,7 +74,7 @@ export function WalletNamespacesModal(props: PropTypes) {
92
74
  icon={
93
75
  <LogoContainer>
94
76
  <WalletImageContainer>
95
- <Image src={props.image} size={45} />
77
+ <Image src={providerImage} size={45} />
96
78
  </WalletImageContainer>
97
79
  <Spinner />
98
80
  </LogoContainer>
@@ -132,6 +114,6 @@ export function WalletNamespacesModal(props: PropTypes) {
132
114
  onClick={() => props.onConfirm(selectedNamespaces)}>
133
115
  {i18n.t('Confirm')}
134
116
  </Button>
135
- </WatermarkedModal>
117
+ </>
136
118
  );
137
119
  }
@@ -1,10 +1,7 @@
1
+ import type { NeedsNamespacesState } from '../../hooks/useStatefulConnect';
1
2
  import type { Namespace } from '@rango-dev/wallets-shared';
2
3
 
3
4
  export interface PropTypes {
4
- open: boolean;
5
- image?: string;
6
- onClose: () => void;
7
5
  onConfirm: (namespaces: Namespace[]) => void;
8
- availableNamespaces?: Namespace[];
9
- singleNamespace?: boolean;
6
+ value: NeedsNamespacesState;
10
7
  }
@@ -0,0 +1,4 @@
1
+ export { Namespaces } from './Namespaces';
2
+ export { DerivationPath } from './DerivationPath';
3
+ export { ConnectStatus } from './ConnectStatus';
4
+ export { ExperimentalChain } from './ExperimentalChain';
@@ -4,7 +4,7 @@ import type {
4
4
  WidgetContextInterface,
5
5
  } from './Wallets.types';
6
6
  import type { ProvidersOptions } from '../../utils/providers';
7
- import type { EventHandler } from '@rango-dev/wallets-react';
7
+ import type { LegacyEventHandler as EventHandler } from '@rango-dev/wallets-core/legacy';
8
8
  import type { PropsWithChildren } from 'react';
9
9
 
10
10
  import { Events, Provider } from '@rango-dev/wallets-react';
@@ -1,5 +1,5 @@
1
1
  import type { WidgetConfig } from '../../types';
2
- import type { EventHandler } from '@rango-dev/wallets-react';
2
+ import type { LegacyEventHandler as EventHandler } from '@rango-dev/wallets-core/legacy';
3
3
 
4
4
  export type OnWalletConnectionChange = (key: string) => void;
5
5
  export interface WidgetContextInterface {
@@ -1,5 +1,5 @@
1
1
  import type { WidgetConfig } from '../../types';
2
- import type { EventHandler } from '@rango-dev/wallets-react';
2
+ import type { LegacyEventHandler as EventHandler } from '@rango-dev/wallets-core/legacy';
3
3
 
4
4
  export type PropTypes = {
5
5
  onUpdateState?: EventHandler;
@@ -0,0 +1,9 @@
1
+ export { useStatefulConnect } from './useStatefulConnect';
2
+ export { ResultStatus } from './useStatefulConnect.types';
3
+ export type {
4
+ NeedsNamespacesState,
5
+ NeedsDerivationPathState,
6
+ Result,
7
+ } from './useStatefulConnect.types';
8
+
9
+ export type { State } from './useStatefulConnect.state';
@@ -0,0 +1,13 @@
1
+ import type { State } from './useStatefulConnect.state';
2
+
3
+ export function isStateOnDerivationPathStep(
4
+ state: State
5
+ ): state is State & { derivationPath: NonNullable<State['derivationPath']> } {
6
+ return !!state.derivationPath;
7
+ }
8
+
9
+ export function isStateOnNamespace(
10
+ state: State
11
+ ): state is State & { namespace: NonNullable<State['namespace']> } {
12
+ return !!state.namespace;
13
+ }