@lifi/widget 4.0.0-beta.17 → 4.0.0-beta.18
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/components/AmountInput/AmountInput.js.map +1 -1
- package/dist/esm/components/AmountInput/AmountInputStartAdornment.js.map +1 -1
- package/dist/esm/components/AmountInput/PriceFormHelperText.js.map +1 -1
- package/dist/esm/components/ChainSelect/ChainSelect.js.map +1 -1
- package/dist/esm/components/ChainSelect/useChainSelect.js.map +1 -1
- package/dist/esm/components/Chains/AllChainsAvatar.js +1 -1
- package/dist/esm/components/Chains/AllChainsAvatar.js.map +1 -1
- package/dist/esm/components/Chains/SelectChainContent.js.map +1 -1
- package/dist/esm/components/Dialog/Dialog.js.map +1 -1
- package/dist/esm/components/Expansion/Expansion.js.map +1 -1
- package/dist/esm/components/IconCircle/IconCircle.js.map +1 -1
- package/dist/esm/components/ReverseTokensButton/ReverseTokensButton.js.map +1 -1
- package/dist/esm/components/RouteCard/RouteCard.js.map +1 -1
- package/dist/esm/components/SendToWallet/SendToWalletButton.js +1 -1
- package/dist/esm/components/SendToWallet/SendToWalletButton.js.map +1 -1
- package/dist/esm/components/Skeleton/WidgetSkeleton.js.map +1 -1
- package/dist/esm/components/Step/Step.js.map +1 -1
- package/dist/esm/components/Step/StepActions.js.map +1 -1
- package/dist/esm/components/Tabs/Tabs.style.js.map +1 -1
- package/dist/esm/components/Timer/StepTimer.js.map +1 -1
- package/dist/esm/components/TokenList/TokenListItem.js.map +1 -1
- package/dist/esm/components/TokenList/VirtualizedTokenList.js.map +1 -1
- package/dist/esm/components/TransactionCard/ActiveTransactionCard.js.map +1 -1
- package/dist/esm/config/version.d.ts +1 -1
- package/dist/esm/config/version.js +1 -1
- package/dist/esm/config/version.js.map +1 -1
- package/dist/esm/hooks/timer/time.js.map +1 -1
- package/dist/esm/hooks/useAccountsBalancesData.js.map +1 -1
- package/dist/esm/hooks/useActionMessage.js +2 -2
- package/dist/esm/hooks/useActionMessage.js.map +1 -1
- package/dist/esm/hooks/useAddressActivity.js.map +1 -1
- package/dist/esm/hooks/useAvailableChains.js.map +1 -1
- package/dist/esm/hooks/useChain.js.map +1 -1
- package/dist/esm/hooks/useChains.js.map +1 -1
- package/dist/esm/hooks/useDebouncedWatch.js.map +1 -1
- package/dist/esm/hooks/useFilteredByTokenBalances.js.map +1 -1
- package/dist/esm/hooks/useFromAmountThreshold.js.map +1 -1
- package/dist/esm/hooks/useFromTokenSufficiency.js.map +1 -1
- package/dist/esm/hooks/useGasRecommendation.js.map +1 -1
- package/dist/esm/hooks/useGasRefuel.js.map +1 -1
- package/dist/esm/hooks/useGasSufficiency.js.map +1 -1
- package/dist/esm/hooks/useIsContractAddress.js.map +1 -1
- package/dist/esm/hooks/useListHeight.js.map +1 -1
- package/dist/esm/hooks/useLongPress.js.map +1 -1
- package/dist/esm/hooks/useNavigateBack.js.map +1 -1
- package/dist/esm/hooks/useRouteExecution.js +0 -2
- package/dist/esm/hooks/useRouteExecution.js.map +1 -1
- package/dist/esm/hooks/useRoutes.js.map +1 -1
- package/dist/esm/hooks/useScrollableContainer.js.map +1 -1
- package/dist/esm/hooks/useSwapOnly.js.map +1 -1
- package/dist/esm/hooks/useToAddressAutoPopulate.js.map +1 -1
- package/dist/esm/hooks/useToAddressReset.js.map +1 -1
- package/dist/esm/hooks/useTokenBalance.js.map +1 -1
- package/dist/esm/hooks/useTokenBalances.js.map +1 -1
- package/dist/esm/hooks/useTokenBalancesQueries.js.map +1 -1
- package/dist/esm/hooks/useTokenSearch.js.map +1 -1
- package/dist/esm/hooks/useTokens.js.map +1 -1
- package/dist/esm/hooks/useTransactionDetails.js.map +1 -1
- package/dist/esm/hooks/useTransactionHistory.js.map +1 -1
- package/dist/esm/hooks/useTransactionList.js.map +1 -1
- package/dist/esm/hooks/useWidgetEvents.js.map +1 -1
- package/dist/esm/i18n/bn.json +3 -0
- package/dist/esm/i18n/de.json +3 -0
- package/dist/esm/i18n/es.json +3 -0
- package/dist/esm/i18n/fr.json +3 -0
- package/dist/esm/i18n/hi.json +3 -0
- package/dist/esm/i18n/id.json +3 -0
- package/dist/esm/i18n/it.json +3 -0
- package/dist/esm/i18n/ja.json +3 -0
- package/dist/esm/i18n/ko.json +3 -0
- package/dist/esm/i18n/pl.json +3 -0
- package/dist/esm/i18n/pt.json +3 -0
- package/dist/esm/i18n/th.json +3 -0
- package/dist/esm/i18n/tr.json +3 -0
- package/dist/esm/i18n/uk.json +3 -0
- package/dist/esm/i18n/vi.json +3 -0
- package/dist/esm/i18n/zh.json +3 -0
- package/dist/esm/pages/SelectChainPage/SelectChainPage.js.map +1 -1
- package/dist/esm/pages/SelectEnabledToolsPage.js.map +1 -1
- package/dist/esm/pages/SettingsPage/SmallBalanceFilterSettings.js.map +1 -1
- package/dist/esm/pages/TransactionDetailsPage/ContactSupportButton.js.map +1 -1
- package/dist/esm/pages/TransactionDetailsPage/StepActionRow.js +2 -2
- package/dist/esm/pages/TransactionDetailsPage/StepActionRow.js.map +1 -1
- package/dist/esm/pages/TransactionDetailsPage/StepActionsList.js +11 -5
- package/dist/esm/pages/TransactionDetailsPage/StepActionsList.js.map +1 -1
- package/dist/esm/pages/TransactionDetailsPage/TransactionDetailsPage.js.map +1 -1
- package/dist/esm/pages/TransactionPage/StartTransactionButton.js.map +1 -1
- package/dist/esm/pages/TransactionPage/TransactionPage.js.map +1 -1
- package/dist/esm/providers/I18nProvider/I18nProvider.js.map +1 -1
- package/dist/esm/providers/I18nProvider/i18n.js.map +1 -1
- package/dist/esm/providers/QueryClientProvider.js.map +1 -1
- package/dist/esm/providers/ThemeProvider/ThemeProvider.js.map +1 -1
- package/dist/esm/providers/WalletProvider/WalletProvider.js.map +1 -1
- package/dist/esm/providers/WalletProvider/useExternalWalletProvider.js.map +1 -1
- package/dist/esm/providers/WidgetProvider/WidgetProvider.js.map +1 -1
- package/dist/esm/stores/bookmarks/useBookmarkActions.js.map +1 -1
- package/dist/esm/stores/chains/ChainOrderStore.js.map +1 -1
- package/dist/esm/stores/chains/useChainOrder.js.map +1 -1
- package/dist/esm/stores/form/URLSearchParamsBuilder.js.map +1 -1
- package/dist/esm/stores/form/createFormStore.js.map +1 -1
- package/dist/esm/stores/form/useFieldActions.js.map +1 -1
- package/dist/esm/stores/form/useFieldValues.js.map +1 -1
- package/dist/esm/stores/form/useTouchedFields.js.map +1 -1
- package/dist/esm/stores/header/useHeaderStore.js.map +1 -1
- package/dist/esm/stores/routes/RouteExecutionStore.js.map +1 -1
- package/dist/esm/stores/routes/createRouteExecutionStore.js.map +1 -1
- package/dist/esm/stores/routes/useRouteExecutionIndicator.js.map +1 -1
- package/dist/esm/stores/routes/utils.js.map +1 -1
- package/dist/esm/stores/settings/SettingsStore.js.map +1 -1
- package/dist/esm/stores/settings/useSettingsActions.js.map +1 -1
- package/dist/esm/stores/settings/useSplitSubvariantStore.js.map +1 -1
- package/dist/esm/utils/converters.js.map +1 -1
- package/dist/esm/utils/format.js.map +1 -1
- package/dist/esm/utils/timer.js.map +1 -1
- package/dist/esm/utils/token.js.map +1 -1
- package/package.json +8 -8
- package/src/components/Chains/AllChainsAvatar.tsx +1 -1
- package/src/components/SendToWallet/SendToWalletButton.tsx +1 -1
- package/src/config/version.ts +1 -1
- package/src/hooks/useActionMessage.ts +4 -3
- package/src/hooks/useRouteExecution.ts +0 -2
- package/src/pages/TransactionDetailsPage/StepActionRow.tsx +3 -2
- package/src/pages/TransactionDetailsPage/StepActionsList.tsx +19 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"URLSearchParamsBuilder.js","names":[],"sources":["../../../../src/stores/form/URLSearchParamsBuilder.tsx"],"sourcesContent":["import { useLocation } from '@tanstack/react-router'\nimport { useEffect } from 'react'\nimport { useAddressValidation } from '../../hooks/useAddressValidation.js'\nimport { useWidgetConfig } from '../../providers/WidgetProvider/WidgetProvider.js'\nimport { useBookmarkActions } from '../bookmarks/useBookmarkActions.js'\nimport type { FormFieldNames } from '../form/types.js'\nimport { useFieldActions } from '../form/useFieldActions.js'\nimport { useFieldValues } from '../form/useFieldValues.js'\nimport { useTouchedFields } from '../form/useTouchedFields.js'\nimport { getDefaultValuesFromQueryString } from './getDefaultValuesFromQueryString.js'\n\nconst formValueKeys: FormFieldNames[] = [\n 'fromAmount',\n 'fromChain',\n 'fromToken',\n 'toAddress',\n 'toChain',\n 'toToken',\n]\n\nexport const URLSearchParamsBuilder = () => {\n const { pathname } = useLocation()\n const touchedFields = useTouchedFields()\n const values = useFieldValues(...formValueKeys)\n const { setSelectedBookmark, addRecentWallet } = useBookmarkActions()\n const { validateAddress } = useAddressValidation()\n const { buildUrl } = useWidgetConfig()\n // Using these methods as trying to use the touchedFields and values above\n // often has a lag that can effect the widgets initialisation sequence\n // and accidentally cause values to be wiped from the query string\n const { getFieldValues, isTouched, setUserAndDefaultValues } =\n useFieldActions()\n\n useEffect(() => {\n // get the initial values from the querystring\n const formValues = getDefaultValuesFromQueryString({ buildUrl })\n const { toAddress, ...initialFormValues } = formValues\n\n /**\n * When URL builder is enabled and user opens a page with toAddress parameter,\n * validate the address and set it up as a bookmark. This allows direct linking\n * to the widget with a pre-filled destination address that will be treated the\n * same way as a manually entered and validated address.\n */\n const initializeFromAddress = async () => {\n if (toAddress) {\n try {\n const validationResult = await validateAddress({\n value: toAddress,\n })\n if (validationResult.isValid && toAddress) {\n const bookmark = {\n address: validationResult.address,\n chainType: validationResult.chainType,\n }\n setUserAndDefaultValues({ toAddress })\n setSelectedBookmark(bookmark)\n addRecentWallet(bookmark)\n }\n } catch (_) {\n // Address validation failed\n }\n }\n }\n\n setUserAndDefaultValues(initialFormValues)\n initializeFromAddress()\n }, [\n setUserAndDefaultValues,\n validateAddress,\n setSelectedBookmark,\n addRecentWallet,\n buildUrl,\n ])\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: run only when pathname changes\n useEffect(() => {\n // set the values on the querysting\n const url = new URL(window.location as any)\n formValueKeys.forEach((key, _index) => {\n const value = getFieldValues(key)[0]\n if (isTouched(key) && value) {\n url.searchParams.set(key, value.toString())\n } else if (url.searchParams.has(key) && !value) {\n url.searchParams.delete(key)\n }\n })\n url.searchParams.sort()\n window.history.replaceState(window.history.state, '', url)\n }, [pathname, touchedFields, values, isTouched, getFieldValues])\n\n return null\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAM,gBAAkC;CACtC;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,+BAA+B;CAC1C,MAAM,EAAE,aAAa,aAAa;CAClC,MAAM,gBAAgB,kBAAkB;CACxC,MAAM,SAAS,eAAe,GAAG,cAAc;CAC/C,MAAM,EAAE,qBAAqB,oBAAoB,oBAAoB;CACrE,MAAM,EAAE,oBAAoB,sBAAsB;CAClD,MAAM,EAAE,aAAa,iBAAiB;CAItC,MAAM,EAAE,gBAAgB,WAAW,4BACjC,iBAAiB;AAEnB,iBAAgB;EAGd,MAAM,EAAE,WAAW,GAAG,sBADH,gCAAgC,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"URLSearchParamsBuilder.js","names":[],"sources":["../../../../src/stores/form/URLSearchParamsBuilder.tsx"],"sourcesContent":["import { useLocation } from '@tanstack/react-router'\nimport { useEffect } from 'react'\nimport { useAddressValidation } from '../../hooks/useAddressValidation.js'\nimport { useWidgetConfig } from '../../providers/WidgetProvider/WidgetProvider.js'\nimport { useBookmarkActions } from '../bookmarks/useBookmarkActions.js'\nimport type { FormFieldNames } from '../form/types.js'\nimport { useFieldActions } from '../form/useFieldActions.js'\nimport { useFieldValues } from '../form/useFieldValues.js'\nimport { useTouchedFields } from '../form/useTouchedFields.js'\nimport { getDefaultValuesFromQueryString } from './getDefaultValuesFromQueryString.js'\n\nconst formValueKeys: FormFieldNames[] = [\n 'fromAmount',\n 'fromChain',\n 'fromToken',\n 'toAddress',\n 'toChain',\n 'toToken',\n]\n\nexport const URLSearchParamsBuilder = () => {\n const { pathname } = useLocation()\n const touchedFields = useTouchedFields()\n const values = useFieldValues(...formValueKeys)\n const { setSelectedBookmark, addRecentWallet } = useBookmarkActions()\n const { validateAddress } = useAddressValidation()\n const { buildUrl } = useWidgetConfig()\n // Using these methods as trying to use the touchedFields and values above\n // often has a lag that can effect the widgets initialisation sequence\n // and accidentally cause values to be wiped from the query string\n const { getFieldValues, isTouched, setUserAndDefaultValues } =\n useFieldActions()\n\n useEffect(() => {\n // get the initial values from the querystring\n const formValues = getDefaultValuesFromQueryString({ buildUrl })\n const { toAddress, ...initialFormValues } = formValues\n\n /**\n * When URL builder is enabled and user opens a page with toAddress parameter,\n * validate the address and set it up as a bookmark. This allows direct linking\n * to the widget with a pre-filled destination address that will be treated the\n * same way as a manually entered and validated address.\n */\n const initializeFromAddress = async () => {\n if (toAddress) {\n try {\n const validationResult = await validateAddress({\n value: toAddress,\n })\n if (validationResult.isValid && toAddress) {\n const bookmark = {\n address: validationResult.address,\n chainType: validationResult.chainType,\n }\n setUserAndDefaultValues({ toAddress })\n setSelectedBookmark(bookmark)\n addRecentWallet(bookmark)\n }\n } catch (_) {\n // Address validation failed\n }\n }\n }\n\n setUserAndDefaultValues(initialFormValues)\n initializeFromAddress()\n }, [\n setUserAndDefaultValues,\n validateAddress,\n setSelectedBookmark,\n addRecentWallet,\n buildUrl,\n ])\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: run only when pathname changes\n useEffect(() => {\n // set the values on the querysting\n const url = new URL(window.location as any)\n formValueKeys.forEach((key, _index) => {\n const value = getFieldValues(key)[0]\n if (isTouched(key) && value) {\n url.searchParams.set(key, value.toString())\n } else if (url.searchParams.has(key) && !value) {\n url.searchParams.delete(key)\n }\n })\n url.searchParams.sort()\n window.history.replaceState(window.history.state, '', url)\n }, [pathname, touchedFields, values, isTouched, getFieldValues])\n\n return null\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAM,gBAAkC;CACtC;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,+BAA+B;CAC1C,MAAM,EAAE,aAAa,aAAa;CAClC,MAAM,gBAAgB,kBAAkB;CACxC,MAAM,SAAS,eAAe,GAAG,cAAc;CAC/C,MAAM,EAAE,qBAAqB,oBAAoB,oBAAoB;CACrE,MAAM,EAAE,oBAAoB,sBAAsB;CAClD,MAAM,EAAE,aAAa,iBAAiB;CAItC,MAAM,EAAE,gBAAgB,WAAW,4BACjC,iBAAiB;AAEnB,iBAAgB;EAGd,MAAM,EAAE,WAAW,GAAG,sBADH,gCAAgC,EAAE,UAAU,CACT;;;;;;;EAQtD,MAAM,wBAAwB,YAAY;AACxC,OAAI,UACF,KAAI;IACF,MAAM,mBAAmB,MAAM,gBAAgB,EAC7C,OAAO,WACR,CAAC;AACF,QAAI,iBAAiB,WAAW,WAAW;KACzC,MAAM,WAAW;MACf,SAAS,iBAAiB;MAC1B,WAAW,iBAAiB;MAC7B;AACD,6BAAwB,EAAE,WAAW,CAAC;AACtC,yBAAoB,SAAS;AAC7B,qBAAgB,SAAS;;YAEpB,GAAG;;AAMhB,0BAAwB,kBAAkB;AAC1C,yBAAuB;IACtB;EACD;EACA;EACA;EACA;EACA;EACD,CAAC;AAGF,iBAAgB;EAEd,MAAM,MAAM,IAAI,IAAI,OAAO,SAAgB;AAC3C,gBAAc,SAAS,KAAK,WAAW;GACrC,MAAM,QAAQ,eAAe,IAAI,CAAC;AAClC,OAAI,UAAU,IAAI,IAAI,MACpB,KAAI,aAAa,IAAI,KAAK,MAAM,UAAU,CAAC;YAClC,IAAI,aAAa,IAAI,IAAI,IAAI,CAAC,MACvC,KAAI,aAAa,OAAO,IAAI;IAE9B;AACF,MAAI,aAAa,MAAM;AACvB,SAAO,QAAQ,aAAa,OAAO,QAAQ,OAAO,IAAI,IAAI;IACzD;EAAC;EAAU;EAAe;EAAQ;EAAW;EAAe,CAAC;AAEhE,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormStore.js","names":[],"sources":["../../../../src/stores/form/createFormStore.ts"],"sourcesContent":["import type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\n\nimport type {\n DefaultValues,\n FormFieldArray,\n FormFieldNames,\n FormValueControl,\n FormValues,\n FormValuesState,\n} from './types.js'\n\nexport const formDefaultValues: DefaultValues = {\n fromAmount: '',\n toAmount: '',\n tokenSearchFilter: '',\n}\n\nconst defaultValueToFormValue = <T>(value: T): FormValueControl<T> => ({\n isTouched: false,\n isDirty: false,\n value,\n})\n\nconst valuesToFormValues = (defaultValues: DefaultValues): FormValues => {\n return (Object.keys(defaultValues) as FormFieldNames[]).reduce(\n (accum, key) => {\n accum[key] = defaultValueToFormValue(defaultValues[key]) as never\n return accum\n },\n {} as FormValues\n )\n}\n\nconst isString = (str: any) => typeof str === 'string' || str instanceof String\n\nconst getUpdatedTouchedFields = (userValues: FormValues) => {\n return (Object.keys(userValues) as FormFieldNames[]).reduce(\n (accum, key) => {\n if (userValues[key]?.isTouched) {\n accum[key] = true\n }\n return accum\n },\n {} as Record<FormFieldNames, boolean>\n )\n}\n\nconst mergeDefaultFormValues = (\n userValues: FormValues,\n defaultValues: FormValues\n) =>\n (Object.keys(defaultValues) as FormFieldNames[]).reduce<FormValues>(\n (accum, key) => {\n const formValue = {\n isTouched: !!(\n userValues[key]?.isTouched || defaultValues[key]?.isTouched\n ),\n isDirty: !!(userValues[key]?.isDirty || defaultValues[key]?.isTouched),\n value:\n userValues[key]?.value || Number.isFinite(userValues[key]?.value)\n ? userValues[key]?.value\n : defaultValues[key]?.value,\n }\n accum[key] = formValue as never\n return accum\n },\n { ...valuesToFormValues(formDefaultValues) }\n )\n\nexport const createFormStore = (\n defaultValues?: DefaultValues\n): UseBoundStore<StoreApi<FormValuesState>> =>\n create<FormValuesState>((set, get) => {\n const _defaultValues = valuesToFormValues({\n ...formDefaultValues,\n ...defaultValues,\n })\n return {\n defaultValues: _defaultValues,\n userValues: _defaultValues,\n touchedFields: {},\n isValid: true,\n isValidating: false,\n errors: {},\n validation: {},\n setDefaultValues: (defaultValue) => {\n const defaultFormValues = valuesToFormValues(defaultValue)\n set((state) => ({\n defaultValues: defaultFormValues,\n userValues: mergeDefaultFormValues(\n state.userValues,\n defaultFormValues\n ),\n }))\n },\n setUserAndDefaultValues: (formValues) => {\n const currentUserValues = get().userValues\n ;(Object.keys(formValues) as FormFieldNames[]).forEach((key) => {\n if (formValues[key] !== currentUserValues[key]?.value) {\n get().resetField(key, { defaultValue: formValues[key] })\n get().setFieldValue(key, formValues[key], { isTouched: true })\n }\n })\n },\n isTouched: (fieldName: FormFieldNames) =>\n !!get().userValues[fieldName]?.isTouched,\n isDirty: (fieldName: FormFieldNames) =>\n !!get().userValues[fieldName]?.isDirty,\n setAsTouched: (fieldName: FormFieldNames) => {\n const userValues = {\n ...get().userValues,\n [fieldName]: {\n ...get().userValues[fieldName],\n isTouched: true,\n },\n }\n\n const touchedFields = getUpdatedTouchedFields(userValues)\n\n set(() => ({\n userValues,\n touchedFields,\n }))\n },\n resetField: (fieldName, { defaultValue } = {}) => {\n if (defaultValue) {\n const fieldValues = {\n ...get().defaultValues[fieldName],\n value: defaultValue,\n }\n const defaultValues = {\n ...get().defaultValues,\n [fieldName]: { ...fieldValues },\n }\n const userValues = {\n ...get().userValues,\n [fieldName]: { ...fieldValues },\n }\n const touchedFields = getUpdatedTouchedFields(userValues)\n\n set(() => {\n return {\n defaultValues,\n userValues,\n touchedFields,\n }\n })\n } else {\n const userValues = {\n ...get().userValues,\n [fieldName]: { ...get().defaultValues[fieldName] },\n }\n const touchedFields = getUpdatedTouchedFields(userValues)\n\n set(() => ({\n userValues,\n touchedFields,\n }))\n }\n },\n setFieldValue: (fieldName, value, { isDirty, isTouched } = {}) => {\n const userValues = {\n ...get().userValues,\n [fieldName]: {\n value,\n isDirty:\n isDirty === undefined\n ? get().userValues[fieldName]?.isDirty\n : isDirty,\n isTouched:\n isTouched === undefined\n ? get().userValues[fieldName]?.isTouched\n : isTouched,\n },\n }\n\n const touchedFields = getUpdatedTouchedFields(userValues)\n\n set(() => ({\n userValues,\n touchedFields,\n }))\n },\n getFieldValues: <T extends FormFieldNames[]>(...names: T) =>\n names.map((name) => get().userValues[name]?.value) as FormFieldArray<T>,\n addFieldValidation: (name, validationFn) => {\n set((state) => ({\n validation: {\n ...state.validation,\n [name]: validationFn,\n },\n }))\n },\n triggerFieldValidation: async (name) => {\n try {\n let valid = true\n set(() => ({ isValid: false, isValidating: true }))\n\n const validationFn = get().validation[name]\n\n if (validationFn) {\n const result = await validationFn(get().userValues?.[name]?.value)\n if (isString(result)) {\n valid = false\n set((state) => ({\n errors: {\n ...state.errors,\n [name]: result,\n },\n }))\n } else {\n valid = result as boolean\n if (valid) {\n get().clearErrors(name)\n }\n }\n }\n\n set(() => ({ isValid: valid, isValidating: false }))\n return valid\n } catch (err) {\n set(() => ({ isValidating: false }))\n throw err\n }\n },\n clearErrors: (name) => {\n const newErrors = { ...get().errors }\n\n delete newErrors[name]\n\n set(() => ({\n errors: newErrors,\n }))\n },\n }\n })\n"],"mappings":";;AAYA,MAAa,oBAAmC;CAC9C,YAAY;CACZ,UAAU;CACV,mBAAmB;CACpB;AAED,MAAM,2BAA8B,WAAmC;CACrE,WAAW;CACX,SAAS;CACT;CACD;AAED,MAAM,sBAAsB,kBAA6C;AACvE,QAAQ,OAAO,KAAK,cAAc,CAAsB,QACrD,OAAO,QAAQ;AACd,QAAM,OAAO,wBAAwB,cAAc,KAAK;AACxD,SAAO;IAET,EAAE,CACH;;AAGH,MAAM,YAAY,QAAa,OAAO,QAAQ,YAAY,eAAe;AAEzE,MAAM,2BAA2B,eAA2B;AAC1D,QAAQ,OAAO,KAAK,WAAW,CAAsB,QAClD,OAAO,QAAQ;AACd,MAAI,WAAW,MAAM,UACnB,OAAM,OAAO;AAEf,SAAO;IAET,EAAE,CACH;;AAGH,MAAM,0BACJ,YACA,kBAEC,OAAO,KAAK,cAAc,CAAsB,QAC9C,OAAO,QAAQ;AAWd,OAAM,OAVY;EAChB,WAAW,CAAC,EACV,WAAW,MAAM,aAAa,cAAc,MAAM;EAEpD,SAAS,CAAC,EAAE,WA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T,EACF,EAAE;YACE;AACL,cAAQ;AACR,UAAI,MACF,MAAK,CAAC,YAAY,KAAK;;;AAK7B,eAAW;KAAE,SAAS;KAAO,cAAc;KAAO,EAAE;AACpD,WAAO;YACA,KAAK;AACZ,eAAW,EAAE,cAAc,OAAO,EAAE;AACpC,UAAM;;;EAGV,cAAc,SAAS;GACrB,MAAM,YAAY,EAAE,GAAG,KAAK,CAAC,QAAQ;AAErC,UAAO,UAAU;AAEjB,cAAW,EACT,QAAQ,WACT,EAAE;;EAEN;EACD"}
|
|
1
|
+
{"version":3,"file":"createFormStore.js","names":[],"sources":["../../../../src/stores/form/createFormStore.ts"],"sourcesContent":["import type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\n\nimport type {\n DefaultValues,\n FormFieldArray,\n FormFieldNames,\n FormValueControl,\n FormValues,\n FormValuesState,\n} from './types.js'\n\nexport const formDefaultValues: DefaultValues = {\n fromAmount: '',\n toAmount: '',\n tokenSearchFilter: '',\n}\n\nconst defaultValueToFormValue = <T>(value: T): FormValueControl<T> => ({\n isTouched: false,\n isDirty: false,\n value,\n})\n\nconst valuesToFormValues = (defaultValues: DefaultValues): FormValues => {\n return (Object.keys(defaultValues) as FormFieldNames[]).reduce(\n (accum, key) => {\n accum[key] = defaultValueToFormValue(defaultValues[key]) as never\n return accum\n },\n {} as FormValues\n )\n}\n\nconst isString = (str: any) => typeof str === 'string' || str instanceof String\n\nconst getUpdatedTouchedFields = (userValues: FormValues) => {\n return (Object.keys(userValues) as FormFieldNames[]).reduce(\n (accum, key) => {\n if (userValues[key]?.isTouched) {\n accum[key] = true\n }\n return accum\n },\n {} as Record<FormFieldNames, boolean>\n )\n}\n\nconst mergeDefaultFormValues = (\n userValues: FormValues,\n defaultValues: FormValues\n) =>\n (Object.keys(defaultValues) as FormFieldNames[]).reduce<FormValues>(\n (accum, key) => {\n const formValue = {\n isTouched: !!(\n userValues[key]?.isTouched || defaultValues[key]?.isTouched\n ),\n isDirty: !!(userValues[key]?.isDirty || defaultValues[key]?.isTouched),\n value:\n userValues[key]?.value || Number.isFinite(userValues[key]?.value)\n ? userValues[key]?.value\n : defaultValues[key]?.value,\n }\n accum[key] = formValue as never\n return accum\n },\n { ...valuesToFormValues(formDefaultValues) }\n )\n\nexport const createFormStore = (\n defaultValues?: DefaultValues\n): UseBoundStore<StoreApi<FormValuesState>> =>\n create<FormValuesState>((set, get) => {\n const _defaultValues = valuesToFormValues({\n ...formDefaultValues,\n ...defaultValues,\n })\n return {\n defaultValues: _defaultValues,\n userValues: _defaultValues,\n touchedFields: {},\n isValid: true,\n isValidating: false,\n errors: {},\n validation: {},\n setDefaultValues: (defaultValue) => {\n const defaultFormValues = valuesToFormValues(defaultValue)\n set((state) => ({\n defaultValues: defaultFormValues,\n userValues: mergeDefaultFormValues(\n state.userValues,\n defaultFormValues\n ),\n }))\n },\n setUserAndDefaultValues: (formValues) => {\n const currentUserValues = get().userValues\n ;(Object.keys(formValues) as FormFieldNames[]).forEach((key) => {\n if (formValues[key] !== currentUserValues[key]?.value) {\n get().resetField(key, { defaultValue: formValues[key] })\n get().setFieldValue(key, formValues[key], { isTouched: true })\n }\n })\n },\n isTouched: (fieldName: FormFieldNames) =>\n !!get().userValues[fieldName]?.isTouched,\n isDirty: (fieldName: FormFieldNames) =>\n !!get().userValues[fieldName]?.isDirty,\n setAsTouched: (fieldName: FormFieldNames) => {\n const userValues = {\n ...get().userValues,\n [fieldName]: {\n ...get().userValues[fieldName],\n isTouched: true,\n },\n }\n\n const touchedFields = getUpdatedTouchedFields(userValues)\n\n set(() => ({\n userValues,\n touchedFields,\n }))\n },\n resetField: (fieldName, { defaultValue } = {}) => {\n if (defaultValue) {\n const fieldValues = {\n ...get().defaultValues[fieldName],\n value: defaultValue,\n }\n const defaultValues = {\n ...get().defaultValues,\n [fieldName]: { ...fieldValues },\n }\n const userValues = {\n ...get().userValues,\n [fieldName]: { ...fieldValues },\n }\n const touchedFields = getUpdatedTouchedFields(userValues)\n\n set(() => {\n return {\n defaultValues,\n userValues,\n touchedFields,\n }\n })\n } else {\n const userValues = {\n ...get().userValues,\n [fieldName]: { ...get().defaultValues[fieldName] },\n }\n const touchedFields = getUpdatedTouchedFields(userValues)\n\n set(() => ({\n userValues,\n touchedFields,\n }))\n }\n },\n setFieldValue: (fieldName, value, { isDirty, isTouched } = {}) => {\n const userValues = {\n ...get().userValues,\n [fieldName]: {\n value,\n isDirty:\n isDirty === undefined\n ? get().userValues[fieldName]?.isDirty\n : isDirty,\n isTouched:\n isTouched === undefined\n ? get().userValues[fieldName]?.isTouched\n : isTouched,\n },\n }\n\n const touchedFields = getUpdatedTouchedFields(userValues)\n\n set(() => ({\n userValues,\n touchedFields,\n }))\n },\n getFieldValues: <T extends FormFieldNames[]>(...names: T) =>\n names.map((name) => get().userValues[name]?.value) as FormFieldArray<T>,\n addFieldValidation: (name, validationFn) => {\n set((state) => ({\n validation: {\n ...state.validation,\n [name]: validationFn,\n },\n }))\n },\n triggerFieldValidation: async (name) => {\n try {\n let valid = true\n set(() => ({ isValid: false, isValidating: true }))\n\n const validationFn = get().validation[name]\n\n if (validationFn) {\n const result = await validationFn(get().userValues?.[name]?.value)\n if (isString(result)) {\n valid = false\n set((state) => ({\n errors: {\n ...state.errors,\n [name]: result,\n },\n }))\n } else {\n valid = result as boolean\n if (valid) {\n get().clearErrors(name)\n }\n }\n }\n\n set(() => ({ isValid: valid, isValidating: false }))\n return valid\n } catch (err) {\n set(() => ({ isValidating: false }))\n throw err\n }\n },\n clearErrors: (name) => {\n const newErrors = { ...get().errors }\n\n delete newErrors[name]\n\n set(() => ({\n errors: newErrors,\n }))\n },\n }\n })\n"],"mappings":";;AAYA,MAAa,oBAAmC;CAC9C,YAAY;CACZ,UAAU;CACV,mBAAmB;CACpB;AAED,MAAM,2BAA8B,WAAmC;CACrE,WAAW;CACX,SAAS;CACT;CACD;AAED,MAAM,sBAAsB,kBAA6C;AACvE,QAAQ,OAAO,KAAK,cAAc,CAAsB,QACrD,OAAO,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AK,CAAC,WAAW,OAAO,MAAM;EACpD,qBAAqB,MAAM,iBAAiB;AAC1C,QAAK,WAAW,EACd,YAAY;IACV,GAAG,MAAM;KACR,OAAO;IACT,EACF,EAAE;;EAEL,wBAAwB,OAAO,SAAS;AACtC,OAAI;IACF,IAAI,QAAQ;AACZ,eAAW;KAAE,SAAS;KAAO,cAAc;KAAM,EAAE;IAEnD,MAAM,eAAe,KAAK,CAAC,WAAW;AAEtC,QAAI,cAAc;KAChB,MAAM,SAAS,MAAM,aAAa,KAAK,CAAC,aAAa,OAAO,MAAM;AAClE,SAAI,SAAS,OAAO,EAAE;AACpB,cAAQ;AACR,WAAK,WAAW,EACd,QAAQ;OACN,GAAG,MAAM;QACR,OAAO;OACT,EACF,EAAE;YACE;AACL,cAAQ;AACR,UAAI,MACF,MAAK,CAAC,YAAY,KAAK;;;AAK7B,eAAW;KAAE,SAAS;KAAO,cAAc;KAAO,EAAE;AACpD,WAAO;YACA,KAAK;AACZ,eAAW,EAAE,cAAc,OAAO,EAAE;AACpC,UAAM;;;EAGV,cAAc,SAAS;GACrB,MAAM,YAAY,EAAE,GAAG,KAAK,CAAC,QAAQ;AAErC,UAAO,UAAU;AAEjB,cAAW,EACT,QAAQ,WACT,EAAE;;EAEN;EACD"}
|
|
@@ -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,KAAA,oBAAmC;GACzC;GACA;GACA;GACD,CAAqB;IAG1B,CAAC,SAAS,QAAQ,CACnB;CAED,MAAM,2CAA2C,aAC9C,eAAuC;EAGtC,MAAM,gBAFiB,OAAO,KAAK,
|
|
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,WAEC,CAAC,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFieldValues.js","names":[],"sources":["../../../../src/stores/form/useFieldValues.ts"],"sourcesContent":["import type { FormFieldArray, FormFieldNames } from './types.js'\nimport { useFormStore } from './useFormStore.js'\n\n// We should return a strongly-typed array based on the specific field names we pass to the function.\nexport const useFieldValues = <T extends FormFieldNames[]>(\n ...names: T\n): FormFieldArray<T> => {\n const values = useFormStore(\n (store) =>\n names.map((name) => store.userValues[name]?.value) as FormFieldArray<T>\n )\n\n return values\n}\n"],"mappings":";;AAIA,MAAa,kBACX,GAAG,UACmB;AAMtB,QALe,cACZ,UACC,MAAM,KAAK,SAAS,MAAM,WAAW,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"useFieldValues.js","names":[],"sources":["../../../../src/stores/form/useFieldValues.ts"],"sourcesContent":["import type { FormFieldArray, FormFieldNames } from './types.js'\nimport { useFormStore } from './useFormStore.js'\n\n// We should return a strongly-typed array based on the specific field names we pass to the function.\nexport const useFieldValues = <T extends FormFieldNames[]>(\n ...names: T\n): FormFieldArray<T> => {\n const values = useFormStore(\n (store) =>\n names.map((name) => store.userValues[name]?.value) as FormFieldArray<T>\n )\n\n return values\n}\n"],"mappings":";;AAIA,MAAa,kBACX,GAAG,UACmB;AAMtB,QALe,cACZ,UACC,MAAM,KAAK,SAAS,MAAM,WAAW,OAAO,MAAM,CAGzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTouchedFields.js","names":[],"sources":["../../../../src/stores/form/useTouchedFields.ts"],"sourcesContent":["import type { TouchedFields } from './types.js'\nimport { useFormStore } from './useFormStore.js'\n\nexport const useTouchedFields = (): TouchedFields => {\n const touchedFields = useFormStore((store) => store.touchedFields)\n\n return touchedFields\n}\n"],"mappings":";;AAGA,MAAa,yBAAwC;AAGnD,QAFsB,cAAc,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"useTouchedFields.js","names":[],"sources":["../../../../src/stores/form/useTouchedFields.ts"],"sourcesContent":["import type { TouchedFields } from './types.js'\nimport { useFormStore } from './useFormStore.js'\n\nexport const useTouchedFields = (): TouchedFields => {\n const touchedFields = useFormStore((store) => store.touchedFields)\n\n return touchedFields\n}\n"],"mappings":";;AAGA,MAAa,yBAAwC;AAGnD,QAFsB,cAAc,UAAU,MAAM,cAEhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHeaderStore.js","names":[],"sources":["../../../../src/stores/header/useHeaderStore.tsx"],"sourcesContent":["import { createContext, useContext, useRef } from 'react'\nimport { create } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport type { PersistStoreProviderProps } from '../types.js'\nimport type { HeaderState, HeaderStore } from './types.js'\n\nconst HeaderStoreContext = createContext<HeaderStore | null>(null)\n\nexport function HeaderStoreProvider({\n children,\n}: PersistStoreProviderProps): any {\n const storeRef = useRef<HeaderStore>(null)\n if (!storeRef.current) {\n storeRef.current = createHeaderStore()\n }\n return (\n <HeaderStoreContext.Provider value={storeRef.current}>\n {children}\n </HeaderStoreContext.Provider>\n )\n}\n\nfunction useHeaderStoreContext() {\n const useStore = useContext(HeaderStoreContext)\n if (!useStore) {\n throw new Error(\n `You forgot to wrap your component in <${HeaderStoreProvider.name}>.`\n )\n }\n return useStore\n}\n\nexport function useHeaderStore<T>(selector: (state: HeaderState) => T): T {\n const useStore = useHeaderStoreContext()\n return useStore(useShallow(selector))\n}\n\n// We use fixed position on the header when Widget is in Full Height layout.\n// We do this to get it to work like the sticky header does in the other layout modes.\n// As the header is position fixed its not in the document flow anymore.\n// To prevent the remaining page content from appearing behind the header we need to\n// pass the headers height so that the position of the page content can be adjusted\nexport function useHeaderHeight(): any {\n const headerHeight = useHeaderStore((state) => state.headerHeight)\n\n return {\n headerHeight,\n }\n}\n\nexport function useSetHeaderHeight(): any {\n const setHeaderHeight = useHeaderStore((state) => state.setHeaderHeight)\n\n return {\n setHeaderHeight,\n }\n}\n\nconst createHeaderStore = () =>\n create<HeaderState>((set, get) => ({\n headerHeight: 108, // a basic default height\n setAction: (element) => {\n set(() => ({\n element,\n }))\n return get().removeAction\n },\n setTitle: (title) => {\n set(() => ({\n title,\n }))\n return get().removeTitle\n },\n removeAction: () => {\n set(() => ({\n element: null,\n }))\n },\n removeTitle: () => {\n set(() => ({\n title: undefined,\n }))\n },\n setHeaderHeight: (headerHeight) => {\n set(() => ({\n headerHeight,\n }))\n },\n setBackAction: (action) => {\n set(() => ({\n backAction: action,\n }))\n },\n executeBackAction: () => {\n const { backAction } = get()\n if (backAction) {\n backAction()\n set(() => ({\n backAction: undefined,\n }))\n }\n },\n }))\n"],"mappings":";;;;;AAMA,MAAM,qBAAqB,cAAkC,KAAK;AAElE,SAAgB,oBAAoB,EAClC,YACiC;CACjC,MAAM,WAAW,OAAoB,KAAK;AAC1C,KAAI,CAAC,SAAS,QACZ,UAAS,UAAU,mBAAmB;AAExC,QACE,oBAAC,mBAAmB,UAApB;EAA6B,OAAO,SAAS;EAC1C;EAC2B,CAAA;;AAIlC,SAAS,wBAAwB;CAC/B,MAAM,WAAW,WAAW,mBAAmB;AAC/C,KAAI,CAAC,SACH,OAAM,IAAI,MACR,yCAAyC,oBAAoB,KAAK,IACnE;AAEH,QAAO;;AAGT,SAAgB,eAAkB,UAAwC;AAExE,QADiB,
|
|
1
|
+
{"version":3,"file":"useHeaderStore.js","names":[],"sources":["../../../../src/stores/header/useHeaderStore.tsx"],"sourcesContent":["import { createContext, useContext, useRef } from 'react'\nimport { create } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport type { PersistStoreProviderProps } from '../types.js'\nimport type { HeaderState, HeaderStore } from './types.js'\n\nconst HeaderStoreContext = createContext<HeaderStore | null>(null)\n\nexport function HeaderStoreProvider({\n children,\n}: PersistStoreProviderProps): any {\n const storeRef = useRef<HeaderStore>(null)\n if (!storeRef.current) {\n storeRef.current = createHeaderStore()\n }\n return (\n <HeaderStoreContext.Provider value={storeRef.current}>\n {children}\n </HeaderStoreContext.Provider>\n )\n}\n\nfunction useHeaderStoreContext() {\n const useStore = useContext(HeaderStoreContext)\n if (!useStore) {\n throw new Error(\n `You forgot to wrap your component in <${HeaderStoreProvider.name}>.`\n )\n }\n return useStore\n}\n\nexport function useHeaderStore<T>(selector: (state: HeaderState) => T): T {\n const useStore = useHeaderStoreContext()\n return useStore(useShallow(selector))\n}\n\n// We use fixed position on the header when Widget is in Full Height layout.\n// We do this to get it to work like the sticky header does in the other layout modes.\n// As the header is position fixed its not in the document flow anymore.\n// To prevent the remaining page content from appearing behind the header we need to\n// pass the headers height so that the position of the page content can be adjusted\nexport function useHeaderHeight(): any {\n const headerHeight = useHeaderStore((state) => state.headerHeight)\n\n return {\n headerHeight,\n }\n}\n\nexport function useSetHeaderHeight(): any {\n const setHeaderHeight = useHeaderStore((state) => state.setHeaderHeight)\n\n return {\n setHeaderHeight,\n }\n}\n\nconst createHeaderStore = () =>\n create<HeaderState>((set, get) => ({\n headerHeight: 108, // a basic default height\n setAction: (element) => {\n set(() => ({\n element,\n }))\n return get().removeAction\n },\n setTitle: (title) => {\n set(() => ({\n title,\n }))\n return get().removeTitle\n },\n removeAction: () => {\n set(() => ({\n element: null,\n }))\n },\n removeTitle: () => {\n set(() => ({\n title: undefined,\n }))\n },\n setHeaderHeight: (headerHeight) => {\n set(() => ({\n headerHeight,\n }))\n },\n setBackAction: (action) => {\n set(() => ({\n backAction: action,\n }))\n },\n executeBackAction: () => {\n const { backAction } = get()\n if (backAction) {\n backAction()\n set(() => ({\n backAction: undefined,\n }))\n }\n },\n }))\n"],"mappings":";;;;;AAMA,MAAM,qBAAqB,cAAkC,KAAK;AAElE,SAAgB,oBAAoB,EAClC,YACiC;CACjC,MAAM,WAAW,OAAoB,KAAK;AAC1C,KAAI,CAAC,SAAS,QACZ,UAAS,UAAU,mBAAmB;AAExC,QACE,oBAAC,mBAAmB,UAApB;EAA6B,OAAO,SAAS;EAC1C;EAC2B,CAAA;;AAIlC,SAAS,wBAAwB;CAC/B,MAAM,WAAW,WAAW,mBAAmB;AAC/C,KAAI,CAAC,SACH,OAAM,IAAI,MACR,yCAAyC,oBAAoB,KAAK,IACnE;AAEH,QAAO;;AAGT,SAAgB,eAAkB,UAAwC;AAExE,QADiB,uBACF,CAAC,WAAW,SAAS,CAAC;;AAQvC,SAAgB,kBAAuB;AAGrC,QAAO,EACL,cAHmB,gBAAgB,UAAU,MAAM,aAGvC,EACb;;AAGH,SAAgB,qBAA0B;AAGxC,QAAO,EACL,iBAHsB,gBAAgB,UAAU,MAAM,gBAGvC,EAChB;;AAGH,MAAM,0BACJ,QAAqB,KAAK,SAAS;CACjC,cAAc;CACd,YAAY,YAAY;AACtB,aAAW,EACT,SACD,EAAE;AACH,SAAO,KAAK,CAAC;;CAEf,WAAW,UAAU;AACnB,aAAW,EACT,OACD,EAAE;AACH,SAAO,KAAK,CAAC;;CAEf,oBAAoB;AAClB,aAAW,EACT,SAAS,MACV,EAAE;;CAEL,mBAAmB;AACjB,aAAW,EACT,OAAO,KAAA,GACR,EAAE;;CAEL,kBAAkB,iBAAiB;AACjC,aAAW,EACT,cACD,EAAE;;CAEL,gBAAgB,WAAW;AACzB,aAAW,EACT,YAAY,QACb,EAAE;;CAEL,yBAAyB;EACvB,MAAM,EAAE,eAAe,KAAK;AAC5B,MAAI,YAAY;AACd,eAAY;AACZ,cAAW,EACT,YAAY,KAAA,GACb,EAAE;;;CAGR,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouteExecutionStore.js","names":[],"sources":["../../../../src/stores/routes/RouteExecutionStore.tsx"],"sourcesContent":["import { createContext, type JSX, useContext, useRef } from 'react'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport type { PersistStoreProviderProps } from '../types.js'\nimport { createRouteExecutionStore } from './createRouteExecutionStore.js'\nimport type { RouteExecutionState } from './types.js'\n\ntype RouteExecutionStore = UseBoundStore<StoreApi<RouteExecutionState>>\n\nconst RouteExecutionStoreContext = createContext<RouteExecutionStore | null>(\n null\n)\n\nexport function RouteExecutionStoreProvider({\n children,\n ...props\n}: PersistStoreProviderProps): JSX.Element {\n const storeRef = useRef<RouteExecutionStore>(null)\n if (!storeRef.current) {\n storeRef.current = createRouteExecutionStore(props)\n }\n return (\n <RouteExecutionStoreContext.Provider value={storeRef.current}>\n {children}\n </RouteExecutionStoreContext.Provider>\n )\n}\n\nexport function useRouteExecutionStoreContext(): any {\n const useStore = useContext(RouteExecutionStoreContext)\n if (!useStore) {\n throw new Error(\n `You forgot to wrap your component in <${RouteExecutionStoreProvider.name}>.`\n )\n }\n return useStore\n}\n\nexport function useRouteExecutionStore<T>(\n selector: (state: RouteExecutionState) => T\n): T {\n const useStore = useRouteExecutionStoreContext()\n return useStore(useShallow(selector))\n}\n"],"mappings":";;;;;AASA,MAAM,6BAA6B,cACjC,KACD;AAED,SAAgB,4BAA4B,EAC1C,UACA,GAAG,SACsC;CACzC,MAAM,WAAW,OAA4B,KAAK;AAClD,KAAI,CAAC,SAAS,QACZ,UAAS,UAAU,0BAA0B,MAAM;AAErD,QACE,oBAAC,2BAA2B,UAA5B;EAAqC,OAAO,SAAS;EAClD;EACmC,CAAA;;AAI1C,SAAgB,gCAAqC;CACnD,MAAM,WAAW,WAAW,2BAA2B;AACvD,KAAI,CAAC,SACH,OAAM,IAAI,MACR,yCAAyC,4BAA4B,KAAK,IAC3E;AAEH,QAAO;;AAGT,SAAgB,uBACd,UACG;AAEH,QADiB,+
|
|
1
|
+
{"version":3,"file":"RouteExecutionStore.js","names":[],"sources":["../../../../src/stores/routes/RouteExecutionStore.tsx"],"sourcesContent":["import { createContext, type JSX, useContext, useRef } from 'react'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport type { PersistStoreProviderProps } from '../types.js'\nimport { createRouteExecutionStore } from './createRouteExecutionStore.js'\nimport type { RouteExecutionState } from './types.js'\n\ntype RouteExecutionStore = UseBoundStore<StoreApi<RouteExecutionState>>\n\nconst RouteExecutionStoreContext = createContext<RouteExecutionStore | null>(\n null\n)\n\nexport function RouteExecutionStoreProvider({\n children,\n ...props\n}: PersistStoreProviderProps): JSX.Element {\n const storeRef = useRef<RouteExecutionStore>(null)\n if (!storeRef.current) {\n storeRef.current = createRouteExecutionStore(props)\n }\n return (\n <RouteExecutionStoreContext.Provider value={storeRef.current}>\n {children}\n </RouteExecutionStoreContext.Provider>\n )\n}\n\nexport function useRouteExecutionStoreContext(): any {\n const useStore = useContext(RouteExecutionStoreContext)\n if (!useStore) {\n throw new Error(\n `You forgot to wrap your component in <${RouteExecutionStoreProvider.name}>.`\n )\n }\n return useStore\n}\n\nexport function useRouteExecutionStore<T>(\n selector: (state: RouteExecutionState) => T\n): T {\n const useStore = useRouteExecutionStoreContext()\n return useStore(useShallow(selector))\n}\n"],"mappings":";;;;;AASA,MAAM,6BAA6B,cACjC,KACD;AAED,SAAgB,4BAA4B,EAC1C,UACA,GAAG,SACsC;CACzC,MAAM,WAAW,OAA4B,KAAK;AAClD,KAAI,CAAC,SAAS,QACZ,UAAS,UAAU,0BAA0B,MAAM;AAErD,QACE,oBAAC,2BAA2B,UAA5B;EAAqC,OAAO,SAAS;EAClD;EACmC,CAAA;;AAI1C,SAAgB,gCAAqC;CACnD,MAAM,WAAW,WAAW,2BAA2B;AACvD,KAAI,CAAC,SACH,OAAM,IAAI,MACR,yCAAyC,4BAA4B,KAAK,IAC3E;AAEH,QAAO;;AAGT,SAAgB,uBACd,UACG;AAEH,QADiB,+BACF,CAAC,WAAW,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRouteExecutionStore.js","names":[],"sources":["../../../../src/stores/routes/createRouteExecutionStore.ts"],"sourcesContent":["import type { Route, RouteExtended } from '@lifi/sdk'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\nimport { persist } from 'zustand/middleware'\nimport { hasEnumFlag } from '../../utils/enum.js'\nimport type { PersistStoreProps } from '../types.js'\nimport type { RouteExecution, RouteExecutionState } from './types.js'\nimport { RouteExecutionStatus } from './types.js'\nimport {\n isRouteDone,\n isRouteFailed,\n isRoutePartiallyDone,\n isRouteRefunded,\n} from './utils.js'\n\nexport const createRouteExecutionStore = ({\n namePrefix,\n}: PersistStoreProps): UseBoundStore<StoreApi<RouteExecutionState>> =>\n create<RouteExecutionState>()(\n persist(\n (set, get) => ({\n routes: {},\n setExecutableRoute: (route: Route, observableRouteIds?: string[]) => {\n if (!get().routes[route.id]) {\n set((state: RouteExecutionState) => {\n const routes = { ...state.routes }\n // clean previous idle routes\n Object.keys(routes)\n .filter(\n (routeId) =>\n !observableRouteIds?.includes(routeId) &&\n hasEnumFlag(\n routes[routeId]!.status,\n RouteExecutionStatus.Idle\n )\n )\n .forEach((routeId) => {\n delete routes[routeId]\n })\n routes[route.id] = {\n route,\n status: RouteExecutionStatus.Idle,\n }\n return {\n routes,\n }\n })\n }\n },\n updateRoute: (route: RouteExtended) => {\n if (get().routes[route.id]) {\n set((state: RouteExecutionState) => {\n const updatedState = {\n routes: {\n ...state.routes,\n [route.id]: { ...state.routes[route.id]!, route },\n },\n }\n const isFailed = isRouteFailed(route)\n if (isFailed) {\n updatedState.routes[route.id]!.status =\n RouteExecutionStatus.Failed\n return updatedState\n }\n const isDone = isRouteDone(route)\n if (isDone) {\n updatedState.routes[route.id]!.status =\n RouteExecutionStatus.Done\n if (isRoutePartiallyDone(route)) {\n updatedState.routes[route.id]!.status |=\n RouteExecutionStatus.Partial\n } else if (isRouteRefunded(route)) {\n updatedState.routes[route.id]!.status |=\n RouteExecutionStatus.Refunded\n }\n return updatedState\n }\n const isLoading = route.steps.some((step) => step.execution)\n if (isLoading) {\n updatedState.routes[route.id]!.status =\n RouteExecutionStatus.Pending\n }\n return updatedState\n })\n }\n },\n deleteRoutes: (type, accountAddresses) =>\n set((state: RouteExecutionState) => {\n const routes = { ...state.routes }\n Object.keys(routes)\n .filter((routeId) => {\n const route = routes[routeId]\n if (\n accountAddresses &&\n !accountAddresses.includes(route?.route.fromAddress ?? '')\n ) {\n return false\n }\n return type === 'completed'\n ? hasEnumFlag(route?.status ?? 0, RouteExecutionStatus.Done)\n : type === 'failed'\n ? hasEnumFlag(\n route?.status ?? 0,\n RouteExecutionStatus.Failed\n )\n : !hasEnumFlag(\n route?.status ?? 0,\n RouteExecutionStatus.Done\n )\n })\n .forEach((routeId) => {\n delete routes[routeId]\n })\n return {\n routes,\n }\n }),\n deleteRoute: (routeId: string) => {\n if (get().routes[routeId]) {\n set((state: RouteExecutionState) => {\n const routes = { ...state.routes }\n delete routes[routeId]\n return {\n routes,\n }\n })\n }\n },\n }),\n {\n name: `${namePrefix || 'li.fi'}-widget-routes`,\n // Bump version on breaking changes to the stored structure.\n version: 4,\n // Clear stored routes on any version mismatch to avoid errors from incompatible data shapes.\n migrate: () => ({ routes: {} }),\n partialize: (state) => ({ routes: state.routes }),\n merge: (persistedState: any, currentState: RouteExecutionState) => {\n const state = {\n ...currentState,\n ...persistedState,\n } as RouteExecutionState\n try {\n // Keep only the most recent 100 routes, evicting the oldest when the\n // limit is exceeded.\n const maxStoredRoutes = 100\n const allRoutes = Object.values(state.routes) as RouteExecution[]\n const storedRoutes = allRoutes\n .sort(\n (a, b) =>\n (b.route.steps[0]?.execution?.startedAt ?? 0) -\n (a.route.steps[0]?.execution?.startedAt ?? 0)\n )\n .slice(0, maxStoredRoutes)\n const keepIds = new Set(storedRoutes.map((r) => r.route.id))\n for (const id of Object.keys(state.routes)) {\n if (!keepIds.has(id)) {\n delete state.routes[id]\n }\n }\n } catch (error) {\n console.error(error)\n }\n return state\n },\n }\n )\n )\n"],"mappings":";;;;;AAeA,MAAa,6BAA6B,EACxC,iBAEA,QAA6B,CAC3B,SACG,KAAK,SAAS;CACb,QAAQ,EAAE;CACV,qBAAqB,OAAc,uBAAkC;AACnE,MAAI,CAAC,KAAK,CAAC,OAAO,MAAM,IACtB,MAAK,UAA+B;GAClC,MAAM,SAAS,EAAE,GAAG,MAAM,QAAQ;AAElC,UAAO,KAAK,OAAO,CAChB,QACE,YACC,CAAC,oBAAoB,SAAS,QAAQ,IACtC,YACE,OAAO,SAAU,QAAA,EAElB,CACJ,CACA,SAAS,YAAY;AACpB,WAAO,OAAO;KACd;AACJ,UAAO,MAAM,MAAM;IACjB;IACA,QAAA;IACD;AACD,UAAO,EACL,QACD;IACD;;CAGN,cAAc,UAAyB;AACrC,MAAI,KAAK,CAAC,OAAO,MAAM,IACrB,MAAK,UAA+B;GAClC,MAAM,eAAe,EACnB,QAAQ;IACN,GAAG,MAAM;KACR,MAAM,KAAK;KAAE,GAAG,MAAM,OAAO,MAAM;KAAM;KAAO;IAClD,EACF;AAED,OADiB,cAAc,
|
|
1
|
+
{"version":3,"file":"createRouteExecutionStore.js","names":[],"sources":["../../../../src/stores/routes/createRouteExecutionStore.ts"],"sourcesContent":["import type { Route, RouteExtended } from '@lifi/sdk'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { create } from 'zustand'\nimport { persist } from 'zustand/middleware'\nimport { hasEnumFlag } from '../../utils/enum.js'\nimport type { PersistStoreProps } from '../types.js'\nimport type { RouteExecution, RouteExecutionState } from './types.js'\nimport { RouteExecutionStatus } from './types.js'\nimport {\n isRouteDone,\n isRouteFailed,\n isRoutePartiallyDone,\n isRouteRefunded,\n} from './utils.js'\n\nexport const createRouteExecutionStore = ({\n namePrefix,\n}: PersistStoreProps): UseBoundStore<StoreApi<RouteExecutionState>> =>\n create<RouteExecutionState>()(\n persist(\n (set, get) => ({\n routes: {},\n setExecutableRoute: (route: Route, observableRouteIds?: string[]) => {\n if (!get().routes[route.id]) {\n set((state: RouteExecutionState) => {\n const routes = { ...state.routes }\n // clean previous idle routes\n Object.keys(routes)\n .filter(\n (routeId) =>\n !observableRouteIds?.includes(routeId) &&\n hasEnumFlag(\n routes[routeId]!.status,\n RouteExecutionStatus.Idle\n )\n )\n .forEach((routeId) => {\n delete routes[routeId]\n })\n routes[route.id] = {\n route,\n status: RouteExecutionStatus.Idle,\n }\n return {\n routes,\n }\n })\n }\n },\n updateRoute: (route: RouteExtended) => {\n if (get().routes[route.id]) {\n set((state: RouteExecutionState) => {\n const updatedState = {\n routes: {\n ...state.routes,\n [route.id]: { ...state.routes[route.id]!, route },\n },\n }\n const isFailed = isRouteFailed(route)\n if (isFailed) {\n updatedState.routes[route.id]!.status =\n RouteExecutionStatus.Failed\n return updatedState\n }\n const isDone = isRouteDone(route)\n if (isDone) {\n updatedState.routes[route.id]!.status =\n RouteExecutionStatus.Done\n if (isRoutePartiallyDone(route)) {\n updatedState.routes[route.id]!.status |=\n RouteExecutionStatus.Partial\n } else if (isRouteRefunded(route)) {\n updatedState.routes[route.id]!.status |=\n RouteExecutionStatus.Refunded\n }\n return updatedState\n }\n const isLoading = route.steps.some((step) => step.execution)\n if (isLoading) {\n updatedState.routes[route.id]!.status =\n RouteExecutionStatus.Pending\n }\n return updatedState\n })\n }\n },\n deleteRoutes: (type, accountAddresses) =>\n set((state: RouteExecutionState) => {\n const routes = { ...state.routes }\n Object.keys(routes)\n .filter((routeId) => {\n const route = routes[routeId]\n if (\n accountAddresses &&\n !accountAddresses.includes(route?.route.fromAddress ?? '')\n ) {\n return false\n }\n return type === 'completed'\n ? hasEnumFlag(route?.status ?? 0, RouteExecutionStatus.Done)\n : type === 'failed'\n ? hasEnumFlag(\n route?.status ?? 0,\n RouteExecutionStatus.Failed\n )\n : !hasEnumFlag(\n route?.status ?? 0,\n RouteExecutionStatus.Done\n )\n })\n .forEach((routeId) => {\n delete routes[routeId]\n })\n return {\n routes,\n }\n }),\n deleteRoute: (routeId: string) => {\n if (get().routes[routeId]) {\n set((state: RouteExecutionState) => {\n const routes = { ...state.routes }\n delete routes[routeId]\n return {\n routes,\n }\n })\n }\n },\n }),\n {\n name: `${namePrefix || 'li.fi'}-widget-routes`,\n // Bump version on breaking changes to the stored structure.\n version: 4,\n // Clear stored routes on any version mismatch to avoid errors from incompatible data shapes.\n migrate: () => ({ routes: {} }),\n partialize: (state) => ({ routes: state.routes }),\n merge: (persistedState: any, currentState: RouteExecutionState) => {\n const state = {\n ...currentState,\n ...persistedState,\n } as RouteExecutionState\n try {\n // Keep only the most recent 100 routes, evicting the oldest when the\n // limit is exceeded.\n const maxStoredRoutes = 100\n const allRoutes = Object.values(state.routes) as RouteExecution[]\n const storedRoutes = allRoutes\n .sort(\n (a, b) =>\n (b.route.steps[0]?.execution?.startedAt ?? 0) -\n (a.route.steps[0]?.execution?.startedAt ?? 0)\n )\n .slice(0, maxStoredRoutes)\n const keepIds = new Set(storedRoutes.map((r) => r.route.id))\n for (const id of Object.keys(state.routes)) {\n if (!keepIds.has(id)) {\n delete state.routes[id]\n }\n }\n } catch (error) {\n console.error(error)\n }\n return state\n },\n }\n )\n )\n"],"mappings":";;;;;AAeA,MAAa,6BAA6B,EACxC,iBAEA,QAA6B,CAC3B,SACG,KAAK,SAAS;CACb,QAAQ,EAAE;CACV,qBAAqB,OAAc,uBAAkC;AACnE,MAAI,CAAC,KAAK,CAAC,OAAO,MAAM,IACtB,MAAK,UAA+B;GAClC,MAAM,SAAS,EAAE,GAAG,MAAM,QAAQ;AAEl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CACJ,cAAc,YAAoB;AAChC,MAAI,KAAK,CAAC,OAAO,SACf,MAAK,UAA+B;GAClC,MAAM,SAAS,EAAE,GAAG,MAAM,QAAQ;AAClC,UAAO,OAAO;AACd,UAAO,EACL,QACD;IACD;;CAGP,GACD;CACE,MAAM,GAAG,cAAc,QAAQ;CAE/B,SAAS;CAET,gBAAgB,EAAE,QAAQ,EAAE,EAAE;CAC9B,aAAa,WAAW,EAAE,QAAQ,MAAM,QAAQ;CAChD,QAAQ,gBAAqB,iBAAsC;EACjE,MAAM,QAAQ;GACZ,GAAG;GACH,GAAG;GACJ;AACD,MAAI;GAKF,MAAM,eADY,OAAO,OAAO,MAAM,OACR,CAC3B,MACE,GAAG,OACD,EAAE,MAAM,MAAM,IAAI,WAAW,aAAa,MAC1C,EAAE,MAAM,MAAM,IAAI,WAAW,aAAa,GAC9C,CACA,MAAM,GAAG,IAAgB;GAC5B,MAAM,UAAU,IAAI,IAAI,aAAa,KAAK,MAAM,EAAE,MAAM,GAAG,CAAC;AAC5D,QAAK,MAAM,MAAM,OAAO,KAAK,MAAM,OAAO,CACxC,KAAI,CAAC,QAAQ,IAAI,GAAG,CAClB,QAAO,MAAM,OAAO;WAGjB,OAAO;AACd,WAAQ,MAAM,MAAM;;AAEtB,SAAO;;CAEV,CACF,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouteExecutionIndicator.js","names":[],"sources":["../../../../src/stores/routes/useRouteExecutionIndicator.ts"],"sourcesContent":["import { useAccount } from '@lifi/wallet-management'\nimport { useCallback, useMemo } from 'react'\nimport { useRouteExecutionStore } from './RouteExecutionStore.js'\nimport type { RouteExecution, RouteExecutionState } from './types.js'\nimport { RouteExecutionStatus } from './types.js'\n\nexport type RouteExecutionIndicator = {\n failed: boolean\n active: boolean\n}\n\nconst isRecentTransaction = (route: RouteExecution): boolean => {\n const startedAt = route.route.steps[0]?.execution?.startedAt ?? 0\n return startedAt > 0 && Date.now() - startedAt < 1000 * 60 * 60 * 24 // 1 day\n}\n\nexport const useRouteExecutionIndicator = (): RouteExecutionIndicator => {\n const { accounts } = useAccount()\n const accountAddresses = useMemo(\n () => accounts.map((account) => account.address),\n [accounts]\n )\n const selector = useCallback(\n (state: RouteExecutionState): RouteExecutionIndicator => {\n const routes = Object.values(state.routes) as RouteExecution[]\n const recentOwnedRoutes = routes.filter(\n (route) =>\n accountAddresses.includes(route.route.fromAddress) &&\n isRecentTransaction(route)\n )\n return {\n failed: recentOwnedRoutes.some(\n (r) => r.status === RouteExecutionStatus.Failed\n ),\n active: recentOwnedRoutes.some(\n (r) => r.status === RouteExecutionStatus.Pending\n ),\n }\n },\n [accountAddresses]\n )\n return useRouteExecutionStore(selector)\n}\n"],"mappings":";;;;AAWA,MAAM,uBAAuB,UAAmC;CAC9D,MAAM,YAAY,MAAM,MAAM,MAAM,IAAI,WAAW,aAAa;AAChE,QAAO,YAAY,KAAK,KAAK,KAAK,GAAG,YAAY,MAAO,KAAK,KAAK;;AAGpE,MAAa,mCAA4D;CACvE,MAAM,EAAE,aAAa,YAAY;CACjC,MAAM,mBAAmB,cACjB,SAAS,KAAK,YAAY,QAAQ,QAAQ,EAChD,CAAC,SAAS,CACX;AAoBD,QAAO,uBAnBU,aACd,UAAwD;EAEvD,MAAM,oBADS,OAAO,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"useRouteExecutionIndicator.js","names":[],"sources":["../../../../src/stores/routes/useRouteExecutionIndicator.ts"],"sourcesContent":["import { useAccount } from '@lifi/wallet-management'\nimport { useCallback, useMemo } from 'react'\nimport { useRouteExecutionStore } from './RouteExecutionStore.js'\nimport type { RouteExecution, RouteExecutionState } from './types.js'\nimport { RouteExecutionStatus } from './types.js'\n\nexport type RouteExecutionIndicator = {\n failed: boolean\n active: boolean\n}\n\nconst isRecentTransaction = (route: RouteExecution): boolean => {\n const startedAt = route.route.steps[0]?.execution?.startedAt ?? 0\n return startedAt > 0 && Date.now() - startedAt < 1000 * 60 * 60 * 24 // 1 day\n}\n\nexport const useRouteExecutionIndicator = (): RouteExecutionIndicator => {\n const { accounts } = useAccount()\n const accountAddresses = useMemo(\n () => accounts.map((account) => account.address),\n [accounts]\n )\n const selector = useCallback(\n (state: RouteExecutionState): RouteExecutionIndicator => {\n const routes = Object.values(state.routes) as RouteExecution[]\n const recentOwnedRoutes = routes.filter(\n (route) =>\n accountAddresses.includes(route.route.fromAddress) &&\n isRecentTransaction(route)\n )\n return {\n failed: recentOwnedRoutes.some(\n (r) => r.status === RouteExecutionStatus.Failed\n ),\n active: recentOwnedRoutes.some(\n (r) => r.status === RouteExecutionStatus.Pending\n ),\n }\n },\n [accountAddresses]\n )\n return useRouteExecutionStore(selector)\n}\n"],"mappings":";;;;AAWA,MAAM,uBAAuB,UAAmC;CAC9D,MAAM,YAAY,MAAM,MAAM,MAAM,IAAI,WAAW,aAAa;AAChE,QAAO,YAAY,KAAK,KAAK,KAAK,GAAG,YAAY,MAAO,KAAK,KAAK;;AAGpE,MAAa,mCAA4D;CACvE,MAAM,EAAE,aAAa,YAAY;CACjC,MAAM,mBAAmB,cACjB,SAAS,KAAK,YAAY,QAAQ,QAAQ,EAChD,CAAC,SAAS,CACX;AAoBD,QAAO,uBAnBU,aACd,UAAwD;EAEvD,MAAM,oBADS,OAAO,OAAO,MAAM,OACH,CAAC,QAC9B,UACC,iBAAiB,SAAS,MAAM,MAAM,YAAY,IAClD,oBAAoB,MAAM,CAC7B;AACD,SAAO;GACL,QAAQ,kBAAkB,MACvB,MAAM,EAAE,WAAA,EACV;GACD,QAAQ,kBAAkB,MACvB,MAAM,EAAE,WAAA,EACV;GACF;IAEH,CAAC,iBAAiB,CAEkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../../../src/stores/routes/utils.ts"],"sourcesContent":["import type { ExecutionAction, RouteExtended } from '@lifi/sdk'\nimport microdiff from 'microdiff'\n\nexport const isRouteDone = (route: RouteExtended): boolean => {\n return route.steps.every((step) => step.execution?.status === 'DONE')\n}\n\nexport const isRoutePartiallyDone = (route: RouteExtended): boolean => {\n return route.steps.some((step) =>\n step.execution?.actions?.some((action) => action.substatus === 'PARTIAL')\n )\n}\n\nexport const isRouteRefunded = (route: RouteExtended): boolean => {\n return route.steps.some((step) =>\n step.execution?.actions?.some((action) => action.substatus === 'REFUNDED')\n )\n}\n\nexport const isRouteFailed = (route: RouteExtended): boolean => {\n return route.steps.some((step) => step.execution?.status === 'FAILED')\n}\n\nexport const isRouteActive = (route?: RouteExtended): boolean => {\n if (!route) {\n return false\n }\n const isDone = isRouteDone(route)\n const isFailed = isRouteFailed(route)\n const alreadyStarted = route.steps.some((step) => step.execution)\n return !isDone && !isFailed && alreadyStarted\n}\n\nexport const getUpdatedAction = (\n currentRoute: RouteExtended,\n updatedRoute: RouteExtended\n): ExecutionAction | undefined => {\n const actionDiff = microdiff(currentRoute, updatedRoute).find((diff) =>\n diff.path.includes('actions')\n )\n if (!actionDiff) {\n return undefined\n }\n // Find action index in the diff array so we can slice the complete action object\n // e.g. ['steps', 0, 'execution', 'actions', 0, 'message']\n const actionDiffIndex = actionDiff.path.indexOf('actions') + 2\n const actionPathSlice = actionDiff.path.slice(0, actionDiffIndex)\n // Reduce updated route using the diff path to get updated process\n const action = actionPathSlice.reduce(\n (obj, path) => obj[path],\n updatedRoute as any\n ) as ExecutionAction\n return action\n}\n\nexport const getSourceTxHash = (route?: RouteExtended): string | undefined => {\n const sourceAction = route?.steps[0].execution?.actions\n ?.filter(\n (action) => !['RESET_ALLOWANCE', 'SET_ALLOWANCE'].includes(action.type)\n )\n .find((action) => action.txHash || action.taskId)\n return sourceAction?.txHash || sourceAction?.taskId\n}\n"],"mappings":";;AAGA,MAAa,eAAe,UAAkC;AAC5D,QAAO,MAAM,MAAM,OAAO,SAAS,KAAK,WAAW,WAAW,OAAO;;AAGvE,MAAa,wBAAwB,UAAkC;AACrE,QAAO,MAAM,MAAM,MAAM,SACvB,KAAK,WAAW,SAAS,MAAM,WAAW,OAAO,cAAc,UAAU,CAC1E;;AAGH,MAAa,mBAAmB,UAAkC;AAChE,QAAO,MAAM,MAAM,MAAM,SACvB,KAAK,WAAW,SAAS,MAAM,WAAW,OAAO,cAAc,WAAW,CAC3E;;AAGH,MAAa,iBAAiB,UAAkC;AAC9D,QAAO,MAAM,MAAM,MAAM,SAAS,KAAK,WAAW,WAAW,SAAS;;AAGxE,MAAa,iBAAiB,UAAmC;AAC/D,KAAI,CAAC,MACH,QAAO;CAET,MAAM,SAAS,YAAY,MAAM;CACjC,MAAM,WAAW,cAAc,MAAM;CACrC,MAAM,iBAAiB,MAAM,MAAM,MAAM,SAAS,KAAK,UAAU;AACjE,QAAO,CAAC,UAAU,CAAC,YAAY;;AAGjC,MAAa,oBACX,cACA,iBACgC;CAChC,MAAM,aAAa,UAAU,cAAc,aAAa,CAAC,MAAM,SAC7D,KAAK,KAAK,SAAS,UAAU,CAC9B;AACD,KAAI,CAAC,WACH;CAIF,MAAM,kBAAkB,WAAW,KAAK,QAAQ,UAAU,GAAG;AAO7D,QANwB,WAAW,KAAK,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../../../src/stores/routes/utils.ts"],"sourcesContent":["import type { ExecutionAction, RouteExtended } from '@lifi/sdk'\nimport microdiff from 'microdiff'\n\nexport const isRouteDone = (route: RouteExtended): boolean => {\n return route.steps.every((step) => step.execution?.status === 'DONE')\n}\n\nexport const isRoutePartiallyDone = (route: RouteExtended): boolean => {\n return route.steps.some((step) =>\n step.execution?.actions?.some((action) => action.substatus === 'PARTIAL')\n )\n}\n\nexport const isRouteRefunded = (route: RouteExtended): boolean => {\n return route.steps.some((step) =>\n step.execution?.actions?.some((action) => action.substatus === 'REFUNDED')\n )\n}\n\nexport const isRouteFailed = (route: RouteExtended): boolean => {\n return route.steps.some((step) => step.execution?.status === 'FAILED')\n}\n\nexport const isRouteActive = (route?: RouteExtended): boolean => {\n if (!route) {\n return false\n }\n const isDone = isRouteDone(route)\n const isFailed = isRouteFailed(route)\n const alreadyStarted = route.steps.some((step) => step.execution)\n return !isDone && !isFailed && alreadyStarted\n}\n\nexport const getUpdatedAction = (\n currentRoute: RouteExtended,\n updatedRoute: RouteExtended\n): ExecutionAction | undefined => {\n const actionDiff = microdiff(currentRoute, updatedRoute).find((diff) =>\n diff.path.includes('actions')\n )\n if (!actionDiff) {\n return undefined\n }\n // Find action index in the diff array so we can slice the complete action object\n // e.g. ['steps', 0, 'execution', 'actions', 0, 'message']\n const actionDiffIndex = actionDiff.path.indexOf('actions') + 2\n const actionPathSlice = actionDiff.path.slice(0, actionDiffIndex)\n // Reduce updated route using the diff path to get updated process\n const action = actionPathSlice.reduce(\n (obj, path) => obj[path],\n updatedRoute as any\n ) as ExecutionAction\n return action\n}\n\nexport const getSourceTxHash = (route?: RouteExtended): string | undefined => {\n const sourceAction = route?.steps[0].execution?.actions\n ?.filter(\n (action) => !['RESET_ALLOWANCE', 'SET_ALLOWANCE'].includes(action.type)\n )\n .find((action) => action.txHash || action.taskId)\n return sourceAction?.txHash || sourceAction?.taskId\n}\n"],"mappings":";;AAGA,MAAa,eAAe,UAAkC;AAC5D,QAAO,MAAM,MAAM,OAAO,SAAS,KAAK,WAAW,WAAW,OAAO;;AAGvE,MAAa,wBAAwB,UAAkC;AACrE,QAAO,MAAM,MAAM,MAAM,SACvB,KAAK,WAAW,SAAS,MAAM,WAAW,OAAO,cAAc,UAAU,CAC1E;;AAGH,MAAa,mBAAmB,UAAkC;AAChE,QAAO,MAAM,MAAM,MAAM,SACvB,KAAK,WAAW,SAAS,MAAM,WAAW,OAAO,cAAc,WAAW,CAC3E;;AAGH,MAAa,iBAAiB,UAAkC;AAC9D,QAAO,MAAM,MAAM,MAAM,SAAS,KAAK,WAAW,WAAW,SAAS;;AAGxE,MAAa,iBAAiB,UAAmC;AAC/D,KAAI,CAAC,MACH,QAAO;CAET,MAAM,SAAS,YAAY,MAAM;CACjC,MAAM,WAAW,cAAc,MAAM;CACrC,MAAM,iBAAiB,MAAM,MAAM,MAAM,SAAS,KAAK,UAAU;AACjE,QAAO,CAAC,UAAU,CAAC,YAAY;;AAGjC,MAAa,oBACX,cACA,iBACgC;CAChC,MAAM,aAAa,UAAU,cAAc,aAAa,CAAC,MAAM,SAC7D,KAAK,KAAK,SAAS,UAAU,CAC9B;AACD,KAAI,CAAC,WACH;CAIF,MAAM,kBAAkB,WAAW,KAAK,QAAQ,UAAU,GAAG;AAO7D,QANwB,WAAW,KAAK,MAAM,GAAG,gBAEnB,CAAC,QAC5B,KAAK,SAAS,IAAI,OACnB,aAEW;;AAGf,MAAa,mBAAmB,UAA8C;CAC5E,MAAM,eAAe,OAAO,MAAM,GAAG,WAAW,SAC5C,QACC,WAAW,CAAC,CAAC,mBAAmB,gBAAgB,CAAC,SAAS,OAAO,KAAK,CACxE,CACA,MAAM,WAAW,OAAO,UAAU,OAAO,OAAO;AACnD,QAAO,cAAc,UAAU,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SettingsStore.js","names":[],"sources":["../../../../src/stores/settings/SettingsStore.tsx"],"sourcesContent":["import {\n createContext,\n type JSX,\n type PropsWithChildren,\n useContext,\n useRef,\n} from 'react'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport { createSettingsStore } from './createSettingsStore.js'\nimport type { SettingsState, SettingsStoreProviderProps } from './types.js'\n\ntype SettingsStore = UseBoundStore<StoreApi<SettingsState>>\n\nconst SettingsStoreContext = createContext<SettingsStore | null>(null)\n\nexport const SettingsStoreProvider = ({\n children,\n config,\n}: PropsWithChildren<SettingsStoreProviderProps>): JSX.Element => {\n const storeRef = useRef<SettingsStore>(null)\n if (!storeRef.current) {\n storeRef.current = createSettingsStore(config)\n }\n return (\n <SettingsStoreContext.Provider value={storeRef.current}>\n {children}\n </SettingsStoreContext.Provider>\n )\n}\n\nexport function useSettingsStoreContext(): any {\n const useStore = useContext(SettingsStoreContext)\n if (!useStore) {\n throw new Error(\n 'You forgot to wrap your component in SettingsStoreContext.'\n )\n }\n return useStore\n}\n\nexport function useSettingsStore<T>(selector: (state: SettingsState) => T): T {\n const useStore = useSettingsStoreContext()\n return useStore(useShallow(selector))\n}\n"],"mappings":";;;;;AAcA,MAAM,uBAAuB,cAAoC,KAAK;AAEtE,MAAa,yBAAyB,EACpC,UACA,aACgE;CAChE,MAAM,WAAW,OAAsB,KAAK;AAC5C,KAAI,CAAC,SAAS,QACZ,UAAS,UAAU,oBAAoB,OAAO;AAEhD,QACE,oBAAC,qBAAqB,UAAtB;EAA+B,OAAO,SAAS;EAC5C;EAC6B,CAAA;;AAIpC,SAAgB,0BAA+B;CAC7C,MAAM,WAAW,WAAW,qBAAqB;AACjD,KAAI,CAAC,SACH,OAAM,IAAI,MACR,6DACD;AAEH,QAAO;;AAGT,SAAgB,iBAAoB,UAA0C;AAE5E,QADiB,
|
|
1
|
+
{"version":3,"file":"SettingsStore.js","names":[],"sources":["../../../../src/stores/settings/SettingsStore.tsx"],"sourcesContent":["import {\n createContext,\n type JSX,\n type PropsWithChildren,\n useContext,\n useRef,\n} from 'react'\nimport type { StoreApi, UseBoundStore } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport { createSettingsStore } from './createSettingsStore.js'\nimport type { SettingsState, SettingsStoreProviderProps } from './types.js'\n\ntype SettingsStore = UseBoundStore<StoreApi<SettingsState>>\n\nconst SettingsStoreContext = createContext<SettingsStore | null>(null)\n\nexport const SettingsStoreProvider = ({\n children,\n config,\n}: PropsWithChildren<SettingsStoreProviderProps>): JSX.Element => {\n const storeRef = useRef<SettingsStore>(null)\n if (!storeRef.current) {\n storeRef.current = createSettingsStore(config)\n }\n return (\n <SettingsStoreContext.Provider value={storeRef.current}>\n {children}\n </SettingsStoreContext.Provider>\n )\n}\n\nexport function useSettingsStoreContext(): any {\n const useStore = useContext(SettingsStoreContext)\n if (!useStore) {\n throw new Error(\n 'You forgot to wrap your component in SettingsStoreContext.'\n )\n }\n return useStore\n}\n\nexport function useSettingsStore<T>(selector: (state: SettingsState) => T): T {\n const useStore = useSettingsStoreContext()\n return useStore(useShallow(selector))\n}\n"],"mappings":";;;;;AAcA,MAAM,uBAAuB,cAAoC,KAAK;AAEtE,MAAa,yBAAyB,EACpC,UACA,aACgE;CAChE,MAAM,WAAW,OAAsB,KAAK;AAC5C,KAAI,CAAC,SAAS,QACZ,UAAS,UAAU,oBAAoB,OAAO;AAEhD,QACE,oBAAC,qBAAqB,UAAtB;EAA+B,OAAO,SAAS;EAC5C;EAC6B,CAAA;;AAIpC,SAAgB,0BAA+B;CAC7C,MAAM,WAAW,WAAW,qBAAqB;AACjD,KAAI,CAAC,SACH,OAAM,IAAI,MACR,6DACD;AAEH,QAAO;;AAGT,SAAgB,iBAAoB,UAA0C;AAE5E,QADiB,yBACF,CAAC,WAAW,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSettingsActions.js","names":[],"sources":["../../../../src/stores/settings/useSettingsActions.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport type { widgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { useWidgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { WidgetEvent } from '../../types/events.js'\nimport type { WidgetConfig } from '../../types/widget.js'\nimport { deepEqual } from '../../utils/deepEqual.js'\nimport { defaultConfigurableSettings } from './createSettingsStore.js'\nimport { useSettingsStore } from './SettingsStore.js'\nimport type {\n SettingsActions,\n SettingsProps,\n SettingsToolType,\n ValueSetter,\n} from './types.js'\n\nconst emitEventOnChange = <T extends (...args: any[]) => any>(\n emitter: typeof widgetEvents,\n actions: Omit<SettingsActions, 'initializeTools'>,\n settingFunction: T,\n ...args: Parameters<T>\n) => {\n const oldSettings = actions.getSettings()\n\n settingFunction(...args)\n\n const newSettings = actions.getSettings()\n\n if (!deepEqual(oldSettings, newSettings)) {\n ;(Object.keys(oldSettings) as (keyof SettingsProps)[]).forEach(\n (toolKey) => {\n if (!deepEqual(oldSettings[toolKey], newSettings[toolKey])) {\n emitter.emit(WidgetEvent.SettingUpdated, {\n setting: toolKey,\n newValue: newSettings[toolKey],\n oldValue: oldSettings[toolKey],\n newSettings: newSettings,\n oldSettings: oldSettings,\n })\n }\n }\n )\n }\n}\n\nexport const useSettingsActions = (): {\n setValue: ValueSetter<SettingsProps>\n setValues: (values: Partial<SettingsProps>) => void\n setDefaultSettings: (config?: WidgetConfig) => void\n resetSettings: (bridges: string[], exchanges: string[]) => void\n setToolValue: (\n toolType: SettingsToolType,\n tool: string,\n value: boolean\n ) => void\n toggleToolKeys: (toolType: SettingsToolType, toolKeys: string[]) => void\n} => {\n const emitter = useWidgetEvents()\n const actions = useSettingsStore((state) => ({\n setValue: state.setValue,\n setValues: state.setValues,\n getValue: state.getValue,\n getSettings: state.getSettings,\n reset: state.reset,\n setToolValue: state.setToolValue,\n toggleToolKeys: state.toggleToolKeys,\n }))\n\n const setValueWithEmittedEvent = useCallback<ValueSetter<SettingsProps>>(\n (value, newValue) => {\n const setting = value as keyof SettingsProps\n emitEventOnChange(emitter, actions, actions.setValue, setting, newValue)\n },\n [emitter, actions]\n )\n\n const setValuesWithEmittedEvent = useCallback(\n (values: Partial<SettingsProps>) => {\n Object.entries(values).forEach(([key, value]) => {\n setValueWithEmittedEvent(key as keyof SettingsProps, value)\n })\n },\n [setValueWithEmittedEvent]\n )\n\n const setDefaultSettingsWithEmittedEvents = useCallback(\n (config?: WidgetConfig) => {\n const slippage = actions.getValue('slippage')\n const routePriority = actions.getValue('routePriority')\n const gasPrice = actions.getValue('gasPrice')\n\n const defaultSlippage =\n (config?.slippage || config?.sdkConfig?.routeOptions?.slippage || 0) *\n 100\n const defaultRoutePriority =\n config?.routePriority || config?.sdkConfig?.routeOptions?.order\n\n defaultConfigurableSettings.slippage = (\n defaultSlippage || defaultConfigurableSettings.slippage\n )?.toString()\n\n defaultConfigurableSettings.routePriority =\n defaultRoutePriority || defaultConfigurableSettings.routePriority\n\n if (!slippage) {\n setValueWithEmittedEvent(\n 'slippage',\n defaultConfigurableSettings.slippage\n )\n }\n if (!routePriority) {\n setValueWithEmittedEvent(\n 'routePriority',\n defaultConfigurableSettings.routePriority\n )\n }\n if (!gasPrice) {\n setValueWithEmittedEvent(\n 'gasPrice',\n defaultConfigurableSettings.gasPrice\n )\n }\n },\n [actions, setValueWithEmittedEvent]\n )\n\n const resetWithEmittedEvents = useCallback(\n (bridges: string[], exchanges: string[]) => {\n emitEventOnChange(emitter, actions, actions.reset, bridges, exchanges)\n },\n [emitter, actions]\n )\n\n const setToolValueWithEmittedEvents = useCallback(\n (toolType: SettingsToolType, tool: string, value: boolean) => {\n emitEventOnChange(\n emitter,\n actions,\n actions.setToolValue,\n toolType,\n tool,\n value\n )\n },\n [emitter, actions]\n )\n\n const toggleToolKeysWithEmittedEvents = useCallback(\n (toolType: SettingsToolType, toolKeys: string[]) => {\n emitEventOnChange(\n emitter,\n actions,\n actions.toggleToolKeys,\n toolType,\n toolKeys\n )\n },\n [emitter, actions]\n )\n\n return {\n setValue: setValueWithEmittedEvent,\n setValues: setValuesWithEmittedEvent,\n setDefaultSettings: setDefaultSettingsWithEmittedEvents,\n resetSettings: resetWithEmittedEvents,\n setToolValue: setToolValueWithEmittedEvents,\n toggleToolKeys: toggleToolKeysWithEmittedEvents,\n }\n}\n"],"mappings":";;;;;;;AAeA,MAAM,qBACJ,SACA,SACA,iBACA,GAAG,SACA;CACH,MAAM,cAAc,QAAQ,aAAa;AAEzC,iBAAgB,GAAG,KAAK;CAExB,MAAM,cAAc,QAAQ,aAAa;AAEzC,KAAI,CAAC,UAAU,aAAa,YAAY,CACpC,QAAO,KAAK,YAAY,CAA6B,SACpD,YAAY;AACX,MAAI,CAAC,UAAU,YAAY,UAAU,YAAY,SAAS,CACxD,SAAQ,KAAA,kBAAiC;GACvC,SAAS;GACT,UAAU,YAAY;GACtB,UAAU,YAAY;GACT;GACA;GACd,CAAC;GAGP;;AAIL,MAAa,2BAWR;CACH,MAAM,UAAU,iBAAiB;CACjC,MAAM,UAAU,kBAAkB,WAAW;EAC3C,UAAU,MAAM;EAChB,WAAW,MAAM;EACjB,UAAU,MAAM;EAChB,aAAa,MAAM;EACnB,OAAO,MAAM;EACb,cAAc,MAAM;EACpB,gBAAgB,MAAM;EACvB,EAAE;CAEH,MAAM,2BAA2B,aAC9B,OAAO,aAAa;EACnB,MAAM,UAAU;AAChB,oBAAkB,SAAS,SAAS,QAAQ,UAAU,SAAS,SAAS;IAE1E,CAAC,SAAS,QAAQ,CACnB;AAsFD,QAAO;EACL,UAAU;EACV,WAtFgC,aAC/B,WAAmC;AAClC,UAAO,QAAQ,OAAO,CAAC,SAAS,CAAC,KAAK,WAAW;AAC/C,6BAAyB,KAA4B,MAAM;KAC3D;KAEJ,CAAC,yBAAyB,
|
|
1
|
+
{"version":3,"file":"useSettingsActions.js","names":[],"sources":["../../../../src/stores/settings/useSettingsActions.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport type { widgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { useWidgetEvents } from '../../hooks/useWidgetEvents.js'\nimport { WidgetEvent } from '../../types/events.js'\nimport type { WidgetConfig } from '../../types/widget.js'\nimport { deepEqual } from '../../utils/deepEqual.js'\nimport { defaultConfigurableSettings } from './createSettingsStore.js'\nimport { useSettingsStore } from './SettingsStore.js'\nimport type {\n SettingsActions,\n SettingsProps,\n SettingsToolType,\n ValueSetter,\n} from './types.js'\n\nconst emitEventOnChange = <T extends (...args: any[]) => any>(\n emitter: typeof widgetEvents,\n actions: Omit<SettingsActions, 'initializeTools'>,\n settingFunction: T,\n ...args: Parameters<T>\n) => {\n const oldSettings = actions.getSettings()\n\n settingFunction(...args)\n\n const newSettings = actions.getSettings()\n\n if (!deepEqual(oldSettings, newSettings)) {\n ;(Object.keys(oldSettings) as (keyof SettingsProps)[]).forEach(\n (toolKey) => {\n if (!deepEqual(oldSettings[toolKey], newSettings[toolKey])) {\n emitter.emit(WidgetEvent.SettingUpdated, {\n setting: toolKey,\n newValue: newSettings[toolKey],\n oldValue: oldSettings[toolKey],\n newSettings: newSettings,\n oldSettings: oldSettings,\n })\n }\n }\n )\n }\n}\n\nexport const useSettingsActions = (): {\n setValue: ValueSetter<SettingsProps>\n setValues: (values: Partial<SettingsProps>) => void\n setDefaultSettings: (config?: WidgetConfig) => void\n resetSettings: (bridges: string[], exchanges: string[]) => void\n setToolValue: (\n toolType: SettingsToolType,\n tool: string,\n value: boolean\n ) => void\n toggleToolKeys: (toolType: SettingsToolType, toolKeys: string[]) => void\n} => {\n const emitter = useWidgetEvents()\n const actions = useSettingsStore((state) => ({\n setValue: state.setValue,\n setValues: state.setValues,\n getValue: state.getValue,\n getSettings: state.getSettings,\n reset: state.reset,\n setToolValue: state.setToolValue,\n toggleToolKeys: state.toggleToolKeys,\n }))\n\n const setValueWithEmittedEvent = useCallback<ValueSetter<SettingsProps>>(\n (value, newValue) => {\n const setting = value as keyof SettingsProps\n emitEventOnChange(emitter, actions, actions.setValue, setting, newValue)\n },\n [emitter, actions]\n )\n\n const setValuesWithEmittedEvent = useCallback(\n (values: Partial<SettingsProps>) => {\n Object.entries(values).forEach(([key, value]) => {\n setValueWithEmittedEvent(key as keyof SettingsProps, value)\n })\n },\n [setValueWithEmittedEvent]\n )\n\n const setDefaultSettingsWithEmittedEvents = useCallback(\n (config?: WidgetConfig) => {\n const slippage = actions.getValue('slippage')\n const routePriority = actions.getValue('routePriority')\n const gasPrice = actions.getValue('gasPrice')\n\n const defaultSlippage =\n (config?.slippage || config?.sdkConfig?.routeOptions?.slippage || 0) *\n 100\n const defaultRoutePriority =\n config?.routePriority || config?.sdkConfig?.routeOptions?.order\n\n defaultConfigurableSettings.slippage = (\n defaultSlippage || defaultConfigurableSettings.slippage\n )?.toString()\n\n defaultConfigurableSettings.routePriority =\n defaultRoutePriority || defaultConfigurableSettings.routePriority\n\n if (!slippage) {\n setValueWithEmittedEvent(\n 'slippage',\n defaultConfigurableSettings.slippage\n )\n }\n if (!routePriority) {\n setValueWithEmittedEvent(\n 'routePriority',\n defaultConfigurableSettings.routePriority\n )\n }\n if (!gasPrice) {\n setValueWithEmittedEvent(\n 'gasPrice',\n defaultConfigurableSettings.gasPrice\n )\n }\n },\n [actions, setValueWithEmittedEvent]\n )\n\n const resetWithEmittedEvents = useCallback(\n (bridges: string[], exchanges: string[]) => {\n emitEventOnChange(emitter, actions, actions.reset, bridges, exchanges)\n },\n [emitter, actions]\n )\n\n const setToolValueWithEmittedEvents = useCallback(\n (toolType: SettingsToolType, tool: string, value: boolean) => {\n emitEventOnChange(\n emitter,\n actions,\n actions.setToolValue,\n toolType,\n tool,\n value\n )\n },\n [emitter, actions]\n )\n\n const toggleToolKeysWithEmittedEvents = useCallback(\n (toolType: SettingsToolType, toolKeys: string[]) => {\n emitEventOnChange(\n emitter,\n actions,\n actions.toggleToolKeys,\n toolType,\n toolKeys\n )\n },\n [emitter, actions]\n )\n\n return {\n setValue: setValueWithEmittedEvent,\n setValues: setValuesWithEmittedEvent,\n setDefaultSettings: setDefaultSettingsWithEmittedEvents,\n resetSettings: resetWithEmittedEvents,\n setToolValue: setToolValueWithEmittedEvents,\n toggleToolKeys: toggleToolKeysWithEmittedEvents,\n }\n}\n"],"mappings":";;;;;;;AAeA,MAAM,qBACJ,SACA,SACA,iBACA,GAAG,SACA;CACH,MAAM,cAAc,QAAQ,aAAa;AAEzC,iBAAgB,GAAG,KAAK;CAExB,MAAM,cAAc,QAAQ,aAAa;AAEzC,KAAI,CAAC,UAAU,aAAa,YAAY,CACpC,QAAO,KAAK,YAAY,CAA6B,SACpD,YAAY;AACX,MAAI,CAAC,UAAU,YAAY,UAAU,YAAY,SAAS,CACxD,SAAQ,KAAA,kBAAiC;GACvC,SAAS;GACT,UAAU,YAAY;GACtB,UAAU,YAAY;GACT;GACA;GACd,CAAC;GAGP;;AAIL,MAAa,2BAWR;CACH,MAAM,UAAU,iBAAiB;CACjC,MAAM,UAAU,kBAAkB,WAAW;EAC3C,UAAU,MAAM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BAnBsC,aACrC,UAA4B,aAAuB;AAClD,qBACE,SACA,SACA,QAAQ,gBACR,UACA,SACD;KAEH,CAAC,SAAS,QAAQ,CAS6B;EAChD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSplitSubvariantStore.js","names":[],"sources":["../../../../src/stores/settings/useSplitSubvariantStore.tsx"],"sourcesContent":["import { createContext, type JSX, useContext, useRef } from 'react'\nimport { create } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport type {\n SplitSubvariantProps,\n SplitSubvariantProviderProps,\n SplitSubvariantState,\n SplitSubvariantStore,\n} from './types.js'\n\nconst SplitSubvariantStoreContext = createContext<SplitSubvariantStore | null>(\n null\n)\n\nconst shouldRecreateStore = (\n store: SplitSubvariantStore,\n props: SplitSubvariantProps\n) => {\n const { state } = store.getState()\n return state !== props.state\n}\n\nexport function SplitSubvariantStoreProvider({\n children,\n ...props\n}: SplitSubvariantProviderProps): JSX.Element {\n const storeRef = useRef<SplitSubvariantStore>(null)\n if (!storeRef.current || shouldRecreateStore(storeRef.current, props)) {\n storeRef.current = createSplitSubvariantStore(props)\n }\n return (\n <SplitSubvariantStoreContext.Provider value={storeRef.current}>\n {children}\n </SplitSubvariantStoreContext.Provider>\n )\n}\n\nfunction useSplitSubvariantStoreContext() {\n const useStore = useContext(SplitSubvariantStoreContext)\n if (!useStore) {\n throw new Error(\n `You forgot to wrap your component in <${SplitSubvariantStoreProvider.name}>.`\n )\n }\n return useStore\n}\n\nexport function useSplitSubvariantStore<T>(\n selector: (state: SplitSubvariantState) => T\n): T {\n const useStore = useSplitSubvariantStoreContext()\n return useStore(useShallow(selector))\n}\n\nconst createSplitSubvariantStore = ({ state }: SplitSubvariantProps) =>\n create<SplitSubvariantState>((set) => ({\n state,\n setState(state) {\n set(() => ({\n state,\n }))\n },\n }))\n"],"mappings":";;;;;AAUA,MAAM,8BAA8B,cAClC,KACD;AAED,MAAM,uBACJ,OACA,UACG;CACH,MAAM,EAAE,UAAU,MAAM,UAAU;AAClC,QAAO,UAAU,MAAM;;AAGzB,SAAgB,6BAA6B,EAC3C,UACA,GAAG,SACyC;CAC5C,MAAM,WAAW,OAA6B,KAAK;AACnD,KAAI,CAAC,SAAS,WAAW,oBAAoB,SAAS,SAAS,MAAM,CACnE,UAAS,UAAU,2BAA2B,MAAM;AAEtD,QACE,oBAAC,4BAA4B,UAA7B;EAAsC,OAAO,SAAS;EACnD;EACoC,CAAA;;AAI3C,SAAS,iCAAiC;CACxC,MAAM,WAAW,WAAW,4BAA4B;AACxD,KAAI,CAAC,SACH,OAAM,IAAI,MACR,yCAAyC,6BAA6B,KAAK,IAC5E;AAEH,QAAO;;AAGT,SAAgB,wBACd,UACG;AAEH,QADiB,
|
|
1
|
+
{"version":3,"file":"useSplitSubvariantStore.js","names":[],"sources":["../../../../src/stores/settings/useSplitSubvariantStore.tsx"],"sourcesContent":["import { createContext, type JSX, useContext, useRef } from 'react'\nimport { create } from 'zustand'\nimport { useShallow } from 'zustand/shallow'\nimport type {\n SplitSubvariantProps,\n SplitSubvariantProviderProps,\n SplitSubvariantState,\n SplitSubvariantStore,\n} from './types.js'\n\nconst SplitSubvariantStoreContext = createContext<SplitSubvariantStore | null>(\n null\n)\n\nconst shouldRecreateStore = (\n store: SplitSubvariantStore,\n props: SplitSubvariantProps\n) => {\n const { state } = store.getState()\n return state !== props.state\n}\n\nexport function SplitSubvariantStoreProvider({\n children,\n ...props\n}: SplitSubvariantProviderProps): JSX.Element {\n const storeRef = useRef<SplitSubvariantStore>(null)\n if (!storeRef.current || shouldRecreateStore(storeRef.current, props)) {\n storeRef.current = createSplitSubvariantStore(props)\n }\n return (\n <SplitSubvariantStoreContext.Provider value={storeRef.current}>\n {children}\n </SplitSubvariantStoreContext.Provider>\n )\n}\n\nfunction useSplitSubvariantStoreContext() {\n const useStore = useContext(SplitSubvariantStoreContext)\n if (!useStore) {\n throw new Error(\n `You forgot to wrap your component in <${SplitSubvariantStoreProvider.name}>.`\n )\n }\n return useStore\n}\n\nexport function useSplitSubvariantStore<T>(\n selector: (state: SplitSubvariantState) => T\n): T {\n const useStore = useSplitSubvariantStoreContext()\n return useStore(useShallow(selector))\n}\n\nconst createSplitSubvariantStore = ({ state }: SplitSubvariantProps) =>\n create<SplitSubvariantState>((set) => ({\n state,\n setState(state) {\n set(() => ({\n state,\n }))\n },\n }))\n"],"mappings":";;;;;AAUA,MAAM,8BAA8B,cAClC,KACD;AAED,MAAM,uBACJ,OACA,UACG;CACH,MAAM,EAAE,UAAU,MAAM,UAAU;AAClC,QAAO,UAAU,MAAM;;AAGzB,SAAgB,6BAA6B,EAC3C,UACA,GAAG,SACyC;CAC5C,MAAM,WAAW,OAA6B,KAAK;AACnD,KAAI,CAAC,SAAS,WAAW,oBAAoB,SAAS,SAAS,MAAM,CACnE,UAAS,UAAU,2BAA2B,MAAM;AAEtD,QACE,oBAAC,4BAA4B,UAA7B;EAAsC,OAAO,SAAS;EACnD;EACoC,CAAA;;AAI3C,SAAS,iCAAiC;CACxC,MAAM,WAAW,WAAW,4BAA4B;AACxD,KAAI,CAAC,SACH,OAAM,IAAI,MACR,yCAAyC,6BAA6B,KAAK,IAC5E;AAEH,QAAO;;AAGT,SAAgB,wBACd,UACG;AAEH,QADiB,gCACF,CAAC,WAAW,SAAS,CAAC;;AAGvC,MAAM,8BAA8B,EAAE,YACpC,QAA8B,SAAS;CACrC;CACA,SAAS,OAAO;AACd,aAAW,EACT,OACD,EAAE;;CAEN,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converters.js","names":[],"sources":["../../../src/utils/converters.ts"],"sourcesContent":["import type {\n ExecutionAction,\n ExecutionActionStatus,\n ExtendedTransactionInfo,\n FeeCost,\n FullStatusData,\n Substatus,\n TokenAmount,\n ToolsResponse,\n} from '@lifi/sdk'\nimport type { RouteExecution } from '../stores/routes/types.js'\nimport { formatTokenPrice } from './format.js'\n\nconst buildActionsFromTxHistory = (tx: FullStatusData): ExecutionAction[] => {\n const sending = tx.sending as ExtendedTransactionInfo\n const receiving = tx.receiving as ExtendedTransactionInfo\n\n if (!sending.token?.chainId || !receiving.token?.chainId) {\n return []\n }\n\n const actionStatus: ExecutionActionStatus =\n tx.status === 'DONE' ? 'DONE' : 'FAILED'\n const substatus: Substatus =\n actionStatus === 'FAILED' ? 'UNKNOWN_ERROR' : 'COMPLETED'\n\n if (sending.chainId === receiving.chainId) {\n return [\n {\n type: 'SWAP', // operations on same chain will be swaps\n message: '',\n status: actionStatus,\n chainId: sending.chainId,\n txHash: sending.txHash,\n txLink: sending.txLink,\n substatus,\n substatusMessage: '',\n },\n ]\n }\n\n const actions: ExecutionAction[] = [\n {\n type: 'CROSS_CHAIN', // first step of bridging, ignoring the approvals\n message: '',\n status: actionStatus, // can be FAILED\n chainId: sending.chainId,\n txHash: sending.txHash,\n txLink: sending.txLink,\n },\n {\n type: 'RECEIVING_CHAIN', // final step of bridging, post swaps\n message: '',\n status: actionStatus,\n substatus,\n substatusMessage: '',\n chainId: receiving.chainId,\n txHash: receiving.txHash,\n txLink: receiving.txLink,\n },\n ]\n\n return actions\n}\n\nexport const buildRouteFromTxHistory = (\n tx: FullStatusData,\n tools?: ToolsResponse\n): RouteExecution | undefined => {\n const sending = tx.sending as ExtendedTransactionInfo\n const receiving = tx.receiving as ExtendedTransactionInfo\n\n if (!sending.token?.chainId || !receiving.token?.chainId) {\n return\n }\n\n let usedTool = tx.sending.includedSteps?.find(\n (step) => step.toolDetails.key === tx.tool\n )?.toolDetails\n\n if (!usedTool) {\n const selectedBridge = tools?.bridges.find(\n (bridge) => bridge.key === tx.tool\n )\n\n const selectedExchange = tools?.exchanges.find(\n (exchange) => exchange.key === tx.tool\n )\n usedTool = {\n key: tx.tool,\n name: selectedBridge?.name ?? selectedExchange?.name ?? tx.tool,\n logoURI: selectedBridge?.logoURI ?? selectedExchange?.logoURI ?? '',\n }\n }\n\n const fromToken: TokenAmount = {\n ...sending.token,\n amount: BigInt(sending.amount ?? 0),\n }\n\n const toToken: TokenAmount = {\n ...receiving.token,\n amount: BigInt(receiving.amount ?? 0),\n }\n\n const sendingValue = sending.value ? BigInt(sending.value) : 0n\n const sendingFeeAmount =\n sending.gasToken.address === sending.token.address && sending.amount\n ? sendingValue - BigInt(sending.amount)\n : sendingValue\n const sendingFeeAmountUsd =\n sending.gasToken.priceUSD && sendingFeeAmount\n ? formatTokenPrice(\n sendingFeeAmount,\n sending.gasToken.priceUSD,\n sending.gasToken.decimals\n )\n : 0\n\n const feeCosts: FeeCost[] | undefined = sendingFeeAmount\n ? [\n {\n amount: sendingFeeAmount.toString(),\n amountUSD: sendingFeeAmountUsd.toFixed(2),\n token: sending.gasToken,\n included: false,\n // Not used\n description: '',\n name: '',\n percentage: '',\n },\n ]\n : undefined\n\n const routeExecution: RouteExecution = {\n status: 1,\n route: {\n id: (tx as FullStatusData).transactionId,\n fromAddress: (tx as FullStatusData).fromAddress,\n toAddress: (tx as FullStatusData).toAddress,\n fromChainId: sending.chainId,\n fromAmount: sending.amount ?? '',\n fromAmountUSD: sending.amountUSD ?? '',\n toAmount: receiving.amount ?? '',\n toAmountMin: receiving.amount ?? '',\n toAmountUSD: receiving.amountUSD ?? '',\n toChainId: receiving.chainId,\n fromToken,\n toToken,\n gasCostUSD: sending.gasAmountUSD,\n steps: [\n {\n id: (tx as FullStatusData).transactionId,\n type: 'lifi',\n tool: tx.tool,\n toolDetails: usedTool,\n action: {\n fromToken: sending.token,\n fromAmount: sending.amount ?? '',\n fromChainId: sending.chainId,\n fromAddress: (tx as FullStatusData).fromAddress,\n toToken: receiving.token,\n toChainId: receiving.chainId,\n toAddress: (tx as FullStatusData).toAddress,\n slippage: 0,\n },\n estimate: {\n tool: tx.tool,\n approvalAddress: '',\n fromAmount: sending.amount ?? '',\n fromAmountUSD: sending.amountUSD ?? '',\n toAmountMin: receiving.amount ?? '',\n toAmount: receiving.amount ?? '',\n toAmountUSD: receiving.amountUSD ?? '',\n executionDuration: 0,\n },\n includedSteps: [\n {\n id: (tx as FullStatusData).transactionId,\n type: sending.chainId === receiving.chainId ? 'swap' : 'cross',\n action: {\n fromChainId: sending.chainId,\n fromAmount: sending.amount ?? '',\n fromToken: sending.token,\n toChainId: receiving.chainId,\n toToken: receiving.token,\n slippage: 0,\n fromAddress: (tx as FullStatusData).fromAddress,\n toAddress: (tx as FullStatusData).toAddress,\n },\n estimate: {\n tool: tx.tool,\n fromAmount: sending.amount ?? '',\n toAmount: receiving.amount ?? '',\n toAmountMin: receiving.amount ?? '',\n approvalAddress: '',\n executionDuration: 0,\n },\n tool: tx.tool,\n toolDetails: usedTool,\n },\n ],\n integrator: tx.metadata?.integrator ?? '',\n execution: {\n status: 'DONE', // can be FAILED\n startedAt: sending.timestamp\n ? sending.timestamp * 1000\n : Date.now(),\n actions: buildActionsFromTxHistory(tx),\n fromAmount: sending.amount,\n toAmount: receiving.amount,\n toToken: receiving.token,\n internalTxLink: tx.lifiExplorerLink,\n externalTxLink: tx.bridgeExplorerLink,\n gasCosts: [\n {\n amount: sending.gasAmount,\n amountUSD: sending.gasAmountUSD,\n token: sending.gasToken,\n estimate: '0',\n limit: '0',\n price: '0',\n type: 'SEND',\n },\n ],\n feeCosts,\n },\n },\n ],\n insurance: {\n state: 'NOT_INSURABLE',\n feeAmountUsd: '0',\n },\n },\n }\n\n return routeExecution\n}\n"],"mappings":";;AAaA,MAAM,6BAA6B,OAA0C;CAC3E,MAAM,UAAU,GAAG;CACnB,MAAM,YAAY,GAAG;AAErB,KAAI,CAAC,QAAQ,OAAO,WAAW,CAAC,UAAU,OAAO,QAC/C,QAAO,EAAE;CAGX,MAAM,eACJ,GAAG,WAAW,SAAS,SAAS;CAClC,MAAM,YACJ,iBAAiB,WAAW,kBAAkB;AAEhD,KAAI,QAAQ,YAAY,UAAU,QAChC,QAAO,CACL;EACE,MAAM;EACN,SAAS;EACT,QAAQ;EACR,SAAS,QAAQ;EACjB,QAAQ,QAAQ;EAChB,QAAQ,QAAQ;EAChB;EACA,kBAAkB;EAC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B;MACpB;KACD,MAAM,GAAG;KACT,aAAa;KACd,CACF;IACD,YAAY,GAAG,UAAU,cAAc;IACvC,WAAW;KACT,QAAQ;KACR,WAAW,QAAQ,YACf,QAAQ,YAAY,MACpB,KAAK,KAAK;KACd,SAAS,0BAA0B,GAAG;KACtC,YAAY,QAAQ;KACpB,UAAU,UAAU;KACpB,SAAS,UAAU;KACnB,gBAAgB,GAAG;KACnB,gBAAgB,GAAG;KACnB,UAAU,CACR;MACE,QAAQ,QAAQ;MAChB,WAAW,QAAQ;MACnB,OAAO,QAAQ;MACf,UAAU;MACV,OAAO;MACP,OAAO;MACP,MAAM;MACP,CACF;KACD;KACD;IACF,CACF;GACD,WAAW;IACT,OAAO;IACP,cAAc;IACf;GACF;EACF"}
|
|
1
|
+
{"version":3,"file":"converters.js","names":[],"sources":["../../../src/utils/converters.ts"],"sourcesContent":["import type {\n ExecutionAction,\n ExecutionActionStatus,\n ExtendedTransactionInfo,\n FeeCost,\n FullStatusData,\n Substatus,\n TokenAmount,\n ToolsResponse,\n} from '@lifi/sdk'\nimport type { RouteExecution } from '../stores/routes/types.js'\nimport { formatTokenPrice } from './format.js'\n\nconst buildActionsFromTxHistory = (tx: FullStatusData): ExecutionAction[] => {\n const sending = tx.sending as ExtendedTransactionInfo\n const receiving = tx.receiving as ExtendedTransactionInfo\n\n if (!sending.token?.chainId || !receiving.token?.chainId) {\n return []\n }\n\n const actionStatus: ExecutionActionStatus =\n tx.status === 'DONE' ? 'DONE' : 'FAILED'\n const substatus: Substatus =\n actionStatus === 'FAILED' ? 'UNKNOWN_ERROR' : 'COMPLETED'\n\n if (sending.chainId === receiving.chainId) {\n return [\n {\n type: 'SWAP', // operations on same chain will be swaps\n message: '',\n status: actionStatus,\n chainId: sending.chainId,\n txHash: sending.txHash,\n txLink: sending.txLink,\n substatus,\n substatusMessage: '',\n },\n ]\n }\n\n const actions: ExecutionAction[] = [\n {\n type: 'CROSS_CHAIN', // first step of bridging, ignoring the approvals\n message: '',\n status: actionStatus, // can be FAILED\n chainId: sending.chainId,\n txHash: sending.txHash,\n txLink: sending.txLink,\n },\n {\n type: 'RECEIVING_CHAIN', // final step of bridging, post swaps\n message: '',\n status: actionStatus,\n substatus,\n substatusMessage: '',\n chainId: receiving.chainId,\n txHash: receiving.txHash,\n txLink: receiving.txLink,\n },\n ]\n\n return actions\n}\n\nexport const buildRouteFromTxHistory = (\n tx: FullStatusData,\n tools?: ToolsResponse\n): RouteExecution | undefined => {\n const sending = tx.sending as ExtendedTransactionInfo\n const receiving = tx.receiving as ExtendedTransactionInfo\n\n if (!sending.token?.chainId || !receiving.token?.chainId) {\n return\n }\n\n let usedTool = tx.sending.includedSteps?.find(\n (step) => step.toolDetails.key === tx.tool\n )?.toolDetails\n\n if (!usedTool) {\n const selectedBridge = tools?.bridges.find(\n (bridge) => bridge.key === tx.tool\n )\n\n const selectedExchange = tools?.exchanges.find(\n (exchange) => exchange.key === tx.tool\n )\n usedTool = {\n key: tx.tool,\n name: selectedBridge?.name ?? selectedExchange?.name ?? tx.tool,\n logoURI: selectedBridge?.logoURI ?? selectedExchange?.logoURI ?? '',\n }\n }\n\n const fromToken: TokenAmount = {\n ...sending.token,\n amount: BigInt(sending.amount ?? 0),\n }\n\n const toToken: TokenAmount = {\n ...receiving.token,\n amount: BigInt(receiving.amount ?? 0),\n }\n\n const sendingValue = sending.value ? BigInt(sending.value) : 0n\n const sendingFeeAmount =\n sending.gasToken.address === sending.token.address && sending.amount\n ? sendingValue - BigInt(sending.amount)\n : sendingValue\n const sendingFeeAmountUsd =\n sending.gasToken.priceUSD && sendingFeeAmount\n ? formatTokenPrice(\n sendingFeeAmount,\n sending.gasToken.priceUSD,\n sending.gasToken.decimals\n )\n : 0\n\n const feeCosts: FeeCost[] | undefined = sendingFeeAmount\n ? [\n {\n amount: sendingFeeAmount.toString(),\n amountUSD: sendingFeeAmountUsd.toFixed(2),\n token: sending.gasToken,\n included: false,\n // Not used\n description: '',\n name: '',\n percentage: '',\n },\n ]\n : undefined\n\n const routeExecution: RouteExecution = {\n status: 1,\n route: {\n id: (tx as FullStatusData).transactionId,\n fromAddress: (tx as FullStatusData).fromAddress,\n toAddress: (tx as FullStatusData).toAddress,\n fromChainId: sending.chainId,\n fromAmount: sending.amount ?? '',\n fromAmountUSD: sending.amountUSD ?? '',\n toAmount: receiving.amount ?? '',\n toAmountMin: receiving.amount ?? '',\n toAmountUSD: receiving.amountUSD ?? '',\n toChainId: receiving.chainId,\n fromToken,\n toToken,\n gasCostUSD: sending.gasAmountUSD,\n steps: [\n {\n id: (tx as FullStatusData).transactionId,\n type: 'lifi',\n tool: tx.tool,\n toolDetails: usedTool,\n action: {\n fromToken: sending.token,\n fromAmount: sending.amount ?? '',\n fromChainId: sending.chainId,\n fromAddress: (tx as FullStatusData).fromAddress,\n toToken: receiving.token,\n toChainId: receiving.chainId,\n toAddress: (tx as FullStatusData).toAddress,\n slippage: 0,\n },\n estimate: {\n tool: tx.tool,\n approvalAddress: '',\n fromAmount: sending.amount ?? '',\n fromAmountUSD: sending.amountUSD ?? '',\n toAmountMin: receiving.amount ?? '',\n toAmount: receiving.amount ?? '',\n toAmountUSD: receiving.amountUSD ?? '',\n executionDuration: 0,\n },\n includedSteps: [\n {\n id: (tx as FullStatusData).transactionId,\n type: sending.chainId === receiving.chainId ? 'swap' : 'cross',\n action: {\n fromChainId: sending.chainId,\n fromAmount: sending.amount ?? '',\n fromToken: sending.token,\n toChainId: receiving.chainId,\n toToken: receiving.token,\n slippage: 0,\n fromAddress: (tx as FullStatusData).fromAddress,\n toAddress: (tx as FullStatusData).toAddress,\n },\n estimate: {\n tool: tx.tool,\n fromAmount: sending.amount ?? '',\n toAmount: receiving.amount ?? '',\n toAmountMin: receiving.amount ?? '',\n approvalAddress: '',\n executionDuration: 0,\n },\n tool: tx.tool,\n toolDetails: usedTool,\n },\n ],\n integrator: tx.metadata?.integrator ?? '',\n execution: {\n status: 'DONE', // can be FAILED\n startedAt: sending.timestamp\n ? sending.timestamp * 1000\n : Date.now(),\n actions: buildActionsFromTxHistory(tx),\n fromAmount: sending.amount,\n toAmount: receiving.amount,\n toToken: receiving.token,\n internalTxLink: tx.lifiExplorerLink,\n externalTxLink: tx.bridgeExplorerLink,\n gasCosts: [\n {\n amount: sending.gasAmount,\n amountUSD: sending.gasAmountUSD,\n token: sending.gasToken,\n estimate: '0',\n limit: '0',\n price: '0',\n type: 'SEND',\n },\n ],\n feeCosts,\n },\n },\n ],\n insurance: {\n state: 'NOT_INSURABLE',\n feeAmountUsd: '0',\n },\n },\n }\n\n return routeExecution\n}\n"],"mappings":";;AAaA,MAAM,6BAA6B,OAA0C;CAC3E,MAAM,UAAU,GAAG;CACnB,MAAM,YAAY,GAAG;AAErB,KAAI,CAAC,QAAQ,OAAO,WAAW,CAAC,UAAU,OAAO,QAC/C,QAAO,EAAE;CAGX,MAAM,eACJ,GAAG,WAAW,SAAS,SAAS;CAClC,MAAM,YACJ,iBAAiB,WAAW,kBAAkB;AAEhD,KAAI,QAAQ,YAAY,UAAU,QAChC,QAAO,CACL;EACE,MAAM;EACN,SAAS;EACT,QAAQ;EACR,SAAS,QAAQ;EACjB,QAAQ,QAAQ;EAChB,QAAQ,QAAQ;EAChB;EACA,kBAAkB;EACnB,CACF;AAwBH,QAAO,CApBL;EACE,MAAM;EACN,SAAS;EACT,QAAQ;EACR,SAAS,QAAQ;EACjB,QAAQ,QAAQ;EAChB,QAAQ,QAAQ;EACjB,EACD;EACE,MAAM;EACN,SAAS;EACT,QAAQ;EACR;EACA,kBAAkB;EAClB,SAAS,UAAU;EACnB,QAAQ,UAAU;EAClB,QAAQ,UAAU;EACnB,CAGW;;AAGhB,MAAa,2BACX,IACA,UAC+B;CAC/B,MAAM,UAAU,GAAG;CACnB,MAAM,YAAY,GAAG;AAErB,KAAI,CAAC,QAAQ,OAAO,WAAW,CAAC,UAAU,OAAO,QAC/C;CAGF,IAAI,WAAW,GAAG,QAAQ,eAAe,MACtC,SAAS,KAAK,YAAY,QAAQ,GAAG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}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","names":[],"sources":["../../../src/utils/format.ts"],"sourcesContent":["import { formatUnits } from '@lifi/sdk'\n\nexport const usdDecimals = 2\n\n/**\n * Format token amount to at least 6 decimals.\n * @param amount amount to format.\n * @returns formatted amount.\n */\nexport function formatTokenAmount(\n amount: bigint | undefined,\n decimals: number\n): string {\n const formattedAmount = amount ? formatUnits(amount, decimals) : '0'\n const parsedAmount = Number.parseFloat(formattedAmount)\n if (!parsedAmount || Number.isNaN(Number(formattedAmount))) {\n return '0'\n }\n\n return formattedAmount\n}\n\nexport function formatSlippage(\n slippage = '',\n defaultValue = '',\n returnInitial = false\n): string {\n if (!slippage) {\n return slippage\n }\n const parsedSlippage = Number.parseFloat(slippage)\n if (Number.isNaN(Number(slippage)) && !Number.isNaN(parsedSlippage)) {\n return parsedSlippage.toString()\n }\n if (Number.isNaN(parsedSlippage)) {\n return defaultValue\n }\n if (parsedSlippage >= 100) {\n return '100'\n }\n if (parsedSlippage < 0) {\n return Math.abs(parsedSlippage).toString()\n }\n if (returnInitial) {\n return slippage\n }\n return parsedSlippage.toString()\n}\n\n/**\n * Formats a user input amount string, normalizing it and optionally limiting decimal places.\n * @param amount - The amount string to format (e.g., '123.45', '1,23', '0..')\n * @param decimals - Maximum number of decimal places to allow. If null, no limit is applied.\n * @param returnInitial - If true, preserves the input format during typing (e.g., keeps trailing dots,\n * preserves leading zeros, keeps negative signs). If false (default), cleans up the\n * format on blur (removes leading/trailing zeros, removes negative signs).\n * @returns The formatted amount string, or empty string for invalid input.\n */\nexport function formatInputAmount(\n amount: string,\n decimals: number | null = null,\n returnInitial: boolean = false\n): string {\n if (!amount) {\n return amount\n }\n\n // Replace commas with dots\n let formattedAmount = amount.trim().replaceAll(',', '.')\n\n // Keep only the first dot, remove all subsequent dots\n const dotIndex = formattedAmount.indexOf('.')\n if (dotIndex !== -1) {\n formattedAmount = `${formattedAmount.slice(0, dotIndex + 1)}${formattedAmount.slice(dotIndex + 1).replaceAll('.', '')}`\n }\n\n // If the amount starts with a dot, prepend 0\n if (\n (!returnInitial && formattedAmount.startsWith('.')) ||\n formattedAmount === '.'\n ) {\n formattedAmount = `0${formattedAmount}`\n }\n\n // Parse the valid part of the amount\n const parsedAmount = Number.parseFloat(formattedAmount)\n if (Number.isNaN(Number(formattedAmount)) && !Number.isNaN(parsedAmount)) {\n formattedAmount = parsedAmount.toString()\n }\n if (Number.isNaN(Math.abs(Number(formattedAmount)))) {\n return ''\n }\n\n // Split and limit decimals\n let [integer, fraction = ''] = formattedAmount.split('.')\n if (decimals !== null && fraction.length > decimals) {\n fraction = fraction.slice(0, decimals)\n }\n\n if (returnInitial) {\n if (!fraction) {\n return formattedAmount\n }\n return `${integer}${fraction ? `.${fraction}` : ''}`\n }\n\n // Remove leading zeros and minus sign\n integer = integer.replace(/^0+|-/, '')\n // Remove trailing zeros\n fraction = fraction.replace(/(0+)$/, '')\n\n return `${integer || (fraction ? '0' : '')}${fraction ? `.${fraction}` : ''}`\n}\n\nexport function formatTokenPrice(\n amount?: string | bigint,\n price?: string,\n decimals?: number\n): number {\n if (!amount || !price) {\n return 0\n }\n\n const formattedAmount =\n typeof amount === 'bigint' && decimals !== undefined\n ? formatUnits(amount, decimals)\n : amount.toString()\n\n if (Number.isNaN(Number(formattedAmount)) || Number.isNaN(Number(price))) {\n return 0\n }\n return Number.parseFloat(formattedAmount) * Number.parseFloat(price)\n}\n\n/**\n * Formatter for price value to token amount\n */\nconst formatter = new Intl.NumberFormat('en', {\n notation: 'standard',\n roundingPriority: 'morePrecision',\n maximumSignificantDigits: 20,\n maximumFractionDigits: 20,\n useGrouping: false,\n})\n\n/**\n * Convert price value to token amount\n */\nexport function priceToTokenAmount(\n priceValue: string,\n priceUSD?: string\n): string {\n if (!priceValue || !priceUSD) {\n return '0'\n }\n\n const numericPriceValue = Number.parseFloat(priceValue)\n const numericPrice = Number.parseFloat(priceUSD)\n\n if (\n Number.isNaN(numericPriceValue) ||\n Number.isNaN(numericPrice) ||\n !numericPrice\n ) {\n return '0'\n }\n\n return formatter.format(numericPriceValue / numericPrice)\n}\n\nconst units = [\n ['day', 86400],\n ['hour', 3600],\n ['minute', 60],\n ['second', 1],\n] as const\n\nexport function formatDuration(seconds: number, locale: string): string {\n const match = units.find(([, v]) => seconds >= v)\n const amount = match ? Math.floor(seconds / match[1]) : 0\n const unit = match?.[0] ?? 'second'\n\n return amount.toLocaleString(locale, {\n style: 'unit',\n unit,\n unitDisplay: 'narrow',\n })\n}\n\nexport function wrapLongWords(text: string): string {\n return text.replace(\n /\\S{32,}/g,\n (word) => `${word.slice(0, 8)}...${word.slice(-4)}`\n )\n}\n"],"mappings":";;AAEA,MAAa,cAAc;;;;;;AAO3B,SAAgB,kBACd,QACA,UACQ;CACR,MAAM,kBAAkB,SAAS,YAAY,QAAQ,SAAS,GAAG;AAEjE,KAAI,CADiB,OAAO,WAAW,
|
|
1
|
+
{"version":3,"file":"format.js","names":[],"sources":["../../../src/utils/format.ts"],"sourcesContent":["import { formatUnits } from '@lifi/sdk'\n\nexport const usdDecimals = 2\n\n/**\n * Format token amount to at least 6 decimals.\n * @param amount amount to format.\n * @returns formatted amount.\n */\nexport function formatTokenAmount(\n amount: bigint | undefined,\n decimals: number\n): string {\n const formattedAmount = amount ? formatUnits(amount, decimals) : '0'\n const parsedAmount = Number.parseFloat(formattedAmount)\n if (!parsedAmount || Number.isNaN(Number(formattedAmount))) {\n return '0'\n }\n\n return formattedAmount\n}\n\nexport function formatSlippage(\n slippage = '',\n defaultValue = '',\n returnInitial = false\n): string {\n if (!slippage) {\n return slippage\n }\n const parsedSlippage = Number.parseFloat(slippage)\n if (Number.isNaN(Number(slippage)) && !Number.isNaN(parsedSlippage)) {\n return parsedSlippage.toString()\n }\n if (Number.isNaN(parsedSlippage)) {\n return defaultValue\n }\n if (parsedSlippage >= 100) {\n return '100'\n }\n if (parsedSlippage < 0) {\n return Math.abs(parsedSlippage).toString()\n }\n if (returnInitial) {\n return slippage\n }\n return parsedSlippage.toString()\n}\n\n/**\n * Formats a user input amount string, normalizing it and optionally limiting decimal places.\n * @param amount - The amount string to format (e.g., '123.45', '1,23', '0..')\n * @param decimals - Maximum number of decimal places to allow. If null, no limit is applied.\n * @param returnInitial - If true, preserves the input format during typing (e.g., keeps trailing dots,\n * preserves leading zeros, keeps negative signs). If false (default), cleans up the\n * format on blur (removes leading/trailing zeros, removes negative signs).\n * @returns The formatted amount string, or empty string for invalid input.\n */\nexport function formatInputAmount(\n amount: string,\n decimals: number | null = null,\n returnInitial: boolean = false\n): string {\n if (!amount) {\n return amount\n }\n\n // Replace commas with dots\n let formattedAmount = amount.trim().replaceAll(',', '.')\n\n // Keep only the first dot, remove all subsequent dots\n const dotIndex = formattedAmount.indexOf('.')\n if (dotIndex !== -1) {\n formattedAmount = `${formattedAmount.slice(0, dotIndex + 1)}${formattedAmount.slice(dotIndex + 1).replaceAll('.', '')}`\n }\n\n // If the amount starts with a dot, prepend 0\n if (\n (!returnInitial && formattedAmount.startsWith('.')) ||\n formattedAmount === '.'\n ) {\n formattedAmount = `0${formattedAmount}`\n }\n\n // Parse the valid part of the amount\n const parsedAmount = Number.parseFloat(formattedAmount)\n if (Number.isNaN(Number(formattedAmount)) && !Number.isNaN(parsedAmount)) {\n formattedAmount = parsedAmount.toString()\n }\n if (Number.isNaN(Math.abs(Number(formattedAmount)))) {\n return ''\n }\n\n // Split and limit decimals\n let [integer, fraction = ''] = formattedAmount.split('.')\n if (decimals !== null && fraction.length > decimals) {\n fraction = fraction.slice(0, decimals)\n }\n\n if (returnInitial) {\n if (!fraction) {\n return formattedAmount\n }\n return `${integer}${fraction ? `.${fraction}` : ''}`\n }\n\n // Remove leading zeros and minus sign\n integer = integer.replace(/^0+|-/, '')\n // Remove trailing zeros\n fraction = fraction.replace(/(0+)$/, '')\n\n return `${integer || (fraction ? '0' : '')}${fraction ? `.${fraction}` : ''}`\n}\n\nexport function formatTokenPrice(\n amount?: string | bigint,\n price?: string,\n decimals?: number\n): number {\n if (!amount || !price) {\n return 0\n }\n\n const formattedAmount =\n typeof amount === 'bigint' && decimals !== undefined\n ? formatUnits(amount, decimals)\n : amount.toString()\n\n if (Number.isNaN(Number(formattedAmount)) || Number.isNaN(Number(price))) {\n return 0\n }\n return Number.parseFloat(formattedAmount) * Number.parseFloat(price)\n}\n\n/**\n * Formatter for price value to token amount\n */\nconst formatter = new Intl.NumberFormat('en', {\n notation: 'standard',\n roundingPriority: 'morePrecision',\n maximumSignificantDigits: 20,\n maximumFractionDigits: 20,\n useGrouping: false,\n})\n\n/**\n * Convert price value to token amount\n */\nexport function priceToTokenAmount(\n priceValue: string,\n priceUSD?: string\n): string {\n if (!priceValue || !priceUSD) {\n return '0'\n }\n\n const numericPriceValue = Number.parseFloat(priceValue)\n const numericPrice = Number.parseFloat(priceUSD)\n\n if (\n Number.isNaN(numericPriceValue) ||\n Number.isNaN(numericPrice) ||\n !numericPrice\n ) {\n return '0'\n }\n\n return formatter.format(numericPriceValue / numericPrice)\n}\n\nconst units = [\n ['day', 86400],\n ['hour', 3600],\n ['minute', 60],\n ['second', 1],\n] as const\n\nexport function formatDuration(seconds: number, locale: string): string {\n const match = units.find(([, v]) => seconds >= v)\n const amount = match ? Math.floor(seconds / match[1]) : 0\n const unit = match?.[0] ?? 'second'\n\n return amount.toLocaleString(locale, {\n style: 'unit',\n unit,\n unitDisplay: 'narrow',\n })\n}\n\nexport function wrapLongWords(text: string): string {\n return text.replace(\n /\\S{32,}/g,\n (word) => `${word.slice(0, 8)}...${word.slice(-4)}`\n )\n}\n"],"mappings":";;AAEA,MAAa,cAAc;;;;;;AAO3B,SAAgB,kBACd,QACA,UACQ;CACR,MAAM,kBAAkB,SAAS,YAAY,QAAQ,SAAS,GAAG;AAEjE,KAAI,CADiB,OAAO,WAAW,gBACtB,IAAI,OAAO,MAAM,OAAO,gBAAgB,CAAC,CACxD,QAAO;AAGT,QAAO;;AAGT,SAAgB,eACd,WAAW,IACX,eAAe,IACf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,KAAK,QACV,aACC,SAAS,GAAG,KAAK,MAAM,GAAG,EAAE,CAAC,KAAK,KAAK,MAAM,GAAG,GAClD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timer.js","names":[],"sources":["../../../src/utils/timer.ts"],"sourcesContent":["export const formatTimer = ({\n days = 0,\n hours = 0,\n minutes = 0,\n seconds = 0,\n locale = 'en',\n}: {\n days?: number\n hours?: number\n minutes?: number\n seconds?: number\n locale?: string\n}): string => {\n if (typeof (Intl as any).DurationFormat === 'function') {\n const time = new (Intl as any).DurationFormat(locale, {\n style: 'digital',\n hours: '2-digit',\n hoursDisplay: 'auto',\n }).format({\n days,\n hours,\n minutes,\n seconds,\n })\n // This handles a fixed bug with Webkit, and Safari\n // https://github.com/WebKit/WebKit/pull/38357\n // https://developer.apple.com/documentation/safari-release-notes/safari-18_4-release-notes#JavaScript\n //\n // Since most users haven't updated their browsers yet, they would have this issue\n // it should be safe to remove the check after a while.\n return time.replace(/^:, /, '')\n }\n\n return ''\n}\n"],"mappings":";AAAA,MAAa,eAAe,EAC1B,OAAO,GACP,QAAQ,GACR,UAAU,GACV,UAAU,GACV,SAAS,WAOG;AACZ,KAAI,OAAQ,KAAa,mBAAmB,WAiB1C,QAhBa,IAAK,KAAa,eAAe,QAAQ;EACpD,OAAO;EACP,OAAO;EACP,cAAc;EACf,CAAC,CAAC,OAAO;EACR;EACA;EACA;EACA;EACD,CAAC,
|
|
1
|
+
{"version":3,"file":"timer.js","names":[],"sources":["../../../src/utils/timer.ts"],"sourcesContent":["export const formatTimer = ({\n days = 0,\n hours = 0,\n minutes = 0,\n seconds = 0,\n locale = 'en',\n}: {\n days?: number\n hours?: number\n minutes?: number\n seconds?: number\n locale?: string\n}): string => {\n if (typeof (Intl as any).DurationFormat === 'function') {\n const time = new (Intl as any).DurationFormat(locale, {\n style: 'digital',\n hours: '2-digit',\n hoursDisplay: 'auto',\n }).format({\n days,\n hours,\n minutes,\n seconds,\n })\n // This handles a fixed bug with Webkit, and Safari\n // https://github.com/WebKit/WebKit/pull/38357\n // https://developer.apple.com/documentation/safari-release-notes/safari-18_4-release-notes#JavaScript\n //\n // Since most users haven't updated their browsers yet, they would have this issue\n // it should be safe to remove the check after a while.\n return time.replace(/^:, /, '')\n }\n\n return ''\n}\n"],"mappings":";AAAA,MAAa,eAAe,EAC1B,OAAO,GACP,QAAQ,GACR,UAAU,GACV,UAAU,GACV,SAAS,WAOG;AACZ,KAAI,OAAQ,KAAa,mBAAmB,WAiB1C,QAhBa,IAAK,KAAa,eAAe,QAAQ;EACpD,OAAO;EACP,OAAO;EACP,cAAc;EACf,CAAC,CAAC,OAAO;EACR;EACA;EACA;EACA;EACD,CAOU,CAAC,QAAQ,QAAQ,GAAG;AAGjC,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","names":[],"sources":["../../../src/utils/token.ts"],"sourcesContent":["import type { BaseToken, Token, TokenExtended } from '@lifi/sdk'\nimport type { FormType } from '../stores/form/types.js'\nimport type { TokensByChain } from '../types/token.js'\nimport type { WidgetChains, WidgetTokens } from '../types/widget.js'\nimport { getConfigItemSets, isFormItemAllowed } from './item.js'\n\n/**\n * Merges verified tokens with search tokens.\n * Verified tokens take priority - search tokens are only added if they don't already exist.\n */\nexport const mergeVerifiedWithSearchTokens = (\n verifiedTokens?: TokensByChain,\n searchTokens?: TokensByChain\n): TokensByChain | undefined => {\n if (!verifiedTokens) {\n return searchTokens\n }\n if (!searchTokens) {\n return verifiedTokens\n }\n\n const result = { ...verifiedTokens }\n\n for (const [chainId, tokens] of Object.entries(searchTokens)) {\n const chainIdNum = Number(chainId)\n const existingTokens = result[chainIdNum] || []\n const existingAddresses = new Set(\n existingTokens.map((t) => t.address.toLowerCase())\n )\n\n const newTokens = tokens.filter(\n (t) => !existingAddresses.has(t.address.toLowerCase())\n )\n\n if (newTokens.length) {\n result[chainIdNum] = [...existingTokens, ...newTokens]\n }\n }\n\n return result\n}\n\n/**\n * Updates a token in the cache by chainId and address.\n * Returns a new cache object with the token updated, or the original if not found.\n */\nexport const updateTokenInCache = (\n data: TokensByChain | undefined,\n token: Token\n): TokensByChain | undefined => {\n if (!data) {\n return data\n }\n const chainTokens = data[token.chainId]\n if (!chainTokens) {\n return data\n }\n const index = chainTokens.findIndex((t) => t.address === token.address)\n if (index < 0) {\n return data\n }\n return {\n ...data,\n [token.chainId]: chainTokens.map((t, i) =>\n i === index ? { ...t, ...token } : t\n ),\n }\n}\n\nexport const filterAllowedTokens = (\n dataTokens: { [chainId: number]: TokenExtended[] } | undefined,\n configTokens?: WidgetTokens,\n chainsConfig?: WidgetChains,\n formType?: FormType\n): { [chainId: number]: TokenExtended[] } | undefined => {\n if (!dataTokens) {\n return\n }\n\n const includedTokens = configTokens?.include || []\n const allChainIds = Array.from(\n new Set([\n ...includedTokens.map((t) => t.chainId),\n ...Object.keys(dataTokens),\n ])\n ).map((chainId) => Number(chainId))\n\n const configChainIdsSet = getConfigItemSets(\n chainsConfig,\n (chainIds: number[]) => new Set(chainIds),\n formType\n )\n\n const allowedChainIds = configChainIdsSet\n ? allChainIds.filter((chainId) =>\n isFormItemAllowed(chainId, configChainIdsSet, formType)\n )\n : allChainIds\n\n const allowedTokensByChain: { [chainId: number]: TokenExtended[] } = {}\n for (const chainId of allowedChainIds) {\n const chainTokens = [\n ...dataTokens[chainId],\n ...includedTokens.filter((t) => Number(t.chainId) === chainId),\n ]\n\n const allowedAddresses = getConfigItemSets(\n configTokens,\n (tokens: BaseToken[]) =>\n new Set(\n tokens\n .filter((t) => Number(t.chainId) === chainId)\n .map((t) => t.address.toLowerCase())\n ),\n formType\n )\n\n const filtered = chainTokens.filter((token) =>\n isFormItemAllowed(token, allowedAddresses, formType, (t) =>\n t.address.toLowerCase()\n )\n )\n\n allowedTokensByChain[chainId] = filtered\n }\n\n return allowedTokensByChain\n}\n"],"mappings":";;;;;;AAUA,MAAa,iCACX,gBACA,iBAC8B;AAC9B,KAAI,CAAC,eACH,QA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M,uBAA+D,EAAE;AACvE,MAAK,MAAM,WAAW,iBAAiB;EACrC,MAAM,cAAc,CAClB,GAAG,WAAW,UACd,GAAG,eAAe,QAAQ,MAAM,OAAO,EAAE,QAAQ,KAAK,QAAQ,CAC/D;EAED,MAAM,mBAAmB,kBACvB,eACC,WACC,IAAI,IACF,OACG,QAAQ,MAAM,OAAO,EAAE,QAAQ,KAAK,QAAQ,CAC5C,KAAK,MAAM,EAAE,QAAQ,aAAa,CAAC,CACvC,EACH,SACD;AAQD,uBAAqB,WANJ,YAAY,QAAQ,UACnC,kBAAkB,OAAO,kBAAkB,WAAW,MACpD,EAAE,QAAQ,aAAa,CACxB,
|
|
1
|
+
{"version":3,"file":"token.js","names":[],"sources":["../../../src/utils/token.ts"],"sourcesContent":["import type { BaseToken, Token, TokenExtended } from '@lifi/sdk'\nimport type { FormType } from '../stores/form/types.js'\nimport type { TokensByChain } from '../types/token.js'\nimport type { WidgetChains, WidgetTokens } from '../types/widget.js'\nimport { getConfigItemSets, isFormItemAllowed } from './item.js'\n\n/**\n * Merges verified tokens with search tokens.\n * Verified tokens take priority - search tokens are only added if they don't already exist.\n */\nexport const mergeVerifiedWithSearchTokens = (\n verifiedTokens?: TokensByChain,\n searchTokens?: TokensByChain\n): TokensByChain | undefined => {\n if (!verifiedTokens) {\n return searchTokens\n }\n if (!searchTokens) {\n return verifiedTokens\n }\n\n const result = { ...verifiedTokens }\n\n for (const [chainId, tokens] of Object.entries(searchTokens)) {\n const chainIdNum = Number(chainId)\n const existingTokens = result[chainIdNum] || []\n const existingAddresses = new Set(\n existingTokens.map((t) => t.address.toLowerCase())\n )\n\n const newTokens = tokens.filter(\n (t) => !existingAddresses.has(t.address.toLowerCase())\n )\n\n if (newTokens.length) {\n result[chainIdNum] = [...existingTokens, ...newTokens]\n }\n }\n\n return result\n}\n\n/**\n * Updates a token in the cache by chainId and address.\n * Returns a new cache object with the token updated, or the original if not found.\n */\nexport const updateTokenInCache = (\n data: TokensByChain | undefined,\n token: Token\n): TokensByChain | undefined => {\n if (!data) {\n return data\n }\n const chainTokens = data[token.chainId]\n if (!chainTokens) {\n return data\n }\n const index = chainTokens.findIndex((t) => t.address === token.address)\n if (index < 0) {\n return data\n }\n return {\n ...data,\n [token.chainId]: chainTokens.map((t, i) =>\n i === index ? { ...t, ...token } : t\n ),\n }\n}\n\nexport const filterAllowedTokens = (\n dataTokens: { [chainId: number]: TokenExtended[] } | undefined,\n configTokens?: WidgetTokens,\n chainsConfig?: WidgetChains,\n formType?: FormType\n): { [chainId: number]: TokenExtended[] } | undefined => {\n if (!dataTokens) {\n return\n }\n\n const includedTokens = configTokens?.include || []\n const allChainIds = Array.from(\n new Set([\n ...includedTokens.map((t) => t.chainId),\n ...Object.keys(dataTokens),\n ])\n ).map((chainId) => Number(chainId))\n\n const configChainIdsSet = getConfigItemSets(\n chainsConfig,\n (chainIds: number[]) => new Set(chainIds),\n formType\n )\n\n const allowedChainIds = configChainIdsSet\n ? allChainIds.filter((chainId) =>\n isFormItemAllowed(chainId, configChainIdsSet, formType)\n )\n : allChainIds\n\n const allowedTokensByChain: { [chainId: number]: TokenExtended[] } = {}\n for (const chainId of allowedChainIds) {\n const chainTokens = [\n ...dataTokens[chainId],\n ...includedTokens.filter((t) => Number(t.chainId) === chainId),\n ]\n\n const allowedAddresses = getConfigItemSets(\n configTokens,\n (tokens: BaseToken[]) =>\n new Set(\n tokens\n .filter((t) => Number(t.chainId) === chainId)\n .map((t) => t.address.toLowerCase())\n ),\n formType\n )\n\n const filtered = chainTokens.filter((token) =>\n isFormItemAllowed(token, allowedAddresses, formType, (t) =>\n t.address.toLowerCase()\n )\n )\n\n allowedTokensByChain[chainId] = filtered\n }\n\n return allowedTokensByChain\n}\n"],"mappings":";;;;;;AAUA,MAAa,iCACX,gBACA,iBAC8B;AAC9B,KAAI,CAAC,eACH,QAAO;AAET,KAAI,CAAC,aACH,QAAO;CAGT,MAAM,SAAS,EAAE,GAAG,gBAAgB;AAEpC,MAAK,MAAM,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,GAAG,eAAe,QAAQ,MAAM,OAAO,EAAE,QAAQ,KAAK,QAAQ,CAC/D;EAED,MAAM,mBAAmB,kBACvB,eACC,WACC,IAAI,IACF,OACG,QAAQ,MAAM,OAAO,EAAE,QAAQ,KAAK,QAAQ,CAC5C,KAAK,MAAM,EAAE,QAAQ,aAAa,CAAC,CACvC,EACH,SACD;AAQD,uBAAqB,WANJ,YAAY,QAAQ,UACnC,kBAAkB,OAAO,kBAAkB,WAAW,MACpD,EAAE,QAAQ,aAAa,CACxB,CAGqC;;AAG1C,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/widget",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.18",
|
|
4
4
|
"description": "LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -34,21 +34,21 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@emotion/react": "^11.14.0",
|
|
36
36
|
"@emotion/styled": "^11.14.1",
|
|
37
|
-
"@lifi/sdk": "4.0.0-beta.
|
|
37
|
+
"@lifi/sdk": "^4.0.0-beta.8",
|
|
38
38
|
"@mui/icons-material": "^9.0.0",
|
|
39
39
|
"@mui/material": "^9.0.0",
|
|
40
40
|
"@mui/system": "^9.0.0",
|
|
41
|
-
"@tanstack/react-router": "^1.168.
|
|
42
|
-
"@tanstack/react-virtual": "^3.13.
|
|
43
|
-
"i18next": "^26.0.
|
|
41
|
+
"@tanstack/react-router": "^1.168.26",
|
|
42
|
+
"@tanstack/react-virtual": "^3.13.24",
|
|
43
|
+
"i18next": "^26.0.8",
|
|
44
44
|
"microdiff": "^1.5.0",
|
|
45
45
|
"mitt": "^3.0.1",
|
|
46
|
-
"react-i18next": "^17.0.
|
|
46
|
+
"react-i18next": "^17.0.6",
|
|
47
47
|
"react-intersection-observer": "^10.0.3",
|
|
48
48
|
"react-transition-group": "^4.4.5",
|
|
49
49
|
"zustand": "^5.0.12",
|
|
50
|
-
"@lifi/wallet-management": "4.0.0-beta.
|
|
51
|
-
"@lifi/widget-provider": "4.0.0-beta.
|
|
50
|
+
"@lifi/wallet-management": "4.0.0-beta.18",
|
|
51
|
+
"@lifi/widget-provider": "4.0.0-beta.18"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@tanstack/react-query": ">=5.90.0",
|
|
@@ -46,7 +46,7 @@ const chainTypeIcons = [
|
|
|
46
46
|
},
|
|
47
47
|
]
|
|
48
48
|
|
|
49
|
-
const maxChainAvatarsCount =
|
|
49
|
+
const maxChainAvatarsCount = 4
|
|
50
50
|
|
|
51
51
|
export const AllChainsAvatar: React.NamedExoticComponent<AllChainsAvatarProps> =
|
|
52
52
|
memo(({ chains, size }: AllChainsAvatarProps): JSX.Element => {
|
|
@@ -172,7 +172,7 @@ export const SendToWalletButton: React.FC<CardProps> = (props) => {
|
|
|
172
172
|
subheader={headerSubheader}
|
|
173
173
|
selected={!!toAddressFieldValue || disabledToAddress}
|
|
174
174
|
action={
|
|
175
|
-
|
|
175
|
+
toAddressFieldValue && !disabledForChanges ? (
|
|
176
176
|
<CardIconButton onClick={clearSelectedBookmark} size="small">
|
|
177
177
|
<CloseRounded fontSize="inherit" />
|
|
178
178
|
</CardIconButton>
|
package/src/config/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/widget'
|
|
2
|
-
export const version = '4.0.0-beta.
|
|
2
|
+
export const version = '4.0.0-beta.18'
|
|
@@ -7,7 +7,8 @@ import { useAvailableChains } from './useAvailableChains.js'
|
|
|
7
7
|
|
|
8
8
|
export const useActionMessage = (
|
|
9
9
|
step?: LiFiStepExtended,
|
|
10
|
-
action?: ExecutionAction
|
|
10
|
+
action?: ExecutionAction,
|
|
11
|
+
defaultLabelsOnly?: boolean
|
|
11
12
|
): { title?: string; message?: string } => {
|
|
12
13
|
const { subvariant, subvariantOptions } = useWidgetConfig()
|
|
13
14
|
const { t } = useTranslation()
|
|
@@ -27,7 +28,7 @@ export const useActionMessage = (
|
|
|
27
28
|
action.type,
|
|
28
29
|
action.status,
|
|
29
30
|
action.substatus,
|
|
30
|
-
subvariant,
|
|
31
|
-
subvariantOptions
|
|
31
|
+
defaultLabelsOnly ? undefined : subvariant,
|
|
32
|
+
defaultLabelsOnly ? undefined : subvariantOptions
|
|
32
33
|
)
|
|
33
34
|
}
|
|
@@ -139,7 +139,6 @@ export const useRouteExecution = ({
|
|
|
139
139
|
return executeRoute(sdkClient, routeExecution.route, {
|
|
140
140
|
updateRouteHook,
|
|
141
141
|
acceptExchangeRateUpdateHook,
|
|
142
|
-
infiniteApproval: false,
|
|
143
142
|
executeInBackground,
|
|
144
143
|
...sdkClient.config?.executionOptions,
|
|
145
144
|
})
|
|
@@ -164,7 +163,6 @@ export const useRouteExecution = ({
|
|
|
164
163
|
return resumeRoute(sdkClient, resumedRoute ?? routeExecution.route, {
|
|
165
164
|
updateRouteHook,
|
|
166
165
|
acceptExchangeRateUpdateHook,
|
|
167
|
-
infiniteApproval: false,
|
|
168
166
|
executeInBackground,
|
|
169
167
|
})
|
|
170
168
|
},
|
|
@@ -10,8 +10,9 @@ export const StepActionRow: React.FC<{
|
|
|
10
10
|
step: LiFiStepExtended
|
|
11
11
|
action: ExecutionAction
|
|
12
12
|
href: string
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
defaultLabelsOnly?: boolean
|
|
14
|
+
}> = ({ step, action, href, defaultLabelsOnly }) => {
|
|
15
|
+
const { title } = useActionMessage(step, action, defaultLabelsOnly)
|
|
15
16
|
const isFailed = action?.status === 'FAILED'
|
|
16
17
|
return (
|
|
17
18
|
<ActionRow
|
|
@@ -46,20 +46,27 @@ export const StepActionsList: React.FC<StepActionsListProps> = ({
|
|
|
46
46
|
return null
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
const lastStepIndex = stepRows.length - 1
|
|
50
|
+
|
|
49
51
|
return (
|
|
50
52
|
<TransactionList>
|
|
51
|
-
{stepRows.map(({ step, rows }) =>
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
{stepRows.map(({ step, rows }, stepIndex) => {
|
|
54
|
+
const lastRowIndex = rows.length - 1
|
|
55
|
+
const isLastStep = stepIndex === lastStepIndex
|
|
56
|
+
return (
|
|
57
|
+
<TransactionList key={step.id}>
|
|
58
|
+
{rows.map(({ action, href }, rowIndex) => (
|
|
59
|
+
<StepActionRow
|
|
60
|
+
key={rowIndex}
|
|
61
|
+
step={step}
|
|
62
|
+
action={action!}
|
|
63
|
+
href={href!}
|
|
64
|
+
defaultLabelsOnly={!(isLastStep && rowIndex === lastRowIndex)}
|
|
65
|
+
/>
|
|
66
|
+
))}
|
|
67
|
+
</TransactionList>
|
|
68
|
+
)
|
|
69
|
+
})}
|
|
63
70
|
{toAddress ? (
|
|
64
71
|
<SentToWalletRow toAddress={toAddress} toChainId={route.toChainId} />
|
|
65
72
|
) : null}
|