@lifi/widget 2.7.1 → 2.8.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.
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/providers/WalletProvider/WalletProvider.js +19 -7
- package/cjs/types/events.d.ts +7 -1
- package/cjs/types/events.js +1 -0
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/package.json +4 -4
- package/providers/WalletProvider/WalletProvider.js +19 -7
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/events.d.ts +7 -1
- package/types/events.js +1 -0
package/cjs/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "2.
|
|
2
|
+
export declare const version = "2.8.0";
|
package/cjs/config/version.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.extractAccountFromSigner = exports.WalletProvider = exports.useWallet =
|
|
|
4
4
|
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
|
+
const hooks_1 = require("../../hooks");
|
|
8
|
+
const types_1 = require("../../types");
|
|
7
9
|
const WidgetProvider_1 = require("../WidgetProvider");
|
|
8
10
|
const liFiWalletManagement = new wallet_management_1.LiFiWalletManagement();
|
|
9
11
|
const stub = () => {
|
|
@@ -21,6 +23,7 @@ const WalletContext = (0, react_1.createContext)(initialContext);
|
|
|
21
23
|
const useWallet = () => (0, react_1.useContext)(WalletContext);
|
|
22
24
|
exports.useWallet = useWallet;
|
|
23
25
|
const WalletProvider = ({ children }) => {
|
|
26
|
+
const emitter = (0, hooks_1.useWidgetEvents)();
|
|
24
27
|
const { walletManagement } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
25
28
|
const [account, setAccount] = (0, react_1.useState)({});
|
|
26
29
|
const [currentWallet, setCurrentWallet] = (0, react_1.useState)();
|
|
@@ -28,18 +31,27 @@ const WalletProvider = ({ children }) => {
|
|
|
28
31
|
setCurrentWallet(wallet);
|
|
29
32
|
const account = await (0, exports.extractAccountFromSigner)(wallet?.account?.signer);
|
|
30
33
|
setAccount(account);
|
|
34
|
+
return account;
|
|
31
35
|
};
|
|
32
36
|
const connect = (0, react_1.useCallback)(async (wallet) => {
|
|
33
37
|
if (walletManagement) {
|
|
34
38
|
const signer = await walletManagement.connect();
|
|
35
39
|
const account = await (0, exports.extractAccountFromSigner)(signer);
|
|
36
40
|
setAccount(account);
|
|
41
|
+
emitter.emit(types_1.WidgetEvent.WalletConnected, {
|
|
42
|
+
address: account.address,
|
|
43
|
+
chainId: account.chainId,
|
|
44
|
+
});
|
|
37
45
|
return;
|
|
38
46
|
}
|
|
39
47
|
await liFiWalletManagement.connect(wallet);
|
|
40
48
|
wallet.on('walletAccountChanged', handleWalletUpdate);
|
|
41
|
-
handleWalletUpdate(wallet);
|
|
42
|
-
|
|
49
|
+
const account = await handleWalletUpdate(wallet);
|
|
50
|
+
emitter.emit(types_1.WidgetEvent.WalletConnected, {
|
|
51
|
+
address: account.address,
|
|
52
|
+
chainId: account.chainId,
|
|
53
|
+
});
|
|
54
|
+
}, [emitter, walletManagement]);
|
|
43
55
|
const disconnect = (0, react_1.useCallback)(async () => {
|
|
44
56
|
if (walletManagement) {
|
|
45
57
|
await walletManagement.disconnect();
|
|
@@ -49,7 +61,7 @@ const WalletProvider = ({ children }) => {
|
|
|
49
61
|
if (currentWallet) {
|
|
50
62
|
await liFiWalletManagement.disconnect(currentWallet);
|
|
51
63
|
currentWallet.removeAllListeners();
|
|
52
|
-
handleWalletUpdate(undefined);
|
|
64
|
+
await handleWalletUpdate(undefined);
|
|
53
65
|
}
|
|
54
66
|
}, [currentWallet, walletManagement]);
|
|
55
67
|
const switchChain = (0, react_1.useCallback)(async (chainId) => {
|
|
@@ -69,7 +81,7 @@ const WalletProvider = ({ children }) => {
|
|
|
69
81
|
}
|
|
70
82
|
else {
|
|
71
83
|
await currentWallet?.switchChain(chainId);
|
|
72
|
-
handleWalletUpdate(currentWallet);
|
|
84
|
+
await handleWalletUpdate(currentWallet);
|
|
73
85
|
}
|
|
74
86
|
// TODO: this will fail if it's not created with ethers 'any' network, replace with the new signer when possible
|
|
75
87
|
return account.signer;
|
|
@@ -92,7 +104,7 @@ const WalletProvider = ({ children }) => {
|
|
|
92
104
|
}
|
|
93
105
|
else {
|
|
94
106
|
await currentWallet?.addChain(chainId);
|
|
95
|
-
handleWalletUpdate(currentWallet);
|
|
107
|
+
await handleWalletUpdate(currentWallet);
|
|
96
108
|
}
|
|
97
109
|
return true;
|
|
98
110
|
}
|
|
@@ -114,7 +126,7 @@ const WalletProvider = ({ children }) => {
|
|
|
114
126
|
}
|
|
115
127
|
else {
|
|
116
128
|
await currentWallet?.addToken(chainId, token);
|
|
117
|
-
handleWalletUpdate(currentWallet);
|
|
129
|
+
await handleWalletUpdate(currentWallet);
|
|
118
130
|
}
|
|
119
131
|
}
|
|
120
132
|
catch { }
|
|
@@ -128,7 +140,7 @@ const WalletProvider = ({ children }) => {
|
|
|
128
140
|
}
|
|
129
141
|
await liFiWalletManagement.autoConnect(activeWallets);
|
|
130
142
|
activeWallets[0].on('walletAccountChanged', handleWalletUpdate);
|
|
131
|
-
handleWalletUpdate(activeWallets[0]);
|
|
143
|
+
await handleWalletUpdate(activeWallets[0]);
|
|
132
144
|
};
|
|
133
145
|
autoConnect();
|
|
134
146
|
}, []);
|
package/cjs/types/events.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ export declare enum WidgetEvent {
|
|
|
9
9
|
SourceChainTokenSelected = "sourceChainTokenSelected",
|
|
10
10
|
DestinationChainTokenSelected = "destinationChainTokenSelected",
|
|
11
11
|
SendToWalletToggled = "sendToWalletToggled",
|
|
12
|
-
ReviewTransactionPageEntered = "reviewTransactionPageEntered"
|
|
12
|
+
ReviewTransactionPageEntered = "reviewTransactionPageEntered",
|
|
13
|
+
WalletConnected = "walletConnected"
|
|
13
14
|
}
|
|
14
15
|
export type WidgetEvents = {
|
|
15
16
|
routeExecutionStarted: Route;
|
|
@@ -22,6 +23,7 @@ export type WidgetEvents = {
|
|
|
22
23
|
destinationChainTokenSelected: ChainTokenSelected;
|
|
23
24
|
sendToWalletToggled: boolean;
|
|
24
25
|
reviewTransactionPageEntered?: Route;
|
|
26
|
+
walletConnected: WalletConnected;
|
|
25
27
|
};
|
|
26
28
|
export interface RouteContactSupport {
|
|
27
29
|
supportId?: string;
|
|
@@ -40,3 +42,7 @@ export interface ChainTokenSelected {
|
|
|
40
42
|
chainId: ChainId;
|
|
41
43
|
tokenAddress: string;
|
|
42
44
|
}
|
|
45
|
+
export interface WalletConnected {
|
|
46
|
+
chainId?: number;
|
|
47
|
+
address?: string;
|
|
48
|
+
}
|
package/cjs/types/events.js
CHANGED
|
@@ -13,4 +13,5 @@ var WidgetEvent;
|
|
|
13
13
|
WidgetEvent["DestinationChainTokenSelected"] = "destinationChainTokenSelected";
|
|
14
14
|
WidgetEvent["SendToWalletToggled"] = "sendToWalletToggled";
|
|
15
15
|
WidgetEvent["ReviewTransactionPageEntered"] = "reviewTransactionPageEntered";
|
|
16
|
+
WidgetEvent["WalletConnected"] = "walletConnected";
|
|
16
17
|
})(WidgetEvent || (exports.WidgetEvent = WidgetEvent = {}));
|
package/config/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/widget";
|
|
2
|
-
export declare const version = "2.
|
|
2
|
+
export declare const version = "2.8.0";
|
package/config/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget';
|
|
2
|
-
export const version = '2.
|
|
2
|
+
export const version = '2.8.0';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/widget",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
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",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@mui/lab": "^5.0.0-alpha.149",
|
|
50
50
|
"@mui/material": "^5.14.14",
|
|
51
51
|
"@tanstack/react-query": "^4.36.1",
|
|
52
|
-
"@tanstack/react-virtual": "^3.0.0-beta.
|
|
52
|
+
"@tanstack/react-virtual": "^3.0.0-beta.68",
|
|
53
53
|
"big.js": "^6.2.1",
|
|
54
54
|
"i18next": "^23.6.0",
|
|
55
55
|
"i18next-browser-languagedetector": "^7.1.0",
|
|
@@ -58,12 +58,12 @@
|
|
|
58
58
|
"react": "^18.2.0",
|
|
59
59
|
"react-dom": "^18.2.0",
|
|
60
60
|
"react-hook-form": "^7.47.0",
|
|
61
|
-
"react-i18next": "^13.3.
|
|
61
|
+
"react-i18next": "^13.3.1",
|
|
62
62
|
"react-intersection-observer": "^9.5.2",
|
|
63
63
|
"react-router-dom": "^6.17.0",
|
|
64
64
|
"react-timer-hook": "^3.0.7",
|
|
65
65
|
"uuid": "^9.0.1",
|
|
66
|
-
"zustand": "^4.4.
|
|
66
|
+
"zustand": "^4.4.4"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"@types/react": "^18.0.0",
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { LiFiWalletManagement, readActiveWallets, supportedWallets, addChain as walletAgnosticAddChain, switchChainAndAddToken as walletAgnosticAddToken, switchChain as walletAgnosticSwitchChain, } from '@lifi/wallet-management';
|
|
3
3
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from 'react';
|
|
4
|
+
import { useWidgetEvents } from '../../hooks';
|
|
5
|
+
import { WidgetEvent } from '../../types';
|
|
4
6
|
import { useWidgetConfig } from '../WidgetProvider';
|
|
5
7
|
const liFiWalletManagement = new LiFiWalletManagement();
|
|
6
8
|
const stub = () => {
|
|
@@ -17,6 +19,7 @@ const initialContext = {
|
|
|
17
19
|
const WalletContext = createContext(initialContext);
|
|
18
20
|
export const useWallet = () => useContext(WalletContext);
|
|
19
21
|
export const WalletProvider = ({ children }) => {
|
|
22
|
+
const emitter = useWidgetEvents();
|
|
20
23
|
const { walletManagement } = useWidgetConfig();
|
|
21
24
|
const [account, setAccount] = useState({});
|
|
22
25
|
const [currentWallet, setCurrentWallet] = useState();
|
|
@@ -24,18 +27,27 @@ export const WalletProvider = ({ children }) => {
|
|
|
24
27
|
setCurrentWallet(wallet);
|
|
25
28
|
const account = await extractAccountFromSigner(wallet?.account?.signer);
|
|
26
29
|
setAccount(account);
|
|
30
|
+
return account;
|
|
27
31
|
};
|
|
28
32
|
const connect = useCallback(async (wallet) => {
|
|
29
33
|
if (walletManagement) {
|
|
30
34
|
const signer = await walletManagement.connect();
|
|
31
35
|
const account = await extractAccountFromSigner(signer);
|
|
32
36
|
setAccount(account);
|
|
37
|
+
emitter.emit(WidgetEvent.WalletConnected, {
|
|
38
|
+
address: account.address,
|
|
39
|
+
chainId: account.chainId,
|
|
40
|
+
});
|
|
33
41
|
return;
|
|
34
42
|
}
|
|
35
43
|
await liFiWalletManagement.connect(wallet);
|
|
36
44
|
wallet.on('walletAccountChanged', handleWalletUpdate);
|
|
37
|
-
handleWalletUpdate(wallet);
|
|
38
|
-
|
|
45
|
+
const account = await handleWalletUpdate(wallet);
|
|
46
|
+
emitter.emit(WidgetEvent.WalletConnected, {
|
|
47
|
+
address: account.address,
|
|
48
|
+
chainId: account.chainId,
|
|
49
|
+
});
|
|
50
|
+
}, [emitter, walletManagement]);
|
|
39
51
|
const disconnect = useCallback(async () => {
|
|
40
52
|
if (walletManagement) {
|
|
41
53
|
await walletManagement.disconnect();
|
|
@@ -45,7 +57,7 @@ export const WalletProvider = ({ children }) => {
|
|
|
45
57
|
if (currentWallet) {
|
|
46
58
|
await liFiWalletManagement.disconnect(currentWallet);
|
|
47
59
|
currentWallet.removeAllListeners();
|
|
48
|
-
handleWalletUpdate(undefined);
|
|
60
|
+
await handleWalletUpdate(undefined);
|
|
49
61
|
}
|
|
50
62
|
}, [currentWallet, walletManagement]);
|
|
51
63
|
const switchChain = useCallback(async (chainId) => {
|
|
@@ -65,7 +77,7 @@ export const WalletProvider = ({ children }) => {
|
|
|
65
77
|
}
|
|
66
78
|
else {
|
|
67
79
|
await currentWallet?.switchChain(chainId);
|
|
68
|
-
handleWalletUpdate(currentWallet);
|
|
80
|
+
await handleWalletUpdate(currentWallet);
|
|
69
81
|
}
|
|
70
82
|
// TODO: this will fail if it's not created with ethers 'any' network, replace with the new signer when possible
|
|
71
83
|
return account.signer;
|
|
@@ -88,7 +100,7 @@ export const WalletProvider = ({ children }) => {
|
|
|
88
100
|
}
|
|
89
101
|
else {
|
|
90
102
|
await currentWallet?.addChain(chainId);
|
|
91
|
-
handleWalletUpdate(currentWallet);
|
|
103
|
+
await handleWalletUpdate(currentWallet);
|
|
92
104
|
}
|
|
93
105
|
return true;
|
|
94
106
|
}
|
|
@@ -110,7 +122,7 @@ export const WalletProvider = ({ children }) => {
|
|
|
110
122
|
}
|
|
111
123
|
else {
|
|
112
124
|
await currentWallet?.addToken(chainId, token);
|
|
113
|
-
handleWalletUpdate(currentWallet);
|
|
125
|
+
await handleWalletUpdate(currentWallet);
|
|
114
126
|
}
|
|
115
127
|
}
|
|
116
128
|
catch { }
|
|
@@ -124,7 +136,7 @@ export const WalletProvider = ({ children }) => {
|
|
|
124
136
|
}
|
|
125
137
|
await liFiWalletManagement.autoConnect(activeWallets);
|
|
126
138
|
activeWallets[0].on('walletAccountChanged', handleWalletUpdate);
|
|
127
|
-
handleWalletUpdate(activeWallets[0]);
|
|
139
|
+
await handleWalletUpdate(activeWallets[0]);
|
|
128
140
|
};
|
|
129
141
|
autoConnect();
|
|
130
142
|
}, []);
|