@lifi/widget 2.0.0-alpha.4 → 2.0.0-beta.1

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 (34) hide show
  1. package/cjs/components/Insurance/Insurance.js +2 -2
  2. package/cjs/components/Insurance/InsuranceCard.js +8 -2
  3. package/cjs/components/Insurance/InsuranceCollapsed.d.ts +2 -2
  4. package/cjs/components/Insurance/InsuranceCollapsed.js +2 -2
  5. package/cjs/components/Insurance/types.d.ts +2 -0
  6. package/cjs/config/version.d.ts +1 -1
  7. package/cjs/config/version.js +1 -1
  8. package/cjs/i18n/pt.json +8 -5
  9. package/cjs/i18n/uk.json +3 -3
  10. package/cjs/pages/SelectWalletPage/SelectWalletPage.js +5 -5
  11. package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +6 -4
  12. package/cjs/pages/SwapPage/SwapPage.js +4 -1
  13. package/cjs/providers/WalletProvider/WalletProvider.js +72 -28
  14. package/cjs/providers/WalletProvider/index.d.ts +1 -1
  15. package/cjs/providers/WalletProvider/index.js +1 -1
  16. package/cjs/providers/WalletProvider/types.d.ts +1 -1
  17. package/components/Insurance/Insurance.js +2 -2
  18. package/components/Insurance/InsuranceCard.js +9 -3
  19. package/components/Insurance/InsuranceCollapsed.d.ts +2 -2
  20. package/components/Insurance/InsuranceCollapsed.js +2 -2
  21. package/components/Insurance/types.d.ts +2 -0
  22. package/config/version.d.ts +1 -1
  23. package/config/version.js +1 -1
  24. package/i18n/pt.json +8 -5
  25. package/i18n/uk.json +3 -3
  26. package/package.json +6 -6
  27. package/pages/SelectWalletPage/SelectWalletPage.js +5 -5
  28. package/pages/SwapDetailsPage/SwapDetailsPage.js +6 -4
  29. package/pages/SwapPage/SwapPage.js +4 -1
  30. package/providers/WalletProvider/WalletProvider.js +73 -29
  31. package/providers/WalletProvider/index.d.ts +1 -1
  32. package/providers/WalletProvider/index.js +1 -1
  33. package/providers/WalletProvider/types.d.ts +1 -1
  34. package/tsconfig.cjs.tsbuildinfo +1 -1
@@ -5,7 +5,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const stores_1 = require("../../stores");
6
6
  const InsuranceCard_1 = require("./InsuranceCard");
7
7
  const InsuranceCollapsed_1 = require("./InsuranceCollapsed");
8
- const Insurance = ({ status, insurableRouteId, feeAmountUsd, onChange, ...props }) => {
9
- return status === stores_1.RouteExecutionStatus.Idle ? ((0, jsx_runtime_1.jsx)(InsuranceCollapsed_1.InsuranceCollapsed, { insurableRouteId: insurableRouteId, feeAmountUsd: feeAmountUsd, status: status, onChange: onChange, ...props })) : ((0, jsx_runtime_1.jsx)(InsuranceCard_1.InsuranceCard, { feeAmountUsd: feeAmountUsd, status: status, ...props }));
8
+ const Insurance = ({ status, insurableRouteId, feeAmountUsd, insuranceCoverageId, onChange, ...props }) => {
9
+ return status === stores_1.RouteExecutionStatus.Idle ? ((0, jsx_runtime_1.jsx)(InsuranceCollapsed_1.InsuranceCollapsed, { insurableRouteId: insurableRouteId, feeAmountUsd: feeAmountUsd, insuranceCoverageId: insuranceCoverageId, status: status, onChange: onChange, ...props })) : ((0, jsx_runtime_1.jsx)(InsuranceCard_1.InsuranceCard, { feeAmountUsd: feeAmountUsd, status: status, insuranceCoverageId: insuranceCoverageId, ...props }));
10
10
  };
11
11
  exports.Insurance = Insurance;
@@ -9,12 +9,18 @@ const icons_1 = require("../../icons");
9
9
  const stores_1 = require("../../stores");
10
10
  const Card_1 = require("../Card");
11
11
  const Switch_1 = require("../Switch");
12
- const InsuranceCard = ({ status, feeAmountUsd, onChange, ...props }) => {
12
+ const InsuranceCard = ({ status, feeAmountUsd, insuranceCoverageId, onChange, ...props }) => {
13
13
  const { t } = (0, react_i18next_1.useTranslation)();
14
14
  return ((0, jsx_runtime_1.jsxs)(Card_1.Card, { selectionColor: "secondary", indented: true, ...props, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 2, children: [(0, jsx_runtime_1.jsxs)(Card_1.CardLabel, { type: 'insurance', children: [(0, jsx_runtime_1.jsx)(VerifiedUser_1.default, { fontSize: "inherit" }), (0, jsx_runtime_1.jsx)(Card_1.CardLabelTypography, { type: "icon", children: status === stores_1.RouteExecutionStatus.Idle
15
15
  ? t(`swap.tags.insurance`)
16
16
  : t(`swap.tags.insured`) })] }), (0, jsx_runtime_1.jsx)(icons_1.InsuraceLogo, {})] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 2, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { fontSize: 24, fontWeight: 700, lineHeight: 1, children: t('format.currency', {
17
17
  value: feeAmountUsd,
18
- }) }), status === stores_1.RouteExecutionStatus.Idle ? ((0, jsx_runtime_1.jsx)(Switch_1.Switch, { onChange: onChange })) : null] }), (0, jsx_runtime_1.jsx)(material_1.Box, { display: "flex", alignItems: "center", justifyContent: "space-between", children: (0, jsx_runtime_1.jsx)(material_1.Typography, { fontSize: 12, children: "Get 100% coverage for lost tokens." }) })] }));
18
+ }) }), status === stores_1.RouteExecutionStatus.Idle ? ((0, jsx_runtime_1.jsx)(Switch_1.Switch, { onChange: onChange })) : null] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { display: "flex", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { fontSize: 12, children: status === stores_1.RouteExecutionStatus.Idle
19
+ ? 'Get 100% coverage for lost tokens.'
20
+ : '100% coverage for lost tokens.' }), (0, jsx_runtime_1.jsx)(material_1.Link, { href: status === stores_1.RouteExecutionStatus.Idle
21
+ ? 'https://docs.insurace.io/landing-page/documentation/cover-products/bridge-cover/li.fi'
22
+ : `https://app.insurace.io/bridge-cover?search=${insuranceCoverageId}`, target: "_blank", underline: "none", color: "text.primary", children: (0, jsx_runtime_1.jsx)(material_1.Typography, { px: 0.5, color: "primary", fontSize: 12, fontWeight: 600, children: status === stores_1.RouteExecutionStatus.Idle
23
+ ? 'Learn more'
24
+ : 'View coverage' }) })] })] }));
19
25
  };
