@rango-dev/widget-embedded 0.1.10-next.98 → 0.1.10

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 (110) hide show
  1. package/dist/App.d.ts.map +1 -1
  2. package/dist/QueueManager.d.ts.map +1 -1
  3. package/dist/components/AppRouter.d.ts +6 -1
  4. package/dist/components/AppRouter.d.ts.map +1 -1
  5. package/dist/components/AppRoutes.d.ts.map +1 -1
  6. package/dist/components/ChangeSlippageButton.d.ts.map +1 -1
  7. package/dist/components/HeaderButtons.d.ts +4 -1
  8. package/dist/components/HeaderButtons.d.ts.map +1 -1
  9. package/dist/components/Layout.d.ts.map +1 -1
  10. package/dist/components/RoutesOverview.d.ts +10 -0
  11. package/dist/components/RoutesOverview.d.ts.map +1 -0
  12. package/dist/components/SwapDetailsPlaceholder.d.ts +9 -0
  13. package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -0
  14. package/dist/components/TokenInfo.d.ts.map +1 -1
  15. package/dist/components/TokenPreview.d.ts +20 -0
  16. package/dist/components/TokenPreview.d.ts.map +1 -0
  17. package/dist/components/UpdateUrl.d.ts.map +1 -1
  18. package/dist/components/warnings/BalanceWarnings.d.ts.map +1 -1
  19. package/dist/components/warnings/HighSlippageWarning.d.ts.map +1 -1
  20. package/dist/components/warnings/MinRequiredSlippage.d.ts +1 -1
  21. package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -1
  22. package/dist/constants/navigationRoutes.d.ts +0 -1
  23. package/dist/constants/navigationRoutes.d.ts.map +1 -1
  24. package/dist/globalStyles.d.ts.map +1 -1
  25. package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
  26. package/dist/lib.d.ts.map +1 -1
  27. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  28. package/dist/pages/HistoryPage.d.ts.map +1 -1
  29. package/dist/pages/Home.d.ts.map +1 -1
  30. package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
  31. package/dist/pages/SelectTokenPage.d.ts.map +1 -1
  32. package/dist/pages/SettingsPage.d.ts.map +1 -1
  33. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  34. package/dist/pages/WalletsPage.d.ts +1 -0
  35. package/dist/pages/WalletsPage.d.ts.map +1 -1
  36. package/dist/store/bestRoute.d.ts +2 -0
  37. package/dist/store/bestRoute.d.ts.map +1 -1
  38. package/dist/store/ui.d.ts.map +1 -1
  39. package/dist/store/wallets.d.ts +14 -0
  40. package/dist/store/wallets.d.ts.map +1 -1
  41. package/dist/types/routing.d.ts +1 -1
  42. package/dist/types/swap.d.ts +6 -0
  43. package/dist/types/swap.d.ts.map +1 -1
  44. package/dist/utils/common.d.ts +1 -0
  45. package/dist/utils/common.d.ts.map +1 -1
  46. package/dist/utils/date.d.ts +3 -0
  47. package/dist/utils/date.d.ts.map +1 -0
  48. package/dist/utils/routing.d.ts +1 -0
  49. package/dist/utils/routing.d.ts.map +1 -1
  50. package/dist/utils/swap.d.ts +18 -6
  51. package/dist/utils/swap.d.ts.map +1 -1
  52. package/dist/utils/time.d.ts +4 -0
  53. package/dist/utils/time.d.ts.map +1 -0
  54. package/dist/utils/wallets.d.ts +1 -1
  55. package/dist/utils/wallets.d.ts.map +1 -1
  56. package/dist/widget-embedded.cjs.development.js +1004 -418
  57. package/dist/widget-embedded.cjs.development.js.map +1 -1
  58. package/dist/widget-embedded.cjs.production.min.js +1004 -418
  59. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  60. package/dist/widget-embedded.esm.js +1008 -423
  61. package/dist/widget-embedded.esm.js.map +1 -1
  62. package/package.json +12 -11
  63. package/readme.md +1 -2
  64. package/src/App.tsx +30 -5
  65. package/src/QueueManager.tsx +5 -2
  66. package/src/components/AppRouter.tsx +24 -13
  67. package/src/components/AppRoutes.tsx +15 -12
  68. package/src/components/ChangeSlippageButton.tsx +4 -8
  69. package/src/components/HeaderButtons.tsx +11 -4
  70. package/src/components/Layout.tsx +37 -5
  71. package/src/components/RoutesOverview.tsx +60 -0
  72. package/src/components/SwapDetailsPlaceholder.tsx +32 -0
  73. package/src/components/TokenInfo.tsx +125 -77
  74. package/src/components/TokenPreview.tsx +178 -0
  75. package/src/components/UpdateUrl.tsx +1 -3
  76. package/src/components/warnings/BalanceWarnings.tsx +1 -0
  77. package/src/components/warnings/HighSlippageWarning.tsx +4 -7
  78. package/src/components/warnings/MinRequiredSlippage.tsx +9 -4
  79. package/src/constants/navigationRoutes.ts +0 -1
  80. package/src/globalStyles.ts +3 -2
  81. package/src/hooks/useConfirmSwap.ts +2 -1
  82. package/src/hooks/useNavigateBack.ts +3 -3
  83. package/src/hooks/useTheme.ts +9 -9
  84. package/src/languages/en.json +9 -8
  85. package/src/lib.tsx +25 -3
  86. package/src/pages/ConfirmSwapPage.tsx +128 -20
  87. package/src/pages/HistoryPage.tsx +4 -4
  88. package/src/pages/Home.tsx +51 -42
  89. package/src/pages/LiquiditySourcesPage.tsx +2 -0
  90. package/src/pages/SelectTokenPage.tsx +3 -1
  91. package/src/pages/SettingsPage.tsx +3 -0
  92. package/src/pages/SwapDetailsPage.tsx +142 -6
  93. package/src/pages/WalletsPage.tsx +49 -16
  94. package/src/store/bestRoute.ts +114 -17
  95. package/src/store/ui.ts +4 -0
  96. package/src/store/wallets.ts +4 -1
  97. package/src/types/routing.ts +1 -1
  98. package/src/types/swap.ts +7 -0
  99. package/src/utils/common.ts +14 -0
  100. package/src/utils/date.ts +62 -0
  101. package/src/utils/routing.ts +23 -13
  102. package/src/utils/swap.ts +113 -11
  103. package/src/utils/time.ts +52 -0
  104. package/src/utils/wallets.ts +13 -4
  105. package/dist/components/Header.d.ts +0 -10
  106. package/dist/components/Header.d.ts.map +0 -1
  107. package/dist/pages/ConfirmWalletsPage.d.ts +0 -3
  108. package/dist/pages/ConfirmWalletsPage.d.ts.map +0 -1
  109. package/src/components/Header.tsx +0 -37
  110. package/src/pages/ConfirmWalletsPage.tsx +0 -80
