@rango-dev/widget-embedded 0.20.1-next.0 → 0.20.1-next.2

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 (51) hide show
  1. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  2. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  3. package/dist/components/Layout/Layout.d.ts.map +1 -1
  4. package/dist/components/Quote/Quote.d.ts.map +1 -1
  5. package/dist/components/Quote/Quote.styles.d.ts +157 -0
  6. package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
  7. package/dist/components/Quote/QuoteSummary.d.ts.map +1 -1
  8. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  9. package/dist/components/SwapDetails/SwapDetails.helpers.d.ts.map +1 -1
  10. package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
  11. package/dist/components/SwapDetailsModal/SwapDetailsModal.d.ts.map +1 -1
  12. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +2 -0
  13. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
  14. package/dist/components/SwapsGroup/SwapsGroup.d.ts.map +1 -1
  15. package/dist/components/WalletModal/WalletModal.d.ts.map +1 -1
  16. package/dist/constants/index.d.ts +1 -0
  17. package/dist/constants/index.d.ts.map +1 -1
  18. package/dist/constants/routing.d.ts +1 -0
  19. package/dist/constants/routing.d.ts.map +1 -1
  20. package/dist/containers/App/App.styles.d.ts.map +1 -1
  21. package/dist/index.js +1 -1
  22. package/dist/index.js.map +4 -4
  23. package/dist/pages/Home.d.ts.map +1 -1
  24. package/dist/utils/common.d.ts.map +1 -1
  25. package/dist/utils/date.d.ts.map +1 -1
  26. package/dist/utils/numbers.d.ts +1 -5
  27. package/dist/utils/numbers.d.ts.map +1 -1
  28. package/dist/utils/time.d.ts.map +1 -1
  29. package/package.json +2 -2
  30. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +4 -1
  31. package/src/components/ConfirmWalletsModal/WalletList.tsx +4 -1
  32. package/src/components/Layout/Layout.styles.ts +3 -3
  33. package/src/components/Layout/Layout.tsx +9 -2
  34. package/src/components/Quote/Quote.styles.ts +5 -1
  35. package/src/components/Quote/Quote.tsx +53 -15
  36. package/src/components/Quote/QuoteSummary.tsx +17 -2
  37. package/src/components/SwapDetails/SwapDetails.helpers.tsx +7 -1
  38. package/src/components/SwapDetails/SwapDetails.tsx +21 -1
  39. package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +9 -1
  40. package/src/components/SwapDetailsModal/SwapDetailsModal.tsx +3 -1
  41. package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +2 -0
  42. package/src/components/SwapsGroup/SwapsGroup.tsx +13 -7
  43. package/src/components/WalletModal/WalletModal.tsx +3 -1
  44. package/src/constants/index.ts +1 -0
  45. package/src/constants/routing.ts +2 -0
  46. package/src/containers/App/App.styles.ts +1 -2
  47. package/src/pages/Home.tsx +11 -1
  48. package/src/utils/common.ts +3 -1
  49. package/src/utils/date.ts +22 -8
  50. package/src/utils/numbers.ts +8 -58
  51. package/src/utils/time.ts +25 -69
@@ -22,7 +22,8 @@ import { useAppStore } from '../store/AppStore';
22
22
  import { useQuoteStore } from '../store/quote';
23
23
  import { useUiStore } from '../store/ui';
24
24
  import { useWalletsStore } from '../store/wallets';
25
- import { numberToString } from '../utils/numbers';
25
+ import { getContainer } from '../utils/common';
26
+ import { formatTooltipNumbers, numberToString } from '../utils/numbers';
26
27
  import { getPriceImpact, getPriceImpactLevel } from '../utils/quote';
27
28
  import { canComputePriceImpact, getSwapButtonState } from '../utils/swap';
28
29
  import { formatBalance, isFetchingBalance } from '../utils/wallets';
@@ -192,6 +193,9 @@ export function Home() {
192
193
  USD_VALUE_MIN_DECIMALS,
193
194
  USD_VALUE_MAX_DECIMALS
194
195
  ),
