@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.
- package/cjs/components/Insurance/Insurance.js +2 -2
- package/cjs/components/Insurance/InsuranceCard.js +8 -2
- package/cjs/components/Insurance/InsuranceCollapsed.d.ts +2 -2
- package/cjs/components/Insurance/InsuranceCollapsed.js +2 -2
- package/cjs/components/Insurance/types.d.ts +2 -0
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/i18n/pt.json +8 -5
- package/cjs/i18n/uk.json +3 -3
- package/cjs/pages/SelectWalletPage/SelectWalletPage.js +5 -5
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +6 -4
- package/cjs/pages/SwapPage/SwapPage.js +4 -1
- package/cjs/providers/WalletProvider/WalletProvider.js +72 -28
- package/cjs/providers/WalletProvider/index.d.ts +1 -1
- package/cjs/providers/WalletProvider/index.js +1 -1
- package/cjs/providers/WalletProvider/types.d.ts +1 -1
- package/components/Insurance/Insurance.js +2 -2
- package/components/Insurance/InsuranceCard.js +9 -3
- package/components/Insurance/InsuranceCollapsed.d.ts +2 -2
- package/components/Insurance/InsuranceCollapsed.js +2 -2
- package/components/Insurance/types.d.ts +2 -0
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/i18n/pt.json +8 -5
- package/i18n/uk.json +3 -3
- package/package.json +6 -6
- package/pages/SelectWalletPage/SelectWalletPage.js +5 -5
- package/pages/SwapDetailsPage/SwapDetailsPage.js +6 -4
- package/pages/SwapPage/SwapPage.js +4 -1
- package/providers/WalletProvider/WalletProvider.js +73 -29
- package/providers/WalletProvider/index.d.ts +1 -1
- package/providers/WalletProvider/index.js +1 -1
- package/providers/WalletProvider/types.d.ts +1 -1
- package/tsconfig.cjs.tsbuildinfo +1 -1
|
@@ -29,9 +29,11 @@ export const SwapDetailsPage = () => {
|
|
|
29
29
|
deleteRoute(routeExecution.route.id);
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const sourceTxHash = routeExecution?.route.steps[0].execution?.process
|
|
33
|
+
.filter((process) => process.type !== 'TOKEN_ALLOWANCE')
|
|
34
|
+
.find((process) => process.txHash)?.txHash;
|
|
35
|
+
const insuranceCoverageId = sourceTxHash ?? routeExecution?.route.fromAddress;
|
|
36
|
+
let supportId = sourceTxHash ?? routeExecution?.route.id ?? '';
|
|
35
37
|
if (process.env.NODE_ENV === 'development') {
|
|
36
38
|
supportId += `_${routeExecution?.route.id}`;
|
|
37
39
|
}
|
|
@@ -48,7 +50,7 @@ export const SwapDetailsPage = () => {
|
|
|
48
50
|
justifyContent: 'space-between',
|
|
49
51
|
}, pb: 1, children: [_jsx(Typography, { fontSize: 12, children: new Intl.DateTimeFormat(i18n.language, { dateStyle: 'long' }).format(startedAt) }), _jsx(Typography, { fontSize: 12, children: new Intl.DateTimeFormat(i18n.language, {
|
|
50
52
|
timeStyle: 'short',
|
|
51
|
-
}).format(startedAt) })] }), getStepList(routeExecution?.route), routeExecution?.route?.insurance?.state === 'INSURED' ? (_jsx(Insurance, { mt: 2, status: routeExecution.status, feeAmountUsd: routeExecution.route.insurance.feeAmountUsd, insurableRouteId: routeExecution.route.id })) : null, _jsxs(Card, { mt: 2, children: [_jsxs(Box, { sx: {
|
|
53
|
+
}).format(startedAt) })] }), getStepList(routeExecution?.route), routeExecution?.route?.insurance?.state === 'INSURED' ? (_jsx(Insurance, { mt: 2, status: routeExecution.status, feeAmountUsd: routeExecution.route.insurance.feeAmountUsd, insurableRouteId: routeExecution.route.id, insuranceCoverageId: insuranceCoverageId })) : null, _jsxs(Card, { mt: 2, children: [_jsxs(Box, { sx: {
|
|
52
54
|
display: 'flex',
|
|
53
55
|
flex: 1,
|
|
54
56
|
}, children: [_jsx(CardTitle, { flex: 1, children: t('swap.supportId') }), _jsx(Box, { mr: 1, mt: 1, children: _jsx(IconButton, { size: "medium", onClick: copySupportId, children: _jsx(ContentCopyIcon, { fontSize: "small" }) }) })] }), _jsx(Typography, { variant: "body2", pt: 1, pb: 2, px: 2, sx: { wordBreak: 'break-all' }, children: supportId })] }), _jsx(Box, { mt: 2, children: _jsx(Button, { href: "https://discord.com/channels/849912621360218112/863689862514343946", target: "_blank", rel: "nofollow noreferrer", fullWidth: true, children: t('button.contactSupport') }) }), _jsxs(Dialog, { open: open, onClose: toggleDialog, children: [_jsx(DialogTitle, { children: t('swap.warning.title.deleteSwap') }), _jsx(DialogContent, { children: _jsx(DialogContentText, { children: t('swap.warning.message.deleteSwapHistory') }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: toggleDialog, children: t('button.cancel') }), _jsx(Button, { variant: "contained", onClick: handleDeleteRoute, autoFocus: true, children: t('button.delete') })] })] })] }));
|
|
@@ -75,7 +75,10 @@ export const SwapPage = () => {
|
|
|
75
75
|
(route?.insurance?.state === 'INSURED' ||
|
|
76
76
|
(status === RouteExecutionStatus.Idle &&
|
|
77
77
|
route?.insurance?.state === 'INSURABLE'));
|
|
78
|
-
|
|
78
|
+
const insuranceCoverageId = route?.steps[0].execution?.process
|
|
79
|
+
.filter((process) => process.type !== 'TOKEN_ALLOWANCE')
|
|
80
|
+
.find((process) => process.txHash)?.txHash ?? route?.fromAddress;
|
|
81
|
+
return (_jsxs(Container, { children: [getStepList(route), insuranceAvailable ? (_jsx(Insurance, { mt: 2, status: status, insurableRouteId: stateRouteId, feeAmountUsd: route?.insurance.feeAmountUsd, insuranceCoverageId: insuranceCoverageId, onChange: setRouteId })) : null, status === RouteExecutionStatus.Idle ||
|
|
79
82
|
status === RouteExecutionStatus.Failed ? (_jsxs(_Fragment, { children: [_jsx(GasMessage, { mt: 2, route: route }), _jsxs(Box, { mt: 2, display: "flex", children: [_jsx(SwapButton, { text: getSwapButtonText(), onClick: handleSwapClick, route: route, insurableRouteId: stateRouteId }), status === RouteExecutionStatus.Failed ? (_jsx(Tooltip, { title: t('button.removeSwap'), placement: "bottom-end", enterDelay: 400, arrow: true, children: _jsx(Button, { onClick: handleRemoveRoute, sx: {
|
|
80
83
|
minWidth: 48,
|
|
81
84
|
marginLeft: 1,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { LiFiWalletManagement, readActiveWallets, supportedWallets, } from '@lifi/wallet-management';
|
|
3
3
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from 'react';
|
|
4
4
|
import { useWidgetConfig } from '../WidgetProvider';
|
|
5
|
+
const liFiWalletManagement = new LiFiWalletManagement();
|
|
5
6
|
const stub = () => {
|
|
6
7
|
throw new Error(`You forgot to wrap your component in <${WalletProvider.name}>.`);
|
|
7
8
|
};
|
|
@@ -17,8 +18,26 @@ const WalletContext = createContext(initialContext);
|
|
|
17
18
|
export const useWallet = () => useContext(WalletContext);
|
|
18
19
|
export const WalletProvider = ({ children }) => {
|
|
19
20
|
const { walletManagement } = useWidgetConfig();
|
|
20
|
-
const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, provider, } = useLiFiWalletManagement();
|
|
21
21
|
const [account, setAccount] = useState({});
|
|
22
|
+
const [currentWallet, setCurrentWallet] = useState();
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const autoConnect = async () => {
|
|
25
|
+
const persistedActiveWallets = readActiveWallets();
|
|
26
|
+
const activeWallets = supportedWallets.filter((wallet) => persistedActiveWallets.some((perstistedWallet) => perstistedWallet.name === wallet.name));
|
|
27
|
+
if (!activeWallets.length) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
await liFiWalletManagement.autoConnect(activeWallets);
|
|
31
|
+
activeWallets[0].on('walletAccountChanged', handleWalletUpdate);
|
|
32
|
+
handleWalletUpdate(activeWallets[0]);
|
|
33
|
+
};
|
|
34
|
+
autoConnect();
|
|
35
|
+
}, []);
|
|
36
|
+
const handleWalletUpdate = async (wallet) => {
|
|
37
|
+
setCurrentWallet(wallet);
|
|
38
|
+
const account = await extractAccountFromSigner(wallet?.account?.signer);
|
|
39
|
+
setAccount(account);
|
|
40
|
+
};
|
|
22
41
|
const connect = useCallback(async (wallet) => {
|
|
23
42
|
if (walletManagement) {
|
|
24
43
|
const signer = await walletManagement.connect();
|
|
@@ -26,17 +45,22 @@ export const WalletProvider = ({ children }) => {
|
|
|
26
45
|
setAccount(account);
|
|
27
46
|
return;
|
|
28
47
|
}
|
|
29
|
-
await
|
|
30
|
-
|
|
48
|
+
await liFiWalletManagement.connect(wallet);
|
|
49
|
+
wallet.on('walletAccountChanged', handleWalletUpdate);
|
|
50
|
+
handleWalletUpdate(wallet);
|
|
51
|
+
}, [walletManagement]);
|
|
31
52
|
const disconnect = useCallback(async () => {
|
|
32
53
|
if (walletManagement) {
|
|
33
54
|
await walletManagement.disconnect();
|
|
34
55
|
setAccount({});
|
|
35
56
|
return;
|
|
36
57
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
58
|
+
if (currentWallet) {
|
|
59
|
+
await liFiWalletManagement.disconnect(currentWallet);
|
|
60
|
+
currentWallet.removeAllListeners();
|
|
61
|
+
handleWalletUpdate(undefined);
|
|
62
|
+
}
|
|
63
|
+
}, [walletManagement, currentWallet]);
|
|
40
64
|
const switchChain = useCallback(async (chainId) => {
|
|
41
65
|
if (walletManagement?.switchChain) {
|
|
42
66
|
const signer = await walletManagement.switchChain(chainId);
|
|
@@ -44,34 +68,46 @@ export const WalletProvider = ({ children }) => {
|
|
|
44
68
|
setAccount(account);
|
|
45
69
|
return true;
|
|
46
70
|
}
|
|
47
|
-
|
|
48
|
-
|
|
71
|
+
try {
|
|
72
|
+
await currentWallet?.switchChain(chainId);
|
|
73
|
+
handleWalletUpdate(currentWallet);
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}, [walletManagement, currentWallet]);
|
|
49
80
|
const addChain = useCallback(async (chainId) => {
|
|
50
81
|
if (walletManagement?.addChain) {
|
|
51
82
|
return walletManagement.addChain(chainId);
|
|
52
83
|
}
|
|
53
|
-
|
|
54
|
-
|
|
84
|
+
try {
|
|
85
|
+
await currentWallet?.addChain(chainId);
|
|
86
|
+
handleWalletUpdate(currentWallet);
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}, [walletManagement, currentWallet]);
|
|
55
93
|
const addToken = useCallback(async (chainId, token) => {
|
|
56
94
|
if (walletManagement?.addToken) {
|
|
57
95
|
return walletManagement.addToken(token, chainId);
|
|
58
96
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
97
|
+
await currentWallet?.addToken(chainId, token);
|
|
98
|
+
handleWalletUpdate(currentWallet);
|
|
99
|
+
return;
|
|
100
|
+
}, [walletManagement, currentWallet]);
|
|
101
|
+
// keep widget in sync with changing external signer object
|
|
62
102
|
useEffect(() => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
account
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
setAccount(account);
|
|
72
|
-
};
|
|
73
|
-
updateAccount();
|
|
74
|
-
}, [signer, walletManagement]);
|
|
103
|
+
if (walletManagement) {
|
|
104
|
+
const updateAccount = async () => {
|
|
105
|
+
const account = await extractAccountFromSigner(walletManagement?.signer);
|
|
106
|
+
setAccount(account);
|
|
107
|
+
};
|
|
108
|
+
updateAccount();
|
|
109
|
+
}
|
|
110
|
+
}, [walletManagement, walletManagement?.signer]);
|
|
75
111
|
const value = useMemo(() => ({
|
|
76
112
|
connect,
|
|
77
113
|
disconnect,
|
|
@@ -79,8 +115,16 @@ export const WalletProvider = ({ children }) => {
|
|
|
79
115
|
addChain,
|
|
80
116
|
addToken,
|
|
81
117
|
account,
|
|
82
|
-
provider,
|
|
83
|
-
}), [
|
|
118
|
+
provider: currentWallet?.account?.provider,
|
|
119
|
+
}), [
|
|
120
|
+
account,
|
|
121
|
+
addChain,
|
|
122
|
+
addToken,
|
|
123
|
+
connect,
|
|
124
|
+
disconnect,
|
|
125
|
+
currentWallet,
|
|
126
|
+
switchChain,
|
|
127
|
+
]);
|
|
84
128
|
return (_jsx(WalletContext.Provider, { value: value, children: children }));
|
|
85
129
|
};
|
|
86
130
|
export const extractAccountFromSigner = async (signer) => {
|
|
@@ -93,7 +137,7 @@ export const extractAccountFromSigner = async (signer) => {
|
|
|
93
137
|
};
|
|
94
138
|
}
|
|
95
139
|
catch (error) {
|
|
96
|
-
console.
|
|
140
|
+
console.error(error);
|
|
97
141
|
return {};
|
|
98
142
|
}
|
|
99
143
|
};
|
|
@@ -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
|
}
|