@rango-dev/widget-embedded 0.36.0 → 0.36.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/Layout/Layout.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +1 -1
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +2 -2
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
- package/dist/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.d.ts.map +1 -1
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +1 -2
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
- package/dist/store/app.d.ts +2 -4
- package/dist/store/app.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/types.d.ts +6 -0
- package/dist/store/slices/types.d.ts.map +1 -0
- package/dist/store/slices/wallets.d.ts +58 -0
- package/dist/store/slices/wallets.d.ts.map +1 -0
- package/dist/store/utils/wallets.d.ts +17 -0
- package/dist/store/utils/wallets.d.ts.map +1 -0
- package/dist/types/config.d.ts +6 -3
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +1 -1
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/hub.d.ts +4 -0
- package/dist/utils/hub.d.ts.map +1 -0
- package/dist/utils/providers.d.ts +3 -8
- package/dist/utils/providers.d.ts.map +1 -1
- package/dist/utils/settings.d.ts +1 -0
- package/dist/utils/settings.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +1 -1
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +12 -14
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +7 -7
- package/src/QueueManager.tsx +12 -7
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +3 -5
- package/src/components/ConfirmWalletsModal/WalletList.tsx +10 -7
- package/src/components/Layout/Layout.tsx +1 -3
- package/src/components/SwapDetails/SwapDetails.tsx +6 -1
- package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
- package/src/components/TokenList/TokenList.tsx +4 -27
- package/src/containers/Inputs/Inputs.tsx +20 -7
- package/src/containers/Wallets/Wallets.tsx +20 -14
- package/src/containers/WidgetInfo/WidgetInfo.tsx +10 -8
- package/src/containers/WidgetInfo/WidgetInfo.types.ts +2 -2
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +40 -2
- package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +7 -6
- package/src/hooks/useSwapInput.ts +1 -2
- package/src/hooks/useWalletList.ts +1 -3
- package/src/hooks/useWalletProviders/useWalletProviders.ts +3 -7
- package/src/index.ts +1 -1
- package/src/pages/Home.tsx +5 -3
- package/src/pages/SelectSwapItemsPage.tsx +1 -2
- package/src/store/app.ts +4 -4
- package/src/store/slices/config.ts +3 -0
- package/src/store/slices/types.ts +9 -0
- package/src/store/slices/wallets.ts +477 -0
- package/src/store/utils/wallets.ts +108 -0
- package/src/types/config.ts +7 -3
- package/src/types/wallets.ts +1 -1
- package/src/utils/hub.ts +22 -0
- package/src/utils/providers.ts +68 -12
- package/src/utils/settings.ts +4 -0
- package/src/utils/swap.ts +1 -1
- package/src/utils/wallets.ts +74 -137
- package/dist/hooks/useObserveBalanceChanges/index.d.ts +0 -2
- package/dist/hooks/useObserveBalanceChanges/index.d.ts.map +0 -1
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts +0 -4
- package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts.map +0 -1
- package/dist/store/wallets.d.ts +0 -66
- package/dist/store/wallets.d.ts.map +0 -1
- package/src/hooks/useObserveBalanceChanges/index.ts +0 -1
- package/src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts +0 -68
- package/src/store/wallets.ts +0 -268
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.36.0",
|
|
3
|
+
"version": "0.36.1-next.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -25,15 +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.40.0",
|
|
28
|
+
"@rango-dev/provider-all": "^0.40.1-next.0",
|
|
29
29
|
"@rango-dev/queue-manager-core": "^0.27.0",
|
|
30
|
-
"@rango-dev/queue-manager-rango-preset": "^0.40.0",
|
|
30
|
+
"@rango-dev/queue-manager-rango-preset": "^0.40.1-next.0",
|
|
31
31
|
"@rango-dev/queue-manager-react": "^0.27.0",
|
|
32
32
|
"@rango-dev/signer-solana": "^0.35.0",
|
|
33
|
-
"@rango-dev/ui": "^0.42.0",
|
|
34
|
-
"@rango-dev/wallets-core": "^0.40.0",
|
|
35
|
-
"@rango-dev/wallets-react": "^0.26.0",
|
|
36
|
-
"@rango-dev/wallets-shared": "^0.40.0",
|
|
33
|
+
"@rango-dev/ui": "^0.42.1-next.0",
|
|
34
|
+
"@rango-dev/wallets-core": "^0.40.1-next.0",
|
|
35
|
+
"@rango-dev/wallets-react": "^0.26.1-next.0",
|
|
36
|
+
"@rango-dev/wallets-shared": "^0.40.1-next.0",
|
|
37
37
|
"bignumber.js": "^9.1.1",
|
|
38
38
|
"copy-to-clipboard": "^3.3.3",
|
|
39
39
|
"dayjs": "^1.11.7",
|
package/src/QueueManager.tsx
CHANGED
|
@@ -15,7 +15,6 @@ import React, { useMemo } from 'react';
|
|
|
15
15
|
import { eventEmitter } from './services/eventEmitter';
|
|
16
16
|
import { useAppStore } from './store/AppStore';
|
|
17
17
|
import { useUiStore } from './store/ui';
|
|
18
|
-
import { useWalletsStore } from './store/wallets';
|
|
19
18
|
import { getConfig } from './utils/configs';
|
|
20
19
|
import { walletAndSupportedChainsNames } from './utils/wallets';
|
|
21
20
|
|
|
@@ -39,8 +38,8 @@ function QueueManager(props: PropsWithChildren<{ apiKey?: string }>) {
|
|
|
39
38
|
});
|
|
40
39
|
}, [props.apiKey]);
|
|
41
40
|
|
|
42
|
-
const blockchains = useAppStore()
|
|
43
|
-
const
|
|
41
|
+
const { blockchains, connectedWallets } = useAppStore();
|
|
42
|
+
const blockchainsList = blockchains();
|
|
44
43
|
|
|
45
44
|
const wallets = {
|
|
46
45
|
blockchains: connectedWallets.map((wallet) => ({
|
|
@@ -53,14 +52,21 @@ function QueueManager(props: PropsWithChildren<{ apiKey?: string }>) {
|
|
|
53
52
|
if (!canSwitchNetworkTo(wallet, network)) {
|
|
54
53
|
return undefined;
|
|
55
54
|
}
|
|
56
|
-
|
|
55
|
+
const result = await connect(wallet, [
|
|
56
|
+
{
|
|
57
|
+
namespace: 'DISCOVER_MODE',
|
|
58
|
+
network,
|
|
59
|
+
},
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
return result;
|
|
57
63
|
};
|
|
58
64
|
|
|
59
65
|
const isMobileWallet = (walletType: WalletType): boolean =>
|
|
60
66
|
!!getWalletInfo(walletType).mobileWallet;
|
|
61
67
|
|
|
62
68
|
// TODO: this code copy & pasted from rango, should be refactored.
|
|
63
|
-
const allBlockchains =
|
|
69
|
+
const allBlockchains = blockchainsList
|
|
64
70
|
.filter((blockchain) => blockchain.enabled)
|
|
65
71
|
.reduce(
|
|
66
72
|
(blockchainsObj: any, blockchain) => (
|
|
@@ -68,7 +74,7 @@ function QueueManager(props: PropsWithChildren<{ apiKey?: string }>) {
|
|
|
68
74
|
),
|
|
69
75
|
{}
|
|
70
76
|
);
|
|
71
|
-
const evmBasedChains =
|
|
77
|
+
const evmBasedChains = blockchainsList.filter(isEvmBlockchain);
|
|
72
78
|
const getSupportedChainNames = (type: WalletType) => {
|
|
73
79
|
const { supportedChains } = getWalletInfo(type);
|
|
74
80
|
return walletAndSupportedChainsNames(supportedChains);
|
|
@@ -88,7 +94,6 @@ function QueueManager(props: PropsWithChildren<{ apiKey?: string }>) {
|
|
|
88
94
|
providers: allProviders,
|
|
89
95
|
switchNetwork,
|
|
90
96
|
canSwitchNetworkTo,
|
|
91
|
-
connect,
|
|
92
97
|
state,
|
|
93
98
|
isMobileWallet,
|
|
94
99
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PropTypes } from './ConfirmWalletsModal.types';
|
|
2
|
-
import type { ConnectedWallet } from '../../store/wallets';
|
|
2
|
+
import type { ConnectedWallet } from '../../store/slices/wallets';
|
|
3
3
|
import type { ConfirmSwapWarnings, Wallet } from '../../types';
|
|
4
4
|
|
|
5
5
|
import { i18n } from '@lingui/core';
|
|
@@ -20,7 +20,6 @@ import { getQuoteErrorMessage } from '../../constants/errors';
|
|
|
20
20
|
import { getQuoteUpdateWarningMessage } from '../../constants/warnings';
|
|
21
21
|
import { useAppStore } from '../../store/AppStore';
|
|
22
22
|
import { useQuoteStore } from '../../store/quote';
|
|
23
|
-
import { useWalletsStore } from '../../store/wallets';
|
|
24
23
|
import { getBlockchainShortNameFor } from '../../utils/meta';
|
|
25
24
|
import { isConfirmSwapDisabled } from '../../utils/swap';
|
|
26
25
|
import { getQuoteWallets } from '../../utils/wallets';
|
|
@@ -54,8 +53,7 @@ export function ConfirmWalletsModal(props: PropTypes) {
|
|
|
54
53
|
customDestination,
|
|
55
54
|
setCustomDestination,
|
|
56
55
|
} = useQuoteStore();
|
|
57
|
-
const { connectedWallets,
|
|
58
|
-
const { config } = useAppStore();
|
|
56
|
+
const { config, connectedWallets, setWalletsAsSelected } = useAppStore();
|
|
59
57
|
|
|
60
58
|
const [showMoreWalletFor, setShowMoreWalletFor] = useState('');
|
|
61
59
|
const [balanceWarnings, setBalanceWarnings] = useState<string[]>([]);
|
|
@@ -217,7 +215,7 @@ export function ConfirmWalletsModal(props: PropTypes) {
|
|
|
217
215
|
const lastSelectedWallets = selectableWallets.filter(
|
|
218
216
|
(wallet) => wallet.selected
|
|
219
217
|
);
|
|
220
|
-
|
|
218
|
+
setWalletsAsSelected(lastSelectedWallets);
|
|
221
219
|
selectQuoteWallets(lastSelectedWallets);
|
|
222
220
|
setQuoteWalletConfirmed(true);
|
|
223
221
|
onClose();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PropTypes } from './WalletList.type';
|
|
2
|
-
import type { Wallet
|
|
2
|
+
import type { Wallet } from '../../types';
|
|
3
|
+
import type { ExtendedModalWalletInfo } from '../../utils/wallets';
|
|
3
4
|
|
|
4
5
|
import { i18n } from '@lingui/core';
|
|
5
6
|
import { warn } from '@rango-dev/logging-core';
|
|
@@ -20,7 +21,6 @@ import {
|
|
|
20
21
|
import { useWalletList } from '../../hooks/useWalletList';
|
|
21
22
|
import { useAppStore } from '../../store/AppStore';
|
|
22
23
|
import { useUiStore } from '../../store/ui';
|
|
23
|
-
import { useWalletsStore } from '../../store/wallets';
|
|
24
24
|
import { getBlockchainDisplayNameFor } from '../../utils/meta';
|
|
25
25
|
import {
|
|
26
26
|
getAddress,
|
|
@@ -41,10 +41,9 @@ export function WalletList(props: PropTypes) {
|
|
|
41
41
|
const { chain, isSelected, selectWallet, limit, onShowMore } = props;
|
|
42
42
|
const isActiveTab = useUiStore.use.isActiveTab();
|
|
43
43
|
|
|
44
|
-
const connectedWallets =
|
|
45
|
-
const { blockchains } = useAppStore();
|
|
44
|
+
const { blockchains, connectedWallets } = useAppStore();
|
|
46
45
|
const [selectedWalletToConnect, setSelectedWalletToConnect] =
|
|
47
|
-
useState<
|
|
46
|
+
useState<ExtendedModalWalletInfo>();
|
|
48
47
|
const [experimentalChainWallet, setExperimentalChainWallet] =
|
|
49
48
|
useState<Wallet | null>(null);
|
|
50
49
|
const [showExperimentalChainModal, setShowExperimentalChainModal] =
|
|
@@ -57,7 +56,7 @@ export function WalletList(props: PropTypes) {
|
|
|
57
56
|
chain,
|
|
58
57
|
});
|
|
59
58
|
|
|
60
|
-
const [sortedList, setSortedList] = useState<
|
|
59
|
+
const [sortedList, setSortedList] = useState<ExtendedModalWalletInfo[]>(list);
|
|
61
60
|
const numberOfSupportedWallets = list.length;
|
|
62
61
|
const shouldShowMoreWallets = limit && numberOfSupportedWallets - limit > 0;
|
|
63
62
|
|
|
@@ -148,9 +147,13 @@ export function WalletList(props: PropTypes) {
|
|
|
148
147
|
|
|
149
148
|
const onSelectableWalletClick = async () => {
|
|
150
149
|
const isDisconnected = wallet.state === WalletState.DISCONNECTED;
|
|
150
|
+
const isConnectedButDifferentThanTargetNamespace = wallet.isHub
|
|
151
|
+
? !conciseAddress
|
|
152
|
+
: !!wallet.namespaces && !conciseAddress;
|
|
153
|
+
|
|
151
154
|
if (isDisconnected) {
|
|
152
155
|
setSelectedWalletToConnect(wallet);
|
|
153
|
-
} else if (
|
|
156
|
+
} else if (isConnectedButDifferentThanTargetNamespace) {
|
|
154
157
|
// wallet is connected on a different namespace
|
|
155
158
|
await handleDisconnect(wallet.type);
|
|
156
159
|
|
|
@@ -13,7 +13,6 @@ import { useNavigateBack } from '../../hooks/useNavigateBack';
|
|
|
13
13
|
import { useTheme } from '../../hooks/useTheme';
|
|
14
14
|
import { useAppStore } from '../../store/AppStore';
|
|
15
15
|
import { tabManager, useUiStore } from '../../store/ui';
|
|
16
|
-
import { useWalletsStore } from '../../store/wallets';
|
|
17
16
|
import { getContainer } from '../../utils/common';
|
|
18
17
|
import { getPendingSwaps } from '../../utils/queue';
|
|
19
18
|
import { isFeatureHidden } from '../../utils/settings';
|
|
@@ -28,9 +27,8 @@ import { Container, Content, Footer, LayoutContainer } from './Layout.styles';
|
|
|
28
27
|
function Layout(props: PropsWithChildren<PropTypes>) {
|
|
29
28
|
const { connectHeightObserver, disconnectHeightObserver } = useIframe();
|
|
30
29
|
const { children, header, footer, height = 'fixed' } = props;
|
|
31
|
-
const { fetchStatus } = useAppStore();
|
|
30
|
+
const { fetchStatus, connectedWallets } = useAppStore();
|
|
32
31
|
const [openRefreshModal, setOpenRefreshModal] = useState(false);
|
|
33
|
-
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
34
32
|
const {
|
|
35
33
|
config: { features, theme },
|
|
36
34
|
} = useAppStore();
|
|
@@ -160,7 +160,12 @@ export function SwapDetails(props: SwapDetailsProps) {
|
|
|
160
160
|
canSwitchNetworkTo(currentStepWallet.walletType, currentStepBlockchain));
|
|
161
161
|
|
|
162
162
|
const switchNetwork = showSwitchNetwork
|
|
163
|
-
? connect.bind(null, currentStepWallet.walletType,
|
|
163
|
+
? connect.bind(null, currentStepWallet.walletType, [
|
|
164
|
+
{
|
|
165
|
+
namespace: 'DISCOVER_MODE',
|
|
166
|
+
network: currentStepBlockchain,
|
|
167
|
+
},
|
|
168
|
+
])
|
|
164
169
|
: undefined;
|
|
165
170
|
|
|
166
171
|
const stepMessage = getSwapMessages(swap, currentStep);
|
|
@@ -15,7 +15,7 @@ export interface SwapAlertsProps extends WaningAlertsProps {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export interface WaningAlertsProps extends FailedAlertsProps {
|
|
18
|
-
switchNetwork: (() => Promise<ConnectResult>) | undefined;
|
|
18
|
+
switchNetwork: (() => Promise<ConnectResult[]>) | undefined;
|
|
19
19
|
showNetworkModal: PendingSwapNetworkStatus | null | undefined;
|
|
20
20
|
setNetworkModal: (network: ModalState) => void;
|
|
21
21
|
}
|
|
@@ -15,11 +15,9 @@ import {
|
|
|
15
15
|
Typography,
|
|
16
16
|
VirtualizedList,
|
|
17
17
|
} from '@rango-dev/ui';
|
|
18
|
-
import React
|
|
18
|
+
import React from 'react';
|
|
19
19
|
|
|
20
|
-
import { useObserveBalanceChanges } from '../../hooks/useObserveBalanceChanges';
|
|
21
20
|
import { useAppStore } from '../../store/AppStore';
|
|
22
|
-
import { useWalletsStore } from '../../store/wallets';
|
|
23
21
|
import { createTintsAndShades } from '../../utils/colors';
|
|
24
22
|
import { formatBalance } from '../../utils/wallets';
|
|
25
23
|
|
|
@@ -93,7 +91,7 @@ const renderDesc = (props: RenderDescProps) => {
|
|
|
93
91
|
|
|
94
92
|
export function TokenList(props: PropTypes) {
|
|
95
93
|
const {
|
|
96
|
-
list,
|
|
94
|
+
list: tokens,
|
|
97
95
|
searchedFor = '',
|
|
98
96
|
onChange,
|
|
99
97
|
selectedBlockchain,
|
|
@@ -101,29 +99,10 @@ export function TokenList(props: PropTypes) {
|
|
|
101
99
|
action,
|
|
102
100
|
} = props;
|
|
103
101
|
|
|
104
|
-
const [tokens, setTokens] = useState<Token[]>(list);
|
|
105
102
|
const fetchStatus = useAppStore().fetchStatus;
|
|
106
103
|
const blockchains = useAppStore().blockchains();
|
|
107
|
-
const
|
|
108
|
-
const { getBalanceFor, loading: loadingWallet } = useWalletsStore();
|
|
104
|
+
const { getBalanceFor, fetchingWallets: loadingWallet } = useAppStore();
|
|
109
105
|
const { isTokenPinned } = useAppStore();
|
|
110
|
-
/**
|
|
111
|
-
* We can create the key by hashing the list of tokens,
|
|
112
|
-
* but if the list is large, the memory usage and cost of comparisons may be high.
|
|
113
|
-
*/
|
|
114
|
-
const { balanceKey } = useObserveBalanceChanges(selectedBlockchain);
|
|
115
|
-
|
|
116
|
-
const loadNextPage = () => {
|
|
117
|
-
setTokens(list.slice(0, tokens.length + PAGE_SIZE));
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
useEffect(() => {
|
|
121
|
-
setHasNextPage(list.length > tokens.length);
|
|
122
|
-
}, [tokens.length]);
|
|
123
|
-
|
|
124
|
-
useEffect(() => {
|
|
125
|
-
setTokens(list.slice(0, PAGE_SIZE));
|
|
126
|
-
}, [list.length, selectedBlockchain, balanceKey]);
|
|
127
106
|
|
|
128
107
|
const endRenderer = (token: Token) => {
|
|
129
108
|
const tokenBalance = formatBalance(getBalanceFor(token));
|
|
@@ -160,11 +139,9 @@ export function TokenList(props: PropTypes) {
|
|
|
160
139
|
)
|
|
161
140
|
);
|
|
162
141
|
};
|
|
163
|
-
|
|
164
142
|
const renderList = () => {
|
|
165
143
|
return (
|
|
166
144
|
<VirtualizedList
|
|
167
|
-
endReached={hasNextPage ? loadNextPage : undefined}
|
|
168
145
|
itemContent={(index) => {
|
|
169
146
|
const token = tokens[index];
|
|
170
147
|
const address = token.address || '';
|
|
@@ -258,7 +235,7 @@ export function TokenList(props: PropTypes) {
|
|
|
258
235
|
);
|
|
259
236
|
}}
|
|
260
237
|
totalCount={tokens.length}
|
|
261
|
-
key={`${selectedBlockchain}-${searchedFor}
|
|
238
|
+
key={`${selectedBlockchain}-${searchedFor}`}
|
|
262
239
|
/>
|
|
263
240
|
);
|
|
264
241
|
};
|
|
@@ -2,10 +2,12 @@ import type { PropTypes } from './Inputs.types';
|
|
|
2
2
|
|
|
3
3
|
import { i18n } from '@lingui/core';
|
|
4
4
|
import { SwapInput } from '@rango-dev/ui';
|
|
5
|
+
import BigNumber from 'bignumber.js';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
7
8
|
import { SwitchFromAndToButton } from '../../components/SwitchFromAndTo';
|
|
8
9
|
import { errorMessages } from '../../constants/errors';
|
|
10
|
+
import { ZERO } from '../../constants/numbers';
|
|
9
11
|
import {
|
|
10
12
|
PERCENTAGE_CHANGE_MAX_DECIMALS,
|
|
11
13
|
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
@@ -14,8 +16,8 @@ import {
|
|
|
14
16
|
USD_VALUE_MAX_DECIMALS,
|
|
15
17
|
USD_VALUE_MIN_DECIMALS,
|
|
16
18
|
} from '../../constants/routing';
|
|
19
|
+
import { useAppStore } from '../../store/AppStore';
|
|
17
20
|
import { useQuoteStore } from '../../store/quote';
|
|
18
|
-
import { useWalletsStore } from '../../store/wallets';
|
|
19
21
|
import { getContainer } from '../../utils/common';
|
|
20
22
|
import { numberToString } from '../../utils/numbers';
|
|
21
23
|
import { getPriceImpact, getPriceImpactLevel } from '../../utils/quote';
|
|
@@ -38,15 +40,16 @@ export function Inputs(props: PropTypes) {
|
|
|
38
40
|
outputUsdValue,
|
|
39
41
|
selectedQuote,
|
|
40
42
|
} = useQuoteStore();
|
|
41
|
-
const { connectedWallets, getBalanceFor } =
|
|
43
|
+
const { connectedWallets, getBalanceFor } = useAppStore();
|
|
42
44
|
const fromTokenBalance = fromToken ? getBalanceFor(fromToken) : null;
|
|
43
45
|
const fromTokenFormattedBalance =
|
|
44
46
|
formatBalance(fromTokenBalance)?.amount ?? '0';
|
|
45
47
|
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const fromBalanceAmount = fromTokenBalance
|
|
49
|
+
? new BigNumber(fromTokenBalance.amount).shiftedBy(
|
|
50
|
+
-fromTokenBalance.decimals
|
|
51
|
+
)
|
|
52
|
+
: ZERO;
|
|
50
53
|
|
|
51
54
|
const fetchingBalance =
|
|
52
55
|
!!fromBlockchain &&
|
|
@@ -107,7 +110,17 @@ export function Inputs(props: PropTypes) {
|
|
|
107
110
|
loadingBalance={fetchingBalance}
|
|
108
111
|
tooltipContainer={getContainer()}
|
|
109
112
|
onSelectMaxBalance={() => {
|
|
110
|
-
|
|
113
|
+
const tokenBalanceReal = numberToString(
|
|
114
|
+
fromBalanceAmount,
|
|
115
|
+
fromTokenBalance?.decimals
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
// if a token hasn't any value, we will reset the input by setting an empty string.
|
|
119
|
+
const nextInputAmount = !!fromTokenBalance?.amount
|
|
120
|
+
? tokenBalanceReal
|
|
121
|
+
: '';
|
|
122
|
+
|
|
123
|
+
setInputAmount(nextInputAmount);
|
|
111
124
|
}}
|
|
112
125
|
anyWalletConnected={connectedWallets.length > 0}
|
|
113
126
|
/>
|
|
@@ -15,7 +15,7 @@ import React, { createContext, useEffect, useMemo, useRef } from 'react';
|
|
|
15
15
|
import { useWalletProviders } from '../../hooks/useWalletProviders';
|
|
16
16
|
import { AppStoreProvider, useAppStore } from '../../store/AppStore';
|
|
17
17
|
import { useUiStore } from '../../store/ui';
|
|
18
|
-
import {
|
|
18
|
+
import { isFeatureEnabled } from '../../utils/settings';
|
|
19
19
|
import {
|
|
20
20
|
prepareAccountsForWalletStore,
|
|
21
21
|
walletAndSupportedChainsNames,
|
|
@@ -38,7 +38,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
38
38
|
fetchStatus,
|
|
39
39
|
} = useAppStore();
|
|
40
40
|
const blockchains = useAppStore().blockchains();
|
|
41
|
-
const {
|
|
41
|
+
const { newWalletConnected, disconnectWallet } = useAppStore();
|
|
42
42
|
const config = useAppStore().config;
|
|
43
43
|
|
|
44
44
|
const walletOptions: ProvidersOptions = {
|
|
@@ -48,9 +48,9 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
48
48
|
walletConnectListedDesktopWalletLink:
|
|
49
49
|
props.config.__UNSTABLE_OR_INTERNAL__
|
|
50
50
|
?.walletConnectListedDesktopWalletLink,
|
|
51
|
+
experimentalWallet: props.config.features?.experimentalWallet,
|
|
51
52
|
};
|
|
52
53
|
const { providers } = useWalletProviders(config.wallets, walletOptions);
|
|
53
|
-
const { connectWallet, disconnectWallet } = useWalletsStore();
|
|
54
54
|
const onConnectWalletHandler = useRef<OnWalletConnectionChange>();
|
|
55
55
|
const onDisconnectWalletHandler = useRef<OnWalletConnectionChange>();
|
|
56
56
|
|
|
@@ -86,7 +86,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
86
86
|
meta.isContractWallet
|
|
87
87
|
);
|
|
88
88
|
if (data.length) {
|
|
89
|
-
|
|
89
|
+
void newWalletConnected(data);
|
|
90
90
|
}
|
|
91
91
|
} else {
|
|
92
92
|
disconnectWallet(type);
|
|
@@ -99,17 +99,17 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
if (
|
|
102
|
+
if (
|
|
103
|
+
(event === Events.ACCOUNTS && state.connected) ||
|
|
104
|
+
// Hub works differently, and this check should be enough.
|
|
105
|
+
(event === Events.ACCOUNTS && meta.isHub)
|
|
106
|
+
) {
|
|
103
107
|
const key = `${type}-${state.network}-${value}`;
|
|
104
108
|
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
console.warn(
|
|
110
|
-
`onConnectWallet handler hasn't been set. Are you sure?`
|
|
111
|
-
);
|
|
112
|
-
}
|
|
109
|
+
if (!!onConnectWalletHandler.current) {
|
|
110
|
+
onConnectWalletHandler.current(key);
|
|
111
|
+
} else {
|
|
112
|
+
console.warn(`onConnectWallet handler hasn't been set. Are you sure?`);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -147,7 +147,13 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
147
147
|
allBlockChains={blockchains}
|
|
148
148
|
providers={providers}
|
|
149
149
|
onUpdateState={onUpdateState}
|
|
150
|
-
autoConnect={!!isActiveTab}
|
|
150
|
+
autoConnect={!!isActiveTab}
|
|
151
|
+
configs={{
|
|
152
|
+
isExperimentalEnabled: isFeatureEnabled(
|
|
153
|
+
'experimentalWallet',
|
|
154
|
+
config.features
|
|
155
|
+
),
|
|
156
|
+
}}>
|
|
151
157
|
{props.children}
|
|
152
158
|
</Provider>
|
|
153
159
|
</WidgetContext.Provider>
|
|
@@ -9,7 +9,6 @@ import { useAppStore } from '../../store/AppStore';
|
|
|
9
9
|
import { useNotificationStore } from '../../store/notification';
|
|
10
10
|
import { useQuoteStore } from '../../store/quote';
|
|
11
11
|
import { tabManager, useUiStore } from '../../store/ui';
|
|
12
|
-
import { useWalletsStore } from '../../store/wallets';
|
|
13
12
|
import { calculateWalletUsdValue } from '../../utils/wallets';
|
|
14
13
|
|
|
15
14
|
import { WidgetHistory } from './WidgetInfo.helpers';
|
|
@@ -22,13 +21,16 @@ export function WidgetInfo(props: React.PropsWithChildren) {
|
|
|
22
21
|
const { manager } = useManager();
|
|
23
22
|
const isActiveTab = useUiStore.use.isActiveTab();
|
|
24
23
|
const retrySwap = useQuoteStore.use.retry();
|
|
25
|
-
const {
|
|
24
|
+
const {
|
|
25
|
+
findToken,
|
|
26
|
+
connectedWallets,
|
|
27
|
+
getBalances,
|
|
28
|
+
fetchBalances: refetch,
|
|
29
|
+
} = useAppStore();
|
|
26
30
|
|
|
27
31
|
const history = new WidgetHistory(manager, { retrySwap, findToken });
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const totalBalance = calculateWalletUsdValue(details);
|
|
31
|
-
const refetch = useWalletsStore.use.getWalletsDetails();
|
|
32
|
+
const { fetchingWallets: isLoading } = useAppStore();
|
|
33
|
+
const totalBalance = calculateWalletUsdValue(getBalances());
|
|
32
34
|
const blockchains = useAppStore().blockchains();
|
|
33
35
|
const tokens = useAppStore().tokens();
|
|
34
36
|
const swappers = useAppStore().swappers();
|
|
@@ -47,9 +49,9 @@ export function WidgetInfo(props: React.PropsWithChildren) {
|
|
|
47
49
|
history,
|
|
48
50
|
wallets: {
|
|
49
51
|
isLoading,
|
|
50
|
-
details,
|
|
52
|
+
details: connectedWallets,
|
|
51
53
|
totalBalance,
|
|
52
|
-
refetch: (accounts) => refetch(accounts
|
|
54
|
+
refetch: async (accounts) => refetch(accounts),
|
|
53
55
|
},
|
|
54
56
|
meta: {
|
|
55
57
|
blockchains,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { WidgetHistory } from './WidgetInfo.helpers';
|
|
2
2
|
import type { FetchStatus, FindToken } from '../../store/slices/data';
|
|
3
|
-
import type { ConnectedWallet } from '../../store/wallets';
|
|
3
|
+
import type { ConnectedWallet } from '../../store/slices/wallets';
|
|
4
4
|
import type { QuoteInputs, UpdateQuoteInputs, Wallet } from '../../types';
|
|
5
5
|
import type { Notification } from '../../types/notification';
|
|
6
6
|
import type { BlockchainMeta, SwapperMeta, Token } from 'rango-sdk';
|
|
@@ -13,7 +13,7 @@ export interface WidgetInfoContextInterface {
|
|
|
13
13
|
details: ConnectedWallet[];
|
|
14
14
|
totalBalance: string;
|
|
15
15
|
isLoading: boolean;
|
|
16
|
-
refetch: (accounts: Wallet[]
|
|
16
|
+
refetch: (accounts: Wallet[]) => void;
|
|
17
17
|
};
|
|
18
18
|
meta: {
|
|
19
19
|
blockchains: BlockchainMeta[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { HandleConnectOptions, Result } from './useStatefulConnect.types';
|
|
2
2
|
import type { WalletInfoWithExtra } from '../../types';
|
|
3
|
+
import type { ExtendedModalWalletInfo } from '../../utils/wallets';
|
|
3
4
|
import type {
|
|
4
5
|
Namespace,
|
|
5
6
|
NamespaceData,
|
|
@@ -10,6 +11,8 @@ import { WalletState } from '@rango-dev/ui';
|
|
|
10
11
|
import { useWallets } from '@rango-dev/wallets-react';
|
|
11
12
|
import { useReducer } from 'react';
|
|
12
13
|
|
|
14
|
+
import { convertCommonNamespacesKeysToLegacyNamespace } from '../../utils/hub';
|
|
15
|
+
|
|
13
16
|
import {
|
|
14
17
|
isStateOnDerivationPathStep,
|
|
15
18
|
isStateOnNamespace,
|
|
@@ -61,7 +64,11 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
61
64
|
});
|
|
62
65
|
|
|
63
66
|
try {
|
|
64
|
-
|
|
67
|
+
const legacyNamespacesInput = namespaces?.map((namespaceInput) => ({
|
|
68
|
+
...namespaceInput,
|
|
69
|
+
network: undefined,
|
|
70
|
+
}));
|
|
71
|
+
await connect(type, legacyNamespacesInput);
|
|
65
72
|
|
|
66
73
|
return { status: ResultStatus.Connected };
|
|
67
74
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -75,7 +82,7 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
75
82
|
};
|
|
76
83
|
|
|
77
84
|
const handleConnect = async (
|
|
78
|
-
wallet:
|
|
85
|
+
wallet: ExtendedModalWalletInfo,
|
|
79
86
|
options?: HandleConnectOptions
|
|
80
87
|
): Promise<{
|
|
81
88
|
status: ResultStatus;
|
|
@@ -83,6 +90,37 @@ export function useStatefulConnect(): UseStatefulConnect {
|
|
|
83
90
|
const isDisconnected = wallet.state === WalletState.DISCONNECTED;
|
|
84
91
|
|
|
85
92
|
if (isDisconnected) {
|
|
93
|
+
// Legacy and hub have different structure to check wether we need to show namespace or not.
|
|
94
|
+
|
|
95
|
+
// Hub
|
|
96
|
+
const isHub = !!wallet.isHub;
|
|
97
|
+
if (isHub) {
|
|
98
|
+
const detachedInstances = wallet.properties?.find(
|
|
99
|
+
(item) => item.name === 'detached'
|
|
100
|
+
);
|
|
101
|
+
const needsNamespace =
|
|
102
|
+
detachedInstances && wallet.state !== 'connected';
|
|
103
|
+
|
|
104
|
+
if (needsNamespace) {
|
|
105
|
+
const availableNamespaces =
|
|
106
|
+
convertCommonNamespacesKeysToLegacyNamespace(
|
|
107
|
+
detachedInstances.value
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
dispatch({
|
|
111
|
+
type: 'needsNamespace',
|
|
112
|
+
payload: {
|
|
113
|
+
providerType: wallet.type,
|
|
114
|
+
providerImage: wallet.image,
|
|
115
|
+
availableNamespaces,
|
|
116
|
+
singleNamespace: false,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
return { status: ResultStatus.Namespace };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Legacy
|
|
86
124
|
if (!wallet.namespaces) {
|
|
87
125
|
return await runConnect(wallet.type, undefined, options);
|
|
88
126
|
}
|
|
@@ -12,13 +12,10 @@ import { useEffect } from 'react';
|
|
|
12
12
|
import { eventEmitter } from '../../services/eventEmitter';
|
|
13
13
|
import { useAppStore } from '../../store/AppStore';
|
|
14
14
|
import { useNotificationStore } from '../../store/notification';
|
|
15
|
-
import { useWalletsStore } from '../../store/wallets';
|
|
16
15
|
|
|
17
16
|
export function useSubscribeToWidgetEvents() {
|
|
18
|
-
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
19
|
-
const getWalletsDetails = useWalletsStore.use.getWalletsDetails();
|
|
20
17
|
const setNotification = useNotificationStore.use.setNotification();
|
|
21
|
-
const {
|
|
18
|
+
const { connectedWallets, fetchBalances } = useAppStore();
|
|
22
19
|
|
|
23
20
|
useEffect(() => {
|
|
24
21
|
const handleStepEvent = (widgetEvent: StepEventData) => {
|
|
@@ -39,8 +36,12 @@ export function useSubscribeToWidgetEvents() {
|
|
|
39
36
|
(wallet) => wallet.chain === step?.toBlockchain
|
|
40
37
|
);
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
if (fromAccount) {
|
|
40
|
+
void fetchBalances([fromAccount]);
|
|
41
|
+
}
|
|
42
|
+
if (toAccount) {
|
|
43
|
+
void fetchBalances([toAccount]);
|
|
44
|
+
}
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
setNotification(event, route);
|
|
@@ -4,7 +4,6 @@ import { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
4
4
|
|
|
5
5
|
import { useAppStore } from '../store/AppStore';
|
|
6
6
|
import { useQuoteStore } from '../store/quote';
|
|
7
|
-
import { useWalletsStore } from '../store/wallets';
|
|
8
7
|
import { QuoteErrorType } from '../types';
|
|
9
8
|
import { debounce } from '../utils/common';
|
|
10
9
|
import { isPositiveNumber } from '../utils/numbers';
|
|
@@ -50,7 +49,7 @@ export function useSwapInput({
|
|
|
50
49
|
const { fetch: fetchQuote, cancelFetch } = useFetchAllQuotes();
|
|
51
50
|
const { excludeLiquiditySources: configExcludeLiquiditySources, routing } =
|
|
52
51
|
useAppStore().config;
|
|
53
|
-
const connectedWallets =
|
|
52
|
+
const { connectedWallets } = useAppStore();
|
|
54
53
|
|
|
55
54
|
const {
|
|
56
55
|
fromToken,
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
import { useCallback, useEffect } from 'react';
|
|
13
13
|
|
|
14
14
|
import { useAppStore } from '../store/AppStore';
|
|
15
|
-
import { useWalletsStore } from '../store/wallets';
|
|
16
15
|
import { configWalletsToWalletName } from '../utils/providers';
|
|
17
16
|
import {
|
|
18
17
|
hashWalletsState,
|
|
@@ -43,9 +42,8 @@ interface API {
|
|
|
43
42
|
*/
|
|
44
43
|
export function useWalletList(params?: Params): API {
|
|
45
44
|
const { chain } = params || {};
|
|
46
|
-
const { config } = useAppStore();
|
|
45
|
+
const { config, connectedWallets } = useAppStore();
|
|
47
46
|
const { state, getWalletInfo } = useWallets();
|
|
48
|
-
const { connectedWallets } = useWalletsStore();
|
|
49
47
|
const blockchains = useAppStore().blockchains();
|
|
50
48
|
const { handleDisconnect } = useStatefulConnect();
|
|
51
49
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { WidgetConfig } from '../../types';
|
|
2
2
|
import type { ProvidersOptions } from '../../utils/providers';
|
|
3
|
-
import type { ProviderInterface } from '@rango-dev/wallets-react';
|
|
4
3
|
|
|
5
4
|
import { useEffect } from 'react';
|
|
6
5
|
|
|
7
|
-
import {
|
|
6
|
+
import { useAppStore } from '../../store/AppStore';
|
|
8
7
|
import { matchAndGenerateProviders } from '../../utils/providers';
|
|
9
8
|
|
|
10
9
|
import { hashProviders } from './useWalletProviders.helpers';
|
|
@@ -13,11 +12,8 @@ export function useWalletProviders(
|
|
|
13
12
|
providers: WidgetConfig['wallets'],
|
|
14
13
|
options?: ProvidersOptions
|
|
15
14
|
) {
|
|
16
|
-
const clearConnectedWallet =
|
|
17
|
-
let generateProviders
|
|
18
|
-
providers,
|
|
19
|
-
options
|
|
20
|
-
);
|
|
15
|
+
const { clearConnectedWallet } = useAppStore();
|
|
16
|
+
let generateProviders = matchAndGenerateProviders(providers, options);
|
|
21
17
|
|
|
22
18
|
useEffect(() => {
|
|
23
19
|
clearConnectedWallet();
|