@rango-dev/widget-embedded 0.31.1-next.2 → 0.31.1-next.4
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.
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts +11 -0
- package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts.map +1 -0
- package/dist/components/StatefulConnectModal/helpers.d.ts +10 -0
- package/dist/components/StatefulConnectModal/helpers.d.ts.map +1 -0
- package/dist/components/StatefulConnectModal/index.d.ts +2 -0
- package/dist/components/StatefulConnectModal/index.d.ts.map +1 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
- package/dist/components/WalletStatefulConnect/ConnectStatus.d.ts +4 -0
- package/dist/components/WalletStatefulConnect/ConnectStatus.d.ts.map +1 -0
- package/dist/components/{WalletModal/WalletModalContent.styles.d.ts → WalletStatefulConnect/ConnectStatus.styles.d.ts} +1 -1
- package/dist/components/{WalletModal/WalletModalContent.styles.d.ts.map → WalletStatefulConnect/ConnectStatus.styles.d.ts.map} +1 -1
- package/dist/components/WalletStatefulConnect/ConnectStatus.types.d.ts +8 -0
- package/dist/components/WalletStatefulConnect/ConnectStatus.types.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.d.ts +4 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +4 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -0
- package/dist/components/{WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts → WalletStatefulConnect/DerivationPath.styles.d.ts} +1 -1
- package/dist/components/WalletStatefulConnect/DerivationPath.styles.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.types.d.ts +6 -0
- package/dist/components/WalletStatefulConnect/DerivationPath.types.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChain.d.ts +8 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChain.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.d.ts +4 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.helpers.d.ts +8 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.helpers.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.types.d.ts +6 -0
- package/dist/components/WalletStatefulConnect/ExperimentalChainStatus.types.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/Namespaces.d.ts +4 -0
- package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/Namespaces.helpers.d.ts +3 -0
- package/dist/components/WalletStatefulConnect/Namespaces.helpers.d.ts.map +1 -0
- package/dist/components/{WalletNamespacesModal/WalletNamespacesModal.styles.d.ts → WalletStatefulConnect/Namespaces.styles.d.ts} +1 -1
- package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +7 -0
- package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -0
- package/dist/components/WalletStatefulConnect/index.d.ts +5 -0
- package/dist/components/WalletStatefulConnect/index.d.ts.map +1 -0
- package/dist/containers/Wallets/Wallets.types.d.ts +1 -1
- package/dist/containers/Wallets/Wallets.types.d.ts.map +1 -1
- package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts +1 -1
- package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/index.d.ts +5 -0
- package/dist/hooks/useStatefulConnect/index.d.ts.map +1 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +25 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.helpers.d.ts +8 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.helpers.d.ts.map +1 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.state.d.ts +9 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.state.d.ts.map +1 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +43 -0
- package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -0
- package/dist/hooks/useWalletList.d.ts +11 -14
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/pages/WalletsPage.d.ts +0 -2
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +7 -6
- package/src/components/ConfirmWalletsModal/WalletList.tsx +52 -243
- package/src/components/HeaderButtons/WalletButton.tsx +1 -1
- package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +168 -0
- package/src/components/StatefulConnectModal/helpers.ts +23 -0
- package/src/components/StatefulConnectModal/index.ts +1 -0
- package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +23 -113
- package/src/components/{WalletModal/WalletModalContent.tsx → WalletStatefulConnect/ConnectStatus.tsx} +13 -5
- package/src/components/WalletStatefulConnect/ConnectStatus.types.ts +11 -0
- package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +23 -0
- package/src/components/{WalletDerivationPathModal/WalletDerivationPathModal.tsx → WalletStatefulConnect/DerivationPath.tsx} +18 -36
- package/src/components/WalletStatefulConnect/DerivationPath.types.ts +6 -0
- package/src/components/WalletStatefulConnect/ExperimentalChain.tsx +36 -0
- package/src/components/WalletStatefulConnect/ExperimentalChainStatus.helpers.ts +53 -0
- package/src/components/WalletStatefulConnect/ExperimentalChainStatus.tsx +35 -0
- package/src/components/WalletStatefulConnect/ExperimentalChainStatus.types.ts +5 -0
- package/src/components/WalletStatefulConnect/Namespaces.helpers.ts +9 -0
- package/src/components/{WalletNamespacesModal/WalletNamespacesModal.tsx → WalletStatefulConnect/Namespaces.tsx} +9 -27
- package/src/components/{WalletNamespacesModal/WalletNamespacesModal.types.tsx → WalletStatefulConnect/Namespaces.types.tsx} +2 -5
- package/src/components/WalletStatefulConnect/index.ts +4 -0
- package/src/containers/Wallets/Wallets.tsx +1 -1
- package/src/containers/Wallets/Wallets.types.ts +1 -1
- package/src/containers/WidgetProvider/WidgetProvider.types.ts +1 -1
- package/src/hooks/useStatefulConnect/index.ts +9 -0
- package/src/hooks/useStatefulConnect/useStatefulConnect.helpers.ts +13 -0
- package/src/hooks/useStatefulConnect/useStatefulConnect.state.ts +45 -0
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +232 -0
- package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +56 -0
- package/src/hooks/useWalletList.ts +22 -53
- package/src/index.ts +5 -8
- package/src/pages/WalletsPage.tsx +10 -162
- package/src/utils/wallets.ts +1 -1
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts +0 -4
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts.map +0 -1
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts.map +0 -1
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts +0 -10
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts.map +0 -1
- package/dist/components/WalletDerivationPathModal/index.d.ts +0 -2
- package/dist/components/WalletDerivationPathModal/index.d.ts.map +0 -1
- package/dist/components/WalletModal/WalletModal.d.ts +0 -4
- package/dist/components/WalletModal/WalletModal.d.ts.map +0 -1
- package/dist/components/WalletModal/WalletModal.types.d.ts +0 -10
- package/dist/components/WalletModal/WalletModal.types.d.ts.map +0 -1
- package/dist/components/WalletModal/WalletModalContent.d.ts +0 -4
- package/dist/components/WalletModal/WalletModalContent.d.ts.map +0 -1
- package/dist/components/WalletModal/index.d.ts +0 -2
- package/dist/components/WalletModal/index.d.ts.map +0 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts +0 -4
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts.map +0 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.styles.d.ts.map +0 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts +0 -10
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts.map +0 -1
- package/dist/components/WalletNamespacesModal/index.d.ts +0 -2
- package/dist/components/WalletNamespacesModal/index.d.ts.map +0 -1
- package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.types.tsx +0 -10
- package/src/components/WalletDerivationPathModal/index.ts +0 -1
- package/src/components/WalletModal/WalletModal.tsx +0 -25
- package/src/components/WalletModal/WalletModal.types.ts +0 -11
- package/src/components/WalletModal/index.ts +0 -1
- package/src/components/WalletNamespacesModal/index.ts +0 -1
- /package/src/components/{WalletModal/WalletModalContent.styles.ts → WalletStatefulConnect/ConnectStatus.styles.ts} +0 -0
- /package/src/components/{WalletDerivationPathModal/WalletDerivationPathModal.styles.ts → WalletStatefulConnect/DerivationPath.styles.ts} +0 -0
- /package/src/components/{WalletNamespacesModal/WalletNamespacesModal.styles.ts → WalletStatefulConnect/Namespaces.styles.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.31.1-next.
|
|
3
|
+
"version": "0.31.1-next.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -25,14 +25,15 @@
|
|
|
25
25
|
"@lingui/core": "4.2.1",
|
|
26
26
|
"@lingui/react": "4.2.1",
|
|
27
27
|
"@rango-dev/logging-core": "^0.6.0",
|
|
28
|
-
"@rango-dev/provider-all": "^0.36.1-next.
|
|
28
|
+
"@rango-dev/provider-all": "^0.36.1-next.1",
|
|
29
29
|
"@rango-dev/queue-manager-core": "^0.27.0",
|
|
30
|
-
"@rango-dev/queue-manager-rango-preset": "^0.36.0",
|
|
30
|
+
"@rango-dev/queue-manager-rango-preset": "^0.36.1-next.0",
|
|
31
31
|
"@rango-dev/queue-manager-react": "^0.27.0",
|
|
32
32
|
"@rango-dev/signer-solana": "^0.31.1-next.0",
|
|
33
|
-
"@rango-dev/ui": "^0.37.1-next.
|
|
34
|
-
"@rango-dev/wallets-
|
|
35
|
-
"@rango-dev/wallets-
|
|
33
|
+
"@rango-dev/ui": "^0.37.1-next.2",
|
|
34
|
+
"@rango-dev/wallets-core": "^0.37.1-next.0",
|
|
35
|
+
"@rango-dev/wallets-react": "^0.22.1-next.0",
|
|
36
|
+
"@rango-dev/wallets-shared": "^0.36.1-next.0",
|
|
36
37
|
"bignumber.js": "^9.1.1",
|
|
37
38
|
"copy-to-clipboard": "^3.3.3",
|
|
38
39
|
"dayjs": "^1.11.7",
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import type { PropTypes } from './WalletList.type';
|
|
2
2
|
import type { Wallet, WalletInfoWithExtra } from '../../types';
|
|
3
|
-
import type { Namespace, WalletType } from '@rango-dev/wallets-shared';
|
|
4
3
|
|
|
5
4
|
import { i18n } from '@lingui/core';
|
|
5
|
+
import { warn } from '@rango-dev/logging-core';
|
|
6
6
|
import {
|
|
7
|
-
Button,
|
|
8
7
|
Divider,
|
|
9
|
-
Image,
|
|
10
|
-
MessageBox,
|
|
11
8
|
SelectableWallet,
|
|
12
9
|
Typography,
|
|
13
10
|
WalletState,
|
|
@@ -16,11 +13,11 @@ import React, { useEffect, useState } from 'react';
|
|
|
16
13
|
|
|
17
14
|
import { useWallets } from '../..';
|
|
18
15
|
import { WIDGET_UI_ID } from '../../constants';
|
|
19
|
-
import { useWalletList } from '../../hooks/useWalletList';
|
|
20
16
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} from '../../
|
|
17
|
+
ResultStatus,
|
|
18
|
+
useStatefulConnect,
|
|
19
|
+
} from '../../hooks/useStatefulConnect';
|
|
20
|
+
import { useWalletList } from '../../hooks/useWalletList';
|
|
24
21
|
import { useAppStore } from '../../store/AppStore';
|
|
25
22
|
import { useUiStore } from '../../store/ui';
|
|
26
23
|
import { useWalletsStore } from '../../store/wallets';
|
|
@@ -31,77 +28,35 @@ import {
|
|
|
31
28
|
isExperimentalChain,
|
|
32
29
|
} from '../../utils/wallets';
|
|
33
30
|
import { WatermarkedModal } from '../common/WatermarkedModal';
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
31
|
+
import { StatefulConnectModal } from '../StatefulConnectModal';
|
|
32
|
+
import { ExperimentalChain } from '../WalletStatefulConnect';
|
|
33
|
+
import { ExperimentalChainStatus } from '../WalletStatefulConnect/ExperimentalChainStatus';
|
|
37
34
|
|
|
38
35
|
import { ShowMoreWallets } from './ConfirmWallets.styles';
|
|
39
|
-
import {
|
|
40
|
-
LogoContainer,
|
|
41
|
-
Spinner,
|
|
42
|
-
WalletImageContainer,
|
|
43
|
-
} from './WalletList.styles';
|
|
44
|
-
|
|
45
|
-
interface WalletNamespacesModalState {
|
|
46
|
-
open: boolean;
|
|
47
|
-
providerType: string;
|
|
48
|
-
providerImage: string;
|
|
49
|
-
availableNamespaces?: Namespace[];
|
|
50
|
-
singleNamespace?: boolean;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
interface DerivationPathModalState {
|
|
54
|
-
open: boolean;
|
|
55
|
-
providerType: string;
|
|
56
|
-
providerImage: string;
|
|
57
|
-
namespace: Namespace;
|
|
58
|
-
}
|
|
59
36
|
|
|
60
37
|
const ACCOUNT_ADDRESS_MAX_CHARACTERS = 7;
|
|
38
|
+
const TIME_TO_CLOSE_MODAL = 3_000;
|
|
39
|
+
|
|
61
40
|
export function WalletList(props: PropTypes) {
|
|
62
|
-
const { chain, isSelected, selectWallet, limit, onShowMore
|
|
63
|
-
props;
|
|
41
|
+
const { chain, isSelected, selectWallet, limit, onShowMore } = props;
|
|
64
42
|
const isActiveTab = useUiStore.use.isActiveTab();
|
|
65
43
|
|
|
66
44
|
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
67
45
|
const { blockchains } = useAppStore();
|
|
68
|
-
const [
|
|
69
|
-
useState<
|
|
46
|
+
const [selectedWalletToConnect, setSelectedWalletToConnect] =
|
|
47
|
+
useState<WalletInfoWithExtra>();
|
|
70
48
|
const [experimentalChainWallet, setExperimentalChainWallet] =
|
|
71
49
|
useState<Wallet | null>(null);
|
|
72
50
|
const [showExperimentalChainModal, setShowExperimentalChainModal] =
|
|
73
51
|
useState(false);
|
|
74
52
|
const [addingExperimentalChainStatus, setAddingExperimentalChainStatus] =
|
|
75
53
|
useState<'in-progress' | 'completed' | 'rejected' | null>(null);
|
|
76
|
-
const [namespacesModalState, setNamespacesModalState] =
|
|
77
|
-
useState<WalletNamespacesModalState | null>(null);
|
|
78
|
-
const [derivationPathModalState, setDerivationPathModalState] =
|
|
79
|
-
useState<DerivationPathModalState | null>(null);
|
|
80
54
|
const { suggestAndConnect } = useWallets();
|
|
81
|
-
|
|
82
|
-
const {
|
|
83
|
-
list,
|
|
84
|
-
error,
|
|
85
|
-
handleClick,
|
|
86
|
-
disconnectWallet,
|
|
87
|
-
disconnectConnectingWallets,
|
|
88
|
-
} = useWalletList({
|
|
55
|
+
const { handleDisconnect } = useStatefulConnect();
|
|
56
|
+
const { list } = useWalletList({
|
|
89
57
|
chain,
|
|
90
|
-
onBeforeConnect: (type) => {
|
|
91
|
-
modalTimerId = setTimeout(() => {
|
|
92
|
-
setOpenWalletStateModal(type);
|
|
93
|
-
}, TIME_TO_IGNORE_MODAL);
|
|
94
|
-
},
|
|
95
|
-
onConnect: (type) => {
|
|
96
|
-
onConnect?.(type);
|
|
97
|
-
if (modalTimerId) {
|
|
98
|
-
clearTimeout(modalTimerId);
|
|
99
|
-
}
|
|
100
|
-
setTimeout(() => {
|
|
101
|
-
setOpenWalletStateModal('');
|
|
102
|
-
}, TIME_TO_CLOSE_MODAL);
|
|
103
|
-
},
|
|
104
58
|
});
|
|
59
|
+
|
|
105
60
|
const [sortedList, setSortedList] = useState<WalletInfoWithExtra[]>(list);
|
|
106
61
|
const numberOfSupportedWallets = list.length;
|
|
107
62
|
const shouldShowMoreWallets = limit && numberOfSupportedWallets - limit > 0;
|
|
@@ -117,70 +72,6 @@ export function WalletList(props: PropTypes) {
|
|
|
117
72
|
}
|
|
118
73
|
};
|
|
119
74
|
|
|
120
|
-
const handleCloseNamespaceModal = () => {
|
|
121
|
-
if (namespacesModalState) {
|
|
122
|
-
setNamespacesModalState({
|
|
123
|
-
...namespacesModalState,
|
|
124
|
-
open: false,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const handleCloseDerivationPathModal = () => {
|
|
130
|
-
if (derivationPathModalState) {
|
|
131
|
-
setDerivationPathModalState({
|
|
132
|
-
...derivationPathModalState,
|
|
133
|
-
open: false,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const handleOpenNamespacesModal = (wallet: WalletInfoWithExtra) => {
|
|
139
|
-
setNamespacesModalState({
|
|
140
|
-
open: true,
|
|
141
|
-
providerType: wallet.type,
|
|
142
|
-
providerImage: wallet.image,
|
|
143
|
-
availableNamespaces: wallet.namespaces,
|
|
144
|
-
singleNamespace: wallet.singleNamespace,
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const handleConfirmNamespaces = (selectedNamespaces: Namespace[]) => {
|
|
149
|
-
const wallet = sortedList.find(
|
|
150
|
-
(wallet) => wallet.type === namespacesModalState?.providerType
|
|
151
|
-
);
|
|
152
|
-
if (
|
|
153
|
-
wallet?.singleNamespace && // Currently we support derivation path only for single namespace wallets
|
|
154
|
-
wallet?.needsDerivationPath &&
|
|
155
|
-
selectedNamespaces[0]
|
|
156
|
-
) {
|
|
157
|
-
setDerivationPathModalState({
|
|
158
|
-
open: true,
|
|
159
|
-
providerType: wallet.type,
|
|
160
|
-
providerImage: wallet.image,
|
|
161
|
-
namespace: selectedNamespaces[0],
|
|
162
|
-
});
|
|
163
|
-
} else {
|
|
164
|
-
void handleClick(
|
|
165
|
-
namespacesModalState?.providerType as string,
|
|
166
|
-
selectedNamespaces.map((namespace) => ({
|
|
167
|
-
namespace,
|
|
168
|
-
}))
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
handleCloseNamespaceModal();
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
const handleDerivationPathConfirm = (derivationPath: string) => {
|
|
175
|
-
if (derivationPath && derivationPathModalState?.namespace) {
|
|
176
|
-
void handleClick(derivationPathModalState.providerType, [
|
|
177
|
-
{ namespace: derivationPathModalState.namespace, derivationPath },
|
|
178
|
-
]);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
handleCloseDerivationPathModal();
|
|
182
|
-
};
|
|
183
|
-
|
|
184
75
|
useEffect(() => {
|
|
185
76
|
setSortedList((sortedList) => {
|
|
186
77
|
const selectedWalletIndex = list.findIndex((wallet) =>
|
|
@@ -223,11 +114,6 @@ export function WalletList(props: PropTypes) {
|
|
|
223
114
|
};
|
|
224
115
|
}, [addingExperimentalChainStatus]);
|
|
225
116
|
|
|
226
|
-
const handleCloseWalletModal = () => {
|
|
227
|
-
disconnectConnectingWallets();
|
|
228
|
-
setOpenWalletStateModal('');
|
|
229
|
-
};
|
|
230
|
-
|
|
231
117
|
return (
|
|
232
118
|
<>
|
|
233
119
|
{sortedList.slice(0, limit).map((wallet) => {
|
|
@@ -261,27 +147,14 @@ export function WalletList(props: PropTypes) {
|
|
|
261
147
|
: conciseAddress;
|
|
262
148
|
|
|
263
149
|
const onSelectableWalletClick = async () => {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
handleOpenNamespacesModal(wallet);
|
|
268
|
-
} else if (wallet.needsDerivationPath) {
|
|
269
|
-
setDerivationPathModalState({
|
|
270
|
-
open: true,
|
|
271
|
-
providerType: wallet.type,
|
|
272
|
-
providerImage: wallet.image,
|
|
273
|
-
namespace: wallet.namespaces[0],
|
|
274
|
-
});
|
|
275
|
-
} else {
|
|
276
|
-
void handleClick(wallet.type);
|
|
277
|
-
}
|
|
278
|
-
} else {
|
|
279
|
-
void handleClick(wallet.type);
|
|
280
|
-
}
|
|
150
|
+
const isDisconnected = wallet.state === WalletState.DISCONNECTED;
|
|
151
|
+
if (isDisconnected) {
|
|
152
|
+
setSelectedWalletToConnect(wallet);
|
|
281
153
|
} else if (!!wallet.namespaces && !conciseAddress) {
|
|
282
154
|
// wallet is connected on a different namespace
|
|
283
|
-
await
|
|
284
|
-
|
|
155
|
+
await handleDisconnect(wallet.type);
|
|
156
|
+
|
|
157
|
+
setSelectedWalletToConnect(wallet);
|
|
285
158
|
} else if (couldAddExperimentalChain) {
|
|
286
159
|
setExperimentalChainWallet({
|
|
287
160
|
walletType: wallet.type,
|
|
@@ -307,29 +180,6 @@ export function WalletList(props: PropTypes) {
|
|
|
307
180
|
: undefined;
|
|
308
181
|
return (
|
|
309
182
|
<React.Fragment key={`${wallet.title}_${blockchainDisplayName}`}>
|
|
310
|
-
<WalletModal
|
|
311
|
-
open={openWalletStateModal === wallet.type}
|
|
312
|
-
onClose={handleCloseWalletModal}
|
|
313
|
-
image={wallet.image}
|
|
314
|
-
state={wallet.state}
|
|
315
|
-
error={error}
|
|
316
|
-
/>
|
|
317
|
-
<WalletNamespacesModal
|
|
318
|
-
open={!!namespacesModalState?.open}
|
|
319
|
-
onClose={handleCloseNamespaceModal}
|
|
320
|
-
onConfirm={handleConfirmNamespaces}
|
|
321
|
-
image={namespacesModalState?.providerImage}
|
|
322
|
-
availableNamespaces={namespacesModalState?.availableNamespaces}
|
|
323
|
-
singleNamespace={namespacesModalState?.singleNamespace}
|
|
324
|
-
/>
|
|
325
|
-
<WalletDerivationPathModal
|
|
326
|
-
open={!!derivationPathModalState?.open}
|
|
327
|
-
selectedNamespace={derivationPathModalState?.namespace}
|
|
328
|
-
type={derivationPathModalState?.providerType}
|
|
329
|
-
image={derivationPathModalState?.providerImage}
|
|
330
|
-
onClose={handleCloseDerivationPathModal}
|
|
331
|
-
onConfirm={handleDerivationPathConfirm}
|
|
332
|
-
/>
|
|
333
183
|
{!!experimentalChainWallet && (
|
|
334
184
|
<WatermarkedModal
|
|
335
185
|
open={!!experimentalChainWallet && showExperimentalChainModal}
|
|
@@ -337,30 +187,12 @@ export function WalletList(props: PropTypes) {
|
|
|
337
187
|
onClose={() => {
|
|
338
188
|
setExperimentalChainWallet(null);
|
|
339
189
|
}}>
|
|
340
|
-
<
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
description={i18n.t({
|
|
347
|
-
id: 'You should connect a {blockchainDisplayName} supported wallet or choose a different {blockchainDisplayName} address',
|
|
348
|
-
values: { blockchainDisplayName },
|
|
349
|
-
})}>
|
|
350
|
-
<Divider size={18} />
|
|
351
|
-
<Divider size={32} />
|
|
352
|
-
<Button
|
|
353
|
-
onClick={addExperimentalChain.bind(
|
|
354
|
-
null,
|
|
355
|
-
experimentalChainWallet
|
|
356
|
-
)}
|
|
357
|
-
variant="outlined"
|
|
358
|
-
type="primary"
|
|
359
|
-
fullWidth
|
|
360
|
-
size="large">
|
|
361
|
-
{i18n.t('Confirm')}
|
|
362
|
-
</Button>
|
|
363
|
-
</MessageBox>
|
|
190
|
+
<ExperimentalChain
|
|
191
|
+
displayName={blockchainDisplayName}
|
|
192
|
+
onConfirm={() => {
|
|
193
|
+
void addExperimentalChain(experimentalChainWallet);
|
|
194
|
+
}}
|
|
195
|
+
/>
|
|
364
196
|
</WatermarkedModal>
|
|
365
197
|
)}
|
|
366
198
|
{addingExperimentalChainStatus && (
|
|
@@ -368,53 +200,11 @@ export function WalletList(props: PropTypes) {
|
|
|
368
200
|
open={!!addingExperimentalChainStatus}
|
|
369
201
|
onClose={setAddingExperimentalChainStatus.bind(null, null)}
|
|
370
202
|
container={modalContainer}>
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
values: { blockchainDisplayName },
|
|
377
|
-
})}
|
|
378
|
-
description={i18n.t({
|
|
379
|
-
id: 'You should connect a {blockchainDisplayName} supported wallet or choose a different {blockchainDisplayName} address',
|
|
380
|
-
values: { blockchainDisplayName },
|
|
381
|
-
})}
|
|
382
|
-
icon={
|
|
383
|
-
<LogoContainer>
|
|
384
|
-
<WalletImageContainer>
|
|
385
|
-
<Image src={wallet.image} size={45} />
|
|
386
|
-
</WalletImageContainer>
|
|
387
|
-
<Spinner />
|
|
388
|
-
</LogoContainer>
|
|
389
|
-
}
|
|
390
|
-
/>
|
|
391
|
-
)}
|
|
392
|
-
|
|
393
|
-
{addingExperimentalChainStatus === 'completed' && (
|
|
394
|
-
<MessageBox
|
|
395
|
-
type="success"
|
|
396
|
-
title={i18n.t({
|
|
397
|
-
id: '{blockchainDisplayName} Chain Added',
|
|
398
|
-
values: { blockchainDisplayName },
|
|
399
|
-
})}
|
|
400
|
-
description={i18n.t({
|
|
401
|
-
id: '{blockchainDisplayName} is added to your wallet, you can use it to swap.',
|
|
402
|
-
values: { blockchainDisplayName },
|
|
403
|
-
})}
|
|
404
|
-
/>
|
|
405
|
-
)}
|
|
406
|
-
|
|
407
|
-
{addingExperimentalChainStatus === 'rejected' && (
|
|
408
|
-
<MessageBox
|
|
409
|
-
type="error"
|
|
410
|
-
title={i18n.t('Request Rejected')}
|
|
411
|
-
description={i18n.t({
|
|
412
|
-
id: "You've rejected adding {blockchainDisplayName} chain to your wallet.",
|
|
413
|
-
values: { blockchainDisplayName },
|
|
414
|
-
})}
|
|
415
|
-
/>
|
|
416
|
-
)}
|
|
417
|
-
|
|
203
|
+
<ExperimentalChainStatus
|
|
204
|
+
status={addingExperimentalChainStatus}
|
|
205
|
+
displayName={blockchainDisplayName}
|
|
206
|
+
image={wallet.image}
|
|
207
|
+
/>
|
|
418
208
|
<Divider direction="vertical" size={32} />
|
|
419
209
|
</WatermarkedModal>
|
|
420
210
|
)}
|
|
@@ -429,6 +219,25 @@ export function WalletList(props: PropTypes) {
|
|
|
429
219
|
</React.Fragment>
|
|
430
220
|
);
|
|
431
221
|
})}
|
|
222
|
+
<StatefulConnectModal
|
|
223
|
+
wallet={selectedWalletToConnect}
|
|
224
|
+
onClose={() => {
|
|
225
|
+
setSelectedWalletToConnect(undefined);
|
|
226
|
+
}}
|
|
227
|
+
onConnect={(result) => {
|
|
228
|
+
if (props.onConnect && result.status === ResultStatus.Connected) {
|
|
229
|
+
if (selectedWalletToConnect?.type) {
|
|
230
|
+
props.onConnect(selectedWalletToConnect.type);
|
|
231
|
+
} else {
|
|
232
|
+
warn(
|
|
233
|
+
new Error(
|
|
234
|
+
"The selected wallet hasn't been detected after the connection process finished. It usually shouldn't happen."
|
|
235
|
+
)
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}}
|
|
240
|
+
/>
|
|
432
241
|
{shouldShowMoreWallets && (
|
|
433
242
|
<ShowMoreWallets selected={false} onClick={onShowMore}>
|
|
434
243
|
<Typography variant="label" size="medium">
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { Result } from '../../hooks/useStatefulConnect';
|
|
2
|
+
import type { WalletInfoWithExtra } from '../../types';
|
|
3
|
+
import type { Namespace } from '@rango-dev/wallets-shared';
|
|
4
|
+
|
|
5
|
+
import { Divider } from '@rango-dev/ui';
|
|
6
|
+
import React, { useEffect, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
ResultStatus,
|
|
10
|
+
useStatefulConnect,
|
|
11
|
+
} from '../../hooks/useStatefulConnect';
|
|
12
|
+
import { useWalletList } from '../../hooks/useWalletList';
|
|
13
|
+
import { getContainer } from '../../utils/common';
|
|
14
|
+
import { WatermarkedModal } from '../common/WatermarkedModal';
|
|
15
|
+
import {
|
|
16
|
+
ConnectStatus,
|
|
17
|
+
DerivationPath,
|
|
18
|
+
Namespaces,
|
|
19
|
+
} from '../WalletStatefulConnect';
|
|
20
|
+
|
|
21
|
+
import { isOnDerivationPath, isOnNamespace, isOnStatus } from './helpers';
|
|
22
|
+
|
|
23
|
+
const KEEP_SUCCESS_MODAL_FOR = 3_000;
|
|
24
|
+
const DELAY_SHOWING_MODAL_FOR = 300;
|
|
25
|
+
|
|
26
|
+
interface PropTypes {
|
|
27
|
+
wallet: WalletInfoWithExtra | undefined;
|
|
28
|
+
onClose: () => void;
|
|
29
|
+
// When `handleConnect` runs **successfully**, this will be called afterwards.
|
|
30
|
+
onConnect?: (result: Result) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function StatefulConnectModal(props: PropTypes) {
|
|
34
|
+
const [isConnecting, setIsConnecting] = useState(false);
|
|
35
|
+
const [error, setError] = useState<string>();
|
|
36
|
+
const catchErrorOnHandle = (error: Error) => {
|
|
37
|
+
setError(error.message);
|
|
38
|
+
};
|
|
39
|
+
const { terminateConnectingWallets } = useWalletList();
|
|
40
|
+
|
|
41
|
+
const {
|
|
42
|
+
handleConnect,
|
|
43
|
+
handleDerivationPath,
|
|
44
|
+
handleNamespace,
|
|
45
|
+
getState,
|
|
46
|
+
resetState,
|
|
47
|
+
} = useStatefulConnect();
|
|
48
|
+
|
|
49
|
+
const handleConfirmNamespaces = (selectedNamespaces: Namespace[]) => {
|
|
50
|
+
handleNamespace(props.wallet!, selectedNamespaces).catch(
|
|
51
|
+
catchErrorOnHandle
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const handleDerivationPathConfirm = (derivationPath: string) => {
|
|
56
|
+
if (!derivationPath) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
"Derivation path is empty. Please make sure you've filled the field correctly."
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
handleDerivationPath(derivationPath).catch(catchErrorOnHandle);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const handleClosingModal = () => {
|
|
66
|
+
setIsConnecting(false);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const resetModalState = () => {
|
|
70
|
+
setError(undefined);
|
|
71
|
+
resetState();
|
|
72
|
+
setIsConnecting(false);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (props.wallet) {
|
|
77
|
+
resetModalState();
|
|
78
|
+
let isConnected = false;
|
|
79
|
+
/*
|
|
80
|
+
* If connecting to wallet is happening quickly, we shouldn't show a modal.
|
|
81
|
+
* by default we are assuming we can connect quickly, but if it passes an certain amount of time
|
|
82
|
+
* We set his flag as false which means we a modal has been opened (showing a connection status or Namespace/Derivation path modal)
|
|
83
|
+
*/
|
|
84
|
+
let isImmediatelyConnected = true;
|
|
85
|
+
|
|
86
|
+
const beforeConnecting = () => {
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
isImmediatelyConnected = false;
|
|
89
|
+
if (!isConnected) {
|
|
90
|
+
setIsConnecting(true);
|
|
91
|
+
}
|
|
92
|
+
}, DELAY_SHOWING_MODAL_FOR);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const afterConnected = (result: Result) => {
|
|
96
|
+
const resultIsConnected = result.status === ResultStatus.Connected;
|
|
97
|
+
const resultIsDisconnected = [
|
|
98
|
+
ResultStatus.Disconnected,
|
|
99
|
+
ResultStatus.DisconnectedUnhandled,
|
|
100
|
+
].includes(result.status);
|
|
101
|
+
const resultIsNeedMoreStepsToConnect = [
|
|
102
|
+
ResultStatus.Namespace,
|
|
103
|
+
ResultStatus.DerivationPath,
|
|
104
|
+
].includes(result.status);
|
|
105
|
+
|
|
106
|
+
if (!resultIsNeedMoreStepsToConnect) {
|
|
107
|
+
isConnected = true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (resultIsConnected && !isImmediatelyConnected) {
|
|
111
|
+
setTimeout(handleClosingModal, KEEP_SUCCESS_MODAL_FOR);
|
|
112
|
+
} else if (resultIsDisconnected) {
|
|
113
|
+
handleClosingModal();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (props.onConnect) {
|
|
117
|
+
props.onConnect(result);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
beforeConnecting();
|
|
122
|
+
handleConnect(props.wallet, {
|
|
123
|
+
disconnectIfConnected: true,
|
|
124
|
+
})
|
|
125
|
+
.then(afterConnected)
|
|
126
|
+
.catch(catchErrorOnHandle);
|
|
127
|
+
}
|
|
128
|
+
}, [props.wallet]);
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<WatermarkedModal
|
|
132
|
+
open={isConnecting}
|
|
133
|
+
onClose={handleClosingModal}
|
|
134
|
+
onExit={() => {
|
|
135
|
+
resetModalState();
|
|
136
|
+
terminateConnectingWallets();
|
|
137
|
+
if (props.onClose) {
|
|
138
|
+
props.onClose();
|
|
139
|
+
}
|
|
140
|
+
}}
|
|
141
|
+
container={getContainer()}>
|
|
142
|
+
{isOnStatus(getState, props.wallet) && (
|
|
143
|
+
<>
|
|
144
|
+
<ConnectStatus
|
|
145
|
+
wallet={{
|
|
146
|
+
type: props.wallet.type,
|
|
147
|
+
image: props.wallet.image,
|
|
148
|
+
}}
|
|
149
|
+
error={error}
|
|
150
|
+
/>
|
|
151
|
+
<Divider direction="vertical" size={32} />
|
|
152
|
+
</>
|
|
153
|
+
)}
|
|
154
|
+
{isOnNamespace(getState) && (
|
|
155
|
+
<Namespaces
|
|
156
|
+
onConfirm={handleConfirmNamespaces}
|
|
157
|
+
value={getState().namespace}
|
|
158
|
+
/>
|
|
159
|
+
)}
|
|
160
|
+
{isOnDerivationPath(getState) && (
|
|
161
|
+
<DerivationPath
|
|
162
|
+
onConfirm={handleDerivationPathConfirm}
|
|
163
|
+
value={getState().derivationPath}
|
|
164
|
+
/>
|
|
165
|
+
)}
|
|
166
|
+
</WatermarkedModal>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { State } from '../../hooks/useStatefulConnect';
|
|
2
|
+
import type { WalletInfoWithExtra } from '../../types';
|
|
3
|
+
|
|
4
|
+
export function isOnStatus(
|
|
5
|
+
getState: () => State,
|
|
6
|
+
wallet?: WalletInfoWithExtra
|
|
7
|
+
): wallet is WalletInfoWithExtra {
|
|
8
|
+
return getState().status === 'init' && !!wallet;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isOnNamespace(
|
|
12
|
+
getState: () => State
|
|
13
|
+
): getState is () => State & { namespace: NonNullable<State['namespace']> } {
|
|
14
|
+
return getState().status === 'namespace';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isOnDerivationPath(
|
|
18
|
+
getState: () => State
|
|
19
|
+
): getState is () => State & {
|
|
20
|
+
derivationPath: NonNullable<State['derivationPath']>;
|
|
21
|
+
} {
|
|
22
|
+
return getState().status === 'derivationPath';
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { StatefulConnectModal } from './StatefulConnectModal';
|