@lifi/widget 2.0.0-beta.7 → 2.0.0-beta.8
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/App.d.ts +1 -1
- package/AppDrawer.d.ts +1 -1
- package/cjs/App.d.ts +1 -1
- package/cjs/AppDrawer.d.ts +1 -1
- package/cjs/components/ChainSelect/ChainSelect.d.ts +1 -1
- package/cjs/components/GasMessage/FundsSufficiencyMessage.d.ts +1 -1
- package/cjs/components/Header/Header.style.d.ts +10 -3
- package/cjs/components/Header/NavigationHeader.js +1 -1
- package/cjs/components/Header/NavigationTabs.d.ts +1 -1
- package/cjs/components/Header/NavigationTabs.style.d.ts +4 -71
- package/cjs/components/Header/WalletHeader.js +1 -1
- package/cjs/components/SelectChainAndToken.js +8 -7
- package/cjs/components/SendToWallet/SendToWallet.js +2 -2
- package/cjs/components/SmallAvatar.d.ts +1 -1
- package/cjs/components/Step/CircularProgress.d.ts +1 -1
- package/cjs/components/Step/Step.js +1 -1
- package/cjs/components/Step/StepList.d.ts +1 -1
- package/cjs/components/SwapInput/SwapInputEndAdornment.d.ts +1 -1
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.d.ts +2 -2
- package/cjs/components/TokenList/TokenList.js +5 -2
- package/cjs/components/TokenList/TokenList.style.d.ts +5 -2
- package/cjs/components/TokenList/TokenList.style.js +20 -1
- package/cjs/components/TokenList/TokenListItem.d.ts +1 -1
- package/cjs/components/TokenList/TokenListItem.js +27 -4
- package/cjs/components/TokenList/VirtualizedTokenList.js +3 -3
- package/cjs/components/TokenList/types.d.ts +4 -0
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/useFundsSufficiency.js +2 -2
- package/cjs/hooks/useGasRefuel.d.ts +1 -1
- package/cjs/hooks/useGasRefuel.js +5 -15
- package/cjs/hooks/useGasSufficiency.js +2 -2
- package/cjs/hooks/useRouteExecution.js +3 -3
- package/cjs/hooks/useSwapRoutes.js +4 -4
- package/cjs/hooks/useTokenBalance.js +2 -2
- package/cjs/i18n/en.json +1 -1
- package/cjs/icons/InsuraceLogo.d.ts +1 -1
- package/cjs/icons/LiFiFullLogo.d.ts +1 -1
- package/cjs/icons/LiFiLogo.d.ts +1 -1
- package/cjs/icons/LiFiToolLogo.d.ts +1 -1
- package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +1 -1
- package/cjs/pages/SelectTokenPage/SearchTokenInput.d.ts +1 -1
- package/cjs/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -1
- package/cjs/pages/SettingsPage/GasPriceSelect.d.ts +1 -1
- package/cjs/pages/SettingsPage/SettingsPage.d.ts +1 -1
- package/cjs/pages/SettingsPage/ShowDestinationWallet.d.ts +1 -1
- package/cjs/pages/SettingsPage/SlippageInput.d.ts +1 -1
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +1 -1
- package/cjs/pages/SwapPage/StatusBottomSheet.js +3 -3
- package/cjs/providers/WalletProvider/WalletProvider.js +73 -47
- package/cjs/providers/WalletProvider/types.d.ts +0 -2
- package/cjs/stores/routes/RouteExecutionStore.d.ts +1 -1
- package/cjs/stores/settings/useSplitSubvariantStore.d.ts +1 -1
- package/cjs/types/widget.d.ts +1 -0
- package/cjs/types/widget.js +1 -0
- package/cjs/utils/wallet.d.ts +1 -1
- package/cjs/utils/wallet.js +3 -3
- package/components/ChainSelect/ChainSelect.d.ts +1 -1
- package/components/GasMessage/FundsSufficiencyMessage.d.ts +1 -1
- package/components/Header/Header.style.d.ts +10 -3
- package/components/Header/NavigationHeader.js +1 -1
- package/components/Header/NavigationTabs.d.ts +1 -1
- package/components/Header/NavigationTabs.style.d.ts +4 -71
- package/components/Header/WalletHeader.js +2 -2
- package/components/SelectChainAndToken.js +9 -8
- package/components/SendToWallet/SendToWallet.js +2 -2
- package/components/SmallAvatar.d.ts +1 -1
- package/components/Step/CircularProgress.d.ts +1 -1
- package/components/Step/Step.js +2 -2
- package/components/Step/StepList.d.ts +1 -1
- package/components/SwapInput/SwapInputEndAdornment.d.ts +1 -1
- package/components/SwapRoutes/SwapRoutesExpanded.d.ts +2 -2
- package/components/TokenList/TokenList.js +6 -3
- package/components/TokenList/TokenList.style.d.ts +5 -2
- package/components/TokenList/TokenList.style.js +21 -2
- package/components/TokenList/TokenListItem.d.ts +1 -1
- package/components/TokenList/TokenListItem.js +31 -8
- package/components/TokenList/VirtualizedTokenList.js +3 -3
- package/components/TokenList/types.d.ts +4 -0
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/useFundsSufficiency.js +2 -2
- package/hooks/useGasRefuel.d.ts +1 -1
- package/hooks/useGasRefuel.js +5 -15
- package/hooks/useGasSufficiency.js +2 -2
- package/hooks/useRouteExecution.js +3 -3
- package/hooks/useSwapRoutes.js +4 -4
- package/hooks/useTokenBalance.js +2 -2
- package/i18n/en.json +1 -1
- package/icons/InsuraceLogo.d.ts +1 -1
- package/icons/LiFiFullLogo.d.ts +1 -1
- package/icons/LiFiLogo.d.ts +1 -1
- package/icons/LiFiToolLogo.d.ts +1 -1
- package/package.json +6 -6
- package/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +1 -1
- package/pages/SelectTokenPage/SearchTokenInput.d.ts +1 -1
- package/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -1
- package/pages/SettingsPage/GasPriceSelect.d.ts +1 -1
- package/pages/SettingsPage/SettingsPage.d.ts +1 -1
- package/pages/SettingsPage/ShowDestinationWallet.d.ts +1 -1
- package/pages/SettingsPage/SlippageInput.d.ts +1 -1
- package/pages/SwapDetailsPage/SwapDetailsPage.js +1 -1
- package/pages/SwapPage/StatusBottomSheet.js +4 -4
- package/providers/WalletProvider/WalletProvider.js +74 -48
- package/providers/WalletProvider/types.d.ts +0 -2
- package/stores/routes/RouteExecutionStore.d.ts +1 -1
- package/stores/settings/useSplitSubvariantStore.d.ts +1 -1
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/widget.d.ts +1 -0
- package/types/widget.js +1 -0
- package/utils/wallet.d.ts +1 -1
- package/utils/wallet.js +1 -1
|
@@ -12,7 +12,7 @@ import { Token } from '../../components/Token';
|
|
|
12
12
|
import { getProcessMessage, useChains, useNavigateBack, useTokenBalance, } from '../../hooks';
|
|
13
13
|
import { SwapFormKey, useWidgetConfig } from '../../providers';
|
|
14
14
|
import { RouteExecutionStatus } from '../../stores';
|
|
15
|
-
import { formatTokenAmount, hasEnumFlag, navigationRoutes,
|
|
15
|
+
import { formatTokenAmount, hasEnumFlag, navigationRoutes, shortenAddress, } from '../../utils';
|
|
16
16
|
import { CenterContainer, IconCircle } from './StatusBottomSheet.style';
|
|
17
17
|
export const StatusBottomSheet = ({ status, route, }) => {
|
|
18
18
|
const { t } = useTranslation();
|
|
@@ -79,7 +79,7 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
79
79
|
amount: token.amount,
|
|
80
80
|
tokenSymbol: token.symbol,
|
|
81
81
|
chainName: getChainById(token.chainId)?.name,
|
|
82
|
-
walletAddress:
|
|
82
|
+
walletAddress: shortenAddress(route.toAddress),
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
handlePrimaryButton = handleDone;
|
|
@@ -96,7 +96,7 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
96
96
|
amount: token.amount,
|
|
97
97
|
tokenSymbol: token.symbol,
|
|
98
98
|
chainName: getChainById(token.chainId)?.name,
|
|
99
|
-
walletAddress:
|
|
99
|
+
walletAddress: shortenAddress(route.toAddress),
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
handlePrimaryButton = handlePartialDone;
|
|
@@ -113,7 +113,7 @@ export const StatusBottomSheet = ({ status, route, }) => {
|
|
|
113
113
|
amount: token.amount,
|
|
114
114
|
tokenSymbol: token.symbol,
|
|
115
115
|
chainName: getChainById(token.chainId)?.name,
|
|
116
|
-
walletAddress:
|
|
116
|
+
walletAddress: shortenAddress(route.toAddress),
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
break;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { LiFiWalletManagement, readActiveWallets, supportedWallets, } from '@lifi/wallet-management';
|
|
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
4
|
import { useWidgetConfig } from '../WidgetProvider';
|
|
5
5
|
const liFiWalletManagement = new LiFiWalletManagement();
|
|
@@ -20,19 +20,6 @@ export const WalletProvider = ({ children }) => {
|
|
|
20
20
|
const { walletManagement } = useWidgetConfig();
|
|
21
21
|
const [account, setAccount] = useState({});
|
|
22
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
23
|
const handleWalletUpdate = async (wallet) => {
|
|
37
24
|
setCurrentWallet(wallet);
|
|
38
25
|
const account = await extractAccountFromSigner(wallet?.account?.signer);
|
|
@@ -60,54 +47,102 @@ export const WalletProvider = ({ children }) => {
|
|
|
60
47
|
currentWallet.removeAllListeners();
|
|
61
48
|
handleWalletUpdate(undefined);
|
|
62
49
|
}
|
|
63
|
-
}, [
|
|
50
|
+
}, [currentWallet, walletManagement]);
|
|
64
51
|
const switchChain = useCallback(async (chainId) => {
|
|
65
|
-
if (walletManagement?.switchChain) {
|
|
66
|
-
const signer = await walletManagement.switchChain(chainId);
|
|
67
|
-
const account = await extractAccountFromSigner(signer);
|
|
68
|
-
setAccount(account);
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
52
|
try {
|
|
72
|
-
|
|
73
|
-
|
|
53
|
+
if (walletManagement?.switchChain) {
|
|
54
|
+
const signer = await walletManagement.switchChain(chainId);
|
|
55
|
+
const account = await extractAccountFromSigner(signer);
|
|
56
|
+
setAccount(account);
|
|
57
|
+
}
|
|
58
|
+
else if (!currentWallet) {
|
|
59
|
+
const provider = account.signer?.provider;
|
|
60
|
+
if (!provider) {
|
|
61
|
+
throw new Error(`Switch chain: No provider available`);
|
|
62
|
+
}
|
|
63
|
+
await walletAgnosticSwitchChain(provider, chainId);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
await currentWallet?.switchChain(chainId);
|
|
67
|
+
handleWalletUpdate(currentWallet);
|
|
68
|
+
}
|
|
74
69
|
return true;
|
|
75
70
|
}
|
|
76
71
|
catch {
|
|
77
72
|
return false;
|
|
78
73
|
}
|
|
79
|
-
}, [
|
|
74
|
+
}, [account.signer?.provider, currentWallet, walletManagement]);
|
|
80
75
|
const addChain = useCallback(async (chainId) => {
|
|
81
|
-
if (walletManagement?.addChain) {
|
|
82
|
-
return walletManagement.addChain(chainId);
|
|
83
|
-
}
|
|
84
76
|
try {
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
if (walletManagement?.addChain) {
|
|
78
|
+
return walletManagement.addChain(chainId);
|
|
79
|
+
}
|
|
80
|
+
else if (!currentWallet) {
|
|
81
|
+
const provider = account.signer?.provider;
|
|
82
|
+
if (!provider) {
|
|
83
|
+
throw new Error(`Add chain: No provider available`);
|
|
84
|
+
}
|
|
85
|
+
await walletAgnosticAddChain(provider, chainId);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
await currentWallet?.addChain(chainId);
|
|
89
|
+
handleWalletUpdate(currentWallet);
|
|
90
|
+
}
|
|
87
91
|
return true;
|
|
88
92
|
}
|
|
89
93
|
catch {
|
|
90
94
|
return false;
|
|
91
95
|
}
|
|
92
|
-
}, [
|
|
96
|
+
}, [account.signer?.provider, currentWallet, walletManagement]);
|
|
93
97
|
const addToken = useCallback(async (chainId, token) => {
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
try {
|
|
99
|
+
if (walletManagement?.addToken) {
|
|
100
|
+
return walletManagement.addToken(token, chainId);
|
|
101
|
+
}
|
|
102
|
+
else if (!currentWallet) {
|
|
103
|
+
const provider = account.signer?.provider;
|
|
104
|
+
if (!provider) {
|
|
105
|
+
throw new Error(`Add token: No provider available`);
|
|
106
|
+
}
|
|
107
|
+
await walletAgnosticAddToken(provider, chainId, token);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
await currentWallet?.addToken(chainId, token);
|
|
111
|
+
handleWalletUpdate(currentWallet);
|
|
112
|
+
}
|
|
96
113
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
114
|
+
catch { }
|
|
115
|
+
}, [account.signer?.provider, currentWallet, walletManagement]);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
const autoConnect = async () => {
|
|
118
|
+
const persistedActiveWallets = readActiveWallets();
|
|
119
|
+
const activeWallets = supportedWallets.filter((wallet) => persistedActiveWallets.some((perstistedWallet) => perstistedWallet.name === wallet.name));
|
|
120
|
+
if (!activeWallets.length) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
await liFiWalletManagement.autoConnect(activeWallets);
|
|
124
|
+
activeWallets[0].on('walletAccountChanged', handleWalletUpdate);
|
|
125
|
+
handleWalletUpdate(activeWallets[0]);
|
|
126
|
+
};
|
|
127
|
+
autoConnect();
|
|
128
|
+
}, []);
|
|
101
129
|
// keep widget in sync with changing external signer object
|
|
102
130
|
useEffect(() => {
|
|
103
131
|
if (walletManagement) {
|
|
132
|
+
let ignore = false;
|
|
104
133
|
const updateAccount = async () => {
|
|
105
134
|
const account = await extractAccountFromSigner(walletManagement?.signer);
|
|
106
|
-
|
|
135
|
+
// we should ignore the update if there is a newer one
|
|
136
|
+
if (!ignore) {
|
|
137
|
+
setAccount(account);
|
|
138
|
+
}
|
|
107
139
|
};
|
|
108
140
|
updateAccount();
|
|
141
|
+
return () => {
|
|
142
|
+
ignore = true;
|
|
143
|
+
};
|
|
109
144
|
}
|
|
110
|
-
}, [walletManagement
|
|
145
|
+
}, [walletManagement]);
|
|
111
146
|
const value = useMemo(() => ({
|
|
112
147
|
connect,
|
|
113
148
|
disconnect,
|
|
@@ -115,16 +150,7 @@ export const WalletProvider = ({ children }) => {
|
|
|
115
150
|
addChain,
|
|
116
151
|
addToken,
|
|
117
152
|
account,
|
|
118
|
-
|
|
119
|
-
}), [
|
|
120
|
-
account,
|
|
121
|
-
addChain,
|
|
122
|
-
addToken,
|
|
123
|
-
connect,
|
|
124
|
-
disconnect,
|
|
125
|
-
currentWallet,
|
|
126
|
-
switchChain,
|
|
127
|
-
]);
|
|
153
|
+
}), [account, addChain, addToken, connect, disconnect, switchChain]);
|
|
128
154
|
return (_jsx(WalletContext.Provider, { value: value, children: children }));
|
|
129
155
|
};
|
|
130
156
|
export const extractAccountFromSigner = async (signer) => {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { Signer } from '@ethersproject/abstract-signer';
|
|
2
|
-
import type { Provider } from '@ethersproject/providers';
|
|
3
2
|
import type { StaticToken } from '@lifi/sdk';
|
|
4
3
|
import type { Wallet } from '@lifi/wallet-management';
|
|
5
4
|
export interface WalletContextProps {
|
|
6
5
|
account: WalletAccount;
|
|
7
|
-
provider?: Provider;
|
|
8
6
|
addChain(chainId: number): Promise<boolean>;
|
|
9
7
|
addToken(chainId: number, token: StaticToken): Promise<void>;
|
|
10
8
|
disconnect(wallet?: Wallet): void;
|
|
@@ -4,6 +4,6 @@ import type { PersistStoreProviderProps } from '../types';
|
|
|
4
4
|
import type { RouteExecutionState } from './types';
|
|
5
5
|
export type RouteExecutionStore = UseBoundStore<StoreApi<RouteExecutionState>>;
|
|
6
6
|
export declare const RouteExecutionStoreContext: import("react").Context<RouteExecutionStore | null>;
|
|
7
|
-
export declare function RouteExecutionStoreProvider({ children, ...props }: PersistStoreProviderProps): JSX.Element;
|
|
7
|
+
export declare function RouteExecutionStoreProvider({ children, ...props }: PersistStoreProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
8
8
|
export declare function useRouteExecutionStore<T>(selector: (state: RouteExecutionState) => T, equalityFn?: (left: T, right: T) => boolean): T;
|
|
9
9
|
export declare function useRouteExecutionStoreContext(): RouteExecutionStore;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { SplitSubvariantProps, SplitSubvariantProviderProps, SplitSubvariantState, SplitSubvariantStore } from './types';
|
|
3
3
|
export declare const SplitSubvariantStoreContext: import("react").Context<SplitSubvariantStore | null>;
|
|
4
|
-
export declare function SplitSubvariantStoreProvider({ children, ...props }: SplitSubvariantProviderProps): JSX.Element;
|
|
4
|
+
export declare function SplitSubvariantStoreProvider({ children, ...props }: SplitSubvariantProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
5
5
|
export declare function useSplitSubvariantStore<T>(selector: (state: SplitSubvariantState) => T, equalityFn?: (left: T, right: T) => boolean): T;
|
|
6
6
|
export declare function useSplitSubvariantStoreContext(): SplitSubvariantStore;
|
|
7
7
|
export declare const createSplitSubvariantStore: ({ state }: SplitSubvariantProps) => import("zustand").UseBoundStore<import("zustand").StoreApi<SplitSubvariantState>>;
|