@rango-dev/widget-embedded 0.1.15 → 0.1.16-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/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/RoutesOverview.d.ts.map +1 -1
- package/dist/components/TokenPreview.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +6 -15
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +7 -0
- package/dist/types/wallets.d.ts.map +1 -0
- package/dist/utils/routing.d.ts +2 -3
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +8 -9
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +11 -12
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +67 -73
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +67 -73
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +67 -73
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/QueueManager.tsx +4 -5
- package/src/components/Layout.tsx +5 -5
- package/src/components/RoutesOverview.tsx +1 -4
- package/src/components/TokenInfo.tsx +5 -5
- package/src/components/TokenPreview.tsx +8 -3
- package/src/hooks/useConfirmSwap.ts +2 -2
- package/src/pages/ConfirmSwapPage.tsx +2 -2
- package/src/pages/Home.tsx +5 -3
- package/src/store/bestRoute.ts +7 -7
- package/src/store/wallets.ts +32 -46
- package/src/types/index.ts +1 -0
- package/src/types/wallets.ts +7 -0
- package/src/utils/routing.ts +2 -3
- package/src/utils/swap.ts +12 -11
- package/src/utils/wallets.ts +59 -52
package/package.json
CHANGED
package/src/QueueManager.tsx
CHANGED
|
@@ -34,13 +34,12 @@ function QueueManager(props: PropsWithChildren<{}>) {
|
|
|
34
34
|
});
|
|
35
35
|
}, []);
|
|
36
36
|
const getOneOfWalletsDetails = useWalletsStore.use.getOneOfWalletsDetails();
|
|
37
|
-
const accounts = useWalletsStore.use.accounts();
|
|
38
37
|
|
|
39
38
|
const { blockchains } = useMetaStore.use.meta();
|
|
40
|
-
const
|
|
39
|
+
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
41
40
|
|
|
42
41
|
const wallets = {
|
|
43
|
-
blockchains:
|
|
42
|
+
blockchains: connectedWallets.map((wallet) => ({
|
|
44
43
|
accounts: [wallet],
|
|
45
44
|
name: wallet.chain,
|
|
46
45
|
})),
|
|
@@ -79,12 +78,12 @@ function QueueManager(props: PropsWithChildren<{}>) {
|
|
|
79
78
|
lastStep?.id !== data.step?.id) ||
|
|
80
79
|
!!outputAmount
|
|
81
80
|
) {
|
|
82
|
-
const fromAccount =
|
|
81
|
+
const fromAccount = connectedWallets.find(
|
|
83
82
|
(account) => account.chain === step?.fromBlockchain
|
|
84
83
|
);
|
|
85
84
|
const toAccount =
|
|
86
85
|
step?.fromBlockchain !== step?.toBlockchain &&
|
|
87
|
-
|
|
86
|
+
connectedWallets.find((wallet) => wallet.chain === step?.toBlockchain);
|
|
88
87
|
|
|
89
88
|
fromAccount && getOneOfWalletsDetails(fromAccount);
|
|
90
89
|
toAccount && getOneOfWalletsDetails(toAccount);
|
|
@@ -39,7 +39,7 @@ const WalletImageContainer = styled('div', {
|
|
|
39
39
|
marginRight: '$6',
|
|
40
40
|
'& img': {
|
|
41
41
|
borderRadius: '50%',
|
|
42
|
-
}
|
|
42
|
+
},
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
export type LayoutProps = {
|
|
@@ -48,10 +48,10 @@ export type LayoutProps = {
|
|
|
48
48
|
|
|
49
49
|
export function Layout({ config }: LayoutProps) {
|
|
50
50
|
const navigate = useNavigate();
|
|
51
|
-
const {
|
|
51
|
+
const { connectedWallets, selectedWallets } = useWalletsStore();
|
|
52
52
|
const { getWalletInfo } = useWallets();
|
|
53
53
|
const connectedWalletsImages = removeDuplicateFrom(
|
|
54
|
-
getSelectableWallets(
|
|
54
|
+
getSelectableWallets(connectedWallets, selectedWallets, getWalletInfo).map(
|
|
55
55
|
(w) => w.image
|
|
56
56
|
)
|
|
57
57
|
);
|
|
@@ -63,7 +63,7 @@ export function Layout({ config }: LayoutProps) {
|
|
|
63
63
|
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
64
64
|
const setAffiliateRef = useSettingsStore.use.setAffiliateRef();
|
|
65
65
|
|
|
66
|
-
const totalBalance = calculateWalletUsdValue(
|
|
66
|
+
const totalBalance = calculateWalletUsdValue(connectedWallets);
|
|
67
67
|
const connectWalletsButtonDisabled =
|
|
68
68
|
useUiStore.use.connectWalletsButtonDisabled();
|
|
69
69
|
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
@@ -126,7 +126,7 @@ export function Layout({ config }: LayoutProps) {
|
|
|
126
126
|
)}
|
|
127
127
|
<div className="balance">
|
|
128
128
|
<Typography variant="body2">
|
|
129
|
-
{!
|
|
129
|
+
{!connectedWallets?.length
|
|
130
130
|
? t('Connect Wallet')
|
|
131
131
|
: `$${totalBalance || 0}`}
|
|
132
132
|
</Typography>
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { styled } from '@rango-dev/ui';
|
|
2
|
+
import { styled, ChevronRightIcon, GasIcon, Spacer } from '@rango-dev/ui';
|
|
3
3
|
import { BestRouteResponse } from 'rango-sdk';
|
|
4
|
-
import { ChevronRightIcon } from '@rango-dev/ui';
|
|
5
|
-
import { GasIcon } from '@rango-dev/ui';
|
|
6
|
-
import { Spacer } from '@rango-dev/ui';
|
|
7
4
|
|
|
8
5
|
export const Container = styled('div', {
|
|
9
6
|
display: 'flex',
|
|
@@ -37,7 +37,7 @@ const Box = styled('div', {
|
|
|
37
37
|
display: 'flex',
|
|
38
38
|
flexDirection: 'column',
|
|
39
39
|
width: '100%',
|
|
40
|
-
overflow: 'hidden'
|
|
40
|
+
overflow: 'hidden',
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
const Container = styled('div', {
|
|
@@ -132,7 +132,7 @@ export function TokenInfo(props: PropTypes) {
|
|
|
132
132
|
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
133
133
|
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
134
134
|
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
135
|
-
const
|
|
135
|
+
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
136
136
|
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
137
137
|
const navigate = useNavigate();
|
|
138
138
|
const { t } = useTranslation();
|
|
@@ -141,7 +141,7 @@ export function TokenInfo(props: PropTypes) {
|
|
|
141
141
|
!!fromChain && !!fromToken
|
|
142
142
|
? numberToString(
|
|
143
143
|
getBalanceFromWallet(
|
|
144
|
-
|
|
144
|
+
connectedWallets,
|
|
145
145
|
fromChain?.name,
|
|
146
146
|
fromToken?.symbol,
|
|
147
147
|
fromToken?.address
|
|
@@ -154,13 +154,13 @@ export function TokenInfo(props: PropTypes) {
|
|
|
154
154
|
!!fromChain && !!fromToken
|
|
155
155
|
? numberToString(
|
|
156
156
|
getBalanceFromWallet(
|
|
157
|
-
|
|
157
|
+
connectedWallets,
|
|
158
158
|
fromChain?.name,
|
|
159
159
|
fromToken?.symbol,
|
|
160
160
|
fromToken?.address
|
|
161
161
|
)?.amount || '0',
|
|
162
162
|
getBalanceFromWallet(
|
|
163
|
-
|
|
163
|
+
connectedWallets,
|
|
164
164
|
fromChain?.name,
|
|
165
165
|
fromToken?.symbol,
|
|
166
166
|
fromToken?.address
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Button,
|
|
4
|
+
InfoCircleIcon,
|
|
5
|
+
styled,
|
|
6
|
+
Typography,
|
|
7
|
+
Spacer,
|
|
8
|
+
Image,
|
|
9
|
+
} from '@rango-dev/ui';
|
|
3
10
|
import { LoadingStatus } from '../store/meta';
|
|
4
11
|
import { useTranslation } from 'react-i18next';
|
|
5
|
-
import { Spacer } from '@rango-dev/ui';
|
|
6
12
|
import BigNumber from 'bignumber.js';
|
|
7
13
|
import { numberToString } from '../utils/numbers';
|
|
8
|
-
import { Image } from '@rango-dev/ui';
|
|
9
14
|
|
|
10
15
|
const Box = styled('div', {
|
|
11
16
|
display: 'flex',
|
|
@@ -51,7 +51,7 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
51
51
|
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
52
52
|
const affiliateRef = useSettingsStore.use.affiliateRef();
|
|
53
53
|
|
|
54
|
-
const
|
|
54
|
+
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
55
55
|
const selectedWallets = useWalletsStore.use.selectedWallets();
|
|
56
56
|
const meta = useMetaStore.use.meta();
|
|
57
57
|
const customSlippage = useSettingsStore.use.customSlippage();
|
|
@@ -108,7 +108,7 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
108
108
|
fromToken,
|
|
109
109
|
toToken,
|
|
110
110
|
inputAmount,
|
|
111
|
-
|
|
111
|
+
connectedWallets,
|
|
112
112
|
selectedWallets,
|
|
113
113
|
disabledLiquiditySources,
|
|
114
114
|
userSlippage,
|
|
@@ -40,7 +40,7 @@ export function ConfirmSwapPage() {
|
|
|
40
40
|
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
41
41
|
const { blockchains, tokens } = useMetaStore.use.meta();
|
|
42
42
|
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
43
|
-
const
|
|
43
|
+
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
44
44
|
const selectedWallets = useWalletsStore.use.selectedWallets();
|
|
45
45
|
const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
|
|
46
46
|
const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
|
|
@@ -87,7 +87,7 @@ export function ConfirmSwapPage() {
|
|
|
87
87
|
}, []);
|
|
88
88
|
|
|
89
89
|
const selectableWallets = getSelectableWallets(
|
|
90
|
-
|
|
90
|
+
connectedWallets,
|
|
91
91
|
selectedWallets,
|
|
92
92
|
getWalletInfo
|
|
93
93
|
);
|
package/src/pages/Home.tsx
CHANGED
|
@@ -83,7 +83,7 @@ export function Home() {
|
|
|
83
83
|
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
84
84
|
const bestRouteError = useBestRouteStore.use.error();
|
|
85
85
|
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
86
|
-
const
|
|
86
|
+
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
87
87
|
const setCurrentPage = useUiStore.use.setCurrentPage();
|
|
88
88
|
const switchFromAndTo = useBestRouteStore.use.switchFromAndTo();
|
|
89
89
|
|
|
@@ -113,7 +113,7 @@ export function Home() {
|
|
|
113
113
|
|
|
114
114
|
const swapButtonState = getSwapButtonState(
|
|
115
115
|
loadingMetaStatus,
|
|
116
|
-
|
|
116
|
+
connectedWallets,
|
|
117
117
|
fetchingBestRoute,
|
|
118
118
|
bestRoute,
|
|
119
119
|
hasLimitError(bestRoute),
|
|
@@ -139,7 +139,9 @@ export function Home() {
|
|
|
139
139
|
title="SWAP"
|
|
140
140
|
suffix={
|
|
141
141
|
<HeaderButtons
|
|
142
|
-
onClickRefresh={
|
|
142
|
+
onClickRefresh={
|
|
143
|
+
!!bestRoute || bestRouteError ? fetchBestRoute : undefined
|
|
144
|
+
}
|
|
143
145
|
/>
|
|
144
146
|
}
|
|
145
147
|
/>
|
package/src/store/bestRoute.ts
CHANGED
|
@@ -105,11 +105,11 @@ export const useBestRouteStore = createSelectors(
|
|
|
105
105
|
set((state) => {
|
|
106
106
|
if (state.fromChain?.name === chain?.name) return {};
|
|
107
107
|
const tokens = useMetaStore.getState().meta.tokens;
|
|
108
|
-
const
|
|
108
|
+
const connectedWallets = useWalletsStore.getState().connectedWallets;
|
|
109
109
|
const sortedTokens = getSortedTokens(
|
|
110
110
|
chain,
|
|
111
111
|
tokens,
|
|
112
|
-
|
|
112
|
+
connectedWallets,
|
|
113
113
|
state.destinationTokens
|
|
114
114
|
);
|
|
115
115
|
const fromToken = getDefaultToken(sortedTokens, state.toToken);
|
|
@@ -136,11 +136,11 @@ export const useBestRouteStore = createSelectors(
|
|
|
136
136
|
set((state) => {
|
|
137
137
|
if (state.toChain?.name === chain?.name) return {};
|
|
138
138
|
const tokens = useMetaStore.getState().meta.tokens;
|
|
139
|
-
const
|
|
139
|
+
const connectedWallets = useWalletsStore.getState().connectedWallets;
|
|
140
140
|
const sortedTokens = getSortedTokens(
|
|
141
141
|
chain,
|
|
142
142
|
tokens,
|
|
143
|
-
|
|
143
|
+
connectedWallets,
|
|
144
144
|
state.destinationTokens
|
|
145
145
|
);
|
|
146
146
|
|
|
@@ -173,7 +173,7 @@ export const useBestRouteStore = createSelectors(
|
|
|
173
173
|
},
|
|
174
174
|
retry: (pendingSwap) => {
|
|
175
175
|
const { tokens, blockchains } = useMetaStore.getState().meta;
|
|
176
|
-
const
|
|
176
|
+
const connectedWallets = useWalletsStore.getState().connectedWallets;
|
|
177
177
|
const failedIndex =
|
|
178
178
|
pendingSwap.status === 'failed'
|
|
179
179
|
? pendingSwap.steps.findIndex((s) => s.status === 'failed')
|
|
@@ -210,13 +210,13 @@ export const useBestRouteStore = createSelectors(
|
|
|
210
210
|
const sortedSourceTokens = getSortedTokens(
|
|
211
211
|
fromChain,
|
|
212
212
|
tokens,
|
|
213
|
-
|
|
213
|
+
connectedWallets,
|
|
214
214
|
[]
|
|
215
215
|
);
|
|
216
216
|
const sortedDestinationTokens = getSortedTokens(
|
|
217
217
|
toChain,
|
|
218
218
|
tokens,
|
|
219
|
-
|
|
219
|
+
connectedWallets,
|
|
220
220
|
[]
|
|
221
221
|
);
|
|
222
222
|
const inputAmount = pendingSwap.inputAmount;
|
package/src/store/wallets.ts
CHANGED
|
@@ -2,26 +2,20 @@ import { SelectableWallet } from '@rango-dev/ui';
|
|
|
2
2
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
3
3
|
import { create } from 'zustand';
|
|
4
4
|
import { subscribeWithSelector } from 'zustand/middleware';
|
|
5
|
+
import { shallow } from 'zustand/shallow';
|
|
5
6
|
import { httpService } from '../services/httpService';
|
|
6
7
|
import {
|
|
7
8
|
getRequiredChains,
|
|
8
9
|
getTokensWithBalance,
|
|
9
|
-
|
|
10
|
+
isAccountAndWalletMatched,
|
|
10
11
|
makeBalanceFor,
|
|
11
|
-
|
|
12
|
-
SelectedWallet,
|
|
12
|
+
resetConnectedWalletState,
|
|
13
13
|
sortTokens,
|
|
14
14
|
} from '../utils/wallets';
|
|
15
15
|
import { useBestRouteStore } from './bestRoute';
|
|
16
16
|
import { useMetaStore } from './meta';
|
|
17
17
|
import createSelectors from './selectors';
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
export interface Account {
|
|
21
|
-
chain: string;
|
|
22
|
-
address: string;
|
|
23
|
-
walletType: WalletType;
|
|
24
|
-
}
|
|
18
|
+
import { Wallet } from '../types';
|
|
25
19
|
|
|
26
20
|
export type TokenBalance = {
|
|
27
21
|
chain: string;
|
|
@@ -35,39 +29,33 @@ export type TokenBalance = {
|
|
|
35
29
|
usdPrice: number | null;
|
|
36
30
|
};
|
|
37
31
|
|
|
38
|
-
export interface
|
|
32
|
+
export interface ConnectedWallet extends Wallet {
|
|
39
33
|
balances: TokenBalance[] | null;
|
|
40
|
-
address: string;
|
|
41
|
-
chain: string;
|
|
42
34
|
loading: boolean;
|
|
43
|
-
walletType: WalletType;
|
|
44
35
|
error: boolean;
|
|
45
36
|
explorerUrl: string | null;
|
|
46
37
|
}
|
|
47
38
|
|
|
48
39
|
interface WalletsStore {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
connectWallet: (accounts: Account[]) => void;
|
|
40
|
+
connectedWallets: ConnectedWallet[];
|
|
41
|
+
selectedWallets: Wallet[];
|
|
42
|
+
connectWallet: (accounts: Wallet[]) => void;
|
|
53
43
|
disconnectWallet: (walletType: WalletType) => void;
|
|
54
44
|
initSelectedWallets: () => void;
|
|
55
45
|
setSelectedWallet: (wallet: SelectableWallet) => void;
|
|
56
46
|
clearConnectedWallet: () => void;
|
|
57
|
-
getOneOfWalletsDetails: (account:
|
|
47
|
+
getOneOfWalletsDetails: (account: Wallet) => void;
|
|
58
48
|
}
|
|
59
49
|
|
|
60
50
|
export const useWalletsStore = createSelectors(
|
|
61
51
|
create<WalletsStore>()(
|
|
62
52
|
subscribeWithSelector((set, get) => ({
|
|
63
|
-
|
|
64
|
-
balances: [],
|
|
53
|
+
connectedWallets: [],
|
|
65
54
|
selectedWallets: [],
|
|
66
55
|
connectWallet: (accounts) => {
|
|
67
56
|
const getOneOfWalletsDetails = get().getOneOfWalletsDetails;
|
|
68
57
|
set((state) => ({
|
|
69
|
-
|
|
70
|
-
balances: state.balances.concat(
|
|
58
|
+
connectedWallets: state.connectedWallets.concat(
|
|
71
59
|
accounts.map((account) => ({
|
|
72
60
|
balances: [],
|
|
73
61
|
address: account.address,
|
|
@@ -83,10 +71,7 @@ export const useWalletsStore = createSelectors(
|
|
|
83
71
|
},
|
|
84
72
|
disconnectWallet: (walletType) => {
|
|
85
73
|
set((state) => ({
|
|
86
|
-
|
|
87
|
-
(account) => account.walletType !== walletType
|
|
88
|
-
),
|
|
89
|
-
balances: state.balances.filter(
|
|
74
|
+
connectedWallets: state.connectedWallets.filter(
|
|
90
75
|
(balance) => balance.walletType !== walletType
|
|
91
76
|
),
|
|
92
77
|
selectedWallets: state.selectedWallets.filter(
|
|
@@ -99,8 +84,8 @@ export const useWalletsStore = createSelectors(
|
|
|
99
84
|
const requiredChains = getRequiredChains(
|
|
100
85
|
useBestRouteStore.getState().bestRoute
|
|
101
86
|
);
|
|
102
|
-
const connectedWallets = state.
|
|
103
|
-
const selectedWallets:
|
|
87
|
+
const connectedWallets = state.connectedWallets;
|
|
88
|
+
const selectedWallets: Wallet[] = [];
|
|
104
89
|
requiredChains.forEach((chain) => {
|
|
105
90
|
const anyWalletSelected = !!state.selectedWallets.find(
|
|
106
91
|
(wallet) => wallet.chain === chain
|
|
@@ -134,14 +119,13 @@ export const useWalletsStore = createSelectors(
|
|
|
134
119
|
|
|
135
120
|
clearConnectedWallet: () =>
|
|
136
121
|
set(() => ({
|
|
137
|
-
|
|
138
|
-
balances: [],
|
|
122
|
+
connectedWallets: [],
|
|
139
123
|
selectedWallets: [],
|
|
140
124
|
})),
|
|
141
|
-
getOneOfWalletsDetails: async (account:
|
|
125
|
+
getOneOfWalletsDetails: async (account: Wallet) => {
|
|
142
126
|
const tokens = useMetaStore.getState().meta.tokens;
|
|
143
127
|
set((state) => ({
|
|
144
|
-
|
|
128
|
+
connectedWallets: state.connectedWallets.map((balance) => {
|
|
145
129
|
return balance.address === account.address &&
|
|
146
130
|
balance.chain === account.chain
|
|
147
131
|
? { ...balance, loading: true }
|
|
@@ -155,18 +139,20 @@ export const useWalletsStore = createSelectors(
|
|
|
155
139
|
const retrivedBalance = response.wallets[0];
|
|
156
140
|
if (retrivedBalance) {
|
|
157
141
|
set((state) => ({
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
142
|
+
connectedWallets: state.connectedWallets.map(
|
|
143
|
+
(connectedWallet) => {
|
|
144
|
+
return isAccountAndWalletMatched(account, connectedWallet)
|
|
145
|
+
? makeBalanceFor(account, retrivedBalance, tokens)
|
|
146
|
+
: connectedWallet;
|
|
147
|
+
}
|
|
148
|
+
),
|
|
163
149
|
}));
|
|
164
150
|
} else throw new Error('Wallet not found');
|
|
165
151
|
} catch (error) {
|
|
166
152
|
set((state) => ({
|
|
167
|
-
|
|
168
|
-
return
|
|
169
|
-
?
|
|
153
|
+
connectedWallets: state.connectedWallets.map((balance) => {
|
|
154
|
+
return isAccountAndWalletMatched(account, balance)
|
|
155
|
+
? resetConnectedWalletState(balance)
|
|
170
156
|
: balance;
|
|
171
157
|
}),
|
|
172
158
|
}));
|
|
@@ -177,16 +163,16 @@ export const useWalletsStore = createSelectors(
|
|
|
177
163
|
);
|
|
178
164
|
|
|
179
165
|
useWalletsStore.subscribe(
|
|
180
|
-
(state) => state.
|
|
181
|
-
(
|
|
166
|
+
(state) => state.connectedWallets,
|
|
167
|
+
(connectedWallets) => {
|
|
182
168
|
useBestRouteStore.setState(({ sourceTokens, destinationTokens }) => {
|
|
183
169
|
const sourceTokensWithBalance = getTokensWithBalance(
|
|
184
170
|
sourceTokens,
|
|
185
|
-
|
|
171
|
+
connectedWallets
|
|
186
172
|
);
|
|
187
173
|
const destinationTokensWithBalance = getTokensWithBalance(
|
|
188
174
|
destinationTokens,
|
|
189
|
-
|
|
175
|
+
connectedWallets
|
|
190
176
|
);
|
|
191
177
|
return {
|
|
192
178
|
sourceTokens: sortTokens(sourceTokensWithBalance),
|
|
@@ -200,4 +186,4 @@ useWalletsStore.subscribe(
|
|
|
200
186
|
);
|
|
201
187
|
|
|
202
188
|
export const fetchingBalanceSelector = (state: WalletsStore) =>
|
|
203
|
-
!!state.
|
|
189
|
+
!!state.connectedWallets.find((wallet) => wallet.loading);
|
package/src/types/index.ts
CHANGED
package/src/utils/routing.ts
CHANGED
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
import BigNumber from 'bignumber.js';
|
|
6
6
|
import { BestRouteResponse, BlockchainMeta, Token } from 'rango-sdk';
|
|
7
7
|
import { areEqual } from './common';
|
|
8
|
-
import {
|
|
9
|
-
import { BestRouteEqualityParams } from '../types';
|
|
8
|
+
import { BestRouteEqualityParams, Wallet } from '../types';
|
|
10
9
|
import { numberToString } from './numbers';
|
|
11
10
|
import { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
12
11
|
|
|
@@ -96,7 +95,7 @@ export function outToRatioHasWarning(
|
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
export function getRequiredBalanceOfWallet(
|
|
99
|
-
selectedWallet:
|
|
98
|
+
selectedWallet: Wallet,
|
|
100
99
|
fee: SimulationValidationStatus[] | null
|
|
101
100
|
): SimulationAssetAndAmount[] | null {
|
|
102
101
|
if (fee === null) return null;
|
package/src/utils/swap.ts
CHANGED
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
SwapResult,
|
|
7
7
|
Token,
|
|
8
8
|
} from 'rango-sdk';
|
|
9
|
-
import {
|
|
9
|
+
import { ConnectedWallet } from '../store/wallets';
|
|
10
10
|
import { ZERO } from '../constants/numbers';
|
|
11
11
|
import { numberToString } from './numbers';
|
|
12
12
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
13
13
|
import { getRequiredBalanceOfWallet } from './routing';
|
|
14
|
-
import { getRequiredChains
|
|
14
|
+
import { getRequiredChains } from './wallets';
|
|
15
15
|
import { LoadingStatus } from '../store/meta';
|
|
16
|
-
import { ConvertedToken, SwapButtonState } from '../types';
|
|
16
|
+
import { ConvertedToken, SwapButtonState, Wallet } from '../types';
|
|
17
17
|
import {
|
|
18
18
|
PendingSwapNetworkStatus,
|
|
19
19
|
PendingSwapStep,
|
|
@@ -122,7 +122,7 @@ export function LimitErrorMessage(bestRoute: BestRouteResponse | null): {
|
|
|
122
122
|
|
|
123
123
|
export function getSwapButtonState(
|
|
124
124
|
loadingMetaStatus: LoadingStatus,
|
|
125
|
-
|
|
125
|
+
connectedWallets: ConnectedWallet[],
|
|
126
126
|
loading: boolean,
|
|
127
127
|
bestRoute: BestRouteResponse | null,
|
|
128
128
|
hasLimitError: boolean,
|
|
@@ -133,7 +133,8 @@ export function getSwapButtonState(
|
|
|
133
133
|
): SwapButtonState {
|
|
134
134
|
if (loadingMetaStatus !== 'success')
|
|
135
135
|
return { title: 'Connect Wallet', disabled: true };
|
|
136
|
-
if (
|
|
136
|
+
if (connectedWallets.length == 0)
|
|
137
|
+
return { title: 'Connect Wallet', disabled: false };
|
|
137
138
|
if (loading) return { title: 'Finding Best Route...', disabled: true };
|
|
138
139
|
else if (!inputAmount || inputAmount === '0')
|
|
139
140
|
return { title: 'Enter an amount', disabled: true };
|
|
@@ -276,7 +277,7 @@ export function hasProperSlippage(
|
|
|
276
277
|
|
|
277
278
|
export function hasEnoughBalance(
|
|
278
279
|
route: BestRouteResponse,
|
|
279
|
-
selectedWallets:
|
|
280
|
+
selectedWallets: Wallet[]
|
|
280
281
|
) {
|
|
281
282
|
const fee = route.validationStatus;
|
|
282
283
|
|
|
@@ -297,7 +298,7 @@ export function hasEnoughBalance(
|
|
|
297
298
|
|
|
298
299
|
export function hasEnoughBalanceAndProperSlippage(
|
|
299
300
|
route: BestRouteResponse,
|
|
300
|
-
selectedWallets:
|
|
301
|
+
selectedWallets: Wallet[],
|
|
301
302
|
userSlippage: string,
|
|
302
303
|
minRequiredSlippage: string | null
|
|
303
304
|
): boolean {
|
|
@@ -311,8 +312,8 @@ export function createBestRouteRequestBody(
|
|
|
311
312
|
fromToken: Token,
|
|
312
313
|
toToken: Token,
|
|
313
314
|
inputAmount: string,
|
|
314
|
-
wallets:
|
|
315
|
-
selectedWallets:
|
|
315
|
+
wallets: ConnectedWallet[],
|
|
316
|
+
selectedWallets: Wallet[],
|
|
316
317
|
disabledLiquiditySources: string[],
|
|
317
318
|
slippage: number,
|
|
318
319
|
affiliateRef: string | null,
|
|
@@ -379,7 +380,7 @@ export function createBestRouteRequestBody(
|
|
|
379
380
|
return requestBody;
|
|
380
381
|
}
|
|
381
382
|
|
|
382
|
-
export function getWalletsForNewSwap(selectedWallets:
|
|
383
|
+
export function getWalletsForNewSwap(selectedWallets: Wallet[]) {
|
|
383
384
|
const wallets = selectedWallets.reduce(
|
|
384
385
|
(
|
|
385
386
|
selectedWalletsMap: {
|
|
@@ -432,7 +433,7 @@ export function isOutputAmountChangedALot(
|
|
|
432
433
|
|
|
433
434
|
export function getBalanceWarnings(
|
|
434
435
|
route: BestRouteResponse,
|
|
435
|
-
selectedWallets:
|
|
436
|
+
selectedWallets: Wallet[]
|
|
436
437
|
) {
|
|
437
438
|
const fee = route.validationStatus;
|
|
438
439
|
const requiredWallets = getRequiredChains(route);
|