196
+ realUsdValue: priceImpactInputCanNotBeComputed
197
+ ? undefined
198
+ : formatTooltipNumbers(inputUsdValue),
195
199
  error: priceImpactInputCanNotBeComputed
196
200
  ? errorMessages().unknownPriceError.impactTitle
197
201
  : undefined,
@@ -199,6 +203,7 @@ export function Home() {
199
203
  disabled={fetchMetaStatus === 'failed'}
200
204
  loading={fetchMetaStatus === 'loading'}
201
205
  loadingBalance={fetchingBalance}
206
+ tooltipContainer={getContainer()}
202
207
  onSelectMaxBalance={() => {
203
208
  if (fromTokenFormattedBalance !== '0') {
204
209
  setInputAmount(tokenBalanceReal.split(',').join(''));
@@ -239,6 +244,10 @@ export function Home() {
239
244
  USD_VALUE_MIN_DECIMALS,
240
245
  USD_VALUE_MAX_DECIMALS
241
246
  ),
247
+ realValue: formatTooltipNumbers(outputAmount),
248
+ realUsdValue: priceImpactOutputCanNotBeComputed
249
+ ? undefined
250
+ : formatTooltipNumbers(outputUsdValue),
242
251
  error: priceImpactOutputCanNotBeComputed
243
252
  ? errorMessages().unknownPriceError.impactTitle
244
253
  : undefined,
@@ -246,6 +255,7 @@ export function Home() {
246
255
  onClickToken={() => navigate(navigationRoutes.toSwap)}
247
256
  disabled={fetchMetaStatus === 'failed'}
248
257
  loading={fetchMetaStatus === 'loading'}
258
+ tooltipContainer={getContainer()}
249
259
  />
250
260
  </InputsContainer>
251
261
  <div className="quote__container">
@@ -1,3 +1,5 @@
1
+ import { RANGO_SWAP_BOX_ID } from '../constants';
2
+
1
3
  export function removeDuplicateFrom<T>(array: T[]): T[] {
2
4
  return Array.from(new Set(array));
3
5
  }
@@ -31,4 +33,4 @@ export function containsText(text: string, searchText: string): boolean {
31
33
  }
32
34
 
33
35
  export const getContainer = () =>
34
- document.getElementById('swap-box') as HTMLElement;
36
+ document.getElementById(RANGO_SWAP_BOX_ID) as HTMLElement;
package/src/utils/date.ts CHANGED
@@ -19,39 +19,53 @@ export const groupSwapsByDate: GroupBy = (swaps) => {
19
19
  },
20
20
  ],
21
21
  [
22
- 'month',
22
+ 'week',
23
23
  {
24
- title: 'Last month',
24
+ title: 'This week',
25
25
  swaps: [],
26
26
  },
27
27
  ],
28
28
  [
29
- 'year',
29
+ 'month',
30
30
  {
31
- title: 'Last year',
31
+ title: 'This month',
32
32
  swaps: [],
33
33
  },
34
34
  ],
35
35
  [
36
- 'history',
36
+ 'year',
37
37
  {
38
- title: 'History',
38
+ title: 'This year',
39
39
  swaps: [],
40
40
  },
41
41
  ],
42
42
  ]);
43
43
 
44
+ function addYearsToOutput(key: string, swap: PendingSwap) {
45
+ if (!output.has(key)) {
46
+ output.set(key, {
47
+ title: key,
48
+ swaps: [],
49
+ });
50
+ }
51
+ output.get(key)?.swaps.push(swap);
52
+ }
53
+
44
54
  const now = dayjs();
45
55
  swaps.forEach((swap) => {
46
- const swapDate = dayjs(Number(swap.creationTime));
56
+ const time = Number(swap.creationTime);
57
+ const swapDate = dayjs(time);
47
58
  if (now.isSame(swapDate, 'day')) {
48
59
  output.get('today')?.swaps.push(swap);
60
+ } else if (now.isSame(swapDate, 'week')) {
61
+ output.get('week')?.swaps.push(swap);
49
62
  } else if (now.isSame(swapDate, 'month')) {
50
63
  output.get('month')?.swaps.push(swap);
51
64
  } else if (now.isSame(swapDate, 'year')) {
52
65
  output.get('year')?.swaps.push(swap);
53
66
  } else {
54
- output.get('history')?.swaps.push(swap);
67
+ const year = new Date(time).getFullYear().toString();
68
+ addYearsToOutput(year, swap);
55
69
  }
56
70
  });
57
71
 
@@ -4,8 +4,7 @@ import type { BestRouteResponse } from 'rango-sdk';
4
4
 
5
5
  import { BigNumber } from 'bignumber.js';
6
6
 
7
- export const percentToString = (p: number, fractions = 0): string =>
8
- (p * 100).toFixed(fractions);
7
+ import { TOOLTIP_DECIMALS } from '../constants/routing';
9
8
 
10
9
  export const secondsToString = (s: number): string => {
11
10
  const seconds = (s % 60).toString().padStart(2, '0');
@@ -96,13 +95,6 @@ export const numberToString = (
96
95
  );
97
96
  };
98
97
 
99
- export const convertBigNumberToHex = (
100
- value: BigNumber,
101
- decimals: number
102
- ): string => {
103
- return '0x' + value.shiftedBy(decimals).toString(16);
104
- };
105
-
106
98
  export const uint8ArrayToHex = (buffer: Uint8Array): string => {
107
99
  // buffer is an ArrayBuffer
108
100
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -110,43 +102,6 @@ export const uint8ArrayToHex = (buffer: Uint8Array): string => {
110
102
  return [...buffer].map((x) => x.toString(16).padStart(2, '0')).join('');
111
103
  };
112
104
 
113
- export function dollarToConciseString(num: number | undefined): string {
114
- if (!num) {
115
- return '-';
116
- }
117
- if (num < 1) {
118
- return ' < 1$';
119
- }
120
- if (num < 1000) {
121
- return numberToString(new BigNumber(num)) + '$';
122
- }
123
- if (num < 10_000) {
124
- return parseInt((num / 100).toString()) / 10 + 'K';
125
- }
126
- if (num < 1_000_000) {
127
- return parseInt((num / 1000).toString()) + 'K';
128
- }
129
- if (num < 100_000_000) {
130
- return parseInt((num / 100000).toString()) / 10 + 'M';
131
- }
132
- return parseInt((num / 1000000).toString()) + 'M';
133
- }
134
-
135
- export function removeExtraDecimals(num: string, maxDecimals: number): string {
136
- try {
137
- if (!num.includes('.')) {
138
- return num;
139
- }
140
- const [b, f] = num.split('.');
141
- if (f && f.length > maxDecimals) {
142
- return `${b}.${f.substring(0, maxDecimals)}`;
143
- }
144
- return num;
145
- } catch (e) {
146
- return num;
147
- }
148
- }
149
-
150
105
  export const totalArrivalTime = (
151
106
  data: { estimatedTimeInSeconds: number | null }[] | undefined
152
107
  ) => data?.reduce((a, b) => a + (b.estimatedTimeInSeconds ?? 0), 0) || 0;
@@ -167,16 +122,11 @@ export const isPositiveNumber = (text?: string) =>
167
122
  !!text && parseFloat(text) > 0;
168
123
  10;
169
124
 
170
- export function limitDecimalPlaces(
171
- numberString: string,
172
- maxDecimalPlaces = 4
173
- ): string {
174
- const number = parseFloat(numberString);
175
- if (isNaN(number)) {
176
- return numberString;
177
- } // Return the original string if it's not a valid number
178
-
179
- const multiplier = Math.pow(10, maxDecimalPlaces);
180
- const roundedNumber = Math.round(number * multiplier) / multiplier;
181
- return roundedNumber.toString();
125
+ export function formatTooltipNumbers(
126
+ number: BigNumber | string | number | null | undefined
127
+ ) {
128
+ return numberToString(number, TOOLTIP_DECIMALS, TOOLTIP_DECIMALS).replace(
129
+ /(?:\.0*|(\.\d+?)0*)$/,
130
+ '$1'
131
+ );
182
132
  }
package/src/utils/time.ts CHANGED
@@ -2,76 +2,32 @@ import type { PendingSwap } from 'rango-types';
2
2
 
3
3
  import { i18n } from '@lingui/core';
4
4
 
5
- const MILLISECOND_PER_SECOND = 1000;
6
- const SECONDS_PER_YEAR = 31536000;
7
- const SECONDS_PER_MONTH = 2592000;
8
- const SECONDS_PER_DAY = 86400;
9
- const SECONDS_PER_HOUR = 3600;
10
- const SECONDS_PER_MINUTE = 60;
11
-
12
- export function timeSince(millisecond: number): string {
13
- const seconds = Math.floor(
14
- (Date.now() - millisecond) / MILLISECOND_PER_SECOND
15
- );
16
-
17
- const intervals = [
18
- {
19
- turningPoint: SECONDS_PER_YEAR,
20
- label: i18n.t('year'),
21
- pluralLabel: i18n.t('years'),
22
- },
23
- {
24
- turningPoint: SECONDS_PER_MONTH,
25
- label: i18n.t('month'),
26
- pluralLabel: i18n.t('months'),
27
- },
28
- {
29
- turningPoint: SECONDS_PER_DAY,
30
- label: i18n.t('day'),
31
- pluralLabel: i18n.t('days'),
32
- },
33
- {
34
- turningPoint: SECONDS_PER_HOUR,
35
- label: i18n.t('hour'),
36
- pluralLabel: i18n.t('hours'),
37
- },
38
- {
39
- turningPoint: SECONDS_PER_MINUTE,
40
- label: i18n.t('minute'),
41
- pluralLabel: i18n.t('minutes'),
42
- },
43
- ];
44
-
45
- const sortedIntervals = intervals.sort(
46
- (a, b) => b.turningPoint - a.turningPoint
47
- );
48
-
49
- for (const interval of sortedIntervals) {
50
- const { turningPoint, label, pluralLabel } = interval;
51
- const intervalCount = Math.floor(seconds / turningPoint);
52
- if (intervalCount > 1) {
53
- return `${intervalCount} ${pluralLabel}`;
54
- }
55
- if (intervalCount === 1) {
56
- return `${intervalCount} ${label}`;
57
- }
58
- }
59
-
60
- if (seconds > 1) {
61
- return `${seconds} ${i18n.t('seconds')}`;
62
- }
63
-
64
- return `${seconds} ${i18n.t('second')}`;
5
+ const daysOfWeek = [
6
+ i18n.t('Sunday'),
7
+ i18n.t('Monday'),
8
+ i18n.t('Tuesday'),
9
+ i18n.t('Wednesday'),
10
+ i18n.t('Thursday'),
11
+ i18n.t('Friday'),
12
+ i18n.t('Saturday'),
13
+ ];
14
+
15
+ export function timeSince(millisecond: number) {
16
+ const date = new Date(millisecond);
17
+ const day = date.getDate();
18
+ const month = date.toLocaleString('default', { month: 'long' });
19
+ const year = date.getFullYear();
20
+ const isToday = date.getDay() === new Date().getDay();
21
+ const formattedDate = isToday
22
+ ? i18n.t('Today')
23
+ : `${daysOfWeek[date.getDay()]} ${day} ${month} ${year}`;
24
+
25
+ return `${formattedDate}, ${new Date(millisecond).toLocaleTimeString()}`;
65
26
  }
66
27
 
67
28
  export function getSwapDate(pendingSwap: PendingSwap) {
68
- return pendingSwap.finishTime
69
- ? i18n.t({
70
- id: '{time} ago',
71
- values: { time: timeSince(parseInt(pendingSwap.finishTime)) },
72
- })
73
- : i18n.t({
74
- id: '{time} ago',
75
- values: { time: timeSince(parseInt(pendingSwap.creationTime)) },
76
- });
29
+ const time = pendingSwap.finishTime
30
+ ? timeSince(parseInt(pendingSwap.finishTime))
31
+ : timeSince(parseInt(pendingSwap.creationTime));
32
+ return time;
77
33
  }