@rango-dev/widget-embedded 0.20.1-next.1 → 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 (33) hide show
  1. package/dist/components/Quote/Quote.d.ts.map +1 -1
  2. package/dist/components/Quote/Quote.styles.d.ts +157 -0
  3. package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
  4. package/dist/components/Quote/QuoteSummary.d.ts.map +1 -1
  5. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  6. package/dist/components/SwapDetails/SwapDetails.helpers.d.ts.map +1 -1
  7. package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
  8. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +2 -0
  9. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
  10. package/dist/components/SwapsGroup/SwapsGroup.d.ts.map +1 -1
  11. package/dist/constants/routing.d.ts +1 -0
  12. package/dist/constants/routing.d.ts.map +1 -1
  13. package/dist/index.js +1 -1
  14. package/dist/index.js.map +3 -3
  15. package/dist/pages/Home.d.ts.map +1 -1
  16. package/dist/utils/date.d.ts.map +1 -1
  17. package/dist/utils/numbers.d.ts +1 -5
  18. package/dist/utils/numbers.d.ts.map +1 -1
  19. package/dist/utils/time.d.ts.map +1 -1
  20. package/package.json +3 -3
  21. package/src/components/Quote/Quote.styles.ts +5 -1
  22. package/src/components/Quote/Quote.tsx +53 -15
  23. package/src/components/Quote/QuoteSummary.tsx +17 -2
  24. package/src/components/SwapDetails/SwapDetails.helpers.tsx +7 -1
  25. package/src/components/SwapDetails/SwapDetails.tsx +21 -1
  26. package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +6 -0
  27. package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +2 -0
  28. package/src/components/SwapsGroup/SwapsGroup.tsx +13 -7
  29. package/src/constants/routing.ts +2 -0
  30. package/src/pages/Home.tsx +11 -1
  31. package/src/utils/date.ts +22 -8
  32. package/src/utils/numbers.ts +8 -58
  33. package/src/utils/time.ts +25 -69
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
  }