@rango-dev/widget-embedded 0.20.1-next.0 → 0.20.1-next.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 (91) hide show
  1. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -0
  2. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
  3. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  4. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  5. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +159 -0
  6. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
  7. package/dist/components/HeaderButtons/HeaderButtons.types.d.ts +0 -1
  8. package/dist/components/HeaderButtons/HeaderButtons.types.d.ts.map +1 -1
  9. package/dist/components/HeaderButtons/HomeButtons.d.ts.map +1 -1
  10. package/dist/components/HeaderButtons/RefreshButton.d.ts +6 -0
  11. package/dist/components/HeaderButtons/RefreshButton.d.ts.map +1 -0
  12. package/dist/components/Layout/Layout.d.ts.map +1 -1
  13. package/dist/components/Quote/Quote.d.ts.map +1 -1
  14. package/dist/components/Quote/Quote.styles.d.ts +157 -0
  15. package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
  16. package/dist/components/Quote/QuoteSummary.d.ts.map +1 -1
  17. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  18. package/dist/components/SwapDetails/SwapDetails.helpers.d.ts.map +1 -1
  19. package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
  20. package/dist/components/SwapDetailsModal/SwapDetailsModal.d.ts.map +1 -1
  21. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +2 -0
  22. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
  23. package/dist/components/SwapsGroup/SwapsGroup.d.ts.map +1 -1
  24. package/dist/components/WalletModal/WalletModal.d.ts.map +1 -1
  25. package/dist/constants/index.d.ts +1 -0
  26. package/dist/constants/index.d.ts.map +1 -1
  27. package/dist/constants/routing.d.ts +1 -0
  28. package/dist/constants/routing.d.ts.map +1 -1
  29. package/dist/containers/App/App.styles.d.ts.map +1 -1
  30. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  31. package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +2 -2
  32. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  33. package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
  34. package/dist/index.d.ts +2 -2
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +1 -1
  37. package/dist/index.js.map +4 -4
  38. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  39. package/dist/pages/Home.d.ts.map +1 -1
  40. package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
  41. package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
  42. package/dist/store/slices/data.d.ts.map +1 -1
  43. package/dist/types/config.d.ts +16 -3
  44. package/dist/types/config.d.ts.map +1 -1
  45. package/dist/utils/common.d.ts.map +1 -1
  46. package/dist/utils/configs.d.ts +8 -0
  47. package/dist/utils/configs.d.ts.map +1 -1
  48. package/dist/utils/date.d.ts.map +1 -1
  49. package/dist/utils/numbers.d.ts +1 -5
  50. package/dist/utils/numbers.d.ts.map +1 -1
  51. package/dist/utils/settings.d.ts +1 -1
  52. package/dist/utils/time.d.ts.map +1 -1
  53. package/package.json +6 -6
  54. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +5 -2
  55. package/src/components/ConfirmWalletsModal/WalletList.tsx +4 -1
  56. package/src/components/HeaderButtons/HeaderButtons.styles.ts +16 -1
  57. package/src/components/HeaderButtons/HeaderButtons.types.ts +0 -1
  58. package/src/components/HeaderButtons/HomeButtons.tsx +20 -33
  59. package/src/components/HeaderButtons/RefreshButton.tsx +81 -0
  60. package/src/components/Layout/Layout.styles.ts +3 -3
  61. package/src/components/Layout/Layout.tsx +9 -2
  62. package/src/components/Quote/Quote.styles.ts +5 -1
  63. package/src/components/Quote/Quote.tsx +53 -15
  64. package/src/components/Quote/QuoteSummary.tsx +20 -4
  65. package/src/components/Slippage/Slippage.tsx +5 -5
  66. package/src/components/SwapDetails/SwapDetails.helpers.tsx +7 -1
  67. package/src/components/SwapDetails/SwapDetails.tsx +21 -1
  68. package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +9 -1
  69. package/src/components/SwapDetailsModal/SwapDetailsModal.tsx +3 -1
  70. package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +2 -0
  71. package/src/components/SwapsGroup/SwapsGroup.tsx +28 -11
  72. package/src/components/WalletModal/WalletModal.tsx +3 -1
  73. package/src/constants/index.ts +1 -0
  74. package/src/constants/routing.ts +2 -0
  75. package/src/containers/App/App.styles.ts +1 -2
  76. package/src/containers/Wallets/Wallets.tsx +11 -2
  77. package/src/hooks/useSwapInput.ts +6 -2
  78. package/src/hooks/useSyncStoresWithConfig.ts +17 -34
  79. package/src/index.ts +2 -0
  80. package/src/pages/ConfirmSwapPage.tsx +12 -10
  81. package/src/pages/Home.tsx +16 -2
  82. package/src/pages/LiquiditySourcePage.tsx +5 -2
  83. package/src/pages/SelectBlockchainPage.tsx +3 -3
  84. package/src/pages/SelectSwapItemsPage.tsx +5 -1
  85. package/src/store/slices/data.ts +5 -7
  86. package/src/types/config.ts +16 -3
  87. package/src/utils/common.ts +3 -1
  88. package/src/utils/configs.ts +41 -0
  89. package/src/utils/date.ts +24 -9
  90. package/src/utils/numbers.ts +8 -58
  91. package/src/utils/time.ts +25 -69