20
26
  exports.InsuranceCard = InsuranceCard;
@@ -1,3 +1,3 @@
1
- import type { PropsWithChildren } from 'react';
1
+ /// <reference types="react" />
2
2
  import type { InsuranceProps } from './types';
3
- export declare const InsuranceCollapsed: React.FC<PropsWithChildren<InsuranceProps>>;
3
+ export declare const InsuranceCollapsed: React.FC<InsuranceProps>;
@@ -7,7 +7,7 @@ const react_1 = require("react");
7
7
  const hooks_1 = require("../../hooks");
8
8
  const stores_1 = require("../../stores");
9
9
  const InsuranceCard_1 = require("./InsuranceCard");
10
- const InsuranceCollapsed = ({ status, insurableRouteId, feeAmountUsd, onChange, children, ...props }) => {
10
+ const InsuranceCollapsed = ({ status, insurableRouteId, insuranceCoverageId, feeAmountUsd, onChange, ...props }) => {
11
11
  const [insuredRoute, setInsuredRoute] = (0, react_1.useState)();
12
12
  const setExecutableRoute = (0, stores_1.useSetExecutableRoute)();
13
13
  const routeExecution = (0, stores_1.useRouteExecutionStore)((state) => state.routes[insurableRouteId]);
@@ -27,6 +27,6 @@ const InsuranceCollapsed = ({ status, insurableRouteId, feeAmountUsd, onChange,
27
27
  onChange?.(checked ? insuredRoute.id : insurableRouteId);
28
28
  }
29
29
  };
30
- return ((0, jsx_runtime_1.jsx)(material_1.Collapse, { timeout: 225, in: insuredRoute?.insurance?.state === 'INSURED', unmountOnExit: true, mountOnEnter: true, appear: status === stores_1.RouteExecutionStatus.Idle, children: (0, jsx_runtime_1.jsx)(InsuranceCard_1.InsuranceCard, { feeAmountUsd: feeAmountUsd, status: status, onChange: toggleInsurance, ...props }) }));
30
+ return ((0, jsx_runtime_1.jsx)(material_1.Collapse, { timeout: 225, in: insuredRoute?.insurance?.state === 'INSURED', unmountOnExit: true, mountOnEnter: true, appear: status === stores_1.RouteExecutionStatus.Idle, children: (0, jsx_runtime_1.jsx)(InsuranceCard_1.InsuranceCard, { feeAmountUsd: feeAmountUsd, status: status, insuranceCoverageId: insuranceCoverageId, onChange: toggleInsurance, ...props }) }));
31
31
  };
32
32
  exports.InsuranceCollapsed = InsuranceCollapsed;
@@ -4,11 +4,13 @@ import type { RouteExecutionStatus } from '../../stores';
4
4
  export interface InsuranceProps extends Omit<BoxProps, 'onChange'> {
5
5
  insurableRouteId: string;
6
6
  feeAmountUsd?: string;
7
+ insuranceCoverageId?: string;
7
8
  status?: RouteExecutionStatus;
8
9
  onChange?: (routeId: string) => void;
9
10
  }
10
11
  export interface InsuranceCardProps {
11
12
  feeAmountUsd?: string;
12
13
  status?: RouteExecutionStatus;
14
+ insuranceCoverageId?: string;
13
15
  onChange?: (_: React.ChangeEvent<HTMLInputElement>, checked: boolean) => void;
14
16
  }
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/widget";
2
- export declare const version = "2.0.0-alpha.4";
2
+ export declare const version = "2.0.0-beta.1";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = exports.name = void 0;
4
4
  exports.name = '@lifi/widget';
5
- exports.version = '2.0.0-alpha.4';
5
+ exports.version = '2.0.0-beta.1';
package/cjs/i18n/pt.json CHANGED
@@ -184,11 +184,13 @@
184
184
  "swapStepDetails": "Converter na {{chain}} via {{tool}}",
185
185
  "swapping": "Convertendo",
186
186
  "tags": {
187
- "ALTERNATIVE": "ALTERNATIVA",
188
- "CHEAPEST": "MAIS BARATO",
189
- "FASTEST": "MAIS RÁPIDO",
190
- "RECOMMENDED": "RECOMENDADO",
191
- "SAFEST": "MAIS SEGURO"
187
+ "cheapest": "Barato",
188
+ "fastest": "Rápido",
189
+ "insurable": "Assegurável",
190
+ "insurance": "Seguro",
191
+ "insured": "Segurado",
192
+ "recommended": "Recomendado",
193
+ "safest": "Seguro"
192
194
  },
193
195
  "to": "Para",
194
196
  "tokenOnChain": "{{tokenSymbol}} na {{chainName}}",
@@ -218,6 +220,7 @@
218
220
  }
