@rango-dev/widget-embedded 0.1.10-next.84 → 0.1.10-next.87

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.
Files changed (43) hide show
  1. package/dist/App.d.ts.map +1 -1
  2. package/dist/QueueManager.d.ts +4 -0
  3. package/dist/QueueManager.d.ts.map +1 -0
  4. package/dist/components/AppRoutes.d.ts.map +1 -1
  5. package/dist/components/HeaderButtons.d.ts.map +1 -1
  6. package/dist/components/UpdateUrl.d.ts.map +1 -1
  7. package/dist/constants/navigationRoutes.d.ts +1 -1
  8. package/dist/hooks/useCopyToClipboard.d.ts +2 -0
  9. package/dist/hooks/useCopyToClipboard.d.ts.map +1 -0
  10. package/dist/hooks/useNavigateBack.d.ts.map +1 -1
  11. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  12. package/dist/pages/ConfirmWalletsPage.d.ts.map +1 -1
  13. package/dist/pages/HistoryPage.d.ts +0 -2
  14. package/dist/pages/HistoryPage.d.ts.map +1 -1
  15. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  16. package/dist/store/confirmSwap.d.ts +2 -1
  17. package/dist/store/confirmSwap.d.ts.map +1 -1
  18. package/dist/store/ui.d.ts.map +1 -1
  19. package/dist/utils/queue.d.ts +4 -0
  20. package/dist/utils/queue.d.ts.map +1 -0
  21. package/dist/widget-embedded.cjs.development.js +154 -1132
  22. package/dist/widget-embedded.cjs.development.js.map +1 -1
  23. package/dist/widget-embedded.cjs.production.min.js +154 -1132
  24. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  25. package/dist/widget-embedded.esm.js +155 -1133
  26. package/dist/widget-embedded.esm.js.map +1 -1
  27. package/package.json +10 -5
  28. package/src/App.tsx +35 -12
  29. package/src/QueueManager.tsx +93 -0
  30. package/src/components/AppRoutes.tsx +5 -2
  31. package/src/components/HeaderButtons.tsx +17 -4
  32. package/src/components/UpdateUrl.tsx +15 -11
  33. package/src/constants/navigationRoutes.ts +2 -2
  34. package/src/hooks/useCopyToClipboard.ts +23 -0
  35. package/src/hooks/useNavigateBack.ts +7 -4
  36. package/src/pages/ConfirmSwapPage.tsx +17 -4
  37. package/src/pages/ConfirmWalletsPage.tsx +3 -1
  38. package/src/pages/HistoryPage.tsx +15 -822
  39. package/src/pages/Home.tsx +1 -1
  40. package/src/pages/SwapDetailsPage.tsx +21 -3
  41. package/src/store/confirmSwap.ts +24 -9
  42. package/src/store/ui.ts +8 -2
  43. package/src/utils/queue.ts +24 -0
@@ -206,7 +206,7 @@ export function Home() {
206
206
  if (swapButtonState.title === 'Connect Wallet')
207
207
  navigate(navigationRoutes.wallets);
208
208
  else {
209
- navigate(navigationRoutes.confirmWallets);
209
+ navigate(navigationRoutes.confirmWallets, { replace: true });
210
210
  }
211
211
  }}
212
212
  >
@@ -1,15 +1,33 @@
1
- import { SwapHistory } from '@rango-dev/ui';
2
1
  import React from 'react';
2
+ import { useManager } from '@rango-dev/queue-manager-react';
3
+ import { SwapHistory } from '@rango-dev/ui';
3
4
  import { navigationRoutes } from '../constants/navigationRoutes';
4
5
  import { useNavigateBack } from '../hooks/useNavigateBack';
5
- import { pendingSwap } from '../mockData/pendingSwap';
6
+ import { getPendingSwaps } from '../utils/queue';
7
+ import { useUiStore } from '../store/ui';
8
+ import useCopyToClipboard from '../hooks/useCopyToClipboard';
6
9
 
7
10
  export function SwapDetailsPage() {
11
+ const selectedSwapRequestId = useUiStore.use.selectedSwapRequestId();
8
12
  const { navigateBackFrom } = useNavigateBack();
13
+ const { manager } = useManager();
14
+ const [isCopied, handleCopy] = useCopyToClipboard(2000);
15
+
16
+ const pendingSwaps = getPendingSwaps(manager);
17
+ const selectedSwap = pendingSwaps.find(
18
+ ({ swap }) => swap.requestId === selectedSwapRequestId
19
+ )?.swap;
20
+
9
21
  return (
10
22
  <SwapHistory
11
23
  onBack={navigateBackFrom.bind(null, navigationRoutes.swapDetails)}
12
- pendingSwap={pendingSwap}
24
+ //todo: move PendingSwap type to rango-types
25
+ //@ts-ignore
26
+ pendingSwap={selectedSwap}
27
+ onCopy={handleCopy}
28
+ isCopied={isCopied}
29
+ //todo: implement swap cancellation (move queueManager logic to queueManager/rango-preset)
30
+ onCancel={(requestId) => console.log(requestId)}
13
31
  />
14
32
  );
15
33
  }
@@ -29,6 +29,7 @@ import { useMetaStore } from './meta';
29
29
  import createSelectors from './selectors';
30
30
  import { useSettingsStore } from './settings';
31
31
  import { useWalletsStore } from './wallets';
32
+ import { PendingSwap } from '@rango-dev/ui/dist/containers/History/types';
32
33
 