@@ -40,6 +40,7 @@ export function LiquiditySourcePage({ sourceType }: PropTypes) {
40
40
  const supportedUniqueSwappersGroups: Array<UniqueSwappersGroupType> =
41
41
  getUniqueSwappersGroups(swappers, disabledLiquiditySources);
42
42
 
43
+ const types = { Exchanges: i18n.t('Exchanges'), Bridges: i18n.t('Bridges') };
43
44
  const validTypes: Array<LiquiditySourceType> = [];
44
45
  if (sourceType === 'Exchanges') {
45
46
  validTypes.push('DEX');
@@ -103,7 +104,7 @@ export function LiquiditySourcePage({ sourceType }: PropTypes) {
103
104
  suffix: (
104
105
  <LiquiditySourceSuffix>
105
106
  <Button variant="ghost" size="xsmall" onClick={toggleAllSources}>
106
- {i18n.t(hasSelectAll ? 'Deselect all' : 'Select all')}
107
+ {hasSelectAll ? i18n.t('Deselect all') : i18n.t('Select all')}
107
108
  </Button>
108
109
  </LiquiditySourceSuffix>
109
110
  ),
@@ -115,7 +116,9 @@ export function LiquiditySourcePage({ sourceType }: PropTypes) {
115
116
  fullWidth
116
117
  color="light"
117
118
  variant="contained"
118
- placeholder={i18n.t('Search {sourceType}', { sourceType })}
119
+ placeholder={i18n.t('Search {sourceType}', {
120
+ sourceType: types[sourceType],
121
+ })}
119
122
  onChange={searchHandler}
120
123
  />
121
124
  {fetchStatus === 'loading' && <LoadingLiquiditySourceList />}
@@ -2,7 +2,7 @@ import { i18n } from '@lingui/core';
2
2
  import {
3
3
  Divider,
4
4
  getCountCategories,
5
- SelectableCategoryList
5
+ SelectableCategoryList,
6
6
  } from '@rango-dev/ui';
7
7
  import React, { useState } from 'react';
8
8
 
@@ -27,7 +27,7 @@ export function SelectBlockchainPage(props: PropTypes) {
27
27
  const fetchStatus = useAppStore().fetchStatus;
28
28
 
29
29
  const blockchains = useAppStore().blockchains({
30
- type: type
30
+ type,
31
31
  });
32
32
 
33
33
  const countActiveCategories = getCountCategories(blockchains);
@@ -37,7 +37,7 @@ export function SelectBlockchainPage(props: PropTypes) {
37
37
  return (
38
38
  <Layout
39
39
  header={{
40
- title: i18n.t(`Select Blockchain`)
40
+ title: i18n.t(`Select Blockchain`),
41
41
  }}>
42
42
  <Divider size={12} />
43
43
 
@@ -68,11 +68,15 @@ export function SelectSwapItemsPage(props: PropTypes) {
68
68
  setToToken({ token, meta: { blockchains, tokens } });
69
69
  }
70
70
  };
71
+ const types = {
72
+ source: i18n.t('Source'),
73
+ destination: i18n.t('Destination'),
74
+ };
71
75
 
72
76
  return (
73
77
  <Layout
74
78
  header={{
75
- title: i18n.t('Swap {type}', { type }),
79
+ title: i18n.t('Swap {type}', { type: types[type] }),
76
80
  }}>
77
81
  <BlockchainsSection
78
82
  blockchains={blockchains}
@@ -6,6 +6,7 @@ import type { StateCreator } from 'zustand';
6
6
 
7
7
  import { httpService as sdk } from '../../services/httpService';
8
8
  import { containsText } from '../../utils/common';
9
+ import { isTokenExcludedInConfig } from '../../utils/configs';
9
10
  import { sortLiquiditySourcesByGroupTitle } from '../../utils/settings';
10
11
  import { tokensAreEqual } from '../../utils/wallets';
11
12
 
@@ -81,21 +82,18 @@ export const createDataSlice: StateCreator<
81
82
  }
82
83
 
83
84
  const config = get().config;
84
- const supportedTokensFromConfig =
85
+ const supportedTokensConfig =
85
86
  (options.type === 'source' ? config.from?.tokens : config.to?.tokens) ??
86
- [];
87
+ {};
87
88
  const blockchains = get().blockchains({
88
89
  type: options.type,
89
90
  });
90
91
 
91
92
  const list = tokensFromState
92
93
  .filter((token) => {
93
- // If there is a list of tokens in config, we only keep them.
94
94
  if (
95
- supportedTokensFromConfig.length > 0 &&
96
- !supportedTokensFromConfig.some((asset) => {
97
- return tokensAreEqual(asset, token);
98
- })
95
+ supportedTokensConfig &&
96
+ isTokenExcludedInConfig(token, supportedTokensConfig)
99
97
  ) {
100
98
  return false;
101
99
  }
@@ -67,6 +67,19 @@ export type WidgetAffiliate = {
67
67
  wallets?: { [key: string]: string };
68
68
  };
69
69
 
70
+ /**
71
+ * `Tokens`
72
+ *
73
+ * @property {boolean} isExcluded - This is a boolean property capable of removing tokens from all or a blockchain.
74
+ * @property {Asset[]} tokens - The `tokens` property is an array of `Asset` objects that
75
+ * you could use that to limit tokens to some limited ones.
76
+ */
77
+
78
+ export type Tokens = {
79
+ isExcluded: boolean;
80
+ tokens: Asset[];
81
+ };
82
+
70
83
  /**
71
84
  * `BlockchainAndTokenConfig`
72
85
  *
@@ -75,8 +88,8 @@ export type WidgetAffiliate = {
75
88
  * which is selected. e.g. {blockchain: 'BSC', symbol: 'BNB', address: null}
76
89
  * @property {string[]} blockchains - An optional array of strings representing the supported
77
90
  * blockchains. e.g. ['BSC','ETHEREUM']
78
- * @property {Asset[]} tokens - The `tokens` property is an optional array of `Asset` objects that
79
- * you could use that to limit tokens to some limited ones.
91
+ * @property {Asset[] |{ [blockchain: string]: Tokens }} tokens - The `tokens` property is an optional object of `blockchain` objects or array of `Asset` objects
92
+ * that you could use that to limit tokens to some limited ones.
80
93
  * @property {Asset} pinnedTokens - The `pinnedTokens` property is an optional array of `Asset` objects that
81
94
  * you could use to pin tokens of your choice to the top of the token list.
82
95
  */
@@ -84,8 +97,8 @@ export type BlockchainAndTokenConfig = {
84
97
  blockchain?: string;
85
98
  token?: Asset;
86
99
  blockchains?: string[];
87
- tokens?: Asset[];
88
100
  pinnedTokens?: Asset[];
101
+ tokens?: Asset[] | { [blockchain: string]: Tokens };
89
102
  };
90
103
 
91
104
  /**
@@ -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;
@@ -1,10 +1,21 @@
1
+ import type { Tokens } from '../types';
2
+ import type { Asset, BlockchainMeta, Token } from 'rango-sdk';
3
+
1
4
  import { RANGO_PUBLIC_API_KEY } from '../constants';
2
5
 
6
+ import { tokensAreEqual } from './wallets';
7
+
3
8
  export interface Configs {
4
9
  API_KEY: string;
5
10
  BASE_URL?: string;
6
11
  }
7
12
 
13
+ type TokensConfig =
14
+ | Asset[]
15
+ | {
16
+ [blockchain: string]: Tokens;
17
+ };
18
+
8
19
  let configs: Configs = {
9
20
  API_KEY: RANGO_PUBLIC_API_KEY,
10
21
  };
@@ -38,3 +49,33 @@ export const DEFAULT_SECONDARY_RADIUS = 25;
38
49
  export const DEFAULT_FONT_FAMILY = 'Roboto';
39
50
 
40
51
  export const THEME_CLASS_NAME_PREFIX = `theme-widget`;
52
+
53
+ export const isTokenExcludedInConfig = (
54
+ token: Token | null,
55
+ tokensConfig?: TokensConfig
56
+ ) => {
57
+ let result = false;
58
+ if (tokensConfig && token) {
59
+ if (Array.isArray(tokensConfig)) {
60
+ result = !tokensConfig.some((asset) => tokensAreEqual(asset, token));
61
+ } else if (!Array.isArray(tokensConfig) && tokensConfig[token.blockchain]) {
62
+ result = tokensConfig[token.blockchain].tokens.some((asset) =>
63
+ tokensAreEqual(asset, token)
64
+ );
65
+ const isExcluded = tokensConfig[token.blockchain].isExcluded;
66
+ return (!isExcluded && !result) || (isExcluded && result);
67
+ }
68
+ }
69
+ return result;
70
+ };
71
+
72
+ export const isBlockchainExcludedInConfig = (
73
+ blockchain: BlockchainMeta | null,
74
+ blockchainsConfig?: string[]
75
+ ) => {
76
+ return (
77
+ blockchain &&
78
+ blockchainsConfig &&
79
+ !blockchainsConfig.includes(blockchain.name)
80
+ );
81
+ };
package/src/utils/date.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { GroupBy } from '../components/SwapsGroup/SwapsGroup.types';
2
2
  import type { PendingSwap } from 'rango-types';
3
3
 
4
+ import { i18n } from '@lingui/core';
4
5
  import dayjs from 'dayjs';
5
6
 
6
7
  export const groupSwapsByDate: GroupBy = (swaps) => {
@@ -14,44 +15,58 @@ export const groupSwapsByDate: GroupBy = (swaps) => {
14
15
  [
15
16
  'today',
16
17
  {
17
- title: 'Today',
18
+ title: i18n.t('Today'),
18
19
  swaps: [],
19
20
  },
20
21
  ],
21
22
  [
22
- 'month',
23
+ 'week',
23
24
  {
24
- title: 'Last month',
25
+ title: i18n.t('This week'),
25
26
  swaps: [],
26
27
  },
27
28
  ],
28
29
  [
29
- 'year',
30
+ 'month',
30
31
  {
31
- title: 'Last year',
32
+ title: i18n.t('This month'),
32
33
  swaps: [],
33
34
  },
34
35
  ],
35
36
  [
36
- 'history',
37
+ 'year',
37
38
  {
38
- title: 'History',
39
+ title: i18n.t('This year'),
39
40
  swaps: [],
40
41
  },
41
42
  ],
42
43
  ]);
43
44
 
45
+ function addYearsToOutput(key: string, swap: PendingSwap) {
46
+ if (!output.has(key)) {
47
+ output.set(key, {
48
+ title: key,
49
+ swaps: [],
50
+ });
51
+ }
52
+ output.get(key)?.swaps.push(swap);
53
+ }
54
+
44
55
  const now = dayjs();
45
56
  swaps.forEach((swap) => {
46
- const swapDate = dayjs(Number(swap.creationTime));
57
+ const time = Number(swap.creationTime);
58
+ const swapDate = dayjs(time);
47
59
  if (now.isSame(swapDate, 'day')) {
48
60
  output.get('today')?.swaps.push(swap);
61
+ } else if (now.isSame(swapDate, 'week')) {
62
+ output.get('week')?.swaps.push(swap);
49
63
  } else if (now.isSame(swapDate, 'month')) {
50
64
  output.get('month')?.swaps.push(swap);
51
65
  } else if (now.isSame(swapDate, 'year')) {
52
66
  output.get('year')?.swaps.push(swap);
53
67
  } else {
54
- output.get('history')?.swaps.push(swap);
68
+ const year = new Date(time).getFullYear().toString();
69
+ addYearsToOutput(year, swap);
55
70
  }
56
71
  });
57
72
 
@@ -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
  }