@lifi/widget 2.0.0-beta.1 → 2.0.0-beta.10
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 +4 -3
- package/AppDrawer.d.ts +1 -1
- package/AppDrawer.js +2 -1
- package/AppProvider.js +1 -1
- package/README.md +11 -12
- package/cjs/App.d.ts +4 -3
- package/cjs/AppDrawer.d.ts +1 -1
- package/cjs/AppDrawer.js +2 -1
- package/cjs/AppProvider.js +1 -1
- package/cjs/components/ChainSelect/ChainSelect.d.ts +1 -2
- package/cjs/components/ChainSelect/ChainSelect.style.js +1 -1
- package/cjs/components/ChainSelect/useChainSelect.js +6 -0
- package/cjs/components/GasMessage/FundsSufficiencyMessage.d.ts +1 -2
- package/cjs/components/GasMessage/GasMessage.js +1 -6
- package/cjs/components/Header/Header.js +2 -2
- package/cjs/components/Header/Header.style.d.ts +10 -3
- package/cjs/components/Header/Header.style.js +3 -0
- package/cjs/components/Header/NavigationHeader.js +23 -7
- package/cjs/components/Header/NavigationTabs.d.ts +1 -0
- package/cjs/components/Header/NavigationTabs.js +26 -0
- package/cjs/components/Header/NavigationTabs.style.d.ts +34 -0
- package/cjs/components/Header/NavigationTabs.style.js +61 -0
- package/cjs/components/Header/WalletHeader.d.ts +1 -0
- package/cjs/components/Header/WalletHeader.js +16 -9
- package/cjs/components/Header/useHeaderActionStore.js +0 -1
- package/cjs/components/Insurance/Insurance.js +2 -2
- package/cjs/components/Insurance/InsuranceCard.js +34 -12
- package/cjs/components/Insurance/InsuranceCollapsed.js +9 -11
- package/cjs/components/Insurance/index.d.ts +1 -0
- package/cjs/components/Insurance/index.js +1 -0
- package/cjs/components/Insurance/types.d.ts +12 -9
- package/cjs/components/NFT/NFT.js +2 -2
- package/cjs/components/NFT/types.d.ts +1 -1
- package/cjs/components/PoweredBy/PoweredBy.js +2 -3
- package/cjs/components/SelectChainAndToken.js +8 -7
- package/cjs/components/SelectTokenButton/SelectTokenButton.js +6 -3
- package/cjs/components/SendToWallet/SendToWallet.js +2 -2
- package/cjs/components/SmallAvatar.d.ts +1 -1
- package/cjs/components/Step/CircularProgress.d.ts +1 -2
- package/cjs/components/Step/Step.js +15 -5
- package/cjs/components/Step/StepList.d.ts +1 -2
- package/cjs/components/StepActions/StepActions.js +4 -20
- package/cjs/components/SwapButton/SwapButton.js +16 -4
- package/cjs/components/SwapInput/FormPriceHelperText.js +1 -1
- package/cjs/components/SwapInput/SwapInput.js +2 -2
- package/cjs/components/SwapInput/SwapInputEndAdornment.d.ts +1 -2
- package/cjs/components/SwapInput/SwapInputEndAdornment.js +2 -2
- package/cjs/components/SwapRouteCard/SwapRouteCard.js +19 -3
- package/cjs/components/SwapRouteCard/SwapRouteCardEssentials.js +1 -1
- package/cjs/components/SwapRouteCard/SwapRouteCardSkeleton.js +1 -1
- package/cjs/components/SwapRoutes/SwapRoutes.js +1 -1
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.d.ts +2 -3
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.js +2 -2
- package/cjs/components/SwapRoutes/SwapRoutesExpanded.style.js +1 -0
- package/cjs/components/Token/Token.js +1 -1
- package/cjs/components/TokenAvatar/TokenAvatar.d.ts +4 -4
- package/cjs/components/TokenList/TokenList.js +9 -4
- 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 +28 -5
- package/cjs/components/TokenList/VirtualizedTokenList.js +3 -3
- package/cjs/components/TokenList/types.d.ts +6 -3
- package/cjs/config/theme.js +15 -3
- package/cjs/config/version.d.ts +1 -1
- package/cjs/config/version.js +1 -1
- package/cjs/hooks/index.d.ts +2 -1
- package/cjs/hooks/index.js +2 -1
- package/cjs/hooks/useContentHeight.js +3 -5
- package/cjs/hooks/useFeaturedTokens.d.ts +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 +12 -3
- package/cjs/hooks/useInitializer.js +0 -1
- package/cjs/hooks/useProcessMessage.d.ts +2 -1
- package/cjs/hooks/useProcessMessage.js +27 -9
- package/cjs/hooks/useRouteExecution.js +6 -5
- package/cjs/hooks/useSwapOnly.d.ts +1 -0
- package/cjs/hooks/useSwapOnly.js +9 -0
- package/cjs/hooks/useSwapRoutes.d.ts +1 -2
- package/cjs/hooks/useSwapRoutes.js +32 -18
- package/cjs/hooks/useToken.d.ts +1 -1
- package/cjs/hooks/useTokenAddressBalance.d.ts +2 -2
- package/cjs/hooks/useTokenBalance.js +6 -7
- package/cjs/hooks/useTokenBalances.d.ts +5 -5
- package/cjs/hooks/useTokenBalances.js +4 -19
- package/cjs/hooks/useTokenSearch.d.ts +2 -2
- package/cjs/hooks/useTokens.d.ts +2 -2
- package/cjs/i18n/bn.json +8 -0
- package/cjs/i18n/en.json +30 -5
- package/cjs/i18n/fr.json +8 -0
- package/cjs/i18n/id.json +22 -7
- package/cjs/i18n/ko.json +22 -7
- package/cjs/i18n/pt.json +32 -7
- package/cjs/i18n/th.json +21 -6
- package/cjs/i18n/uk.json +43 -18
- package/cjs/i18n/zh.json +23 -8
- 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/index.d.ts +1 -1
- package/cjs/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +1 -2
- package/cjs/pages/SelectTokenPage/SearchTokenInput.d.ts +1 -2
- package/cjs/pages/SelectTokenPage/SelectTokenPage.js +3 -1
- package/cjs/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -2
- package/cjs/pages/SettingsPage/GasPriceSelect.d.ts +1 -2
- package/cjs/pages/SettingsPage/LanguageSelect.js +1 -1
- package/cjs/pages/SettingsPage/SettingsPage.d.ts +1 -2
- package/cjs/pages/SettingsPage/ShowDestinationWallet.d.ts +1 -2
- package/cjs/pages/SettingsPage/SlippageInput.d.ts +1 -2
- package/cjs/pages/SwapDetailsPage/SwapDetailsPage.js +6 -2
- package/cjs/pages/SwapPage/ExchangeRateBottomSheet.js +1 -1
- package/cjs/pages/SwapPage/StatusBottomSheet.js +15 -9
- package/cjs/pages/SwapPage/StatusBottomSheet.style.d.ts +1 -1
- package/cjs/pages/SwapPage/StatusBottomSheet.style.js +2 -2
- package/cjs/pages/SwapPage/SwapPage.js +31 -10
- package/cjs/pages/SwapPage/TokenValueBottomSheet.js +7 -12
- package/cjs/pages/SwapPage/utils.d.ts +2 -0
- package/cjs/pages/SwapPage/utils.js +10 -0
- package/cjs/providers/I18nProvider/I18nProvider.js +3 -3
- package/cjs/providers/SDKProvider/SDKProvider.js +2 -0
- package/cjs/providers/SwapFormProvider/FormUpdater.js +3 -0
- package/cjs/providers/WalletProvider/WalletProvider.js +77 -49
- package/cjs/providers/WalletProvider/types.d.ts +3 -5
- package/cjs/providers/WidgetProvider/WidgetProvider.js +1 -1
- package/cjs/stores/StoreProvider.d.ts +2 -2
- package/cjs/stores/StoreProvider.js +3 -2
- package/cjs/stores/routes/RouteExecutionStore.d.ts +1 -1
- package/cjs/stores/routes/RouteExecutionStore.js +0 -1
- package/cjs/stores/settings/index.d.ts +1 -0
- package/cjs/stores/settings/index.js +1 -0
- package/cjs/stores/settings/types.d.ts +11 -0
- package/cjs/stores/settings/useSplitSubvariantStore.d.ts +7 -0
- package/cjs/stores/settings/useSplitSubvariantStore.js +44 -0
- package/cjs/types/events.d.ts +9 -1
- package/cjs/types/events.js +1 -0
- package/cjs/types/token.d.ts +2 -2
- package/cjs/types/widget.d.ts +13 -8
- package/cjs/types/widget.js +4 -2
- package/cjs/utils/format.d.ts +1 -1
- package/cjs/utils/format.js +7 -12
- package/cjs/utils/wallet.d.ts +1 -1
- package/cjs/utils/wallet.js +3 -3
- package/components/ChainSelect/ChainSelect.d.ts +1 -2
- package/components/ChainSelect/ChainSelect.style.js +1 -1
- package/components/ChainSelect/useChainSelect.js +7 -1
- package/components/GasMessage/FundsSufficiencyMessage.d.ts +1 -2
- package/components/GasMessage/GasMessage.js +2 -7
- package/components/Header/Header.js +3 -3
- package/components/Header/Header.style.d.ts +10 -3
- package/components/Header/Header.style.js +3 -0
- package/components/Header/NavigationHeader.js +23 -7
- package/components/Header/NavigationTabs.d.ts +1 -0
- package/components/Header/NavigationTabs.js +22 -0
- package/components/Header/NavigationTabs.style.d.ts +34 -0
- package/components/Header/NavigationTabs.style.js +58 -0
- package/components/Header/WalletHeader.d.ts +1 -0
- package/components/Header/WalletHeader.js +14 -8
- package/components/Header/useHeaderActionStore.js +0 -1
- package/components/Insurance/Insurance.js +2 -2
- package/components/Insurance/InsuranceCard.js +37 -15
- package/components/Insurance/InsuranceCollapsed.js +9 -11
- package/components/Insurance/index.d.ts +1 -0
- package/components/Insurance/index.js +1 -0
- package/components/Insurance/types.d.ts +12 -9
- package/components/NFT/NFT.js +2 -2
- package/components/NFT/types.d.ts +1 -1
- package/components/PoweredBy/PoweredBy.js +2 -3
- package/components/SelectChainAndToken.js +9 -8
- package/components/SelectTokenButton/SelectTokenButton.js +7 -4
- package/components/SendToWallet/SendToWallet.js +2 -2
- package/components/SmallAvatar.d.ts +1 -1
- package/components/Step/CircularProgress.d.ts +1 -2
- package/components/Step/Step.js +16 -6
- package/components/Step/StepList.d.ts +1 -2
- package/components/StepActions/StepActions.js +4 -20
- package/components/SwapButton/SwapButton.js +16 -4
- package/components/SwapInput/FormPriceHelperText.js +2 -2
- package/components/SwapInput/SwapInput.js +3 -3
- package/components/SwapInput/SwapInputEndAdornment.d.ts +1 -2
- package/components/SwapInput/SwapInputEndAdornment.js +2 -2
- package/components/SwapRouteCard/SwapRouteCard.js +21 -5
- package/components/SwapRouteCard/SwapRouteCardEssentials.js +1 -1
- package/components/SwapRouteCard/SwapRouteCardSkeleton.js +1 -1
- package/components/SwapRoutes/SwapRoutes.js +1 -1
- package/components/SwapRoutes/SwapRoutesExpanded.d.ts +2 -3
- package/components/SwapRoutes/SwapRoutesExpanded.js +2 -2
- package/components/SwapRoutes/SwapRoutesExpanded.style.js +1 -0
- package/components/Token/Token.js +1 -1
- package/components/TokenAvatar/TokenAvatar.d.ts +4 -4
- package/components/TokenList/TokenList.js +10 -5
- 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 +32 -9
- package/components/TokenList/VirtualizedTokenList.js +3 -3
- package/components/TokenList/types.d.ts +6 -3
- package/config/theme.js +15 -3
- package/config/version.d.ts +1 -1
- package/config/version.js +1 -1
- package/hooks/index.d.ts +2 -1
- package/hooks/index.js +2 -1
- package/hooks/useContentHeight.js +4 -6
- package/hooks/useFeaturedTokens.d.ts +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 +13 -4
- package/hooks/useInitializer.js +0 -1
- package/hooks/useProcessMessage.d.ts +2 -1
- package/hooks/useProcessMessage.js +27 -9
- package/hooks/useRouteExecution.js +6 -5
- package/hooks/useSwapOnly.d.ts +1 -0
- package/hooks/useSwapOnly.js +5 -0
- package/hooks/useSwapRoutes.d.ts +1 -2
- package/hooks/useSwapRoutes.js +32 -18
- package/hooks/useToken.d.ts +1 -1
- package/hooks/useTokenAddressBalance.d.ts +2 -2
- package/hooks/useTokenBalance.js +6 -7
- package/hooks/useTokenBalances.d.ts +5 -5
- package/hooks/useTokenBalances.js +4 -19
- package/hooks/useTokenSearch.d.ts +2 -2
- package/hooks/useTokens.d.ts +2 -2
- package/i18n/bn.json +8 -0
- package/i18n/en.json +30 -5
- package/i18n/fr.json +8 -0
- package/i18n/id.json +22 -7
- package/i18n/ko.json +22 -7
- package/i18n/pt.json +32 -7
- package/i18n/th.json +21 -6
- package/i18n/uk.json +43 -18
- package/i18n/zh.json +23 -8
- 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/index.d.ts +1 -1
- package/package.json +13 -13
- package/pages/ActiveSwapsPage/ActiveSwapsPage.d.ts +1 -2
- package/pages/SelectTokenPage/SearchTokenInput.d.ts +1 -2
- package/pages/SelectTokenPage/SelectTokenPage.js +4 -2
- package/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -2
- package/pages/SettingsPage/GasPriceSelect.d.ts +1 -2
- package/pages/SettingsPage/LanguageSelect.js +1 -1
- package/pages/SettingsPage/SettingsPage.d.ts +1 -2
- package/pages/SettingsPage/ShowDestinationWallet.d.ts +1 -2
- package/pages/SettingsPage/SlippageInput.d.ts +1 -2
- package/pages/SwapDetailsPage/SwapDetailsPage.js +6 -2
- package/pages/SwapPage/ExchangeRateBottomSheet.js +2 -2
- package/pages/SwapPage/StatusBottomSheet.js +18 -12
- package/pages/SwapPage/StatusBottomSheet.style.d.ts +1 -1
- package/pages/SwapPage/StatusBottomSheet.style.js +1 -1
- package/pages/SwapPage/SwapPage.js +33 -12
- package/pages/SwapPage/TokenValueBottomSheet.js +8 -13
- package/pages/SwapPage/utils.d.ts +2 -0
- package/pages/SwapPage/utils.js +6 -0
- package/providers/I18nProvider/I18nProvider.js +3 -3
- package/providers/SDKProvider/SDKProvider.js +2 -0
- package/providers/SwapFormProvider/FormUpdater.js +3 -0
- package/providers/WalletProvider/WalletProvider.js +78 -50
- package/providers/WalletProvider/types.d.ts +3 -5
- package/providers/WidgetProvider/WidgetProvider.js +2 -2
- package/stores/StoreProvider.d.ts +2 -2
- package/stores/StoreProvider.js +3 -2
- package/stores/routes/RouteExecutionStore.d.ts +1 -1
- package/stores/routes/RouteExecutionStore.js +0 -1
- package/stores/settings/index.d.ts +1 -0
- package/stores/settings/index.js +1 -0
- package/stores/settings/types.d.ts +11 -0
- package/stores/settings/useSplitSubvariantStore.d.ts +7 -0
- package/stores/settings/useSplitSubvariantStore.js +37 -0
- package/tsconfig.cjs.tsbuildinfo +1 -1
- package/types/events.d.ts +9 -1
- package/types/events.js +1 -0
- package/types/token.d.ts +2 -2
- package/types/widget.d.ts +13 -8
- package/types/widget.js +4 -2
- package/utils/format.d.ts +1 -1
- package/utils/format.js +5 -10
- package/utils/wallet.d.ts +1 -1
- package/utils/wallet.js +1 -1
|
@@ -24,19 +24,6 @@ const WalletProvider = ({ children }) => {
|
|
|
24
24
|
const { walletManagement } = (0, WidgetProvider_1.useWidgetConfig)();
|
|
25
25
|
const [account, setAccount] = (0, react_1.useState)({});
|
|
26
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
27
|
const handleWalletUpdate = async (wallet) => {
|
|
41
28
|
setCurrentWallet(wallet);
|
|
42
29
|
const account = await (0, exports.extractAccountFromSigner)(wallet?.account?.signer);
|
|
@@ -64,54 +51,104 @@ const WalletProvider = ({ children }) => {
|
|
|
64
51
|
currentWallet.removeAllListeners();
|
|
65
52
|
handleWalletUpdate(undefined);
|
|
66
53
|
}
|
|
67
|
-
}, [
|
|
54
|
+
}, [currentWallet, walletManagement]);
|
|
68
55
|
const switchChain = (0, react_1.useCallback)(async (chainId) => {
|
|
69
|
-
if (walletManagement?.switchChain) {
|
|
70
|
-
const signer = await walletManagement.switchChain(chainId);
|
|
71
|
-
const account = await (0, exports.extractAccountFromSigner)(signer);
|
|
72
|
-
setAccount(account);
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
56
|
try {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
57
|
+
if (walletManagement?.switchChain) {
|
|
58
|
+
const signer = await walletManagement.switchChain(chainId);
|
|
59
|
+
const account = await (0, exports.extractAccountFromSigner)(signer);
|
|
60
|
+
setAccount(account);
|
|
61
|
+
return signer;
|
|
62
|
+
}
|
|
63
|
+
else if (!currentWallet) {
|
|
64
|
+
const provider = account.signer?.provider;
|
|
65
|
+
if (!provider) {
|
|
66
|
+
throw new Error(`Switch chain: No provider available`);
|
|
67
|
+
}
|
|
68
|
+
await (0, wallet_management_1.switchChain)(provider, chainId);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
await currentWallet?.switchChain(chainId);
|
|
72
|
+
handleWalletUpdate(currentWallet);
|
|
73
|
+
}
|
|
74
|
+
// TODO: this will fail if it's not created with ethers 'any' network, replace with the new signer when possible
|
|
75
|
+
return account.signer;
|
|
79
76
|
}
|
|
80
77
|
catch {
|
|
81
|
-
return
|
|
78
|
+
return account.signer;
|
|
82
79
|
}
|
|
83
|
-
}, [
|
|
80
|
+
}, [account.signer, currentWallet, walletManagement]);
|
|
84
81
|
const addChain = (0, react_1.useCallback)(async (chainId) => {
|
|
85
|
-
if (walletManagement?.addChain) {
|
|
86
|
-
return walletManagement.addChain(chainId);
|
|
87
|
-
}
|
|
88
82
|
try {
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
if (walletManagement?.addChain) {
|
|
84
|
+
return walletManagement.addChain(chainId);
|
|
85
|
+
}
|
|
86
|
+
else if (!currentWallet) {
|
|
87
|
+
const provider = account.signer?.provider;
|
|
88
|
+
if (!provider) {
|
|
89
|
+
throw new Error(`Add chain: No provider available`);
|
|
90
|
+
}
|
|
91
|
+
await (0, wallet_management_1.addChain)(provider, chainId);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
await currentWallet?.addChain(chainId);
|
|
95
|
+
handleWalletUpdate(currentWallet);
|
|
96
|
+
}
|
|
91
97
|
return true;
|
|
92
98
|
}
|
|
93
99
|
catch {
|
|
94
100
|
return false;
|
|
95
101
|
}
|
|
96
|
-
}, [
|
|
102
|
+
}, [account.signer?.provider, currentWallet, walletManagement]);
|
|
97
103
|
const addToken = (0, react_1.useCallback)(async (chainId, token) => {
|
|
98
|
-
|
|
99
|
-
|
|
104
|
+
try {
|
|
105
|
+
if (walletManagement?.addToken) {
|
|
106
|
+
return walletManagement.addToken(token, chainId);
|
|
107
|
+
}
|
|
108
|
+
else if (!currentWallet) {
|
|
109
|
+
const provider = account.signer?.provider;
|
|
110
|
+
if (!provider) {
|
|
111
|
+
throw new Error(`Add token: No provider available`);
|
|
112
|
+
}
|
|
113
|
+
await (0, wallet_management_1.switchChainAndAddToken)(provider, chainId, token);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
await currentWallet?.addToken(chainId, token);
|
|
117
|
+
handleWalletUpdate(currentWallet);
|
|
118
|
+
}
|
|
100
119
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
120
|
+
catch { }
|
|
121
|
+
}, [account.signer?.provider, currentWallet, walletManagement]);
|
|
122
|
+
(0, react_1.useEffect)(() => {
|
|
123
|
+
const autoConnect = async () => {
|
|
124
|
+
const persistedActiveWallets = (0, wallet_management_1.readActiveWallets)();
|
|
125
|
+
const activeWallets = wallet_management_1.supportedWallets.filter((wallet) => persistedActiveWallets.some((perstistedWallet) => perstistedWallet.name === wallet.name));
|
|
126
|
+
if (!activeWallets.length) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
await liFiWalletManagement.autoConnect(activeWallets);
|
|
130
|
+
activeWallets[0].on('walletAccountChanged', handleWalletUpdate);
|
|
131
|
+
handleWalletUpdate(activeWallets[0]);
|
|
132
|
+
};
|
|
133
|
+
autoConnect();
|
|
134
|
+
}, []);
|
|
105
135
|
// keep widget in sync with changing external signer object
|
|
106
136
|
(0, react_1.useEffect)(() => {
|
|
107
137
|
if (walletManagement) {
|
|
138
|
+
let ignore = false;
|
|
108
139
|
const updateAccount = async () => {
|
|
109
140
|
const account = await (0, exports.extractAccountFromSigner)(walletManagement?.signer);
|
|
110
|
-
|
|
141
|
+
// we should ignore the update if there is a newer one
|
|
142
|
+
if (!ignore) {
|
|
143
|
+
setAccount(account);
|
|
144
|
+
}
|
|
111
145
|
};
|
|
112
146
|
updateAccount();
|
|
147
|
+
return () => {
|
|
148
|
+
ignore = true;
|
|
149
|
+
};
|
|
113
150
|
}
|
|
114
|
-
}, [walletManagement
|
|
151
|
+
}, [walletManagement]);
|
|
115
152
|
const value = (0, react_1.useMemo)(() => ({
|
|
116
153
|
connect,
|
|
117
154
|
disconnect,
|
|
@@ -119,16 +156,7 @@ const WalletProvider = ({ children }) => {
|
|
|
119
156
|
addChain,
|
|
120
157
|
addToken,
|
|
121
158
|
account,
|
|
122
|
-
|
|
123
|
-
}), [
|
|
124
|
-
account,
|
|
125
|
-
addChain,
|
|
126
|
-
addToken,
|
|
127
|
-
connect,
|
|
128
|
-
disconnect,
|
|
129
|
-
currentWallet,
|
|
130
|
-
switchChain,
|
|
131
|
-
]);
|
|
159
|
+
}), [account, addChain, addToken, connect, disconnect, switchChain]);
|
|
132
160
|
return ((0, jsx_runtime_1.jsx)(WalletContext.Provider, { value: value, children: children }));
|
|
133
161
|
};
|
|
134
162
|
exports.WalletProvider = WalletProvider;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { Signer } from '@ethersproject/abstract-signer';
|
|
2
|
-
import type {
|
|
3
|
-
import type { Token } from '@lifi/sdk';
|
|
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
|
-
addToken(chainId: number, token:
|
|
7
|
+
addToken(chainId: number, token: StaticToken): Promise<void>;
|
|
10
8
|
disconnect(wallet?: Wallet): void;
|
|
11
|
-
switchChain(chainId: number): Promise<
|
|
9
|
+
switchChain(chainId: number): Promise<Signer | undefined>;
|
|
12
10
|
connect(wallet?: Wallet | undefined): Promise<void>;
|
|
13
11
|
}
|
|
14
12
|
export interface WalletAccount {
|
|
@@ -50,7 +50,7 @@ const WidgetProvider = ({ children, config: { fromChain, fromToken, toChain, toT
|
|
|
50
50
|
toToken: searchParams.toToken?.toLowerCase() || toToken?.toLowerCase(),
|
|
51
51
|
fromAmount: typeof searchParams.fromAmount === 'string' &&
|
|
52
52
|
!isNaN(parseFloat(searchParams.fromAmount))
|
|
53
|
-
? (0, utils_1.
|
|
53
|
+
? (0, utils_1.formatInputAmount)(searchParams.fromAmount)
|
|
54
54
|
: fromAmount,
|
|
55
55
|
elementId,
|
|
56
56
|
integrator,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { PropsWithChildren } from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const StoreProvider: React.FC<PropsWithChildren<
|
|
2
|
+
import type { WidgetConfigProps } from '../types';
|
|
3
|
+
export declare const StoreProvider: React.FC<PropsWithChildren<WidgetConfigProps>>;
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.StoreProvider = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const routes_1 = require("./routes");
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const settings_1 = require("./settings");
|
|
7
|
+
const StoreProvider = ({ children, config, }) => {
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(settings_1.SplitSubvariantStoreProvider, { state: config.subvariant === 'split' ? 'swap' : undefined, children: (0, jsx_runtime_1.jsx)(routes_1.RouteExecutionStoreProvider, { namePrefix: config?.localStorageKeyPrefix, children: children }) }));
|
|
8
9
|
};
|
|
9
10
|
exports.StoreProvider = StoreProvider;
|
|
@@ -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;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useRouteExecutionStoreContext = exports.useRouteExecutionStore = exports.RouteExecutionStoreProvider = exports.RouteExecutionStoreContext = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
/* eslint-disable no-underscore-dangle */
|
|
6
5
|
const react_1 = require("react");
|
|
7
6
|
const createRouteExecutionStore_1 = require("./createRouteExecutionStore");
|
|
8
7
|
exports.RouteExecutionStoreContext = (0, react_1.createContext)(null);
|
|
@@ -19,3 +19,4 @@ __exportStar(require("./useAppearance"), exports);
|
|
|
19
19
|
__exportStar(require("./useSendToWalletStore"), exports);
|
|
20
20
|
__exportStar(require("./useSettings"), exports);
|
|
21
21
|
__exportStar(require("./useSettingsStore"), exports);
|
|
22
|
+
__exportStar(require("./useSplitSubvariantStore"), exports);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Order } from '@lifi/sdk';
|
|
2
|
+
import type { PropsWithChildren } from 'react';
|
|
3
|
+
import type { StoreApi, UseBoundStore } from 'zustand';
|
|
2
4
|
import type { Appearance, WidgetConfig } from '../../types';
|
|
3
5
|
export type ValueSetter<S> = <K extends keyof S>(key: K, value: S[Extract<K, string>]) => void;
|
|
4
6
|
export type ValuesSetter<S> = <K extends keyof S>(values: Record<K, S[Extract<K, string>]>) => void;
|
|
@@ -32,3 +34,12 @@ export interface SendToWalletStore extends SendToWalletState {
|
|
|
32
34
|
toggleSendToWallet(): void;
|
|
33
35
|
setSendToWallet(value: boolean): void;
|
|
34
36
|
}
|
|
37
|
+
export interface SplitSubvariantState {
|
|
38
|
+
state?: 'swap' | 'bridge';
|
|
39
|
+
setState(state: 'swap' | 'bridge'): void;
|
|
40
|
+
}
|
|
41
|
+
export type SplitSubvariantStore = UseBoundStore<StoreApi<SplitSubvariantState>>;
|
|
42
|
+
export interface SplitSubvariantProps {
|
|
43
|
+
state?: 'swap' | 'bridge';
|
|
44
|
+
}
|
|
45
|
+
export type SplitSubvariantProviderProps = PropsWithChildren<SplitSubvariantProps>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { SplitSubvariantProps, SplitSubvariantProviderProps, SplitSubvariantState, SplitSubvariantStore } from './types';
|
|
3
|
+
export declare const SplitSubvariantStoreContext: import("react").Context<SplitSubvariantStore | null>;
|
|
4
|
+
export declare function SplitSubvariantStoreProvider({ children, ...props }: SplitSubvariantProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare function useSplitSubvariantStore<T>(selector: (state: SplitSubvariantState) => T, equalityFn?: (left: T, right: T) => boolean): T;
|
|
6
|
+
export declare function useSplitSubvariantStoreContext(): SplitSubvariantStore;
|
|
7
|
+
export declare const createSplitSubvariantStore: ({ state }: SplitSubvariantProps) => import("zustand").UseBoundStore<import("zustand").StoreApi<SplitSubvariantState>>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSplitSubvariantStore = exports.useSplitSubvariantStoreContext = exports.useSplitSubvariantStore = exports.SplitSubvariantStoreProvider = exports.SplitSubvariantStoreContext = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const zustand_1 = require("zustand");
|
|
7
|
+
exports.SplitSubvariantStoreContext = (0, react_1.createContext)(null);
|
|
8
|
+
const shouldRecreateStore = (store, props) => {
|
|
9
|
+
const { state } = store.getState();
|
|
10
|
+
return (!state && props.state) || (state && !props.state);
|
|
11
|
+
};
|
|
12
|
+
function SplitSubvariantStoreProvider({ children, ...props }) {
|
|
13
|
+
const storeRef = (0, react_1.useRef)();
|
|
14
|
+
if (!storeRef.current || shouldRecreateStore(storeRef.current, props)) {
|
|
15
|
+
storeRef.current = (0, exports.createSplitSubvariantStore)(props);
|
|
16
|
+
}
|
|
17
|
+
return ((0, jsx_runtime_1.jsx)(exports.SplitSubvariantStoreContext.Provider, { value: storeRef.current, children: children }));
|
|
18
|
+
}
|
|
19
|
+
exports.SplitSubvariantStoreProvider = SplitSubvariantStoreProvider;
|
|
20
|
+
function useSplitSubvariantStore(selector, equalityFn) {
|
|
21
|
+
const useStore = (0, react_1.useContext)(exports.SplitSubvariantStoreContext);
|
|
22
|
+
if (!useStore) {
|
|
23
|
+
throw new Error(`You forgot to wrap your component in <${SplitSubvariantStoreProvider.name}>.`);
|
|
24
|
+
}
|
|
25
|
+
return useStore(selector, equalityFn);
|
|
26
|
+
}
|
|
27
|
+
exports.useSplitSubvariantStore = useSplitSubvariantStore;
|
|
28
|
+
function useSplitSubvariantStoreContext() {
|
|
29
|
+
const useStore = (0, react_1.useContext)(exports.SplitSubvariantStoreContext);
|
|
30
|
+
if (!useStore) {
|
|
31
|
+
throw new Error(`You forgot to wrap your component in <${SplitSubvariantStoreProvider.name}>.`);
|
|
32
|
+
}
|
|
33
|
+
return useStore;
|
|
34
|
+
}
|
|
35
|
+
exports.useSplitSubvariantStoreContext = useSplitSubvariantStoreContext;
|
|
36
|
+
const createSplitSubvariantStore = ({ state }) => (0, zustand_1.create)((set) => ({
|
|
37
|
+
state,
|
|
38
|
+
setState(state) {
|
|
39
|
+
set(() => ({
|
|
40
|
+
state,
|
|
41
|
+
}));
|
|
42
|
+
},
|
|
43
|
+
}));
|
|
44
|
+
exports.createSplitSubvariantStore = createSplitSubvariantStore;
|
package/cjs/types/events.d.ts
CHANGED
|
@@ -3,13 +3,21 @@ export declare enum WidgetEvent {
|
|
|
3
3
|
RouteExecutionStarted = "routeExecutionStarted",
|
|
4
4
|
RouteExecutionUpdated = "routeExecutionUpdated",
|
|
5
5
|
RouteExecutionCompleted = "routeExecutionCompleted",
|
|
6
|
-
RouteExecutionFailed = "routeExecutionFailed"
|
|
6
|
+
RouteExecutionFailed = "routeExecutionFailed",
|
|
7
|
+
RouteHighValueLoss = "routeHighValueLoss"
|
|
8
|
+
}
|
|
9
|
+
export interface RouteHighValueLossUpdate {
|
|
10
|
+
fromAmountUsd: string;
|
|
11
|
+
gasCostUSD: string | undefined;
|
|
12
|
+
toAmountUSD: string;
|
|
13
|
+
valueLoss: string;
|
|
7
14
|
}
|
|
8
15
|
export type WidgetEvents = {
|
|
9
16
|
routeExecutionStarted: Route;
|
|
10
17
|
routeExecutionUpdated: RouteExecutionUpdate;
|
|
11
18
|
routeExecutionCompleted: Route;
|
|
12
19
|
routeExecutionFailed: RouteExecutionUpdate;
|
|
20
|
+
routeHighValueLoss: RouteHighValueLossUpdate;
|
|
13
21
|
};
|
|
14
22
|
export interface RouteExecutionUpdate {
|
|
15
23
|
route: Route;
|
package/cjs/types/events.js
CHANGED
|
@@ -7,4 +7,5 @@ var WidgetEvent;
|
|
|
7
7
|
WidgetEvent["RouteExecutionUpdated"] = "routeExecutionUpdated";
|
|
8
8
|
WidgetEvent["RouteExecutionCompleted"] = "routeExecutionCompleted";
|
|
9
9
|
WidgetEvent["RouteExecutionFailed"] = "routeExecutionFailed";
|
|
10
|
+
WidgetEvent["RouteHighValueLoss"] = "routeHighValueLoss";
|
|
10
11
|
})(WidgetEvent = exports.WidgetEvent || (exports.WidgetEvent = {}));
|
package/cjs/types/token.d.ts
CHANGED
package/cjs/types/widget.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Signer } from '@ethersproject/abstract-signer';
|
|
2
|
-
import type { ChainKey, ConfigUpdate, Order, RouteOptions,
|
|
2
|
+
import type { BaseToken, ChainKey, ConfigUpdate, Order, RouteOptions, StaticToken } from '@lifi/sdk';
|
|
3
3
|
import type { Components, PaletteMode, PaletteOptions, Shape, Theme } from '@mui/material';
|
|
4
4
|
import type { TypographyOptions } from '@mui/material/styles/createTypography';
|
|
5
5
|
import type { CSSProperties, ReactNode, RefObject } from 'react';
|
|
6
6
|
import type { LanguageKey, LanguageResources } from '../providers';
|
|
7
7
|
export type WidgetVariant = 'default' | 'expandable' | 'drawer' | 'refuel' | 'nft';
|
|
8
|
+
export type WidgetSubvariant = 'default' | 'split';
|
|
8
9
|
export declare enum DisabledUI {
|
|
9
10
|
FromAmount = "fromAmount",
|
|
10
11
|
FromToken = "fromToken",
|
|
@@ -14,9 +15,13 @@ export declare enum DisabledUI {
|
|
|
14
15
|
export type DisabledUIType = `${DisabledUI}`;
|
|
15
16
|
export declare enum HiddenUI {
|
|
16
17
|
Appearance = "appearance",
|
|
18
|
+
DrawerButton = "drawerButton",
|
|
19
|
+
History = "history",
|
|
17
20
|
Language = "language",
|
|
18
21
|
PoweredBy = "poweredBy",
|
|
19
|
-
ToAddress = "toAddress"
|
|
22
|
+
ToAddress = "toAddress",
|
|
23
|
+
ToToken = "toToken",
|
|
24
|
+
WalletMenu = "walletMenu"
|
|
20
25
|
}
|
|
21
26
|
export type HiddenUIType = `${HiddenUI}`;
|
|
22
27
|
export declare enum RequiredUI {
|
|
@@ -34,7 +39,7 @@ export interface WidgetWalletManagement {
|
|
|
34
39
|
connect(): Promise<Signer>;
|
|
35
40
|
disconnect(): Promise<void>;
|
|
36
41
|
switchChain?(chainId: number): Promise<Signer>;
|
|
37
|
-
addToken?(token:
|
|
42
|
+
addToken?(token: StaticToken, chainId: number): Promise<void>;
|
|
38
43
|
addChain?(chainId: number): Promise<boolean>;
|
|
39
44
|
signer?: Signer;
|
|
40
45
|
}
|
|
@@ -72,10 +77,10 @@ export interface WidgetConfig {
|
|
|
72
77
|
slippage?: number;
|
|
73
78
|
insurance?: boolean;
|
|
74
79
|
variant?: WidgetVariant;
|
|
80
|
+
subvariant?: WidgetSubvariant;
|
|
75
81
|
appearance?: Appearance;
|
|
76
82
|
theme?: ThemeConfig;
|
|
77
83
|
containerStyle?: CSSProperties;
|
|
78
|
-
disableTelemetry?: boolean;
|
|
79
84
|
disabledUI?: DisabledUIType[];
|
|
80
85
|
hiddenUI?: HiddenUIType[];
|
|
81
86
|
requiredUI?: RequiredUIType[];
|
|
@@ -97,9 +102,9 @@ export interface WidgetConfig {
|
|
|
97
102
|
deny?: number[];
|
|
98
103
|
};
|
|
99
104
|
tokens?: {
|
|
100
|
-
featured?:
|
|
101
|
-
allow?:
|
|
102
|
-
deny?:
|
|
105
|
+
featured?: StaticToken[];
|
|
106
|
+
allow?: BaseToken[];
|
|
107
|
+
deny?: BaseToken[];
|
|
103
108
|
};
|
|
104
109
|
languages?: {
|
|
105
110
|
default?: LanguageKey;
|
|
@@ -107,7 +112,7 @@ export interface WidgetConfig {
|
|
|
107
112
|
deny?: LanguageKey[];
|
|
108
113
|
};
|
|
109
114
|
languageResources?: LanguageResources;
|
|
110
|
-
|
|
115
|
+
disableLanguageDetector?: boolean;
|
|
111
116
|
}
|
|
112
117
|
export type WidgetDrawerProps = {
|
|
113
118
|
elementRef?: RefObject<HTMLDivElement>;
|
package/cjs/types/widget.js
CHANGED
|
@@ -11,11 +11,13 @@ var DisabledUI;
|
|
|
11
11
|
var HiddenUI;
|
|
12
12
|
(function (HiddenUI) {
|
|
13
13
|
HiddenUI["Appearance"] = "appearance";
|
|
14
|
-
|
|
14
|
+
HiddenUI["DrawerButton"] = "drawerButton";
|
|
15
|
+
HiddenUI["History"] = "history";
|
|
15
16
|
HiddenUI["Language"] = "language";
|
|
16
17
|
HiddenUI["PoweredBy"] = "poweredBy";
|
|
17
18
|
HiddenUI["ToAddress"] = "toAddress";
|
|
18
|
-
|
|
19
|
+
HiddenUI["ToToken"] = "toToken";
|
|
20
|
+
HiddenUI["WalletMenu"] = "walletMenu";
|
|
19
21
|
})(HiddenUI = exports.HiddenUI || (exports.HiddenUI = {}));
|
|
20
22
|
var RequiredUI;
|
|
21
23
|
(function (RequiredUI) {
|
package/cjs/utils/format.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export declare const formatTokenAmount: (amount?: string, decimals?: number, decimalPlaces?: number) => string;
|
|
7
7
|
export declare const formatSlippage: (slippage?: string, defaultValue?: string, returnInitial?: boolean) => string;
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const formatInputAmount: (amount: string, returnInitial?: boolean) => string;
|
|
9
9
|
export declare const formatTokenPrice: (amount?: string, price?: string) => number;
|
package/cjs/utils/format.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatTokenPrice = exports.
|
|
3
|
+
exports.formatTokenPrice = exports.formatInputAmount = exports.formatSlippage = exports.formatTokenAmount = void 0;
|
|
4
4
|
const big_js_1 = require("big.js");
|
|
5
5
|
// JavaScript numbers use exponential notation for positive exponents of 21 and above. We need more.
|
|
6
6
|
big_js_1.default.PE = 42;
|
|
@@ -24,7 +24,7 @@ const formatTokenAmount = (amount = '0', decimals = 0, decimalPlaces = 3) => {
|
|
|
24
24
|
while (absAmount < 1 / 10 ** decimalPlaces) {
|
|
25
25
|
decimalPlaces++;
|
|
26
26
|
}
|
|
27
|
-
return (0, big_js_1.default)(
|
|
27
|
+
return (0, big_js_1.default)(parsedAmount).toFixed(decimalPlaces + 1, 0);
|
|
28
28
|
};
|
|
29
29
|
exports.formatTokenAmount = formatTokenAmount;
|
|
30
30
|
const formatSlippage = (slippage = '', defaultValue = '', returnInitial = false) => {
|
|
@@ -50,7 +50,7 @@ const formatSlippage = (slippage = '', defaultValue = '', returnInitial = false)
|
|
|
50
50
|
return parsedSlippage.toString();
|
|
51
51
|
};
|
|
52
52
|
exports.formatSlippage = formatSlippage;
|
|
53
|
-
const
|
|
53
|
+
const formatInputAmount = (amount, returnInitial = false) => {
|
|
54
54
|
if (!amount) {
|
|
55
55
|
return amount;
|
|
56
56
|
}
|
|
@@ -62,23 +62,18 @@ const formatAmount = (amount = '', returnInitial = false) => {
|
|
|
62
62
|
if (isNaN(Number(formattedAmount)) && !isNaN(parsedAmount)) {
|
|
63
63
|
return parsedAmount.toString();
|
|
64
64
|
}
|
|
65
|
-
if (isNaN(parsedAmount)) {
|
|
66
|
-
return '';
|
|
67
|
-
}
|
|
68
|
-
if (parsedAmount < 0) {
|
|
69
|
-
return Math.abs(parsedAmount).toString();
|
|
70
|
-
}
|
|
71
65
|
try {
|
|
72
|
-
|
|
66
|
+
const absFormattedAmount = (0, big_js_1.default)(formattedAmount).abs();
|
|
67
|
+
if (returnInitial) {
|
|
73
68
|
return formattedAmount;
|
|
74
69
|
}
|
|
70
|
+
return absFormattedAmount.toString();
|
|
75
71
|
}
|
|
76
72
|
catch {
|
|
77
73
|
return '';
|
|
78
74
|
}
|
|
79
|
-
return (0, big_js_1.default)(parsedAmount).toString();
|
|
80
75
|
};
|
|
81
|
-
exports.
|
|
76
|
+
exports.formatInputAmount = formatInputAmount;
|
|
82
77
|
const formatTokenPrice = (amount, price) => {
|
|
83
78
|
if (!amount || !price) {
|
|
84
79
|
return 0;
|
package/cjs/utils/wallet.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const shortenAddress: (address?: string) => string | null;
|
package/cjs/utils/wallet.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.shortenAddress = void 0;
|
|
4
|
+
const shortenAddress = (address) => address
|
|
5
5
|
? `${address.substring(0, 5)}...${address.substring(address.length - 4)}`
|
|
6
6
|
: null;
|
|
7
|
-
exports.
|
|
7
|
+
exports.shortenAddress = shortenAddress;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { SwapFormTypeProps } from '../../providers';
|
|
3
|
-
export declare const ChainSelect: ({ formType }: SwapFormTypeProps) => JSX.Element;
|
|
2
|
+
export declare const ChainSelect: ({ formType }: SwapFormTypeProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -9,7 +9,7 @@ export const ChainCard = styled(Card)({
|
|
|
9
9
|
});
|
|
10
10
|
export const ChainContainer = styled(Box)(({ theme }) => ({
|
|
11
11
|
display: 'grid',
|
|
12
|
-
gridTemplateColumns: 'repeat(
|
|
12
|
+
gridTemplateColumns: 'repeat(auto-fit, minmax(52px, 1fr))',
|
|
13
13
|
gridAutoRows: '56px',
|
|
14
14
|
justifyContent: 'space-between',
|
|
15
15
|
gap: theme.spacing(1.5),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useController, useFormContext } from 'react-hook-form';
|
|
2
|
-
import { useChains } from '../../hooks';
|
|
2
|
+
import { useChains, useSwapOnly } from '../../hooks';
|
|
3
3
|
import { SwapFormKey, SwapFormKeyHelper } from '../../providers';
|
|
4
4
|
import { useChainOrder } from '../../stores';
|
|
5
5
|
export const useChainSelect = (formType) => {
|
|
@@ -8,6 +8,7 @@ export const useChainSelect = (formType) => {
|
|
|
8
8
|
const { setValue } = useFormContext();
|
|
9
9
|
const { chains, isLoading } = useChains();
|
|
10
10
|
const [chainOrder, setChainOrder] = useChainOrder();
|
|
11
|
+
const swapOnly = useSwapOnly();
|
|
11
12
|
const getChains = () => {
|
|
12
13
|
if (!chains) {
|
|
13
14
|
return [];
|
|
@@ -20,6 +21,11 @@ export const useChainSelect = (formType) => {
|
|
|
20
21
|
const setCurrentChain = (chainId) => {
|
|
21
22
|
onChange(chainId);
|
|
22
23
|
onBlur();
|
|
24
|
+
if (swapOnly) {
|
|
25
|
+
setValue(SwapFormKeyHelper.getChainKey('to'), chainId, {
|
|
26
|
+
shouldTouch: true,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
23
29
|
setValue(SwapFormKeyHelper.getTokenKey(formType), '');
|
|
24
30
|
setValue(SwapFormKeyHelper.getAmountKey(formType), '');
|
|
25
31
|
setValue(SwapFormKey.TokenSearchFilter, '');
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const FundsSufficiencyMessage: () => JSX.Element;
|
|
1
|
+
export declare const FundsSufficiencyMessage: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Collapse } from '@mui/material';
|
|
3
|
-
import { useFundsSufficiency,
|
|
4
|
-
import { useSettings } from '../../stores';
|
|
3
|
+
import { useFundsSufficiency, useGasSufficiency } from '../../hooks';
|
|
5
4
|
import { FundsSufficiencyMessage } from './FundsSufficiencyMessage';
|
|
6
5
|
import { GasSufficiencyMessage } from './GasSufficiencyMessage';
|
|
7
6
|
export const GasMessage = ({ route, ...props }) => {
|
|
8
7
|
const { insufficientGas } = useGasSufficiency(route);
|
|
9
8
|
const { insufficientFunds } = useFundsSufficiency(route);
|
|
10
|
-
|
|
11
|
-
const { enabled, isLoading: isRefuelLoading } = useGasRefuel();
|
|
12
|
-
const enabledRefuel = enabled && enabledAutoRefuel;
|
|
13
|
-
const showGasSufficiencyMessage = insufficientGas?.length && !isRefuelLoading && !enabledRefuel;
|
|
14
|
-
return (_jsx(Collapse, { timeout: 225, in: Boolean(insufficientFunds || showGasSufficiencyMessage), unmountOnExit: true, mountOnEnter: true, children: _jsx(Box, { ...props, children: insufficientFunds ? (_jsx(FundsSufficiencyMessage, {})) : showGasSufficiencyMessage ? (_jsx(GasSufficiencyMessage, { insufficientGas: insufficientGas })) : null }) }));
|
|
9
|
+
return (_jsx(Collapse, { timeout: 225, in: Boolean(insufficientFunds || insufficientGas?.length), unmountOnExit: true, mountOnEnter: true, children: _jsx(Box, { ...props, children: insufficientFunds ? (_jsx(FundsSufficiencyMessage, {})) : insufficientGas?.length ? (_jsx(GasSufficiencyMessage, { insufficientGas: insufficientGas })) : null }) }));
|
|
15
10
|
};
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useLocation } from 'react-router-dom';
|
|
3
3
|
import { useDefaultElementId } from '../../hooks';
|
|
4
4
|
import { useWidgetConfig } from '../../providers';
|
|
5
|
-
import {
|
|
5
|
+
import { ElementId, createElementId, stickyHeaderRoutes } from '../../utils';
|
|
6
6
|
import { Container } from './Header.style';
|
|
7
7
|
import { NavigationHeader } from './NavigationHeader';
|
|
8
8
|
import { WalletHeader } from './WalletHeader';
|
|
@@ -12,6 +12,6 @@ export const HeaderContainer = ({ children }) => {
|
|
|
12
12
|
return (_jsx(Container, { id: createElementId(ElementId.Header, elementId), sticky: stickyHeaderRoutes.some((route) => pathname.includes(route)), children: children }));
|
|
13
13
|
};
|
|
14
14
|
export const Header = () => {
|
|
15
|
-
const { walletManagement } = useWidgetConfig();
|
|
16
|
-
return (_jsxs(HeaderContainer, { children: [!walletManagement ? _jsx(WalletHeader, {}) : null, _jsx(NavigationHeader, {})] }));
|
|
15
|
+
const { walletManagement, subvariant } = useWidgetConfig();
|
|
16
|
+
return (_jsxs(HeaderContainer, { children: [!walletManagement && subvariant !== 'split' ? _jsx(WalletHeader, {}) : null, _jsx(NavigationHeader, {})] }));
|
|
17
17
|
};
|