33
34
  interface ConfirmSwapState {
34
35
  loading: boolean;
@@ -95,7 +96,7 @@ export enum ConfirmSwapWarningTypes {
95
96
  INSUFFICIENT_BALANCE,
96
97
  }
97
98
 
98
- export const confirmSwap = () => {
99
+ export const confirmSwap = async (): Promise<PendingSwap | undefined> => {
99
100
  const {
100
101
  fromToken,
101
102
  toToken,
@@ -131,11 +132,15 @@ export const confirmSwap = () => {
131
132
 
132
133
  console.log('new swap:', newSwap);
133
134
 
134
- return useConfirmSwapStore.setState({
135
+ // queueManager?.create('swap', { swapDetails: newSwap });
136
+
137
+ useConfirmSwapStore.setState({
135
138
  errors: [],
136
139
  warnings: [],
137
140
  proceedAnyway: false,
138
141
  });
142
+
143
+ return newSwap;
139
144
  }
140
145
 
141
146
  let abortController: AbortController | null = new AbortController();
@@ -181,7 +186,7 @@ export const confirmSwap = () => {
181
186
  }
182
187
  );
183
188
 
184
- httpService
189
+ const newSwap: PendingSwap | undefined | void = await httpService
185
190
  .getBestRoute(requestBody, { signal: abortController.signal })
186
191
  .then((confiremedRoute) => {
187
192
  useConfirmSwapStore.setState({ loading: false });
@@ -191,12 +196,14 @@ export const confirmSwap = () => {
191
196
  !new BigNumber(confiremedRoute.requestAmount).isEqualTo(
192
197
  new BigNumber(inputAmount || '-1')
193
198
  )
194
- )
195
- return useConfirmSwapStore.setState((prevState) => ({
199
+ ) {
200
+ useConfirmSwapStore.setState((prevState) => ({
196
201
  errors: prevState.errors.concat({
197
202
  type: ConfirmSwapErrorTypes.NO_ROUTE,
198
203
  }),
199
204
  }));
205
+ return undefined;
206
+ }
200
207
 
201
208
  const confirmSwap: Partial<ConfirmSwapState> = {
202
209
  loading: false,
@@ -286,7 +293,7 @@ export const confirmSwap = () => {
286
293
 
287
294
  const newSwap = calculatePendingSwap(
288
295
  inputAmount.toString(),
289
- initialRoute,
296
+ confiremedRoute,
290
297
  getWalletsForNewSwap(selectedWallets),
291
298
  swapSettings,
292
299
  false,
@@ -294,12 +301,18 @@ export const confirmSwap = () => {
294
301
  );
295
302
 
296
303
  console.log('new swap:', newSwap);
297
- } else if (!proceedAnyway) confirmSwap.proceedAnyway = true;
298
-
304
+ return newSwap;
305
+ } else if (!proceedAnyway) {
306
+ confirmSwap.proceedAnyway = true;
307
+ useConfirmSwapStore.setState(confirmSwap);
308
+ }
309
+ return undefined;
310
+ })
311
+ .then((result) => {
299
312
  abortController = null;
300
- useConfirmSwapStore.setState(confirmSwap);
301
313
  unsubscribeFromBestRouteStore();
302
314
  unsubscribeFromWalletsStore();
315
+ return result;
303
316
  })
304
317
  .catch((error) => {
305
318
  abortController = null;
@@ -324,4 +337,6 @@ export const confirmSwap = () => {
324
337
  }),
325
338
  }));
326
339
  });
340
+
341
+ return newSwap || undefined;
327
342
  };
package/src/store/ui.ts CHANGED
@@ -3,13 +3,19 @@ import createSelectors from './selectors';
3
3
 
4
4
  interface UiState {
5
5
  connectWalletsButtonDisabled: boolean;
6
+ selectedSwapRequestId: string | null;
6
7
  toggleConnectWalletsButton: () => void;
8
+ setSelectedSwap: (requestId: string | null) => void;
7
9
  }
8
10
 
9
11
  export const useUiStore = createSelectors(
10
12
  create<UiState>()((set) => ({
11
13
  connectWalletsButtonDisabled: false,
14
+ selectedSwapRequestId: null,
12
15
  toggleConnectWalletsButton: () =>
13
- set((state) => ({ connectWalletsButtonDisabled: !state.connectWalletsButtonDisabled })),
14
- })),
16
+ set((state) => ({
17
+ connectWalletsButtonDisabled: !state.connectWalletsButtonDisabled,
18
+ })),
19
+ setSelectedSwap: (requestId) => set({ selectedSwapRequestId: requestId }),
20
+ }))
15
21
  );
@@ -0,0 +1,24 @@
1
+ import { Manager } from '@rango-dev/queue-manager-core';
2
+ import {
3
+ PendingSwapWithQueueID,
4
+ SwapStorage,
5
+ } from '@rango-dev/queue-manager-rango-preset';
6
+
7
+ export const getPendingSwaps = (manager: Manager | undefined) => {
8
+ const result: PendingSwapWithQueueID[] = [];
9
+
10
+ manager?.getAll().forEach((q, id) => {
11
+ const storage = q.list.getStorage() as SwapStorage;
12
+
13
+ if (storage?.swapDetails) {
14
+ result.push({
15
+ id,
16
+ swap: storage?.swapDetails,
17
+ });
18
+ }
19
+ });
20
+
21
+ return result.sort(
22
+ (a, b) => Number(b.swap.creationTime) - Number(a.swap.creationTime)
23
+ );
24
+ };