@lifi/widget 3.4.4 → 3.5.0

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 (116) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/_esm/components/AppContainer.js +11 -3
  3. package/_esm/components/AppContainer.js.map +1 -1
  4. package/_esm/components/Card/CardIconButton.d.ts +1 -1
  5. package/_esm/components/Header/WalletMenu.js +5 -1
  6. package/_esm/components/Header/WalletMenu.js.map +1 -1
  7. package/_esm/components/Step/Step.js +3 -3
  8. package/_esm/components/Step/Step.js.map +1 -1
  9. package/_esm/components/Step/StepProcess.js +3 -1
  10. package/_esm/components/Step/StepProcess.js.map +1 -1
  11. package/_esm/components/Tabs/Tabs.style.d.ts +1 -1
  12. package/_esm/components/Token/Token.js +8 -12
  13. package/_esm/components/Token/Token.js.map +1 -1
  14. package/_esm/components/TokenList/TokenList.js +4 -1
  15. package/_esm/components/TokenList/TokenList.js.map +1 -1
  16. package/_esm/components/TokenList/TokenList.style.d.ts +2 -2
  17. package/_esm/components/TokenList/TokenListItem.js +3 -1
  18. package/_esm/components/TokenList/TokenListItem.js.map +1 -1
  19. package/_esm/components/TransactionDetails.js +5 -11
  20. package/_esm/components/TransactionDetails.js.map +1 -1
  21. package/_esm/config/constants.d.ts +2 -1
  22. package/_esm/config/constants.js +2 -1
  23. package/_esm/config/constants.js.map +1 -1
  24. package/_esm/config/version.d.ts +1 -1
  25. package/_esm/config/version.js +1 -1
  26. package/_esm/hooks/useExplorer.d.ts +5 -0
  27. package/_esm/hooks/useExplorer.js +40 -0
  28. package/_esm/hooks/useExplorer.js.map +1 -0
  29. package/_esm/hooks/useProcessMessage.js +1 -1
  30. package/_esm/hooks/useRoutes.d.ts +1 -1
  31. package/_esm/hooks/useRoutes.js +4 -0
  32. package/_esm/hooks/useRoutes.js.map +1 -1
  33. package/_esm/i18n/bn.json +42 -33
  34. package/_esm/i18n/de.json +43 -34
  35. package/_esm/i18n/en.json +3 -2
  36. package/_esm/i18n/es.json +113 -104
  37. package/_esm/i18n/fr.json +45 -36
  38. package/_esm/i18n/hi.json +38 -29
  39. package/_esm/i18n/id.json +42 -33
  40. package/_esm/i18n/it.json +43 -34
  41. package/_esm/i18n/ja.json +45 -36
  42. package/_esm/i18n/ko.json +43 -34
  43. package/_esm/i18n/pt.json +45 -36
  44. package/_esm/i18n/th.json +45 -36
  45. package/_esm/i18n/tr.json +44 -35
  46. package/_esm/i18n/uk.json +45 -36
  47. package/_esm/i18n/vi.json +45 -36
  48. package/_esm/i18n/zh.json +45 -36
  49. package/_esm/pages/SelectTokenPage/useTokenListHeight.js +2 -0
  50. package/_esm/pages/SelectTokenPage/useTokenListHeight.js.map +1 -1
  51. package/_esm/pages/SendToWallet/BookmarksPage.js +3 -4
  52. package/_esm/pages/SendToWallet/BookmarksPage.js.map +1 -1
  53. package/_esm/pages/SendToWallet/ConnectedWalletsPage.js +5 -4
  54. package/_esm/pages/SendToWallet/ConnectedWalletsPage.js.map +1 -1
  55. package/_esm/pages/SendToWallet/RecentWalletsPage.js +3 -4
  56. package/_esm/pages/SendToWallet/RecentWalletsPage.js.map +1 -1
  57. package/_esm/pages/SendToWallet/SendToConfiguredWalletPage.js +3 -4
  58. package/_esm/pages/SendToWallet/SendToConfiguredWalletPage.js.map +1 -1
  59. package/_esm/pages/SendToWallet/SendToWalletPage.style.js +3 -1
  60. package/_esm/pages/SendToWallet/SendToWalletPage.style.js.map +1 -1
  61. package/_esm/pages/TransactionDetailsPage/TransactionDetailsPage.js +2 -11
  62. package/_esm/pages/TransactionDetailsPage/TransactionDetailsPage.js.map +1 -1
  63. package/_esm/pages/TransactionDetailsPage/TransferIdCard.d.ts +5 -0
  64. package/_esm/pages/TransactionDetailsPage/TransferIdCard.js +32 -0
  65. package/_esm/pages/TransactionDetailsPage/TransferIdCard.js.map +1 -0
  66. package/_esm/providers/I18nProvider/I18nProvider.js +2 -0
  67. package/_esm/providers/I18nProvider/I18nProvider.js.map +1 -1
  68. package/_esm/providers/I18nProvider/percentFormatter.d.ts +7 -0
  69. package/_esm/providers/I18nProvider/percentFormatter.js +19 -0
  70. package/_esm/providers/I18nProvider/percentFormatter.js.map +1 -0
  71. package/_esm/types/widget.d.ts +1 -0
  72. package/_esm/utils/elements.d.ts +2 -1
  73. package/_esm/utils/elements.js +1 -0
  74. package/_esm/utils/elements.js.map +1 -1
  75. package/components/AppContainer.tsx +31 -18
  76. package/components/Header/WalletMenu.tsx +7 -1
  77. package/components/Step/Step.tsx +3 -6
  78. package/components/Step/StepProcess.tsx +5 -2
  79. package/components/Token/Token.tsx +15 -18
  80. package/components/TokenList/TokenList.tsx +8 -1
  81. package/components/TokenList/TokenListItem.tsx +4 -1
  82. package/components/TransactionDetails.tsx +8 -17
  83. package/config/constants.ts +3 -1
  84. package/config/version.ts +1 -1
  85. package/hooks/useExplorer.ts +51 -0
  86. package/hooks/useProcessMessage.ts +1 -1
  87. package/hooks/useRoutes.ts +5 -0
  88. package/i18n/bn.json +42 -33
  89. package/i18n/de.json +43 -34
  90. package/i18n/en.json +3 -2
  91. package/i18n/es.json +113 -104
  92. package/i18n/fr.json +45 -36
  93. package/i18n/hi.json +38 -29
  94. package/i18n/id.json +42 -33
  95. package/i18n/it.json +43 -34
  96. package/i18n/ja.json +45 -36
  97. package/i18n/ko.json +43 -34
  98. package/i18n/pt.json +45 -36
  99. package/i18n/th.json +45 -36
  100. package/i18n/tr.json +44 -35
  101. package/i18n/uk.json +45 -36
  102. package/i18n/vi.json +45 -36
  103. package/i18n/zh.json +45 -36
  104. package/package.json +12 -12
  105. package/pages/SelectTokenPage/useTokenListHeight.ts +3 -0
  106. package/pages/SendToWallet/BookmarksPage.tsx +6 -4
  107. package/pages/SendToWallet/ConnectedWalletsPage.tsx +8 -7
  108. package/pages/SendToWallet/RecentWalletsPage.tsx +6 -6
  109. package/pages/SendToWallet/SendToConfiguredWalletPage.tsx +6 -6
  110. package/pages/SendToWallet/SendToWalletPage.style.tsx +3 -0
  111. package/pages/TransactionDetailsPage/TransactionDetailsPage.tsx +2 -32
  112. package/pages/TransactionDetailsPage/TransferIdCard.tsx +67 -0
  113. package/providers/I18nProvider/I18nProvider.tsx +2 -0
  114. package/providers/I18nProvider/percentFormatter.ts +18 -0
  115. package/types/widget.ts +1 -1
  116. package/utils/elements.ts +1 -0
