@lifi/widget 1.0.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/App.d.ts +4 -0
- package/App.js +18 -0
- package/AppDrawer.d.ts +14 -0
- package/AppDrawer.js +34 -0
- package/AppDrawer.style.d.ts +49 -0
- package/AppDrawer.style.js +52 -0
- package/AppProvider.d.ts +6 -0
- package/AppProvider.js +12 -0
- package/LICENSE.md +21 -0
- package/components/AppContainer.d.ts +5 -0
- package/components/AppContainer.js +53 -0
- package/components/BottomSheet/BottomSheet.d.ts +3 -0
- package/components/BottomSheet/BottomSheet.js +42 -0
- package/components/BottomSheet/index.d.ts +2 -0
- package/components/BottomSheet/index.js +2 -0
- package/components/BottomSheet/types.d.ts +10 -0
- package/components/BottomSheet/types.js +1 -0
- package/components/Card/Card.d.ts +8 -0
- package/components/Card/Card.js +8 -0
- package/components/Card/CardContainer.d.ts +11 -0
- package/components/Card/CardContainer.js +16 -0
- package/components/Card/CardHeader.d.ts +18 -0
- package/components/Card/CardHeader.js +20 -0
- package/components/Card/CardTitle.d.ts +14 -0
- package/components/Card/CardTitle.js +9 -0
- package/components/Card/index.d.ts +4 -0
- package/components/Card/index.js +4 -0
- package/components/Header/Header.d.ts +2 -0
- package/components/Header/Header.js +17 -0
- package/components/Header/Header.style.d.ts +22 -0
- package/components/Header/Header.style.js +21 -0
- package/components/Header/NavigationHeader.d.ts +2 -0
- package/components/Header/NavigationHeader.js +46 -0
- package/components/Header/WalletHeader.d.ts +2 -0
- package/components/Header/WalletHeader.js +28 -0
- package/components/Header/index.d.ts +1 -0
- package/components/Header/index.js +1 -0
- package/components/Input.d.ts +1 -0
- package/components/Input.js +14 -0
- package/components/LiFiLogo.d.ts +5 -0
- package/components/LiFiLogo.js +7 -0
- package/components/PoweredBy.d.ts +2 -0
- package/components/PoweredBy.js +14 -0
- package/components/ProgressToNextUpdate/ProgressToNextUpdate.d.ts +7 -0
- package/components/ProgressToNextUpdate/ProgressToNextUpdate.js +49 -0
- package/components/ProgressToNextUpdate/index.d.ts +1 -0
- package/components/ProgressToNextUpdate/index.js +1 -0
- package/components/ReverseTokensButton/ReverseTokensButton.d.ts +4 -0
- package/components/ReverseTokensButton/ReverseTokensButton.js +24 -0
- package/components/ReverseTokensButton/ReverseTokensButton.style.d.ts +29 -0
- package/components/ReverseTokensButton/ReverseTokensButton.style.js +14 -0
- package/components/ReverseTokensButton/index.d.ts +1 -0
- package/components/ReverseTokensButton/index.js +1 -0
- package/components/Select.d.ts +3 -0
- package/components/Select.js +27 -0
- package/components/SelectChainAndToken.d.ts +3 -0
- package/components/SelectChainAndToken.js +19 -0
- package/components/SelectTokenButton/SelectTokenButton.d.ts +5 -0
- package/components/SelectTokenButton/SelectTokenButton.js +29 -0
- package/components/SelectTokenButton/SelectTokenButton.style.d.ts +28 -0
- package/components/SelectTokenButton/SelectTokenButton.style.js +31 -0
- package/components/SelectTokenButton/index.d.ts +1 -0
- package/components/SelectTokenButton/index.js +1 -0
- package/components/StepActions/StepActions.d.ts +13 -0
- package/components/StepActions/StepActions.js +49 -0
- package/components/StepActions/StepActions.style.d.ts +20 -0
- package/components/StepActions/StepActions.style.js +56 -0
- package/components/StepActions/index.d.ts +1 -0
- package/components/StepActions/index.js +1 -0
- package/components/StepActions/types.d.ts +6 -0
- package/components/StepActions/types.js +1 -0
- package/components/StepToken.d.ts +6 -0
- package/components/StepToken.js +21 -0
- package/components/SwapButton/ButtonTooltip.d.ts +4 -0
- package/components/SwapButton/ButtonTooltip.js +3 -0
- package/components/SwapButton/SwapButton.d.ts +2 -0
- package/components/SwapButton/SwapButton.js +77 -0
- package/components/SwapButton/SwapButton.style.d.ts +65 -0
- package/components/SwapButton/SwapButton.style.js +20 -0
- package/components/SwapButton/index.d.ts +1 -0
- package/components/SwapButton/index.js +1 -0
- package/components/SwapInProgress/SwapInProgress.d.ts +3 -0
- package/components/SwapInProgress/SwapInProgress.js +22 -0
- package/components/SwapInProgress/SwapInProgress.style.d.ts +43 -0
- package/components/SwapInProgress/SwapInProgress.style.js +15 -0
- package/components/SwapInProgress/index.d.ts +1 -0
- package/components/SwapInProgress/index.js +1 -0
- package/components/SwapInput/FormPriceHelperText.d.ts +5 -0
- package/components/SwapInput/FormPriceHelperText.js +27 -0
- package/components/SwapInput/SwapInput.d.ts +3 -0
- package/components/SwapInput/SwapInput.js +43 -0
- package/components/SwapInput/SwapInput.style.d.ts +21 -0
- package/components/SwapInput/SwapInput.style.js +30 -0
- package/components/SwapInput/SwapInputAdornment.d.ts +2 -0
- package/components/SwapInput/SwapInputAdornment.js +23 -0
- package/components/SwapInput/SwapInputAdornment.style.d.ts +34 -0
- package/components/SwapInput/SwapInputAdornment.style.js +22 -0
- package/components/SwapInput/index.d.ts +1 -0
- package/components/SwapInput/index.js +1 -0
- package/components/SwapRouteCard/SwapRouteCard.d.ts +4 -0
- package/components/SwapRouteCard/SwapRouteCard.js +34 -0
- package/components/SwapRouteCard/SwapRouteCard.style.d.ts +36 -0
- package/components/SwapRouteCard/SwapRouteCard.style.js +71 -0
- package/components/SwapRouteCard/index.d.ts +1 -0
- package/components/SwapRouteCard/index.js +1 -0
- package/components/SwapRouteCard/types.d.ts +7 -0
- package/components/SwapRouteCard/types.js +1 -0
- package/components/SwapRoutes/SwapRoutes.d.ts +3 -0
- package/components/SwapRoutes/SwapRoutes.js +33 -0
- package/components/SwapRoutes/SwapRoutes.style.d.ts +11 -0
- package/components/SwapRoutes/SwapRoutes.style.js +9 -0
- package/components/SwapRoutes/SwapRoutesUpdateProgress.d.ts +3 -0
- package/components/SwapRoutes/SwapRoutesUpdateProgress.js +24 -0
- package/components/SwapRoutes/index.d.ts +1 -0
- package/components/SwapRoutes/index.js +1 -0
- package/components/Switch.d.ts +1 -0
- package/components/Switch.js +53 -0
- package/components/TextFitter/TextFitter.d.ts +3 -0
- package/components/TextFitter/TextFitter.js +44 -0
- package/components/TextFitter/index.d.ts +1 -0
- package/components/TextFitter/index.js +1 -0
- package/components/TextFitter/types.d.ts +12 -0
- package/components/TextFitter/types.js +1 -0
- package/components/TokenList/TokenList.d.ts +3 -0
- package/components/TokenList/TokenList.js +58 -0
- package/components/TokenList/TokenList.style.d.ts +32 -0
- package/components/TokenList/TokenList.style.js +22 -0
- package/components/TokenList/TokenListItem.d.ts +4 -0
- package/components/TokenList/TokenListItem.js +24 -0
- package/components/TokenList/index.d.ts +1 -0
- package/components/TokenList/index.js +1 -0
- package/components/TokenList/types.d.ts +16 -0
- package/components/TokenList/types.js +1 -0
- package/components/TokenList/utils.d.ts +15 -0
- package/components/TokenList/utils.js +10 -0
- package/config/env.d.ts +12 -0
- package/config/env.js +19 -0
- package/config/queryClient.d.ts +2 -0
- package/config/queryClient.js +25 -0
- package/config/rpcs.d.ts +1 -0
- package/config/rpcs.js +20 -0
- package/config/theme.d.ts +27 -0
- package/config/theme.js +126 -0
- package/hooks/index.d.ts +15 -0
- package/hooks/index.js +15 -0
- package/hooks/useBridges.d.ts +1 -0
- package/hooks/useBridges.js +12 -0
- package/hooks/useChain.d.ts +4 -0
- package/hooks/useChain.js +13 -0
- package/hooks/useChains.d.ts +101 -0
- package/hooks/useChains.js +39 -0
- package/hooks/useContentHeight.d.ts +1 -0
- package/hooks/useContentHeight.js +15 -0
- package/hooks/useDebouncedWatch.d.ts +1 -0
- package/hooks/useDebouncedWatch.js +27 -0
- package/hooks/useExchanges.d.ts +1 -0
- package/hooks/useExchanges.js +12 -0
- package/hooks/useHasSufficientBalance.d.ts +5 -0
- package/hooks/useHasSufficientBalance.js +59 -0
- package/hooks/useRouteExecution/index.d.ts +3 -0
- package/hooks/useRouteExecution/index.js +3 -0
- package/hooks/useRouteExecution/types.d.ts +15 -0
- package/hooks/useRouteExecution/types.js +1 -0
- package/hooks/useRouteExecution/useRouteExecution.d.ts +8 -0
- package/hooks/useRouteExecution/useRouteExecution.js +132 -0
- package/hooks/useRouteExecution/useRouteStore.d.ts +17 -0
- package/hooks/useRouteExecution/useRouteStore.js +71 -0
- package/hooks/useScrollableContainer.d.ts +2 -0
- package/hooks/useScrollableContainer.js +24 -0
- package/hooks/useSettings/index.d.ts +2 -0
- package/hooks/useSettings/index.js +2 -0
- package/hooks/useSettings/types.d.ts +5 -0
- package/hooks/useSettings/types.js +1 -0
- package/hooks/useSettings/useSettingsStore.d.ts +13 -0
- package/hooks/useSettings/useSettingsStore.js +22 -0
- package/hooks/useSwapRoutes.d.ts +8 -0
- package/hooks/useSwapRoutes.js +101 -0
- package/hooks/useToken.d.ts +4 -0
- package/hooks/useToken.js +13 -0
- package/hooks/useTokenBalance.d.ts +7 -0
- package/hooks/useTokenBalance.js +46 -0
- package/hooks/useTokenBalances.d.ts +7 -0
- package/hooks/useTokenBalances.js +54 -0
- package/hooks/useTokens.d.ts +5 -0
- package/hooks/useTokens.js +24 -0
- package/i18n/en/translation.json +138 -0
- package/i18n/index.d.ts +144 -0
- package/i18n/index.js +20 -0
- package/i18n/react-i18next.d.ts +9 -0
- package/index.d.ts +5 -0
- package/index.js +9 -0
- package/lifi.d.ts +2 -0
- package/lifi.js +10 -0
- package/package.json +55 -0
- package/pages/MainPage/MainPage.d.ts +2 -0
- package/pages/MainPage/MainPage.js +11 -0
- package/pages/MainPage/MainPage.style.d.ts +11 -0
- package/pages/MainPage/MainPage.style.js +8 -0
- package/pages/MainPage/SendToRecipientForm.d.ts +2 -0
- package/pages/MainPage/SendToRecipientForm.js +20 -0
- package/pages/MainPage/index.d.ts +1 -0
- package/pages/MainPage/index.js +1 -0
- package/pages/SelectTokenPage/ChainSelect.d.ts +2 -0
- package/pages/SelectTokenPage/ChainSelect.js +25 -0
- package/pages/SelectTokenPage/SearchTokenInput.d.ts +1 -0
- package/pages/SelectTokenPage/SearchTokenInput.js +17 -0
- package/pages/SelectTokenPage/SearchTokenInput.style.d.ts +1 -0
- package/pages/SelectTokenPage/SearchTokenInput.style.js +5 -0
- package/pages/SelectTokenPage/SelectTokenPage.d.ts +5 -0
- package/pages/SelectTokenPage/SelectTokenPage.js +16 -0
- package/pages/SelectTokenPage/index.d.ts +2 -0
- package/pages/SelectTokenPage/index.js +2 -0
- package/pages/SelectTokenPage/types.d.ts +4 -0
- package/pages/SelectTokenPage/types.js +5 -0
- package/pages/SelectWalletPage/SelectWalletPage.d.ts +1 -0
- package/pages/SelectWalletPage/SelectWalletPage.js +68 -0
- package/pages/SelectWalletPage/SelectWalletPage.style.d.ts +46 -0
- package/pages/SelectWalletPage/SelectWalletPage.style.js +27 -0
- package/pages/SelectWalletPage/index.d.ts +1 -0
- package/pages/SelectWalletPage/index.js +1 -0
- package/pages/SettingsPage/AdvancedPreferences.d.ts +1 -0
- package/pages/SettingsPage/AdvancedPreferences.js +19 -0
- package/pages/SettingsPage/ColorSchemeButtonGroup.d.ts +2 -0
- package/pages/SettingsPage/ColorSchemeButtonGroup.js +20 -0
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.d.ts +33 -0
- package/pages/SettingsPage/ColorSchemeButtonGroup.style.js +16 -0
- package/pages/SettingsPage/EnabledBridgesSelect.d.ts +2 -0
- package/pages/SettingsPage/EnabledBridgesSelect.js +15 -0
- package/pages/SettingsPage/EnabledExchangesSelect.d.ts +2 -0
- package/pages/SettingsPage/EnabledExchangesSelect.js +15 -0
- package/pages/SettingsPage/GasPriceSelect.d.ts +1 -0
- package/pages/SettingsPage/GasPriceSelect.js +13 -0
- package/pages/SettingsPage/RoutePrioritySelect.d.ts +2 -0
- package/pages/SettingsPage/RoutePrioritySelect.js +13 -0
- package/pages/SettingsPage/SettingsPage.d.ts +1 -0
- package/pages/SettingsPage/SettingsPage.js +10 -0
- package/pages/SettingsPage/SlippageInput.d.ts +1 -0
- package/pages/SettingsPage/SlippageInput.js +28 -0
- package/pages/SettingsPage/index.d.ts +1 -0
- package/pages/SettingsPage/index.js +1 -0
- package/pages/SwapPage/CircularProgress.d.ts +4 -0
- package/pages/SwapPage/CircularProgress.js +20 -0
- package/pages/SwapPage/CircularProgress.style.d.ts +6 -0
- package/pages/SwapPage/CircularProgress.style.js +51 -0
- package/pages/SwapPage/ExecutionItem.d.ts +6 -0
- package/pages/SwapPage/ExecutionItem.js +21 -0
- package/pages/SwapPage/ExecutionItem.style.d.ts +39 -0
- package/pages/SwapPage/ExecutionItem.style.js +5 -0
- package/pages/SwapPage/StatusBottomSheet.d.ts +3 -0
- package/pages/SwapPage/StatusBottomSheet.js +79 -0
- package/pages/SwapPage/StatusBottomSheet.style.d.ts +25 -0
- package/pages/SwapPage/StatusBottomSheet.style.js +32 -0
- package/pages/SwapPage/StepDivider.d.ts +2 -0
- package/pages/SwapPage/StepDivider.js +6 -0
- package/pages/SwapPage/StepDivider.style.d.ts +11 -0
- package/pages/SwapPage/StepDivider.style.js +8 -0
- package/pages/SwapPage/StepItem.d.ts +7 -0
- package/pages/SwapPage/StepItem.js +29 -0
- package/pages/SwapPage/StepTimer.d.ts +5 -0
- package/pages/SwapPage/StepTimer.js +59 -0
- package/pages/SwapPage/SwapPage.d.ts +2 -0
- package/pages/SwapPage/SwapPage.js +22 -0
- package/pages/SwapPage/SwapPage.style.d.ts +44 -0
- package/pages/SwapPage/SwapPage.style.js +12 -0
- package/pages/SwapPage/index.d.ts +1 -0
- package/pages/SwapPage/index.js +1 -0
- package/pages/SwapPage/utils.d.ts +6 -0
- package/pages/SwapPage/utils.js +85 -0
- package/pages/SwapRoutesPage/SwapRoutesPage.d.ts +3 -0
- package/pages/SwapRoutesPage/SwapRoutesPage.js +24 -0
- package/pages/SwapRoutesPage/SwapRoutesPage.style.d.ts +11 -0
- package/pages/SwapRoutesPage/SwapRoutesPage.style.js +6 -0
- package/pages/SwapRoutesPage/index.d.ts +1 -0
- package/pages/SwapRoutesPage/index.js +1 -0
- package/providers/SwapFormProvider/SwapFormProvider.d.ts +2 -0
- package/providers/SwapFormProvider/SwapFormProvider.js +20 -0
- package/providers/SwapFormProvider/index.d.ts +2 -0
- package/providers/SwapFormProvider/index.js +2 -0
- package/providers/SwapFormProvider/types.d.ts +44 -0
- package/providers/SwapFormProvider/types.js +24 -0
- package/providers/ThemeProvider/ThemeProvider.d.ts +2 -0
- package/providers/ThemeProvider/ThemeProvider.js +33 -0
- package/providers/ThemeProvider/index.d.ts +1 -0
- package/providers/ThemeProvider/index.js +1 -0
- package/providers/WalletProvider/WalletProvider.d.ts +4 -0
- package/providers/WalletProvider/WalletProvider.js +89 -0
- package/providers/WalletProvider/index.d.ts +2 -0
- package/providers/WalletProvider/index.js +2 -0
- package/providers/WalletProvider/types.d.ts +17 -0
- package/providers/WalletProvider/types.js +1 -0
- package/providers/WidgetProvider/WidgetProvider.d.ts +4 -0
- package/providers/WidgetProvider/WidgetProvider.js +44 -0
- package/providers/WidgetProvider/index.d.ts +2 -0
- package/providers/WidgetProvider/index.js +2 -0
- package/providers/WidgetProvider/types.d.ts +8 -0
- package/providers/WidgetProvider/types.js +1 -0
- package/react-app-env.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/widget.d.ts +41 -0
- package/types/widget.js +1 -0
- package/utils/colors.d.ts +2 -0
- package/utils/colors.js +3 -0
- package/utils/deepClone.d.ts +1 -0
- package/utils/deepClone.js +3 -0
- package/utils/elements.d.ts +4 -0
- package/utils/elements.js +5 -0
- package/utils/format.d.ts +9 -0
- package/utils/format.js +76 -0
- package/utils/input.d.ts +1 -0
- package/utils/input.js +24 -0
- package/utils/routes.d.ts +10 -0
- package/utils/routes.js +9 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export var SwapFormKey;
|
|
2
|
+
(function (SwapFormKey) {
|
|
3
|
+
SwapFormKey["BridgePrioritization"] = "bridgePrioritization";
|
|
4
|
+
SwapFormKey["EnabledBridges"] = "enabledBridges";
|
|
5
|
+
SwapFormKey["EnabledExchanges"] = "enabledExchanges";
|
|
6
|
+
SwapFormKey["FromAmount"] = "fromAmount";
|
|
7
|
+
SwapFormKey["FromChain"] = "fromChain";
|
|
8
|
+
SwapFormKey["FromToken"] = "fromToken";
|
|
9
|
+
SwapFormKey["GasPrice"] = "gasPrice";
|
|
10
|
+
SwapFormKey["IsAddressConfirmed"] = "isAddressConfirmed";
|
|
11
|
+
SwapFormKey["IsSendToRecipient"] = "isSendToRecipient";
|
|
12
|
+
SwapFormKey["RecipientsAddress"] = "recipientsAddress";
|
|
13
|
+
SwapFormKey["RoutePriority"] = "routePriority";
|
|
14
|
+
SwapFormKey["SearchTokensFilter"] = "searchTokensFilter";
|
|
15
|
+
SwapFormKey["Slippage"] = "slippage";
|
|
16
|
+
SwapFormKey["ToChain"] = "toChain";
|
|
17
|
+
SwapFormKey["ToToken"] = "toToken";
|
|
18
|
+
})(SwapFormKey || (SwapFormKey = {}));
|
|
19
|
+
export const SwapFormKeyHelper = {
|
|
20
|
+
getChainKey: (formType) => `${formType}Chain`,
|
|
21
|
+
getTokenKey: (formType) => `${formType}Token`,
|
|
22
|
+
getAmountKey: (formType) => `${formType}Amount`,
|
|
23
|
+
getSearchTokensFilterKey: (formType) => `${formType}SearchTokensFilter`,
|
|
24
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMediaQuery } from '@mui/material';
|
|
3
|
+
import { ThemeProvider as MuiThemeProvider } from '@mui/material/styles';
|
|
4
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
5
|
+
import { createTheme } from '../../config/theme';
|
|
6
|
+
import { useAppearance } from '../../hooks';
|
|
7
|
+
import { useWidgetConfig } from '../WidgetProvider';
|
|
8
|
+
export const ThemeProvider = ({ children, }) => {
|
|
9
|
+
const { appearance: colorSchemeMode, theme: themeConfig } = useWidgetConfig();
|
|
10
|
+
const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)');
|
|
11
|
+
const [appearance, setAppearance] = useAppearance();
|
|
12
|
+
const [mode, setMode] = useState((colorSchemeMode !== null && colorSchemeMode !== void 0 ? colorSchemeMode : appearance === 'auto')
|
|
13
|
+
? prefersDarkMode
|
|
14
|
+
? 'dark'
|
|
15
|
+
: 'light'
|
|
16
|
+
: appearance);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (appearance === 'auto') {
|
|
19
|
+
setMode(prefersDarkMode ? 'dark' : 'light');
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
setMode(appearance);
|
|
23
|
+
}
|
|
24
|
+
}, [appearance, prefersDarkMode]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (colorSchemeMode) {
|
|
27
|
+
setAppearance(colorSchemeMode);
|
|
28
|
+
}
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
+
}, [colorSchemeMode]);
|
|
31
|
+
const theme = useMemo(() => createTheme(mode, themeConfig), [mode, themeConfig]);
|
|
32
|
+
return _jsx(MuiThemeProvider, Object.assign({ theme: theme }, { children: children }));
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ThemeProvider';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ThemeProvider';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { addChain as walletAddChain, switchChain as walletSwitchChain, switchChainAndAddToken, useLifiWalletManagement, } from '@lifi/wallet-management';
|
|
12
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from 'react';
|
|
13
|
+
import { useWidgetConfig } from '../WidgetProvider';
|
|
14
|
+
const stub = () => {
|
|
15
|
+
throw new Error('You forgot to wrap your component in <WalletProvider>.');
|
|
16
|
+
};
|
|
17
|
+
const initialContext = {
|
|
18
|
+
connect: stub,
|
|
19
|
+
disconnect: stub,
|
|
20
|
+
switchChain: stub,
|
|
21
|
+
addChain: stub,
|
|
22
|
+
addToken: stub,
|
|
23
|
+
account: {},
|
|
24
|
+
};
|
|
25
|
+
const WalletContext = createContext(initialContext);
|
|
26
|
+
export const useWallet = () => useContext(WalletContext);
|
|
27
|
+
export const WalletProvider = ({ children }) => {
|
|
28
|
+
const config = useWidgetConfig();
|
|
29
|
+
const { connect: walletManagementConnect, disconnect: walletManagementDisconnect, signer, } = useLifiWalletManagement();
|
|
30
|
+
const [account, setAccount] = useState({});
|
|
31
|
+
const connect = useCallback((wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
if (config.disableInternalWalletManagement) {
|
|
33
|
+
// TODO
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
yield walletManagementConnect(wallet);
|
|
37
|
+
}), [config.disableInternalWalletManagement, walletManagementConnect]);
|
|
38
|
+
const disconnect = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
if (config.disableInternalWalletManagement) {
|
|
40
|
+
setAccount({});
|
|
41
|
+
}
|
|
42
|
+
yield walletManagementDisconnect();
|
|
43
|
+
}), [config.disableInternalWalletManagement, walletManagementDisconnect]);
|
|
44
|
+
// only for injected wallets
|
|
45
|
+
const switchChain = useCallback((chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
if (config.disableInternalWalletManagement) {
|
|
47
|
+
// TODO
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return walletSwitchChain(chainId);
|
|
51
|
+
}), [config.disableInternalWalletManagement]);
|
|
52
|
+
const addChain = useCallback((chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
if (!config.disableInternalWalletManagement) {
|
|
54
|
+
yield walletAddChain(chainId);
|
|
55
|
+
}
|
|
56
|
+
}), [config.disableInternalWalletManagement]);
|
|
57
|
+
const addToken = useCallback((chainId, token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
if (!config.disableInternalWalletManagement) {
|
|
59
|
+
yield switchChainAndAddToken(chainId, token);
|
|
60
|
+
}
|
|
61
|
+
}), [config.disableInternalWalletManagement]);
|
|
62
|
+
// keep account information up to date
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
const updateAccount = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
if (!config.disableInternalWalletManagement) {
|
|
66
|
+
const account = yield extractAccountFromSigner(signer);
|
|
67
|
+
setAccount(account);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
updateAccount();
|
|
71
|
+
}, [signer, config.disableInternalWalletManagement]);
|
|
72
|
+
const value = useMemo(() => ({
|
|
73
|
+
connect,
|
|
74
|
+
disconnect,
|
|
75
|
+
switchChain,
|
|
76
|
+
addChain,
|
|
77
|
+
addToken,
|
|
78
|
+
account,
|
|
79
|
+
}), [account, addChain, addToken, connect, disconnect, switchChain]);
|
|
80
|
+
return (_jsx(WalletContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
81
|
+
};
|
|
82
|
+
const extractAccountFromSigner = (signer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
return ({
|
|
84
|
+
address: (yield (signer === null || signer === void 0 ? void 0 : signer.getAddress())) || undefined,
|
|
85
|
+
isActive: (signer && !!(yield signer.getAddress()) === null) || !!signer,
|
|
86
|
+
signer,
|
|
87
|
+
chainId: (yield (signer === null || signer === void 0 ? void 0 : signer.getChainId())) || undefined,
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Wallet } from '@lifi/wallet-management';
|
|
2
|
+
import { Token } from '@lifinance/sdk';
|
|
3
|
+
import { Signer } from 'ethers';
|
|
4
|
+
export interface WalletContextProps {
|
|
5
|
+
account: WalletAccount;
|
|
6
|
+
addChain(chainId: number): Promise<void>;
|
|
7
|
+
addToken(chainId: number, token: Token): Promise<void>;
|
|
8
|
+
disconnect(): void;
|
|
9
|
+
switchChain(chainId: number): Promise<boolean>;
|
|
10
|
+
connect(wallet?: Wallet | undefined): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export interface WalletAccount {
|
|
13
|
+
address?: string;
|
|
14
|
+
isActive?: boolean;
|
|
15
|
+
signer?: Signer;
|
|
16
|
+
chainId?: number;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { ChainId, getChainByKey } from '@lifinance/sdk';
|
|
14
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
15
|
+
const stub = () => {
|
|
16
|
+
throw new Error('You forgot to wrap your component in <WidgetProvider>.');
|
|
17
|
+
};
|
|
18
|
+
const initialContext = {
|
|
19
|
+
enabledChains: [],
|
|
20
|
+
};
|
|
21
|
+
const WidgetContext = createContext(initialContext);
|
|
22
|
+
export const useWidgetConfig = () => useContext(WidgetContext);
|
|
23
|
+
export const WidgetProvider = (_a) => {
|
|
24
|
+
var { children } = _a, _b = _a.config, { fromChain, toChain } = _b, other = __rest(_b, ["fromChain", "toChain"]);
|
|
25
|
+
const value = useMemo(() => {
|
|
26
|
+
const config = Object.assign({}, other);
|
|
27
|
+
try {
|
|
28
|
+
return Object.assign(Object.assign({}, config), { fromChain: typeof fromChain === 'number'
|
|
29
|
+
? fromChain
|
|
30
|
+
: typeof fromChain === 'string'
|
|
31
|
+
? getChainByKey(fromChain).id
|
|
32
|
+
: ChainId.ETH, toChain: typeof toChain === 'number'
|
|
33
|
+
? toChain
|
|
34
|
+
: typeof toChain === 'string'
|
|
35
|
+
? getChainByKey(toChain).id
|
|
36
|
+
: ChainId.ETH });
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
console.warn(e);
|
|
40
|
+
return config;
|
|
41
|
+
}
|
|
42
|
+
}, [fromChain, other, toChain]);
|
|
43
|
+
return (_jsx(WidgetContext.Provider, Object.assign({ value: value }, { children: children })));
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="react-scripts" />
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './widget';
|
package/types/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './widget';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ChainKey } from '@lifinance/sdk';
|
|
2
|
+
import { PaletteMode, PaletteOptions, Shape } from '@mui/material';
|
|
3
|
+
import { TypographyOptions } from '@mui/material/styles/createTypography';
|
|
4
|
+
import { Signer } from 'ethers';
|
|
5
|
+
import { CSSProperties } from 'react';
|
|
6
|
+
export declare type Appearance = PaletteMode | 'auto';
|
|
7
|
+
export declare type ThemeConfig = {
|
|
8
|
+
palette?: PaletteOptions;
|
|
9
|
+
shape?: Shape;
|
|
10
|
+
typography?: TypographyOptions;
|
|
11
|
+
};
|
|
12
|
+
export interface WidgetConfig {
|
|
13
|
+
fromAmount?: number;
|
|
14
|
+
fromChain?: `${ChainKey}` | number;
|
|
15
|
+
fromToken?: string;
|
|
16
|
+
toChain?: `${ChainKey}` | number;
|
|
17
|
+
toToken?: string;
|
|
18
|
+
enabledChains: number[];
|
|
19
|
+
disableInternalWalletManagement?: boolean;
|
|
20
|
+
walletCallbacks?: {
|
|
21
|
+
connect: {
|
|
22
|
+
(): Signer;
|
|
23
|
+
};
|
|
24
|
+
disconnect: {
|
|
25
|
+
(): void;
|
|
26
|
+
};
|
|
27
|
+
provideSigner: {
|
|
28
|
+
(): Signer;
|
|
29
|
+
};
|
|
30
|
+
switchChain: {
|
|
31
|
+
(): Signer;
|
|
32
|
+
};
|
|
33
|
+
addToken: {
|
|
34
|
+
(): void;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
containerStyle?: CSSProperties;
|
|
38
|
+
theme?: ThemeConfig;
|
|
39
|
+
appearance?: Appearance;
|
|
40
|
+
disableAppearance?: boolean;
|
|
41
|
+
}
|
package/types/widget.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/utils/colors.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const deepClone: <T>(src: T) => T;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format token amount to at least 4 decimals.
|
|
3
|
+
* @param amount amount to format.
|
|
4
|
+
* @returns formatted amount.
|
|
5
|
+
*/
|
|
6
|
+
export declare const formatTokenAmount: (amount?: string, decimals?: number) => string;
|
|
7
|
+
export declare const formatSlippage: (slippage?: string, defaultValue?: string, returnInitial?: boolean) => string | number;
|
|
8
|
+
export declare const formatAmount: (amount?: string, returnInitial?: boolean) => string;
|
|
9
|
+
export declare const formatTokenPrice: (amount?: string, price?: string) => number;
|
package/utils/format.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
// JavaScript numbers use exponential notation for positive exponents of 21 and above.
|
|
3
|
+
Big.PE = 21;
|
|
4
|
+
// JavaScript numbers use exponential notation for negative exponents of -7 and below. We need more.
|
|
5
|
+
Big.NE = -21;
|
|
6
|
+
/**
|
|
7
|
+
* Format token amount to at least 4 decimals.
|
|
8
|
+
* @param amount amount to format.
|
|
9
|
+
* @returns formatted amount.
|
|
10
|
+
*/
|
|
11
|
+
export const formatTokenAmount = (amount = '0', decimals = 0) => {
|
|
12
|
+
let shiftedAmount = amount;
|
|
13
|
+
if (decimals) {
|
|
14
|
+
shiftedAmount = (Number(amount) / Math.pow(10, decimals)).toString();
|
|
15
|
+
}
|
|
16
|
+
const parsedAmount = parseFloat(shiftedAmount);
|
|
17
|
+
if (parsedAmount === 0 || isNaN(Number(shiftedAmount))) {
|
|
18
|
+
return '0';
|
|
19
|
+
}
|
|
20
|
+
let decimalPlaces = 3;
|
|
21
|
+
const absAmount = Math.abs(parsedAmount);
|
|
22
|
+
while (absAmount < 1 / Math.pow(10, decimalPlaces)) {
|
|
23
|
+
decimalPlaces++;
|
|
24
|
+
}
|
|
25
|
+
return Big(parseFloat(Big(parsedAmount).toFixed(decimalPlaces + 1, 0))).toString();
|
|
26
|
+
};
|
|
27
|
+
export const formatSlippage = (slippage = '', defaultValue = '', returnInitial = false) => {
|
|
28
|
+
if (!slippage) {
|
|
29
|
+
return slippage;
|
|
30
|
+
}
|
|
31
|
+
const parsedSlippage = parseFloat(slippage);
|
|
32
|
+
if (isNaN(Number(slippage)) && !isNaN(parsedSlippage)) {
|
|
33
|
+
return parsedSlippage;
|
|
34
|
+
}
|
|
35
|
+
if (isNaN(parsedSlippage)) {
|
|
36
|
+
return defaultValue;
|
|
37
|
+
}
|
|
38
|
+
if (parsedSlippage > 100) {
|
|
39
|
+
return '100';
|
|
40
|
+
}
|
|
41
|
+
if (parsedSlippage < 0) {
|
|
42
|
+
return Math.abs(parsedSlippage).toString();
|
|
43
|
+
}
|
|
44
|
+
if (returnInitial) {
|
|
45
|
+
return slippage;
|
|
46
|
+
}
|
|
47
|
+
return parsedSlippage.toString();
|
|
48
|
+
};
|
|
49
|
+
export const formatAmount = (amount = '', returnInitial = false) => {
|
|
50
|
+
if (!amount) {
|
|
51
|
+
return amount;
|
|
52
|
+
}
|
|
53
|
+
const parsedAmount = parseFloat(amount);
|
|
54
|
+
if (isNaN(Number(amount)) && !isNaN(parsedAmount)) {
|
|
55
|
+
return parsedAmount.toString();
|
|
56
|
+
}
|
|
57
|
+
if (isNaN(parsedAmount)) {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
if (parsedAmount < 0) {
|
|
61
|
+
return Math.abs(parsedAmount).toString();
|
|
62
|
+
}
|
|
63
|
+
if (returnInitial) {
|
|
64
|
+
return amount;
|
|
65
|
+
}
|
|
66
|
+
return Big(parsedAmount).toString();
|
|
67
|
+
};
|
|
68
|
+
export const formatTokenPrice = (amount, price) => {
|
|
69
|
+
if (!amount || !price) {
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
if (isNaN(Number(amount)) || isNaN(Number(price))) {
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
return parseFloat(amount) * parseFloat(price);
|
|
76
|
+
};
|
package/utils/input.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fitInputText: (maxFontSize: number, minFontSize: number, element: HTMLElement) => void;
|
package/utils/input.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const fitInputText = (maxFontSize, minFontSize, element) => {
|
|
2
|
+
if (!element) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
let high = maxFontSize;
|
|
6
|
+
let low = minFontSize;
|
|
7
|
+
let size = minFontSize;
|
|
8
|
+
let mid = 0;
|
|
9
|
+
// Binary search for highest font size best fit
|
|
10
|
+
while (low <= high) {
|
|
11
|
+
mid = (high + low) >> 1;
|
|
12
|
+
const fontSize = `${mid + 1}px`;
|
|
13
|
+
element.style.fontSize = fontSize;
|
|
14
|
+
if (element.scrollWidth <= element.clientWidth) {
|
|
15
|
+
size = mid;
|
|
16
|
+
low = mid + 1;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
high = mid - 1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const fontSize = `${size}px`;
|
|
23
|
+
element.style.fontSize = fontSize;
|
|
24
|
+
};
|