219
221
  },
220
222
  "tooltip": {
223
+ "additionalProviderFee": "Pontes adicionais, DEXes e taxas de serviço.",
221
224
  "estimatedNetworkFee": "Taxa de rede estimada.",
222
225
  "estimatedTime": "Tempo de execução da conversão estimado em minutos.",
223
226
  "notFound": {
package/cjs/i18n/uk.json CHANGED
@@ -41,7 +41,7 @@
41
41
  "from": "Своп з",
42
42
  "gas": "Газ",
43
43
  "gasSwap": "Своп газу",
44
- "routes": "Ви отримуєте",
44
+ "routes": "Ви отримаєте",
45
45
  "selectChain": "Оберіть чейн",
46
46
  "selectWallet": "Виберіть свій гаманець",
47
47
  "settings": "Налаштування",
@@ -157,7 +157,7 @@
157
157
  "rateChange": "Зміна курсу",
158
158
  "receiving": "Отримання",
159
159
  "refuelStepDetails": "Отримати газ через {{tool}}",
160
- "routes": "Ви отримуєте",
160
+ "routes": "Ви отримаєте",
161
161
  "selectChain": "Чейн",
162
162
  "selectChainAndToken": "Виберіть чейн і токен",
163
163
  "selectToken": "Токен",
@@ -186,7 +186,7 @@
186
186
  "tags": {
187
187
  "cheapest": "Дешевий",
188
188
  "fastest": "Швидкий",
189
- "insurable": "Страхування",
189
+ "insurable": "Страховка",
190
190
  "insurance": "Страхування",
191
191
  "insured": "Застрахований",
192
192
  "recommended": "Рекомендований",
@@ -16,6 +16,9 @@ const SelectWalletPage = () => {
16
16
  const { navigateBack } = (0, hooks_1.useNavigateBack)();
17
17
  const { connect } = (0, providers_1.useWallet)();
18
18
  const [walletIdentity, setWalletIdentity] = (0, react_1.useState)({ show: false });
19
+ // separate into installed and not installed wallets
20
+ const installedWallets = wallet_management_1.supportedWallets.filter((wallet) => wallet.installed());
21
+ const notInstalledWallets = wallet_management_1.supportedWallets.filter((wallet) => !wallet.installed() && wallet.name !== 'Default Wallet');
19
22
  const closeDialog = () => {
20
23
  setWalletIdentity((state) => ({
21
24
  ...state,
@@ -23,10 +26,7 @@ const SelectWalletPage = () => {
23
26
  }));
24
27
  };
25
28
  const handleConnect = (0, react_1.useCallback)(async (wallet) => {
26
- const { ethereum } = window;
27
- const identityCheckPassed = wallet.checkProviderIdentity({
28
- provider: ethereum,
29
- });
29
+ const identityCheckPassed = wallet.installed();
30
30
  if (!identityCheckPassed) {
31
31
  setWalletIdentity({
32
32
  show: true,
@@ -40,7 +40,7 @@ const SelectWalletPage = () => {
40
40
  return ((0, jsx_runtime_1.jsxs)(material_1.Container, { disableGutters: true, children: [(0, jsx_runtime_1.jsx)(material_1.List, { sx: {
41
41
  paddingLeft: 1.5,
42
42
  paddingRight: 1.5,
43
- }, children: wallet_management_1.supportedWallets.map((wallet) => ((0, jsx_runtime_1.jsxs)(ListItemButton_1.ListItemButton, { onClick: () => handleConnect(wallet), children: [(0, jsx_runtime_1.jsx)(material_1.ListItemAvatar, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, { src: wallet.icon.src || wallet.icon, alt: wallet.name, children: wallet.name[0] }) }), (0, jsx_runtime_1.jsx)(ListItemText_1.ListItemText, { primary: wallet.name })] }, wallet.name))) }), (0, jsx_runtime_1.jsxs)(Dialog_1.Dialog, { open: walletIdentity.show, onClose: closeDialog, children: [(0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsx)(material_1.DialogContentText, { children: t('wallet.extensionNotFound', {
43
+ }, children: [...installedWallets, ...notInstalledWallets].map((wallet) => ((0, jsx_runtime_1.jsxs)(ListItemButton_1.ListItemButton, { onClick: () => handleConnect(wallet), children: [(0, jsx_runtime_1.jsx)(material_1.ListItemAvatar, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, { src: wallet.icon.src || wallet.icon, alt: wallet.name, children: wallet.name[0] }) }), (0, jsx_runtime_1.jsx)(ListItemText_1.ListItemText, { primary: wallet.name })] }, wallet.name))) }), (0, jsx_runtime_1.jsxs)(Dialog_1.Dialog, { open: walletIdentity.show, onClose: closeDialog, children: [(0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsx)(material_1.DialogContentText, { children: t('wallet.extensionNotFound', {
44
44
  name: walletIdentity.wallet?.name,
45
45
  }) }) }), (0, jsx_runtime_1.jsx)(material_1.DialogActions, { children: (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", onClick: closeDialog, autoFocus: true, children: t('button.ok') }) })] })] }));
46
46
  };
@@ -32,9 +32,11 @@ const SwapDetailsPage = () => {
32
32
  deleteRoute(routeExecution.route.id);
33
33
  }
34
34
  };
35
- let supportId = routeExecution?.route.steps[0].execution?.process.find((process) => process.txHash)?.txHash ??
36
- routeExecution?.route.id ??
37
- '';
35
+ const sourceTxHash = routeExecution?.route.steps[0].execution?.process
36
+ .filter((process) => process.type !== 'TOKEN_ALLOWANCE')
37
+ .find((process) => process.txHash)?.txHash;
38
+ const insuranceCoverageId = sourceTxHash ?? routeExecution?.route.fromAddress;
39
+ let supportId = sourceTxHash ?? routeExecution?.route.id ?? '';
38
40
  if (process.env.NODE_ENV === 'development') {
39
41
  supportId += `_${routeExecution?.route.id}`;
40
42
  }
@@ -51,7 +53,7 @@ const SwapDetailsPage = () => {
51
53
  justifyContent: 'space-between',
52
54
  }, pb: 1, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { fontSize: 12, children: new Intl.DateTimeFormat(i18n.language, { dateStyle: 'long' }).format(startedAt) }), (0, jsx_runtime_1.jsx)(material_1.Typography, { fontSize: 12, children: new Intl.DateTimeFormat(i18n.language, {
53
55
  timeStyle: 'short',
54
- }).format(startedAt) })] }), (0, Step_1.getStepList)(routeExecution?.route), routeExecution?.route?.insurance?.state === 'INSURED' ? ((0, jsx_runtime_1.jsx)(Insurance_1.Insurance, { mt: 2, status: routeExecution.status, feeAmountUsd: routeExecution.route.insurance.feeAmountUsd, insurableRouteId: routeExecution.route.id })) : null, (0, jsx_runtime_1.jsxs)(Card_1.Card, { mt: 2, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
56
+ }).format(startedAt) })] }), (0, Step_1.getStepList)(routeExecution?.route), routeExecution?.route?.insurance?.state === 'INSURED' ? ((0, jsx_runtime_1.jsx)(Insurance_1.Insurance, { mt: 2, status: routeExecution.status, feeAmountUsd: routeExecution.route.insurance.feeAmountUsd, insurableRouteId: routeExecution.route.id, insuranceCoverageId: insuranceCoverageId })) : null, (0, jsx_runtime_1.jsxs)(Card_1.Card, { mt: 2, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
55
57
  display: 'flex',
56
58
  flex: 1,
57
59
  }, children: [(0, jsx_runtime_1.jsx)(Card_1.CardTitle, { flex: 1, children: t('swap.supportId') }), (0, jsx_runtime_1.jsx)(material_1.Box, { mr: 1, mt: 1, children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "medium", onClick: copySupportId, children: (0, jsx_runtime_1.jsx)(ContentCopyRounded_1.default, { fontSize: "small" }) }) })] }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", pt: 1, pb: 2, px: 2, sx: { wordBreak: 'break-all' }, children: supportId })] }), (0, jsx_runtime_1.jsx)(material_1.Box, { mt: 2, children: (0, jsx_runtime_1.jsx)(material_1.Button, { href: "https://discord.com/channels/849912621360218112/863689862514343946", target: "_blank", rel: "nofollow noreferrer", fullWidth: true, children: t('button.contactSupport') }) }), (0, jsx_runtime_1.jsxs)(Dialog_1.Dialog, { open: open, onClose: toggleDialog, children: [(0, jsx_runtime_1.jsx)(material_1.DialogTitle, { children: t('swap.warning.title.deleteSwap') }), (0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsx)(material_1.DialogContentText, { children: t('swap.warning.message.deleteSwapHistory') }) }), (0, jsx_runtime_1.jsxs)(material_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, { onClick: toggleDialog, children: t('button.cancel') }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", onClick: handleDeleteRoute, autoFocus: true, children: t('button.delete') })] })] })] }));
@@ -78,7 +78,10 @@ const SwapPage = () => {
78
78
  (route?.insurance?.state === 'INSURED' ||
79
79
  (status === stores_1.RouteExecutionStatus.Idle &&
80
80
  route?.insurance?.state === 'INSURABLE'));
81
- return ((0, jsx_runtime_1.jsxs)(SwapPage_style_1.Container, { children: [(0, Step_1.getStepList)(route), insuranceAvailable ? ((0, jsx_runtime_1.jsx)(Insurance_1.Insurance, { mt: 2, status: status, insurableRouteId: stateRouteId, feeAmountUsd: route?.insurance.feeAmountUsd, onChange: setRouteId })) : null, status === stores_1.RouteExecutionStatus.Idle ||
81
+ const insuranceCoverageId = route?.steps[0].execution?.process
82
+ .filter((process) => process.type !== 'TOKEN_ALLOWANCE')
83
+ .find((process) => process.txHash)?.txHash ?? route?.fromAddress;
84
+ return ((0, jsx_runtime_1.jsxs)(SwapPage_style_1.Container, { children: [(0, Step_1.getStepList)(route), insuranceAvailable ? ((0, jsx_runtime_1.jsx)(Insurance_1.Insurance, { mt: 2, status: status, insurableRouteId: stateRouteId, feeAmountUsd: route?.insurance.feeAmountUsd, insuranceCoverageId: insuranceCoverageId, onChange: setRouteId })) : null, status === stores_1.RouteExecutionStatus.Idle ||
82
85
  status === stores_1.RouteExecutionStatus.Failed ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(GasMessage_1.GasMessage, { mt: 2, route: route }), (0, jsx_runtime_1.jsxs)(material_1.Box, { mt: 2, display: "flex", children: [(0, jsx_runtime_1.jsx)(SwapButton, { text: getSwapButtonText(), onClick: handleSwapClick, route: route, insurableRouteId: stateRouteId }), status === stores_1.RouteExecutionStatus.Failed ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: t('button.removeSwap'), placement: "bottom-end", enterDelay: 400, arrow: true, children: (0, jsx_runtime_1.jsx)(material_1.Button, { onClick: handleRemoveRoute, sx: {
83
86
  minWidth: 48,
84
87
  marginLeft: 1,
@@ -5,6 +5,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const wallet_management_1 = require("@lifi/wallet-management");
6
6
  const react_1 = require("react");
7
7
  const WidgetProvider_1 = require("../WidgetProvider");
8
+ const liFiWalletManagement = new wallet_management_1.LiFiWalletManagement();
8
9
  const stub = () => {
9
10
  throw new Error(`You forgot to wrap your component in <${exports.WalletProvider.name}>.`);
10
11
  };
@@ -21,8 +22,26 @@ const useWallet = () => (0, react_1.useContext)(WalletContext);
21
22
  exports.useWallet = useWallet;
22
23
  const WalletProvider = ({ children }) => {
23
24
  const { walletManagement } = (0, WidgetProvider_1.useWidgetConfig)();
24
- const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, provider, } = (0, wallet_management_1.useLiFiWalletManagement)();
25
25
  const [account, setAccount] = (0, react_1.useState)({});
26
+ const [currentWallet, setCurrentWallet] = (0, react_1.useState)();
27
+ (0, react_1.useEffect)(() => {
28
+ const autoConnect = async () => {
29
+ const persistedActiveWallets = (0, wallet_management_1.readActiveWallets)();
30
+ const activeWallets = wallet_management_1.supportedWallets.filter((wallet) => persistedActiveWallets.some((perstistedWallet) => perstistedWallet.name === wallet.name));
31
+ if (!activeWallets.length) {
32
+ return;
33
+ }
34
+ await liFiWalletManagement.autoConnect(activeWallets);
35
+ activeWallets[0].on('walletAccountChanged', handleWalletUpdate);
36
+ handleWalletUpdate(activeWallets[0]);
37
+ };
38
+ autoConnect();
39
+ }, []);
40
+ const handleWalletUpdate = async (wallet) => {
41
+ setCurrentWallet(wallet);
42
+ const account = await (0, exports.extractAccountFromSigner)(wallet?.account?.signer);
43
+ setAccount(account);
44
+ };
26
45
  const connect = (0, react_1.useCallback)(async (wallet) => {
27
46
  if (walletManagement) {
28
47
  const signer = await walletManagement.connect();
@@ -30,17 +49,22 @@ const WalletProvider = ({ children }) => {
30
49
  setAccount(account);
31
50
  return;
32
51
  }
33
- await walletManagementConnect(wallet);
34
- }, [walletManagement, walletManagementConnect]);
52
+ await liFiWalletManagement.connect(wallet);
53
+ wallet.on('walletAccountChanged', handleWalletUpdate);
54
+ handleWalletUpdate(wallet);
55
+ }, [walletManagement]);
35
56
  const disconnect = (0, react_1.useCallback)(async () => {
36
57
  if (walletManagement) {
37
58
  await walletManagement.disconnect();
38
59
  setAccount({});
39
60
  return;
40
61
  }
41
- await walletManagementDisconnect();
42
- }, [walletManagement, walletManagementDisconnect]);
43
- // only for injected wallets
62
+ if (currentWallet) {
63
+ await liFiWalletManagement.disconnect(currentWallet);
64
+ currentWallet.removeAllListeners();
65
+ handleWalletUpdate(undefined);
66
+ }
67
+ }, [walletManagement, currentWallet]);
44
68
  const switchChain = (0, react_1.useCallback)(async (chainId) => {
45
69
  if (walletManagement?.switchChain) {
46
70
  const signer = await walletManagement.switchChain(chainId);
@@ -48,34 +72,46 @@ const WalletProvider = ({ children }) => {
48
72
  setAccount(account);
49
73
  return true;
50
74
  }
51
- return (0, wallet_management_1.switchChain)(chainId);
52
- }, [walletManagement]);
75
+ try {
76
+ await currentWallet?.switchChain(chainId);
77
+ handleWalletUpdate(currentWallet);
78
+ return true;
79
+ }
80
+ catch {
81
+ return false;
82
+ }
83
+ }, [walletManagement, currentWallet]);
53
84
  const addChain = (0, react_1.useCallback)(async (chainId) => {
54
85
  if (walletManagement?.addChain) {
55
86
  return walletManagement.addChain(chainId);
56
87
  }
57
- return (0, wallet_management_1.addChain)(chainId);
58
- }, [walletManagement]);
88
+ try {
89
+ await currentWallet?.addChain(chainId);
90
+ handleWalletUpdate(currentWallet);
91
+ return true;
92
+ }
93
+ catch {
94
+ return false;
95
+ }
96
+ }, [walletManagement, currentWallet]);
59
97
  const addToken = (0, react_1.useCallback)(async (chainId, token) => {
60
98
  if (walletManagement?.addToken) {
61
99
  return walletManagement.addToken(token, chainId);
62
100
  }
63
- return (0, wallet_management_1.switchChainAndAddToken)(chainId, token);
64
- }, [walletManagement]);
65
- // keep account information up to date
101
+ await currentWallet?.addToken(chainId, token);
102
+ handleWalletUpdate(currentWallet);
103
+ return;
104
+ }, [walletManagement, currentWallet]);
105
+ // keep widget in sync with changing external signer object
66
106
  (0, react_1.useEffect)(() => {
67
- const updateAccount = async () => {
68
- let account;
69
- if (walletManagement) {
70
- account = await (0, exports.extractAccountFromSigner)(walletManagement?.signer);
71
- }
72
- else {
73
- account = await (0, exports.extractAccountFromSigner)(signer);
74
- }
75
- setAccount(account);
76
- };
77
- updateAccount();
78
- }, [signer, walletManagement]);
107
+ if (walletManagement) {
108
+ const updateAccount = async () => {
109
+ const account = await (0, exports.extractAccountFromSigner)(walletManagement?.signer);
110
+ setAccount(account);
111
+ };
112
+ updateAccount();
113
+ }
114
+ }, [walletManagement, walletManagement?.signer]);
79
115
  const value = (0, react_1.useMemo)(() => ({
80
116
  connect,
81
117
  disconnect,
@@ -83,8 +119,16 @@ const WalletProvider = ({ children }) => {
83
119
  addChain,
84
120
  addToken,
85
121
  account,
86
- provider,
87
- }), [account, addChain, addToken, connect, disconnect, provider, switchChain]);
122
+ provider: currentWallet?.account?.provider,
123
+ }), [
124
+ account,
125
+ addChain,
126
+ addToken,
127
+ connect,
128
+ disconnect,
129
+ currentWallet,
130
+ switchChain,
131
+ ]);
88
132
  return ((0, jsx_runtime_1.jsx)(WalletContext.Provider, { value: value, children: children }));
89
133
  };
90
134
  exports.WalletProvider = WalletProvider;
@@ -98,7 +142,7 @@ const extractAccountFromSigner = async (signer) => {
98
142
  };
99
143
  }
100
144
  catch (error) {
101
- console.log(error);
145
+ console.error(error);
102
146
  return {};
103
147
  }
104
148
  };
@@ -1,2 +1,2 @@
1
- export * from './types';
2
1
  export * from './WalletProvider';
2
+ export * from './types';
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
17
  __exportStar(require("./WalletProvider"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -7,7 +7,7 @@ export interface WalletContextProps {
7
7
  provider?: Provider;
8
8
  addChain(chainId: number): Promise<boolean>;
9
9
  addToken(chainId: number, token: Token): Promise<void>;
10
- disconnect(): void;
10
+ disconnect(wallet?: Wallet): void;
11
11
  switchChain(chainId: number): Promise<boolean>;
12
12
  connect(wallet?: Wallet | undefined): Promise<void>;
13
13
  }
@@ -2,6 +2,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { RouteExecutionStatus } from '../../stores';
3
3
  import { InsuranceCard } from './InsuranceCard';
4
4
  import { InsuranceCollapsed } from './InsuranceCollapsed';
5
- export const Insurance = ({ status, insurableRouteId, feeAmountUsd, onChange, ...props }) => {
6
- return status === RouteExecutionStatus.Idle ? (_jsx(InsuranceCollapsed, { insurableRouteId: insurableRouteId, feeAmountUsd: feeAmountUsd, status: status, onChange: onChange, ...props })) : (_jsx(InsuranceCard, { feeAmountUsd: feeAmountUsd, status: status, ...props }));
5
+ export const Insurance = ({ status, insurableRouteId, feeAmountUsd, insuranceCoverageId, onChange, ...props }) => {
6
+ return status === RouteExecutionStatus.Idle ? (_jsx(InsuranceCollapsed, { insurableRouteId: insurableRouteId, feeAmountUsd: feeAmountUsd, insuranceCoverageId: insuranceCoverageId, status: status, onChange: onChange, ...props })) : (_jsx(InsuranceCard, { feeAmountUsd: feeAmountUsd, status: status, insuranceCoverageId: insuranceCoverageId, ...props }));
7
7
  };
@@ -1,16 +1,22 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import VerifiedUserIcon from '@mui/icons-material/VerifiedUser';
3
- import { Box, Typography } from '@mui/material';
3
+ import { Box, Link, Typography } from '@mui/material';
4
4
  import { useTranslation } from 'react-i18next';
5
5
  import { InsuraceLogo } from '../../icons';
6
6
  import { RouteExecutionStatus } from '../../stores';
7
7
  import { Card, CardLabel, CardLabelTypography } from '../Card';
8
8
  import { Switch } from '../Switch';
9
- export const InsuranceCard = ({ status, feeAmountUsd, onChange, ...props }) => {
9
+ export const InsuranceCard = ({ status, feeAmountUsd, insuranceCoverageId, onChange, ...props }) => {
10
10
  const { t } = useTranslation();
11
11
  return (_jsxs(Card, { selectionColor: "secondary", indented: true, ...props, children: [_jsxs(Box, { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 2, children: [_jsxs(CardLabel, { type: 'insurance', children: [_jsx(VerifiedUserIcon, { fontSize: "inherit" }), _jsx(CardLabelTypography, { type: "icon", children: status === RouteExecutionStatus.Idle
12
12
  ? t(`swap.tags.insurance`)
13
13
  : t(`swap.tags.insured`) })] }), _jsx(InsuraceLogo, {})] }), _jsxs(Box, { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 2, children: [_jsx(Typography, { fontSize: 24, fontWeight: 700, lineHeight: 1, children: t('format.currency', {
14
14
  value: feeAmountUsd,
15
- }) }), status === RouteExecutionStatus.Idle ? (_jsx(Switch, { onChange: onChange })) : null] }), _jsx(Box, { display: "flex", alignItems: "center", justifyContent: "space-between", children: _jsx(Typography, { fontSize: 12, children: "Get 100% coverage for lost tokens." }) })] }));
15
+ }) }), status === RouteExecutionStatus.Idle ? (_jsx(Switch, { onChange: onChange })) : null] }), _jsxs(Box, { display: "flex", alignItems: "center", children: [_jsx(Typography, { fontSize: 12, children: status === RouteExecutionStatus.Idle
16
+ ? 'Get 100% coverage for lost tokens.'
17
+ : '100% coverage for lost tokens.' }), _jsx(Link, { href: status === RouteExecutionStatus.Idle
18
+ ? 'https://docs.insurace.io/landing-page/documentation/cover-products/bridge-cover/li.fi'
19
+ : `https://app.insurace.io/bridge-cover?search=${insuranceCoverageId}`, target: "_blank", underline: "none", color: "text.primary", children: _jsx(Typography, { px: 0.5, color: "primary", fontSize: 12, fontWeight: 600, children: status === RouteExecutionStatus.Idle
20
+ ? 'Learn more'
21
+ : 'View coverage' }) })] })] }));
16
22
  };
