@rango-dev/widget-embedded 0.20.1-next.1 → 0.20.1-next.3
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/components/Quote/Quote.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +157 -0
- package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
- package/dist/components/Quote/QuoteSummary.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.helpers.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +2 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
- package/dist/components/SwapsGroup/SwapsGroup.d.ts.map +1 -1
- package/dist/constants/routing.d.ts +1 -0
- package/dist/constants/routing.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/utils/date.d.ts.map +1 -1
- package/dist/utils/numbers.d.ts +1 -5
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/time.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/components/Quote/Quote.styles.ts +5 -1
- package/src/components/Quote/Quote.tsx +53 -15
- package/src/components/Quote/QuoteSummary.tsx +17 -2
- package/src/components/SwapDetails/SwapDetails.helpers.tsx +7 -1
- package/src/components/SwapDetails/SwapDetails.tsx +21 -1
- package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +6 -0
- package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +2 -0
- package/src/components/SwapsGroup/SwapsGroup.tsx +13 -7
- package/src/constants/routing.ts +2 -0
- package/src/pages/Home.tsx +11 -1
- package/src/utils/date.ts +22 -8
- package/src/utils/numbers.ts +8 -58
- package/src/utils/time.ts +25 -69
package/src/utils/numbers.ts
CHANGED
|
@@ -4,8 +4,7 @@ import type { BestRouteResponse } from 'rango-sdk';
|
|
|
4
4
|
|
|
5
5
|
import { BigNumber } from 'bignumber.js';
|
|
6
6
|
|
|
7
|
-
|
|
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
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
69
|
-
?
|
|
70
|
-
|
|
71
|
-
|
|
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
|
}
|