@rango-dev/widget-embedded 0.32.1 → 0.32.2-next.1
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/CHANGELOG.md +4 -0
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.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 +5 -3
- 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 +8 -7
- package/src/components/ConfirmWalletsModal/WalletList.tsx +52 -243
- package/src/components/HeaderButtons/WalletButton.tsx +1 -1
- package/src/components/Slippage/Slippage.tsx +3 -0
- package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +176 -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} +34 -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 +7 -8
- package/src/pages/WalletsPage.tsx +10 -162
- package/src/store/wallets.ts +1 -1
- 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.32.1",
|
|
3
|
+
"version": "0.32.2-next.1",
|
|
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.
|
|
28
|
+
"@rango-dev/provider-all": "^0.36.1-next.5",
|
|
29
29
|
"@rango-dev/queue-manager-core": "^0.27.0",
|
|
30
|
-
"@rango-dev/queue-manager-rango-preset": "^0.36.
|
|
30
|
+
"@rango-dev/queue-manager-rango-preset": "^0.36.1-next.1",
|
|
31
31
|
"@rango-dev/queue-manager-react": "^0.27.0",
|
|
32
|
-
"@rango-dev/signer-solana": "^0.31.
|
|
33
|
-
"@rango-dev/ui": "^0.38.0",
|
|
34
|
-
"@rango-dev/wallets-
|
|
35
|
-
"@rango-dev/wallets-
|
|
32
|
+
"@rango-dev/signer-solana": "^0.31.1-next.1",
|
|
33
|
+
"@rango-dev/ui": "^0.38.1-next.0",
|
|
34
|
+
"@rango-dev/wallets-core": "^0.37.1-next.1",
|
|
35
|
+
"@rango-dev/wallets-react": "^0.22.1-next.1",
|
|
36
|
+
"@rango-dev/wallets-shared": "^0.36.1-next.1",
|
|
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">
|
|
@@ -2,6 +2,7 @@ import { i18n } from '@lingui/core';
|
|
|
2
2
|
import {
|
|
3
3
|
Divider,
|
|
4
4
|
InfoIcon,
|
|
5
|
+
SlippageIcon,
|
|
5
6
|
TextField,
|
|
6
7
|
Tooltip,
|
|
7
8
|
Typography,
|
|
@@ -31,6 +32,8 @@ export function Slippage() {
|
|
|
31
32
|
return (
|
|
32
33
|
<BaseContainer>
|
|
33
34
|
<Head>
|
|
35
|
+
<SlippageIcon size={16} color="gray" />
|
|
36
|
+
<Divider direction="horizontal" size={4} />
|
|
34
37
|
<Typography variant="title" size="xmedium">
|
|
35
38
|
{i18n.t('Slippage tolerance per swap')}
|
|
36
39
|
</Typography>
|
|
@@ -0,0 +1,176 @@
|
|
|
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, useRef, 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 successModalTimerId = useRef<ReturnType<typeof setTimeout>>();
|
|
35
|
+
const [isConnecting, setIsConnecting] = useState(false);
|
|
36
|
+
const [error, setError] = useState<string>();
|
|
37
|
+
const catchErrorOnHandle = (error: Error) => {
|
|
38
|
+
setError(error.message);
|
|
39
|
+
};
|
|
40
|
+
const { terminateConnectingWallets } = useWalletList();
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
handleConnect,
|
|
44
|
+
handleDerivationPath,
|
|
45
|
+
handleNamespace,
|
|
46
|
+
getState,
|
|
47
|
+
resetState,
|
|
48
|
+
} = useStatefulConnect();
|
|
49
|
+
|
|
50
|
+
const handleConfirmNamespaces = (selectedNamespaces: Namespace[]) => {
|
|
51
|
+
handleNamespace(props.wallet!, selectedNamespaces).catch(
|
|
52
|
+
catchErrorOnHandle
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handleDerivationPathConfirm = (derivationPath: string) => {
|
|
57
|
+
if (!derivationPath) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
"Derivation path is empty. Please make sure you've filled the field correctly."
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
handleDerivationPath(derivationPath).catch(catchErrorOnHandle);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const handleClosingModal = () => {
|
|
67
|
+
setIsConnecting(false);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const resetModalState = () => {
|
|
71
|
+
setError(undefined);
|
|
72
|
+
resetState();
|
|
73
|
+
setIsConnecting(false);
|
|
74
|
+
|
|
75
|
+
if (successModalTimerId.current) {
|
|
76
|
+
clearTimeout(successModalTimerId.current);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (props.wallet) {
|
|
82
|
+
resetModalState();
|
|
83
|
+
let isConnected = false;
|
|
84
|
+
/*
|
|
85
|
+
* If connecting to wallet is happening quickly, we shouldn't show a modal.
|
|
86
|
+
* by default we are assuming we can connect quickly, but if it passes an certain amount of time
|
|
87
|
+
* We set his flag as false which means we a modal has been opened (showing a connection status or Namespace/Derivation path modal)
|
|
88
|
+
*/
|
|
89
|
+
let isImmediatelyConnected = true;
|
|
90
|
+
|
|
91
|
+
const beforeConnecting = () => {
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
isImmediatelyConnected = false;
|
|
94
|
+
if (!isConnected) {
|
|
95
|
+
setIsConnecting(true);
|
|
96
|
+
}
|
|
97
|
+
}, DELAY_SHOWING_MODAL_FOR);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const afterConnected = (result: Result) => {
|
|
101
|
+
const resultIsConnected = result.status === ResultStatus.Connected;
|
|
102
|
+
const resultIsDisconnected = [
|
|
103
|
+
ResultStatus.Disconnected,
|
|
104
|
+
ResultStatus.DisconnectedUnhandled,
|
|
105
|
+
].includes(result.status);
|
|
106
|
+
const resultIsNeedMoreStepsToConnect = [
|
|
107
|
+
ResultStatus.Namespace,
|
|
108
|
+
ResultStatus.DerivationPath,
|
|
109
|
+
].includes(result.status);
|
|
110
|
+
|
|
111
|
+
if (!resultIsNeedMoreStepsToConnect) {
|
|
112
|
+
isConnected = true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (resultIsConnected && !isImmediatelyConnected) {
|
|
116
|
+
successModalTimerId.current = setTimeout(
|
|
117
|
+
handleClosingModal,
|
|
118
|
+
KEEP_SUCCESS_MODAL_FOR
|
|
119
|
+
);
|
|
120
|
+
} else if (resultIsDisconnected) {
|
|
121
|
+
handleClosingModal();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (props.onConnect) {
|
|
125
|
+
props.onConnect(result);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
beforeConnecting();
|
|
130
|
+
handleConnect(props.wallet, {
|
|
131
|
+
disconnectIfConnected: true,
|
|
132
|
+
})
|
|
133
|
+
.then(afterConnected)
|
|
134
|
+
.catch(catchErrorOnHandle);
|
|
135
|
+
}
|
|
136
|
+
}, [props.wallet]);
|
|
137
|
+
|
|
138
|
+
return (
|
|
139
|
+
<WatermarkedModal
|
|
140
|
+
open={isConnecting}
|
|
141
|
+
onClose={handleClosingModal}
|
|
142
|
+
onExit={() => {
|
|
143
|
+
resetModalState();
|
|
144
|
+
terminateConnectingWallets();
|
|
145
|
+
if (props.onClose) {
|
|
146
|
+
props.onClose();
|
|
147
|
+
}
|
|
148
|
+
}}
|
|
149
|
+
container={getContainer()}>
|
|
150
|
+
{isOnStatus(getState, props.wallet) && (
|
|
151
|
+
<>
|
|
152
|
+
<ConnectStatus
|
|
153
|
+
wallet={{
|
|
154
|
+
type: props.wallet.type,
|
|
155
|
+
image: props.wallet.image,
|
|
156
|
+
}}
|
|
157
|
+
error={error}
|
|
158
|
+
/>
|
|
159
|
+
<Divider direction="vertical" size={32} />
|
|
160
|
+
</>
|
|
161
|
+
)}
|
|
162
|
+
{isOnNamespace(getState) && (
|
|
163
|
+
<Namespaces
|
|
164
|
+
onConfirm={handleConfirmNamespaces}
|
|
165
|
+
value={getState().namespace}
|
|
166
|
+
/>
|
|
167
|
+
)}
|
|
168
|
+
{isOnDerivationPath(getState) && (
|
|
169
|
+
<DerivationPath
|
|
170
|
+
onConfirm={handleDerivationPathConfirm}
|
|
171
|
+
value={getState().derivationPath}
|
|
172
|
+
/>
|
|
173
|
+
)}
|
|
174
|
+
</WatermarkedModal>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
@@ -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';
|