@lifi/widget 3.24.0-alpha.0 → 3.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +10 -6
  3. package/dist/esm/components/Header/Header.style.js +1 -0
  4. package/dist/esm/components/Header/Header.style.js.map +1 -1
  5. package/dist/esm/components/RouteCard/RouteCard.js +3 -3
  6. package/dist/esm/components/RouteCard/RouteCard.js.map +1 -1
  7. package/dist/esm/components/RouteCard/RouteCardEssentials.js +5 -5
  8. package/dist/esm/components/RouteCard/RouteCardEssentials.js.map +1 -1
  9. package/dist/esm/components/Step/CircularProgress.style.js +22 -17
  10. package/dist/esm/components/Step/CircularProgress.style.js.map +1 -1
  11. package/dist/esm/components/StepActions/StepActions.js +3 -3
  12. package/dist/esm/components/TokenList/TokenList.js +2 -2
  13. package/dist/esm/components/TokenList/TokenList.js.map +1 -1
  14. package/dist/esm/components/TransactionDetails.js +7 -7
  15. package/dist/esm/components/TransactionDetails.js.map +1 -1
  16. package/dist/esm/config/version.d.ts +1 -1
  17. package/dist/esm/config/version.js +1 -1
  18. package/dist/esm/config/version.js.map +1 -1
  19. package/dist/esm/hooks/useTokenBalances.d.ts +2 -1
  20. package/dist/esm/hooks/useTokenBalances.js +2 -2
  21. package/dist/esm/hooks/useTokenBalances.js.map +1 -1
  22. package/dist/esm/hooks/useTokenSearch.d.ts +2 -1
  23. package/dist/esm/hooks/useTokenSearch.js +7 -2
  24. package/dist/esm/hooks/useTokenSearch.js.map +1 -1
  25. package/dist/esm/hooks/useTokens.d.ts +2 -1
  26. package/dist/esm/hooks/useTokens.js +6 -13
  27. package/dist/esm/hooks/useTokens.js.map +1 -1
  28. package/dist/esm/index.d.ts +1 -0
  29. package/dist/esm/index.js +1 -0
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/pages/TransactionPage/StatusBottomSheet.style.js +18 -7
  32. package/dist/esm/pages/TransactionPage/StatusBottomSheet.style.js.map +1 -1
  33. package/dist/esm/pages/TransactionPage/TokenValueBottomSheet.js +4 -4
  34. package/dist/esm/pages/TransactionPage/TokenValueBottomSheet.js.map +1 -1
  35. package/dist/esm/types/widget.d.ts +2 -0
  36. package/dist/esm/utils/item.d.ts +7 -2
  37. package/dist/esm/utils/item.js +10 -3
  38. package/dist/esm/utils/item.js.map +1 -1
  39. package/package.json +14 -14
  40. package/package.json.tmp +13 -13
  41. package/src/components/Header/Header.style.ts +1 -0
  42. package/src/components/RouteCard/RouteCard.tsx +3 -3
  43. package/src/components/RouteCard/RouteCardEssentials.tsx +5 -5
  44. package/src/components/Step/CircularProgress.style.tsx +25 -17
  45. package/src/components/StepActions/StepActions.tsx +3 -3
  46. package/src/components/TokenList/TokenList.tsx +7 -2
  47. package/src/components/TransactionDetails.tsx +8 -8
  48. package/src/config/version.ts +1 -1
  49. package/src/hooks/useTokenBalances.ts +9 -3
  50. package/src/hooks/useTokenSearch.ts +11 -2
  51. package/src/hooks/useTokens.ts +10 -21
  52. package/src/index.ts +1 -0
  53. package/src/pages/TransactionPage/StatusBottomSheet.style.tsx +19 -11
  54. package/src/pages/TransactionPage/TokenValueBottomSheet.tsx +4 -4
  55. package/src/types/widget.ts +2 -0
  56. package/src/utils/item.ts +29 -4
@@ -2,11 +2,13 @@ import { ChainType, getTokens } from '@lifi/sdk'
2
2
  import { useQuery } from '@tanstack/react-query'
3
3
  import { useMemo } from 'react'
4
4
  import { useWidgetConfig } from '../providers/WidgetProvider/WidgetProvider.js'
5
+ import type { FormType } from '../stores/form/types.js'
5
6
  import type { TokenAmount } from '../types/token.js'
7
+ import { isTokenAllowed } from '../utils/item.js'
6
8
  import { getQueryKey } from '../utils/queries.js'
7
9
  import { useChains } from './useChains.js'
8
10
 