@@ -10,7 +10,7 @@ import { AccountAvatar } from '../../components/Avatar/AccountAvatar.js';
10
10
  import { ListItem } from '../../components/ListItem/ListItem.js';
11
11
  import { ListItemButton } from '../../components/ListItem/ListItemButton.js';
12
12
  import { Menu } from '../../components/Menu.js';
13
- import { useChains } from '../../hooks/useChains.js';
13
+ import { useExplorer } from '../../hooks/useExplorer.js';
14
14
  import { useHeader } from '../../hooks/useHeader.js';
15
15
  import { useNavigateBack } from '../../hooks/useNavigateBack.js';
16
16
  import { useToAddressRequirements } from '../../hooks/useToAddressRequirements.js';
@@ -34,10 +34,10 @@ export const SendToConfiguredWalletPage = () => {
34
34
  const { requiredToChainType } = useToAddressRequirements();
35
35
  const { setSelectedBookmark } = useBookmarkActions();
36
36
  const { setFieldValue } = useFieldActions();
37
- const { getChainById } = useChains();
38
37
  const moreMenuId = useId();
39
38
  const [moreMenuAnchorEl, setMenuAnchorEl] = useState<HTMLElement | null>();
40
39
  const open = Boolean(moreMenuAnchorEl);
40
+ const { getAddressLink } = useExplorer();
41
41
 
42
42
  useHeader(t(`header.sendToWallet`));
43
43
 
@@ -65,11 +65,11 @@ export const SendToConfiguredWalletPage = () => {
65
65
 
66
66
  const handleViewOnExplorer = () => {
67
67
  if (selectedToAddress) {
68
- const chain = getChainById(
69
- defaultChainIdsByType[selectedToAddress.chainType],
70
- );
71
68
  window.open(
72
- `${chain?.metamask.blockExplorerUrls[0]}address/${selectedToAddress.address}`,
69
+ getAddressLink(
70
+ selectedToAddress.address,
71
+ defaultChainIdsByType[selectedToAddress.chainType],
72
+ ),
73
73
  '_blank',
74
74
  );
75
75
  }
@@ -44,6 +44,9 @@ interface FullHeightAdjustablePageContainerProps extends PageContainerProps {
44
44
 
45
45
  export const FullHeightAdjustablePageContainer = styled(
46
46
  SendToWalletPageContainer,
47
+ {
48
+ shouldForwardProp: (prop) => prop !== 'enableFullHeight',
49
+ },
47
50
  )<FullHeightAdjustablePageContainerProps>(({ theme, enableFullHeight }) => ({
48
51
  justifyContent: 'space-between',
49
52
  ...(enableFullHeight && theme.container?.height === '100%'
@@ -1,12 +1,8 @@
1
1
  import type { FullStatusData } from '@lifi/sdk';
2
- import { ContentCopyRounded } from '@mui/icons-material';
3
2
  import { Box, Typography } from '@mui/material';
4
3
  import { useEffect, useMemo } from 'react';
5
4
  import { useTranslation } from 'react-i18next';
6
5
  import { useLocation } from 'react-router-dom';
7
- import { Card } from '../../components/Card/Card.js';
8
- import { CardIconButton } from '../../components/Card/CardIconButton.js';
9
- import { CardTitle } from '../../components/Card/CardTitle.js';
10
6
  import { ContractComponent } from '../../components/ContractComponent/ContractComponent.js';
11
7
  import { PageContainer } from '../../components/PageContainer.js';
12
8
  import { getStepList } from '../../components/Step/StepList.js';
@@ -22,6 +18,7 @@ import { buildRouteFromTxHistory } from '../../utils/converters.js';
22
18
  import { navigationRoutes } from '../../utils/navigationRoutes.js';
23
19
  import { ContactSupportButton } from './ContactSupportButton.js';
24
20
  import { TransactionDetailsSkeleton } from './TransactionDetailsSkeleton.js';
21
+ import { TransferIdCard } from './TransferIdCard.js';
25
22
 
26
23
  export const TransactionDetailsPage: React.FC = () => {
27
24
  const { t, i18n } = useTranslation();
@@ -66,10 +63,6 @@ export const TransactionDetailsPage: React.FC = () => {
66
63
  }
67
64
  }, [isLoading, navigate, routeExecution]);
68
65
 
69
- const copySupportId = async () => {
70
- await navigator.clipboard.writeText(supportId);
71
- };
72
-
73
66
  const sourceTxHash = getSourceTxHash(routeExecution?.route);
74
67
 
75
68
  let supportId = sourceTxHash ?? routeExecution?.route.id ?? '';
@@ -117,30 +110,7 @@ export const TransactionDetailsPage: React.FC = () => {
117
110
  sx={{ marginTop: 2 }}
118
111
  />
119
112
  ) : null}
120
- <Card sx={{ marginTop: 2 }}>
121
- <Box
122
- sx={{
123
- display: 'flex',
124
- flex: 1,
125
- }}
126
- >
127
- <CardTitle flex={1}>{t('main.supportId')}</CardTitle>
128
- <Box mr={2} mt={1}>
129
- <CardIconButton size="small" onClick={copySupportId}>
130
- <ContentCopyRounded fontSize="inherit" />
131
- </CardIconButton>
132
- </Box>
133
- </Box>
134
- <Typography
135
- variant="body2"
136
- pt={1}
137
- pb={2}
138
- px={2}
139
- sx={{ wordBreak: 'break-all' }}
140
- >
141
- {supportId}
142
- </Typography>
143
- </Card>
113
+ <TransferIdCard transferId={supportId} />
144
114
  <Box mt={2}>
145
115
  <ContactSupportButton supportId={supportId} />
146
116
  </Box>
@@ -0,0 +1,67 @@
1
+ import { ContentCopyRounded, OpenInNew } from '@mui/icons-material';
2
+ import { Box, Typography } from '@mui/material';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { Card } from '../../components/Card/Card.js';
5
+ import { CardIconButton } from '../../components/Card/CardIconButton.js';
6
+ import { CardTitle } from '../../components/Card/CardTitle.js';
7
+ import { useExplorer } from '../../hooks/useExplorer.js';
8
+
9
+ interface TransferIdCardProps {
10
+ transferId: string;
11
+ }
12
+
13
+ const getTxHash = (transferId: string) =>
14
+ transferId.indexOf('_') !== -1
15
+ ? transferId.substring(0, transferId.indexOf('_'))
16
+ : transferId;
17
+
18
+ export const TransferIdCard = ({ transferId }: TransferIdCardProps) => {
19
+ const { t } = useTranslation();
20
+ const { getTransactionLink } = useExplorer();
21
+
22
+ const copyTransferId = async () => {
23
+ await navigator.clipboard.writeText(transferId);
24
+ };
25
+
26
+ const openTransferIdInExplorer = () => {
27
+ const txHash = getTxHash(transferId);
28
+ window.open(getTransactionLink(txHash), '_blank');
29
+ };
30
+
31
+ return (
32
+ <Card sx={{ marginTop: 2 }}>
33
+ <Box
34
+ sx={{
35
+ display: 'flex',
36
+ flex: 1,
37
+ }}
38
+ >
39
+ <CardTitle flex={1}>{t('main.transferId')}</CardTitle>
40
+ <Box
41
+ sx={{
42
+ gap: 1,
43
+ display: 'flex',
44
+ marginRight: 2,
45
+ marginTop: 1,
46
+ }}
47
+ >
48
+ <CardIconButton size="small" onClick={copyTransferId}>
49
+ <ContentCopyRounded fontSize="inherit" />
50
+ </CardIconButton>
51
+ <CardIconButton size="small" onClick={openTransferIdInExplorer}>
52
+ <OpenInNew fontSize="inherit" />
53
+ </CardIconButton>
54
+ </Box>
55
+ </Box>
56
+ <Typography
57
+ variant="body2"
58
+ pt={1}
59
+ pb={2}
60
+ px={2}
61
+ sx={{ wordBreak: 'break-all' }}
62
+ >
63
+ {transferId}
64
+ </Typography>
65
+ </Card>
66
+ );
67
+ };
@@ -8,6 +8,7 @@ import { deepMerge } from '../../utils/deepMerge.js';
8
8
  import { isItemAllowed } from '../../utils/item.js';
9
9
  import { useWidgetConfig } from '../WidgetProvider/WidgetProvider.js';
10
10
  import { currencyExtendedFormatter } from './currencyExtendedFormatter.js';
11
+ import { percentFormatter } from './percentFormatter.js';
11
12
  import type { LanguageKey, LanguageTranslationResources } from './types.js';
12
13
 
13
14
  export const I18nProvider: React.FC<React.PropsWithChildren> = ({
@@ -66,6 +67,7 @@ export const I18nProvider: React.FC<React.PropsWithChildren> = ({
66
67
  'currencyExt',
67
68
  currencyExtendedFormatter,
68
69
  );
70
+ i18n.services.formatter?.addCached('percent', percentFormatter);
69
71
 
70
72
  return i18n;
71
73
  }, [language, languageResources, languages]);
@@ -0,0 +1,18 @@
1
+ /**
2
+ * We use <0.01% for both small positive and negative changes to keep it simple and clear, focusing on minimal impact rather than direction.
3
+ * Examples:
4
+ * +0.007% -> <0.01%
5
+ * -0.003% -> <0.01%
6
+ */
7
+ export const percentFormatter = (lng: string | undefined, options: any) => {
8
+ const formatter = new Intl.NumberFormat(lng, {
9
+ ...options,
10
+ style: 'percent',
11
+ });
12
+ return (value: any) => {
13
+ if ((value > 0 && value < 0.0001) || (value < 0 && value > -0.0001)) {
14
+ return `<${formatter.format(0.0001)}`;
15
+ }
16
+ return formatter.format(value);
17
+ };
18
+ };
package/types/widget.ts CHANGED
@@ -188,7 +188,6 @@ export interface WidgetConfig {
188
188
  contractSecondaryComponent?: ReactNode;
189
189
  contractCompactComponent?: ReactNode;
190
190
  contractTool?: WidgetContractTool;
191
-
192
191
  integrator: string;
193
192
  apiKey?: string;
194
193
  /**
@@ -225,6 +224,7 @@ export interface WidgetConfig {
225
224
  tokens?: WidgetTokens;
226
225
  languages?: WidgetLanguages;
227
226
  languageResources?: LanguageResources;
227
+ explorerUrls?: Record<number | 'internal', string[]>;
228
228
  }
229
229
 
230
230
  export interface WidgetConfigProps {
package/utils/elements.ts CHANGED
@@ -3,6 +3,7 @@ export enum ElementId {
3
3
  Header = 'widget-header',
4
4
  RelativeContainer = 'widget-relative-container',
5
5
  ScrollableContainer = 'widget-scrollable-container',
6
+ TokenList = 'token-list',
6
7
  }
7
8
 
8
9
  export const createElementId = (ElementId: ElementId, elementId: string) =>