@lifi/widget 4.0.0-beta.13 → 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/AmountInput/PriceFormHelperText.style.js +2 -2
- package/dist/esm/components/AmountInput/PriceFormHelperText.style.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/ButtonTertiary.js +6 -6
- package/dist/esm/components/ButtonTertiary.js.map +1 -1
- package/dist/esm/components/Card/Card.js +2 -2
- package/dist/esm/components/Card/Card.js.map +1 -1
- package/dist/esm/components/Card/CardIconButton.js +2 -2
- package/dist/esm/components/Card/CardIconButton.js.map +1 -1
- package/dist/esm/components/Card/CardLabel.js +2 -2
- package/dist/esm/components/Card/CardLabel.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/ContextMenu.style.js +1 -1
- package/dist/esm/components/ContextMenu.style.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/ActivitiesButton.style.js +4 -4
- package/dist/esm/components/Header/ActivitiesButton.style.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/Header.style.js +2 -2
- package/dist/esm/components/Header/Header.style.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/SettingsButton.style.js +8 -8
- package/dist/esm/components/Header/SettingsButton.style.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/IconCircle/IconCircle.style.js +7 -7
- package/dist/esm/components/IconCircle/IconCircle.style.js.map +1 -1
- package/dist/esm/components/IconTypography.js +2 -2
- package/dist/esm/components/IconTypography.js.map +1 -1
- package/dist/esm/components/ListItemButton.js +1 -1
- package/dist/esm/components/ListItemButton.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/Messages/AlertMessage.style.js +4 -4
- package/dist/esm/components/Messages/AlertMessage.style.js.map +1 -1
- package/dist/esm/components/Messages/GasRefuelMessage.style.js +2 -2
- package/dist/esm/components/Messages/GasRefuelMessage.style.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/CircularProgress.style.js +4 -4
- package/dist/esm/components/Step/CircularProgress.style.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/StepActions/StepActions.style.js +4 -4
- package/dist/esm/components/StepActions/StepActions.style.js.map +1 -1
- package/dist/esm/components/Switch.js +2 -2
- package/dist/esm/components/Switch.js.map +1 -1
- package/dist/esm/components/Tabs/NavigationTabs.js +2 -2
- package/dist/esm/components/Tabs/NavigationTabs.js.map +1 -1
- package/dist/esm/components/Tabs/Tabs.style.js +3 -3
- package/dist/esm/components/Tabs/Tabs.style.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/Token/Token.style.js +1 -1
- package/dist/esm/components/Token/Token.style.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/TokenList.style.js +1 -1
- package/dist/esm/components/TokenList/TokenList.style.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/TransactionCard/ActiveTransactionCard.style.js +1 -1
- package/dist/esm/components/TransactionCard/ActiveTransactionCard.style.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/ResetSettingsButton.style.js +2 -2
- package/dist/esm/pages/SettingsPage/ResetSettingsButton.style.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/SlippageSettings/SlippageSettings.style.js +5 -5
- package/dist/esm/pages/SettingsPage/SlippageSettings/SlippageSettings.style.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/ActionRow.style.js +2 -2
- package/dist/esm/pages/TransactionDetailsPage/ActionRow.style.js.map +1 -1
- package/dist/esm/pages/TransactionDetailsPage/ReceiptsCard.style.js +1 -1
- package/dist/esm/pages/TransactionDetailsPage/ReceiptsCard.style.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 +12 -13
- 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 +19 -23
- package/dist/esm/themes/createTheme.js.map +1 -1
- package/dist/esm/themes/types.d.ts +0 -11
- package/dist/esm/themes/types.d.ts.map +1 -1
- package/dist/esm/themes/watermelonLight.js +1 -1
- package/dist/esm/themes/watermelonLight.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/AmountInput/PriceFormHelperText.style.tsx +2 -2
- package/src/components/ButtonTertiary.tsx +6 -6
- package/src/components/Card/Card.tsx +2 -2
- package/src/components/Card/CardIconButton.tsx +2 -2
- package/src/components/Card/CardLabel.tsx +2 -2
- package/src/components/Chains/AllChainsAvatar.tsx +6 -0
- package/src/components/ContextMenu.style.tsx +1 -1
- package/src/components/ContractComponent/ItemPrice.tsx +1 -1
- package/src/components/ContractComponent/NFT/NFTBase.tsx +1 -1
- package/src/components/Header/ActivitiesButton.style.tsx +4 -4
- package/src/components/Header/ActivitiesButton.tsx +1 -1
- package/src/components/Header/Header.style.ts +2 -2
- package/src/components/Header/SettingsButton.style.tsx +8 -8
- package/src/components/IconCircle/IconCircle.style.tsx +7 -7
- package/src/components/IconTypography.ts +8 -8
- package/src/components/ListItemButton.tsx +1 -1
- package/src/components/Messages/AlertMessage.style.tsx +4 -4
- package/src/components/Messages/AlertMessage.tsx +1 -1
- package/src/components/Messages/GasRefuelMessage.style.ts +2 -2
- package/src/components/RouteCard/RouteCardEssentials.tsx +2 -2
- package/src/components/SelectChainAndToken.tsx +1 -1
- package/src/components/Step/CircularProgress.style.tsx +4 -4
- package/src/components/Step/Step.tsx +6 -7
- package/src/components/StepActions/StepActions.style.tsx +4 -4
- package/src/components/Switch.tsx +2 -2
- package/src/components/Tabs/NavigationTabs.tsx +2 -2
- package/src/components/Tabs/Tabs.style.tsx +3 -3
- package/src/components/Timer/TimerContent.tsx +1 -0
- package/src/components/Token/Token.style.tsx +1 -1
- package/src/components/Token/Token.tsx +2 -2
- package/src/components/TokenList/TokenDetailsSheetContent.tsx +6 -4
- package/src/components/TokenList/TokenList.style.tsx +1 -1
- package/src/components/TransactionCard/ActiveTransactionCard.style.tsx +1 -1
- 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/SettingsPage/ResetSettingsButton.style.tsx +2 -2
- package/src/pages/SettingsPage/SlippageSettings/SlippageSettings.style.tsx +5 -5
- package/src/pages/TransactionDetailsPage/ActionRow.style.tsx +2 -2
- package/src/pages/TransactionDetailsPage/ReceiptsCard.style.tsx +1 -1
- package/src/pages/TransactionPage/ExchangeRateBottomSheet.tsx +1 -1
- package/src/pages/TransactionPage/StatusBottomSheet.style.tsx +7 -7
- 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 +18 -24
- package/src/themes/types.ts +0 -12
- package/src/themes/watermelonLight.ts +1 -1
- 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatusBottomSheet.style.js","names":[],"sources":["../../../../src/pages/TransactionPage/StatusBottomSheet.style.tsx"],"sourcesContent":["import type { Theme } from '@mui/material'\nimport { Box, styled } from '@mui/material'\nimport type React from 'react'\nimport { RouteExecutionStatus } from '../../stores/routes/types.js'\n\ntype StatusColor = RouteExecutionStatus | 'warning'\n\nconst getStatusColor = (status: StatusColor, theme: Theme) => {\n switch (status) {\n case RouteExecutionStatus.Done:\n return {\n color: theme.vars.palette.success.
|
|
1
|
+
{"version":3,"file":"StatusBottomSheet.style.js","names":[],"sources":["../../../../src/pages/TransactionPage/StatusBottomSheet.style.tsx"],"sourcesContent":["import type { Theme } from '@mui/material'\nimport { Box, styled } from '@mui/material'\nimport type React from 'react'\nimport { RouteExecutionStatus } from '../../stores/routes/types.js'\n\ntype StatusColor = RouteExecutionStatus | 'warning'\n\nconst getStatusColor = (status: StatusColor, theme: Theme) => {\n switch (status) {\n case RouteExecutionStatus.Done:\n return {\n color: theme.vars.palette.success.main,\n alpha: 0.12,\n lightDarken: 0,\n darkDarken: 0,\n }\n case RouteExecutionStatus.Failed:\n return {\n color: theme.vars.palette.error.main,\n alpha: 0.12,\n lightDarken: 0,\n darkDarken: 0,\n }\n case RouteExecutionStatus.Done | RouteExecutionStatus.Partial:\n case RouteExecutionStatus.Done | RouteExecutionStatus.Refunded:\n case 'warning':\n return {\n color: theme.vars.palette.warning.main,\n alpha: 0.48,\n lightDarken: 0.32,\n darkDarken: 0,\n }\n default:\n return {\n color: theme.vars.palette.primary.main,\n alpha: 0.12,\n lightDarken: 0,\n darkDarken: 0,\n }\n }\n}\n\nexport const CenterContainer: React.FC<\n React.ComponentProps<typeof Box> & { status?: StatusColor }\n> = styled(Box)(() => ({\n display: 'grid',\n placeItems: 'center',\n position: 'relative',\n}))\n\nexport const IconCircle: React.FC<\n React.ComponentProps<typeof Box> & { status?: StatusColor }\n> = styled(Box, {\n shouldForwardProp: (prop) => prop !== 'status',\n})<{ status?: StatusColor }>(\n ({ theme, status = RouteExecutionStatus.Idle }) => {\n const statusConfig = getStatusColor(status, theme)\n\n return {\n backgroundColor: `color-mix(in srgb, ${statusConfig.color} ${statusConfig.alpha * 100}%, transparent)`,\n borderRadius: '50%',\n width: 72,\n height: 72,\n display: 'grid',\n position: 'relative',\n placeItems: 'center',\n '& > svg': {\n color: `color-mix(in srgb, ${statusConfig.color} ${(1 - statusConfig.lightDarken) * 100}%, black)`,\n width: 36,\n height: 36,\n },\n ...theme.applyStyles('dark', {\n '& > svg': {\n color: `color-mix(in srgb, ${statusConfig.color} ${(1 - statusConfig.darkDarken) * 100}%, black)`,\n width: 36,\n height: 36,\n },\n }),\n }\n }\n)\n"],"mappings":";;AAOA,MAAM,kBAAkB,QAAqB,UAAiB;AAC5D,SAAQ,QAAR;EACE,KAAA,EACE,QAAO;GACL,OAAO,MAAM,KAAK,QAAQ,QAAQ;GAClC,OAAO;GACP,aAAa;GACb,YAAY;GACb;EACH,KAAA,EACE,QAAO;GACL,OAAO,MAAM,KAAK,QAAQ,MAAM;GAChC,OAAO;GACP,aAAa;GACb,YAAY;GACb;EACH,KAAA;EACA,KAAA;EACA,KAAK,UACH,QAAO;GACL,OAAO,MAAM,KAAK,QAAQ,QAAQ;GAClC,OAAO;GACP,aAAa;GACb,YAAY;GACb;EACH,QACE,QAAO;GACL,OAAO,MAAM,KAAK,QAAQ,QAAQ;GAClC,OAAO;GACP,aAAa;GACb,YAAY;GACb;;;AAIP,MAAa,kBAET,OAAO,IAAI,QAAQ;CACrB,SAAS;CACT,YAAY;CACZ,UAAU;CACX,EAAE;AAEH,MAAa,aAET,OAAO,KAAK,EACd,oBAAoB,SAAS,SAAS,UACvC,CAAC,EACC,EAAE,OAAO,SAAA,QAAyC;CACjD,MAAM,eAAe,eAAe,QAAQ,MAAM;AAElD,QAAO;EACL,iBAAiB,sBAAsB,aAAa,MAAM,GAAG,aAAa,QAAQ,IAAI;EACtF,cAAc;EACd,OAAO;EACP,QAAQ;EACR,SAAS;EACT,UAAU;EACV,YAAY;EACZ,WAAW;GACT,OAAO,sBAAsB,aAAa,MAAM,IAAI,IAAI,aAAa,eAAe,IAAI;GACxF,OAAO;GACP,QAAQ;GACT;EACD,GAAG,MAAM,YAAY,QAAQ,EAC3B,WAAW;GACT,OAAO,sBAAsB,aAAa,MAAM,IAAI,IAAI,aAAa,cAAc,IAAI;GACvF,OAAO;GACP,QAAQ;GACT,EACF,CAAC;EACH;EAEJ"}
|
|
@@ -4,8 +4,8 @@ import { BottomSheet } from "../../components/BottomSheet/BottomSheet.js";
|
|
|
4
4
|
import { useSetContentHeight } from "../../hooks/useSetContentHeight.js";
|
|
5
5
|
import { CenterContainer, IconCircle } from "./StatusBottomSheet.style.js";
|
|
6
6
|
import { calculateValueLossPercentage } from "./utils.js";
|
|
7
|
-
import { forwardRef, useRef } from "react";
|
|
8
|
-
import { Box, Button, Typography } from "@mui/material";
|
|
7
|
+
import { forwardRef, useRef, useState } from "react";
|
|
8
|
+
import { Box, Button, Checkbox, FormControlLabel, Typography } from "@mui/material";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
import { useTranslation } from "react-i18next";
|
|
11
11
|
import WarningRounded from "@mui/icons-material/WarningRounded";
|
|
@@ -26,6 +26,7 @@ const TokenValueBottomSheet = forwardRef(({ route, onContinue, onCancel }, ref)
|
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
28
|
const TokenValueBottomSheetContent = ({ route, onCancel, onContinue }) => {
|
|
29
|
+
const [accepted, setAccepted] = useState(false);
|
|
29
30
|
const { t } = useTranslation();
|
|
30
31
|
const ref = useRef(null);
|
|
31
32
|
useSetContentHeight(ref);
|
|
@@ -38,7 +39,7 @@ const TokenValueBottomSheetContent = ({ route, onCancel, onContinue }) => {
|
|
|
38
39
|
children: [
|
|
39
40
|
/* @__PURE__ */ jsxs(CenterContainer, { children: [/* @__PURE__ */ jsx(IconCircle, {
|
|
40
41
|
status: "warning",
|
|
41
|
-
mb: 1,
|
|
42
|
+
sx: { mb: 1 },
|
|
42
43
|
children: /* @__PURE__ */ jsx(WarningRounded, { color: "warning" })
|
|
43
44
|
}), /* @__PURE__ */ jsx(Typography, {
|
|
44
45
|
sx: {
|
|
@@ -114,10 +115,18 @@ const TokenValueBottomSheetContent = ({ route, onCancel, onContinue }) => {
|
|
|
114
115
|
children: [calculateValueLossPercentage(fromAmountUSD, toAmountUSD, gasCostUSD, feeCostUSD), "%"]
|
|
115
116
|
})]
|
|
116
117
|
}),
|
|
118
|
+
/* @__PURE__ */ jsx(FormControlLabel, {
|
|
119
|
+
control: /* @__PURE__ */ jsx(Checkbox, {
|
|
120
|
+
checked: accepted,
|
|
121
|
+
onChange: (_, checked) => setAccepted(checked)
|
|
122
|
+
}),
|
|
123
|
+
label: t("warning.checkbox.highValueLoss"),
|
|
124
|
+
sx: { mt: 1 }
|
|
125
|
+
}),
|
|
117
126
|
/* @__PURE__ */ jsxs(Box, {
|
|
118
127
|
sx: {
|
|
119
128
|
display: "flex",
|
|
120
|
-
mt:
|
|
129
|
+
mt: 1
|
|
121
130
|
},
|
|
122
131
|
children: [
|
|
123
132
|
/* @__PURE__ */ jsx(Button, {
|
|
@@ -133,6 +142,7 @@ const TokenValueBottomSheetContent = ({ route, onCancel, onContinue }) => {
|
|
|
133
142
|
/* @__PURE__ */ jsx(Button, {
|
|
134
143
|
variant: "contained",
|
|
135
144
|
onClick: onContinue,
|
|
145
|
+
disabled: !accepted,
|
|
136
146
|
fullWidth: true,
|
|
137
147
|
children: t("button.continue")
|
|
138
148
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenValueBottomSheet.js","names":[],"sources":["../../../../src/pages/TransactionPage/TokenValueBottomSheet.tsx"],"sourcesContent":["import type { Route } from '@lifi/sdk'\nimport WarningRounded from '@mui/icons-material/WarningRounded'\nimport {
|
|
1
|
+
{"version":3,"file":"TokenValueBottomSheet.js","names":[],"sources":["../../../../src/pages/TransactionPage/TokenValueBottomSheet.tsx"],"sourcesContent":["import type { Route } from '@lifi/sdk'\nimport WarningRounded from '@mui/icons-material/WarningRounded'\nimport {\n Box,\n Button,\n Checkbox,\n FormControlLabel,\n Typography,\n} from '@mui/material'\nimport type { ForwardRefExoticComponent, RefAttributes, RefObject } from 'react'\nimport { forwardRef, useRef, useState } from 'react'\nimport { useTranslation } from 'react-i18next'\nimport { BottomSheet } from '../../components/BottomSheet/BottomSheet.js'\nimport type { BottomSheetBase } from '../../components/BottomSheet/types.js'\nimport { FeeBreakdownTooltip } from '../../components/FeeBreakdownTooltip.js'\nimport { useSetContentHeight } from '../../hooks/useSetContentHeight.js'\nimport { getAccumulatedFeeCostsBreakdown } from '../../utils/fees.js'\nimport { CenterContainer, IconCircle } from './StatusBottomSheet.style.js'\nimport { calculateValueLossPercentage } from './utils.js'\n\ninterface TokenValueBottomSheetProps {\n route: Route\n onContinue(): void\n onCancel?(): void\n}\n\nexport const TokenValueBottomSheet: ForwardRefExoticComponent<\n TokenValueBottomSheetProps & RefAttributes<BottomSheetBase>\n> = forwardRef<BottomSheetBase, TokenValueBottomSheetProps>(\n ({ route, onContinue, onCancel }, ref) => {\n const handleCancel = () => {\n ;(ref as RefObject<BottomSheetBase>).current?.close()\n onCancel?.()\n }\n\n return (\n <BottomSheet ref={ref} onClose={onCancel}>\n <TokenValueBottomSheetContent\n route={route}\n onContinue={onContinue}\n onCancel={handleCancel}\n />\n </BottomSheet>\n )\n }\n)\n\nconst TokenValueBottomSheetContent: React.FC<TokenValueBottomSheetProps> = ({\n route,\n onCancel,\n onContinue,\n}) => {\n const [accepted, setAccepted] = useState(false)\n const { t } = useTranslation()\n const ref = useRef<HTMLElement>(null)\n useSetContentHeight(ref)\n const { gasCosts, feeCosts, gasCostUSD, feeCostUSD } =\n getAccumulatedFeeCostsBreakdown(route)\n const fromAmountUSD = Number.parseFloat(route.fromAmountUSD)\n const toAmountUSD = Number.parseFloat(route.toAmountUSD)\n return (\n <Box\n ref={ref}\n sx={{\n p: 3,\n }}\n >\n <CenterContainer>\n <IconCircle status=\"warning\" sx={{ mb: 1 }}>\n <WarningRounded color=\"warning\" />\n </IconCircle>\n <Typography\n sx={{\n py: 1,\n fontSize: 18,\n fontWeight: 700,\n }}\n >\n {t('warning.title.highValueLoss')}\n </Typography>\n </CenterContainer>\n <Typography\n sx={{\n py: 1,\n }}\n >\n {t('warning.message.highValueLoss')}\n </Typography>\n <Box\n sx={{\n display: 'flex',\n justifyContent: 'space-between',\n mt: 1,\n }}\n >\n <Typography>{t('main.sending')}</Typography>\n <Typography\n sx={{\n fontWeight: 600,\n }}\n >\n {t('format.currency', { value: route.fromAmountUSD })}\n </Typography>\n </Box>\n <Box\n sx={{\n display: 'flex',\n justifyContent: 'space-between',\n mt: 0.25,\n }}\n >\n <Typography>{t('main.fees.network')}</Typography>\n <FeeBreakdownTooltip gasCosts={gasCosts} gasless={!gasCostUSD}>\n <Typography\n sx={{\n fontWeight: 600,\n }}\n >\n {!gasCostUSD\n ? t('main.fees.free')\n : t('format.currency', { value: gasCostUSD })}\n </Typography>\n </FeeBreakdownTooltip>\n </Box>\n {feeCostUSD ? (\n <Box\n sx={{\n display: 'flex',\n justifyContent: 'space-between',\n mt: 0.25,\n }}\n >\n <Typography>{t('main.fees.provider')}</Typography>\n <FeeBreakdownTooltip feeCosts={feeCosts}>\n <Typography\n sx={{\n fontWeight: 600,\n }}\n >\n {t('format.currency', { value: feeCostUSD })}\n </Typography>\n </FeeBreakdownTooltip>\n </Box>\n ) : null}\n <Box\n sx={{\n display: 'flex',\n justifyContent: 'space-between',\n mt: 0.25,\n }}\n >\n <Typography>{t('main.receiving')}</Typography>\n <Typography\n sx={{\n fontWeight: 600,\n }}\n >\n {t('format.currency', { value: route.toAmountUSD })}\n </Typography>\n </Box>\n <Box\n sx={{\n display: 'flex',\n justifyContent: 'space-between',\n mt: 0.25,\n }}\n >\n <Typography>{t('main.valueLoss')}</Typography>\n <Typography\n sx={{\n fontWeight: 600,\n }}\n >\n {calculateValueLossPercentage(\n fromAmountUSD,\n toAmountUSD,\n gasCostUSD,\n feeCostUSD\n )}\n %\n </Typography>\n </Box>\n <FormControlLabel\n control={\n <Checkbox\n checked={accepted}\n onChange={(_, checked) => setAccepted(checked)}\n />\n }\n label={t('warning.checkbox.highValueLoss')}\n sx={{ mt: 1 }}\n />\n <Box\n sx={{\n display: 'flex',\n mt: 1,\n }}\n >\n <Button variant=\"text\" onClick={onCancel} fullWidth>\n {t('button.cancel')}\n </Button>\n <Box\n sx={{\n display: 'flex',\n p: 1,\n }}\n />\n <Button\n variant=\"contained\"\n onClick={onContinue}\n disabled={!accepted}\n fullWidth\n >\n {t('button.continue')}\n </Button>\n </Box>\n </Box>\n )\n}\n"],"mappings":";;;;;;;;;;;;AA0BA,MAAa,wBAET,YACD,EAAE,OAAO,YAAY,YAAY,QAAQ;CACxC,MAAM,qBAAqB;AACvB,MAAmC,SAAS,OAAO;AACrD,cAAY;;AAGd,QACE,oBAAC,aAAD;EAAkB;EAAK,SAAS;YAC9B,oBAAC,8BAAD;GACS;GACK;GACZ,UAAU;GACV,CAAA;EACU,CAAA;EAGnB;AAED,MAAM,gCAAsE,EAC1E,OACA,UACA,iBACI;CACJ,MAAM,CAAC,UAAU,eAAe,SAAS,MAAM;CAC/C,MAAM,EAAE,MAAM,gBAAgB;CAC9B,MAAM,MAAM,OAAoB,KAAK;AACrC,qBAAoB,IAAI;CACxB,MAAM,EAAE,UAAU,UAAU,YAAY,eACtC,gCAAgC,MAAM;CACxC,MAAM,gBAAgB,OAAO,WAAW,MAAM,cAAc;CAC5D,MAAM,cAAc,OAAO,WAAW,MAAM,YAAY;AACxD,QACE,qBAAC,KAAD;EACO;EACL,IAAI,EACF,GAAG,GACJ;YAJH;GAME,qBAAC,iBAAD,EAAA,UAAA,CACE,oBAAC,YAAD;IAAY,QAAO;IAAU,IAAI,EAAE,IAAI,GAAG;cACxC,oBAAC,gBAAD,EAAgB,OAAM,WAAY,CAAA;IACvB,CAAA,EACb,oBAAC,YAAD;IACE,IAAI;KACF,IAAI;KACJ,UAAU;KACV,YAAY;KACb;cAEA,EAAE,8BAA8B;IACtB,CAAA,CACG,EAAA,CAAA;GAClB,oBAAC,YAAD;IACE,IAAI,EACF,IAAI,GACL;cAEA,EAAE,gCAAgC;IACxB,CAAA;GACb,qBAAC,KAAD;IACE,IAAI;KACF,SAAS;KACT,gBAAgB;KAChB,IAAI;KACL;cALH,CAOE,oBAAC,YAAD,EAAA,UAAa,EAAE,eAAe,EAAc,CAAA,EAC5C,oBAAC,YAAD;KACE,IAAI,EACF,YAAY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S;KACT,WAAW,GAAG,YAAY,YAAY,QAAQ;KAC9C,CAAA;IAEJ,OAAO,EAAE,iCAAiC;IAC1C,IAAI,EAAE,IAAI,GAAG;IACb,CAAA;GACF,qBAAC,KAAD;IACE,IAAI;KACF,SAAS;KACT,IAAI;KACL;cAJH;KAME,oBAAC,QAAD;MAAQ,SAAQ;MAAO,SAAS;MAAU,WAAA;gBACvC,EAAE,gBAAgB;MACZ,CAAA;KACT,oBAAC,KAAD,EACE,IAAI;MACF,SAAS;MACT,GAAG;MACJ,EACD,CAAA;KACF,oBAAC,QAAD;MACE,SAAQ;MACR,SAAS;MACT,UAAU,CAAC;MACX,WAAA;gBAEC,EAAE,kBAAkB;MACd,CAAA;KACL;;GACF"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { useWidgetEvents } from "../../hooks/useWidgetEvents.js";
|
|
2
|
-
import
|
|
2
|
+
import "../../types/events.js";
|
|
3
3
|
import { useWidgetConfig } from "../../providers/WidgetProvider/WidgetProvider.js";
|
|
4
4
|
import { useHeaderStore } from "../../stores/header/useHeaderStore.js";
|
|
5
|
-
import
|
|
5
|
+
import "../../types/widget.js";
|
|
6
6
|
import { navigationRoutes } from "../../utils/navigationRoutes.js";
|
|
7
7
|
import { useFieldActions } from "../../stores/form/useFieldActions.js";
|
|
8
8
|
import { PageContainer } from "../../components/PageContainer.js";
|
|
9
|
-
import { RouteExecutionStatus } from "../../stores/routes/types.js";
|
|
10
9
|
import { getAccumulatedFeeCostsBreakdown } from "../../utils/fees.js";
|
|
11
10
|
import { useNavigateBack } from "../../hooks/useNavigateBack.js";
|
|
12
11
|
import { useHeader } from "../../hooks/useHeader.js";
|
|
@@ -23,7 +22,7 @@ import { StartTransactionButton } from "./StartTransactionButton.js";
|
|
|
23
22
|
import { StatusBottomSheet } from "./StatusBottomSheet.js";
|
|
24
23
|
import { calculateValueLossPercentage, getTokenValueLossThreshold } from "./utils.js";
|
|
25
24
|
import { TokenValueBottomSheet } from "./TokenValueBottomSheet.js";
|
|
26
|
-
import {
|
|
25
|
+
import { useMemo, useRef, useState } from "react";
|
|
27
26
|
import { useLocation, useNavigate } from "@tanstack/react-router";
|
|
28
27
|
import { Box, Button, Tooltip } from "@mui/material";
|
|
29
28
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -57,26 +56,23 @@ const TransactionPage = () => {
|
|
|
57
56
|
if (subvariant === "custom") return t(`header.${subvariantOptions?.custom ?? "checkout"}`);
|
|
58
57
|
if (route) {
|
|
59
58
|
const transactionType = route.fromChainId === route.toChainId ? "swap" : "bridge";
|
|
60
|
-
return status ===
|
|
59
|
+
return status === 1 ? t(`button.${transactionType}Review`) : t(`header.${transactionType}`);
|
|
61
60
|
}
|
|
62
61
|
return t("header.exchange");
|
|
63
62
|
};
|
|
64
|
-
const headerAction = useMemo(() => status ===
|
|
63
|
+
const headerAction = useMemo(() => status === 1 ? /* @__PURE__ */ jsx(RouteTracker, {
|
|
65
64
|
observableRouteId: stateRouteId,
|
|
66
65
|
onChange: setRouteId,
|
|
67
66
|
onFetching: setRouteRefreshing
|
|
68
67
|
}) : void 0, [stateRouteId, status]);
|
|
69
68
|
useHeader(getHeaderTitle(), headerAction);
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
if (status === RouteExecutionStatus.Idle) emitter.emit(WidgetEvent.ReviewTransactionPageEntered, route);
|
|
72
|
-
}, []);
|
|
73
69
|
if (!route) return null;
|
|
74
70
|
const handleExecuteRoute = () => {
|
|
75
71
|
if (tokenValueBottomSheetRef.current?.isOpen()) {
|
|
76
72
|
const { gasCostUSD, feeCostUSD } = getAccumulatedFeeCostsBreakdown(route);
|
|
77
73
|
const fromAmountUSD = Number.parseFloat(route.fromAmountUSD);
|
|
78
74
|
const toAmountUSD = Number.parseFloat(route.toAmountUSD);
|
|
79
|
-
emitter.emit(
|
|
75
|
+
emitter.emit("routeHighValueLoss", {
|
|
80
76
|
fromAmountUSD,
|
|
81
77
|
toAmountUSD,
|
|
82
78
|
gasCostUSD,
|
|
@@ -99,8 +95,8 @@ const TransactionPage = () => {
|
|
|
99
95
|
});
|
|
100
96
|
};
|
|
101
97
|
const handleStartClick = async () => {
|
|
102
|
-
if (status ===
|
|
103
|
-
if (toAddress && !hasActivity && !isLoadingAddressActivity && isActivityAddressFetched && !hiddenUI?.includes(
|
|
98
|
+
if (status === 1) {
|
|
99
|
+
if (toAddress && !hasActivity && !isLoadingAddressActivity && isActivityAddressFetched && !hiddenUI?.includes("lowAddressActivityConfirmation")) {
|
|
104
100
|
confirmToAddressSheetRef.current?.open();
|
|
105
101
|
return;
|
|
106
102
|
}
|
|
@@ -108,7 +104,7 @@ const TransactionPage = () => {
|
|
|
108
104
|
if (getTokenValueLossThreshold(Number.parseFloat(route.fromAmountUSD), Number.parseFloat(route.toAmountUSD), gasCostUSD, feeCostUSD) && subvariant !== "custom") tokenValueBottomSheetRef.current?.open();
|
|
109
105
|
else handleExecuteRoute();
|
|
110
106
|
}
|
|
111
|
-
if (status ===
|
|
107
|
+
if (status === 8) restartRoute();
|
|
112
108
|
};
|
|
113
109
|
const handleRemoveRoute = () => {
|
|
114
110
|
navigateBack();
|
|
@@ -116,12 +112,12 @@ const TransactionPage = () => {
|
|
|
116
112
|
};
|
|
117
113
|
const getButtonText = () => {
|
|
118
114
|
switch (status) {
|
|
119
|
-
case
|
|
115
|
+
case 1: switch (subvariant) {
|
|
120
116
|
case "custom": return subvariantOptions?.custom === "deposit" ? t("button.deposit") : t("button.buy");
|
|
121
117
|
case "refuel": return t("button.startBridging");
|
|
122
118
|
default: return t(`button.start${route.fromChainId === route.toChainId ? "Swapping" : "Bridging"}`);
|
|
123
119
|
}
|
|
124
|
-
case
|
|
120
|
+
case 8: return t("button.tryAgain");
|
|
125
121
|
default: return "";
|
|
126
122
|
}
|
|
127
123
|
};
|
|
@@ -137,8 +133,8 @@ const TransactionPage = () => {
|
|
|
137
133
|
route,
|
|
138
134
|
sx: { marginTop: 2 }
|
|
139
135
|
}),
|
|
140
|
-
status ===
|
|
141
|
-
mt: 2,
|
|
136
|
+
status === 1 || status === 8 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(WarningMessages, {
|
|
137
|
+
sx: { mt: 2 },
|
|
142
138
|
route,
|
|
143
139
|
allowInteraction: true
|
|
144
140
|
}), /* @__PURE__ */ jsxs(Box, {
|
|
@@ -151,7 +147,7 @@ const TransactionPage = () => {
|
|
|
151
147
|
onClick: handleStartClick,
|
|
152
148
|
route,
|
|
153
149
|
loading: routeRefreshing || isLoadingAddressActivity
|
|
154
|
-
}), status ===
|
|
150
|
+
}), status === 8 ? /* @__PURE__ */ jsx(Tooltip, {
|
|
155
151
|
title: t("button.clearTransaction"),
|
|
156
152
|
placement: "bottom-end",
|
|
157
153
|
children: /* @__PURE__ */ jsx(Button, {
|
|
@@ -174,7 +170,7 @@ const TransactionPage = () => {
|
|
|
174
170
|
onContinue: handleExecuteRoute
|
|
175
171
|
}) : null,
|
|
176
172
|
/* @__PURE__ */ jsx(ExchangeRateBottomSheet, { ref: exchangeRateBottomSheetRef }),
|
|
177
|
-
!hiddenUI?.includes(
|
|
173
|
+
!hiddenUI?.includes("lowAddressActivityConfirmation") ? /* @__PURE__ */ jsx(ConfirmToAddressSheet, {
|
|
178
174
|
ref: confirmToAddressSheetRef,
|
|
179
175
|
onContinue: handleExecuteRoute,
|
|
180
176
|
toAddress,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionPage.js","names":[],"sources":["../../../../src/pages/TransactionPage/TransactionPage.tsx"],"sourcesContent":["import type { ExchangeRateUpdateParams } from '@lifi/sdk'\nimport Delete from '@mui/icons-material/Delete'\nimport { Box, Button, Tooltip } from '@mui/material'\nimport { useLocation, useNavigate } from '@tanstack/react-router'\nimport { type JSX, useEffect, useMemo, useRef, useState } from 'react'\nimport { useTranslation } from 'react-i18next'\nimport type { BottomSheetBase } from '../../components/BottomSheet/types.js'\nimport { ContractComponent } from '../../components/ContractComponent/ContractComponent.js'\nimport { WarningMessages } from '../../components/Messages/WarningMessages.js'\nimport { PageContainer } from '../../components/PageContainer.js'\nimport { getStepList } from '../../components/Step/StepList.js'\nimport { TransactionDetails } from '../../components/TransactionDetails.js'\nimport { useAddressActivity } from '../../hooks/useAddressActivity.js'\nimport { useHeader } from '../../hooks/useHeader.js'\nimport { useNavigateBack } from '../../hooks/useNavigateBack.js'\nimport { useRouteExecution } from '../../hooks/useRouteExecution.js'\nimport { useWidgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { useWidgetConfig } from '../../providers/WidgetProvider/WidgetProvider.js'\nimport { useFieldActions } from '../../stores/form/useFieldActions.js'\nimport { useHeaderStore } from '../../stores/header/useHeaderStore.js'\nimport { RouteExecutionStatus } from '../../stores/routes/types.js'\nimport { WidgetEvent } from '../../types/events.js'\nimport { HiddenUI } from '../../types/widget.js'\nimport { getAccumulatedFeeCostsBreakdown } from '../../utils/fees.js'\nimport { navigationRoutes } from '../../utils/navigationRoutes.js'\nimport { ConfirmToAddressSheet } from './ConfirmToAddressSheet.js'\nimport type { ExchangeRateBottomSheetBase } from './ExchangeRateBottomSheet.js'\nimport { ExchangeRateBottomSheet } from './ExchangeRateBottomSheet.js'\nimport { RouteTracker } from './RouteTracker.js'\nimport { StartTransactionButton } from './StartTransactionButton.js'\nimport { StatusBottomSheet } from './StatusBottomSheet.js'\nimport { TokenValueBottomSheet } from './TokenValueBottomSheet.js'\nimport {\n calculateValueLossPercentage,\n getTokenValueLossThreshold,\n} from './utils.js'\n\nexport const TransactionPage = (): JSX.Element | null => {\n const { t } = useTranslation()\n const { setFieldValue } = useFieldActions()\n const emitter = useWidgetEvents()\n const setBackAction = useHeaderStore((state) => state.setBackAction)\n const navigate = useNavigate()\n const navigateBack = useNavigateBack()\n const {\n subvariant,\n subvariantOptions,\n contractSecondaryComponent,\n hiddenUI,\n } = useWidgetConfig()\n const { search }: any = useLocation()\n const stateRouteId = search?.routeId\n const [routeId, setRouteId] = useState<string>(stateRouteId)\n const [routeRefreshing, setRouteRefreshing] = useState(false)\n\n const tokenValueBottomSheetRef = useRef<BottomSheetBase>(null)\n const exchangeRateBottomSheetRef = useRef<ExchangeRateBottomSheetBase>(null)\n const confirmToAddressSheetRef = useRef<BottomSheetBase>(null)\n\n const onAcceptExchangeRateUpdate = (\n resolver: (value: boolean) => void,\n data: ExchangeRateUpdateParams\n ) => {\n exchangeRateBottomSheetRef.current?.open(resolver, data)\n }\n\n const { route, status, executeRoute, restartRoute, deleteRoute } =\n useRouteExecution({\n routeId: routeId,\n onAcceptExchangeRateUpdate,\n })\n\n const {\n toAddress,\n hasActivity,\n isLoading: isLoadingAddressActivity,\n isFetched: isActivityAddressFetched,\n } = useAddressActivity(route?.toChainId)\n\n const getHeaderTitle = () => {\n if (subvariant === 'custom') {\n return t(`header.${subvariantOptions?.custom ?? 'checkout'}`)\n }\n if (route) {\n const transactionType =\n route.fromChainId === route.toChainId ? 'swap' : 'bridge'\n return status === RouteExecutionStatus.Idle\n ? t(`button.${transactionType}Review`)\n : t(`header.${transactionType}`)\n }\n\n return t('header.exchange')\n }\n\n const headerAction = useMemo(\n () =>\n status === RouteExecutionStatus.Idle ? (\n <RouteTracker\n observableRouteId={stateRouteId}\n onChange={setRouteId}\n onFetching={setRouteRefreshing}\n />\n ) : undefined,\n [stateRouteId, status]\n )\n\n useHeader(getHeaderTitle(), headerAction)\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: We want to emit event only when the page is mounted\n useEffect(() => {\n if (status === RouteExecutionStatus.Idle) {\n emitter.emit(WidgetEvent.ReviewTransactionPageEntered, route)\n }\n }, [])\n\n if (!route) {\n return null\n }\n\n const handleExecuteRoute = () => {\n if (tokenValueBottomSheetRef.current?.isOpen()) {\n const { gasCostUSD, feeCostUSD } = getAccumulatedFeeCostsBreakdown(route)\n const fromAmountUSD = Number.parseFloat(route.fromAmountUSD)\n const toAmountUSD = Number.parseFloat(route.toAmountUSD)\n emitter.emit(WidgetEvent.RouteHighValueLoss, {\n fromAmountUSD,\n toAmountUSD,\n gasCostUSD,\n feeCostUSD,\n valueLoss: calculateValueLossPercentage(\n fromAmountUSD,\n toAmountUSD,\n gasCostUSD,\n feeCostUSD\n ),\n })\n }\n tokenValueBottomSheetRef.current?.close()\n executeRoute()\n setFieldValue('fromAmount', '')\n if (subvariant === 'custom') {\n setFieldValue('fromToken', '')\n setFieldValue('toToken', '')\n }\n // Once transaction is started, set the back action to navigate to the home page\n setBackAction(() => {\n navigate({ to: navigationRoutes.home, replace: true })\n })\n }\n\n const handleStartClick = async () => {\n if (status === RouteExecutionStatus.Idle) {\n if (\n toAddress &&\n !hasActivity &&\n !isLoadingAddressActivity &&\n isActivityAddressFetched &&\n !hiddenUI?.includes(HiddenUI.LowAddressActivityConfirmation)\n ) {\n confirmToAddressSheetRef.current?.open()\n return\n }\n\n const { gasCostUSD, feeCostUSD } = getAccumulatedFeeCostsBreakdown(route)\n const fromAmountUSD = Number.parseFloat(route.fromAmountUSD)\n const toAmountUSD = Number.parseFloat(route.toAmountUSD)\n const tokenValueLossThresholdExceeded = getTokenValueLossThreshold(\n fromAmountUSD,\n toAmountUSD,\n gasCostUSD,\n feeCostUSD\n )\n if (tokenValueLossThresholdExceeded && subvariant !== 'custom') {\n tokenValueBottomSheetRef.current?.open()\n } else {\n handleExecuteRoute()\n }\n }\n if (status === RouteExecutionStatus.Failed) {\n restartRoute()\n }\n }\n\n const handleRemoveRoute = () => {\n navigateBack()\n deleteRoute()\n }\n\n const getButtonText = (): string => {\n switch (status) {\n case RouteExecutionStatus.Idle:\n switch (subvariant) {\n case 'custom':\n return subvariantOptions?.custom === 'deposit'\n ? t('button.deposit')\n : t('button.buy')\n case 'refuel':\n return t('button.startBridging')\n default: {\n const transactionType =\n route.fromChainId === route.toChainId ? 'Swapping' : 'Bridging'\n return t(`button.start${transactionType}`)\n }\n }\n case RouteExecutionStatus.Failed:\n return t('button.tryAgain')\n default:\n return ''\n }\n }\n\n return (\n <PageContainer bottomGutters>\n {getStepList(route, subvariant)}\n {subvariant === 'custom' && contractSecondaryComponent ? (\n <ContractComponent sx={{ marginTop: 2 }}>\n {contractSecondaryComponent}\n </ContractComponent>\n ) : null}\n <TransactionDetails route={route} sx={{ marginTop: 2 }} />\n {status === RouteExecutionStatus.Idle ||\n status === RouteExecutionStatus.Failed ? (\n <>\n <WarningMessages mt={2} route={route} allowInteraction />\n <Box\n sx={{\n mt: 2,\n display: 'flex',\n }}\n >\n <StartTransactionButton\n text={getButtonText()}\n onClick={handleStartClick}\n route={route}\n loading={routeRefreshing || isLoadingAddressActivity}\n />\n {status === RouteExecutionStatus.Failed ? (\n <Tooltip\n title={t('button.clearTransaction')}\n placement=\"bottom-end\"\n >\n <Button\n onClick={handleRemoveRoute}\n sx={{\n minWidth: 48,\n marginLeft: 1,\n }}\n >\n <Delete />\n </Button>\n </Tooltip>\n ) : null}\n </Box>\n </>\n ) : null}\n {status ? <StatusBottomSheet status={status} route={route} /> : null}\n {subvariant !== 'custom' ? (\n <TokenValueBottomSheet\n route={route}\n ref={tokenValueBottomSheetRef}\n onContinue={handleExecuteRoute}\n />\n ) : null}\n <ExchangeRateBottomSheet ref={exchangeRateBottomSheetRef} />\n {!hiddenUI?.includes(HiddenUI.LowAddressActivityConfirmation) ? (\n <ConfirmToAddressSheet\n ref={confirmToAddressSheetRef}\n onContinue={handleExecuteRoute}\n toAddress={toAddress!}\n toChainId={route.toChainId!}\n />\n ) : null}\n </PageContainer>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAa,wBAA4C;CACvD,MAAM,EAAE,MAAM,gBAAgB;CAC9B,MAAM,EAAE,kBAAkB,iBAAiB;CAC3C,MAAM,UAAU,iBAAiB;CACjC,MAAM,gBAAgB,gBAAgB,UAAU,MAAM,cAAc;CACpE,MAAM,WAAW,aAAa;CAC9B,MAAM,eAAe,iBAAiB;CACtC,MAAM,EACJ,YACA,mBACA,4BACA,aACE,iBAAiB;CACrB,M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B,IAAI,EAAE,WAAW,GAAG;cACpC;IACiB,CAAA,GAClB;GACJ,oBAAC,oBAAD;IAA2B;IAAO,IAAI,EAAE,WAAW,GAAG;IAAI,CAAA;GACzD,WAAW,qBAAqB,QACjC,WAAW,qBAAqB,SAC9B,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,iBAAD;IAAiB,IAAI;IAAU;IAAO,kBAAA;IAAmB,CAAA,EACzD,qBAAC,KAAD;IACE,IAAI;KACF,IAAI;KACJ,SAAS;KACV;cAJH,CAME,oBAAC,wBAAD;KACE,MAAM,eAAe;KACrB,SAAS;KACF;KACP,SAAS,mBAAmB;KAC5B,CAAA,EACD,WAAW,qBAAqB,SAC/B,oBAAC,SAAD;KACE,OAAO,EAAE,0BAA0B;KACnC,WAAU;eAEV,oBAAC,QAAD;MACE,SAAS;MACT,IAAI;OACF,UAAU;OACV,YAAY;OACb;gBAED,oBAAC,QAAD,EAAU,CAAA;MACH,CAAA;KACD,CAAA,GACR,KACA;MACL,EAAA,CAAA,GACD;GACH,SAAS,oBAAC,mBAAD;IAA2B;IAAe;IAAS,CAAA,GAAG;GAC/D,eAAe,WACd,oBAAC,uBAAD;IACS;IACP,KAAK;IACL,YAAY;IACZ,CAAA,GACA;GACJ,oBAAC,yBAAD,EAAyB,KAAK,4BAA8B,CAAA;GAC3D,CAAC,UAAU,SAAS,SAAS,+BAA+B,GAC3D,oBAAC,uBAAD;IACE,KAAK;IACL,YAAY;IACD;IACX,WAAW,MAAM;IACjB,CAAA,GACA;GACU"}
|
|
1
|
+
{"version":3,"file":"TransactionPage.js","names":[],"sources":["../../../../src/pages/TransactionPage/TransactionPage.tsx"],"sourcesContent":["import type { ExchangeRateUpdateParams } from '@lifi/sdk'\nimport Delete from '@mui/icons-material/Delete'\nimport { Box, Button, Tooltip } from '@mui/material'\nimport { useLocation, useNavigate } from '@tanstack/react-router'\nimport { type JSX, useMemo, useRef, useState } from 'react'\nimport { useTranslation } from 'react-i18next'\nimport type { BottomSheetBase } from '../../components/BottomSheet/types.js'\nimport { ContractComponent } from '../../components/ContractComponent/ContractComponent.js'\nimport { WarningMessages } from '../../components/Messages/WarningMessages.js'\nimport { PageContainer } from '../../components/PageContainer.js'\nimport { getStepList } from '../../components/Step/StepList.js'\nimport { TransactionDetails } from '../../components/TransactionDetails.js'\nimport { useAddressActivity } from '../../hooks/useAddressActivity.js'\nimport { useHeader } from '../../hooks/useHeader.js'\nimport { useNavigateBack } from '../../hooks/useNavigateBack.js'\nimport { useRouteExecution } from '../../hooks/useRouteExecution.js'\nimport { useWidgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { useWidgetConfig } from '../../providers/WidgetProvider/WidgetProvider.js'\nimport { useFieldActions } from '../../stores/form/useFieldActions.js'\nimport { useHeaderStore } from '../../stores/header/useHeaderStore.js'\nimport { RouteExecutionStatus } from '../../stores/routes/types.js'\nimport { WidgetEvent } from '../../types/events.js'\nimport { HiddenUI } from '../../types/widget.js'\nimport { getAccumulatedFeeCostsBreakdown } from '../../utils/fees.js'\nimport { navigationRoutes } from '../../utils/navigationRoutes.js'\nimport { ConfirmToAddressSheet } from './ConfirmToAddressSheet.js'\nimport type { ExchangeRateBottomSheetBase } from './ExchangeRateBottomSheet.js'\nimport { ExchangeRateBottomSheet } from './ExchangeRateBottomSheet.js'\nimport { RouteTracker } from './RouteTracker.js'\nimport { StartTransactionButton } from './StartTransactionButton.js'\nimport { StatusBottomSheet } from './StatusBottomSheet.js'\nimport { TokenValueBottomSheet } from './TokenValueBottomSheet.js'\nimport {\n calculateValueLossPercentage,\n getTokenValueLossThreshold,\n} from './utils.js'\n\nexport const TransactionPage = (): JSX.Element | null => {\n const { t } = useTranslation()\n const { setFieldValue } = useFieldActions()\n const emitter = useWidgetEvents()\n const setBackAction = useHeaderStore((state) => state.setBackAction)\n const navigate = useNavigate()\n const navigateBack = useNavigateBack()\n const {\n subvariant,\n subvariantOptions,\n contractSecondaryComponent,\n hiddenUI,\n } = useWidgetConfig()\n const { search }: any = useLocation()\n const stateRouteId = search?.routeId\n const [routeId, setRouteId] = useState<string>(stateRouteId)\n const [routeRefreshing, setRouteRefreshing] = useState(false)\n\n const tokenValueBottomSheetRef = useRef<BottomSheetBase>(null)\n const exchangeRateBottomSheetRef = useRef<ExchangeRateBottomSheetBase>(null)\n const confirmToAddressSheetRef = useRef<BottomSheetBase>(null)\n\n const onAcceptExchangeRateUpdate = (\n resolver: (value: boolean) => void,\n data: ExchangeRateUpdateParams\n ) => {\n exchangeRateBottomSheetRef.current?.open(resolver, data)\n }\n\n const { route, status, executeRoute, restartRoute, deleteRoute } =\n useRouteExecution({\n routeId: routeId,\n onAcceptExchangeRateUpdate,\n })\n\n const {\n toAddress,\n hasActivity,\n isLoading: isLoadingAddressActivity,\n isFetched: isActivityAddressFetched,\n } = useAddressActivity(route?.toChainId)\n\n const getHeaderTitle = () => {\n if (subvariant === 'custom') {\n return t(`header.${subvariantOptions?.custom ?? 'checkout'}`)\n }\n if (route) {\n const transactionType =\n route.fromChainId === route.toChainId ? 'swap' : 'bridge'\n return status === RouteExecutionStatus.Idle\n ? t(`button.${transactionType}Review`)\n : t(`header.${transactionType}`)\n }\n\n return t('header.exchange')\n }\n\n const headerAction = useMemo(\n () =>\n status === RouteExecutionStatus.Idle ? (\n <RouteTracker\n observableRouteId={stateRouteId}\n onChange={setRouteId}\n onFetching={setRouteRefreshing}\n />\n ) : undefined,\n [stateRouteId, status]\n )\n\n useHeader(getHeaderTitle(), headerAction)\n\n if (!route) {\n return null\n }\n\n const handleExecuteRoute = () => {\n if (tokenValueBottomSheetRef.current?.isOpen()) {\n const { gasCostUSD, feeCostUSD } = getAccumulatedFeeCostsBreakdown(route)\n const fromAmountUSD = Number.parseFloat(route.fromAmountUSD)\n const toAmountUSD = Number.parseFloat(route.toAmountUSD)\n emitter.emit(WidgetEvent.RouteHighValueLoss, {\n fromAmountUSD,\n toAmountUSD,\n gasCostUSD,\n feeCostUSD,\n valueLoss: calculateValueLossPercentage(\n fromAmountUSD,\n toAmountUSD,\n gasCostUSD,\n feeCostUSD\n ),\n })\n }\n tokenValueBottomSheetRef.current?.close()\n executeRoute()\n setFieldValue('fromAmount', '')\n if (subvariant === 'custom') {\n setFieldValue('fromToken', '')\n setFieldValue('toToken', '')\n }\n // Once transaction is started, set the back action to navigate to the home page\n setBackAction(() => {\n navigate({ to: navigationRoutes.home, replace: true })\n })\n }\n\n const handleStartClick = async () => {\n if (status === RouteExecutionStatus.Idle) {\n if (\n toAddress &&\n !hasActivity &&\n !isLoadingAddressActivity &&\n isActivityAddressFetched &&\n !hiddenUI?.includes(HiddenUI.LowAddressActivityConfirmation)\n ) {\n confirmToAddressSheetRef.current?.open()\n return\n }\n\n const { gasCostUSD, feeCostUSD } = getAccumulatedFeeCostsBreakdown(route)\n const fromAmountUSD = Number.parseFloat(route.fromAmountUSD)\n const toAmountUSD = Number.parseFloat(route.toAmountUSD)\n const tokenValueLossThresholdExceeded = getTokenValueLossThreshold(\n fromAmountUSD,\n toAmountUSD,\n gasCostUSD,\n feeCostUSD\n )\n if (tokenValueLossThresholdExceeded && subvariant !== 'custom') {\n tokenValueBottomSheetRef.current?.open()\n } else {\n handleExecuteRoute()\n }\n }\n if (status === RouteExecutionStatus.Failed) {\n restartRoute()\n }\n }\n\n const handleRemoveRoute = () => {\n navigateBack()\n deleteRoute()\n }\n\n const getButtonText = (): string => {\n switch (status) {\n case RouteExecutionStatus.Idle:\n switch (subvariant) {\n case 'custom':\n return subvariantOptions?.custom === 'deposit'\n ? t('button.deposit')\n : t('button.buy')\n case 'refuel':\n return t('button.startBridging')\n default: {\n const transactionType =\n route.fromChainId === route.toChainId ? 'Swapping' : 'Bridging'\n return t(`button.start${transactionType}`)\n }\n }\n case RouteExecutionStatus.Failed:\n return t('button.tryAgain')\n default:\n return ''\n }\n }\n\n return (\n <PageContainer bottomGutters>\n {getStepList(route, subvariant)}\n {subvariant === 'custom' && contractSecondaryComponent ? (\n <ContractComponent sx={{ marginTop: 2 }}>\n {contractSecondaryComponent}\n </ContractComponent>\n ) : null}\n <TransactionDetails route={route} sx={{ marginTop: 2 }} />\n {status === RouteExecutionStatus.Idle ||\n status === RouteExecutionStatus.Failed ? (\n <>\n <WarningMessages sx={{ mt: 2 }} route={route} allowInteraction />\n <Box\n sx={{\n mt: 2,\n display: 'flex',\n }}\n >\n <StartTransactionButton\n text={getButtonText()}\n onClick={handleStartClick}\n route={route}\n loading={routeRefreshing || isLoadingAddressActivity}\n />\n {status === RouteExecutionStatus.Failed ? (\n <Tooltip\n title={t('button.clearTransaction')}\n placement=\"bottom-end\"\n >\n <Button\n onClick={handleRemoveRoute}\n sx={{\n minWidth: 48,\n marginLeft: 1,\n }}\n >\n <Delete />\n </Button>\n </Tooltip>\n ) : null}\n </Box>\n </>\n ) : null}\n {status ? <StatusBottomSheet status={status} route={route} /> : null}\n {subvariant !== 'custom' ? (\n <TokenValueBottomSheet\n route={route}\n ref={tokenValueBottomSheetRef}\n onContinue={handleExecuteRoute}\n />\n ) : null}\n <ExchangeRateBottomSheet ref={exchangeRateBottomSheetRef} />\n {!hiddenUI?.includes(HiddenUI.LowAddressActivityConfirmation) ? (\n <ConfirmToAddressSheet\n ref={confirmToAddressSheetRef}\n onContinue={handleExecuteRoute}\n toAddress={toAddress!}\n toChainId={route.toChainId!}\n />\n ) : null}\n </PageContainer>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAa,wBAA4C;CACvD,MAAM,EAAE,MAAM,gBAAgB;CAC9B,MAAM,EAAE,kBAAkB,iBAAiB;CAC3C,MAAM,UAAU,iBAAiB;CACjC,MAAM,gBAAgB,gBAAgB,UAAU,MAAM,cAAc;CACpE,MAAM,WAAW,aAAa;CAC9B,MAAM,eAAe,iBAAiB;CACtC,MAAM,EACJ,YACA,mBACA,4BACA,aACE,iBAAiB;CACrB,MAAM,EAAE,WAAgB,aAAa;CACrC,MAAM,eAAe,QAAQ;CAC7B,MAAM,CAAC,SAAS,cAAc,SAAiB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A,EACjE,qBAAC,KAAD;IACE,IAAI;KACF,IAAI;KACJ,SAAS;KACV;cAJH,CAME,oBAAC,wBAAD;KACE,MAAM,eAAe;KACrB,SAAS;KACF;KACP,SAAS,mBAAmB;KAC5B,CAAA,EACD,WAAA,IACC,oBAAC,SAAD;KACE,OAAO,EAAE,0BAA0B;KACnC,WAAU;eAEV,oBAAC,QAAD;MACE,SAAS;MACT,IAAI;OACF,UAAU;OACV,YAAY;OACb;gBAED,oBAAC,QAAD,EAAU,CAAA;MACH,CAAA;KACD,CAAA,GACR,KACA;MACL,EAAA,CAAA,GACD;GACH,SAAS,oBAAC,mBAAD;IAA2B;IAAe;IAAS,CAAA,GAAG;GAC/D,eAAe,WACd,oBAAC,uBAAD;IACS;IACP,KAAK;IACL,YAAY;IACZ,CAAA,GACA;GACJ,oBAAC,yBAAD,EAAyB,KAAK,4BAA8B,CAAA;GAC3D,CAAC,UAAU,SAAA,iCAAiD,GAC3D,oBAAC,uBAAD;IACE,KAAK;IACL,YAAY;IACD;IACX,WAAW,MAAM;IACjB,CAAA,GACA;GACU"}
|
|
@@ -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,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;KACn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AEH,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,YAChD,SAAS,SAAS,QAAQ,CAC3B;GACD,MAAM,cAAc,SAAS,QAC1B,YAAY,CAAC,WAAW,SAAS,QAAQ,CAC3C;AACD,OAAI,WAAW,WAAA,KAA+B,CAAC,YAAY,OACzD,QAAO;IACL,iBAAiB;KACf,GAAG,MAAM;MACR,OAAO;KACT;IACD,YAAY;KACV,GAAG,MAAM;MACR,OAAO;KACT;IACF;GAEH,MAAM,oBAAA,IAAuC,WAAW;AACxD,QAAK,IAAI,QAAQ,GAAG,QAAQ,mBAAmB,QAC7C,YAAW,KAAK,YAAY,OAAO;AAErC,UAAO;IACL,iBAAiB;KACf,GAAG,MAAM;MACR,OAAO;KACT;IACD,YAAY;KACV,GAAG,MAAM;MACR,OAAO;KACT;IACF;IACD;AACF,SAAO,KAAK,CAAC,WAAW,MAAM,MAAM,GAAA,EAAoB;;CAE1D,WAAW,SAAS,SAAS;EAC3B,MAAM,QAAQ,KAAK;AACnB,MACE,MAAM,WAAW,MAAM,SAAS,QAAQ,IACxC,CAAC,MAAM,gBAAgB,MAAM,SAAS,QAAQ,CAE9C;AAEF,OAAK,UAA2B;GAC9B,MAAM,aAAa,CAAC,SAAS,GAAG,MAAM,WAAW,MAAM,CAAC,MACtD,GAAA,EAED;AACD,UAAO,EACL,YAAY;IACV,GAAG,MAAM;KACR,OAAO;IACT,EACF;IACD;;CAEJ,mBAAmB,eAAe,aAAa;AAC7C,MAAI,GAAG,GAAG,SAAS,iBAAiB,eAAe,CAAC;;CAEtD,qBAAqB,iBAAiB,aAAa;AACjD,MAAI,GAAG,GAAG,SAAS,mBAAmB,iBAAiB,CAAC;;CAE1D,iBAAiB,YAAY;EAE3B,MAAM,mBADsB,KAAK,CAAC,aACW,SAAS,QAAQ;AAC9D,OAAK,UAA2B;GAC9B,MAAM,eAAe,CAAC,GAAG,MAAM,aAAa;AAC5C,OAAI,iBACF,QAAO,EACL,cAAc,aAAa,QAAQ,OAAO,OAAO,QAAQ,EAC1D;AAEH,gBAAa,KAAK,QAAQ;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 }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BAAiB,eAAe,CAAC;;CAEtD,qBAAqB,iBAAiB,aAAa;AACjD,MAAI,GAAG,GAAG,SAAS,mBAAmB,iBAAiB,CAAC;;CAE1D,iBAAiB,YAAY;EAE3B,MAAM,mBADsB,KAAK,CAAC,aACW,SAAS,QAAQ;AAC9D,OAAK,UAA2B;GAC9B,MAAM,eAAe,CAAC,GAAG,MAAM,aAAa;AAC5C,OAAI,iBACF,QAAO,EACL,cAAc,aAAa,QAAQ,OAAO,OAAO,QAAQ,EAC1D;AAEH,gBAAa,KAAK,QAAQ;AAC1B,UAAO,EACL,cACD;IACD;AACF,eAAa,KAAA,eAA8B;GACzC;GACA,QAAQ,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"}
|