@@ -117,19 +117,22 @@ export function isRouteParametersChanged(
117
117
  currentParams: BestRouteParams
118
118
  ) {
119
119
  return (
120
- prevParams.fromChain?.name !== currentParams.fromChain?.name ||
121
- prevParams.toChain?.name !== currentParams.toChain?.name ||
122
- prevParams.fromToken?.symbol !== currentParams.fromToken?.symbol ||
123
- prevParams.toToken?.symbol !== currentParams.toToken?.symbol ||
124
- prevParams.fromToken?.blockchain !== currentParams.fromToken?.blockchain ||
125
- prevParams.toToken?.blockchain !== currentParams.toToken?.blockchain ||
126
- prevParams.fromToken?.address !== currentParams.fromToken?.address ||
127
- prevParams.toToken?.address !== currentParams.toToken?.address ||
128
- prevParams.inputAmount !== currentParams.inputAmount ||
129
- prevParams.slippage !== currentParams.slippage ||
130
- prevParams.customSlippage !== currentParams.customSlippage ||
131
- prevParams.disabledLiquiditySources?.length !==
132
- currentParams.disabledLiquiditySources?.length
120
+ !!currentParams.fromToken &&
121
+ !!currentParams.toToken &&
122
+ (prevParams.fromChain?.name !== currentParams.fromChain?.name ||
123
+ prevParams.toChain?.name !== currentParams.toChain?.name ||
124
+ prevParams.fromToken?.symbol !== currentParams.fromToken?.symbol ||
125
+ prevParams.toToken?.symbol !== currentParams.toToken?.symbol ||
126
+ prevParams.fromToken?.blockchain !==
127
+ currentParams.fromToken?.blockchain ||
128
+ prevParams.toToken?.blockchain !== currentParams.toToken?.blockchain ||
129
+ prevParams.fromToken?.address !== currentParams.fromToken?.address ||
130
+ prevParams.toToken?.address !== currentParams.toToken?.address ||
131
+ prevParams.inputAmount !== currentParams.inputAmount ||
132
+ prevParams.slippage !== currentParams.slippage ||
133
+ prevParams.customSlippage !== currentParams.customSlippage ||
134
+ prevParams.disabledLiquiditySources?.length !==
135
+ currentParams.disabledLiquiditySources?.length)
133
136
  );
134
137
  }
