@rango-dev/widget-embedded 0.12.1-next.30 → 0.12.1-next.31
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/Widget.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +2 -0
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/BlockchainsSection/BlockchainsSection.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.helpers.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.types.d.ts +0 -1
- package/dist/components/TokenList/TokenList.types.d.ts.map +1 -1
- package/dist/components/UpdateUrl.d.ts +6 -1
- package/dist/components/UpdateUrl.d.ts.map +1 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList.d.ts +18 -0
- package/dist/hooks/usePrepareBlockchainList.d.ts.map +1 -0
- package/dist/hooks/useSyncStoresWithConfig.d.ts +3 -0
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -0
- package/dist/hooks/useWalletProviders.d.ts +3 -3
- package/dist/hooks/useWalletProviders.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/SelectBlockchainPage.d.ts +1 -2
- package/dist/pages/SelectBlockchainPage.d.ts.map +1 -1
- package/dist/pages/SelectSwapItemsPage.d.ts +1 -5
- package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
- package/dist/services/httpService.d.ts +0 -1
- package/dist/services/httpService.d.ts.map +1 -1
- package/dist/store/app.d.ts +26 -0
- package/dist/store/app.d.ts.map +1 -0
- package/dist/store/bestRoute.d.ts +4 -8
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/meta.d.ts +0 -2
- package/dist/store/meta.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts +8 -0
- package/dist/store/slices/config.d.ts.map +1 -0
- package/dist/store/slices/data.d.ts +26 -0
- package/dist/store/slices/data.d.ts.map +1 -0
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +3 -0
- package/dist/utils/configs.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +1 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/Widget.tsx +11 -62
- package/src/components/AppRouter.tsx +3 -1
- package/src/components/AppRoutes.tsx +4 -28
- package/src/components/BlockchainsSection/BlockchainsSection.tsx +19 -41
- package/src/components/TokenList/TokenList.helpers.ts +6 -8
- package/src/components/TokenList/TokenList.tsx +24 -20
- package/src/components/TokenList/TokenList.types.ts +0 -1
- package/src/components/UpdateUrl.tsx +7 -1
- package/src/constants.ts +1 -0
- package/src/hooks/usePrepareBlockchainList.ts +122 -0
- package/src/hooks/useSyncStoresWithConfig.ts +102 -0
- package/src/hooks/useWalletProviders.ts +7 -7
- package/src/pages/SelectBlockchainPage.tsx +18 -23
- package/src/pages/SelectSwapItemsPage.tsx +52 -90
- package/src/services/httpService.ts +4 -5
- package/src/store/app.ts +15 -0
- package/src/store/bestRoute.ts +45 -71
- package/src/store/meta.ts +11 -29
- package/src/store/slices/config.ts +26 -0
- package/src/store/slices/data.ts +203 -0
- package/src/store/wallets.ts +0 -27
- package/src/utils/configs.ts +5 -2
- package/src/utils/wallets.ts +38 -18
- package/dist/components/BlockchainsSection/BlockchainSection.helpers.d.ts +0 -3
- package/dist/components/BlockchainsSection/BlockchainSection.helpers.d.ts.map +0 -1
- package/src/components/BlockchainsSection/BlockchainSection.helpers.ts +0 -20
|
@@ -1,43 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
import type { Asset, Token } from 'rango-sdk';
|
|
1
|
+
import type { BlockchainMeta, Token } from 'rango-sdk';
|
|
3
2
|
|
|
4
3
|
import { i18n } from '@lingui/core';
|
|
5
4
|
import { Divider } from '@rango-dev/ui';
|
|
6
|
-
import React, {
|
|
5
|
+
import React, { useState } from 'react';
|
|
7
6
|
import { useNavigate } from 'react-router-dom';
|
|
8
7
|
|
|
9
8
|
import { BlockchainsSection } from '../components/BlockchainsSection';
|
|
10
9
|
import { Layout } from '../components/Layout';
|
|
11
10
|
import { SearchInput } from '../components/SearchInput';
|
|
12
11
|
import { TokenList } from '../components/TokenList/TokenList';
|
|
13
|
-
import { filterTokens } from '../components/TokenList/TokenList.helpers';
|
|
14
12
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
15
13
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
14
|
+
import { useAppStore } from '../store/app';
|
|
16
15
|
import { useBestRouteStore } from '../store/bestRoute';
|
|
17
|
-
import { useMetaStore } from '../store/meta';
|
|
18
16
|
import { useWalletsStore } from '../store/wallets';
|
|
19
|
-
import {
|
|
20
|
-
import { tokensAreEqual } from '../utils/wallets';
|
|
17
|
+
import { getTokensBalanceFromWalletAndSort } from '../utils/wallets';
|
|
21
18
|
|
|
22
19
|
interface PropTypes {
|
|
23
|
-
type: '
|
|
24
|
-
supportedBlockchains?: string[];
|
|
25
|
-
supportedTokens?: Asset[];
|
|
26
|
-
pinnedTokens?: Asset[];
|
|
20
|
+
type: 'source' | 'destination';
|
|
27
21
|
}
|
|
28
22
|
|
|
29
23
|
export function SelectSwapItemsPage(props: PropTypes) {
|
|
30
|
-
const { type
|
|
31
|
-
const [selectedBlockchain, setSelectedBlockchain] = useState('');
|
|
24
|
+
const { type } = props;
|
|
32
25
|
const navigate = useNavigate();
|
|
33
26
|
const { navigateBackFrom } = useNavigateBack();
|
|
34
27
|
const {
|
|
35
|
-
meta: { tokens },
|
|
36
|
-
setTokensWithBalance,
|
|
37
|
-
} = useMetaStore();
|
|
38
|
-
const {
|
|
39
|
-
sourceTokens,
|
|
40
|
-
destinationTokens,
|
|
41
28
|
fromBlockchain,
|
|
42
29
|
toBlockchain,
|
|
43
30
|
setFromToken,
|
|
@@ -45,89 +32,69 @@ export function SelectSwapItemsPage(props: PropTypes) {
|
|
|
45
32
|
setFromBlockchain,
|
|
46
33
|
setToBlockchain,
|
|
47
34
|
} = useBestRouteStore();
|
|
48
|
-
const { connectedWallets
|
|
35
|
+
const { connectedWallets } = useWalletsStore();
|
|
49
36
|
const [searchedFor, setSearchedFor] = useState<string>('');
|
|
50
37
|
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
.meta()
|
|
54
|
-
.blockchains.filter((chain) =>
|
|
55
|
-
supportedBlockchains.includes(chain.name)
|
|
56
|
-
)
|
|
57
|
-
: useMetaStore.use.meta().blockchains;
|
|
58
|
-
|
|
59
|
-
const allTokens = supportedTokens
|
|
60
|
-
? findCommonTokens(supportedTokens, tokens)
|
|
61
|
-
: tokens.filter((token) =>
|
|
62
|
-
new Set(blockchains.map((blockchain) => blockchain.name)).has(
|
|
63
|
-
token.blockchain
|
|
64
|
-
)
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
const supportedSourceTokens = supportedTokens
|
|
68
|
-
? findCommonTokens(supportedTokens, sourceTokens)
|
|
69
|
-
: sourceTokens;
|
|
70
|
-
|
|
71
|
-
const supportedDestinationTokens = supportedTokens
|
|
72
|
-
? findCommonTokens(supportedTokens, destinationTokens)
|
|
73
|
-
: destinationTokens;
|
|
74
|
-
|
|
75
|
-
const tokensByType =
|
|
76
|
-
type === 'from' ? supportedSourceTokens : supportedDestinationTokens;
|
|
77
|
-
|
|
78
|
-
let tokenList: Token[] = [];
|
|
38
|
+
const selectedBlockchain = type === 'source' ? fromBlockchain : toBlockchain;
|
|
39
|
+
const selectedBlockchainName = selectedBlockchain?.name ?? '';
|
|
79
40
|
|
|
80
|
-
|
|
81
|
-
|
|
41
|
+
// Tokens & Blockchains list
|
|
42
|
+
const blockchains = useAppStore().blockchains({
|
|
43
|
+
type: type,
|
|
44
|
+
});
|
|
45
|
+
const tokens = useAppStore().tokens({
|
|
46
|
+
type,
|
|
47
|
+
blockchain: selectedBlockchainName,
|
|
48
|
+
searchFor: searchedFor,
|
|
49
|
+
});
|
|
50
|
+
const tokensList = getTokensBalanceFromWalletAndSort(
|
|
51
|
+
tokens,
|
|
52
|
+
connectedWallets
|
|
53
|
+
);
|
|
82
54
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}));
|
|
92
|
-
}
|
|
55
|
+
// Actions
|
|
56
|
+
const updateBlockchain = (blockchain: BlockchainMeta) => {
|
|
57
|
+
if (type === 'source') {
|
|
58
|
+
setFromBlockchain(blockchain);
|
|
59
|
+
} else {
|
|
60
|
+
setToBlockchain(blockchain);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
93
63
|
|
|
94
|
-
|
|
95
|
-
if (
|
|
96
|
-
|
|
64
|
+
const updateToken = (token: Token) => {
|
|
65
|
+
if (type === 'source') {
|
|
66
|
+
setFromToken(token);
|
|
67
|
+
} else {
|
|
68
|
+
setToToken(token);
|
|
97
69
|
}
|
|
98
|
-
}
|
|
70
|
+
};
|
|
99
71
|
|
|
100
72
|
return (
|
|
101
73
|
<Layout
|
|
102
74
|
header={{
|
|
103
75
|
onBack: () =>
|
|
104
76
|
navigateBackFrom(
|
|
105
|
-
type === '
|
|
77
|
+
type === 'source'
|
|
106
78
|
? navigationRoutes.fromSwap
|
|
107
79
|
: navigationRoutes.toSwap
|
|
108
80
|
),
|
|
109
|
-
title: i18n.t('Swap {type}', {
|
|
81
|
+
title: i18n.t('Swap {type}', {
|
|
82
|
+
type: type === 'source' ? 'from' : 'to',
|
|
83
|
+
}),
|
|
110
84
|
}}>
|
|
111
85
|
<BlockchainsSection
|
|
112
86
|
blockchains={blockchains}
|
|
113
|
-
type={type}
|
|
114
|
-
blockchain={type === '
|
|
87
|
+
type={type == 'source' ? 'from' : 'to'}
|
|
88
|
+
blockchain={type === 'source' ? fromBlockchain : toBlockchain}
|
|
115
89
|
onMoreClick={() =>
|
|
116
90
|
navigate(
|
|
117
|
-
type === '
|
|
91
|
+
type === 'source'
|
|
118
92
|
? navigationRoutes.fromBlockchain
|
|
119
93
|
: navigationRoutes.toBlockchain
|
|
120
94
|
)
|
|
121
95
|
}
|
|
122
96
|
onChange={(blockchain) => {
|
|
123
|
-
|
|
124
|
-
if (type === 'from') {
|
|
125
|
-
setFromBlockchain(blockchain, true);
|
|
126
|
-
} else {
|
|
127
|
-
setToBlockchain(blockchain, true);
|
|
128
|
-
}
|
|
129
|
-
setSelectedBlockchain(blockchain.name);
|
|
130
|
-
}
|
|
97
|
+
updateBlockchain(blockchain);
|
|
131
98
|
}}
|
|
132
99
|
/>
|
|
133
100
|
<Divider size={24} />
|
|
@@ -143,24 +110,19 @@ export function SelectSwapItemsPage(props: PropTypes) {
|
|
|
143
110
|
/>
|
|
144
111
|
<Divider size={16} />
|
|
145
112
|
<TokenList
|
|
146
|
-
list={
|
|
147
|
-
selectedBlockchain={
|
|
113
|
+
list={tokensList}
|
|
114
|
+
selectedBlockchain={selectedBlockchainName}
|
|
148
115
|
searchedFor={searchedFor}
|
|
149
116
|
onChange={(token) => {
|
|
150
|
-
|
|
117
|
+
updateToken(token);
|
|
118
|
+
|
|
119
|
+
const tokenBlockchain = blockchains.find(
|
|
151
120
|
(chain) => token.blockchain === chain.name
|
|
152
121
|
);
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
if (!!blockchain) {
|
|
156
|
-
setFromBlockchain(blockchain, true);
|
|
157
|
-
}
|
|
158
|
-
} else {
|
|
159
|
-
setToToken(token);
|
|
160
|
-
if (!!blockchain) {
|
|
161
|
-
setToBlockchain(blockchain, true);
|
|
162
|
-
}
|
|
122
|
+
if (tokenBlockchain) {
|
|
123
|
+
updateBlockchain(tokenBlockchain);
|
|
163
124
|
}
|
|
125
|
+
|
|
164
126
|
navigateBackFrom(navigationRoutes.fromSwap);
|
|
165
127
|
}}
|
|
166
128
|
/>
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { RangoClient } from 'rango-sdk';
|
|
2
|
-
import { getConfig } from '../utils/configs';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
// it is only for test purpose
|
|
6
|
-
export const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
|
|
3
|
+
import { getConfig } from '../utils/configs';
|
|
7
4
|
|
|
8
5
|
let rango: RangoClient | undefined = undefined;
|
|
9
6
|
|
|
10
7
|
export const httpService = () => {
|
|
11
|
-
if (rango)
|
|
8
|
+
if (rango) {
|
|
9
|
+
return rango;
|
|
10
|
+
}
|
|
12
11
|
rango = new RangoClient(getConfig('API_KEY'));
|
|
13
12
|
return rango;
|
|
14
13
|
};
|
package/src/store/app.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ConfigSlice } from './slices/config';
|
|
2
|
+
import type { DataSlice } from './slices/data';
|
|
3
|
+
|
|
4
|
+
import { create } from 'zustand';
|
|
5
|
+
|
|
6
|
+
import createSelectors from './selectors';
|
|
7
|
+
import { createConfigSlice } from './slices/config';
|
|
8
|
+
import { createDataSlice } from './slices/data';
|
|
9
|
+
|
|
10
|
+
const store = create<DataSlice & ConfigSlice>()((...a) => ({
|
|
11
|
+
...createDataSlice(...a),
|
|
12
|
+
...createConfigSlice(...a),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
export const useAppStore = createSelectors(store);
|
package/src/store/bestRoute.ts
CHANGED
|
@@ -11,15 +11,10 @@ import { ZERO } from '../constants/numbers';
|
|
|
11
11
|
import { isPositiveNumber } from '../utils/numbers';
|
|
12
12
|
import { getBestRouteToTokenUsdPrice } from '../utils/routing';
|
|
13
13
|
import { calcOutputUsdValue } from '../utils/swap';
|
|
14
|
-
import {
|
|
15
|
-
getDefaultToken,
|
|
16
|
-
getSortedTokens,
|
|
17
|
-
tokensAreEqual,
|
|
18
|
-
} from '../utils/wallets';
|
|
14
|
+
import { tokensAreEqual } from '../utils/wallets';
|
|
19
15
|
|
|
20
16
|
import { useMetaStore } from './meta';
|
|
21
17
|
import createSelectors from './selectors';
|
|
22
|
-
import { useWalletsStore } from './wallets';
|
|
23
18
|
|
|
24
19
|
const getUsdValue = (token: Token | null, amount: string): BigNumber | null =>
|
|
25
20
|
token?.usdPrice
|
|
@@ -36,20 +31,12 @@ export interface RouteState {
|
|
|
36
31
|
fromToken: TokenWithBalance | null;
|
|
37
32
|
toToken: TokenWithBalance | null;
|
|
38
33
|
routeWalletsConfirmed: boolean;
|
|
39
|
-
sourceTokens: Token[];
|
|
40
|
-
destinationTokens: Token[];
|
|
41
34
|
selectedWallets: Wallet[];
|
|
42
35
|
resetRoute: () => void;
|
|
43
36
|
resetToBlockchain: () => void;
|
|
44
37
|
resetFromBlockchain: () => void;
|
|
45
|
-
setFromBlockchain: (
|
|
46
|
-
|
|
47
|
-
setDefaultToken?: boolean
|
|
48
|
-
) => void;
|
|
49
|
-
setToBlockchain: (
|
|
50
|
-
chian: BlockchainMeta | null,
|
|
51
|
-
setDefaultToken?: boolean
|
|
52
|
-
) => void;
|
|
38
|
+
setFromBlockchain: (chain: BlockchainMeta | null) => void;
|
|
39
|
+
setToBlockchain: (chian: BlockchainMeta | null) => void;
|
|
53
40
|
|
|
54
41
|
setFromToken: (token: Token | null) => void;
|
|
55
42
|
setToToken: (token: Token | null) => void;
|
|
@@ -78,8 +65,6 @@ export const useBestRouteStore = createSelectors(
|
|
|
78
65
|
toToken: null,
|
|
79
66
|
bestRoute: null,
|
|
80
67
|
routeWalletsConfirmed: false,
|
|
81
|
-
sourceTokens: [],
|
|
82
|
-
destinationTokens: [],
|
|
83
68
|
selectedWallets: [],
|
|
84
69
|
customDestination: '',
|
|
85
70
|
setRoute: (bestRoute) =>
|
|
@@ -112,66 +97,65 @@ export const useBestRouteStore = createSelectors(
|
|
|
112
97
|
outputAmount: null,
|
|
113
98
|
outputUsdValue: new BigNumber(0),
|
|
114
99
|
})),
|
|
115
|
-
setFromBlockchain: (chain
|
|
100
|
+
setFromBlockchain: (chain) => {
|
|
116
101
|
set((state) => {
|
|
117
102
|
if (state.fromBlockchain?.name === chain?.name) {
|
|
118
103
|
return {};
|
|
119
104
|
}
|
|
120
|
-
|
|
121
|
-
const connectedWallets = useWalletsStore.getState().connectedWallets;
|
|
122
|
-
const sortedTokens = getSortedTokens(
|
|
123
|
-
chain,
|
|
124
|
-
tokens,
|
|
125
|
-
connectedWallets,
|
|
126
|
-
state.destinationTokens
|
|
127
|
-
);
|
|
128
|
-
const fromToken = getDefaultToken(sortedTokens, state.toToken);
|
|
105
|
+
|
|
129
106
|
return {
|
|
130
107
|
fromBlockchain: chain,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
fromToken,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
inputUsdValue: getUsdValue(fromToken, state.inputAmount),
|
|
108
|
+
...(state.fromToken && {
|
|
109
|
+
bestRoute: null,
|
|
110
|
+
fromToken: null,
|
|
111
|
+
outputAmount: null,
|
|
112
|
+
outputUsdValue: null,
|
|
137
113
|
}),
|
|
138
114
|
};
|
|
139
115
|
});
|
|
140
116
|
},
|
|
141
|
-
setFromToken: (token) =>
|
|
142
|
-
|
|
117
|
+
setFromToken: (token) => {
|
|
118
|
+
const { blockchains } = useMetaStore.getState().meta;
|
|
119
|
+
const fromBlockchain =
|
|
120
|
+
blockchains.find(
|
|
121
|
+
(blockchain) => blockchain.name === token?.blockchain
|
|
122
|
+
) ?? null;
|
|
123
|
+
return set((state) => ({
|
|
143
124
|
fromToken: token,
|
|
125
|
+
fromBlockchain,
|
|
144
126
|
...(!!state.inputAmount && {
|
|
145
127
|
inputUsdValue: getUsdValue(token, state.inputAmount),
|
|
146
128
|
}),
|
|
147
|
-
}))
|
|
148
|
-
|
|
129
|
+
}));
|
|
130
|
+
},
|
|
131
|
+
setToBlockchain: (chain) => {
|
|
149
132
|
set((state) => {
|
|
150
133
|
if (state.toBlockchain?.name === chain?.name) {
|
|
151
134
|
return {};
|
|
152
135
|
}
|
|
153
|
-
const tokens = useMetaStore.getState().meta.tokens;
|
|
154
|
-
const connectedWallets = useWalletsStore.getState().connectedWallets;
|
|
155
|
-
const sortedTokens = getSortedTokens(
|
|
156
|
-
chain,
|
|
157
|
-
tokens,
|
|
158
|
-
connectedWallets,
|
|
159
|
-
state.destinationTokens
|
|
160
|
-
);
|
|
161
136
|
|
|
162
137
|
return {
|
|
163
138
|
toBlockchain: chain,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
toToken:
|
|
139
|
+
...(state.toToken && {
|
|
140
|
+
bestRoute: null,
|
|
141
|
+
toToken: null,
|
|
142
|
+
outputAmount: null,
|
|
143
|
+
outputUsdValue: null,
|
|
167
144
|
}),
|
|
168
145
|
};
|
|
169
146
|
});
|
|
170
147
|
},
|
|
171
|
-
setToToken: (token) =>
|
|
172
|
-
|
|
148
|
+
setToToken: (token) => {
|
|
149
|
+
const { blockchains } = useMetaStore.getState().meta;
|
|
150
|
+
const toBlockchain =
|
|
151
|
+
blockchains.find(
|
|
152
|
+
(blockchain) => blockchain.name === token?.blockchain
|
|
153
|
+
) ?? null;
|
|
154
|
+
return set(() => ({
|
|
173
155
|
toToken: token,
|
|
174
|
-
|
|
156
|
+
toBlockchain,
|
|
157
|
+
}));
|
|
158
|
+
},
|
|
175
159
|
setInputAmount: (amount) => {
|
|
176
160
|
set((state) => ({
|
|
177
161
|
inputAmount: amount,
|
|
@@ -187,7 +171,6 @@ export const useBestRouteStore = createSelectors(
|
|
|
187
171
|
},
|
|
188
172
|
retry: (pendingSwap) => {
|
|
189
173
|
const { tokens, blockchains } = useMetaStore.getState().meta;
|
|
190
|
-
const connectedWallets = useWalletsStore.getState().connectedWallets;
|
|
191
174
|
const failedIndex =
|
|
192
175
|
pendingSwap.status === 'failed'
|
|
193
176
|
? pendingSwap.steps.findIndex((s) => s.status === 'failed')
|
|
@@ -223,18 +206,7 @@ export const useBestRouteStore = createSelectors(
|
|
|
223
206
|
address: lastStep.toSymbolAddress,
|
|
224
207
|
})
|
|
225
208
|
);
|
|
226
|
-
|
|
227
|
-
fromBlockchain,
|
|
228
|
-
tokens,
|
|
229
|
-
connectedWallets,
|
|
230
|
-
[]
|
|
231
|
-
);
|
|
232
|
-
const sortedDestinationTokens = getSortedTokens(
|
|
233
|
-
toBlockchain,
|
|
234
|
-
tokens,
|
|
235
|
-
connectedWallets,
|
|
236
|
-
[]
|
|
237
|
-
);
|
|
209
|
+
|
|
238
210
|
const inputAmount = pendingSwap.inputAmount;
|
|
239
211
|
set({
|
|
240
212
|
fromBlockchain,
|
|
@@ -246,8 +218,6 @@ export const useBestRouteStore = createSelectors(
|
|
|
246
218
|
toBlockchain,
|
|
247
219
|
toToken,
|
|
248
220
|
bestRoute: null,
|
|
249
|
-
sourceTokens: sortedSourceTokens,
|
|
250
|
-
destinationTokens: sortedDestinationTokens,
|
|
251
221
|
});
|
|
252
222
|
},
|
|
253
223
|
switchFromAndTo: () =>
|
|
@@ -256,8 +226,6 @@ export const useBestRouteStore = createSelectors(
|
|
|
256
226
|
fromToken: state.toToken,
|
|
257
227
|
toBlockchain: state.fromBlockchain,
|
|
258
228
|
toToken: state.fromToken,
|
|
259
|
-
sourceTokens: state.destinationTokens,
|
|
260
|
-
destinationTokens: state.sourceTokens,
|
|
261
229
|
inputAmount: state.outputAmount?.toString() || '',
|
|
262
230
|
inputUsdValue: getUsdValue(
|
|
263
231
|
state.toToken,
|
|
@@ -267,13 +235,19 @@ export const useBestRouteStore = createSelectors(
|
|
|
267
235
|
|
|
268
236
|
resetFromBlockchain: () =>
|
|
269
237
|
set(() => ({
|
|
238
|
+
fromToken: null,
|
|
270
239
|
fromBlockchain: null,
|
|
271
|
-
|
|
240
|
+
outputAmount: null,
|
|
241
|
+
outputUsdValue: null,
|
|
242
|
+
bestRoute: null,
|
|
272
243
|
})),
|
|
273
244
|
resetToBlockchain: () =>
|
|
274
245
|
set(() => ({
|
|
246
|
+
toToken: null,
|
|
275
247
|
toBlockchain: null,
|
|
276
|
-
|
|
248
|
+
outputAmount: null,
|
|
249
|
+
outputUsdValue: null,
|
|
250
|
+
bestRoute: null,
|
|
277
251
|
})),
|
|
278
252
|
setRouteWalletConfirmed: (flag) =>
|
|
279
253
|
set({
|
package/src/store/meta.ts
CHANGED
|
@@ -3,12 +3,8 @@ import type { MetaResponse } from 'rango-sdk';
|
|
|
3
3
|
|
|
4
4
|
import { create } from 'zustand';
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import { removeDuplicateFrom } from '../utils/common';
|
|
8
|
-
import { getTokensWithBalance, sortTokens } from '../utils/wallets';
|
|
9
|
-
|
|
6
|
+
import { useAppStore } from './app';
|
|
10
7
|
import createSelectors from './selectors';
|
|
11
|
-
import { useWalletsStore } from './wallets';
|
|
12
8
|
|
|
13
9
|
export type LoadingStatus = 'loading' | 'success' | 'failed';
|
|
14
10
|
|
|
@@ -16,38 +12,24 @@ export interface MetaState {
|
|
|
16
12
|
meta: MetaResponse & { tokens: TokenWithBalance[] };
|
|
17
13
|
loadingStatus: LoadingStatus;
|
|
18
14
|
fetchMeta: () => Promise<void>;
|
|
19
|
-
setTokensWithBalance: () => void;
|
|
20
15
|
}
|
|
21
16
|
|
|
22
17
|
export const useMetaStore = createSelectors(
|
|
23
18
|
create<MetaState>()((set) => ({
|
|
24
19
|
meta: { blockchains: [], popularTokens: [], swappers: [], tokens: [] },
|
|
25
20
|
loadingStatus: 'loading',
|
|
26
|
-
setTokensWithBalance: () => {
|
|
27
|
-
const connectedWallets = useWalletsStore.getState().connectedWallets;
|
|
28
|
-
|
|
29
|
-
set((state) => ({
|
|
30
|
-
...state,
|
|
31
|
-
meta: {
|
|
32
|
-
...state.meta,
|
|
33
|
-
tokens: sortTokens(
|
|
34
|
-
getTokensWithBalance(state.meta.tokens, connectedWallets)
|
|
35
|
-
),
|
|
36
|
-
},
|
|
37
|
-
}));
|
|
38
|
-
},
|
|
39
21
|
fetchMeta: async () => {
|
|
40
22
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
23
|
+
await useAppStore.getState().fetch();
|
|
24
|
+
|
|
25
|
+
const state = useAppStore.getState();
|
|
26
|
+
const response: MetaResponse = {
|
|
27
|
+
blockchains: state.blockchains(),
|
|
28
|
+
tokens: state.tokens(),
|
|
29
|
+
popularTokens: state._popularTokens,
|
|
30
|
+
swappers: state._swappers,
|
|
31
|
+
};
|
|
32
|
+
|
|
51
33
|
set({ meta: response, loadingStatus: 'success' });
|
|
52
34
|
} catch (error) {
|
|
53
35
|
set({ loadingStatus: 'failed' });
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { WidgetConfig } from '../../types';
|
|
2
|
+
import type { StateCreator } from 'zustand';
|
|
3
|
+
|
|
4
|
+
const initConfig: WidgetConfig = { apiKey: '' };
|
|
5
|
+
|
|
6
|
+
export type ConfigSlice = {
|
|
7
|
+
config: WidgetConfig;
|
|
8
|
+
|
|
9
|
+
updateConfig: (config: WidgetConfig) => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const createConfigSlice: StateCreator<ConfigSlice> = (set, get) => ({
|
|
13
|
+
config: initConfig,
|
|
14
|
+
|
|
15
|
+
// Actions
|
|
16
|
+
updateConfig: (nextConfig: WidgetConfig) => {
|
|
17
|
+
const currentConfig = get().config;
|
|
18
|
+
|
|
19
|
+
set({
|
|
20
|
+
config: {
|
|
21
|
+
...currentConfig,
|
|
22
|
+
...nextConfig,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
});
|