@@ -1,3 +1,3 @@
1
- import type { PropsWithChildren } from 'react';
1
+ /// <reference types="react" />
2
2
  import type { InsuranceProps } from './types';
3
- export declare const InsuranceCollapsed: React.FC<PropsWithChildren<InsuranceProps>>;
3
+ export declare const InsuranceCollapsed: React.FC<InsuranceProps>;
@@ -4,7 +4,7 @@ import { useState } from 'react';
4
4
  import { useSwapRoutes } from '../../hooks';
5
5
  import { RouteExecutionStatus, useRouteExecutionStore, useSetExecutableRoute, } from '../../stores';
6
6
  import { InsuranceCard } from './InsuranceCard';
7
- export const InsuranceCollapsed = ({ status, insurableRouteId, feeAmountUsd, onChange, children, ...props }) => {
7
+ export const InsuranceCollapsed = ({ status, insurableRouteId, insuranceCoverageId, feeAmountUsd, onChange, ...props }) => {
8
8
  const [insuredRoute, setInsuredRoute] = useState();
9
9
  const setExecutableRoute = useSetExecutableRoute();
10
10
  const routeExecution = useRouteExecutionStore((state) => state.routes[insurableRouteId]);
@@ -24,5 +24,5 @@ export const InsuranceCollapsed = ({ status, insurableRouteId, feeAmountUsd, onC
24
24
  onChange?.(checked ? insuredRoute.id : insurableRouteId);
25
25
  }
26
26
  };
27
- return (_jsx(Collapse, { timeout: 225, in: insuredRoute?.insurance?.state === 'INSURED', unmountOnExit: true, mountOnEnter: true, appear: status === RouteExecutionStatus.Idle, children: _jsx(InsuranceCard, { feeAmountUsd: feeAmountUsd, status: status, onChange: toggleInsurance, ...props }) }));
27
+ return (_jsx(Collapse, { timeout: 225, in: insuredRoute?.insurance?.state === 'INSURED', unmountOnExit: true, mountOnEnter: true, appear: status === RouteExecutionStatus.Idle, children: _jsx(InsuranceCard, { feeAmountUsd: feeAmountUsd, status: status, insuranceCoverageId: insuranceCoverageId, onChange: toggleInsurance, ...props }) }));
28
28
  };
@@ -4,11 +4,13 @@ import type { RouteExecutionStatus } from '../../stores';
4
4
  export interface InsuranceProps extends Omit<BoxProps, 'onChange'> {
5
5
  insurableRouteId: string;
6
6
  feeAmountUsd?: string;
7
+ insuranceCoverageId?: string;
7
8
  status?: RouteExecutionStatus;
8
9
  onChange?: (routeId: string) => void;
9
10
  }
10
11
  export interface InsuranceCardProps {
11
12
  feeAmountUsd?: string;
12
13
  status?: RouteExecutionStatus;
14
+ insuranceCoverageId?: string;
13
15
  onChange?: (_: React.ChangeEvent<HTMLInputElement>, checked: boolean) => void;
14
16
  }
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/widget";
2
- export declare const version = "2.0.0-alpha.4";
2
+ export declare const version = "2.0.0-beta.1";
package/config/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/widget';
2
- export const version = '2.0.0-alpha.4';
2
+ export const version = '2.0.0-beta.1';
package/i18n/pt.json CHANGED
@@ -184,11 +184,13 @@
184
184
  "swapStepDetails": "Converter na {{chain}} via {{tool}}",
185
185
  "swapping": "Convertendo",
186
186
  "tags": {
187
- "ALTERNATIVE": "ALTERNATIVA",
188
- "CHEAPEST": "MAIS BARATO",
189
- "FASTEST": "MAIS RÁPIDO",
190
- "RECOMMENDED": "RECOMENDADO",
191
- "SAFEST": "MAIS SEGURO"
187
+ "cheapest": "Barato",
188
+ "fastest": "Rápido",
189
+ "insurable": "Assegurável",
190
+ "insurance": "Seguro",
191
+ "insured": "Segurado",
192
+ "recommended": "Recomendado",
193
+ "safest": "Seguro"
192
194
  },
193
195
  "to": "Para",
194
196
  "tokenOnChain": "{{tokenSymbol}} na {{chainName}}",
@@ -218,6 +220,7 @@
218
220
  }