135
138
 
@@ -148,3 +151,10 @@ export function getBestRouteWithCalculatedFees(
148
151
  result: { ...bestRoute.result, swaps: swapsWithFee },
149
152
  };
150
153
  }
154
+
155
+ //todo: refactor bestRoute store and add loadingStatus
156
+ export const getBestRouteStatus = (loading: boolean, error: boolean) => {
157
+ if (loading) return 'loading';
158
+ if (error) return 'failed';
159
+ else return 'success';
160
+ };
package/src/utils/swap.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { PendingSwap } from '@rango-dev/ui/dist/containers/History/types';
2
1
  import {
3
2
  WalletTypeAndAddress,
4
3
  SwapSavedSettings,
@@ -19,7 +18,12 @@ import { WalletType } from '@rango-dev/wallets-shared';
19
18
  import { getRequiredBalanceOfWallet } from './routing';
20
19
  import { getRequiredChains, SelectedWallet } from './wallets';
21
20
  import { LoadingStatus } from '../store/meta';
22
- import { SwapButtonState } from '../types';
21
+ import { ConvertedToken, SwapButtonState } from '../types';
22
+ import {
23
+ PendingSwapNetworkStatus,
24
+ PendingSwapStep,
25
+ } from '@rango-dev/queue-manager-rango-preset';
26
+ import { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
23
27
 
24
28
  export function getOutputRatio(
25
29
  inputUsdValue: BigNumber,
@@ -128,12 +132,14 @@ export function getSwapButtonState(
128
132
  hasLimitError: boolean,
129
133
  highValueLoss: boolean,
130
134
  priceImpactCanNotBeComputed: boolean,
131
- needsToWarnEthOnPath: boolean
135
+ needsToWarnEthOnPath: boolean,
136
+ inputIsZero: boolean
132
137
  ): SwapButtonState {
133
138
  if (loadingMetaStatus !== 'success')
134
139
  return { title: 'Connect Wallet', disabled: true };
135
140
  if (accounts.length == 0) return { title: 'Connect Wallet', disabled: false };
136
141
  if (loading) return { title: 'Finding Best Route...', disabled: true };
142
+ else if (inputIsZero) return { title: 'Enter an amount', disabled: true };
137
143
  else if (!bestRoute) return { title: 'Swap', disabled: true };
138
144
  else if (hasLimitError) return { title: 'Limit Error', disabled: true };
139
145
  else if (highValueLoss)
@@ -185,6 +191,7 @@ export function calculatePendingSwap(
185
191
  finishTime: null,
186
192
  requestId: bestRoute.requestId || '',
187
193
  inputAmount: inputAmount,
194
+ //@ts-ignore
188
195
  wallets,
189
196
  status: 'running',
190
197
  isPaused: false,
@@ -199,6 +206,7 @@ export function calculatePendingSwap(
199
206
  settings: settings,
200
207
  simulationResult: simulationResult,
201
208
  validateBalanceOrFee,
209
+ //@ts-ignore
202
210
  steps:
203
211
  bestRoute.result?.swaps?.map((swap, index) => {
204
212
  const swapper = meta.swappers.find(
@@ -337,25 +345,24 @@ export function hasSlippageError(
337
345
 
338
346
  export function getMinRequiredSlippage(
339
347
  route: BestRouteResponse
340
- ): number | null {
348
+ ): string | null {
341
349
  const slippages = route.result?.swaps.map(
342
350
  (slippage) => slippage.recommendedSlippage
343
351
  );
344
352
  return (
345
353
  slippages
346
- ?.map((s) => parseFloat(s?.slippage || '0'))
347
- ?.filter((s) => s > 0)
348
- ?.sort((a, b) => b - a)
354
+ ?.map((s) => s?.slippage || '0')
355
+ ?.filter((s) => parseFloat(s) > 0)
356
+ ?.sort((a, b) => parseFloat(b) - parseFloat(a))
349
357
  ?.find(() => true) || null
350
358
  );
351
359
  }
352
360
 
353
361
  export function hasProperSlippage(
354
362
  userSlippage: string,
355
- minRequiredSlippage: number | null
363
+ minRequiredSlippage: string | null
356
364
  ) {
357
365
  if (!minRequiredSlippage) return true;
358
- //@ts-ignore
359
366
  return parseFloat(userSlippage) >= parseFloat(minRequiredSlippage);
360
367
  }
361
368
 
@@ -384,7 +391,7 @@ export function hasEnoughBalanceAndProperSlippage(
384
391
  route: BestRouteResponse,
385
392
  selectedWallets: SelectedWallet[],
386
393
  userSlippage: string,
387
- minRequiredSlippage: number | null
394
+ minRequiredSlippage: string | null
388
395
  ): boolean {
389
396
  return (
390
397
  hasEnoughBalance(route, selectedWallets) &&
@@ -427,6 +434,8 @@ export function createBestRouteRequestBody(
427
434
  });
428
435
  });
429
436
 
437
+ const filteredBlockchains = selectedWallets.map((wallet) => wallet.chain);
438
+
430
439
  const requestBody: BestRouteRequest = {
431
440
  amount: inputAmount.toString(),
432
441
  checkPrerequisites,
@@ -444,8 +453,8 @@ export function createBestRouteRequestBody(
444
453
  selectedWallets: selectedWalletsMap,
445
454
  swapperGroups: disabledLiquiditySources,
446
455
  swappersGroupsExclude: true,
447
- //@ts-ignore
448
456
  slippage: slippage.toString(),
457
+ ...(checkPrerequisites && { blockchains: filteredBlockchains }),
449
458
  };
450
459
 
451
460
  return requestBody;
@@ -539,3 +548,96 @@ export function getBalanceWarnings(
539
548
  return warningMessage;
540
549
  });
541
550
  }
551
+
552
+ export function calcOutputUsdValue(
553
+ outputAmount?: string,
554
+ tokenPrice?: number | null
555
+ ) {
556
+ const amount = !!outputAmount ? new BigNumber(outputAmount) : ZERO;
557
+
558
+ return amount.multipliedBy(tokenPrice || 0);
559
+ }
560
+
561
+ export function isNetworkStatusInWarningState(
562
+ pendingSwapStep: PendingSwapStep | null
563
+ ): boolean {
564
+ return (
565
+ !!pendingSwapStep &&
566
+ pendingSwapStep.networkStatus !== null &&
567
+ pendingSwapStep.networkStatus !== PendingSwapNetworkStatus.NetworkChanged
568
+ );
569
+ }
570
+
571
+ export function getSwapMessages(
572
+ pendingSwap: PendingSwap,
573
+ currentStep: PendingSwapStep | null
574
+ ): {
575
+ shortMessage: string;
576
+ detailedMessage: { content: string; long: boolean };
577
+ } {
578
+ const textForRemove = 'bellow button or';
579
+ let message = pendingSwap.extraMessage;
580
+ let detailedMessage = pendingSwap.extraMessageDetail;
581
+
582
+ if (pendingSwap.networkStatusExtraMessageDetail?.includes(textForRemove)) {
583
+ pendingSwap.networkStatusExtraMessageDetail =
584
+ pendingSwap.networkStatusExtraMessageDetail.replace(textForRemove, '');
585
+ }
586
+
587
+ const networkWarningState = isNetworkStatusInWarningState(currentStep);
588
+
589
+ if (networkWarningState) {
590
+ message = pendingSwap.networkStatusExtraMessage || '';
591
+ detailedMessage = pendingSwap.networkStatusExtraMessageDetail || '';
592
+ switch (currentStep?.networkStatus) {
593
+ case PendingSwapNetworkStatus.WaitingForConnectingWallet:
594
+ message = message || 'Waiting for connecting wallet';
595
+ break;
596
+ case PendingSwapNetworkStatus.WaitingForQueue:
597
+ message = message || 'Waiting for other running tasks to be finished';
598
+ break;
599
+ case PendingSwapNetworkStatus.WaitingForNetworkChange:
600
+ message = message || 'Waiting for changing wallet network';
601
+ break;
602
+ }
603
+ }
604
+ detailedMessage = detailedMessage || '';
605
+ message = message || '';
606
+ const isRpc =
607
+ message?.indexOf('code') !== -1 && message?.indexOf('reason') !== -1;
608
+
609
+ return {
610
+ shortMessage: message,
611
+ detailedMessage: { content: detailedMessage, long: isRpc },
612
+ };
613
+ }
614
+
615
+ export function getLastConvertedTokenInFailedSwap(
616
+ pendingSwap: PendingSwap
617
+ ): ConvertedToken {
618
+ let resultToken: ConvertedToken = null;
619
+ if (pendingSwap.status === 'failed') {
620
+ const lastSuccessStep = pendingSwap.steps
621
+ .slice()
622
+ .reverse()
623
+ .filter((step) => step.status === 'success')[0];
624
+
625
+ if (lastSuccessStep) {
626
+ resultToken = {
627
+ blockchain: lastSuccessStep.toBlockchain,
628
+ symbol: lastSuccessStep.toSymbol,
629
+ outputAmount: lastSuccessStep.outputAmount,
630
+ address: lastSuccessStep.toSymbolAddress,
631
+ };
632
+ }
633
+ }
634
+ return resultToken;
635
+ }
636
+
637
+ export function shouldRetrySwap(pendingSwap: PendingSwap) {
638
+ return (
639
+ pendingSwap.status === 'failed' &&
640
+ !!pendingSwap.finishTime &&
641
+ new Date().getTime() - parseInt(pendingSwap.finishTime) < 4 * 3600 * 1000
642
+ );
643
+ }
@@ -0,0 +1,52 @@
1
+ import { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
2
+
3
+ export function timeSince(timeMillis: number): string {
4
+ const seconds = Math.floor((new Date().getTime() - timeMillis) / 1000);
5
+ let intervalType: string;
6
+
7
+ let interval = Math.floor(seconds / 31536000);
8
+ if (interval >= 1) {
9
+ intervalType = 'year';
10
+ } else {
11
+ interval = Math.floor(seconds / 2592000);
12
+ if (interval >= 1) {
13
+ intervalType = 'month';
14
+ } else {
15
+ interval = Math.floor(seconds / 86400);
16
+ if (interval >= 1) {
17
+ intervalType = 'day';
18
+ } else {
19
+ interval = Math.floor(seconds / 3600);
20
+ if (interval >= 1) {
21
+ intervalType = 'hour';
22
+ } else {
23
+ interval = Math.floor(seconds / 60);
24
+ if (interval >= 1) {
25
+ intervalType = 'minute';
26
+ } else {
27
+ interval = seconds;
28
+ intervalType = 'second';
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ if (interval > 1 || interval === 0) {
36
+ intervalType += 's';
37
+ }
38
+
39
+ return interval + ' ' + intervalType;
40
+ }
41
+
42
+ export function getSwapDate(pendingSwap: PendingSwap) {
43
+ return pendingSwap.finishTime
44
+ ? `Finished ${timeSince(parseInt(pendingSwap.finishTime))} ago @ ${new Date(
45
+ parseInt(pendingSwap.finishTime)
46
+ ).toLocaleString()}`
47
+ : `Started ${timeSince(
48
+ parseInt(pendingSwap.creationTime)
49
+ )} ago @ ${new Date(
50
+ parseInt(pendingSwap.creationTime)
51
+ ).toLocaleString()}`;
52
+ }
@@ -441,10 +441,13 @@ export function getSortedTokens(
441
441
  return sortTokens(getTokensWithBalance(filteredTokens, balances));
442
442
  }
443
443
 
444
- export function tokensAreEqual(tokenA: Token | null, tokenB: Token | null) {
444
+ export function tokensAreEqual(
445
+ tokenA: Pick<Token, 'blockchain' | 'symbol' | 'address'> | null,
446
+ tokenB: Pick<Token, 'blockchain' | 'symbol' | 'address'> | null
447
+ ) {
445
448
  return (
446
449
  tokenA?.blockchain === tokenB?.blockchain &&
447
- tokenA?.name === tokenB?.name &&
450
+ tokenA?.symbol === tokenB?.symbol &&
448
451
  tokenA?.address === tokenB?.address
449
452
  );
450
453
  }
@@ -469,7 +472,13 @@ export function sortWalletsBasedOnState(
469
472
  (a, b) =>
470
473
  Number(b.state === WalletStatus.CONNECTED) -
471
474
  Number(a.state === WalletStatus.CONNECTED) ||
472
- Number(b.state === WalletStatus.DISCONNECTED) -
473
- Number(a.state === WalletStatus.DISCONNECTED)
475
+ Number(
476
+ b.state === WalletStatus.DISCONNECTED ||
477
+ b.state === WalletStatus.CONNECTING
478
+ ) -
479
+ Number(
480
+ a.state === WalletStatus.DISCONNECTED ||
481
+ a.state === WalletStatus.CONNECTING
482
+ )
474
483
  );
475
484
  }
@@ -1,10 +0,0 @@
1
- /// <reference types="react" />
2
- export declare const HeaderContainer: any;
3
- export interface PropTypes {
4
- onClickRefresh: () => void;
5
- title?: string;
6
- titleSize?: number;
7
- titleWeight?: number;
8
- }
9
- export declare function Header(props: PropTypes): JSX.Element;
10
- //# sourceMappingURL=Header.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../src/components/Header.tsx"],"names":[],"mappings":";AAKA,eAAO,MAAM,eAAe,KAM1B,CAAC;AAEH,MAAM,WAAW,SAAS;IACxB,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,eAgBtC"}
@@ -1,3 +0,0 @@
1
- /// <reference types="react" />
2
- export declare function ConfirmWalletsPage(): JSX.Element;
3
- //# sourceMappingURL=ConfirmWalletsPage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ConfirmWalletsPage.d.ts","sourceRoot":"","sources":["../src/pages/ConfirmWalletsPage.tsx"],"names":[],"mappings":";AAmBA,wBAAgB,kBAAkB,gBA4DjC"}
@@ -1,37 +0,0 @@
1
- import React from 'react';
2
- import { css, styled, Typography } from '@rango-dev/ui';
3
- import { HeaderButtons } from './HeaderButtons';
4
- import { useTranslation } from 'react-i18next';
5
-
6
- export const HeaderContainer = styled('div', {
7
- display: 'flex',
8
- justifyContent: 'space-between',
9
- alignItems: 'center',
10
- width: '100%',
11
- padding: '$16 0',
12
- });
13
-
14
- export interface PropTypes {
15
- onClickRefresh: () => void;
16
- title?: string;
17
- titleSize?: number;
18
- titleWeight?: number;
19
- }
20
-
21
- export function Header(props: PropTypes) {
22
- const { onClickRefresh, title, titleSize, titleWeight } = props;
23
- const { t } = useTranslation();
24
- const titleStyle = css({
25
- fontSize: `${titleSize}px !important`,
26
- fontWeight: `${titleWeight} !important`,
27
- });
28
-
29
- return (
30
- <HeaderContainer>
31
- <Typography variant="h4" className={titleStyle()}>
32
- {title ? t(title.toLocaleLowerCase()) : ''}
33
- </Typography>
34
- <HeaderButtons onClickRefresh={onClickRefresh} />
35
- </HeaderContainer>
36
- );
37
- }
@@ -1,80 +0,0 @@
1
- import React, { useEffect } from 'react';
2
- import { ConfirmWallets } from '@rango-dev/ui';
3
- import { useNavigate } from 'react-router-dom';
4
- import { useBestRouteStore } from '../store/bestRoute';
5
- import { useWalletsStore } from '../store/wallets';
6
- import { useWallets } from '@rango-dev/wallets-core';
7
- import { navigationRoutes } from '../constants/navigationRoutes';
8
- import {
9
- getKeplrCompatibleConnectedWallets,
10
- getRequiredChains,
11
- getSelectableWallets,
12
- isExperimentalChain,
13
- } from '../utils/wallets';
14
- import { requiredWallets } from '../utils/swap';
15
- import { decimalNumber } from '../utils/numbers';
16
- import { useMetaStore } from '../store/meta';
17
- import { Network, WalletType } from '@rango-dev/wallets-shared';
18
- import { useNavigateBack } from '../hooks/useNavigateBack';
19
-
20
- export function ConfirmWalletsPage() {
21
- const navigate = useNavigate();
22
- const { navigateBackFrom } = useNavigateBack();
23
- const bestRoute = useBestRouteStore.use.bestRoute();
24
-
25
- const { blockchains } = useMetaStore.use.meta();
26
- const accounts = useWalletsStore.use.accounts();
27
- const selectedWallets = useWalletsStore.use.selectedWallets();
28
- const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
29
- const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
30
-
31
- const { getWalletInfo, connect } = useWallets();
32
- const confirmDisabled = !requiredWallets(bestRoute).every((chain) =>
33
- selectedWallets.map((wallet) => wallet.chain).includes(chain)
34
- );
35
-
36
- const firstStep = bestRoute?.result?.swaps[0];
37
- const lastStep =
38
- bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1];
39
-
40
- const fromAmount = decimalNumber(firstStep?.fromAmount, 3);
41
- const toAmount = decimalNumber(lastStep?.toAmount, 3);
42
- useEffect(() => {
43
- initSelectedWallets();
44
- }, []);
45
-
46
- const selectableWallets = getSelectableWallets(
47
- accounts,
48
- selectedWallets,
49
- getWalletInfo
50
- );
51
-
52
- const handleConnectChain = (wallet: string) => {
53
- const network = wallet as Network;
54
- getKeplrCompatibleConnectedWallets(selectableWallets).forEach(
55
- (compatibleWallet: WalletType) => connect?.(compatibleWallet, network)
56
- );
57
- };
58
-
59
- return (
60
- <ConfirmWallets
61
- requiredWallets={getRequiredChains(bestRoute)}
62
- selectableWallets={selectableWallets}
63
- onBack={navigateBackFrom.bind(null, navigationRoutes.confirmWallets)}
64
- swap={bestRoute}
65
- fromAmount={fromAmount}
66
- toAmount={toAmount}
67
- onConfirm={() =>
68
- navigate(navigationRoutes.confirmSwap, { replace: true })
69
- }
70
- onChange={(wallet) => setSelectedWallet(wallet)}
71
- confirmDisabled={confirmDisabled}
72
- handleConnectChain={(wallet) => handleConnectChain(wallet)}
73
- isExperimentalChain={(wallet) =>
74
- getKeplrCompatibleConnectedWallets(selectableWallets).length > 0
75
- ? isExperimentalChain(blockchains, wallet)
76
- : false
77
- }
78
- />
79
- );
80
- }