@lifi/widget 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/App.d.ts +4 -2
- package/dist/esm/App.d.ts.map +1 -1
- package/dist/esm/App.js +4 -4
- package/dist/esm/App.js.map +1 -1
- package/dist/esm/AppDrawer.d.ts +1 -1
- package/dist/esm/AppDrawer.d.ts.map +1 -1
- package/dist/esm/AppDrawer.js +5 -6
- package/dist/esm/AppDrawer.js.map +1 -1
- package/dist/esm/AppDrawerContext.js +2 -2
- package/dist/esm/AppDrawerContext.js.map +1 -1
- package/dist/esm/components/ActionRow/ActionRow.style.js.map +1 -1
- package/dist/esm/components/AmountInput/AmountInput.js.map +1 -1
- package/dist/esm/components/AmountInput/AmountInput.style.js.map +1 -1
- package/dist/esm/components/AmountInput/AmountInputEndAdornment.style.js.map +1 -1
- package/dist/esm/components/AmountInput/PriceFormHelperText.style.js.map +1 -1
- package/dist/esm/components/AppContainer.js.map +1 -1
- package/dist/esm/components/Avatar/AccountAvatar.js.map +1 -1
- package/dist/esm/components/Avatar/Avatar.style.js.map +1 -1
- package/dist/esm/components/Avatar/SmallAvatar.js.map +1 -1
- package/dist/esm/components/BaseTransactionButton/BaseTransactionButton.js +1 -0
- package/dist/esm/components/BaseTransactionButton/BaseTransactionButton.js.map +1 -1
- package/dist/esm/components/BottomSheet/BottomSheet.js +3 -3
- package/dist/esm/components/BottomSheet/BottomSheet.js.map +1 -1
- package/dist/esm/components/ButtonTertiary.js.map +1 -1
- package/dist/esm/components/Card/Card.js.map +1 -1
- package/dist/esm/components/Card/CardButton.style.js.map +1 -1
- package/dist/esm/components/Card/CardHeader.js.map +1 -1
- package/dist/esm/components/Card/CardIconButton.js.map +1 -1
- package/dist/esm/components/Card/CardLabel.js.map +1 -1
- package/dist/esm/components/Card/CardTitle.js.map +1 -1
- package/dist/esm/components/Card/InputCard.js.map +1 -1
- package/dist/esm/components/ChainSelect/ChainSelect.js.map +1 -1
- package/dist/esm/components/ChainSelect/ChainSelect.style.js.map +1 -1
- package/dist/esm/components/ChainSelect/useChainSelect.js.map +1 -1
- package/dist/esm/components/Chains/AllChainsAvatar.js.map +1 -1
- package/dist/esm/components/Chains/ChainList.js.map +1 -1
- package/dist/esm/components/Chains/ChainList.style.js.map +1 -1
- package/dist/esm/components/Chains/ChainsExpanded.style.js.map +1 -1
- package/dist/esm/components/Chains/VirtualizedChainList.js.map +1 -1
- package/dist/esm/components/ContextMenu.style.js.map +1 -1
- package/dist/esm/components/ContractComponent/NFT/NFT.style.js.map +1 -1
- package/dist/esm/components/Dialog/Dialog.style.js.map +1 -1
- package/dist/esm/components/EmptyListIndicator/EmptyListIndicator.style.js.map +1 -1
- package/dist/esm/components/ExecutionStatusCard/StatusIcon.js.map +1 -1
- package/dist/esm/components/ExecutionStatusCard/StatusIcon.style.js.map +1 -1
- package/dist/esm/components/ExecutionStatusCard/iconKey.js.map +1 -1
- package/dist/esm/components/Expansion/Expansion.style.js.map +1 -1
- package/dist/esm/components/Header/ActivitiesButton.style.js.map +1 -1
- package/dist/esm/components/Header/CloseDrawerButton.js +1 -0
- package/dist/esm/components/Header/CloseDrawerButton.js.map +1 -1
- package/dist/esm/components/Header/Header.js +7 -10
- package/dist/esm/components/Header/Header.js.map +1 -1
- package/dist/esm/components/Header/Header.style.js.map +1 -1
- package/dist/esm/components/Header/HeaderNavigationTabs.js +26 -0
- package/dist/esm/components/Header/HeaderNavigationTabs.js.map +1 -0
- package/dist/esm/components/Header/HeaderTabs.js +33 -0
- package/dist/esm/components/Header/HeaderTabs.js.map +1 -0
- package/dist/esm/components/Header/NavigationHeader.js +7 -5
- package/dist/esm/components/Header/NavigationHeader.js.map +1 -1
- package/dist/esm/components/Header/SettingsButton.style.js.map +1 -1
- package/dist/esm/components/Header/WalletMenu.style.js.map +1 -1
- package/dist/esm/components/IconCircle/IconCircle.style.js.map +1 -1
- package/dist/esm/components/IconTypography.js.map +1 -1
- package/dist/esm/components/Input.js.map +1 -1
- package/dist/esm/components/ListItem/ListItem.js.map +1 -1
- package/dist/esm/components/ListItem/ListItemButton.js.map +1 -1
- package/dist/esm/components/ListItemButton.js.map +1 -1
- package/dist/esm/components/ListItemText.js.map +1 -1
- package/dist/esm/components/Menu.js.map +1 -1
- package/dist/esm/components/Messages/AlertMessage.style.js.map +1 -1
- package/dist/esm/components/Messages/GasRefuelMessage.style.js.map +1 -1
- package/dist/esm/components/Messages/WarningMessages.js.map +1 -1
- package/dist/esm/components/PageContainer.js.map +1 -1
- package/dist/esm/components/PoweredBy/PoweredBy.js.map +1 -1
- package/dist/esm/components/PoweredBy/PoweredBy.style.js.map +1 -1
- package/dist/esm/components/ReverseTokensButton/ReverseTokensButton.js +1 -0
- package/dist/esm/components/ReverseTokensButton/ReverseTokensButton.js.map +1 -1
- package/dist/esm/components/ReverseTokensButton/ReverseTokensButton.style.js.map +1 -1
- package/dist/esm/components/RouteCard/RouteDetails.js.map +1 -1
- package/dist/esm/components/RouteCard/RouteDetails.style.js +2 -2
- package/dist/esm/components/RouteCard/RouteDetails.style.js.map +1 -1
- package/dist/esm/components/RouteCard/RouteToken.style.js.map +1 -1
- package/dist/esm/components/RouteCard/RouteTokens.js.map +1 -1
- package/dist/esm/components/RouteCard/getMatchingLabels.js.map +1 -1
- package/dist/esm/components/Routes/RoutesContent.js.map +1 -1
- package/dist/esm/components/Routes/RoutesExpanded.style.js.map +1 -1
- package/dist/esm/components/Search/SearchInput.style.js.map +1 -1
- package/dist/esm/components/Search/SearchNotFound.style.js.map +1 -1
- package/dist/esm/components/SelectTokenButton/SelectTokenButton.style.js.map +1 -1
- package/dist/esm/components/SendToWallet/SendToWalletButton.style.js.map +1 -1
- package/dist/esm/components/SettingsListItemButton.js.map +1 -1
- package/dist/esm/components/Skeleton/WidgetSkeleton.js +50 -47
- package/dist/esm/components/Skeleton/WidgetSkeleton.js.map +1 -1
- package/dist/esm/components/Skeleton/WidgetSkeleton.style.js.map +1 -1
- package/dist/esm/components/Step/StepActions.js.map +1 -1
- package/dist/esm/components/Step/StepActions.style.js.map +1 -1
- package/dist/esm/components/StepActions/SentToWalletRow.style.js.map +1 -1
- package/dist/esm/components/StepActions/StepActionRow.style.js.map +1 -1
- package/dist/esm/components/Switch.js.map +1 -1
- package/dist/esm/components/Tabs/NavigationTabs.js +3 -0
- package/dist/esm/components/Tabs/NavigationTabs.js.map +1 -1
- package/dist/esm/components/Tabs/Tabs.style.js.map +1 -1
- package/dist/esm/components/Timer/StepStatusTimer.style.js.map +1 -1
- package/dist/esm/components/Token/Token.style.js.map +1 -1
- package/dist/esm/components/TokenList/PinTokenButton.js.map +1 -1
- package/dist/esm/components/TokenList/TokenDetailsSheet.js +4 -4
- package/dist/esm/components/TokenList/TokenDetailsSheet.js.map +1 -1
- package/dist/esm/components/TokenList/TokenDetailsSheetContent.js +4 -4
- package/dist/esm/components/TokenList/TokenDetailsSheetContent.js.map +1 -1
- package/dist/esm/components/TokenList/TokenDetailsSheetContent.style.js.map +1 -1
- package/dist/esm/components/TokenList/TokenList.style.js.map +1 -1
- package/dist/esm/components/TokenList/TokenListItem.js +2 -2
- package/dist/esm/components/TokenList/TokenListItem.js.map +1 -1
- package/dist/esm/components/TokenList/VirtualizedTokenList.js.map +1 -1
- package/dist/esm/components/TokenList/useTokenSelect.js +3 -3
- package/dist/esm/components/TokenList/useTokenSelect.js.map +1 -1
- package/dist/esm/components/TokenRate/TokenRate.style.js.map +1 -1
- package/dist/esm/components/TransactionCard/ActiveTransactionCard.js.map +1 -1
- package/dist/esm/components/TransactionCard/ActiveTransactionCard.style.js.map +1 -1
- package/dist/esm/components/TransactionCard/TransactionCard.style.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/timer/validate.js.map +1 -1
- package/dist/esm/hooks/useAccountsBalancesData.js.map +1 -1
- package/dist/esm/hooks/useAvailableChains.js +1 -1
- package/dist/esm/hooks/useChainSearch.js.map +1 -1
- package/dist/esm/hooks/useChains.js +1 -1
- package/dist/esm/hooks/useExplorer.js.map +1 -1
- package/dist/esm/hooks/useFilteredByTokenBalances.js +1 -1
- package/dist/esm/hooks/useFilteredByTokenBalances.js.map +1 -1
- package/dist/esm/hooks/useFromTokenSufficiency.js.map +1 -1
- package/dist/esm/hooks/useGasSufficiency.js.map +1 -1
- package/dist/esm/hooks/useLanguages.js +2 -2
- package/dist/esm/hooks/useLanguages.js.map +1 -1
- package/dist/esm/hooks/useRouteExecution.js.map +1 -1
- package/dist/esm/hooks/useRouteExecutionMessage.js.map +1 -1
- package/dist/esm/hooks/useRouteRequiredAccountConnection.js.map +1 -1
- package/dist/esm/hooks/useRoutes.js.map +1 -1
- package/dist/esm/hooks/useSwapOnly.js +2 -4
- package/dist/esm/hooks/useSwapOnly.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/useToken.js.map +1 -1
- package/dist/esm/hooks/useTokenBalance.js.map +1 -1
- package/dist/esm/hooks/useTokenBalances.js.map +1 -1
- package/dist/esm/hooks/useTokenBalancesQueries.js.map +1 -1
- package/dist/esm/hooks/useTokenSearch.js +1 -1
- package/dist/esm/hooks/useTokenSearch.js.map +1 -1
- package/dist/esm/hooks/useTokens.js +1 -1
- package/dist/esm/hooks/useTokens.js.map +1 -1
- package/dist/esm/hooks/useTools.js +1 -1
- package/dist/esm/hooks/useTransactionDetails.js.map +1 -1
- package/dist/esm/hooks/useTransactionHistory.js.map +1 -1
- package/dist/esm/hooks/useTransactionList.js.map +1 -1
- package/dist/esm/i18n/en.json +3 -0
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/pages/ActivitiesPage/ActivitiesPage.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.map +1 -1
- package/dist/esm/pages/RoutesPage/RoutesPage.style.js.map +1 -1
- package/dist/esm/pages/SelectEnabledToolsPage.js.map +1 -1
- package/dist/esm/pages/SendToWallet/BookmarkAddressSheet.js +3 -3
- package/dist/esm/pages/SendToWallet/BookmarkAddressSheet.js.map +1 -1
- package/dist/esm/pages/SendToWallet/ConfirmAddressSheet.js +3 -3
- package/dist/esm/pages/SendToWallet/ConfirmAddressSheet.js.map +1 -1
- package/dist/esm/pages/SendToWallet/SendToWalletPage.js.map +1 -1
- package/dist/esm/pages/SendToWallet/SendToWalletPage.style.js.map +1 -1
- package/dist/esm/pages/SettingsPage/BridgeAndExchangeSettings.js.map +1 -1
- package/dist/esm/pages/SettingsPage/GasPriceSettings.js +1 -1
- package/dist/esm/pages/SettingsPage/ResetSettingsButton.style.js.map +1 -1
- package/dist/esm/pages/SettingsPage/RoutePrioritySettings.js +1 -1
- package/dist/esm/pages/SettingsPage/SettingsCard/SettingCard.style.js.map +1 -1
- package/dist/esm/pages/SettingsPage/SettingsCard/SettingCardExpandable.js +3 -3
- package/dist/esm/pages/SettingsPage/SettingsCard/SettingCardExpandable.js.map +1 -1
- package/dist/esm/pages/SettingsPage/SettingsCard/SettingsAccordian.js +3 -3
- package/dist/esm/pages/SettingsPage/SettingsCard/SettingsAccordian.js.map +1 -1
- package/dist/esm/pages/SettingsPage/SlippageSettings/SlippageSettings.style.js.map +1 -1
- package/dist/esm/pages/SettingsPage/ThemeSettings.js.map +1 -1
- package/dist/esm/pages/TransactionDetailsPage/ContactSupportButton.style.js.map +1 -1
- package/dist/esm/pages/TransactionDetailsPage/TransactionDetailsPage.js.map +1 -1
- package/dist/esm/pages/TransactionDetailsPage/TransactionDetailsSkeleton.js.map +1 -1
- package/dist/esm/pages/TransactionPage/ConfirmToAddressSheet.js +3 -3
- package/dist/esm/pages/TransactionPage/ConfirmToAddressSheet.js.map +1 -1
- package/dist/esm/pages/TransactionPage/ExchangeRateBottomSheet.js +16 -15
- package/dist/esm/pages/TransactionPage/ExchangeRateBottomSheet.js.map +1 -1
- package/dist/esm/pages/TransactionPage/ExchangeRateBottomSheet.style.js.map +1 -1
- package/dist/esm/pages/TransactionPage/RouteTracker.js.map +1 -1
- package/dist/esm/pages/TransactionPage/TokenValueBottomSheet.js +3 -3
- package/dist/esm/pages/TransactionPage/TokenValueBottomSheet.js.map +1 -1
- package/dist/esm/pages/TransactionPage/TokenValueBottomSheet.style.js.map +1 -1
- package/dist/esm/pages/TransactionPage/TransactionExecutionContent.js +27 -31
- package/dist/esm/pages/TransactionPage/TransactionExecutionContent.js.map +1 -1
- package/dist/esm/pages/TransactionPage/utils.js.map +1 -1
- package/dist/esm/providers/I18nProvider/I18nProvider.js.map +1 -1
- package/dist/esm/providers/I18nProvider/i18n.js.map +1 -1
- package/dist/esm/providers/QueryClientProvider.js +2 -2
- package/dist/esm/providers/QueryClientProvider.js.map +1 -1
- package/dist/esm/providers/SDKClientProvider.js +26 -27
- package/dist/esm/providers/SDKClientProvider.js.map +1 -1
- package/dist/esm/providers/WidgetProvider/WidgetProvider.js +25 -27
- package/dist/esm/providers/WidgetProvider/WidgetProvider.js.map +1 -1
- package/dist/esm/stores/StoreProvider.js +3 -4
- package/dist/esm/stores/StoreProvider.js.map +1 -1
- package/dist/esm/stores/bookmarks/BookmarkStore.js +3 -3
- package/dist/esm/stores/bookmarks/BookmarkStore.js.map +1 -1
- package/dist/esm/stores/bookmarks/createBookmarkStore.js.map +1 -1
- package/dist/esm/stores/chains/ChainOrderStore.js +4 -4
- package/dist/esm/stores/chains/ChainOrderStore.js.map +1 -1
- package/dist/esm/stores/chains/createChainOrderStore.js.map +1 -1
- package/dist/esm/stores/form/FormStore.js +1 -1
- package/dist/esm/stores/form/FormStore.js.map +1 -1
- package/dist/esm/stores/form/URLSearchParamsBuilder.js.map +1 -1
- package/dist/esm/stores/form/createFormStore.js.map +1 -1
- package/dist/esm/stores/form/getDefaultValuesFromQueryString.js.map +1 -1
- package/dist/esm/stores/form/useFieldActions.js.map +1 -1
- package/dist/esm/stores/form/useFieldValues.js.map +1 -1
- package/dist/esm/stores/form/useFormRef.js.map +1 -1
- package/dist/esm/stores/form/useFormStore.js +2 -2
- package/dist/esm/stores/form/useFormStore.js.map +1 -1
- package/dist/esm/stores/header/useHeaderStore.js +3 -3
- package/dist/esm/stores/header/useHeaderStore.js.map +1 -1
- package/dist/esm/stores/inputMode/useInputModeStore.js.map +1 -1
- package/dist/esm/stores/navigationTabs/useNavigationTabLabel.js +22 -0
- package/dist/esm/stores/navigationTabs/useNavigationTabLabel.js.map +1 -0
- package/dist/esm/stores/navigationTabs/useNavigationTabsStore.js +62 -0
- package/dist/esm/stores/navigationTabs/useNavigationTabsStore.js.map +1 -0
- package/dist/esm/stores/navigationTabs/utils.js +92 -0
- package/dist/esm/stores/navigationTabs/utils.js.map +1 -0
- package/dist/esm/stores/pinnedTokens/PinnedTokensStore.js +3 -3
- package/dist/esm/stores/pinnedTokens/PinnedTokensStore.js.map +1 -1
- package/dist/esm/stores/pinnedTokens/createPinnedTokensStore.js.map +1 -1
- package/dist/esm/stores/routes/RouteExecutionStore.js +3 -3
- package/dist/esm/stores/routes/RouteExecutionStore.js.map +1 -1
- package/dist/esm/stores/routes/createRouteExecutionStore.js.map +1 -1
- package/dist/esm/stores/routes/useIntermediateRoutesStore.js.map +1 -1
- package/dist/esm/stores/routes/useRouteExecutionIndicator.js.map +1 -1
- package/dist/esm/stores/routes/utils.js.map +1 -1
- package/dist/esm/stores/settings/SettingsStore.js +3 -3
- package/dist/esm/stores/settings/SettingsStore.js.map +1 -1
- package/dist/esm/stores/settings/createSettingsStore.js +122 -96
- package/dist/esm/stores/settings/createSettingsStore.js.map +1 -1
- package/dist/esm/stores/settings/types.d.ts +0 -2
- package/dist/esm/stores/settings/types.d.ts.map +1 -1
- package/dist/esm/stores/settings/types.js.map +1 -1
- package/dist/esm/stores/settings/useSettingsActions.js.map +1 -1
- package/dist/esm/themes/createTheme.js.map +1 -1
- package/dist/esm/themes/utils.js.map +1 -1
- package/dist/esm/types/widget.d.ts +19 -2
- package/dist/esm/types/widget.d.ts.map +1 -1
- package/dist/esm/types/widget.js.map +1 -1
- package/dist/esm/utils/compactNumberFormatter.js.map +1 -1
- package/dist/esm/utils/converters.js.map +1 -1
- package/dist/esm/utils/deepEqual.js.map +1 -1
- package/dist/esm/utils/fees.js.map +1 -1
- package/dist/esm/utils/format.js.map +1 -1
- package/dist/esm/utils/getActionMessage.js.map +1 -1
- package/dist/esm/utils/getErrorMessage.js.map +1 -1
- package/dist/esm/utils/item.js.map +1 -1
- package/dist/esm/utils/{variant.js → mode.js} +2 -2
- package/dist/esm/utils/mode.js.map +1 -0
- package/dist/esm/utils/prepareActions.js +1 -1
- package/dist/esm/utils/prepareActions.js.map +1 -1
- package/dist/esm/utils/timer.js.map +1 -1
- package/dist/esm/utils/token.js +1 -1
- package/dist/esm/utils/token.js.map +1 -1
- package/dist/esm/utils/tokenList.js.map +1 -1
- package/package.json +11 -11
- package/src/App.tsx +7 -7
- package/src/AppDrawer.tsx +77 -78
- package/src/AppDrawerContext.ts +2 -2
- package/src/components/BaseTransactionButton/BaseTransactionButton.tsx +1 -0
- package/src/components/BottomSheet/BottomSheet.tsx +56 -52
- package/src/components/Header/CloseDrawerButton.tsx +5 -1
- package/src/components/Header/Header.tsx +20 -18
- package/src/components/Header/HeaderNavigationTabs.tsx +25 -0
- package/src/components/Header/HeaderTabs.tsx +48 -0
- package/src/components/Header/NavigationHeader.tsx +11 -8
- package/src/components/ReverseTokensButton/ReverseTokensButton.tsx +4 -1
- package/src/components/Skeleton/WidgetSkeleton.tsx +1 -1
- package/src/components/Tabs/NavigationTabs.tsx +3 -0
- package/src/components/TokenList/TokenDetailsSheet.tsx +9 -7
- package/src/components/TokenList/TokenDetailsSheetContent.tsx +176 -177
- package/src/components/TokenList/useTokenSelect.ts +2 -2
- package/src/config/version.ts +1 -1
- package/src/hooks/useSwapOnly.ts +2 -5
- package/src/hooks/useToAddressRequirements.ts +2 -2
- package/src/pages/MainPage/ReviewButton.tsx +2 -2
- package/src/pages/SendToWallet/BookmarkAddressSheet.tsx +176 -185
- package/src/pages/SendToWallet/ConfirmAddressSheet.tsx +9 -6
- package/src/pages/SettingsPage/SettingsCard/SettingCardExpandable.tsx +58 -65
- package/src/pages/SettingsPage/SettingsCard/SettingsAccordian.tsx +4 -4
- package/src/pages/TransactionPage/ConfirmToAddressSheet.tsx +9 -6
- package/src/pages/TransactionPage/ExchangeRateBottomSheet.tsx +53 -58
- package/src/pages/TransactionPage/TokenValueBottomSheet.tsx +24 -21
- package/src/pages/TransactionPage/TransactionExecutionContent.tsx +8 -6
- package/src/providers/QueryClientProvider.tsx +2 -2
- package/src/providers/SDKClientProvider.tsx +3 -7
- package/src/providers/WidgetProvider/WidgetProvider.tsx +6 -7
- package/src/stores/StoreProvider.tsx +3 -10
- package/src/stores/bookmarks/BookmarkStore.tsx +4 -4
- package/src/stores/chains/ChainOrderStore.tsx +4 -4
- package/src/stores/form/FormStore.tsx +2 -2
- package/src/stores/form/useFormStore.ts +2 -2
- package/src/stores/header/useHeaderStore.tsx +3 -5
- package/src/stores/navigationTabs/types.ts +27 -0
- package/src/stores/navigationTabs/useNavigationTabLabel.ts +28 -0
- package/src/stores/navigationTabs/useNavigationTabsStore.tsx +108 -0
- package/src/stores/navigationTabs/utils.ts +134 -0
- package/src/stores/pinnedTokens/PinnedTokensStore.tsx +4 -4
- package/src/stores/routes/RouteExecutionStore.tsx +4 -4
- package/src/stores/settings/SettingsStore.tsx +4 -4
- package/src/stores/settings/createSettingsStore.ts +48 -12
- package/src/stores/settings/types.ts +1 -16
- package/src/types/widget.ts +31 -1
- package/dist/esm/components/Header/SplitNavigationTabs.js +0 -33
- package/dist/esm/components/Header/SplitNavigationTabs.js.map +0 -1
- package/dist/esm/stores/settings/useSplitModeStore.js +0 -36
- package/dist/esm/stores/settings/useSplitModeStore.js.map +0 -1
- package/dist/esm/utils/variant.js.map +0 -1
- package/src/components/Header/SplitNavigationTabs.tsx +0 -32
- package/src/stores/settings/useSplitModeStore.tsx +0 -58
- /package/src/utils/{variant.ts → mode.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext,
|
|
1
|
+
import { createContext, use, useRef } from "react";
|
|
2
2
|
import { create } from "zustand";
|
|
3
3
|
import { useShallow } from "zustand/shallow";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -7,13 +7,13 @@ const HeaderStoreContext = createContext(null);
|
|
|
7
7
|
function HeaderStoreProvider({ children }) {
|
|
8
8
|
const storeRef = useRef(null);
|
|
9
9
|
if (!storeRef.current) storeRef.current = createHeaderStore();
|
|
10
|
-
return /* @__PURE__ */ jsx(HeaderStoreContext
|
|
10
|
+
return /* @__PURE__ */ jsx(HeaderStoreContext, {
|
|
11
11
|
value: storeRef.current,
|
|
12
12
|
children
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
function useHeaderStoreContext() {
|
|
16
|
-
const useStore =
|
|
16
|
+
const useStore = use(HeaderStoreContext);
|
|
17
17
|
if (!useStore) throw new Error(`You forgot to wrap your component in <${HeaderStoreProvider.name}>.`);
|
|
18
18
|
return useStore;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHeaderStore.js","names":[],"sources":["../../../../src/stores/header/useHeaderStore.tsx"],"sourcesContent":["import { createContext,
|
|
1
|
+
{"version":3,"file":"useHeaderStore.js","names":[],"sources":["../../../../src/stores/header/useHeaderStore.tsx"],"sourcesContent":["import { createContext, use, useRef } from 'react'\nimport { create } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport type { PersistStoreProviderProps } from '../types.js'\nimport type { HeaderState, HeaderStore } from './types.js'\n\nconst HeaderStoreContext = createContext<HeaderStore | null>(null)\n\nexport function HeaderStoreProvider({\n children,\n}: PersistStoreProviderProps): any {\n const storeRef = useRef<HeaderStore>(null)\n if (!storeRef.current) {\n storeRef.current = createHeaderStore()\n }\n return (\n <HeaderStoreContext value={storeRef.current}>{children}</HeaderStoreContext>\n )\n}\n\nfunction useHeaderStoreContext() {\n const useStore = use(HeaderStoreContext)\n if (!useStore) {\n throw new Error(\n `You forgot to wrap your component in <${HeaderStoreProvider.name}>.`\n )\n }\n return useStore\n}\n\nexport function useHeaderStore<T>(selector: (state: HeaderState) => T): T {\n const useStore = useHeaderStoreContext()\n return useStore(useShallow(selector))\n}\n\n// We use fixed position on the header when Widget is in Full Height layout.\n// We do this to get it to work like the sticky header does in the other layout modes.\n// As the header is position fixed its not in the document flow anymore.\n// To prevent the remaining page content from appearing behind the header we need to\n// pass the headers height so that the position of the page content can be adjusted\nexport function useHeaderHeight(): any {\n const headerHeight = useHeaderStore((state) => state.headerHeight)\n\n return {\n headerHeight,\n }\n}\n\nexport function useSetHeaderHeight(): any {\n const setHeaderHeight = useHeaderStore((state) => state.setHeaderHeight)\n\n return {\n setHeaderHeight,\n }\n}\n\nconst createHeaderStore = () =>\n create<HeaderState>((set, get) => ({\n headerHeight: 108, // default header height\n setAction: (element) => {\n set(() => ({\n element,\n }))\n return get().removeAction\n },\n setTitle: (title) => {\n set(() => ({\n title,\n }))\n return get().removeTitle\n },\n removeAction: () => {\n set(() => ({\n element: null,\n }))\n },\n removeTitle: () => {\n set(() => ({\n title: undefined,\n }))\n },\n setHeaderHeight: (headerHeight) => {\n set(() => ({\n headerHeight,\n }))\n },\n setBackAction: (action) => {\n set(() => ({\n backAction: action,\n }))\n },\n executeBackAction: () => {\n const { backAction } = get()\n if (backAction) {\n backAction()\n set(() => ({\n backAction: undefined,\n }))\n }\n },\n }))\n"],"mappings":";;;;;AAMA,MAAM,qBAAqB,cAAkC,IAAI;AAEjE,SAAgB,oBAAoB,EAClC,YACiC;CACjC,MAAM,WAAW,OAAoB,IAAI;CACzC,IAAI,CAAC,SAAS,SACZ,SAAS,UAAU,kBAAkB;CAEvC,OACE,oBAAC,oBAAD;EAAoB,OAAO,SAAS;EAAU;CAA6B,CAAA;AAE/E;AAEA,SAAS,wBAAwB;CAC/B,MAAM,WAAW,IAAI,kBAAkB;CACvC,IAAI,CAAC,UACH,MAAM,IAAI,MACR,yCAAyC,oBAAoB,KAAK,GACpE;CAEF,OAAO;AACT;AAEA,SAAgB,eAAkB,UAAwC;CAExE,OADiB,sBACH,CAAC,CAAC,WAAW,QAAQ,CAAC;AACtC;AAOA,SAAgB,kBAAuB;CAGrC,OAAO,EACL,cAHmB,gBAAgB,UAAU,MAAM,YAGxC,EACb;AACF;AAEA,SAAgB,qBAA0B;CAGxC,OAAO,EACL,iBAHsB,gBAAgB,UAAU,MAAM,eAGxC,EAChB;AACF;AAEA,MAAM,0BACJ,QAAqB,KAAK,SAAS;CACjC,cAAc;CACd,YAAY,YAAY;EACtB,WAAW,EACT,QACF,EAAE;EACF,OAAO,IAAI,CAAC,CAAC;CACf;CACA,WAAW,UAAU;EACnB,WAAW,EACT,MACF,EAAE;EACF,OAAO,IAAI,CAAC,CAAC;CACf;CACA,oBAAoB;EAClB,WAAW,EACT,SAAS,KACX,EAAE;CACJ;CACA,mBAAmB;EACjB,WAAW,EACT,OAAO,KAAA,EACT,EAAE;CACJ;CACA,kBAAkB,iBAAiB;EACjC,WAAW,EACT,aACF,EAAE;CACJ;CACA,gBAAgB,WAAW;EACzB,WAAW,EACT,YAAY,OACd,EAAE;CACJ;CACA,yBAAyB;EACvB,MAAM,EAAE,eAAe,IAAI;EAC3B,IAAI,YAAY;GACd,WAAW;GACX,WAAW,EACT,YAAY,KAAA,EACd,EAAE;EACJ;CACF;AACF,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInputModeStore.js","names":[],"sources":["../../../../src/stores/inputMode/useInputModeStore.ts"],"sourcesContent":["import type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\nimport type { FormTypeProps } from '../form/types.js'\n\ntype InputMode = 'amount' | 'price'\n\ninterface InputModeState {\n inputMode: Record<'from' | 'to', InputMode>\n setInputMode: (formType: FormTypeProps['formType'], mode: InputMode) => void\n toggleInputMode: (formType: FormTypeProps['formType']) => void\n}\n\nexport const useInputModeStore: UseBoundStore<StoreApi<InputModeState>> =\n create<InputModeState>((set, get) => ({\n inputMode: {\n from: 'amount',\n to: 'amount',\n },\n setInputMode: (formType, mode) =>\n set((state) => ({\n inputMode: {\n ...state.inputMode,\n [formType]: mode,\n },\n })),\n toggleInputMode: (formType) => {\n const currentMode = get().inputMode[formType]\n const newMode = currentMode === 'amount' ? 'price' : 'amount'\n get().setInputMode(formType, newMode)\n },\n }))\n"],"mappings":";;AAYA,MAAa,oBACX,QAAwB,KAAK,SAAS;CACpC,WAAW;EACT,MAAM;EACN,IAAI;CACN;CACA,eAAe,UAAU,SACvB,KAAK,WAAW,EACd,WAAW;EACT,GAAG,MAAM;GACR,WAAW;CACd,EACF,EAAE;CACJ,kBAAkB,aAAa;EAE7B,MAAM,UADc,IAAI,
|
|
1
|
+
{"version":3,"file":"useInputModeStore.js","names":[],"sources":["../../../../src/stores/inputMode/useInputModeStore.ts"],"sourcesContent":["import type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\nimport type { FormTypeProps } from '../form/types.js'\n\ntype InputMode = 'amount' | 'price'\n\ninterface InputModeState {\n inputMode: Record<'from' | 'to', InputMode>\n setInputMode: (formType: FormTypeProps['formType'], mode: InputMode) => void\n toggleInputMode: (formType: FormTypeProps['formType']) => void\n}\n\nexport const useInputModeStore: UseBoundStore<StoreApi<InputModeState>> =\n create<InputModeState>((set, get) => ({\n inputMode: {\n from: 'amount',\n to: 'amount',\n },\n setInputMode: (formType, mode) =>\n set((state) => ({\n inputMode: {\n ...state.inputMode,\n [formType]: mode,\n },\n })),\n toggleInputMode: (formType) => {\n const currentMode = get().inputMode[formType]\n const newMode = currentMode === 'amount' ? 'price' : 'amount'\n get().setInputMode(formType, newMode)\n },\n }))\n"],"mappings":";;AAYA,MAAa,oBACX,QAAwB,KAAK,SAAS;CACpC,WAAW;EACT,MAAM;EACN,IAAI;CACN;CACA,eAAe,UAAU,SACvB,KAAK,WAAW,EACd,WAAW;EACT,GAAG,MAAM;GACR,WAAW;CACd,EACF,EAAE;CACJ,kBAAkB,aAAa;EAE7B,MAAM,UADc,IAAI,CAAC,CAAC,UAAU,cACJ,WAAW,UAAU;EACrD,IAAI,CAAC,CAAC,aAAa,UAAU,OAAO;CACtC;AACF,EAAE"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useTranslation } from "react-i18next";
|
|
2
|
+
//#region src/stores/navigationTabs/useNavigationTabLabel.ts
|
|
3
|
+
const useNavigationTabLabel = () => {
|
|
4
|
+
const { t } = useTranslation();
|
|
5
|
+
return (key) => {
|
|
6
|
+
switch (key) {
|
|
7
|
+
case "default": return t("header.swapAndBridge");
|
|
8
|
+
case "private": return t("header.private");
|
|
9
|
+
case "refuel": return t("header.gas");
|
|
10
|
+
case "swap":
|
|
11
|
+
case "swap-advanced": return t("header.swap");
|
|
12
|
+
case "bridge":
|
|
13
|
+
case "bridge-advanced": return t("header.bridge");
|
|
14
|
+
case "limit": return t("header.limit");
|
|
15
|
+
default: return t("header.swapAndBridge");
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { useNavigationTabLabel };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=useNavigationTabLabel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNavigationTabLabel.js","names":[],"sources":["../../../../src/stores/navigationTabs/useNavigationTabLabel.ts"],"sourcesContent":["import { useTranslation } from 'react-i18next'\nimport type { NavigationTabKey } from '../../types/widget.js'\n\nexport const useNavigationTabLabel = (): ((\n key: NavigationTabKey\n) => string) => {\n const { t } = useTranslation()\n return (key: NavigationTabKey) => {\n switch (key) {\n case 'default':\n return t('header.swapAndBridge')\n case 'private':\n return t('header.private')\n case 'refuel':\n return t('header.gas')\n case 'swap':\n case 'swap-advanced':\n return t('header.swap')\n case 'bridge':\n case 'bridge-advanced':\n return t('header.bridge')\n case 'limit':\n return t('header.limit')\n default:\n return t('header.swapAndBridge')\n }\n }\n}\n"],"mappings":";;AAGA,MAAa,8BAEG;CACd,MAAM,EAAE,MAAM,eAAe;CAC7B,QAAQ,QAA0B;EAChC,QAAQ,KAAR;GACE,KAAK,WACH,OAAO,EAAE,sBAAsB;GACjC,KAAK,WACH,OAAO,EAAE,gBAAgB;GAC3B,KAAK,UACH,OAAO,EAAE,YAAY;GACvB,KAAK;GACL,KAAK,iBACH,OAAO,EAAE,aAAa;GACxB,KAAK;GACL,KAAK,mBACH,OAAO,EAAE,eAAe;GAC1B,KAAK,SACH,OAAO,EAAE,cAAc;GACzB,SACE,OAAO,EAAE,sBAAsB;EACnC;CACF;AACF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { WidgetContext, useWidgetConfig } from "../../providers/WidgetProvider/WidgetProvider.js";
|
|
2
|
+
import { getInitialActiveTab, getNavigationTabKeys, getTabMode, getTabModeOptions, getTabSplitMode, getTabVariant } from "./utils.js";
|
|
3
|
+
import { createContext, use, useMemo, useRef } from "react";
|
|
4
|
+
import { create } from "zustand";
|
|
5
|
+
import { useShallow } from "zustand/shallow";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
//#region src/stores/navigationTabs/useNavigationTabsStore.tsx
|
|
8
|
+
const NavigationTabsStoreContext = createContext(null);
|
|
9
|
+
function NavigationTabsStoreProvider({ children, config }) {
|
|
10
|
+
const tabs = getNavigationTabKeys(config);
|
|
11
|
+
const initialActiveTab = getInitialActiveTab(config);
|
|
12
|
+
const signature = `${tabs.join(",")}|${initialActiveTab ?? ""}`;
|
|
13
|
+
const storeRef = useRef(null);
|
|
14
|
+
const signatureRef = useRef(signature);
|
|
15
|
+
let store = storeRef.current;
|
|
16
|
+
if (!store || signatureRef.current !== signature) {
|
|
17
|
+
store = createNavigationTabsStore(tabs, initialActiveTab);
|
|
18
|
+
storeRef.current = store;
|
|
19
|
+
signatureRef.current = signature;
|
|
20
|
+
}
|
|
21
|
+
const widgetConfig = useWidgetConfig();
|
|
22
|
+
const activeTab = store((state) => state.activeTab);
|
|
23
|
+
const tabConfig = useMemo(() => {
|
|
24
|
+
if (!activeTab) return widgetConfig;
|
|
25
|
+
return {
|
|
26
|
+
...widgetConfig,
|
|
27
|
+
mode: getTabMode(widgetConfig, activeTab),
|
|
28
|
+
variant: getTabVariant(widgetConfig, activeTab),
|
|
29
|
+
modeOptions: getTabModeOptions(widgetConfig, activeTab)
|
|
30
|
+
};
|
|
31
|
+
}, [widgetConfig, activeTab]);
|
|
32
|
+
return /* @__PURE__ */ jsx(NavigationTabsStoreContext, {
|
|
33
|
+
value: store,
|
|
34
|
+
children: /* @__PURE__ */ jsx(WidgetContext, {
|
|
35
|
+
value: tabConfig,
|
|
36
|
+
children
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function useNavigationTabsStoreContext() {
|
|
41
|
+
const useStore = use(NavigationTabsStoreContext);
|
|
42
|
+
if (!useStore) throw new Error(`You forgot to wrap your component in <${NavigationTabsStoreProvider.name}>.`);
|
|
43
|
+
return useStore;
|
|
44
|
+
}
|
|
45
|
+
function useNavigationTabsStore(selector) {
|
|
46
|
+
return useNavigationTabsStoreContext()(useShallow(selector));
|
|
47
|
+
}
|
|
48
|
+
/** Effective split mode derived from the active tab. */
|
|
49
|
+
function useSplitMode() {
|
|
50
|
+
return useNavigationTabsStore((state) => getTabSplitMode(state.activeTab));
|
|
51
|
+
}
|
|
52
|
+
const createNavigationTabsStore = (tabs, initialActiveTab) => create((set) => ({
|
|
53
|
+
tabs,
|
|
54
|
+
activeTab: initialActiveTab,
|
|
55
|
+
setActiveTab(activeTab) {
|
|
56
|
+
set({ activeTab });
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
//#endregion
|
|
60
|
+
export { NavigationTabsStoreProvider, useNavigationTabsStore, useSplitMode };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=useNavigationTabsStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNavigationTabsStore.js","names":[],"sources":["../../../../src/stores/navigationTabs/useNavigationTabsStore.tsx"],"sourcesContent":["import {\n createContext,\n type JSX,\n type PropsWithChildren,\n use,\n useMemo,\n useRef,\n} from 'react'\nimport { create } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport {\n useWidgetConfig,\n WidgetContext,\n} from '../../providers/WidgetProvider/WidgetProvider.js'\nimport type {\n NavigationTabKey,\n SplitMode,\n WidgetConfig,\n} from '../../types/widget.js'\nimport type { NavigationTabsState, NavigationTabsStore } from './types.js'\nimport {\n getInitialActiveTab,\n getNavigationTabKeys,\n getTabMode,\n getTabModeOptions,\n getTabSplitMode,\n getTabVariant,\n} from './utils.js'\n\nconst NavigationTabsStoreContext = createContext<NavigationTabsStore | null>(\n null\n)\n\nexport function NavigationTabsStoreProvider({\n children,\n config,\n}: PropsWithChildren<{ config: WidgetConfig }>): JSX.Element {\n const tabs = getNavigationTabKeys(config)\n const initialActiveTab = getInitialActiveTab(config)\n // Recreate (re-seeding tabs + active tab) only when the config-driven inputs\n // change — not on runtime tab clicks, which must be preserved.\n const signature = `${tabs.join(',')}|${initialActiveTab ?? ''}`\n const storeRef = useRef<NavigationTabsStore>(null)\n const signatureRef = useRef(signature)\n let store = storeRef.current\n if (!store || signatureRef.current !== signature) {\n store = createNavigationTabsStore(tabs, initialActiveTab)\n storeRef.current = store\n signatureRef.current = signature\n }\n\n // Override the widget config with the active tab's mode, variant and\n // modeOptions (each falling back to the config), so the rest of the widget\n // reads tab-driven config transparently. No-op when there is no active tab.\n const widgetConfig = useWidgetConfig()\n const activeTab = store((state) => state.activeTab)\n const tabConfig = useMemo(() => {\n if (!activeTab) {\n return widgetConfig\n }\n return {\n ...widgetConfig,\n mode: getTabMode(widgetConfig, activeTab),\n variant: getTabVariant(widgetConfig, activeTab),\n modeOptions: getTabModeOptions(widgetConfig, activeTab),\n }\n }, [widgetConfig, activeTab])\n\n return (\n <NavigationTabsStoreContext value={store}>\n <WidgetContext value={tabConfig}>{children}</WidgetContext>\n </NavigationTabsStoreContext>\n )\n}\n\nfunction useNavigationTabsStoreContext(): NavigationTabsStore {\n const useStore = use(NavigationTabsStoreContext)\n if (!useStore) {\n throw new Error(\n `You forgot to wrap your component in <${NavigationTabsStoreProvider.name}>.`\n )\n }\n return useStore\n}\n\nexport function useNavigationTabsStore<T>(\n selector: (state: NavigationTabsState) => T\n): T {\n const useStore = useNavigationTabsStoreContext()\n return useStore(useShallow(selector))\n}\n\n/** Effective split mode derived from the active tab. */\nexport function useSplitMode(): SplitMode | undefined {\n return useNavigationTabsStore((state) => getTabSplitMode(state.activeTab))\n}\n\nconst createNavigationTabsStore = (\n tabs: NavigationTabKey[],\n initialActiveTab?: NavigationTabKey\n): NavigationTabsStore =>\n create<NavigationTabsState>((set) => ({\n tabs,\n activeTab: initialActiveTab,\n setActiveTab(activeTab) {\n set({ activeTab })\n },\n }))\n"],"mappings":";;;;;;;AA6BA,MAAM,6BAA6B,cACjC,IACF;AAEA,SAAgB,4BAA4B,EAC1C,UACA,UAC2D;CAC3D,MAAM,OAAO,qBAAqB,MAAM;CACxC,MAAM,mBAAmB,oBAAoB,MAAM;CAGnD,MAAM,YAAY,GAAG,KAAK,KAAK,GAAG,EAAE,GAAG,oBAAoB;CAC3D,MAAM,WAAW,OAA4B,IAAI;CACjD,MAAM,eAAe,OAAO,SAAS;CACrC,IAAI,QAAQ,SAAS;CACrB,IAAI,CAAC,SAAS,aAAa,YAAY,WAAW;EAChD,QAAQ,0BAA0B,MAAM,gBAAgB;EACxD,SAAS,UAAU;EACnB,aAAa,UAAU;CACzB;CAKA,MAAM,eAAe,gBAAgB;CACrC,MAAM,YAAY,OAAO,UAAU,MAAM,SAAS;CAClD,MAAM,YAAY,cAAc;EAC9B,IAAI,CAAC,WACH,OAAO;EAET,OAAO;GACL,GAAG;GACH,MAAM,WAAW,cAAc,SAAS;GACxC,SAAS,cAAc,cAAc,SAAS;GAC9C,aAAa,kBAAkB,cAAc,SAAS;EACxD;CACF,GAAG,CAAC,cAAc,SAAS,CAAC;CAE5B,OACE,oBAAC,4BAAD;EAA4B,OAAO;YACjC,oBAAC,eAAD;GAAe,OAAO;GAAY;EAAwB,CAAA;CAChC,CAAA;AAEhC;AAEA,SAAS,gCAAqD;CAC5D,MAAM,WAAW,IAAI,0BAA0B;CAC/C,IAAI,CAAC,UACH,MAAM,IAAI,MACR,yCAAyC,4BAA4B,KAAK,GAC5E;CAEF,OAAO;AACT;AAEA,SAAgB,uBACd,UACG;CAEH,OADiB,8BACH,CAAC,CAAC,WAAW,QAAQ,CAAC;AACtC;;AAGA,SAAgB,eAAsC;CACpD,OAAO,wBAAwB,UAAU,gBAAgB,MAAM,SAAS,CAAC;AAC3E;AAEA,MAAM,6BACJ,MACA,qBAEA,QAA6B,SAAS;CACpC;CACA,WAAW;CACX,aAAa,WAAW;EACtB,IAAI,EAAE,UAAU,CAAC;CACnB;AACF,EAAE"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { getSplitMode } from "../../utils/mode.js";
|
|
2
|
+
//#region src/stores/navigationTabs/utils.ts
|
|
3
|
+
/** Configured navigation tabs by key. Labels are resolved from the key by a hook. */
|
|
4
|
+
const navigationTabsByKey = {
|
|
5
|
+
default: {
|
|
6
|
+
key: "default",
|
|
7
|
+
variant: "wide",
|
|
8
|
+
mode: "default"
|
|
9
|
+
},
|
|
10
|
+
private: {
|
|
11
|
+
key: "private",
|
|
12
|
+
variant: "compact",
|
|
13
|
+
mode: "split",
|
|
14
|
+
modeOptions: { split: "swap" }
|
|
15
|
+
},
|
|
16
|
+
refuel: {
|
|
17
|
+
key: "refuel",
|
|
18
|
+
variant: "wide",
|
|
19
|
+
mode: "refuel"
|
|
20
|
+
},
|
|
21
|
+
limit: {
|
|
22
|
+
key: "limit",
|
|
23
|
+
variant: "compact",
|
|
24
|
+
mode: "limit"
|
|
25
|
+
},
|
|
26
|
+
"swap-advanced": {
|
|
27
|
+
key: "swap-advanced",
|
|
28
|
+
variant: "wide",
|
|
29
|
+
mode: "split",
|
|
30
|
+
modeOptions: { split: "swap" }
|
|
31
|
+
},
|
|
32
|
+
"bridge-advanced": {
|
|
33
|
+
key: "bridge-advanced",
|
|
34
|
+
variant: "wide",
|
|
35
|
+
mode: "split",
|
|
36
|
+
modeOptions: { split: "bridge" }
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/** Split-mode tabs (Swap / Bridge), shown when no navigation tabs are configured. */
|
|
40
|
+
const splitTabs = [{
|
|
41
|
+
key: "swap",
|
|
42
|
+
mode: "split",
|
|
43
|
+
modeOptions: { split: "swap" }
|
|
44
|
+
}, {
|
|
45
|
+
key: "bridge",
|
|
46
|
+
mode: "split",
|
|
47
|
+
modeOptions: { split: "bridge" }
|
|
48
|
+
}];
|
|
49
|
+
const splitTabsByKey = Object.fromEntries(splitTabs.map((tab) => [tab.key, tab]));
|
|
50
|
+
/** Combined lookup across configured and split tabs. */
|
|
51
|
+
const tabByKey = {
|
|
52
|
+
...navigationTabsByKey,
|
|
53
|
+
...splitTabsByKey
|
|
54
|
+
};
|
|
55
|
+
/** Tab keys shown in split mode when no navigation tabs are configured. */
|
|
56
|
+
const splitTabKeys = splitTabs.map((tab) => tab.key);
|
|
57
|
+
/** Resolves which navigation tabs the header should render from the config. */
|
|
58
|
+
const getNavigationTabKeys = (config) => {
|
|
59
|
+
if (config._navigationTabs?.length) return config._navigationTabs;
|
|
60
|
+
if (config.mode === "split" && typeof config.modeOptions?.split !== "string") return splitTabKeys;
|
|
61
|
+
return [];
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* The tab the store seeds as active from the config. With navigation tabs it's
|
|
65
|
+
* the first configured tab; otherwise split mode's selection is itself a tab
|
|
66
|
+
* (`swap`/`bridge`), so it seeds the active tab too.
|
|
67
|
+
*/
|
|
68
|
+
const getInitialActiveTab = (config) => {
|
|
69
|
+
if (config._navigationTabs?.length) return config._navigationTabs[0];
|
|
70
|
+
return config.mode === "split" ? getSplitMode(config.modeOptions?.split) : void 0;
|
|
71
|
+
};
|
|
72
|
+
/** Split mode (`swap`/`bridge`) implied by a tab, or `undefined` if not split. */
|
|
73
|
+
const getTabSplitMode = (key) => {
|
|
74
|
+
const tab = key ? tabByKey[key] : void 0;
|
|
75
|
+
return tab?.mode === "split" ? getSplitMode(tab.modeOptions?.split) : void 0;
|
|
76
|
+
};
|
|
77
|
+
/** Variant for a tab, falling back to the widget config's variant when unset. */
|
|
78
|
+
const getTabVariant = (config, key) => {
|
|
79
|
+
return (key ? tabByKey[key] : void 0)?.variant ?? config.variant;
|
|
80
|
+
};
|
|
81
|
+
/** Mode for a tab, falling back to the widget config's mode when unset. */
|
|
82
|
+
const getTabMode = (config, key) => {
|
|
83
|
+
return (key ? tabByKey[key] : void 0)?.mode ?? config.mode;
|
|
84
|
+
};
|
|
85
|
+
/** Mode options for a tab, falling back to the widget config's when unset. */
|
|
86
|
+
const getTabModeOptions = (config, key) => {
|
|
87
|
+
return (key ? tabByKey[key] : void 0)?.modeOptions ?? config.modeOptions;
|
|
88
|
+
};
|
|
89
|
+
//#endregion
|
|
90
|
+
export { getInitialActiveTab, getNavigationTabKeys, getTabMode, getTabModeOptions, getTabSplitMode, getTabVariant };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../../../src/stores/navigationTabs/utils.ts"],"sourcesContent":["import type {\n InternalNavigationTabKey,\n ModeOptions,\n NavigationTabKey,\n SplitMode,\n SplitNavigationTabKey,\n WidgetConfig,\n WidgetMode,\n WidgetVariant,\n} from '../../types/widget.js'\nimport { getSplitMode } from '../../utils/mode.js'\nimport type { NavigationTab } from './types.js'\n\n/** Configured navigation tabs by key. Labels are resolved from the key by a hook. */\nconst navigationTabsByKey: Record<InternalNavigationTabKey, NavigationTab> = {\n default: { key: 'default', variant: 'wide', mode: 'default' },\n private: {\n key: 'private',\n variant: 'compact',\n mode: 'split',\n modeOptions: { split: 'swap' },\n },\n refuel: { key: 'refuel', variant: 'wide', mode: 'refuel' },\n limit: { key: 'limit', variant: 'compact', mode: 'limit' },\n 'swap-advanced': {\n key: 'swap-advanced',\n variant: 'wide',\n mode: 'split',\n modeOptions: { split: 'swap' },\n },\n 'bridge-advanced': {\n key: 'bridge-advanced',\n variant: 'wide',\n mode: 'split',\n modeOptions: { split: 'bridge' },\n },\n}\n\n/** Split-mode tabs (Swap / Bridge), shown when no navigation tabs are configured. */\nconst splitTabs: NavigationTab[] = [\n {\n key: 'swap',\n mode: 'split',\n modeOptions: { split: 'swap' },\n },\n {\n key: 'bridge',\n mode: 'split',\n modeOptions: { split: 'bridge' },\n },\n]\n\nconst splitTabsByKey = Object.fromEntries(\n splitTabs.map((tab) => [tab.key, tab])\n) as Record<SplitNavigationTabKey, NavigationTab>\n\n/** Combined lookup across configured and split tabs. */\nconst tabByKey: Record<NavigationTabKey, NavigationTab> = {\n ...navigationTabsByKey,\n ...splitTabsByKey,\n}\n\n/** Tab keys shown in split mode when no navigation tabs are configured. */\nexport const splitTabKeys: NavigationTabKey[] = splitTabs.map((tab) => tab.key)\n\n/** Resolves which navigation tabs the header should render from the config. */\nexport const getNavigationTabKeys = (\n config: WidgetConfig\n): NavigationTabKey[] => {\n if (config._navigationTabs?.length) {\n return config._navigationTabs\n }\n // Split mode shows Swap / Bridge tabs unless pinned to a single side.\n if (\n config.mode === 'split' &&\n typeof config.modeOptions?.split !== 'string'\n ) {\n return splitTabKeys\n }\n return []\n}\n\n/**\n * The tab the store seeds as active from the config. With navigation tabs it's\n * the first configured tab; otherwise split mode's selection is itself a tab\n * (`swap`/`bridge`), so it seeds the active tab too.\n */\nexport const getInitialActiveTab = (\n config: WidgetConfig\n): NavigationTabKey | undefined => {\n if (config._navigationTabs?.length) {\n return config._navigationTabs[0]\n }\n return config.mode === 'split'\n ? getSplitMode(config.modeOptions?.split)\n : undefined\n}\n\n/** Split mode (`swap`/`bridge`) implied by a tab, or `undefined` if not split. */\nexport const getTabSplitMode = (\n key?: NavigationTabKey\n): SplitMode | undefined => {\n const tab = key ? tabByKey[key] : undefined\n return tab?.mode === 'split'\n ? getSplitMode(tab.modeOptions?.split)\n : undefined\n}\n\n/** Variant for a tab, falling back to the widget config's variant when unset. */\nexport const getTabVariant = (\n config: WidgetConfig,\n key?: NavigationTabKey\n): WidgetVariant | undefined => {\n const tab = key ? tabByKey[key] : undefined\n return tab?.variant ?? config.variant\n}\n\n/** Mode for a tab, falling back to the widget config's mode when unset. */\nexport const getTabMode = (\n config: WidgetConfig,\n key?: NavigationTabKey\n): WidgetMode | undefined => {\n const tab = key ? tabByKey[key] : undefined\n return tab?.mode ?? config.mode\n}\n\n/** Mode options for a tab, falling back to the widget config's when unset. */\nexport const getTabModeOptions = (\n config: WidgetConfig,\n key?: NavigationTabKey\n): ModeOptions | undefined => {\n const tab = key ? tabByKey[key] : undefined\n return tab?.modeOptions ?? config.modeOptions\n}\n"],"mappings":";;;AAcA,MAAM,sBAAuE;CAC3E,SAAS;EAAE,KAAK;EAAW,SAAS;EAAQ,MAAM;CAAU;CAC5D,SAAS;EACP,KAAK;EACL,SAAS;EACT,MAAM;EACN,aAAa,EAAE,OAAO,OAAO;CAC/B;CACA,QAAQ;EAAE,KAAK;EAAU,SAAS;EAAQ,MAAM;CAAS;CACzD,OAAO;EAAE,KAAK;EAAS,SAAS;EAAW,MAAM;CAAQ;CACzD,iBAAiB;EACf,KAAK;EACL,SAAS;EACT,MAAM;EACN,aAAa,EAAE,OAAO,OAAO;CAC/B;CACA,mBAAmB;EACjB,KAAK;EACL,SAAS;EACT,MAAM;EACN,aAAa,EAAE,OAAO,SAAS;CACjC;AACF;;AAGA,MAAM,YAA6B,CACjC;CACE,KAAK;CACL,MAAM;CACN,aAAa,EAAE,OAAO,OAAO;AAC/B,GACA;CACE,KAAK;CACL,MAAM;CACN,aAAa,EAAE,OAAO,SAAS;AACjC,CACF;AAEA,MAAM,iBAAiB,OAAO,YAC5B,UAAU,KAAK,QAAQ,CAAC,IAAI,KAAK,GAAG,CAAC,CACvC;;AAGA,MAAM,WAAoD;CACxD,GAAG;CACH,GAAG;AACL;;AAGA,MAAa,eAAmC,UAAU,KAAK,QAAQ,IAAI,GAAG;;AAG9E,MAAa,wBACX,WACuB;CACvB,IAAI,OAAO,iBAAiB,QAC1B,OAAO,OAAO;CAGhB,IACE,OAAO,SAAS,WAChB,OAAO,OAAO,aAAa,UAAU,UAErC,OAAO;CAET,OAAO,CAAC;AACV;;;;;;AAOA,MAAa,uBACX,WACiC;CACjC,IAAI,OAAO,iBAAiB,QAC1B,OAAO,OAAO,gBAAgB;CAEhC,OAAO,OAAO,SAAS,UACnB,aAAa,OAAO,aAAa,KAAK,IACtC,KAAA;AACN;;AAGA,MAAa,mBACX,QAC0B;CAC1B,MAAM,MAAM,MAAM,SAAS,OAAO,KAAA;CAClC,OAAO,KAAK,SAAS,UACjB,aAAa,IAAI,aAAa,KAAK,IACnC,KAAA;AACN;;AAGA,MAAa,iBACX,QACA,QAC8B;CAE9B,QADY,MAAM,SAAS,OAAO,KAAA,EAAA,EACtB,WAAW,OAAO;AAChC;;AAGA,MAAa,cACX,QACA,QAC2B;CAE3B,QADY,MAAM,SAAS,OAAO,KAAA,EAAA,EACtB,QAAQ,OAAO;AAC7B;;AAGA,MAAa,qBACX,QACA,QAC4B;CAE5B,QADY,MAAM,SAAS,OAAO,KAAA,EAAA,EACtB,eAAe,OAAO;AACpC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createPinnedTokensStore } from "./createPinnedTokensStore.js";
|
|
2
|
-
import { createContext,
|
|
2
|
+
import { createContext, use, useRef } from "react";
|
|
3
3
|
import { useShallow } from "zustand/shallow";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/stores/pinnedTokens/PinnedTokensStore.tsx
|
|
@@ -7,13 +7,13 @@ const PinnedTokensStoreContext = createContext(null);
|
|
|
7
7
|
const PinnedTokensStoreProvider = ({ children, ...props }) => {
|
|
8
8
|
const storeRef = useRef(null);
|
|
9
9
|
if (!storeRef.current) storeRef.current = createPinnedTokensStore(props);
|
|
10
|
-
return /* @__PURE__ */ jsx(PinnedTokensStoreContext
|
|
10
|
+
return /* @__PURE__ */ jsx(PinnedTokensStoreContext, {
|
|
11
11
|
value: storeRef.current,
|
|
12
12
|
children
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
15
|
function usePinnedTokensStore(selector) {
|
|
16
|
-
const useStore =
|
|
16
|
+
const useStore = use(PinnedTokensStoreContext);
|
|
17
17
|
if (!useStore) throw new Error(`You forgot to wrap your component in <${PinnedTokensStoreProvider.name}>.`);
|
|
18
18
|
return useStore(useShallow(selector));
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PinnedTokensStore.js","names":[],"sources":["../../../../src/stores/pinnedTokens/PinnedTokensStore.tsx"],"sourcesContent":["import { createContext,
|
|
1
|
+
{"version":3,"file":"PinnedTokensStore.js","names":[],"sources":["../../../../src/stores/pinnedTokens/PinnedTokensStore.tsx"],"sourcesContent":["import { createContext, use, useRef } from 'react'\nimport { useShallow } from 'zustand/shallow'\nimport type { PersistStoreProviderProps } from '../types.js'\nimport { createPinnedTokensStore } from './createPinnedTokensStore.js'\nimport type { PinnedTokensState, PinnedTokensStore } from './types.js'\n\nconst PinnedTokensStoreContext = createContext<PinnedTokensStore | null>(null)\n\nexport const PinnedTokensStoreProvider: React.FC<PersistStoreProviderProps> = ({\n children,\n ...props\n}) => {\n const storeRef = useRef<PinnedTokensStore>(null)\n\n if (!storeRef.current) {\n storeRef.current = createPinnedTokensStore(props)\n }\n\n return (\n <PinnedTokensStoreContext value={storeRef.current}>\n {children}\n </PinnedTokensStoreContext>\n )\n}\n\nexport function usePinnedTokensStore<T>(\n selector: (store: PinnedTokensState) => T\n): T {\n const useStore = use(PinnedTokensStoreContext)\n\n if (!useStore) {\n throw new Error(\n `You forgot to wrap your component in <${PinnedTokensStoreProvider.name}>.`\n )\n }\n\n return useStore(useShallow(selector))\n}\n"],"mappings":";;;;;AAMA,MAAM,2BAA2B,cAAwC,IAAI;AAE7E,MAAa,6BAAkE,EAC7E,UACA,GAAG,YACC;CACJ,MAAM,WAAW,OAA0B,IAAI;CAE/C,IAAI,CAAC,SAAS,SACZ,SAAS,UAAU,wBAAwB,KAAK;CAGlD,OACE,oBAAC,0BAAD;EAA0B,OAAO,SAAS;EACvC;CACuB,CAAA;AAE9B;AAEA,SAAgB,qBACd,UACG;CACH,MAAM,WAAW,IAAI,wBAAwB;CAE7C,IAAI,CAAC,UACH,MAAM,IAAI,MACR,yCAAyC,0BAA0B,KAAK,GAC1E;CAGF,OAAO,SAAS,WAAW,QAAQ,CAAC;AACtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPinnedTokensStore.js","names":[],"sources":["../../../../src/stores/pinnedTokens/createPinnedTokensStore.ts"],"sourcesContent":["import type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\nimport { persist } from 'zustand/middleware'\nimport type { PersistStoreProps } from '../types.js'\nimport type { PinnedTokensState } from './types.js'\n\nexport const createPinnedTokensStore = ({\n namePrefix,\n}: PersistStoreProps): UseBoundStore<StoreApi<PinnedTokensState>> =>\n create<PinnedTokensState>()(\n persist(\n (set, get) => ({\n pinnedTokens: {},\n pinToken: (chainId: number, tokenAddress: string) => {\n set((state) => {\n const normalizedAddress = tokenAddress.toLowerCase()\n const chainTokens = state.pinnedTokens[chainId] || []\n if (!chainTokens.includes(normalizedAddress)) {\n return {\n pinnedTokens: {\n ...state.pinnedTokens,\n [chainId]: [...chainTokens, normalizedAddress],\n },\n }\n }\n return state\n })\n },\n unpinToken: (chainId: number, tokenAddress: string) => {\n set((state) => {\n const normalizedAddress = tokenAddress.toLowerCase()\n const chainTokens = state.pinnedTokens[chainId] || []\n if (chainTokens.includes(normalizedAddress)) {\n return {\n pinnedTokens: {\n ...state.pinnedTokens,\n [chainId]: chainTokens.filter(\n (addr) => addr !== normalizedAddress\n ),\n },\n }\n }\n return state\n })\n },\n isPinned: (chainId: number, tokenAddress: string) => {\n const normalizedAddress = tokenAddress.toLowerCase()\n const chainTokens = get().pinnedTokens[chainId] || []\n return chainTokens.includes(normalizedAddress)\n },\n getPinnedTokens: (chainId: number) => {\n return get().pinnedTokens[chainId] || []\n },\n getAllPinnedTokens: () => {\n const allPinned: Array<{ chainId: number; tokenAddress: string }> = []\n const pinnedTokens = get().pinnedTokens\n Object.entries(pinnedTokens).forEach(([chainIdStr, addresses]) => {\n const chainId = Number.parseInt(chainIdStr, 10)\n addresses.forEach((address) => {\n allPinned.push({ chainId, tokenAddress: address })\n })\n })\n return allPinned\n },\n }),\n {\n name: `${namePrefix || 'li.fi'}-pinned-tokens`,\n version: 0,\n partialize: (state) => ({\n pinnedTokens: state.pinnedTokens,\n }),\n }\n )\n )\n"],"mappings":";;;AAMA,MAAa,2BAA2B,EACtC,iBAEA,OAA0B,
|
|
1
|
+
{"version":3,"file":"createPinnedTokensStore.js","names":[],"sources":["../../../../src/stores/pinnedTokens/createPinnedTokensStore.ts"],"sourcesContent":["import type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\nimport { persist } from 'zustand/middleware'\nimport type { PersistStoreProps } from '../types.js'\nimport type { PinnedTokensState } from './types.js'\n\nexport const createPinnedTokensStore = ({\n namePrefix,\n}: PersistStoreProps): UseBoundStore<StoreApi<PinnedTokensState>> =>\n create<PinnedTokensState>()(\n persist(\n (set, get) => ({\n pinnedTokens: {},\n pinToken: (chainId: number, tokenAddress: string) => {\n set((state) => {\n const normalizedAddress = tokenAddress.toLowerCase()\n const chainTokens = state.pinnedTokens[chainId] || []\n if (!chainTokens.includes(normalizedAddress)) {\n return {\n pinnedTokens: {\n ...state.pinnedTokens,\n [chainId]: [...chainTokens, normalizedAddress],\n },\n }\n }\n return state\n })\n },\n unpinToken: (chainId: number, tokenAddress: string) => {\n set((state) => {\n const normalizedAddress = tokenAddress.toLowerCase()\n const chainTokens = state.pinnedTokens[chainId] || []\n if (chainTokens.includes(normalizedAddress)) {\n return {\n pinnedTokens: {\n ...state.pinnedTokens,\n [chainId]: chainTokens.filter(\n (addr) => addr !== normalizedAddress\n ),\n },\n }\n }\n return state\n })\n },\n isPinned: (chainId: number, tokenAddress: string) => {\n const normalizedAddress = tokenAddress.toLowerCase()\n const chainTokens = get().pinnedTokens[chainId] || []\n return chainTokens.includes(normalizedAddress)\n },\n getPinnedTokens: (chainId: number) => {\n return get().pinnedTokens[chainId] || []\n },\n getAllPinnedTokens: () => {\n const allPinned: Array<{ chainId: number; tokenAddress: string }> = []\n const pinnedTokens = get().pinnedTokens\n Object.entries(pinnedTokens).forEach(([chainIdStr, addresses]) => {\n const chainId = Number.parseInt(chainIdStr, 10)\n addresses.forEach((address) => {\n allPinned.push({ chainId, tokenAddress: address })\n })\n })\n return allPinned\n },\n }),\n {\n name: `${namePrefix || 'li.fi'}-pinned-tokens`,\n version: 0,\n partialize: (state) => ({\n pinnedTokens: state.pinnedTokens,\n }),\n }\n )\n )\n"],"mappings":";;;AAMA,MAAa,2BAA2B,EACtC,iBAEA,OAA0B,CAAC,CACzB,SACG,KAAK,SAAS;CACb,cAAc,CAAC;CACf,WAAW,SAAiB,iBAAyB;EACnD,KAAK,UAAU;GACb,MAAM,oBAAoB,aAAa,YAAY;GACnD,MAAM,cAAc,MAAM,aAAa,YAAY,CAAC;GACpD,IAAI,CAAC,YAAY,SAAS,iBAAiB,GACzC,OAAO,EACL,cAAc;IACZ,GAAG,MAAM;KACR,UAAU,CAAC,GAAG,aAAa,iBAAiB;GAC/C,EACF;GAEF,OAAO;EACT,CAAC;CACH;CACA,aAAa,SAAiB,iBAAyB;EACrD,KAAK,UAAU;GACb,MAAM,oBAAoB,aAAa,YAAY;GACnD,MAAM,cAAc,MAAM,aAAa,YAAY,CAAC;GACpD,IAAI,YAAY,SAAS,iBAAiB,GACxC,OAAO,EACL,cAAc;IACZ,GAAG,MAAM;KACR,UAAU,YAAY,QACpB,SAAS,SAAS,iBACrB;GACF,EACF;GAEF,OAAO;EACT,CAAC;CACH;CACA,WAAW,SAAiB,iBAAyB;EACnD,MAAM,oBAAoB,aAAa,YAAY;EAEnD,QADoB,IAAI,CAAC,CAAC,aAAa,YAAY,CAAC,EAAA,CACjC,SAAS,iBAAiB;CAC/C;CACA,kBAAkB,YAAoB;EACpC,OAAO,IAAI,CAAC,CAAC,aAAa,YAAY,CAAC;CACzC;CACA,0BAA0B;EACxB,MAAM,YAA8D,CAAC;EACrE,MAAM,eAAe,IAAI,CAAC,CAAC;EAC3B,OAAO,QAAQ,YAAY,CAAC,CAAC,SAAS,CAAC,YAAY,eAAe;GAChE,MAAM,UAAU,OAAO,SAAS,YAAY,EAAE;GAC9C,UAAU,SAAS,YAAY;IAC7B,UAAU,KAAK;KAAE;KAAS,cAAc;IAAQ,CAAC;GACnD,CAAC;EACH,CAAC;EACD,OAAO;CACT;AACF,IACA;CACE,MAAM,GAAG,cAAc,QAAQ;CAC/B,SAAS;CACT,aAAa,WAAW,EACtB,cAAc,MAAM,aACtB;AACF,CACF,CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRouteExecutionStore } from "./createRouteExecutionStore.js";
|
|
2
|
-
import { createContext,
|
|
2
|
+
import { createContext, use, useRef } from "react";
|
|
3
3
|
import { useShallow } from "zustand/shallow";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/stores/routes/RouteExecutionStore.tsx
|
|
@@ -7,13 +7,13 @@ const RouteExecutionStoreContext = createContext(null);
|
|
|
7
7
|
function RouteExecutionStoreProvider({ children, ...props }) {
|
|
8
8
|
const storeRef = useRef(null);
|
|
9
9
|
if (!storeRef.current) storeRef.current = createRouteExecutionStore(props);
|
|
10
|
-
return /* @__PURE__ */ jsx(RouteExecutionStoreContext
|
|
10
|
+
return /* @__PURE__ */ jsx(RouteExecutionStoreContext, {
|
|
11
11
|
value: storeRef.current,
|
|
12
12
|
children
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
function useRouteExecutionStoreContext() {
|
|
16
|
-
const useStore =
|
|
16
|
+
const useStore = use(RouteExecutionStoreContext);
|
|
17
17
|
if (!useStore) throw new Error(`You forgot to wrap your component in <${RouteExecutionStoreProvider.name}>.`);
|
|
18
18
|
return useStore;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouteExecutionStore.js","names":[],"sources":["../../../../src/stores/routes/RouteExecutionStore.tsx"],"sourcesContent":["import { createContext, type JSX,
|
|
1
|
+
{"version":3,"file":"RouteExecutionStore.js","names":[],"sources":["../../../../src/stores/routes/RouteExecutionStore.tsx"],"sourcesContent":["import { createContext, type JSX, use, useRef } from 'react'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport type { PersistStoreProviderProps } from '../types.js'\nimport { createRouteExecutionStore } from './createRouteExecutionStore.js'\nimport type { RouteExecutionState } from './types.js'\n\ntype RouteExecutionStore = UseBoundStore<StoreApi<RouteExecutionState>>\n\nconst RouteExecutionStoreContext = createContext<RouteExecutionStore | null>(\n null\n)\n\nexport function RouteExecutionStoreProvider({\n children,\n ...props\n}: PersistStoreProviderProps): JSX.Element {\n const storeRef = useRef<RouteExecutionStore>(null)\n if (!storeRef.current) {\n storeRef.current = createRouteExecutionStore(props)\n }\n return (\n <RouteExecutionStoreContext value={storeRef.current}>\n {children}\n </RouteExecutionStoreContext>\n )\n}\n\nexport function useRouteExecutionStoreContext(): any {\n const useStore = use(RouteExecutionStoreContext)\n if (!useStore) {\n throw new Error(\n `You forgot to wrap your component in <${RouteExecutionStoreProvider.name}>.`\n )\n }\n return useStore\n}\n\nexport function useRouteExecutionStore<T>(\n selector: (state: RouteExecutionState) => T\n): T {\n const useStore = useRouteExecutionStoreContext()\n return useStore(useShallow(selector))\n}\n"],"mappings":";;;;;AASA,MAAM,6BAA6B,cACjC,IACF;AAEA,SAAgB,4BAA4B,EAC1C,UACA,GAAG,SACsC;CACzC,MAAM,WAAW,OAA4B,IAAI;CACjD,IAAI,CAAC,SAAS,SACZ,SAAS,UAAU,0BAA0B,KAAK;CAEpD,OACE,oBAAC,4BAAD;EAA4B,OAAO,SAAS;EACzC;CACyB,CAAA;AAEhC;AAEA,SAAgB,gCAAqC;CACnD,MAAM,WAAW,IAAI,0BAA0B;CAC/C,IAAI,CAAC,UACH,MAAM,IAAI,MACR,yCAAyC,4BAA4B,KAAK,GAC5E;CAEF,OAAO;AACT;AAEA,SAAgB,uBACd,UACG;CAEH,OADiB,8BACH,CAAC,CAAC,WAAW,QAAQ,CAAC;AACtC"}
|
|
@@ -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":";;;;;AAeA,MAAa,6BAA6B,EACxC,iBAEA,OAA4B,
|
|
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,OAA4B,CAAC,CAC3B,SACG,KAAK,SAAS;CACb,QAAQ,CAAC;CACT,qBAAqB,OAAc,uBAAkC;EACnE,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,MAAM,KACtB,KAAK,UAA+B;GAClC,MAAM,SAAS,EAAE,GAAG,MAAM,OAAO;GAEjC,OAAO,KAAK,MAAM,CAAC,CAChB,QACE,YACC,CAAC,oBAAoB,SAAS,OAAO,KACrC,YACE,OAAO,QAAQ,CAAE,QAAA,CAEnB,CACJ,CAAC,CACA,SAAS,YAAY;IACpB,OAAO,OAAO;GAChB,CAAC;GACH,OAAO,MAAM,MAAM;IACjB;IACA,QAAA;GACF;GACA,OAAO,EACL,OACF;EACF,CAAC;CAEL;CACA,cAAc,UAAyB;EACrC,IAAI,IAAI,CAAC,CAAC,OAAO,MAAM,KACrB,KAAK,UAA+B;GAClC,MAAM,eAAe,EACnB,QAAQ;IACN,GAAG,MAAM;KACR,MAAM,KAAK;KAAE,GAAG,MAAM,OAAO,MAAM;KAAM;IAAM;GAClD,EACF;GAEA,IADiB,cAAc,KACpB,GAAG;IACZ,aAAa,OAAO,MAAM,GAAG,CAAE,SAAA;IAE/B,OAAO;GACT;GAEA,IADe,YAAY,KAClB,GAAG;IACV,aAAa,OAAO,MAAM,GAAG,CAAE,SAAA;IAE/B,IAAI,qBAAqB,KAAK,GAC5B,aAAa,OAAO,MAAM,GAAG,CAAE,UAAA;SAE1B,IAAI,gBAAgB,KAAK,GAC9B,aAAa,OAAO,MAAM,GAAG,CAAE,UAAA;IAGjC,OAAO;GACT;GAEA,IADkB,MAAM,MAAM,MAAM,SAAS,KAAK,SACtC,GACV,aAAa,OAAO,MAAM,GAAG,CAAE,SAAA;GAGjC,OAAO;EACT,CAAC;CAEL;CACA,eAAe,MAAM,qBACnB,KAAK,UAA+B;EAClC,MAAM,SAAS,EAAE,GAAG,MAAM,OAAO;EACjC,OAAO,KAAK,MAAM,CAAC,CAChB,QAAQ,YAAY;GACnB,MAAM,QAAQ,OAAO;GACrB,IACE,oBACA,CAAC,iBAAiB,SAAS,OAAO,MAAM,eAAe,EAAE,GAEzD,OAAO;GAET,OAAO,SAAS,cACZ,YAAY,OAAO,UAAU,GAAA,CAA4B,IACzD,SAAS,WACP,YACE,OAAO,UAAU,GAAA,CAEnB,IACA,CAAC,YACC,OAAO,UAAU,GAAA,CAEnB;EACR,CAAC,CAAC,CACD,SAAS,YAAY;GACpB,OAAO,OAAO;EAChB,CAAC;EACH,OAAO,EACL,OACF;CACF,CAAC;CACH,cAAc,YAAoB;EAChC,IAAI,IAAI,CAAC,CAAC,OAAO,UACf,KAAK,UAA+B;GAClC,MAAM,SAAS,EAAE,GAAG,MAAM,OAAO;GACjC,OAAO,OAAO;GACd,OAAO,EACL,OACF;EACF,CAAC;CAEL;AACF,IACA;CACE,MAAM,GAAG,cAAc,QAAQ;CAE/B,SAAS;CAET,gBAAgB,EAAE,QAAQ,CAAC,EAAE;CAC7B,aAAa,WAAW,EAAE,QAAQ,MAAM,OAAO;CAC/C,QAAQ,gBAAqB,iBAAsC;EACjE,MAAM,QAAQ;GACZ,GAAG;GACH,GAAG;EACL;EACA,IAAI;GAKF,MAAM,eADY,OAAO,OAAO,MAAM,MACT,CAAC,CAC3B,MACE,GAAG,OACD,EAAE,MAAM,MAAM,EAAE,EAAE,WAAW,aAAa,MAC1C,EAAE,MAAM,MAAM,EAAE,EAAE,WAAW,aAAa,EAC/C,CAAC,CACA,MAAM,GAAG,GAAe;GAC3B,MAAM,UAAU,IAAI,IAAI,aAAa,KAAK,MAAM,EAAE,MAAM,EAAE,CAAC;GAC3D,KAAK,MAAM,MAAM,OAAO,KAAK,MAAM,MAAM,GACvC,IAAI,CAAC,QAAQ,IAAI,EAAE,GACjB,OAAO,MAAM,OAAO;EAG1B,SAAS,OAAO;GACd,QAAQ,MAAM,KAAK;EACrB;EACA,OAAO;CACT;AACF,CACF,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntermediateRoutesStore.js","names":[],"sources":["../../../../src/stores/routes/useIntermediateRoutesStore.ts"],"sourcesContent":["import type { Route } from '@lifi/sdk'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\n\ninterface IntermediateRoutesState {\n intermediateRoutes: Record<string, Route[] | undefined>\n setIntermediateRoutes: (\n key: readonly unknown[],\n routes: Route[] | undefined\n ) => void\n getIntermediateRoutes: (key: readonly unknown[]) => Route[] | undefined\n}\n\nexport const useIntermediateRoutesStore: UseBoundStore<\n StoreApi<IntermediateRoutesState>\n> = create<IntermediateRoutesState>((set, get) => ({\n intermediateRoutes: {},\n setIntermediateRoutes: (key, routes) => {\n const stringKey = JSON.stringify(key)\n // Create a new state with only the current key\n const newRoutesByKey: Record<string, Route[] | undefined> = {}\n newRoutesByKey[stringKey] = routes\n set({ intermediateRoutes: newRoutesByKey })\n },\n getIntermediateRoutes: (key) => {\n const stringKey = JSON.stringify(key)\n return get().intermediateRoutes[stringKey]\n },\n}))\n"],"mappings":";;AAaA,MAAa,6BAET,QAAiC,KAAK,SAAS;CACjD,oBAAoB,CAAC;CACrB,wBAAwB,KAAK,WAAW;EACtC,MAAM,YAAY,KAAK,UAAU,GAAG;EAEpC,MAAM,iBAAsD,CAAC;EAC7D,eAAe,aAAa;EAC5B,IAAI,EAAE,oBAAoB,eAAe,CAAC;CAC5C;CACA,wBAAwB,QAAQ;EAC9B,MAAM,YAAY,KAAK,UAAU,GAAG;EACpC,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"useIntermediateRoutesStore.js","names":[],"sources":["../../../../src/stores/routes/useIntermediateRoutesStore.ts"],"sourcesContent":["import type { Route } from '@lifi/sdk'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\n\ninterface IntermediateRoutesState {\n intermediateRoutes: Record<string, Route[] | undefined>\n setIntermediateRoutes: (\n key: readonly unknown[],\n routes: Route[] | undefined\n ) => void\n getIntermediateRoutes: (key: readonly unknown[]) => Route[] | undefined\n}\n\nexport const useIntermediateRoutesStore: UseBoundStore<\n StoreApi<IntermediateRoutesState>\n> = create<IntermediateRoutesState>((set, get) => ({\n intermediateRoutes: {},\n setIntermediateRoutes: (key, routes) => {\n const stringKey = JSON.stringify(key)\n // Create a new state with only the current key\n const newRoutesByKey: Record<string, Route[] | undefined> = {}\n newRoutesByKey[stringKey] = routes\n set({ intermediateRoutes: newRoutesByKey })\n },\n getIntermediateRoutes: (key) => {\n const stringKey = JSON.stringify(key)\n return get().intermediateRoutes[stringKey]\n },\n}))\n"],"mappings":";;AAaA,MAAa,6BAET,QAAiC,KAAK,SAAS;CACjD,oBAAoB,CAAC;CACrB,wBAAwB,KAAK,WAAW;EACtC,MAAM,YAAY,KAAK,UAAU,GAAG;EAEpC,MAAM,iBAAsD,CAAC;EAC7D,eAAe,aAAa;EAC5B,IAAI,EAAE,oBAAoB,eAAe,CAAC;CAC5C;CACA,wBAAwB,QAAQ;EAC9B,MAAM,YAAY,KAAK,UAAU,GAAG;EACpC,OAAO,IAAI,CAAC,CAAC,mBAAmB;CAClC;AACF,EAAE"}
|
|
@@ -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":";;;;AAWA,MAAM,uBAAuB,UAAmC;CAC9D,MAAM,YAAY,MAAM,MAAM,MAAM,
|
|
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,EAAE,EAAE,WAAW,aAAa;CAChE,OAAO,YAAY,KAAK,KAAK,IAAI,IAAI,YAAY,MAAO,KAAK,KAAK;AACpE;AAEA,MAAa,mCAA4D;CACvE,MAAM,EAAE,aAAa,WAAW;CAChC,MAAM,mBAAmB,cACjB,SAAS,KAAK,YAAY,QAAQ,OAAO,GAC/C,CAAC,QAAQ,CACX;CAoBA,OAAO,uBAnBU,aACd,UAAwD;EAEvD,MAAM,oBADS,OAAO,OAAO,MAAM,MACJ,CAAC,CAAC,QAC9B,UACC,iBAAiB,SAAS,MAAM,MAAM,WAAW,KACjD,oBAAoB,KAAK,CAC7B;EACA,OAAO;GACL,QAAQ,kBAAkB,MACvB,MAAM,EAAE,WAAA,CACX;GACA,QAAQ,kBAAkB,MACvB,MAAM,EAAE,WAAA,CACX;EACF;CACF,GACA,CAAC,gBAAgB,CAEkB,CAAC;AACxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../../../src/stores/routes/utils.ts"],"sourcesContent":["import type { ExecutionAction, RouteExtended } from '@lifi/sdk'\nimport microdiff from 'microdiff'\n\nexport const isRouteDone = (route: RouteExtended): boolean => {\n return route.steps.every((step) => step.execution?.status === 'DONE')\n}\n\nexport const isRoutePartiallyDone = (route: RouteExtended): boolean => {\n return route.steps.some((step) =>\n step.execution?.actions?.some((action) => action.substatus === 'PARTIAL')\n )\n}\n\nexport const isRouteRefunded = (route: RouteExtended): boolean => {\n return route.steps.some((step) =>\n step.execution?.actions?.some((action) => action.substatus === 'REFUNDED')\n )\n}\n\nexport const isRouteFailed = (route: RouteExtended): boolean => {\n return route.steps.some((step) => step.execution?.status === 'FAILED')\n}\n\nexport const isRouteActive = (route?: RouteExtended): boolean => {\n if (!route) {\n return false\n }\n const isDone = isRouteDone(route)\n const isFailed = isRouteFailed(route)\n const alreadyStarted = route.steps.some((step) => step.execution)\n return !isDone && !isFailed && alreadyStarted\n}\n\nexport const getUpdatedAction = (\n currentRoute: RouteExtended,\n updatedRoute: RouteExtended\n): ExecutionAction | undefined => {\n const actionDiff = microdiff(currentRoute, updatedRoute).find((diff) =>\n diff.path.includes('actions')\n )\n if (!actionDiff) {\n return undefined\n }\n // Find action index in the diff array so we can slice the complete action object\n // e.g. ['steps', 0, 'execution', 'actions', 0, 'message']\n const actionDiffIndex = actionDiff.path.indexOf('actions') + 2\n const actionPathSlice = actionDiff.path.slice(0, actionDiffIndex)\n // Reduce updated route using the diff path to get updated process\n const action = actionPathSlice.reduce(\n (obj, path) => obj[path],\n updatedRoute as any\n ) as ExecutionAction\n return action\n}\n\nexport const getSourceTxHash = (route?: RouteExtended): string | undefined => {\n const sourceAction = route?.steps[0].execution?.actions\n ?.filter(\n (action) => !['RESET_ALLOWANCE', 'SET_ALLOWANCE'].includes(action.type)\n )\n .find((action) => action.txHash || action.taskId)\n return sourceAction?.txHash || sourceAction?.taskId\n}\n"],"mappings":";;AAGA,MAAa,eAAe,UAAkC;CAC5D,OAAO,MAAM,MAAM,OAAO,SAAS,KAAK,WAAW,WAAW,MAAM;AACtE;AAEA,MAAa,wBAAwB,UAAkC;CACrE,OAAO,MAAM,MAAM,MAAM,SACvB,KAAK,WAAW,SAAS,MAAM,WAAW,OAAO,cAAc,SAAS,CAC1E;AACF;AAEA,MAAa,mBAAmB,UAAkC;CAChE,OAAO,MAAM,MAAM,MAAM,SACvB,KAAK,WAAW,SAAS,MAAM,WAAW,OAAO,cAAc,UAAU,CAC3E;AACF;AAEA,MAAa,iBAAiB,UAAkC;CAC9D,OAAO,MAAM,MAAM,MAAM,SAAS,KAAK,WAAW,WAAW,QAAQ;AACvE;AAEA,MAAa,iBAAiB,UAAmC;CAC/D,IAAI,CAAC,OACH,OAAO;CAET,MAAM,SAAS,YAAY,KAAK;CAChC,MAAM,WAAW,cAAc,KAAK;CACpC,MAAM,iBAAiB,MAAM,MAAM,MAAM,SAAS,KAAK,SAAS;CAChE,OAAO,CAAC,UAAU,CAAC,YAAY;AACjC;AAEA,MAAa,oBACX,cACA,iBACgC;CAChC,MAAM,aAAa,UAAU,cAAc,YAAY,
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../../../src/stores/routes/utils.ts"],"sourcesContent":["import type { ExecutionAction, RouteExtended } from '@lifi/sdk'\nimport microdiff from 'microdiff'\n\nexport const isRouteDone = (route: RouteExtended): boolean => {\n return route.steps.every((step) => step.execution?.status === 'DONE')\n}\n\nexport const isRoutePartiallyDone = (route: RouteExtended): boolean => {\n return route.steps.some((step) =>\n step.execution?.actions?.some((action) => action.substatus === 'PARTIAL')\n )\n}\n\nexport const isRouteRefunded = (route: RouteExtended): boolean => {\n return route.steps.some((step) =>\n step.execution?.actions?.some((action) => action.substatus === 'REFUNDED')\n )\n}\n\nexport const isRouteFailed = (route: RouteExtended): boolean => {\n return route.steps.some((step) => step.execution?.status === 'FAILED')\n}\n\nexport const isRouteActive = (route?: RouteExtended): boolean => {\n if (!route) {\n return false\n }\n const isDone = isRouteDone(route)\n const isFailed = isRouteFailed(route)\n const alreadyStarted = route.steps.some((step) => step.execution)\n return !isDone && !isFailed && alreadyStarted\n}\n\nexport const getUpdatedAction = (\n currentRoute: RouteExtended,\n updatedRoute: RouteExtended\n): ExecutionAction | undefined => {\n const actionDiff = microdiff(currentRoute, updatedRoute).find((diff) =>\n diff.path.includes('actions')\n )\n if (!actionDiff) {\n return undefined\n }\n // Find action index in the diff array so we can slice the complete action object\n // e.g. ['steps', 0, 'execution', 'actions', 0, 'message']\n const actionDiffIndex = actionDiff.path.indexOf('actions') + 2\n const actionPathSlice = actionDiff.path.slice(0, actionDiffIndex)\n // Reduce updated route using the diff path to get updated process\n const action = actionPathSlice.reduce(\n (obj, path) => obj[path],\n updatedRoute as any\n ) as ExecutionAction\n return action\n}\n\nexport const getSourceTxHash = (route?: RouteExtended): string | undefined => {\n const sourceAction = route?.steps[0].execution?.actions\n ?.filter(\n (action) => !['RESET_ALLOWANCE', 'SET_ALLOWANCE'].includes(action.type)\n )\n .find((action) => action.txHash || action.taskId)\n return sourceAction?.txHash || sourceAction?.taskId\n}\n"],"mappings":";;AAGA,MAAa,eAAe,UAAkC;CAC5D,OAAO,MAAM,MAAM,OAAO,SAAS,KAAK,WAAW,WAAW,MAAM;AACtE;AAEA,MAAa,wBAAwB,UAAkC;CACrE,OAAO,MAAM,MAAM,MAAM,SACvB,KAAK,WAAW,SAAS,MAAM,WAAW,OAAO,cAAc,SAAS,CAC1E;AACF;AAEA,MAAa,mBAAmB,UAAkC;CAChE,OAAO,MAAM,MAAM,MAAM,SACvB,KAAK,WAAW,SAAS,MAAM,WAAW,OAAO,cAAc,UAAU,CAC3E;AACF;AAEA,MAAa,iBAAiB,UAAkC;CAC9D,OAAO,MAAM,MAAM,MAAM,SAAS,KAAK,WAAW,WAAW,QAAQ;AACvE;AAEA,MAAa,iBAAiB,UAAmC;CAC/D,IAAI,CAAC,OACH,OAAO;CAET,MAAM,SAAS,YAAY,KAAK;CAChC,MAAM,WAAW,cAAc,KAAK;CACpC,MAAM,iBAAiB,MAAM,MAAM,MAAM,SAAS,KAAK,SAAS;CAChE,OAAO,CAAC,UAAU,CAAC,YAAY;AACjC;AAEA,MAAa,oBACX,cACA,iBACgC;CAChC,MAAM,aAAa,UAAU,cAAc,YAAY,CAAC,CAAC,MAAM,SAC7D,KAAK,KAAK,SAAS,SAAS,CAC9B;CACA,IAAI,CAAC,YACH;CAIF,MAAM,kBAAkB,WAAW,KAAK,QAAQ,SAAS,IAAI;CAO7D,OANwB,WAAW,KAAK,MAAM,GAAG,eAEpB,CAAC,CAAC,QAC5B,KAAK,SAAS,IAAI,OACnB,YAEU;AACd;AAEA,MAAa,mBAAmB,UAA8C;CAC5E,MAAM,eAAe,OAAO,MAAM,EAAE,CAAC,WAAW,SAC5C,QACC,WAAW,CAAC,CAAC,mBAAmB,eAAe,CAAC,CAAC,SAAS,OAAO,IAAI,CACxE,CAAC,CACA,MAAM,WAAW,OAAO,UAAU,OAAO,MAAM;CAClD,OAAO,cAAc,UAAU,cAAc;AAC/C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createSettingsStore } from "./createSettingsStore.js";
|
|
2
|
-
import { createContext,
|
|
2
|
+
import { createContext, use, useRef } from "react";
|
|
3
3
|
import { useShallow } from "zustand/shallow";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/stores/settings/SettingsStore.tsx
|
|
@@ -7,13 +7,13 @@ const SettingsStoreContext = createContext(null);
|
|
|
7
7
|
const SettingsStoreProvider = ({ children, config }) => {
|
|
8
8
|
const storeRef = useRef(null);
|
|
9
9
|
if (!storeRef.current) storeRef.current = createSettingsStore(config);
|
|
10
|
-
return /* @__PURE__ */ jsx(SettingsStoreContext
|
|
10
|
+
return /* @__PURE__ */ jsx(SettingsStoreContext, {
|
|
11
11
|
value: storeRef.current,
|
|
12
12
|
children
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
15
|
function useSettingsStoreContext() {
|
|
16
|
-
const useStore =
|
|
16
|
+
const useStore = use(SettingsStoreContext);
|
|
17
17
|
if (!useStore) throw new Error("You forgot to wrap your component in SettingsStoreContext.");
|
|
18
18
|
return useStore;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SettingsStore.js","names":[],"sources":["../../../../src/stores/settings/SettingsStore.tsx"],"sourcesContent":["import {\n createContext,\n type JSX,\n type PropsWithChildren,\n
|
|
1
|
+
{"version":3,"file":"SettingsStore.js","names":[],"sources":["../../../../src/stores/settings/SettingsStore.tsx"],"sourcesContent":["import {\n createContext,\n type JSX,\n type PropsWithChildren,\n use,\n useRef,\n} from 'react'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport { createSettingsStore } from './createSettingsStore.js'\nimport type { SettingsState, SettingsStoreProviderProps } from './types.js'\n\ntype SettingsStore = UseBoundStore<StoreApi<SettingsState>>\n\nconst SettingsStoreContext = createContext<SettingsStore | null>(null)\n\nexport const SettingsStoreProvider = ({\n children,\n config,\n}: PropsWithChildren<SettingsStoreProviderProps>): JSX.Element => {\n const storeRef = useRef<SettingsStore>(null)\n if (!storeRef.current) {\n storeRef.current = createSettingsStore(config)\n }\n return (\n <SettingsStoreContext value={storeRef.current}>\n {children}\n </SettingsStoreContext>\n )\n}\n\nexport function useSettingsStoreContext(): any {\n const useStore = use(SettingsStoreContext)\n if (!useStore) {\n throw new Error(\n 'You forgot to wrap your component in SettingsStoreContext.'\n )\n }\n return useStore\n}\n\nexport function useSettingsStore<T>(selector: (state: SettingsState) => T): T {\n const useStore = useSettingsStoreContext()\n return useStore(useShallow(selector))\n}\n"],"mappings":";;;;;AAcA,MAAM,uBAAuB,cAAoC,IAAI;AAErE,MAAa,yBAAyB,EACpC,UACA,aACgE;CAChE,MAAM,WAAW,OAAsB,IAAI;CAC3C,IAAI,CAAC,SAAS,SACZ,SAAS,UAAU,oBAAoB,MAAM;CAE/C,OACE,oBAAC,sBAAD;EAAsB,OAAO,SAAS;EACnC;CACmB,CAAA;AAE1B;AAEA,SAAgB,0BAA+B;CAC7C,MAAM,WAAW,IAAI,oBAAoB;CACzC,IAAI,CAAC,UACH,MAAM,IAAI,MACR,4DACF;CAEF,OAAO;AACT;AAEA,SAAgB,iBAAoB,UAA0C;CAE5E,OADiB,wBACH,CAAC,CAAC,WAAW,QAAQ,CAAC;AACtC"}
|