219
221
  },
220
222
  "tooltip": {
223
+ "additionalProviderFee": "Pontes adicionais, DEXes e taxas de serviço.",
221
224
  "estimatedNetworkFee": "Taxa de rede estimada.",
222
225
  "estimatedTime": "Tempo de execução da conversão estimado em minutos.",
223
226
  "notFound": {
package/i18n/uk.json CHANGED
@@ -41,7 +41,7 @@
41
41
  "from": "Своп з",
42
42
  "gas": "Газ",
43
43
  "gasSwap": "Своп газу",
44
- "routes": "Ви отримуєте",
44
+ "routes": "Ви отримаєте",
45
45
  "selectChain": "Оберіть чейн",
46
46
  "selectWallet": "Виберіть свій гаманець",
47
47
  "settings": "Налаштування",
@@ -157,7 +157,7 @@
157
157
  "rateChange": "Зміна курсу",
158
158
  "receiving": "Отримання",
159
159
  "refuelStepDetails": "Отримати газ через {{tool}}",
160
- "routes": "Ви отримуєте",
160
+ "routes": "Ви отримаєте",
161
161
  "selectChain": "Чейн",
162
162
  "selectChainAndToken": "Виберіть чейн і токен",
163
163
  "selectToken": "Токен",
@@ -186,7 +186,7 @@
186
186
  "tags": {
187
187
  "cheapest": "Дешевий",
188
188
  "fastest": "Швидкий",
189
- "insurable": "Страхування",
189
+ "insurable": "Страховка",
190
190
  "insurance": "Страхування",
191
191
  "insured": "Застрахований",
192
192
  "recommended": "Рекомендований",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/widget",
3
- "version": "2.0.0-alpha.4",
3
+ "version": "2.0.0-beta.1",
4
4
  "description": "LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./index.js",
@@ -44,16 +44,16 @@
44
44
  "@ethersproject/experimental": "^5.7.0",
45
45
  "@ethersproject/providers": "^5.7.2",
46
46
  "@lifi/sdk": "^2.0.0-beta.8",
47
- "@lifi/wallet-management": "^1.2.11",
47
+ "@lifi/wallet-management": "^2.0.0-beta.0",
48
48
  "@mui/icons-material": "^5.11.16",
49
- "@mui/lab": "^5.0.0-alpha.126",
50
- "@mui/material": "^5.12.0",
51
- "@tanstack/react-query": "^4.29.1",
49
+ "@mui/lab": "^5.0.0-alpha.127",
50
+ "@mui/material": "^5.12.1",
51
+ "@tanstack/react-query": "^4.29.3",
52
52
  "@tanstack/react-virtual": "^3.0.0-beta.54",
53
53
  "big.js": "^6.2.1",
54
54
  "i18next": "^22.4.14",
55
55
  "i18next-browser-languagedetector": "^7.0.1",
56
- "microdiff": "^1.3.1",
56
+ "microdiff": "^1.3.2",
57
57
  "mitt": "^3.0.0",
58
58
  "react": "^18.2.0",
59
59
  "react-dom": "^18.2.0",
@@ -13,6 +13,9 @@ export const SelectWalletPage = () => {
13
13
  const { navigateBack } = useNavigateBack();
14
14
  const { connect } = useWallet();
15
15
  const [walletIdentity, setWalletIdentity] = useState({ show: false });
16
+ // separate into installed and not installed wallets
17
+ const installedWallets = supportedWallets.filter((wallet) => wallet.installed());
18
+ const notInstalledWallets = supportedWallets.filter((wallet) => !wallet.installed() && wallet.name !== 'Default Wallet');
16
19
  const closeDialog = () => {
17
20
  setWalletIdentity((state) => ({
18
21
  ...state,
@@ -20,10 +23,7 @@ export const SelectWalletPage = () => {
20
23
  }));
21
24
  };
22
25
  const handleConnect = useCallback(async (wallet) => {
23
- const { ethereum } = window;
24
- const identityCheckPassed = wallet.checkProviderIdentity({
25
- provider: ethereum,
26
- });
26
+ const identityCheckPassed = wallet.installed();
27
27
  if (!identityCheckPassed) {
28
28
  setWalletIdentity({
29
29
  show: true,
@@ -37,7 +37,7 @@ export const SelectWalletPage = () => {
37
37
  return (_jsxs(Container, { disableGutters: true, children: [_jsx(List, { sx: {
38
38
  paddingLeft: 1.5,
39
39
  paddingRight: 1.5,
40
- }, children: supportedWallets.map((wallet) => (_jsxs(ListItemButton, { onClick: () => handleConnect(wallet), children: [_jsx(ListItemAvatar, { children: _jsx(Avatar, { src: wallet.icon.src || wallet.icon, alt: wallet.name, children: wallet.name[0] }) }), _jsx(ListItemText, { primary: wallet.name })] }, wallet.name))) }), _jsxs(Dialog, { open: walletIdentity.show, onClose: closeDialog, children: [_jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('wallet.extensionNotFound', {
40
+ }, children: [...installedWallets, ...notInstalledWallets].map((wallet) => (_jsxs(ListItemButton, { onClick: () => handleConnect(wallet), children: [_jsx(ListItemAvatar, { children: _jsx(Avatar, { src: wallet.icon.src || wallet.icon, alt: wallet.name, children: wallet.name[0] }) }), _jsx(ListItemText, { primary: wallet.name })] }, wallet.name))) }), _jsxs(Dialog, { open: walletIdentity.show, onClose: closeDialog, children: [_jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('wallet.extensionNotFound', {
41
41
  name: walletIdentity.wallet?.name,
42
42
  }) }) }), _jsx(DialogActions, { children: _jsx(Button, { variant: "contained", onClick: closeDialog, autoFocus: true, children: t('button.ok') }) })] })] }));
43
43
  };