@lifi/widget 4.0.0-beta.14 → 4.0.0-beta.17
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/dist/esm/AppDefault.js +31 -29
- package/dist/esm/AppDefault.js.map +1 -1
- package/dist/esm/AppLayout.js +2 -2
- package/dist/esm/AppLayout.js.map +1 -1
- package/dist/esm/components/AmountInput/AmountInput.js +2 -2
- package/dist/esm/components/AmountInput/AmountInput.js.map +1 -1
- package/dist/esm/components/AppContainer.js +3 -3
- package/dist/esm/components/AppContainer.js.map +1 -1
- package/dist/esm/components/Chains/AllChainsAvatar.js +6 -0
- package/dist/esm/components/Chains/AllChainsAvatar.js.map +1 -1
- package/dist/esm/components/ContractComponent/ItemPrice.js +1 -1
- package/dist/esm/components/ContractComponent/ItemPrice.js.map +1 -1
- package/dist/esm/components/ContractComponent/NFT/NFTBase.js +1 -1
- package/dist/esm/components/ContractComponent/NFT/NFTBase.js.map +1 -1
- package/dist/esm/components/Expansion/Expansion.js +4 -4
- package/dist/esm/components/Expansion/Expansion.js.map +1 -1
- package/dist/esm/components/Header/ActivitiesButton.js +1 -1
- package/dist/esm/components/Header/ActivitiesButton.js.map +1 -1
- package/dist/esm/components/Header/Header.js +2 -2
- package/dist/esm/components/Header/Header.js.map +1 -1
- package/dist/esm/components/Header/NavigationHeader.js +3 -3
- package/dist/esm/components/Header/NavigationHeader.js.map +1 -1
- package/dist/esm/components/Header/WalletHeader.js +3 -3
- package/dist/esm/components/Header/WalletHeader.js.map +1 -1
- package/dist/esm/components/IconTypography.js.map +1 -1
- package/dist/esm/components/Messages/AlertMessage.js +1 -1
- package/dist/esm/components/Messages/AlertMessage.js.map +1 -1
- package/dist/esm/components/PageEntered.js +2 -2
- package/dist/esm/components/PageEntered.js.map +1 -1
- package/dist/esm/components/RouteCard/RouteCard.js +2 -2
- package/dist/esm/components/RouteCard/RouteCard.js.map +1 -1
- package/dist/esm/components/RouteCard/RouteCardEssentials.js +10 -4
- package/dist/esm/components/RouteCard/RouteCardEssentials.js.map +1 -1
- package/dist/esm/components/RouteCard/RouteToken.js +2 -2
- package/dist/esm/components/RouteCard/RouteToken.js.map +1 -1
- package/dist/esm/components/Routes/RoutesExpanded.js +3 -3
- package/dist/esm/components/Routes/RoutesExpanded.js.map +1 -1
- package/dist/esm/components/SelectChainAndToken.js +8 -5
- package/dist/esm/components/SelectChainAndToken.js.map +1 -1
- package/dist/esm/components/SelectTokenButton/SelectTokenButton.style.js +1 -2
- package/dist/esm/components/SelectTokenButton/SelectTokenButton.style.js.map +1 -1
- package/dist/esm/components/SendToWallet/SendToWalletButton.js +3 -3
- package/dist/esm/components/SendToWallet/SendToWalletButton.js.map +1 -1
- package/dist/esm/components/SendToWallet/SendToWalletExpandButton.js +3 -3
- package/dist/esm/components/SendToWallet/SendToWalletExpandButton.js.map +1 -1
- package/dist/esm/components/Step/Step.js +20 -9
- package/dist/esm/components/Step/Step.js.map +1 -1
- package/dist/esm/components/Step/StepActions.js +2 -2
- package/dist/esm/components/Step/StepActions.js.map +1 -1
- package/dist/esm/components/StepActions/StepActions.js +2 -2
- package/dist/esm/components/StepActions/StepActions.js.map +1 -1
- package/dist/esm/components/Timer/TimerContent.js +1 -0
- package/dist/esm/components/Timer/TimerContent.js.map +1 -1
- package/dist/esm/components/Token/Token.js +2 -2
- package/dist/esm/components/Token/Token.js.map +1 -1
- package/dist/esm/components/TokenList/TokenDetailsSheetContent.js +6 -4
- package/dist/esm/components/TokenList/TokenDetailsSheetContent.js.map +1 -1
- package/dist/esm/components/TokenList/TokenList.js +2 -2
- package/dist/esm/components/TokenList/TokenList.js.map +1 -1
- package/dist/esm/components/TokenList/useTokenSelect.js +2 -2
- package/dist/esm/components/TokenList/useTokenSelect.js.map +1 -1
- package/dist/esm/components/TransactionCard/ActiveTransactionCard.js +2 -3
- package/dist/esm/components/TransactionCard/ActiveTransactionCard.js.map +1 -1
- package/dist/esm/components/TransactionDetails.js +5 -2
- package/dist/esm/components/TransactionDetails.js.map +1 -1
- package/dist/esm/config/version.d.ts +1 -1
- package/dist/esm/config/version.js +1 -1
- package/dist/esm/config/version.js.map +1 -1
- package/dist/esm/hooks/useAddressValidation.js +3 -8
- package/dist/esm/hooks/useAddressValidation.js.map +1 -1
- package/dist/esm/hooks/useAvailableChains.js +2 -1
- package/dist/esm/hooks/useAvailableChains.js.map +1 -1
- package/dist/esm/hooks/useContactSupport.js +3 -3
- package/dist/esm/hooks/useContactSupport.js.map +1 -1
- package/dist/esm/hooks/useExplorer.js +15 -4
- package/dist/esm/hooks/useExplorer.js.map +1 -1
- package/dist/esm/hooks/useGasRecommendation.js +2 -2
- package/dist/esm/hooks/useGasRecommendation.js.map +1 -1
- package/dist/esm/hooks/useGasRefuel.js +2 -2
- package/dist/esm/hooks/useGasRefuel.js.map +1 -1
- package/dist/esm/hooks/useGasSufficiency.js +2 -2
- package/dist/esm/hooks/useGasSufficiency.js.map +1 -1
- package/dist/esm/hooks/useHasChainExpansion.js +3 -3
- package/dist/esm/hooks/useHasChainExpansion.js.map +1 -1
- package/dist/esm/hooks/useListHeight.js +2 -2
- package/dist/esm/hooks/useListHeight.js.map +1 -1
- package/dist/esm/hooks/useRouteExecution.js +5 -5
- package/dist/esm/hooks/useRouteExecution.js.map +1 -1
- package/dist/esm/hooks/useRoutes.js +4 -4
- package/dist/esm/hooks/useRoutes.js.map +1 -1
- package/dist/esm/hooks/useToAddressRequirements.js +2 -2
- package/dist/esm/hooks/useToAddressRequirements.js.map +1 -1
- package/dist/esm/hooks/useToAddressReset.js +2 -2
- package/dist/esm/hooks/useToAddressReset.js.map +1 -1
- package/dist/esm/hooks/useTokenBalances.js +2 -2
- package/dist/esm/hooks/useTokenBalances.js.map +1 -1
- package/dist/esm/hooks/useTokens.js +4 -2
- package/dist/esm/hooks/useTokens.js.map +1 -1
- package/dist/esm/hooks/useTransactionList.js +2 -3
- package/dist/esm/hooks/useTransactionList.js.map +1 -1
- package/dist/esm/i18n/en.json +3 -0
- package/dist/esm/pages/ActivitiesPage/ActivitiesPage.js +1 -2
- package/dist/esm/pages/ActivitiesPage/ActivitiesPage.js.map +1 -1
- package/dist/esm/pages/ActivitiesPage/ActivitiesPageMenuButton.js +1 -1
- package/dist/esm/pages/ActivitiesPage/ActivitiesPageMenuButton.js.map +1 -1
- package/dist/esm/pages/MainPage/MainPage.js +6 -6
- package/dist/esm/pages/MainPage/MainPage.js.map +1 -1
- package/dist/esm/pages/MainPage/ReviewButton.js +2 -2
- package/dist/esm/pages/MainPage/ReviewButton.js.map +1 -1
- package/dist/esm/pages/RoutesPage/RoutesPage.js +3 -3
- package/dist/esm/pages/RoutesPage/RoutesPage.js.map +1 -1
- package/dist/esm/pages/SelectTokenPage/SelectTokenPage.js +3 -3
- package/dist/esm/pages/SelectTokenPage/SelectTokenPage.js.map +1 -1
- package/dist/esm/pages/SendToWallet/BookmarksPage.js +1 -1
- package/dist/esm/pages/SendToWallet/BookmarksPage.js.map +1 -1
- package/dist/esm/pages/SendToWallet/RecentWalletsPage.js +1 -1
- package/dist/esm/pages/SendToWallet/RecentWalletsPage.js.map +1 -1
- package/dist/esm/pages/SendToWallet/SendToWalletPage.js +6 -6
- package/dist/esm/pages/SendToWallet/SendToWalletPage.js.map +1 -1
- package/dist/esm/pages/SettingsPage/BridgeAndExchangeSettings.js +2 -2
- package/dist/esm/pages/SettingsPage/BridgeAndExchangeSettings.js.map +1 -1
- package/dist/esm/pages/SettingsPage/LanguageSetting.js +2 -2
- package/dist/esm/pages/SettingsPage/LanguageSetting.js.map +1 -1
- package/dist/esm/pages/SettingsPage/SettingsPage.js +2 -2
- package/dist/esm/pages/SettingsPage/SettingsPage.js.map +1 -1
- package/dist/esm/pages/SettingsPage/ThemeSettings.js +2 -2
- package/dist/esm/pages/SettingsPage/ThemeSettings.js.map +1 -1
- package/dist/esm/pages/TransactionDetailsPage/TransferIdCard.js +2 -2
- package/dist/esm/pages/TransactionDetailsPage/TransferIdCard.js.map +1 -1
- package/dist/esm/pages/TransactionPage/ConfirmToAddressSheet.js +2 -2
- package/dist/esm/pages/TransactionPage/ConfirmToAddressSheet.js.map +1 -1
- package/dist/esm/pages/TransactionPage/ExchangeRateBottomSheet.js +1 -1
- package/dist/esm/pages/TransactionPage/ExchangeRateBottomSheet.js.map +1 -1
- package/dist/esm/pages/TransactionPage/StatusBottomSheet.js +20 -21
- package/dist/esm/pages/TransactionPage/StatusBottomSheet.js.map +1 -1
- package/dist/esm/pages/TransactionPage/StatusBottomSheet.style.js +5 -6
- package/dist/esm/pages/TransactionPage/StatusBottomSheet.style.js.map +1 -1
- package/dist/esm/pages/TransactionPage/TokenValueBottomSheet.js +14 -4
- package/dist/esm/pages/TransactionPage/TokenValueBottomSheet.js.map +1 -1
- package/dist/esm/pages/TransactionPage/TransactionPage.js +15 -19
- package/dist/esm/pages/TransactionPage/TransactionPage.js.map +1 -1
- package/dist/esm/providers/WalletProvider/useExternalWalletProvider.js +7 -3
- package/dist/esm/providers/WalletProvider/useExternalWalletProvider.js.map +1 -1
- package/dist/esm/stores/chains/ChainOrderStore.js +2 -2
- package/dist/esm/stores/chains/ChainOrderStore.js.map +1 -1
- package/dist/esm/stores/chains/createChainOrderStore.js +2 -2
- package/dist/esm/stores/chains/createChainOrderStore.js.map +1 -1
- package/dist/esm/stores/form/useFieldActions.js +3 -3
- package/dist/esm/stores/form/useFieldActions.js.map +1 -1
- package/dist/esm/stores/form/useFormRef.js +2 -2
- package/dist/esm/stores/form/useFormRef.js.map +1 -1
- package/dist/esm/stores/routes/createRouteExecutionStore.js +8 -9
- package/dist/esm/stores/routes/createRouteExecutionStore.js.map +1 -1
- package/dist/esm/stores/routes/useRouteExecutionIndicator.js +2 -3
- package/dist/esm/stores/routes/useRouteExecutionIndicator.js.map +1 -1
- package/dist/esm/stores/settings/createSettingsStore.js +1 -5
- package/dist/esm/stores/settings/createSettingsStore.js.map +1 -1
- package/dist/esm/stores/settings/useSettingsActions.js +2 -2
- package/dist/esm/stores/settings/useSettingsActions.js.map +1 -1
- package/dist/esm/themes/createTheme.js +4 -4
- package/dist/esm/themes/createTheme.js.map +1 -1
- package/dist/esm/types/events.d.ts +0 -5
- package/dist/esm/types/events.d.ts.map +1 -1
- package/dist/esm/types/events.js +0 -4
- package/dist/esm/types/events.js.map +1 -1
- package/dist/esm/types/widget.d.ts +1 -5
- package/dist/esm/types/widget.d.ts.map +1 -1
- package/dist/esm/types/widget.js.map +1 -1
- package/dist/esm/utils/elements.js +5 -12
- package/dist/esm/utils/elements.js.map +1 -1
- package/package.json +7 -7
- package/src/AppDefault.tsx +9 -11
- package/src/components/Chains/AllChainsAvatar.tsx +6 -0
- package/src/components/ContractComponent/ItemPrice.tsx +1 -1
- package/src/components/ContractComponent/NFT/NFTBase.tsx +1 -1
- package/src/components/Header/ActivitiesButton.tsx +1 -1
- package/src/components/IconTypography.ts +8 -8
- package/src/components/Messages/AlertMessage.tsx +1 -1
- package/src/components/RouteCard/RouteCardEssentials.tsx +2 -2
- package/src/components/SelectChainAndToken.tsx +1 -1
- package/src/components/Step/Step.tsx +6 -7
- package/src/components/Timer/TimerContent.tsx +1 -0
- package/src/components/Token/Token.tsx +2 -2
- package/src/components/TokenList/TokenDetailsSheetContent.tsx +6 -4
- package/src/components/TransactionCard/ActiveTransactionCard.tsx +1 -1
- package/src/components/TransactionDetails.tsx +1 -1
- package/src/config/version.ts +1 -1
- package/src/hooks/useAvailableChains.ts +1 -0
- package/src/hooks/useExplorer.ts +16 -5
- package/src/hooks/useTokens.ts +2 -0
- package/src/pages/ActivitiesPage/ActivitiesPageMenuButton.tsx +1 -1
- package/src/pages/MainPage/MainPage.tsx +3 -3
- package/src/pages/RoutesPage/RoutesPage.tsx +6 -1
- package/src/pages/SendToWallet/BookmarksPage.tsx +1 -1
- package/src/pages/SendToWallet/RecentWalletsPage.tsx +1 -1
- package/src/pages/TransactionPage/ExchangeRateBottomSheet.tsx +1 -1
- package/src/pages/TransactionPage/StatusBottomSheet.tsx +1 -1
- package/src/pages/TransactionPage/TokenValueBottomSheet.tsx +27 -5
- package/src/pages/TransactionPage/TransactionPage.tsx +2 -9
- package/src/providers/WalletProvider/useExternalWalletProvider.ts +9 -1
- package/src/stores/settings/createSettingsStore.ts +1 -9
- package/src/themes/createTheme.ts +4 -6
- package/src/types/events.ts +0 -5
- package/src/types/widget.ts +1 -4
- package/dist/esm/stores/routes/types.js +0 -14
- package/dist/esm/stores/routes/types.js.map +0 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { useWidgetConfig } from "../WidgetProvider/WidgetProvider.js";
|
|
2
2
|
import { ChainType } from "@lifi/sdk";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
|
-
import { useBitcoinContext, useEthereumContext, useSolanaContext, useSuiContext } from "@lifi/widget-provider";
|
|
4
|
+
import { useBitcoinContext, useEthereumContext, useSolanaContext, useSuiContext, useTronContext } from "@lifi/widget-provider";
|
|
5
5
|
//#region src/providers/WalletProvider/useExternalWalletProvider.ts
|
|
6
6
|
const internalChainTypes = [
|
|
7
7
|
ChainType.EVM,
|
|
8
8
|
ChainType.SVM,
|
|
9
9
|
ChainType.UTXO,
|
|
10
|
-
ChainType.MVM
|
|
10
|
+
ChainType.MVM,
|
|
11
|
+
ChainType.TVM
|
|
11
12
|
];
|
|
12
13
|
function useExternalWalletProvider() {
|
|
13
14
|
const { walletConfig } = useWidgetConfig();
|
|
@@ -15,14 +16,16 @@ function useExternalWalletProvider() {
|
|
|
15
16
|
const { isExternalContext: hasExternalSolanaContext } = useSolanaContext();
|
|
16
17
|
const { isExternalContext: hasExternalBitcoinContext } = useBitcoinContext();
|
|
17
18
|
const { isExternalContext: hasExternalSuiContext } = useSuiContext();
|
|
19
|
+
const { isExternalContext: hasExternalTronContext } = useTronContext();
|
|
18
20
|
return useMemo(() => {
|
|
19
21
|
const providers = [];
|
|
20
22
|
if (hasExternalEthereumContext) providers.push(ChainType.EVM);
|
|
21
23
|
if (hasExternalSolanaContext) providers.push(ChainType.SVM);
|
|
22
24
|
if (hasExternalBitcoinContext) providers.push(ChainType.UTXO);
|
|
23
25
|
if (hasExternalSuiContext) providers.push(ChainType.MVM);
|
|
26
|
+
if (hasExternalTronContext) providers.push(ChainType.TVM);
|
|
24
27
|
return {
|
|
25
|
-
useExternalWalletProvidersOnly: (hasExternalEthereumContext || hasExternalSolanaContext || hasExternalBitcoinContext || hasExternalSuiContext) && !walletConfig?.usePartialWalletManagement && !walletConfig?.forceInternalWalletManagement,
|
|
28
|
+
useExternalWalletProvidersOnly: (hasExternalEthereumContext || hasExternalSolanaContext || hasExternalBitcoinContext || hasExternalSuiContext || hasExternalTronContext) && !walletConfig?.usePartialWalletManagement && !walletConfig?.forceInternalWalletManagement,
|
|
26
29
|
externalChainTypes: providers,
|
|
27
30
|
internalChainTypes: internalChainTypes.filter((chainType) => !providers.includes(chainType))
|
|
28
31
|
};
|
|
@@ -31,6 +34,7 @@ function useExternalWalletProvider() {
|
|
|
31
34
|
hasExternalSolanaContext,
|
|
32
35
|
hasExternalBitcoinContext,
|
|
33
36
|
hasExternalSuiContext,
|
|
37
|
+
hasExternalTronContext,
|
|
34
38
|
walletConfig?.usePartialWalletManagement,
|
|
35
39
|
walletConfig?.forceInternalWalletManagement
|
|
36
40
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useExternalWalletProvider.js","names":[],"sources":["../../../../src/providers/WalletProvider/useExternalWalletProvider.ts"],"sourcesContent":["import { ChainType } from '@lifi/sdk'\nimport {\n useBitcoinContext,\n useEthereumContext,\n useSolanaContext,\n useSuiContext,\n} from '@lifi/widget-provider'\nimport { useMemo } from 'react'\nimport { useWidgetConfig } from '../WidgetProvider/WidgetProvider.js'\n\ninterface ExternalWalletProvider {\n useExternalWalletProvidersOnly: boolean\n externalChainTypes: ChainType[]\n internalChainTypes: ChainType[]\n}\n\nconst internalChainTypes = [\n ChainType.EVM,\n ChainType.SVM,\n ChainType.UTXO,\n ChainType.MVM,\n]\n\nexport function useExternalWalletProvider(): ExternalWalletProvider {\n const { walletConfig } = useWidgetConfig()\n const { isExternalContext: hasExternalEthereumContext } = useEthereumContext()\n const { isExternalContext: hasExternalSolanaContext } = useSolanaContext()\n const { isExternalContext: hasExternalBitcoinContext } = useBitcoinContext()\n const { isExternalContext: hasExternalSuiContext } = useSuiContext()\n const data = useMemo(() => {\n const providers: ChainType[] = []\n if (hasExternalEthereumContext) {\n providers.push(ChainType.EVM)\n }\n if (hasExternalSolanaContext) {\n providers.push(ChainType.SVM)\n }\n if (hasExternalBitcoinContext) {\n providers.push(ChainType.UTXO)\n }\n if (hasExternalSuiContext) {\n providers.push(ChainType.MVM)\n }\n const hasExternalProvider =\n hasExternalEthereumContext ||\n hasExternalSolanaContext ||\n hasExternalBitcoinContext ||\n hasExternalSuiContext\n\n const useExternalWalletProvidersOnly =\n hasExternalProvider &&\n !walletConfig?.usePartialWalletManagement &&\n !walletConfig?.forceInternalWalletManagement\n return {\n useExternalWalletProvidersOnly,\n externalChainTypes: providers,\n internalChainTypes: internalChainTypes.filter(\n (chainType) => !providers.includes(chainType)\n ),\n }\n }, [\n hasExternalEthereumContext,\n hasExternalSolanaContext,\n hasExternalBitcoinContext,\n hasExternalSuiContext,\n walletConfig?.usePartialWalletManagement,\n walletConfig?.forceInternalWalletManagement,\n ])\n\n return data\n}\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"useExternalWalletProvider.js","names":[],"sources":["../../../../src/providers/WalletProvider/useExternalWalletProvider.ts"],"sourcesContent":["import { ChainType } from '@lifi/sdk'\nimport {\n useBitcoinContext,\n useEthereumContext,\n useSolanaContext,\n useSuiContext,\n useTronContext,\n} from '@lifi/widget-provider'\nimport { useMemo } from 'react'\nimport { useWidgetConfig } from '../WidgetProvider/WidgetProvider.js'\n\ninterface ExternalWalletProvider {\n useExternalWalletProvidersOnly: boolean\n externalChainTypes: ChainType[]\n internalChainTypes: ChainType[]\n}\n\nconst internalChainTypes = [\n ChainType.EVM,\n ChainType.SVM,\n ChainType.UTXO,\n ChainType.MVM,\n ChainType.TVM,\n]\n\nexport function useExternalWalletProvider(): ExternalWalletProvider {\n const { walletConfig } = useWidgetConfig()\n const { isExternalContext: hasExternalEthereumContext } = useEthereumContext()\n const { isExternalContext: hasExternalSolanaContext } = useSolanaContext()\n const { isExternalContext: hasExternalBitcoinContext } = useBitcoinContext()\n const { isExternalContext: hasExternalSuiContext } = useSuiContext()\n const { isExternalContext: hasExternalTronContext } = useTronContext()\n const data = useMemo(() => {\n const providers: ChainType[] = []\n if (hasExternalEthereumContext) {\n providers.push(ChainType.EVM)\n }\n if (hasExternalSolanaContext) {\n providers.push(ChainType.SVM)\n }\n if (hasExternalBitcoinContext) {\n providers.push(ChainType.UTXO)\n }\n if (hasExternalSuiContext) {\n providers.push(ChainType.MVM)\n }\n if (hasExternalTronContext) {\n providers.push(ChainType.TVM)\n }\n const hasExternalProvider =\n hasExternalEthereumContext ||\n hasExternalSolanaContext ||\n hasExternalBitcoinContext ||\n hasExternalSuiContext ||\n hasExternalTronContext\n\n const useExternalWalletProvidersOnly =\n hasExternalProvider &&\n !walletConfig?.usePartialWalletManagement &&\n !walletConfig?.forceInternalWalletManagement\n return {\n useExternalWalletProvidersOnly,\n externalChainTypes: providers,\n internalChainTypes: internalChainTypes.filter(\n (chainType) => !providers.includes(chainType)\n ),\n }\n }, [\n hasExternalEthereumContext,\n hasExternalSolanaContext,\n hasExternalBitcoinContext,\n hasExternalSuiContext,\n hasExternalTronContext,\n walletConfig?.usePartialWalletManagement,\n walletConfig?.forceInternalWalletManagement,\n ])\n\n return data\n}\n"],"mappings":";;;;;AAiBA,MAAM,qBAAqB;CACzB,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACV,UAAU;CACX;AAED,SAAgB,4BAAoD;CAClE,MAAM,EAAE,iBAAiB,iBAAiB;CAC1C,MAAM,EAAE,mBAAmB,+BAA+B,oBAAoB;CAC9E,MAAM,EAAE,mBAAmB,6BAA6B,kBAAkB;CAC1E,MAAM,EAAE,mBAAmB,8BAA8B,mBAAmB;CAC5E,MAAM,EAAE,mBAAmB,0BAA0B,eAAe;CACpE,MAAM,EAAE,mBAAmB,2BAA2B,gBAAgB;AA8CtE,QA7Ca,cAAc;EACzB,MAAM,YAAyB,EAAE;AACjC,MAAI,2BACF,WAAU,KAAK,UAAU,IAAI;AAE/B,MAAI,yBACF,WAAU,KAAK,UAAU,IAAI;AAE/B,MAAI,0BACF,WAAU,KAAK,UAAU,KAAK;AAEhC,MAAI,sBACF,WAAU,KAAK,UAAU,IAAI;AAE/B,MAAI,uBACF,WAAU,KAAK,UAAU,IAAI;AAa/B,SAAO;GACL,iCAXA,8BACA,4BACA,6BACA,yBACA,2BAIA,CAAC,cAAc,8BACf,CAAC,cAAc;GAGf,oBAAoB;GACpB,oBAAoB,mBAAmB,QACpC,cAAc,CAAC,UAAU,SAAS,UAAU,CAC9C;GACF;IACA;EACD;EACA;EACA;EACA;EACA;EACA,cAAc;EACd,cAAc;EACf,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useWidgetConfig } from "../../providers/WidgetProvider/WidgetProvider.js";
|
|
2
|
-
import
|
|
2
|
+
import "../../types/widget.js";
|
|
3
3
|
import { useSwapOnly } from "../../hooks/useSwapOnly.js";
|
|
4
4
|
import { getConfigItemSets, isItemAllowedForSets } from "../../utils/item.js";
|
|
5
5
|
import { useChains } from "../../hooks/useChains.js";
|
|
@@ -33,7 +33,7 @@ function ChainOrderStoreProvider({ children, ...props }) {
|
|
|
33
33
|
});
|
|
34
34
|
const chainOrder = storeRef.current?.getState().initializeChains(filteredChains.map((chain) => chain.id), key);
|
|
35
35
|
const isSwapTo = swapOnly && key === "to";
|
|
36
|
-
const showAllNetworks = filteredChains.length > 1 && !hiddenUI?.includes(
|
|
36
|
+
const showAllNetworks = filteredChains.length > 1 && !hiddenUI?.includes("allNetworks") && !isSwapTo;
|
|
37
37
|
const urlValues = getDefaultValuesFromQueryString({ buildUrl });
|
|
38
38
|
const urlChainValue = key === "from" ? urlValues.fromChain : urlValues.toChain;
|
|
39
39
|
const initialIsAllNetworks = showAllNetworks && !(key === "from" ? fromChainConfig : toChainConfig) && !urlChainValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChainOrderStore.js","names":[],"sources":["../../../../src/stores/chains/ChainOrderStore.tsx"],"sourcesContent":["import { createContext, type JSX, useContext, useEffect, useRef } from 'react'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport { useChains } from '../../hooks/useChains.js'\nimport { useSwapOnly } from '../../hooks/useSwapOnly.js'\nimport { useExternalWalletProvider } from '../../providers/WalletProvider/useExternalWalletProvider.js'\nimport { useWidgetConfig } from '../../providers/WidgetProvider/WidgetProvider.js'\nimport { HiddenUI } from '../../types/widget.js'\nimport { getConfigItemSets, isItemAllowedForSets } from '../../utils/item.js'\nimport { getDefaultValuesFromQueryString } from '../form/getDefaultValuesFromQueryString.js'\nimport type { FormType } from '../form/types.js'\nimport { useFieldActions } from '../form/useFieldActions.js'\nimport type { PersistStoreProviderProps } from '../types.js'\nimport { createChainOrderStore } from './createChainOrderStore.js'\nimport type { ChainOrderState } from './types.js'\n\ntype ChainOrderStore = UseBoundStore<StoreApi<ChainOrderState>>\n\nconst ChainOrderStoreContext = createContext<ChainOrderStore | null>(null)\n\nexport function ChainOrderStoreProvider({\n children,\n ...props\n}: PersistStoreProviderProps): JSX.Element {\n const {\n chains: chainsConfig,\n hiddenUI,\n fromChain: fromChainConfig,\n toChain: toChainConfig,\n buildUrl,\n } = useWidgetConfig()\n const storeRef = useRef<ChainOrderStore>(null)\n const { chains } = useChains()\n const { setFieldValue, getFieldValues } = useFieldActions()\n const swapOnly = useSwapOnly()\n const { variant, subvariantOptions } = useWidgetConfig()\n const { externalChainTypes, useExternalWalletProvidersOnly } =\n useExternalWalletProvider()\n\n if (!storeRef.current) {\n storeRef.current = createChainOrderStore({\n ...props,\n })\n }\n\n useEffect(() => {\n if (chains) {\n ;(['from', 'to'] as FormType[]).forEach((key) => {\n const configChainIds = chainsConfig?.[key]\n const isFromKey = key === 'from'\n\n // Convert configChainIds to Sets for O(1) lookup\n const configChainIdsSet = getConfigItemSets(\n configChainIds,\n (chainIds) => new Set(chainIds)\n )\n const filteredChains = chains.filter((chain) => {\n const passesChainsConfigFilter = configChainIdsSet\n ? isItemAllowedForSets(chain.id, configChainIdsSet)\n : true\n // If the integrator uses external wallet management and has not opted in for partial wallet management,\n // restrict the displayed chains to those compatible with external wallet management.\n // This ensures users only see chains for which they can sign transactions.\n const passesWalletConfigFilter = isFromKey\n ? !useExternalWalletProvidersOnly ||\n externalChainTypes.includes(chain.chainType)\n : true\n return passesChainsConfigFilter && passesWalletConfigFilter\n })\n\n const chainOrder = storeRef.current?.getState().initializeChains(\n filteredChains.map((chain) => chain.id),\n key\n )\n\n const isSwapTo = swapOnly && key === 'to'\n\n // Show \"All networks\" button if there are multiple networks\n const showAllNetworks =\n filteredChains.length > 1 &&\n !hiddenUI?.includes(HiddenUI.AllNetworks) &&\n !isSwapTo\n\n // Initialize the isAllNetworks with true if the tab is shown,\n // there is no config chain value and no url chain value\n const urlValues = getDefaultValuesFromQueryString({ buildUrl })\n const urlChainValue =\n key === 'from' ? urlValues.fromChain : urlValues.toChain\n const configChainValue =\n key === 'from' ? fromChainConfig : toChainConfig\n const initialIsAllNetworks =\n showAllNetworks && !configChainValue && !urlChainValue\n storeRef.current?.getState().setIsAllNetworks(initialIsAllNetworks, key)\n storeRef.current?.getState().setShowAllNetworks(showAllNetworks, key)\n\n // If swap only, set the to chain to the from chain\n if (isSwapTo) {\n const [fromChainValue] = getFieldValues('fromChain')\n setFieldValue('toChain', fromChainValue)\n }\n\n // When \"All Networks\" is active, don't auto-select a chain from the\n // persisted chain order. This prevents stale cross-ecosystem selections\n // (e.g. EVM from + Solana to) from triggering the \"destination wallet\n // address required\" message after a page refresh.\n if (initialIsAllNetworks) {\n return\n }\n\n const [chainValue] = getFieldValues(`${key}Chain`)\n if (chainValue) {\n return\n }\n\n const firstAllowedPinnedChain = storeRef.current\n ?.getState()\n .pinnedChains?.find((chainId) =>\n filteredChains.some((chain) => chain.id === chainId)\n )\n if (\n variant === 'wide' &&\n !subvariantOptions?.wide?.disableChainSidebar &&\n firstAllowedPinnedChain\n ) {\n setFieldValue(`${key}Chain`, firstAllowedPinnedChain)\n } else if (chainOrder?.length) {\n setFieldValue(`${key}Chain`, chainOrder[0])\n }\n })\n }\n }, [\n chains,\n chainsConfig,\n externalChainTypes,\n getFieldValues,\n setFieldValue,\n useExternalWalletProvidersOnly,\n variant,\n subvariantOptions?.wide?.disableChainSidebar,\n hiddenUI,\n swapOnly,\n fromChainConfig,\n toChainConfig,\n buildUrl,\n ])\n\n return (\n <ChainOrderStoreContext.Provider value={storeRef.current}>\n {children}\n </ChainOrderStoreContext.Provider>\n )\n}\n\nfunction useChainOrderStoreContext() {\n const useStore = useContext(ChainOrderStoreContext)\n if (!useStore) {\n throw new Error(\n `You forgot to wrap your component in <${ChainOrderStoreProvider.name}>.`\n )\n }\n return useStore\n}\n\nexport function useChainOrderStore<T>(\n selector: (state: ChainOrderState) => T\n): T {\n const useStore = useChainOrderStoreContext()\n return useStore(useShallow(selector))\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,MAAM,yBAAyB,cAAsC,KAAK;AAE1E,SAAgB,wBAAwB,EACtC,UACA,GAAG,SACsC;CACzC,MAAM,EACJ,QAAQ,cACR,UACA,WAAW,iBACX,SAAS,eACT,aACE,iBAAiB;CACrB,MAAM,WAAW,OAAwB,KAAK;CAC9C,MAAM,EAAE,WAAW,WAAW;CAC9B,MAAM,EAAE,eAAe,mBAAmB,iBAAiB;CAC3D,MAAM,WAAW,aAAa;CAC9B,MAAM,EAAE,SAAS,sBAAsB,iBAAiB;CACxD,MAAM,EAAE,oBAAoB,mCAC1B,2BAA2B;AAE7B,KAAI,CAAC,SAAS,QACZ,UAAS,UAAU,sBAAsB,EACvC,GAAG,OACJ,CAAC;AAGJ,iBAAgB;AACd,MAAI,OACA,EAAC,QAAQ,KAAK,CAAgB,SAAS,QAAQ;GAC/C,MAAM,iBAAiB,eAAe;GACtC,MAAM,YAAY,QAAQ;GAG1B,MAAM,oBAAoB,kBACxB,iBACC,aAAa,IAAI,IAAI,SAAS,CAChC;GACD,MAAM,iBAAiB,OAAO,QAAQ,UAAU;IAC9C,MAAM,2BAA2B,oBAC7B,qBAAqB,MAAM,IAAI,kBAAkB,GACjD;IAIJ,MAAM,2BAA2B,YAC7B,CAAC,kCACD,mBAAmB,SAAS,MAAM,UAAU,GAC5C;AACJ,WAAO,4BAA4B;KACnC;GAEF,MAAM,aAAa,SAAS,SAAS,UAAU,CAAC,iBAC9C,eAAe,KAAK,UAAU,MAAM,GAAG,EACvC,IACD;GAED,MAAM,WAAW,YAAY,QAAQ;GAGrC,MAAM,kBACJ,eAAe,SAAS,KACxB,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"ChainOrderStore.js","names":[],"sources":["../../../../src/stores/chains/ChainOrderStore.tsx"],"sourcesContent":["import { createContext, type JSX, useContext, useEffect, useRef } from 'react'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport { useChains } from '../../hooks/useChains.js'\nimport { useSwapOnly } from '../../hooks/useSwapOnly.js'\nimport { useExternalWalletProvider } from '../../providers/WalletProvider/useExternalWalletProvider.js'\nimport { useWidgetConfig } from '../../providers/WidgetProvider/WidgetProvider.js'\nimport { HiddenUI } from '../../types/widget.js'\nimport { getConfigItemSets, isItemAllowedForSets } from '../../utils/item.js'\nimport { getDefaultValuesFromQueryString } from '../form/getDefaultValuesFromQueryString.js'\nimport type { FormType } from '../form/types.js'\nimport { useFieldActions } from '../form/useFieldActions.js'\nimport type { PersistStoreProviderProps } from '../types.js'\nimport { createChainOrderStore } from './createChainOrderStore.js'\nimport type { ChainOrderState } from './types.js'\n\ntype ChainOrderStore = UseBoundStore<StoreApi<ChainOrderState>>\n\nconst ChainOrderStoreContext = createContext<ChainOrderStore | null>(null)\n\nexport function ChainOrderStoreProvider({\n children,\n ...props\n}: PersistStoreProviderProps): JSX.Element {\n const {\n chains: chainsConfig,\n hiddenUI,\n fromChain: fromChainConfig,\n toChain: toChainConfig,\n buildUrl,\n } = useWidgetConfig()\n const storeRef = useRef<ChainOrderStore>(null)\n const { chains } = useChains()\n const { setFieldValue, getFieldValues } = useFieldActions()\n const swapOnly = useSwapOnly()\n const { variant, subvariantOptions } = useWidgetConfig()\n const { externalChainTypes, useExternalWalletProvidersOnly } =\n useExternalWalletProvider()\n\n if (!storeRef.current) {\n storeRef.current = createChainOrderStore({\n ...props,\n })\n }\n\n useEffect(() => {\n if (chains) {\n ;(['from', 'to'] as FormType[]).forEach((key) => {\n const configChainIds = chainsConfig?.[key]\n const isFromKey = key === 'from'\n\n // Convert configChainIds to Sets for O(1) lookup\n const configChainIdsSet = getConfigItemSets(\n configChainIds,\n (chainIds) => new Set(chainIds)\n )\n const filteredChains = chains.filter((chain) => {\n const passesChainsConfigFilter = configChainIdsSet\n ? isItemAllowedForSets(chain.id, configChainIdsSet)\n : true\n // If the integrator uses external wallet management and has not opted in for partial wallet management,\n // restrict the displayed chains to those compatible with external wallet management.\n // This ensures users only see chains for which they can sign transactions.\n const passesWalletConfigFilter = isFromKey\n ? !useExternalWalletProvidersOnly ||\n externalChainTypes.includes(chain.chainType)\n : true\n return passesChainsConfigFilter && passesWalletConfigFilter\n })\n\n const chainOrder = storeRef.current?.getState().initializeChains(\n filteredChains.map((chain) => chain.id),\n key\n )\n\n const isSwapTo = swapOnly && key === 'to'\n\n // Show \"All networks\" button if there are multiple networks\n const showAllNetworks =\n filteredChains.length > 1 &&\n !hiddenUI?.includes(HiddenUI.AllNetworks) &&\n !isSwapTo\n\n // Initialize the isAllNetworks with true if the tab is shown,\n // there is no config chain value and no url chain value\n const urlValues = getDefaultValuesFromQueryString({ buildUrl })\n const urlChainValue =\n key === 'from' ? urlValues.fromChain : urlValues.toChain\n const configChainValue =\n key === 'from' ? fromChainConfig : toChainConfig\n const initialIsAllNetworks =\n showAllNetworks && !configChainValue && !urlChainValue\n storeRef.current?.getState().setIsAllNetworks(initialIsAllNetworks, key)\n storeRef.current?.getState().setShowAllNetworks(showAllNetworks, key)\n\n // If swap only, set the to chain to the from chain\n if (isSwapTo) {\n const [fromChainValue] = getFieldValues('fromChain')\n setFieldValue('toChain', fromChainValue)\n }\n\n // When \"All Networks\" is active, don't auto-select a chain from the\n // persisted chain order. This prevents stale cross-ecosystem selections\n // (e.g. EVM from + Solana to) from triggering the \"destination wallet\n // address required\" message after a page refresh.\n if (initialIsAllNetworks) {\n return\n }\n\n const [chainValue] = getFieldValues(`${key}Chain`)\n if (chainValue) {\n return\n }\n\n const firstAllowedPinnedChain = storeRef.current\n ?.getState()\n .pinnedChains?.find((chainId) =>\n filteredChains.some((chain) => chain.id === chainId)\n )\n if (\n variant === 'wide' &&\n !subvariantOptions?.wide?.disableChainSidebar &&\n firstAllowedPinnedChain\n ) {\n setFieldValue(`${key}Chain`, firstAllowedPinnedChain)\n } else if (chainOrder?.length) {\n setFieldValue(`${key}Chain`, chainOrder[0])\n }\n })\n }\n }, [\n chains,\n chainsConfig,\n externalChainTypes,\n getFieldValues,\n setFieldValue,\n useExternalWalletProvidersOnly,\n variant,\n subvariantOptions?.wide?.disableChainSidebar,\n hiddenUI,\n swapOnly,\n fromChainConfig,\n toChainConfig,\n buildUrl,\n ])\n\n return (\n <ChainOrderStoreContext.Provider value={storeRef.current}>\n {children}\n </ChainOrderStoreContext.Provider>\n )\n}\n\nfunction useChainOrderStoreContext() {\n const useStore = useContext(ChainOrderStoreContext)\n if (!useStore) {\n throw new Error(\n `You forgot to wrap your component in <${ChainOrderStoreProvider.name}>.`\n )\n }\n return useStore\n}\n\nexport function useChainOrderStore<T>(\n selector: (state: ChainOrderState) => T\n): T {\n const useStore = useChainOrderStoreContext()\n return useStore(useShallow(selector))\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,MAA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AAsB,IAAI;AACxE,YAAS,SAAS,UAAU,CAAC,mBAAmB,iBAAiB,IAAI;AAGrE,OAAI,UAAU;IACZ,MAAM,CAAC,kBAAkB,eAAe,YAAY;AACpD,kBAAc,WAAW,eAAe;;AAO1C,OAAI,qBACF;GAGF,MAAM,CAAC,cAAc,eAAe,GAAG,IAAI,OAAO;AAClD,OAAI,WACF;GAGF,MAAM,0BAA0B,SAAS,SACrC,UAAU,CACX,cAAc,MAAM,YACnB,eAAe,MAAM,UAAU,MAAM,OAAO,QAAQ,CACrD;AACH,OACE,YAAY,UACZ,CAAC,mBAAmB,MAAM,uBAC1B,wBAEA,eAAc,GAAG,IAAI,QAAQ,wBAAwB;YAC5C,YAAY,OACrB,eAAc,GAAG,IAAI,QAAQ,WAAW,GAAG;IAE7C;IAEH;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA,mBAAmB,MAAM;EACzB;EACA;EACA;EACA;EACA;EACD,CAAC;AAEF,QACE,oBAAC,uBAAuB,UAAxB;EAAiC,OAAO,SAAS;EAC9C;EAC+B,CAAA;;AAItC,SAAS,4BAA4B;CACnC,MAAM,WAAW,WAAW,uBAAuB;AACnD,KAAI,CAAC,SACH,OAAM,IAAI,MACR,yCAAyC,wBAAwB,KAAK,IACvE;AAEH,QAAO;;AAGT,SAAgB,mBACd,UACG;AAEH,QADiB,2BAA2B,CAC5B,WAAW,SAAS,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { widgetEvents } from "../../hooks/useWidgetEvents.js";
|
|
2
|
-
import
|
|
2
|
+
import "../../types/events.js";
|
|
3
3
|
import { create } from "zustand";
|
|
4
4
|
import { persist } from "zustand/middleware";
|
|
5
5
|
const defaultChainState = {
|
|
@@ -68,7 +68,7 @@ const createChainOrderStore = ({ namePrefix }) => create()(persist((set, get) =>
|
|
|
68
68
|
pinnedChains.push(chainId);
|
|
69
69
|
return { pinnedChains };
|
|
70
70
|
});
|
|
71
|
-
widgetEvents.emit(
|
|
71
|
+
widgetEvents.emit("chainPinned", {
|
|
72
72
|
chainId,
|
|
73
73
|
pinned: !wasAlreadyPinned
|
|
74
74
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createChainOrderStore.js","names":[],"sources":["../../../../src/stores/chains/createChainOrderStore.ts"],"sourcesContent":["import type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\nimport { persist } from 'zustand/middleware'\nimport { widgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { WidgetEvent } from '../../types/events.js'\nimport type { PersistStoreProps } from '../types.js'\nimport type { ChainOrderState } from './types.js'\n\n// (10 tiles: 9 + 1 for \"All chains\")\nexport const maxGridItemsToShow = 10\nexport const maxChainsToShow: number = maxGridItemsToShow - 1\n// If there are more than maxChainsToShow chains to show,\n// -1 tile to show a button \"+ N\" more chains\nexport const maxChainsToOrder: number = maxChainsToShow - 1\n\nconst defaultChainState = {\n from: [],\n to: [],\n}\n\nexport const createChainOrderStore = ({\n namePrefix,\n}: PersistStoreProps): UseBoundStore<StoreApi<ChainOrderState>> =>\n create<ChainOrderState>()(\n persist(\n (set, get) => ({\n chainOrder: defaultChainState,\n fromIsAllNetworks: true,\n toIsAllNetworks: true,\n fromShowAllNetworks: true,\n toShowAllNetworks: true,\n availableChains: defaultChainState,\n pinnedChains: [],\n initializeChains: (chainIds, type) => {\n set((state: ChainOrderState) => {\n const chainOrder = state.chainOrder[type].filter((chainId) =>\n chainIds.includes(chainId)\n )\n const chainsToAdd = chainIds.filter(\n (chainId) => !chainOrder.includes(chainId)\n )\n if (chainOrder.length === maxChainsToOrder || !chainsToAdd.length) {\n return {\n availableChains: {\n ...state.availableChains,\n [type]: chainIds,\n },\n chainOrder: {\n ...state.chainOrder,\n [type]: chainOrder,\n },\n }\n }\n const chainsToAddLength = maxChainsToOrder - chainOrder.length\n for (let index = 0; index < chainsToAddLength; index++) {\n chainOrder.push(chainsToAdd[index])\n }\n return {\n availableChains: {\n ...state.availableChains,\n [type]: chainIds,\n },\n chainOrder: {\n ...state.chainOrder,\n [type]: chainOrder,\n },\n }\n })\n return get().chainOrder[type].slice(0, maxChainsToOrder)\n },\n setChain: (chainId, type) => {\n const state = get()\n if (\n state.chainOrder[type].includes(chainId) ||\n !state.availableChains[type].includes(chainId)\n ) {\n return\n }\n set((state: ChainOrderState) => {\n const chainOrder = [chainId, ...state.chainOrder[type]].slice(\n 0,\n maxChainsToOrder\n )\n return {\n chainOrder: {\n ...state.chainOrder,\n [type]: chainOrder,\n },\n }\n })\n },\n setIsAllNetworks: (isAllNetworks, formType) => {\n set({ [`${formType}IsAllNetworks`]: isAllNetworks })\n },\n setShowAllNetworks: (showAllNetworks, formType) => {\n set({ [`${formType}ShowAllNetworks`]: showAllNetworks })\n },\n setPinnedChain: (chainId) => {\n const currentPinnedChains = get().pinnedChains\n const wasAlreadyPinned = currentPinnedChains.includes(chainId)\n set((state: ChainOrderState) => {\n const pinnedChains = [...state.pinnedChains]\n if (wasAlreadyPinned) {\n return {\n pinnedChains: pinnedChains.filter((id) => id !== chainId),\n }\n }\n pinnedChains.push(chainId)\n return {\n pinnedChains,\n }\n })\n widgetEvents.emit(WidgetEvent.ChainPinned, {\n chainId,\n pinned: !wasAlreadyPinned,\n })\n },\n }),\n {\n name: `${namePrefix || 'li.fi'}-widget-chains-order`,\n version: 4,\n partialize: (state) => ({\n chainOrder: state.chainOrder,\n pinnedChains: state.pinnedChains,\n }),\n }\n )\n )\n"],"mappings":";;;;AAeA,MAAM,oBAAoB;CACxB,MAAM,EAAE;CACR,IAAI,EAAE;CACP;AAED,MAAa,yBAAyB,EACpC,iBAEA,QAAyB,CACvB,SACG,KAAK,SAAS;CACb,YAAY;CACZ,mBAAmB;CACnB,iBAAiB;CACjB,qBAAqB;CACrB,mBAAmB;CACnB,iBAAiB;CACjB,cAAc,EAAE;CAChB,mBAAmB,UAAU,SAAS;AACpC,OAAK,UAA2B;GAC9B,MAAM,aAAa,MAAM,WAAW,MAAM,QAAQ,YACh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;AAC1B,UAAO,EACL,cACD;IACD;AACF,eAAa,
|
|
1
|
+
{"version":3,"file":"createChainOrderStore.js","names":[],"sources":["../../../../src/stores/chains/createChainOrderStore.ts"],"sourcesContent":["import type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\nimport { persist } from 'zustand/middleware'\nimport { widgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { WidgetEvent } from '../../types/events.js'\nimport type { PersistStoreProps } from '../types.js'\nimport type { ChainOrderState } from './types.js'\n\n// (10 tiles: 9 + 1 for \"All chains\")\nexport const maxGridItemsToShow = 10\nexport const maxChainsToShow: number = maxGridItemsToShow - 1\n// If there are more than maxChainsToShow chains to show,\n// -1 tile to show a button \"+ N\" more chains\nexport const maxChainsToOrder: number = maxChainsToShow - 1\n\nconst defaultChainState = {\n from: [],\n to: [],\n}\n\nexport const createChainOrderStore = ({\n namePrefix,\n}: PersistStoreProps): UseBoundStore<StoreApi<ChainOrderState>> =>\n create<ChainOrderState>()(\n persist(\n (set, get) => ({\n chainOrder: defaultChainState,\n fromIsAllNetworks: true,\n toIsAllNetworks: true,\n fromShowAllNetworks: true,\n toShowAllNetworks: true,\n availableChains: defaultChainState,\n pinnedChains: [],\n initializeChains: (chainIds, type) => {\n set((state: ChainOrderState) => {\n const chainOrder = state.chainOrder[type].filter((chainId) =>\n chainIds.includes(chainId)\n )\n const chainsToAdd = chainIds.filter(\n (chainId) => !chainOrder.includes(chainId)\n )\n if (chainOrder.length === maxChainsToOrder || !chainsToAdd.length) {\n return {\n availableChains: {\n ...state.availableChains,\n [type]: chainIds,\n },\n chainOrder: {\n ...state.chainOrder,\n [type]: chainOrder,\n },\n }\n }\n const chainsToAddLength = maxChainsToOrder - chainOrder.length\n for (let index = 0; index < chainsToAddLength; index++) {\n chainOrder.push(chainsToAdd[index])\n }\n return {\n availableChains: {\n ...state.availableChains,\n [type]: chainIds,\n },\n chainOrder: {\n ...state.chainOrder,\n [type]: chainOrder,\n },\n }\n })\n return get().chainOrder[type].slice(0, maxChainsToOrder)\n },\n setChain: (chainId, type) => {\n const state = get()\n if (\n state.chainOrder[type].includes(chainId) ||\n !state.availableChains[type].includes(chainId)\n ) {\n return\n }\n set((state: ChainOrderState) => {\n const chainOrder = [chainId, ...state.chainOrder[type]].slice(\n 0,\n maxChainsToOrder\n )\n return {\n chainOrder: {\n ...state.chainOrder,\n [type]: chainOrder,\n },\n }\n })\n },\n setIsAllNetworks: (isAllNetworks, formType) => {\n set({ [`${formType}IsAllNetworks`]: isAllNetworks })\n },\n setShowAllNetworks: (showAllNetworks, formType) => {\n set({ [`${formType}ShowAllNetworks`]: showAllNetworks })\n },\n setPinnedChain: (chainId) => {\n const currentPinnedChains = get().pinnedChains\n const wasAlreadyPinned = currentPinnedChains.includes(chainId)\n set((state: ChainOrderState) => {\n const pinnedChains = [...state.pinnedChains]\n if (wasAlreadyPinned) {\n return {\n pinnedChains: pinnedChains.filter((id) => id !== chainId),\n }\n }\n pinnedChains.push(chainId)\n return {\n pinnedChains,\n }\n })\n widgetEvents.emit(WidgetEvent.ChainPinned, {\n chainId,\n pinned: !wasAlreadyPinned,\n })\n },\n }),\n {\n name: `${namePrefix || 'li.fi'}-widget-chains-order`,\n version: 4,\n partialize: (state) => ({\n chainOrder: state.chainOrder,\n pinnedChains: state.pinnedChains,\n }),\n }\n )\n )\n"],"mappings":";;;;AAeA,MAAM,oBAAoB;CACxB,MAAM,EAAE;CACR,IAAI,EAAE;CACP;AAED,MAAa,yBAAyB,EACpC,iBAEA,QAAyB,CACvB,SACG,KAAK,SAAS;CACb,YAAY;CACZ,mBAAmB;CACnB,iBAAiB;CACjB,qBAAqB;CACrB,mBAAmB;CACnB,iBAAiB;CACjB,cAAc,EAAE;CAChB,mBAAmB,UAAU,SAAS;AACpC,OAAK,UAA2B;GAC9B,MAAM,aAAa,MAAM,WAAW,MAAM,QAAQ,YAChD,SAAS,SAAS,QAAQ,CAC3B;GACD,MAAM,cAAc,SAAS,QAC1B,YAAY,CAA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Q,CAAC;GACV,CAAC;;CAEL,GACD;CACE,MAAM,GAAG,cAAc,QAAQ;CAC/B,SAAS;CACT,aAAa,WAAW;EACtB,YAAY,MAAM;EAClB,cAAc,MAAM;EACrB;CACF,CACF,CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useWidgetEvents } from "../../hooks/useWidgetEvents.js";
|
|
2
|
-
import
|
|
2
|
+
import "../../types/events.js";
|
|
3
3
|
import { useFormStore } from "./useFormStore.js";
|
|
4
4
|
import { useCallback } from "react";
|
|
5
5
|
//#region src/stores/form/useFieldActions.ts
|
|
@@ -18,7 +18,7 @@ const useFieldActions = () => {
|
|
|
18
18
|
const setFieldValueWithEmittedEvents = useCallback((fieldName, newValue, options) => {
|
|
19
19
|
const oldValue = actions.getFieldValues(fieldName)[0];
|
|
20
20
|
actions.setFieldValue(fieldName, newValue, options);
|
|
21
|
-
if (newValue !== oldValue) emitter.emit(
|
|
21
|
+
if (newValue !== oldValue) emitter.emit("formFieldChanged", {
|
|
22
22
|
fieldName,
|
|
23
23
|
newValue,
|
|
24
24
|
oldValue
|
|
@@ -37,7 +37,7 @@ const useFieldActions = () => {
|
|
|
37
37
|
}, []);
|
|
38
38
|
actions.setUserAndDefaultValues(formValues);
|
|
39
39
|
changedValues.forEach(({ fieldName, newValue, oldValue }) => {
|
|
40
|
-
emitter.emit(
|
|
40
|
+
emitter.emit("formFieldChanged", {
|
|
41
41
|
fieldName,
|
|
42
42
|
newValue,
|
|
43
43
|
oldValue
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFieldActions.js","names":[],"sources":["../../../../src/stores/form/useFieldActions.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport { useWidgetEvents } from '../../hooks/useWidgetEvents.js'\nimport type { FormFieldChanged } from '../../types/events.js'\nimport { WidgetEvent } from '../../types/events.js'\nimport type {\n DefaultValues,\n FormActions,\n FormFieldNames,\n GenericFormValue,\n SetOptions,\n} from './types.js'\nimport { useFormStore } from './useFormStore.js'\n\nexport const useFieldActions = (): FormActions => {\n const emitter = useWidgetEvents()\n const actions = useFormStore<FormActions>((store) => ({\n getFieldValues: store.getFieldValues,\n isTouched: store.isTouched,\n isDirty: store.isDirty,\n resetField: store.resetField,\n setAsTouched: store.setAsTouched,\n setDefaultValues: store.setDefaultValues,\n setFieldValue: store.setFieldValue,\n setUserAndDefaultValues: store.setUserAndDefaultValues,\n }))\n\n const setFieldValueWithEmittedEvents = useCallback(\n (\n fieldName: FormFieldNames,\n newValue: GenericFormValue,\n options?: SetOptions\n ) => {\n const oldValue = actions.getFieldValues(fieldName)[0]\n\n actions.setFieldValue(fieldName, newValue, options)\n\n if (newValue !== oldValue) {\n emitter.emit(WidgetEvent.FormFieldChanged, {\n fieldName,\n newValue,\n oldValue,\n } as FormFieldChanged)\n }\n },\n [actions, emitter]\n )\n\n const setUserAndDefaultValuesWithEmittedEvents = useCallback(\n (formValues: Partial<DefaultValues>) => {\n const formValuesKeys = Object.keys(formValues) as FormFieldNames[]\n\n const changedValues = formValuesKeys.reduce(\n (accum, fieldName) => {\n const oldValue = actions.getFieldValues(fieldName)[0]\n const newValue = formValues[fieldName]\n\n if (newValue !== oldValue) {\n accum.push({ fieldName, newValue, oldValue })\n }\n\n return accum\n },\n [] as {\n fieldName: FormFieldNames\n newValue: GenericFormValue\n oldValue: GenericFormValue\n }[]\n )\n\n actions.setUserAndDefaultValues(formValues)\n\n changedValues.forEach(({ fieldName, newValue, oldValue }) => {\n emitter.emit(WidgetEvent.FormFieldChanged, {\n fieldName,\n newValue,\n oldValue,\n } as FormFieldChanged)\n })\n },\n [actions, emitter]\n )\n\n return {\n getFieldValues: actions.getFieldValues,\n isTouched: actions.isTouched,\n isDirty: actions.isDirty,\n resetField: actions.resetField,\n setAsTouched: actions.setAsTouched,\n setDefaultValues: actions.setDefaultValues,\n setFieldValue: setFieldValueWithEmittedEvents,\n setUserAndDefaultValues: setUserAndDefaultValuesWithEmittedEvents,\n }\n}\n"],"mappings":";;;;;AAaA,MAAa,wBAAqC;CAChD,MAAM,UAAU,iBAAiB;CACjC,MAAM,UAAU,cAA2B,WAAW;EACpD,gBAAgB,MAAM;EACtB,WAAW,MAAM;EACjB,SAAS,MAAM;EACf,YAAY,MAAM;EAClB,cAAc,MAAM;EACpB,kBAAkB,MAAM;EACxB,eAAe,MAAM;EACrB,yBAAyB,MAAM;EAChC,EAAE;CAEH,MAAM,iCAAiC,aAEnC,WACA,UACA,YACG;EACH,MAAM,WAAW,QAAQ,eAAe,UAAU,CAAC;AAEnD,UAAQ,cAAc,WAAW,UAAU,QAAQ;AAEnD,MAAI,aAAa,SACf,SAAQ,
|
|
1
|
+
{"version":3,"file":"useFieldActions.js","names":[],"sources":["../../../../src/stores/form/useFieldActions.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport { useWidgetEvents } from '../../hooks/useWidgetEvents.js'\nimport type { FormFieldChanged } from '../../types/events.js'\nimport { WidgetEvent } from '../../types/events.js'\nimport type {\n DefaultValues,\n FormActions,\n FormFieldNames,\n GenericFormValue,\n SetOptions,\n} from './types.js'\nimport { useFormStore } from './useFormStore.js'\n\nexport const useFieldActions = (): FormActions => {\n const emitter = useWidgetEvents()\n const actions = useFormStore<FormActions>((store) => ({\n getFieldValues: store.getFieldValues,\n isTouched: store.isTouched,\n isDirty: store.isDirty,\n resetField: store.resetField,\n setAsTouched: store.setAsTouched,\n setDefaultValues: store.setDefaultValues,\n setFieldValue: store.setFieldValue,\n setUserAndDefaultValues: store.setUserAndDefaultValues,\n }))\n\n const setFieldValueWithEmittedEvents = useCallback(\n (\n fieldName: FormFieldNames,\n newValue: GenericFormValue,\n options?: SetOptions\n ) => {\n const oldValue = actions.getFieldValues(fieldName)[0]\n\n actions.setFieldValue(fieldName, newValue, options)\n\n if (newValue !== oldValue) {\n emitter.emit(WidgetEvent.FormFieldChanged, {\n fieldName,\n newValue,\n oldValue,\n } as FormFieldChanged)\n }\n },\n [actions, emitter]\n )\n\n const setUserAndDefaultValuesWithEmittedEvents = useCallback(\n (formValues: Partial<DefaultValues>) => {\n const formValuesKeys = Object.keys(formValues) as FormFieldNames[]\n\n const changedValues = formValuesKeys.reduce(\n (accum, fieldName) => {\n const oldValue = actions.getFieldValues(fieldName)[0]\n const newValue = formValues[fieldName]\n\n if (newValue !== oldValue) {\n accum.push({ fieldName, newValue, oldValue })\n }\n\n return accum\n },\n [] as {\n fieldName: FormFieldNames\n newValue: GenericFormValue\n oldValue: GenericFormValue\n }[]\n )\n\n actions.setUserAndDefaultValues(formValues)\n\n changedValues.forEach(({ fieldName, newValue, oldValue }) => {\n emitter.emit(WidgetEvent.FormFieldChanged, {\n fieldName,\n newValue,\n oldValue,\n } as FormFieldChanged)\n })\n },\n [actions, emitter]\n )\n\n return {\n getFieldValues: actions.getFieldValues,\n isTouched: actions.isTouched,\n isDirty: actions.isDirty,\n resetField: actions.resetField,\n setAsTouched: actions.setAsTouched,\n setDefaultValues: actions.setDefaultValues,\n setFieldValue: setFieldValueWithEmittedEvents,\n setUserAndDefaultValues: setUserAndDefaultValuesWithEmittedEvents,\n }\n}\n"],"mappings":";;;;;AAaA,MAAa,wBAAqC;CAChD,MAAM,UAAU,iBAAiB;CACjC,MAAM,UAAU,cAA2B,WAAW;EACpD,gBAAgB,MAAM;EACtB,WAAW,MAAM;EACjB,SAAS,MAAM;EACf,YAAY,MAAM;EAClB,cAAc,MAAM;EACpB,kBAAkB,MAAM;EACxB,eAAe,MAAM;EACrB,yBAAyB,MAAM;EAChC,EAAE;CAEH,MAAM,iCAAiC,aAEnC,WACA,UACA,YACG;EACH,MAAM,WAAW,QAAQ,eAAe,UAAU,CAAC;AAEnD,UAAQ,cAAc,WAAW,UAAU,QAAQ;AAEnD,MAAI,aAAa,SACf,SAAQ,KAAA,oBAAmC;GACzC;GACA;GACA;GACD,CAAqB;IAG1B,CAAC,SAAS,QAAQ,CACnB;CAED,MAAM,2CAA2C,aAC9C,eAAuC;EAGtC,MAAM,gBAFiB,OAAO,KAAK,WAAW,CAET,QAClC,OAAO,cAAc;GACpB,MAAM,WAAW,QAAQ,eAAe,UAAU,CAAC;GACnD,MAAM,WAAW,WAAW;AAE5B,OAAI,aAAa,SACf,OAAM,KAAK;IAAE;IAAW;IAAU;IAAU,CAAC;AAG/C,UAAO;KAET,EAAE,CAKH;AAED,UAAQ,wBAAwB,WAAW;AAE3C,gBAAc,SAAS,EAAE,WAAW,UAAU,eAAe;AAC3D,WAAQ,KAAA,oBAAmC;IACzC;IACA;IACA;IACD,CAAqB;IACtB;IAEJ,CAAC,SAAS,QAAQ,CACnB;AAED,QAAO;EACL,gBAAgB,QAAQ;EACxB,WAAW,QAAQ;EACnB,SAAS,QAAQ;EACjB,YAAY,QAAQ;EACpB,cAAc,QAAQ;EACtB,kBAAkB,QAAQ;EAC1B,eAAe;EACf,yBAAyB;EAC1B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { widgetEvents } from "../../hooks/useWidgetEvents.js";
|
|
2
|
-
import
|
|
2
|
+
import "../../types/events.js";
|
|
3
3
|
import { useBookmarkActions } from "../bookmarks/useBookmarkActions.js";
|
|
4
4
|
import { formDefaultValues } from "./createFormStore.js";
|
|
5
5
|
import { useImperativeHandle } from "react";
|
|
@@ -22,7 +22,7 @@ const useFormRef = (formStore, formRef) => {
|
|
|
22
22
|
const fieldValueOptions = options?.setUrlSearchParam ? { isTouched: options?.setUrlSearchParam } : void 0;
|
|
23
23
|
const oldValue = formStore.getState().getFieldValues(fieldName)[0];
|
|
24
24
|
formStore.getState().setFieldValue(fieldName, sanitizedValue, fieldValueOptions);
|
|
25
|
-
if (sanitizedValue !== oldValue) widgetEvents.emit(
|
|
25
|
+
if (sanitizedValue !== oldValue) widgetEvents.emit("formFieldChanged", {
|
|
26
26
|
fieldName,
|
|
27
27
|
newValue: sanitizedValue,
|
|
28
28
|
oldValue
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormRef.js","names":[],"sources":["../../../../src/stores/form/useFormRef.ts"],"sourcesContent":["import { useImperativeHandle } from 'react'\nimport { widgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { useBookmarkActions } from '../../stores/bookmarks/useBookmarkActions.js'\nimport { formDefaultValues } from '../../stores/form/createFormStore.js'\nimport type { FormFieldChanged } from '../../types/events.js'\nimport { WidgetEvent } from '../../types/events.js'\nimport type { FormRef } from '../../types/widget.js'\nimport type {\n FormFieldNames,\n FormStoreStore,\n GenericFormValue,\n} from './types.js'\n\nexport const useFormRef = (\n formStore: FormStoreStore,\n formRef?: FormRef\n): void => {\n const { setSelectedBookmark } = useBookmarkActions()\n\n useImperativeHandle(formRef, () => {\n const sanitizeValue: {\n [key: string]: (value: any) => GenericFormValue\n } = {\n fromAmount: (value) =>\n (typeof value === 'number' ? value?.toPrecision() : value) ||\n formDefaultValues.fromAmount,\n toAmount: (value) =>\n (typeof value === 'number' ? value?.toPrecision() : value) ||\n formDefaultValues.toAmount,\n toAddress: (value) => {\n const isToAddressObj = typeof value !== 'string'\n\n const address =\n (isToAddressObj ? value?.address : value) ||\n formDefaultValues.toAddress\n\n // we can assume that the toAddress has been passed as ToAddress object\n // and display it accordingly - this ensures that if a name is included\n // that it is displayed in the Send To Wallet form field correctly\n if (isToAddressObj) {\n setSelectedBookmark(value)\n }\n\n return address\n },\n }\n\n return {\n setFieldValue: (fieldName, value, options) => {\n const sanitizedValue = (\n sanitizeValue[fieldName] ? sanitizeValue[fieldName](value) : value\n ) as GenericFormValue\n\n const fieldValueOptions = options?.setUrlSearchParam\n ? { isTouched: options?.setUrlSearchParam }\n : undefined\n\n const oldValue = formStore\n .getState()\n .getFieldValues(fieldName as FormFieldNames)[0]\n\n formStore\n .getState()\n .setFieldValue(fieldName, sanitizedValue, fieldValueOptions)\n\n if (sanitizedValue !== oldValue) {\n widgetEvents.emit(WidgetEvent.FormFieldChanged, {\n fieldName,\n newValue: sanitizedValue,\n oldValue,\n } as FormFieldChanged)\n }\n },\n }\n }, [formStore, setSelectedBookmark])\n}\n"],"mappings":";;;;;;AAaA,MAAa,cACX,WACA,YACS;CACT,MAAM,EAAE,wBAAwB,oBAAoB;AAEpD,qBAAoB,eAAe;EACjC,MAAM,gBAEF;GACF,aAAa,WACV,OAAO,UAAU,WAAW,OAAO,aAAa,GAAG,UACpD,kBAAkB;GACpB,WAAW,WACR,OAAO,UAAU,WAAW,OAAO,aAAa,GAAG,UACpD,kBAAkB;GACpB,YAAY,UAAU;IACpB,MAAM,iBAAiB,OAAO,UAAU;IAExC,MAAM,WACH,iBAAiB,OAAO,UAAU,UACnC,kBAAkB;AAKpB,QAAI,eACF,qBAAoB,MAAM;AAG5B,WAAO;;GAEV;AAED,SAAO,EACL,gBAAgB,WAAW,OAAO,YAAY;GAC5C,MAAM,iBACJ,cAAc,aAAa,cAAc,WAAW,MAAM,GAAG;GAG/D,MAAM,oBAAoB,SAAS,oBAC/B,EAAE,WAAW,SAAS,mBAAmB,GACzC,KAAA;GAEJ,MAAM,WAAW,UACd,UAAU,CACV,eAAe,UAA4B,CAAC;AAE/C,aACG,UAAU,CACV,cAAc,WAAW,gBAAgB,kBAAkB;AAE9D,OAAI,mBAAmB,SACrB,cAAa,
|
|
1
|
+
{"version":3,"file":"useFormRef.js","names":[],"sources":["../../../../src/stores/form/useFormRef.ts"],"sourcesContent":["import { useImperativeHandle } from 'react'\nimport { widgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { useBookmarkActions } from '../../stores/bookmarks/useBookmarkActions.js'\nimport { formDefaultValues } from '../../stores/form/createFormStore.js'\nimport type { FormFieldChanged } from '../../types/events.js'\nimport { WidgetEvent } from '../../types/events.js'\nimport type { FormRef } from '../../types/widget.js'\nimport type {\n FormFieldNames,\n FormStoreStore,\n GenericFormValue,\n} from './types.js'\n\nexport const useFormRef = (\n formStore: FormStoreStore,\n formRef?: FormRef\n): void => {\n const { setSelectedBookmark } = useBookmarkActions()\n\n useImperativeHandle(formRef, () => {\n const sanitizeValue: {\n [key: string]: (value: any) => GenericFormValue\n } = {\n fromAmount: (value) =>\n (typeof value === 'number' ? value?.toPrecision() : value) ||\n formDefaultValues.fromAmount,\n toAmount: (value) =>\n (typeof value === 'number' ? value?.toPrecision() : value) ||\n formDefaultValues.toAmount,\n toAddress: (value) => {\n const isToAddressObj = typeof value !== 'string'\n\n const address =\n (isToAddressObj ? value?.address : value) ||\n formDefaultValues.toAddress\n\n // we can assume that the toAddress has been passed as ToAddress object\n // and display it accordingly - this ensures that if a name is included\n // that it is displayed in the Send To Wallet form field correctly\n if (isToAddressObj) {\n setSelectedBookmark(value)\n }\n\n return address\n },\n }\n\n return {\n setFieldValue: (fieldName, value, options) => {\n const sanitizedValue = (\n sanitizeValue[fieldName] ? sanitizeValue[fieldName](value) : value\n ) as GenericFormValue\n\n const fieldValueOptions = options?.setUrlSearchParam\n ? { isTouched: options?.setUrlSearchParam }\n : undefined\n\n const oldValue = formStore\n .getState()\n .getFieldValues(fieldName as FormFieldNames)[0]\n\n formStore\n .getState()\n .setFieldValue(fieldName, sanitizedValue, fieldValueOptions)\n\n if (sanitizedValue !== oldValue) {\n widgetEvents.emit(WidgetEvent.FormFieldChanged, {\n fieldName,\n newValue: sanitizedValue,\n oldValue,\n } as FormFieldChanged)\n }\n },\n }\n }, [formStore, setSelectedBookmark])\n}\n"],"mappings":";;;;;;AAaA,MAAa,cACX,WACA,YACS;CACT,MAAM,EAAE,wBAAwB,oBAAoB;AAEpD,qBAAoB,eAAe;EACjC,MAAM,gBAEF;GACF,aAAa,WACV,OAAO,UAAU,WAAW,OAAO,aAAa,GAAG,UACpD,kBAAkB;GACpB,WAAW,WACR,OAAO,UAAU,WAAW,OAAO,aAAa,GAAG,UACpD,kBAAkB;GACpB,YAAY,UAAU;IACpB,MAAM,iBAAiB,OAAO,UAAU;IAExC,MAAM,WACH,iBAAiB,OAAO,UAAU,UACnC,kBAAkB;AAKpB,QAAI,eACF,qBAAoB,MAAM;AAG5B,WAAO;;GAEV;AAED,SAAO,EACL,gBAAgB,WAAW,OAAO,YAAY;GAC5C,MAAM,iBACJ,cAAc,aAAa,cAAc,WAAW,MAAM,GAAG;GAG/D,MAAM,oBAAoB,SAAS,oBAC/B,EAAE,WAAW,SAAS,mBAAmB,GACzC,KAAA;GAEJ,MAAM,WAAW,UACd,UAAU,CACV,eAAe,UAA4B,CAAC;AAE/C,aACG,UAAU,CACV,cAAc,WAAW,gBAAgB,kBAAkB;AAE9D,OAAI,mBAAmB,SACrB,cAAa,KAAA,oBAAmC;IAC9C;IACA,UAAU;IACV;IACD,CAAqB;KAG3B;IACA,CAAC,WAAW,oBAAoB,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { hasEnumFlag } from "../../utils/enum.js";
|
|
2
|
-
import { RouteExecutionStatus } from "./types.js";
|
|
3
2
|
import { isRouteDone, isRouteFailed, isRoutePartiallyDone, isRouteRefunded } from "./utils.js";
|
|
4
3
|
import { create } from "zustand";
|
|
5
4
|
import { persist } from "zustand/middleware";
|
|
@@ -9,12 +8,12 @@ const createRouteExecutionStore = ({ namePrefix }) => create()(persist((set, get
|
|
|
9
8
|
setExecutableRoute: (route, observableRouteIds) => {
|
|
10
9
|
if (!get().routes[route.id]) set((state) => {
|
|
11
10
|
const routes = { ...state.routes };
|
|
12
|
-
Object.keys(routes).filter((routeId) => !observableRouteIds?.includes(routeId) && hasEnumFlag(routes[routeId].status,
|
|
11
|
+
Object.keys(routes).filter((routeId) => !observableRouteIds?.includes(routeId) && hasEnumFlag(routes[routeId].status, 1)).forEach((routeId) => {
|
|
13
12
|
delete routes[routeId];
|
|
14
13
|
});
|
|
15
14
|
routes[route.id] = {
|
|
16
15
|
route,
|
|
17
|
-
status:
|
|
16
|
+
status: 1
|
|
18
17
|
};
|
|
19
18
|
return { routes };
|
|
20
19
|
});
|
|
@@ -29,16 +28,16 @@ const createRouteExecutionStore = ({ namePrefix }) => create()(persist((set, get
|
|
|
29
28
|
}
|
|
30
29
|
} };
|
|
31
30
|
if (isRouteFailed(route)) {
|
|
32
|
-
updatedState.routes[route.id].status =
|
|
31
|
+
updatedState.routes[route.id].status = 8;
|
|
33
32
|
return updatedState;
|
|
34
33
|
}
|
|
35
34
|
if (isRouteDone(route)) {
|
|
36
|
-
updatedState.routes[route.id].status =
|
|
37
|
-
if (isRoutePartiallyDone(route)) updatedState.routes[route.id].status |=
|
|
38
|
-
else if (isRouteRefunded(route)) updatedState.routes[route.id].status |=
|
|
35
|
+
updatedState.routes[route.id].status = 4;
|
|
36
|
+
if (isRoutePartiallyDone(route)) updatedState.routes[route.id].status |= 16;
|
|
37
|
+
else if (isRouteRefunded(route)) updatedState.routes[route.id].status |= 32;
|
|
39
38
|
return updatedState;
|
|
40
39
|
}
|
|
41
|
-
if (route.steps.some((step) => step.execution)) updatedState.routes[route.id].status =
|
|
40
|
+
if (route.steps.some((step) => step.execution)) updatedState.routes[route.id].status = 2;
|
|
42
41
|
return updatedState;
|
|
43
42
|
});
|
|
44
43
|
},
|
|
@@ -47,7 +46,7 @@ const createRouteExecutionStore = ({ namePrefix }) => create()(persist((set, get
|
|
|
47
46
|
Object.keys(routes).filter((routeId) => {
|
|
48
47
|
const route = routes[routeId];
|
|
49
48
|
if (accountAddresses && !accountAddresses.includes(route?.route.fromAddress ?? "")) return false;
|
|
50
|
-
return type === "completed" ? hasEnumFlag(route?.status ?? 0,
|
|
49
|
+
return type === "completed" ? hasEnumFlag(route?.status ?? 0, 4) : type === "failed" ? hasEnumFlag(route?.status ?? 0, 8) : !hasEnumFlag(route?.status ?? 0, 4);
|
|
51
50
|
}).forEach((routeId) => {
|
|
52
51
|
delete routes[routeId];
|
|
53
52
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRouteExecutionStore.js","names":[],"sources":["../../../../src/stores/routes/createRouteExecutionStore.ts"],"sourcesContent":["import type { Route, RouteExtended } from '@lifi/sdk'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\nimport { persist } from 'zustand/middleware'\nimport { hasEnumFlag } from '../../utils/enum.js'\nimport type { PersistStoreProps } from '../types.js'\nimport type { RouteExecution, RouteExecutionState } from './types.js'\nimport { RouteExecutionStatus } from './types.js'\nimport {\n isRouteDone,\n isRouteFailed,\n isRoutePartiallyDone,\n isRouteRefunded,\n} from './utils.js'\n\nexport const createRouteExecutionStore = ({\n namePrefix,\n}: PersistStoreProps): UseBoundStore<StoreApi<RouteExecutionState>> =>\n create<RouteExecutionState>()(\n persist(\n (set, get) => ({\n routes: {},\n setExecutableRoute: (route: Route, observableRouteIds?: string[]) => {\n if (!get().routes[route.id]) {\n set((state: RouteExecutionState) => {\n const routes = { ...state.routes }\n // clean previous idle routes\n Object.keys(routes)\n .filter(\n (routeId) =>\n !observableRouteIds?.includes(routeId) &&\n hasEnumFlag(\n routes[routeId]!.status,\n RouteExecutionStatus.Idle\n )\n )\n .forEach((routeId) => {\n delete routes[routeId]\n })\n routes[route.id] = {\n route,\n status: RouteExecutionStatus.Idle,\n }\n return {\n routes,\n }\n })\n }\n },\n updateRoute: (route: RouteExtended) => {\n if (get().routes[route.id]) {\n set((state: RouteExecutionState) => {\n const updatedState = {\n routes: {\n ...state.routes,\n [route.id]: { ...state.routes[route.id]!, route },\n },\n }\n const isFailed = isRouteFailed(route)\n if (isFailed) {\n updatedState.routes[route.id]!.status =\n RouteExecutionStatus.Failed\n return updatedState\n }\n const isDone = isRouteDone(route)\n if (isDone) {\n updatedState.routes[route.id]!.status =\n RouteExecutionStatus.Done\n if (isRoutePartiallyDone(route)) {\n updatedState.routes[route.id]!.status |=\n RouteExecutionStatus.Partial\n } else if (isRouteRefunded(route)) {\n updatedState.routes[route.id]!.status |=\n RouteExecutionStatus.Refunded\n }\n return updatedState\n }\n const isLoading = route.steps.some((step) => step.execution)\n if (isLoading) {\n updatedState.routes[route.id]!.status =\n RouteExecutionStatus.Pending\n }\n return updatedState\n })\n }\n },\n deleteRoutes: (type, accountAddresses) =>\n set((state: RouteExecutionState) => {\n const routes = { ...state.routes }\n Object.keys(routes)\n .filter((routeId) => {\n const route = routes[routeId]\n if (\n accountAddresses &&\n !accountAddresses.includes(route?.route.fromAddress ?? '')\n ) {\n return false\n }\n return type === 'completed'\n ? hasEnumFlag(route?.status ?? 0, RouteExecutionStatus.Done)\n : type === 'failed'\n ? hasEnumFlag(\n route?.status ?? 0,\n RouteExecutionStatus.Failed\n )\n : !hasEnumFlag(\n route?.status ?? 0,\n RouteExecutionStatus.Done\n )\n })\n .forEach((routeId) => {\n delete routes[routeId]\n })\n return {\n routes,\n }\n }),\n deleteRoute: (routeId: string) => {\n if (get().routes[routeId]) {\n set((state: RouteExecutionState) => {\n const routes = { ...state.routes }\n delete routes[routeId]\n return {\n routes,\n }\n })\n }\n },\n }),\n {\n name: `${namePrefix || 'li.fi'}-widget-routes`,\n // Bump version on breaking changes to the stored structure.\n version: 4,\n // Clear stored routes on any version mismatch to avoid errors from incompatible data shapes.\n migrate: () => ({ routes: {} }),\n partialize: (state) => ({ routes: state.routes }),\n merge: (persistedState: any, currentState: RouteExecutionState) => {\n const state = {\n ...currentState,\n ...persistedState,\n } as RouteExecutionState\n try {\n // Keep only the most recent 100 routes, evicting the oldest when the\n // limit is exceeded.\n const maxStoredRoutes = 100\n const allRoutes = Object.values(state.routes) as RouteExecution[]\n const storedRoutes = allRoutes\n .sort(\n (a, b) =>\n (b.route.steps[0]?.execution?.startedAt ?? 0) -\n (a.route.steps[0]?.execution?.startedAt ?? 0)\n )\n .slice(0, maxStoredRoutes)\n const keepIds = new Set(storedRoutes.map((r) => r.route.id))\n for (const id of Object.keys(state.routes)) {\n if (!keepIds.has(id)) {\n delete state.routes[id]\n }\n }\n } catch (error) {\n console.error(error)\n }\n return state\n },\n }\n )\n )\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"createRouteExecutionStore.js","names":[],"sources":["../../../../src/stores/routes/createRouteExecutionStore.ts"],"sourcesContent":["import type { Route, RouteExtended } from '@lifi/sdk'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\nimport { persist } from 'zustand/middleware'\nimport { hasEnumFlag } from '../../utils/enum.js'\nimport type { PersistStoreProps } from '../types.js'\nimport type { RouteExecution, RouteExecutionState } from './types.js'\nimport { RouteExecutionStatus } from './types.js'\nimport {\n isRouteDone,\n isRouteFailed,\n isRoutePartiallyDone,\n isRouteRefunded,\n} from './utils.js'\n\nexport const createRouteExecutionStore = ({\n namePrefix,\n}: PersistStoreProps): UseBoundStore<StoreApi<RouteExecutionState>> =>\n create<RouteExecutionState>()(\n persist(\n (set, get) => ({\n routes: {},\n setExecutableRoute: (route: Route, observableRouteIds?: string[]) => {\n if (!get().routes[route.id]) {\n set((state: RouteExecutionState) => {\n const routes = { ...state.routes }\n // clean previous idle routes\n Object.keys(routes)\n .filter(\n (routeId) =>\n !observableRouteIds?.includes(routeId) &&\n hasEnumFlag(\n routes[routeId]!.status,\n RouteExecutionStatus.Idle\n )\n )\n .forEach((routeId) => {\n delete routes[routeId]\n })\n routes[route.id] = {\n route,\n status: RouteExecutionStatus.Idle,\n }\n return {\n routes,\n }\n })\n }\n },\n updateRoute: (route: RouteExtended) => {\n if (get().routes[route.id]) {\n set((state: RouteExecutionState) => {\n const updatedState = {\n routes: {\n ...state.routes,\n [route.id]: { ...state.routes[route.id]!, route },\n },\n }\n const isFailed = isRouteFailed(route)\n if (isFailed) {\n updatedState.routes[route.id]!.status =\n RouteExecutionStatus.Failed\n return updatedState\n }\n const isDone = isRouteDone(route)\n if (isDone) {\n updatedState.routes[route.id]!.status =\n RouteExecutionStatus.Done\n if (isRoutePartiallyDone(route)) {\n updatedState.routes[route.id]!.status |=\n RouteExecutionStatus.Partial\n } else if (isRouteRefunded(route)) {\n updatedState.routes[route.id]!.status |=\n RouteExecutionStatus.Refunded\n }\n return updatedState\n }\n const isLoading = route.steps.some((step) => step.execution)\n if (isLoading) {\n updatedState.routes[route.id]!.status =\n RouteExecutionStatus.Pending\n }\n return updatedState\n })\n }\n },\n deleteRoutes: (type, accountAddresses) =>\n set((state: RouteExecutionState) => {\n const routes = { ...state.routes }\n Object.keys(routes)\n .filter((routeId) => {\n const route = routes[routeId]\n if (\n accountAddresses &&\n !accountAddresses.includes(route?.route.fromAddress ?? '')\n ) {\n return false\n }\n return type === 'completed'\n ? hasEnumFlag(route?.status ?? 0, RouteExecutionStatus.Done)\n : type === 'failed'\n ? hasEnumFlag(\n route?.status ?? 0,\n RouteExecutionStatus.Failed\n )\n : !hasEnumFlag(\n route?.status ?? 0,\n RouteExecutionStatus.Done\n )\n })\n .forEach((routeId) => {\n delete routes[routeId]\n })\n return {\n routes,\n }\n }),\n deleteRoute: (routeId: string) => {\n if (get().routes[routeId]) {\n set((state: RouteExecutionState) => {\n const routes = { ...state.routes }\n delete routes[routeId]\n return {\n routes,\n }\n })\n }\n },\n }),\n {\n name: `${namePrefix || 'li.fi'}-widget-routes`,\n // Bump version on breaking changes to the stored structure.\n version: 4,\n // Clear stored routes on any version mismatch to avoid errors from incompatible data shapes.\n migrate: () => ({ routes: {} }),\n partialize: (state) => ({ routes: state.routes }),\n merge: (persistedState: any, currentState: RouteExecutionState) => {\n const state = {\n ...currentState,\n ...persistedState,\n } as RouteExecutionState\n try {\n // Keep only the most recent 100 routes, evicting the oldest when the\n // limit is exceeded.\n const maxStoredRoutes = 100\n const allRoutes = Object.values(state.routes) as RouteExecution[]\n const storedRoutes = allRoutes\n .sort(\n (a, b) =>\n (b.route.steps[0]?.execution?.startedAt ?? 0) -\n (a.route.steps[0]?.execution?.startedAt ?? 0)\n )\n .slice(0, maxStoredRoutes)\n const keepIds = new Set(storedRoutes.map((r) => r.route.id))\n for (const id of Object.keys(state.routes)) {\n if (!keepIds.has(id)) {\n delete state.routes[id]\n }\n }\n } catch (error) {\n console.error(error)\n }\n return state\n },\n }\n )\n )\n"],"mappings":";;;;;AAeA,MAAa,6BAA6B,EACxC,iBAEA,QAA6B,CAC3B,SACG,KAAK,SAAS;CACb,QAAQ,EAAE;CACV,qBAAqB,OAAc,uBAAkC;AACnE,MAAI,CAAC,K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O,UAAU,GAAA,EAElB;IACP,CACD,SAAS,YAAY;AACpB,UAAO,OAAO;IACd;AACJ,SAAO,EACL,QACD;GACD;CACJ,cAAc,YAAoB;AAChC,MAAI,KAAK,CAAC,OAAO,SACf,MAAK,UAA+B;GAClC,MAAM,SAAS,EAAE,GAAG,MAAM,QAAQ;AAClC,UAAO,OAAO;AACd,UAAO,EACL,QACD;IACD;;CAGP,GACD;CACE,MAAM,GAAG,cAAc,QAAQ;CAE/B,SAAS;CAET,gBAAgB,EAAE,QAAQ,EAAE,EAAE;CAC9B,aAAa,WAAW,EAAE,QAAQ,MAAM,QAAQ;CAChD,QAAQ,gBAAqB,iBAAsC;EACjE,MAAM,QAAQ;GACZ,GAAG;GACH,GAAG;GACJ;AACD,MAAI;GAKF,MAAM,eADY,OAAO,OAAO,MAAM,OAAO,CAE1C,MACE,GAAG,OACD,EAAE,MAAM,MAAM,IAAI,WAAW,aAAa,MAC1C,EAAE,MAAM,MAAM,IAAI,WAAW,aAAa,GAC9C,CACA,MAAM,GARe,IAQI;GAC5B,MAAM,UAAU,IAAI,IAAI,aAAa,KAAK,MAAM,EAAE,MAAM,GAAG,CAAC;AAC5D,QAAK,MAAM,MAAM,OAAO,KAAK,MAAM,OAAO,CACxC,KAAI,CAAC,QAAQ,IAAI,GAAG,CAClB,QAAO,MAAM,OAAO;WAGjB,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;;CAEV,CACF,CACF"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { RouteExecutionStatus } from "./types.js";
|
|
2
1
|
import { useRouteExecutionStore } from "./RouteExecutionStore.js";
|
|
3
2
|
import { useCallback, useMemo } from "react";
|
|
4
3
|
import { useAccount } from "@lifi/wallet-management";
|
|
@@ -13,8 +12,8 @@ const useRouteExecutionIndicator = () => {
|
|
|
13
12
|
return useRouteExecutionStore(useCallback((state) => {
|
|
14
13
|
const recentOwnedRoutes = Object.values(state.routes).filter((route) => accountAddresses.includes(route.route.fromAddress) && isRecentTransaction(route));
|
|
15
14
|
return {
|
|
16
|
-
failed: recentOwnedRoutes.some((r) => r.status ===
|
|
17
|
-
active: recentOwnedRoutes.some((r) => r.status ===
|
|
15
|
+
failed: recentOwnedRoutes.some((r) => r.status === 8),
|
|
16
|
+
active: recentOwnedRoutes.some((r) => r.status === 2)
|
|
18
17
|
};
|
|
19
18
|
}, [accountAddresses]));
|
|
20
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouteExecutionIndicator.js","names":[],"sources":["../../../../src/stores/routes/useRouteExecutionIndicator.ts"],"sourcesContent":["import { useAccount } from '@lifi/wallet-management'\nimport { useCallback, useMemo } from 'react'\nimport { useRouteExecutionStore } from './RouteExecutionStore.js'\nimport type { RouteExecution, RouteExecutionState } from './types.js'\nimport { RouteExecutionStatus } from './types.js'\n\nexport type RouteExecutionIndicator = {\n failed: boolean\n active: boolean\n}\n\nconst isRecentTransaction = (route: RouteExecution): boolean => {\n const startedAt = route.route.steps[0]?.execution?.startedAt ?? 0\n return startedAt > 0 && Date.now() - startedAt < 1000 * 60 * 60 * 24 // 1 day\n}\n\nexport const useRouteExecutionIndicator = (): RouteExecutionIndicator => {\n const { accounts } = useAccount()\n const accountAddresses = useMemo(\n () => accounts.map((account) => account.address),\n [accounts]\n )\n const selector = useCallback(\n (state: RouteExecutionState): RouteExecutionIndicator => {\n const routes = Object.values(state.routes) as RouteExecution[]\n const recentOwnedRoutes = routes.filter(\n (route) =>\n accountAddresses.includes(route.route.fromAddress) &&\n isRecentTransaction(route)\n )\n return {\n failed: recentOwnedRoutes.some(\n (r) => r.status === RouteExecutionStatus.Failed\n ),\n active: recentOwnedRoutes.some(\n (r) => r.status === RouteExecutionStatus.Pending\n ),\n }\n },\n [accountAddresses]\n )\n return useRouteExecutionStore(selector)\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRouteExecutionIndicator.js","names":[],"sources":["../../../../src/stores/routes/useRouteExecutionIndicator.ts"],"sourcesContent":["import { useAccount } from '@lifi/wallet-management'\nimport { useCallback, useMemo } from 'react'\nimport { useRouteExecutionStore } from './RouteExecutionStore.js'\nimport type { RouteExecution, RouteExecutionState } from './types.js'\nimport { RouteExecutionStatus } from './types.js'\n\nexport type RouteExecutionIndicator = {\n failed: boolean\n active: boolean\n}\n\nconst isRecentTransaction = (route: RouteExecution): boolean => {\n const startedAt = route.route.steps[0]?.execution?.startedAt ?? 0\n return startedAt > 0 && Date.now() - startedAt < 1000 * 60 * 60 * 24 // 1 day\n}\n\nexport const useRouteExecutionIndicator = (): RouteExecutionIndicator => {\n const { accounts } = useAccount()\n const accountAddresses = useMemo(\n () => accounts.map((account) => account.address),\n [accounts]\n )\n const selector = useCallback(\n (state: RouteExecutionState): RouteExecutionIndicator => {\n const routes = Object.values(state.routes) as RouteExecution[]\n const recentOwnedRoutes = routes.filter(\n (route) =>\n accountAddresses.includes(route.route.fromAddress) &&\n isRecentTransaction(route)\n )\n return {\n failed: recentOwnedRoutes.some(\n (r) => r.status === RouteExecutionStatus.Failed\n ),\n active: recentOwnedRoutes.some(\n (r) => r.status === RouteExecutionStatus.Pending\n ),\n }\n },\n [accountAddresses]\n )\n return useRouteExecutionStore(selector)\n}\n"],"mappings":";;;;AAWA,MAAM,uBAAuB,UAAmC;CAC9D,MAAM,YAAY,MAAM,MAAM,MAAM,IAAI,WAAW,aAAa;AAChE,QAAO,YAAY,KAAK,KAAK,KAAK,GAAG,YAAY,MAAO,KAAK,KAAK;;AAGpE,MAAa,mCAA4D;CACvE,MAAM,EAAE,aAAa,YAAY;CACjC,MAAM,mBAAmB,cACjB,SAAS,KAAK,YAAY,QAAQ,QAAQ,EAChD,CAAC,SAAS,CACX;AAoBD,QAAO,uBAnBU,aACd,UAAwD;EAEvD,MAAM,oBADS,OAAO,OAAO,MAAM,OAAO,CACT,QAC9B,UACC,iBAAiB,SAAS,MAAM,MAAM,YAAY,IAClD,oBAAoB,MAAM,CAC7B;AACD,SAAO;GACL,QAAQ,kBAAkB,MACvB,MAAM,EAAE,WAAA,EACV;GACD,QAAQ,kBAAkB,MACvB,MAAM,EAAE,WAAA,EACV;GACF;IAEH,CAAC,iBAAiB,CACnB,CACsC"}
|
|
@@ -104,11 +104,7 @@ const createSettingsStore = (config) => create()(persist((set, get) => ({
|
|
|
104
104
|
});
|
|
105
105
|
return state;
|
|
106
106
|
},
|
|
107
|
-
migrate: (
|
|
108
|
-
if (version === 1) persistedState.slippage = defaultConfigurableSettings.slippage;
|
|
109
|
-
if (version <= 3) persistedState.routePriority = "CHEAPEST";
|
|
110
|
-
return persistedState;
|
|
111
|
-
},
|
|
107
|
+
migrate: () => ({}),
|
|
112
108
|
onRehydrateStorage: () => {
|
|
113
109
|
const initializeLanguageSettings = async (state, initialLanguage) => {
|
|
114
110
|
const customLanguages = Object.keys(config?.languageResources || {}).filter((key) => !allLanguages.includes(key));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSettingsStore.js","names":[],"sources":["../../../../src/stores/settings/createSettingsStore.ts"],"sourcesContent":["/** biome-ignore-all lint/correctness/noUnusedVariables: allowed in this store */\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\nimport { persist } from 'zustand/middleware'\nimport { allLanguages } from '../../providers/I18nProvider/constants.js'\nimport { loadLocale } from '../../providers/I18nProvider/i18n.js'\nimport type { LanguageKey } from '../../providers/I18nProvider/types.js'\nimport type { WidgetConfig } from '../../types/widget.js'\nimport type { SettingsProps, SettingsState } from './types.js'\nimport { SettingsToolTypes } from './types.js'\nimport { getStateValues } from './utils/getStateValues.js'\n\nexport const defaultSlippage = undefined\n\nexport const defaultConfigurableSettings: Pick<\n SettingsState,\n 'routePriority' | 'slippage' | 'gasPrice'\n> = {\n routePriority: 'CHEAPEST',\n slippage: defaultSlippage,\n gasPrice: 'normal',\n}\n\nconst defaultSettings: SettingsProps = {\n gasPrice: 'normal',\n enabledAutoRefuel: true,\n disabledBridges: [],\n disabledExchanges: [],\n enabledBridges: [],\n enabledExchanges: [],\n _enabledBridges: {},\n _enabledExchanges: {},\n smallBalanceThreshold: undefined,\n}\n\nexport const createSettingsStore = (\n config: WidgetConfig\n): UseBoundStore<StoreApi<SettingsState>> =>\n create<SettingsState>()(\n persist(\n (set, get) => ({\n ...defaultSettings,\n setValue: (key, value) =>\n set(() => ({\n [key]: value,\n })),\n setValues: (values: Partial<SettingsProps>) =>\n set(() => ({\n ...values,\n })),\n getSettings: () => getStateValues(get()),\n getValue: (key) => get()[key],\n initializeTools: (toolType, tools, reset) => {\n if (!tools.length) {\n return\n }\n set((state) => {\n const updatedState = { ...state }\n if (!reset) {\n // Add new tools\n tools.forEach((tool) => {\n if (!Object.hasOwn(updatedState[`_enabled${toolType}`], tool)) {\n updatedState[`_enabled${toolType}`][tool] = true\n }\n })\n // Filter tools we no longer have\n updatedState[`_enabled${toolType}`] = Object.fromEntries(\n Object.entries(updatedState[`_enabled${toolType}`]).filter(\n ([key]) => tools.includes(key)\n )\n )\n } else {\n tools.forEach((tool) => {\n updatedState[`_enabled${toolType}`][tool] = true\n })\n }\n const enabledToolKeys = Object.keys(\n updatedState[`_enabled${toolType}`]\n )\n updatedState[`enabled${toolType}`] = enabledToolKeys.filter(\n (key) => updatedState[`_enabled${toolType}`][key]\n )\n updatedState[`disabled${toolType}`] = enabledToolKeys.filter(\n (key) => !updatedState[`_enabled${toolType}`][key]\n )\n return updatedState\n })\n },\n setToolValue: (toolType, tool, value) =>\n set((state) => {\n const enabledTools = {\n ...state[`_enabled${toolType}`],\n [tool]: value,\n }\n const enabledToolKeys = Object.keys(enabledTools)\n return {\n [`_enabled${toolType}`]: enabledTools,\n [`enabled${toolType}`]: enabledToolKeys.filter(\n (key) => enabledTools[key]\n ),\n [`disabled${toolType}`]: enabledToolKeys.filter(\n (key) => !enabledTools[key]\n ),\n }\n }),\n toggleToolKeys: (toolType, toolKeys) =>\n set((state) => {\n const allKeysInCollectionEnabled = toolKeys.every(\n (toolKey) => state[`_enabled${toolType}`][toolKey]\n )\n\n // then toggle those keys to false\n const updatedTools = toolKeys.reduce(\n (accum, toolKey) => {\n accum[toolKey] = !allKeysInCollectionEnabled\n return accum\n },\n {\n ...state[`_enabled${toolType}`],\n }\n )\n\n const enableKeys: string[] = []\n const disabledKeys: string[] = []\n\n Object.entries(updatedTools).forEach(([key, value]) => {\n if (value) {\n enableKeys.push(key)\n } else {\n disabledKeys.push(key)\n }\n })\n\n return {\n [`_enabled${toolType}`]: updatedTools,\n [`enabled${toolType}`]: enableKeys,\n [`disabled${toolType}`]: disabledKeys,\n }\n }),\n reset: (bridges, exchanges) => {\n set(() => ({\n ...defaultSettings,\n ...defaultConfigurableSettings,\n }))\n get().initializeTools('Bridges', bridges, true)\n get().initializeTools('Exchanges', exchanges, true)\n return { ...get() }\n },\n }),\n {\n name: 'li.fi-widget-settings',\n version: 6,\n partialize: (state) => {\n const {\n disabledBridges,\n disabledExchanges,\n enabledBridges,\n enabledExchanges,\n ...partializedState\n } = state\n return partializedState\n },\n merge: (persistedState: any, currentState: SettingsState) => {\n const state = { ...currentState, ...persistedState }\n SettingsToolTypes.forEach((toolType) => {\n if (persistedState?.[`_enabled${toolType}`]) {\n const enabledToolKeys = Object.keys(\n persistedState[`_enabled${toolType}`]\n )\n state[`enabled${toolType}`] = enabledToolKeys.filter(\n (key) => persistedState[`_enabled${toolType}`][key]\n )\n state[`disabled${toolType}`] = enabledToolKeys.filter(\n (key) => !persistedState[`_enabled${toolType}`][key]\n )\n }\n })\n return state\n },\n migrate: (persistedState: any, version) => {\n if (version === 1) {\n persistedState.slippage = defaultConfigurableSettings.slippage\n }\n if (version <= 3) {\n persistedState.routePriority = 'CHEAPEST'\n }\n return persistedState as SettingsState\n },\n onRehydrateStorage: () => {\n const initializeLanguageSettings = async (\n state: SettingsState,\n initialLanguage?: string\n ) => {\n const customLanguages = Object.keys(\n config?.languageResources || {}\n ).filter((key) => !allLanguages.includes(key as LanguageKey))\n if (\n initialLanguage &&\n // Custom language resources and English are added statically.\n initialLanguage !== 'en' &&\n !customLanguages.includes(initialLanguage)\n ) {\n await loadLocale(\n initialLanguage as LanguageKey,\n config?.languageResources?.[initialLanguage as LanguageKey]\n ).then((languageResource) => {\n state.setValues({\n language: initialLanguage,\n languageCache: languageResource,\n })\n })\n }\n }\n return (state?: SettingsState) => {\n // Preload translations (from existing translation files)\n if (state) {\n // NB: State always exists unless there is any error\n initializeLanguageSettings(\n state,\n state.getValue('language') || config?.languages?.default\n )\n }\n }\n },\n }\n )\n )\n"],"mappings":";;;;;;AAcA,MAAa,8BAGT;CACF,eAAe;CACf,UAAA,KAAA;CACA,UAAU;CACX;AAED,MAAM,kBAAiC;CACrC,UAAU;CACV,mBAAmB;CACnB,iBAAiB,EAAE;CACnB,mBAAmB,EAAE;CACrB,gBAAgB,EAAE;CAClB,kBAAkB,EAAE;CACpB,iBAAiB,EAAE;CACnB,mBAAmB,EAAE;CACrB,uBAAuB,KAAA;CACxB;AAED,MAAa,uBACX,WAEA,QAAuB,CACrB,SACG,KAAK,SAAS;CACb,GAAG;CACH,WAAW,KAAK,UACd,WAAW,GACR,MAAM,OACR,EAAE;CACL,YAAY,WACV,WAAW,EACT,GAAG,QACJ,EAAE;CACL,mBAAmB,eAAe,KAAK,CAAC;CACxC,WAAW,QAAQ,KAAK,CAAC;CACzB,kBAAkB,UAAU,OAAO,UAAU;AAC3C,MAAI,CAAC,MAAM,OACT;AAEF,OAAK,UAAU;GACb,MAAM,eAAe,EAAE,GAAG,OAAO;AACjC,OAAI,CAAC,OAAO;AAEV,UAAM,SAAS,SAAS;AACtB,SAAI,CAAC,OAAO,OAAO,aAAa,WAAW,aAAa,KAAK,CAC3D,cAAa,WAAW,YAAY,QAAQ;MAE9C;AAEF,iBAAa,WAAW,cAAc,OAAO,YAC3C,OAAO,QAAQ,aAAa,WAAW,YAAY,CAAC,QACjD,CAAC,SAAS,MAAM,SAAS,IAAI,CAC/B,CACF;SAED,OAAM,SAAS,SAAS;AACtB,iBAAa,W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;CACT,aAAa,UAAU;EACrB,MAAM,EACJ,iBACA,mBACA,gBACA,kBACA,GAAG,qBACD;AACJ,SAAO;;CAET,QAAQ,gBAAqB,iBAAgC;EAC3D,MAAM,QAAQ;GAAE,GAAG;GAAc,GAAG;GAAgB;AACpD,oBAAkB,SAAS,aAAa;AACtC,OAAI,iBAAiB,WAAW,aAAa;IAC3C,MAAM,kBAAkB,OAAO,KAC7B,eAAe,WAAW,YAC3B;AACD,UAAM,UAAU,cAAc,gBAAgB,QAC3C,QAAQ,eAAe,WAAW,YAAY,KAChD;AACD,UAAM,WAAW,cAAc,gBAAgB,QAC5C,QAAQ,CAAC,eAAe,WAAW,YAAY,KACjD;;IAEH;AACF,SAAO;;CAET,UAAU,gBAAqB,YAAY;AACzC,MAAI,YAAY,EACd,gBAAe,WAAW,4BAA4B;AAExD,MAAI,WAAW,EACb,gBAAe,gBAAgB;AAEjC,SAAO;;CAET,0BAA0B;EACxB,MAAM,6BAA6B,OACjC,OACA,oBACG;GACH,MAAM,kBAAkB,OAAO,KAC7B,QAAQ,qBAAqB,EAAE,CAChC,CAAC,QAAQ,QAAQ,CAAC,aAAa,SAAS,IAAmB,CAAC;AAC7D,OACE,mBAEA,oBAAoB,QACpB,CAAC,gBAAgB,SAAS,gBAAgB,CAE1C,OAAM,WACJ,iBACA,QAAQ,oBAAoB,iBAC7B,CAAC,MAAM,qBAAqB;AAC3B,UAAM,UAAU;KACd,UAAU;KACV,eAAe;KAChB,CAAC;KACF;;AAGN,UAAQ,UAA0B;AAEhC,OAAI,MAEF,4BACE,OACA,MAAM,SAAS,WAAW,IAAI,QAAQ,WAAW,QAClD;;;CAIR,CACF,CACF"}
|
|
1
|
+
{"version":3,"file":"createSettingsStore.js","names":[],"sources":["../../../../src/stores/settings/createSettingsStore.ts"],"sourcesContent":["/** biome-ignore-all lint/correctness/noUnusedVariables: allowed in this store */\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\nimport { persist } from 'zustand/middleware'\nimport { allLanguages } from '../../providers/I18nProvider/constants.js'\nimport { loadLocale } from '../../providers/I18nProvider/i18n.js'\nimport type { LanguageKey } from '../../providers/I18nProvider/types.js'\nimport type { WidgetConfig } from '../../types/widget.js'\nimport type { SettingsProps, SettingsState } from './types.js'\nimport { SettingsToolTypes } from './types.js'\nimport { getStateValues } from './utils/getStateValues.js'\n\nexport const defaultSlippage = undefined\n\nexport const defaultConfigurableSettings: Pick<\n SettingsState,\n 'routePriority' | 'slippage' | 'gasPrice'\n> = {\n routePriority: 'CHEAPEST',\n slippage: defaultSlippage,\n gasPrice: 'normal',\n}\n\nconst defaultSettings: SettingsProps = {\n gasPrice: 'normal',\n enabledAutoRefuel: true,\n disabledBridges: [],\n disabledExchanges: [],\n enabledBridges: [],\n enabledExchanges: [],\n _enabledBridges: {},\n _enabledExchanges: {},\n smallBalanceThreshold: undefined,\n}\n\nexport const createSettingsStore = (\n config: WidgetConfig\n): UseBoundStore<StoreApi<SettingsState>> =>\n create<SettingsState>()(\n persist(\n (set, get) => ({\n ...defaultSettings,\n setValue: (key, value) =>\n set(() => ({\n [key]: value,\n })),\n setValues: (values: Partial<SettingsProps>) =>\n set(() => ({\n ...values,\n })),\n getSettings: () => getStateValues(get()),\n getValue: (key) => get()[key],\n initializeTools: (toolType, tools, reset) => {\n if (!tools.length) {\n return\n }\n set((state) => {\n const updatedState = { ...state }\n if (!reset) {\n // Add new tools\n tools.forEach((tool) => {\n if (!Object.hasOwn(updatedState[`_enabled${toolType}`], tool)) {\n updatedState[`_enabled${toolType}`][tool] = true\n }\n })\n // Filter tools we no longer have\n updatedState[`_enabled${toolType}`] = Object.fromEntries(\n Object.entries(updatedState[`_enabled${toolType}`]).filter(\n ([key]) => tools.includes(key)\n )\n )\n } else {\n tools.forEach((tool) => {\n updatedState[`_enabled${toolType}`][tool] = true\n })\n }\n const enabledToolKeys = Object.keys(\n updatedState[`_enabled${toolType}`]\n )\n updatedState[`enabled${toolType}`] = enabledToolKeys.filter(\n (key) => updatedState[`_enabled${toolType}`][key]\n )\n updatedState[`disabled${toolType}`] = enabledToolKeys.filter(\n (key) => !updatedState[`_enabled${toolType}`][key]\n )\n return updatedState\n })\n },\n setToolValue: (toolType, tool, value) =>\n set((state) => {\n const enabledTools = {\n ...state[`_enabled${toolType}`],\n [tool]: value,\n }\n const enabledToolKeys = Object.keys(enabledTools)\n return {\n [`_enabled${toolType}`]: enabledTools,\n [`enabled${toolType}`]: enabledToolKeys.filter(\n (key) => enabledTools[key]\n ),\n [`disabled${toolType}`]: enabledToolKeys.filter(\n (key) => !enabledTools[key]\n ),\n }\n }),\n toggleToolKeys: (toolType, toolKeys) =>\n set((state) => {\n const allKeysInCollectionEnabled = toolKeys.every(\n (toolKey) => state[`_enabled${toolType}`][toolKey]\n )\n\n // then toggle those keys to false\n const updatedTools = toolKeys.reduce(\n (accum, toolKey) => {\n accum[toolKey] = !allKeysInCollectionEnabled\n return accum\n },\n {\n ...state[`_enabled${toolType}`],\n }\n )\n\n const enableKeys: string[] = []\n const disabledKeys: string[] = []\n\n Object.entries(updatedTools).forEach(([key, value]) => {\n if (value) {\n enableKeys.push(key)\n } else {\n disabledKeys.push(key)\n }\n })\n\n return {\n [`_enabled${toolType}`]: updatedTools,\n [`enabled${toolType}`]: enableKeys,\n [`disabled${toolType}`]: disabledKeys,\n }\n }),\n reset: (bridges, exchanges) => {\n set(() => ({\n ...defaultSettings,\n ...defaultConfigurableSettings,\n }))\n get().initializeTools('Bridges', bridges, true)\n get().initializeTools('Exchanges', exchanges, true)\n return { ...get() }\n },\n }),\n {\n name: 'li.fi-widget-settings',\n version: 6,\n partialize: (state) => {\n const {\n disabledBridges,\n disabledExchanges,\n enabledBridges,\n enabledExchanges,\n ...partializedState\n } = state\n return partializedState\n },\n merge: (persistedState: any, currentState: SettingsState) => {\n const state = { ...currentState, ...persistedState }\n SettingsToolTypes.forEach((toolType) => {\n if (persistedState?.[`_enabled${toolType}`]) {\n const enabledToolKeys = Object.keys(\n persistedState[`_enabled${toolType}`]\n )\n state[`enabled${toolType}`] = enabledToolKeys.filter(\n (key) => persistedState[`_enabled${toolType}`][key]\n )\n state[`disabled${toolType}`] = enabledToolKeys.filter(\n (key) => !persistedState[`_enabled${toolType}`][key]\n )\n }\n })\n return state\n },\n migrate: () => ({}),\n onRehydrateStorage: () => {\n const initializeLanguageSettings = async (\n state: SettingsState,\n initialLanguage?: string\n ) => {\n const customLanguages = Object.keys(\n config?.languageResources || {}\n ).filter((key) => !allLanguages.includes(key as LanguageKey))\n if (\n initialLanguage &&\n // Custom language resources and English are added statically.\n initialLanguage !== 'en' &&\n !customLanguages.includes(initialLanguage)\n ) {\n await loadLocale(\n initialLanguage as LanguageKey,\n config?.languageResources?.[initialLanguage as LanguageKey]\n ).then((languageResource) => {\n state.setValues({\n language: initialLanguage,\n languageCache: languageResource,\n })\n })\n }\n }\n return (state?: SettingsState) => {\n // Preload translations (from existing translation files)\n if (state) {\n // NB: State always exists unless there is any error\n initializeLanguageSettings(\n state,\n state.getValue('language') || config?.languages?.default\n )\n }\n }\n },\n }\n )\n )\n"],"mappings":";;;;;;AAcA,MAAa,8BAGT;CACF,eAAe;CACf,UAAA,KAAA;CACA,UAAU;CACX;AAED,MAAM,kBAAiC;CACrC,UAAU;CACV,mBAAmB;CACnB,iBAAiB,EAAE;CACnB,mBAAmB,EAAE;CACrB,gBAAgB,EAAE;CAClB,kBAAkB,EAAE;CACpB,iBAAiB,EAAE;CACnB,mBAAmB,EAAE;CACrB,uBAAuB,KAAA;CACxB;AAED,MAAa,uBACX,WAEA,QAAuB,CACrB,SACG,KAAK,SAAS;CACb,GAAG;CACH,WAAW,KAAK,UACd,WAAW,GACR,MAAM,OACR,EAAE;CACL,YAAY,WACV,WAAW,EACT,GAAG,QACJ,EAAE;CACL,mBAAmB,eAAe,KAAK,CAAC;CACxC,WAAW,QAAQ,KAAK,CAAC;CACzB,kBAAkB,UAAU,OAAO,UAAU;AAC3C,MAAI,CAAC,MAAM,OACT;AAEF,OA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W,IAAI,QAAQ,WAAW,QAClD;;;CAIR,CACF,CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useWidgetEvents } from "../../hooks/useWidgetEvents.js";
|
|
2
|
-
import
|
|
2
|
+
import "../../types/events.js";
|
|
3
3
|
import { deepEqual } from "../../utils/deepEqual.js";
|
|
4
4
|
import { defaultConfigurableSettings } from "./createSettingsStore.js";
|
|
5
5
|
import { useSettingsStore } from "./SettingsStore.js";
|
|
@@ -10,7 +10,7 @@ const emitEventOnChange = (emitter, actions, settingFunction, ...args) => {
|
|
|
10
10
|
settingFunction(...args);
|
|
11
11
|
const newSettings = actions.getSettings();
|
|
12
12
|
if (!deepEqual(oldSettings, newSettings)) Object.keys(oldSettings).forEach((toolKey) => {
|
|
13
|
-
if (!deepEqual(oldSettings[toolKey], newSettings[toolKey])) emitter.emit(
|
|
13
|
+
if (!deepEqual(oldSettings[toolKey], newSettings[toolKey])) emitter.emit("settingUpdated", {
|
|
14
14
|
setting: toolKey,
|
|
15
15
|
newValue: newSettings[toolKey],
|
|
16
16
|
oldValue: oldSettings[toolKey],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSettingsActions.js","names":[],"sources":["../../../../src/stores/settings/useSettingsActions.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport type { widgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { useWidgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { WidgetEvent } from '../../types/events.js'\nimport type { WidgetConfig } from '../../types/widget.js'\nimport { deepEqual } from '../../utils/deepEqual.js'\nimport { defaultConfigurableSettings } from './createSettingsStore.js'\nimport { useSettingsStore } from './SettingsStore.js'\nimport type {\n SettingsActions,\n SettingsProps,\n SettingsToolType,\n ValueSetter,\n} from './types.js'\n\nconst emitEventOnChange = <T extends (...args: any[]) => any>(\n emitter: typeof widgetEvents,\n actions: Omit<SettingsActions, 'initializeTools'>,\n settingFunction: T,\n ...args: Parameters<T>\n) => {\n const oldSettings = actions.getSettings()\n\n settingFunction(...args)\n\n const newSettings = actions.getSettings()\n\n if (!deepEqual(oldSettings, newSettings)) {\n ;(Object.keys(oldSettings) as (keyof SettingsProps)[]).forEach(\n (toolKey) => {\n if (!deepEqual(oldSettings[toolKey], newSettings[toolKey])) {\n emitter.emit(WidgetEvent.SettingUpdated, {\n setting: toolKey,\n newValue: newSettings[toolKey],\n oldValue: oldSettings[toolKey],\n newSettings: newSettings,\n oldSettings: oldSettings,\n })\n }\n }\n )\n }\n}\n\nexport const useSettingsActions = (): {\n setValue: ValueSetter<SettingsProps>\n setValues: (values: Partial<SettingsProps>) => void\n setDefaultSettings: (config?: WidgetConfig) => void\n resetSettings: (bridges: string[], exchanges: string[]) => void\n setToolValue: (\n toolType: SettingsToolType,\n tool: string,\n value: boolean\n ) => void\n toggleToolKeys: (toolType: SettingsToolType, toolKeys: string[]) => void\n} => {\n const emitter = useWidgetEvents()\n const actions = useSettingsStore((state) => ({\n setValue: state.setValue,\n setValues: state.setValues,\n getValue: state.getValue,\n getSettings: state.getSettings,\n reset: state.reset,\n setToolValue: state.setToolValue,\n toggleToolKeys: state.toggleToolKeys,\n }))\n\n const setValueWithEmittedEvent = useCallback<ValueSetter<SettingsProps>>(\n (value, newValue) => {\n const setting = value as keyof SettingsProps\n emitEventOnChange(emitter, actions, actions.setValue, setting, newValue)\n },\n [emitter, actions]\n )\n\n const setValuesWithEmittedEvent = useCallback(\n (values: Partial<SettingsProps>) => {\n Object.entries(values).forEach(([key, value]) => {\n setValueWithEmittedEvent(key as keyof SettingsProps, value)\n })\n },\n [setValueWithEmittedEvent]\n )\n\n const setDefaultSettingsWithEmittedEvents = useCallback(\n (config?: WidgetConfig) => {\n const slippage = actions.getValue('slippage')\n const routePriority = actions.getValue('routePriority')\n const gasPrice = actions.getValue('gasPrice')\n\n const defaultSlippage =\n (config?.slippage || config?.sdkConfig?.routeOptions?.slippage || 0) *\n 100\n const defaultRoutePriority =\n config?.routePriority || config?.sdkConfig?.routeOptions?.order\n\n defaultConfigurableSettings.slippage = (\n defaultSlippage || defaultConfigurableSettings.slippage\n )?.toString()\n\n defaultConfigurableSettings.routePriority =\n defaultRoutePriority || defaultConfigurableSettings.routePriority\n\n if (!slippage) {\n setValueWithEmittedEvent(\n 'slippage',\n defaultConfigurableSettings.slippage\n )\n }\n if (!routePriority) {\n setValueWithEmittedEvent(\n 'routePriority',\n defaultConfigurableSettings.routePriority\n )\n }\n if (!gasPrice) {\n setValueWithEmittedEvent(\n 'gasPrice',\n defaultConfigurableSettings.gasPrice\n )\n }\n },\n [actions, setValueWithEmittedEvent]\n )\n\n const resetWithEmittedEvents = useCallback(\n (bridges: string[], exchanges: string[]) => {\n emitEventOnChange(emitter, actions, actions.reset, bridges, exchanges)\n },\n [emitter, actions]\n )\n\n const setToolValueWithEmittedEvents = useCallback(\n (toolType: SettingsToolType, tool: string, value: boolean) => {\n emitEventOnChange(\n emitter,\n actions,\n actions.setToolValue,\n toolType,\n tool,\n value\n )\n },\n [emitter, actions]\n )\n\n const toggleToolKeysWithEmittedEvents = useCallback(\n (toolType: SettingsToolType, toolKeys: string[]) => {\n emitEventOnChange(\n emitter,\n actions,\n actions.toggleToolKeys,\n toolType,\n toolKeys\n )\n },\n [emitter, actions]\n )\n\n return {\n setValue: setValueWithEmittedEvent,\n setValues: setValuesWithEmittedEvent,\n setDefaultSettings: setDefaultSettingsWithEmittedEvents,\n resetSettings: resetWithEmittedEvents,\n setToolValue: setToolValueWithEmittedEvents,\n toggleToolKeys: toggleToolKeysWithEmittedEvents,\n }\n}\n"],"mappings":";;;;;;;AAeA,MAAM,qBACJ,SACA,SACA,iBACA,GAAG,SACA;CACH,MAAM,cAAc,QAAQ,aAAa;AAEzC,iBAAgB,GAAG,KAAK;CAExB,MAAM,cAAc,QAAQ,aAAa;AAEzC,KAAI,CAAC,UAAU,aAAa,YAAY,CACpC,QAAO,KAAK,YAAY,CAA6B,SACpD,YAAY;AACX,MAAI,CAAC,UAAU,YAAY,UAAU,YAAY,SAAS,CACxD,SAAQ,
|
|
1
|
+
{"version":3,"file":"useSettingsActions.js","names":[],"sources":["../../../../src/stores/settings/useSettingsActions.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport type { widgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { useWidgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { WidgetEvent } from '../../types/events.js'\nimport type { WidgetConfig } from '../../types/widget.js'\nimport { deepEqual } from '../../utils/deepEqual.js'\nimport { defaultConfigurableSettings } from './createSettingsStore.js'\nimport { useSettingsStore } from './SettingsStore.js'\nimport type {\n SettingsActions,\n SettingsProps,\n SettingsToolType,\n ValueSetter,\n} from './types.js'\n\nconst emitEventOnChange = <T extends (...args: any[]) => any>(\n emitter: typeof widgetEvents,\n actions: Omit<SettingsActions, 'initializeTools'>,\n settingFunction: T,\n ...args: Parameters<T>\n) => {\n const oldSettings = actions.getSettings()\n\n settingFunction(...args)\n\n const newSettings = actions.getSettings()\n\n if (!deepEqual(oldSettings, newSettings)) {\n ;(Object.keys(oldSettings) as (keyof SettingsProps)[]).forEach(\n (toolKey) => {\n if (!deepEqual(oldSettings[toolKey], newSettings[toolKey])) {\n emitter.emit(WidgetEvent.SettingUpdated, {\n setting: toolKey,\n newValue: newSettings[toolKey],\n oldValue: oldSettings[toolKey],\n newSettings: newSettings,\n oldSettings: oldSettings,\n })\n }\n }\n )\n }\n}\n\nexport const useSettingsActions = (): {\n setValue: ValueSetter<SettingsProps>\n setValues: (values: Partial<SettingsProps>) => void\n setDefaultSettings: (config?: WidgetConfig) => void\n resetSettings: (bridges: string[], exchanges: string[]) => void\n setToolValue: (\n toolType: SettingsToolType,\n tool: string,\n value: boolean\n ) => void\n toggleToolKeys: (toolType: SettingsToolType, toolKeys: string[]) => void\n} => {\n const emitter = useWidgetEvents()\n const actions = useSettingsStore((state) => ({\n setValue: state.setValue,\n setValues: state.setValues,\n getValue: state.getValue,\n getSettings: state.getSettings,\n reset: state.reset,\n setToolValue: state.setToolValue,\n toggleToolKeys: state.toggleToolKeys,\n }))\n\n const setValueWithEmittedEvent = useCallback<ValueSetter<SettingsProps>>(\n (value, newValue) => {\n const setting = value as keyof SettingsProps\n emitEventOnChange(emitter, actions, actions.setValue, setting, newValue)\n },\n [emitter, actions]\n )\n\n const setValuesWithEmittedEvent = useCallback(\n (values: Partial<SettingsProps>) => {\n Object.entries(values).forEach(([key, value]) => {\n setValueWithEmittedEvent(key as keyof SettingsProps, value)\n })\n },\n [setValueWithEmittedEvent]\n )\n\n const setDefaultSettingsWithEmittedEvents = useCallback(\n (config?: WidgetConfig) => {\n const slippage = actions.getValue('slippage')\n const routePriority = actions.getValue('routePriority')\n const gasPrice = actions.getValue('gasPrice')\n\n const defaultSlippage =\n (config?.slippage || config?.sdkConfig?.routeOptions?.slippage || 0) *\n 100\n const defaultRoutePriority =\n config?.routePriority || config?.sdkConfig?.routeOptions?.order\n\n defaultConfigurableSettings.slippage = (\n defaultSlippage || defaultConfigurableSettings.slippage\n )?.toString()\n\n defaultConfigurableSettings.routePriority =\n defaultRoutePriority || defaultConfigurableSettings.routePriority\n\n if (!slippage) {\n setValueWithEmittedEvent(\n 'slippage',\n defaultConfigurableSettings.slippage\n )\n }\n if (!routePriority) {\n setValueWithEmittedEvent(\n 'routePriority',\n defaultConfigurableSettings.routePriority\n )\n }\n if (!gasPrice) {\n setValueWithEmittedEvent(\n 'gasPrice',\n defaultConfigurableSettings.gasPrice\n )\n }\n },\n [actions, setValueWithEmittedEvent]\n )\n\n const resetWithEmittedEvents = useCallback(\n (bridges: string[], exchanges: string[]) => {\n emitEventOnChange(emitter, actions, actions.reset, bridges, exchanges)\n },\n [emitter, actions]\n )\n\n const setToolValueWithEmittedEvents = useCallback(\n (toolType: SettingsToolType, tool: string, value: boolean) => {\n emitEventOnChange(\n emitter,\n actions,\n actions.setToolValue,\n toolType,\n tool,\n value\n )\n },\n [emitter, actions]\n )\n\n const toggleToolKeysWithEmittedEvents = useCallback(\n (toolType: SettingsToolType, toolKeys: string[]) => {\n emitEventOnChange(\n emitter,\n actions,\n actions.toggleToolKeys,\n toolType,\n toolKeys\n )\n },\n [emitter, actions]\n )\n\n return {\n setValue: setValueWithEmittedEvent,\n setValues: setValuesWithEmittedEvent,\n setDefaultSettings: setDefaultSettingsWithEmittedEvents,\n resetSettings: resetWithEmittedEvents,\n setToolValue: setToolValueWithEmittedEvents,\n toggleToolKeys: toggleToolKeysWithEmittedEvents,\n }\n}\n"],"mappings":";;;;;;;AAeA,MAAM,qBACJ,SACA,SACA,iBACA,GAAG,SACA;CACH,MAAM,cAAc,QAAQ,aAAa;AAEzC,iBAAgB,GAAG,KAAK;CAExB,MAAM,cAAc,QAAQ,aAAa;AAEzC,KAAI,CAAC,UAAU,aAAa,YAAY,CACpC,QAAO,KAAK,YAAY,CAA6B,SACpD,YAAY;AACX,MAAI,CAAC,UAAU,YAAY,UAAU,YAAY,SAAS,CACxD,SAAQ,KAAA,kBAAiC;GACvC,SAAS;GACT,UAAU,YAAY;GACtB,UAAU,YAAY;GACT;GACA;GACd,CAAC;GAGP;;AAIL,MAAa,2BAWR;CACH,MAAM,UAAU,iBAAiB;CACjC,MAAM,UAAU,kBAAkB,WAAW;EAC3C,UAAU,MAAM;EAChB,WAAW,MAAM;EACjB,UAAU,MAAM;EAChB,aAAa,MAAM;EACnB,OAAO,MAAM;EACb,cAAc,MAAM;EACpB,gBAAgB,MAAM;EACvB,EAAE;CAEH,MAAM,2BAA2B,aAC9B,OAAO,aAAa;EACnB,MAAM,UAAU;AAChB,oBAAkB,SAAS,SAAS,QAAQ,UAAU,SAAS,SAAS;IAE1E,CAAC,SAAS,QAAQ,CACnB;AAsFD,QAAO;EACL,UAAU;EACV,WAtFgC,aAC/B,WAAmC;AAClC,UAAO,QAAQ,OAAO,CAAC,SAAS,CAAC,KAAK,WAAW;AAC/C,6BAAyB,KAA4B,MAAM;KAC3D;KAEJ,CAAC,yBAAyB,CAC3B;EAgFC,oBA9E0C,aACzC,WAA0B;GACzB,MAAM,WAAW,QAAQ,SAAS,WAAW;GAC7C,MAAM,gBAAgB,QAAQ,SAAS,gBAAgB;GACvD,MAAM,WAAW,QAAQ,SAAS,WAAW;GAE7C,MAAM,mBACH,QAAQ,YAAY,QAAQ,WAAW,cAAc,YAAY,KAClE;GACF,MAAM,uBACJ,QAAQ,iBAAiB,QAAQ,WAAW,cAAc;AAE5D,+BAA4B,YAC1B,mBAAmB,4BAA4B,WAC9C,UAAU;AAEb,+BAA4B,gBAC1B,wBAAwB,4BAA4B;AAEtD,OAAI,CAAC,SACH,0BACE,YACA,4BAA4B,SAC7B;AAEH,OAAI,CAAC,cACH,0BACE,iBACA,4BAA4B,cAC7B;AAEH,OAAI,CAAC,SACH,0BACE,YACA,4BAA4B,SAC7B;KAGL,CAAC,SAAS,yBAAyB,CACpC;EAwCC,eAtC6B,aAC5B,SAAmB,cAAwB;AAC1C,qBAAkB,SAAS,SAAS,QAAQ,OAAO,SAAS,UAAU;KAExE,CAAC,SAAS,QAAQ,CACnB;EAkCC,cAhCoC,aACnC,UAA4B,MAAc,UAAmB;AAC5D,qBACE,SACA,SACA,QAAQ,cACR,UACA,MACA,MACD;KAEH,CAAC,SAAS,QAAQ,CACnB;EAqBC,gBAnBsC,aACrC,UAA4B,aAAuB;AAClD,qBACE,SACA,SACA,QAAQ,gBACR,UACA,SACD;KAEH,CAAC,SAAS,QAAQ,CACnB;EASA"}
|
|
@@ -18,8 +18,8 @@ const enterKeyframe = keyframes`
|
|
|
18
18
|
}
|
|
19
19
|
`;
|
|
20
20
|
const createTheme$1 = (widgetTheme = {}) => {
|
|
21
|
-
const configuredPaletteLight = widgetTheme.colorSchemes?.light?.palette
|
|
22
|
-
const configuredPaletteDark = widgetTheme.colorSchemes?.dark?.palette
|
|
21
|
+
const configuredPaletteLight = widgetTheme.colorSchemes?.light?.palette;
|
|
22
|
+
const configuredPaletteDark = widgetTheme.colorSchemes?.dark?.palette;
|
|
23
23
|
const primaryMainColorLight = (configuredPaletteLight?.primary)?.main ?? palette.primary.main;
|
|
24
24
|
const primaryMainColorDark = (configuredPaletteDark?.primary)?.main ?? palette.primary.main;
|
|
25
25
|
const primaryLightenColorLight = lighten(primaryMainColorLight, .84);
|
|
@@ -42,7 +42,7 @@ const createTheme$1 = (widgetTheme = {}) => {
|
|
|
42
42
|
light: { palette: {
|
|
43
43
|
...palette,
|
|
44
44
|
...paletteLight,
|
|
45
|
-
...widgetTheme.colorSchemes?.light?.palette
|
|
45
|
+
...widgetTheme.colorSchemes?.light?.palette,
|
|
46
46
|
primary: {
|
|
47
47
|
main: primaryMainColorLight,
|
|
48
48
|
light: primaryLightenColorLight,
|
|
@@ -57,7 +57,7 @@ const createTheme$1 = (widgetTheme = {}) => {
|
|
|
57
57
|
dark: { palette: {
|
|
58
58
|
...palette,
|
|
59
59
|
...paletteDark,
|
|
60
|
-
...widgetTheme.colorSchemes?.dark?.palette
|
|
60
|
+
...widgetTheme.colorSchemes?.dark?.palette,
|
|
61
61
|
primary: {
|
|
62
62
|
main: primaryMainColorDark,
|
|
63
63
|
light: primaryLightenColorDark,
|