9
- export const useTokens = (selectedChainId?: number) => {
11
+ export const useTokens = (selectedChainId?: number, formType?: FormType) => {
10
12
  const { tokens: configTokens, keyPrefix } = useWidgetConfig()
11
13
  const { data, isLoading } = useQuery({
12
14
  queryKey: [getQueryKey('tokens', keyPrefix)],
@@ -45,27 +47,13 @@ export const useTokens = (selectedChainId?: number) => {
45
47
  filteredTokens = [...includedTokens, ...filteredTokens]
46
48
  }
47
49
 
48
- if (configTokens?.allow?.length || configTokens?.deny?.length) {
49
- const allowedTokensSet = new Set(
50
- configTokens?.allow
51
- ?.filter((token) => token.chainId === selectedChainId)
52
- .map((token) => token.address)
53
- )
54
-
55
- const deniedTokenAddressesSet = new Set(
56
- configTokens?.deny
57
- ?.filter((token) => token.chainId === selectedChainId)
58
- .map((token) => token.address)
59
- )
50
+ // Get the appropriate allow/deny lists based on formType
51
+ filteredTokens = filteredTokens.filter(
52
+ (token) =>
53
+ token.chainId === selectedChainId &&
54
+ isTokenAllowed(token, configTokens, formType)
55
+ )
60
56
 
61
- if (allowedTokensSet.size || deniedTokenAddressesSet.size) {
62
- filteredTokens = filteredTokens.filter(
63
- (token) =>
64
- (!allowedTokensSet.size || allowedTokensSet.has(token.address)) &&
65
- !deniedTokenAddressesSet.has(token.address)
66
- )
67
- }
68
- }
69
57
  const filteredTokensMap = new Map(
70
58
  filteredTokens.map((token) => [token.address, token])
71
59
  )
@@ -118,6 +106,7 @@ export const useTokens = (selectedChainId?: number) => {
118
106
  getChainById,
119
107
  isSupportedChainsLoading,
120
108
  selectedChainId,
109
+ formType,
121
110
  ])
122
111
 
123
112
  return {
package/src/index.ts CHANGED
@@ -25,6 +25,7 @@ export * from './types/events.js'
25
25
  export type { TokenAmount } from './types/token.js'
26
26
  export * from './types/widget.js'
27
27
  export { getPriceImpact } from './utils/getPriceImpact.js'
28
+ export * from './utils/format.js'
28
29
  export { percentFormatter } from './utils/percentFormatter.js'
29
30
  export { compactNumberFormatter } from './utils/compactNumberFormatter.js'
30
31
  export { currencyExtendedFormatter } from './utils/currencyExtendedFormatter.js'
@@ -10,13 +10,15 @@ const getStatusColor = (status: StatusColor, theme: Theme) => {
10
10
  return {
11
11
  color: theme.vars.palette.success.mainChannel,
12
12
  alpha: 0.12,
13
- darken: 0,
13
+ lightDarken: 0,
14
+ darkDarken: 0,
14
15
  }
15
16
  case RouteExecutionStatus.Failed:
16
17
  return {
17
18
  color: theme.vars.palette.error.mainChannel,
18
19
  alpha: 0.12,
19
- darken: 0,
20
+ lightDarken: 0,
21
+ darkDarken: 0,
20
22
  }
21
23
  case RouteExecutionStatus.Done | RouteExecutionStatus.Partial:
22
24
  case RouteExecutionStatus.Done | RouteExecutionStatus.Refunded:
@@ -24,13 +26,15 @@ const getStatusColor = (status: StatusColor, theme: Theme) => {
24
26
  return {
25
27
  color: theme.vars.palette.warning.mainChannel,
26
28
  alpha: 0.48,
27
- darken: theme.palette.mode === 'light' ? 0.32 : 0,
29
+ lightDarken: 0.32,
30
+ darkDarken: 0,
28
31
  }
29
32
  default:
30
33
  return {
31
34
  color: theme.vars.palette.primary.mainChannel,
32
35
  alpha: 0.12,
33
- darken: 0,
36
+ lightDarken: 0,
37
+ darkDarken: 0,
34
38
  }
35
39
  }
36
40
  }
@@ -44,13 +48,10 @@ export const CenterContainer = styled(Box)(() => ({
44
48
  export const IconCircle = styled(Box, {
45
49
  shouldForwardProp: (prop) => prop !== 'status',
46
50
  })<{ status: StatusColor }>(({ theme, status }) => {
47
- const {
48
- color,
49
- alpha: alphaValue,
50
- darken: darkenValue,
51
- } = getStatusColor(status, theme)
51
+ const statusConfig = getStatusColor(status, theme)
52
+
52
53
  return {
53
- backgroundColor: `rgba(${color} / ${alphaValue})`,
54
+ backgroundColor: `rgba(${statusConfig.color} / ${statusConfig.alpha})`,
54
55
  borderRadius: '50%',
55
56
  width: 72,
56
57
  height: 72,
@@ -58,9 +59,16 @@ export const IconCircle = styled(Box, {
58
59
  position: 'relative',
59
60
  placeItems: 'center',
60
61
  '& > svg': {
61
- color: `color-mix(in srgb, rgb(${color}) ${(1 - darkenValue) * 100}%, black)`,
62
+ color: `color-mix(in srgb, rgb(${statusConfig.color}) ${(1 - statusConfig.lightDarken) * 100}%, black)`,
62
63
  width: 36,
63
64
  height: 36,
64
65
  },
66
+ ...theme.applyStyles('dark', {
67
+ '& > svg': {
68
+ color: `color-mix(in srgb, rgb(${statusConfig.color}) ${(1 - statusConfig.darkDarken) * 100}%, black)`,
69
+ width: 36,
70
+ height: 36,
71
+ },
72
+ }),
65
73
  }
66
74
  })
@@ -1,5 +1,5 @@
1
1
  import type { Route } from '@lifi/sdk'
2
- import { isRelayerStep } from '@lifi/sdk'
2
+ import { isGaslessStep } from '@lifi/sdk'
3
3
  import WarningRounded from '@mui/icons-material/WarningRounded'
4
4
  import { Box, Button, Typography } from '@mui/material'
5
5
  import type { RefObject } from 'react'
@@ -51,7 +51,7 @@ const TokenValueBottomSheetContent: React.FC<TokenValueBottomSheetProps> = ({
51
51
  getAccumulatedFeeCostsBreakdown(route)
52
52
  const fromAmountUSD = Number.parseFloat(route.fromAmountUSD)
53
53
  const toAmountUSD = Number.parseFloat(route.toAmountUSD)
54
- const hasRelayerSupport = route.steps.every(isRelayerStep)
54
+ const hasGaslessSupport = route.steps.some(isGaslessStep)
55
55
  return (
56
56
  <Box
57
57
  ref={ref}
@@ -106,14 +106,14 @@ const TokenValueBottomSheetContent: React.FC<TokenValueBottomSheetProps> = ({
106
106
  <Typography>{t('main.fees.network')}</Typography>
107
107
  <FeeBreakdownTooltip
108
108
  gasCosts={gasCosts}
109
- relayerSupport={hasRelayerSupport}
109
+ relayerSupport={hasGaslessSupport}
110
110
  >
111
111
  <Typography
112
112
  sx={{
113
113
  fontWeight: 600,
114
114
  }}
115
115
  >
116
- {hasRelayerSupport
116
+ {hasGaslessSupport
117
117
  ? t('main.fees.free')
118
118
  : t('format.currency', { value: gasCostUSD })}
119
119
  </Typography>
@@ -218,6 +218,8 @@ export type WidgetTokens = {
218
218
  featured?: StaticToken[]
219
219
  include?: Token[]
220
220
  popular?: StaticToken[]
221
+ from?: AllowDeny<BaseToken>
222
+ to?: AllowDeny<BaseToken>
221
223
  } & AllowDeny<BaseToken>
222
224
 
223
225
  export type WidgetLanguages = {
package/src/utils/item.ts CHANGED
@@ -1,8 +1,33 @@
1
- import type { AllowDeny } from '../types/widget.js'
1
+ import type { BaseToken } from '@lifi/sdk'
2
+ import type { FormType } from '../stores/form/types.js'
3
+ import type { AllowDeny, WidgetTokens } from '../types/widget.js'
2
4
 
3
- export const isItemAllowed = <T>(itemId: T, items?: AllowDeny<T>) => {
5
+ type IncludesFn<T> = (list: T[], item: T) => boolean
6
+
7
+ export const isItemAllowed = <T>(
8
+ item: T,
9
+ items?: AllowDeny<T>,
10
+ includes: IncludesFn<T> = (list, val) => list.includes(val)
11
+ ): boolean => {
4
12
  if (items?.allow?.length) {
5
- return items.allow.includes(itemId)
13
+ return includes(items.allow, item)
6
14
  }
7
- return !items?.deny?.includes(itemId)
15
+
16
+ return !includes(items?.deny ?? [], item)
17
+ }
18
+
19
+ const tokenIncludes = (list: BaseToken[], item: BaseToken) =>
20
+ list.some((t) => t.address === item.address && t.chainId === item.chainId)
21
+
22
+ export const isTokenAllowed = (
23
+ token: BaseToken,
24
+ configTokens: WidgetTokens | undefined,
25
+ formType: FormType | undefined
26
+ ) => {
27
+ return (
28
+ isItemAllowed(token, configTokens, tokenIncludes) &&
29
+ (formType
30
+ ? isItemAllowed(token, configTokens?.[formType], tokenIncludes)
31
+ : true)
32
+ )
8
33
  }