@rango-dev/widget-embedded 0.1.13-next.0 → 0.1.13-next.5
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/App.d.ts.map +1 -1
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/TokenInfo.d.ts.map +1 -1
- package/dist/components/TokenPreview.d.ts.map +1 -1
- package/dist/components/UpdateUrl.d.ts.map +1 -1
- package/dist/components/warnings/BalanceErrors.d.ts.map +1 -1
- package/dist/globalStyles.d.ts +0 -1
- package/dist/globalStyles.d.ts.map +1 -1
- package/dist/hooks/useNavigateBack.d.ts.map +1 -1
- package/dist/lib.d.ts +1 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts +1 -0
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +1 -0
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/utils/numbers.d.ts +1 -2
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +1087 -1149
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +1087 -1149
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +1090 -1152
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/App.tsx +1 -2
- package/src/QueueManager.tsx +28 -3
- package/src/components/AppRouter.tsx +4 -29
- package/src/components/AppRoutes.tsx +9 -9
- package/src/components/BottomLogo.tsx +1 -1
- package/src/components/ChangeSlippageButton.tsx +1 -1
- package/src/components/Layout.tsx +3 -1
- package/src/components/RoutesOverview.tsx +2 -2
- package/src/components/TokenInfo.tsx +3 -2
- package/src/components/TokenPreview.tsx +1 -0
- package/src/components/UpdateUrl.tsx +19 -50
- package/src/components/warnings/BalanceErrors.tsx +4 -2
- package/src/constants/navigationRoutes.ts +9 -9
- package/src/globalStyles.ts +0 -19
- package/src/hooks/useNavigateBack.ts +3 -4
- package/src/index.tsx +1 -1
- package/src/lib.tsx +16 -8
- package/src/pages/ConfirmSwapPage.tsx +33 -13
- package/src/pages/HistoryPage.tsx +1 -1
- package/src/pages/Home.tsx +1 -1
- package/src/pages/SwapDetailsPage.tsx +1 -2
- package/src/store/bestRoute.ts +18 -16
- package/src/store/wallets.ts +38 -28
- package/src/utils/numbers.ts +2 -5
- package/dist/hooks/useCopyToClipboard.d.ts +0 -2
- package/dist/hooks/useCopyToClipboard.d.ts.map +0 -1
- package/src/hooks/useCopyToClipboard.ts +0 -23
package/src/pages/Home.tsx
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
3
|
-
import useCopyToClipboard from '../hooks/useCopyToClipboard';
|
|
4
3
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
5
4
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
6
5
|
import { getPendingSwaps } from '../utils/queue';
|
|
7
|
-
import { SwapHistory } from '@rango-dev/ui';
|
|
6
|
+
import { SwapHistory, useCopyToClipboard } from '@rango-dev/ui';
|
|
8
7
|
import { useUiStore } from '../store/ui';
|
|
9
8
|
import {
|
|
10
9
|
cancelSwap,
|
package/src/store/bestRoute.ts
CHANGED
|
@@ -40,6 +40,7 @@ export interface RouteState {
|
|
|
40
40
|
error: string;
|
|
41
41
|
sourceTokens: Token[];
|
|
42
42
|
destinationTokens: Token[];
|
|
43
|
+
resetRoute: () => void;
|
|
43
44
|
setFromChain: (
|
|
44
45
|
chain: BlockchainMeta | null,
|
|
45
46
|
setDefaultToken?: boolean
|
|
@@ -92,6 +93,14 @@ export const useBestRouteStore = createSelectors(
|
|
|
92
93
|
}),
|
|
93
94
|
};
|
|
94
95
|
}),
|
|
96
|
+
resetRoute: () =>
|
|
97
|
+
set(() => ({
|
|
98
|
+
loading: true,
|
|
99
|
+
error: '',
|
|
100
|
+
bestRoute: null,
|
|
101
|
+
outputAmount: null,
|
|
102
|
+
outputUsdValue: new BigNumber(0),
|
|
103
|
+
})),
|
|
95
104
|
setFromChain: (chain, setDefaultToken) => {
|
|
96
105
|
set((state) => {
|
|
97
106
|
if (state.fromChain?.name === chain?.name) return {};
|
|
@@ -155,6 +164,7 @@ export const useBestRouteStore = createSelectors(
|
|
|
155
164
|
outputAmount: new BigNumber(0),
|
|
156
165
|
outputUsdValue: new BigNumber(0),
|
|
157
166
|
bestRoute: null,
|
|
167
|
+
error: '',
|
|
158
168
|
}),
|
|
159
169
|
...(!!state.fromToken && {
|
|
160
170
|
inputUsdValue: getUsdValue(state.fromToken, amount),
|
|
@@ -250,7 +260,8 @@ const bestRoute = (
|
|
|
250
260
|
) => {
|
|
251
261
|
let abortController: AbortController | null = null;
|
|
252
262
|
const fetchBestRoute = () => {
|
|
253
|
-
const { fromToken, toToken, inputAmount } =
|
|
263
|
+
const { fromToken, toToken, inputAmount, resetRoute } =
|
|
264
|
+
bestRouteStore.getState();
|
|
254
265
|
const { slippage, customSlippage, disabledLiquiditySources, affiliateRef } =
|
|
255
266
|
settingsStore.getState();
|
|
256
267
|
if (!fromToken || !toToken || !isPositiveNumber(inputAmount)) return;
|
|
@@ -267,13 +278,10 @@ const bestRoute = (
|
|
|
267
278
|
userSlippage,
|
|
268
279
|
affiliateRef
|
|
269
280
|
);
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
outputAmount: null,
|
|
275
|
-
outputUsdValue: new BigNumber(0),
|
|
276
|
-
});
|
|
281
|
+
|
|
282
|
+
if (!bestRouteStore.getState().loading) {
|
|
283
|
+
resetRoute();
|
|
284
|
+
}
|
|
277
285
|
httpService()
|
|
278
286
|
.getBestRoute(requestBody, {
|
|
279
287
|
signal: abortController.signal,
|
|
@@ -296,7 +304,7 @@ const bestRoute = (
|
|
|
296
304
|
const debouncedFetchBestRoute = debounce(fetchBestRoute, 600);
|
|
297
305
|
|
|
298
306
|
const bestRouteParamsListener = () => {
|
|
299
|
-
const { fromToken, toToken, inputAmount, inputUsdValue } =
|
|
307
|
+
const { fromToken, toToken, inputAmount, inputUsdValue, resetRoute } =
|
|
300
308
|
useBestRouteStore.getState();
|
|
301
309
|
if (!isPositiveNumber(inputAmount) || inputUsdValue.eq(0))
|
|
302
310
|
return bestRouteStore.setState({ loading: false });
|
|
@@ -309,13 +317,7 @@ const bestRoute = (
|
|
|
309
317
|
outputUsdValue: inputUsdValue,
|
|
310
318
|
});
|
|
311
319
|
|
|
312
|
-
if (!bestRouteStore.getState().loading)
|
|
313
|
-
bestRouteStore.setState({
|
|
314
|
-
loading: true,
|
|
315
|
-
bestRoute: null,
|
|
316
|
-
outputAmount: null,
|
|
317
|
-
outputUsdValue: new BigNumber(0),
|
|
318
|
-
});
|
|
320
|
+
if (!bestRouteStore.getState().loading) resetRoute();
|
|
319
321
|
debouncedFetchBestRoute();
|
|
320
322
|
};
|
|
321
323
|
|
package/src/store/wallets.ts
CHANGED
|
@@ -54,17 +54,17 @@ interface WalletsStore {
|
|
|
54
54
|
initSelectedWallets: () => void;
|
|
55
55
|
setSelectedWallet: (wallet: SelectableWallet) => void;
|
|
56
56
|
clearConnectedWallet: () => void;
|
|
57
|
+
getOneOfWalletsDetails: (account: Account) => void;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
export const useWalletsStore = createSelectors(
|
|
60
61
|
create<WalletsStore>()(
|
|
61
|
-
subscribeWithSelector((set) => ({
|
|
62
|
+
subscribeWithSelector((set, get) => ({
|
|
62
63
|
accounts: [],
|
|
63
64
|
balances: [],
|
|
64
65
|
selectedWallets: [],
|
|
65
66
|
connectWallet: (accounts) => {
|
|
66
|
-
const
|
|
67
|
-
|
|
67
|
+
const getOneOfWalletsDetails = get().getOneOfWalletsDetails;
|
|
68
68
|
set((state) => ({
|
|
69
69
|
accounts: state.accounts.concat(accounts),
|
|
70
70
|
balances: state.balances.concat(
|
|
@@ -79,31 +79,7 @@ export const useWalletsStore = createSelectors(
|
|
|
79
79
|
}))
|
|
80
80
|
),
|
|
81
81
|
}));
|
|
82
|
-
accounts.forEach(async (account) =>
|
|
83
|
-
try {
|
|
84
|
-
const response = await httpService().getWalletsDetails([
|
|
85
|
-
{ address: account.address, blockchain: account.chain },
|
|
86
|
-
]);
|
|
87
|
-
const retrivedBalance = response.wallets[0];
|
|
88
|
-
if (retrivedBalance) {
|
|
89
|
-
set((state) => ({
|
|
90
|
-
balances: state.balances.map((balance) => {
|
|
91
|
-
return isAccountAndBalanceMatched(account, balance)
|
|
92
|
-
? makeBalanceFor(account, retrivedBalance, tokens)
|
|
93
|
-
: balance;
|
|
94
|
-
}),
|
|
95
|
-
}));
|
|
96
|
-
} else throw new Error('Wallet not found');
|
|
97
|
-
} catch (error) {
|
|
98
|
-
set((state) => ({
|
|
99
|
-
balances: state.balances.map((balance) => {
|
|
100
|
-
return isAccountAndBalanceMatched(account, balance)
|
|
101
|
-
? resetBalanceState(balance)
|
|
102
|
-
: balance;
|
|
103
|
-
}),
|
|
104
|
-
}));
|
|
105
|
-
}
|
|
106
|
-
});
|
|
82
|
+
accounts.forEach(async (account) => getOneOfWalletsDetails(account));
|
|
107
83
|
},
|
|
108
84
|
disconnectWallet: (walletType) => {
|
|
109
85
|
set((state) => ({
|
|
@@ -162,6 +138,40 @@ export const useWalletsStore = createSelectors(
|
|
|
162
138
|
balances: [],
|
|
163
139
|
selectedWallets: [],
|
|
164
140
|
})),
|
|
141
|
+
getOneOfWalletsDetails: async (account: Account) => {
|
|
142
|
+
const tokens = useMetaStore.getState().meta.tokens;
|
|
143
|
+
set((state) => ({
|
|
144
|
+
balances: state.balances.map((balance) => {
|
|
145
|
+
return balance.address === account.address &&
|
|
146
|
+
balance.chain === account.chain
|
|
147
|
+
? { ...balance, loading: true }
|
|
148
|
+
: balance;
|
|
149
|
+
}),
|
|
150
|
+
}));
|
|
151
|
+
try {
|
|
152
|
+
const response = await httpService().getWalletsDetails([
|
|
153
|
+
{ address: account.address, blockchain: account.chain },
|
|
154
|
+
]);
|
|
155
|
+
const retrivedBalance = response.wallets[0];
|
|
156
|
+
if (retrivedBalance) {
|
|
157
|
+
set((state) => ({
|
|
158
|
+
balances: state.balances.map((balance) => {
|
|
159
|
+
return isAccountAndBalanceMatched(account, balance)
|
|
160
|
+
? makeBalanceFor(account, retrivedBalance, tokens)
|
|
161
|
+
: balance;
|
|
162
|
+
}),
|
|
163
|
+
}));
|
|
164
|
+
} else throw new Error('Wallet not found');
|
|
165
|
+
} catch (error) {
|
|
166
|
+
set((state) => ({
|
|
167
|
+
balances: state.balances.map((balance) => {
|
|
168
|
+
return isAccountAndBalanceMatched(account, balance)
|
|
169
|
+
? resetBalanceState(balance)
|
|
170
|
+
: balance;
|
|
171
|
+
}),
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
},
|
|
165
175
|
}))
|
|
166
176
|
)
|
|
167
177
|
);
|
package/src/utils/numbers.ts
CHANGED
|
@@ -12,11 +12,11 @@ export const secondsToString = (s: number): string => {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export const numberToString = (
|
|
15
|
-
number: BigNumber | string | null,
|
|
15
|
+
number: BigNumber | string | null | undefined,
|
|
16
16
|
minDecimals: number | null = null,
|
|
17
17
|
maxDecimals: number | null = null
|
|
18
18
|
): string => {
|
|
19
|
-
if (number === null) return '';
|
|
19
|
+
if (number === null || number === undefined) return '';
|
|
20
20
|
if (number === '') return '';
|
|
21
21
|
const n = new BigNumber(number);
|
|
22
22
|
const roundingMode = 1;
|
|
@@ -126,9 +126,6 @@ export const rawFees = (data: BestRouteResponse): string =>
|
|
|
126
126
|
.reduce((partialSum, a) => partialSum + parseFloat(a.fee.amount), 0)
|
|
127
127
|
.toFixed(3);
|
|
128
128
|
|
|
129
|
-
export const decimalNumber = (number = '0', toFixed: number) =>
|
|
130
|
-
parseFloat(number).toFixed(toFixed);
|
|
131
|
-
|
|
132
129
|
export const containsText = (text: string, searchText: string) =>
|
|
133
130
|
text.toLowerCase().indexOf(searchText.toLowerCase()) > -1;
|
|
134
131
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCopyToClipboard.d.ts","sourceRoot":"","sources":["../src/hooks/useCopyToClipboard.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,aAAa,CAAC,EAAE,MAAM,6BAGnB,MAAM,GAAG,MAAM,WAgB5D"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import copy from 'copy-to-clipboard';
|
|
3
|
-
|
|
4
|
-
export default function useCopyToClipboard(resetInterval?: number) {
|
|
5
|
-
const [isCopied, setCopied] = React.useState(false);
|
|
6
|
-
|
|
7
|
-
const handleCopy = React.useCallback((text: string | number) => {
|
|
8
|
-
copy(text.toString());
|
|
9
|
-
setCopied(true);
|
|
10
|
-
}, []);
|
|
11
|
-
|
|
12
|
-
React.useEffect(() => {
|
|
13
|
-
let timeout: NodeJS.Timeout;
|
|
14
|
-
if (isCopied && resetInterval) {
|
|
15
|
-
timeout = setTimeout(() => setCopied(false), resetInterval);
|
|
16
|
-
}
|
|
17
|
-
return () => {
|
|
18
|
-
clearTimeout(timeout);
|
|
19
|
-
};
|
|
20
|
-
}, [isCopied, resetInterval]);
|
|
21
|
-
|
|
22
|
-
return [isCopied, handleCopy] as const;
|
|
23
|
-
}
|