Skip to content

Commit 9cfeae0

Browse files
authored
fix: avoid using i18n in hookDappsRegistry (#6633)
Because Explorer has not integrated it yet and cannot render the values from registry
1 parent d93ff73 commit 9cfeae0

File tree

7 files changed

+96
-103
lines changed

7 files changed

+96
-103
lines changed

apps/cowswap-frontend/src/common/containers/OrderHooksDetails/HookItem/index.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { useState } from 'react'
1+
import { ReactNode, useState } from 'react'
22

33
import { CowHookDetails, HookToDappMatch } from '@cowprotocol/hook-dapp-lib'
44

55
import { t } from '@lingui/core/macro'
6-
import { Trans, useLingui } from '@lingui/react/macro'
6+
import { Trans } from '@lingui/react/macro'
77
import { ChevronDown, ChevronUp } from 'react-feather'
88

99
import { useSimulationData } from 'modules/tenderly/hooks/useSimulationData'
@@ -13,13 +13,18 @@ import { CowSwapAnalyticsCategory, toCowSwapGtmEvent } from 'common/analytics/ty
1313
import * as styledEl from './styled'
1414

1515
// TODO: Break down this large function into smaller functions
16-
// TODO: Add proper return type annotation
17-
// TODO: Reduce function complexity by extracting logic
18-
// eslint-disable-next-line max-lines-per-function, @typescript-eslint/explicit-function-return-type
19-
export function HookItem({ details, item, index }: { details?: CowHookDetails; item: HookToDappMatch; index: number }) {
16+
// eslint-disable-next-line max-lines-per-function
17+
export function HookItem({
18+
details,
19+
item,
20+
index,
21+
}: {
22+
details?: CowHookDetails
23+
item: HookToDappMatch
24+
index: number
25+
}): ReactNode {
2026
const [isOpen, setIsOpen] = useState(false)
2127
const simulationData = useSimulationData(details?.uuid)
22-
const { i18n } = useLingui()
2328

2429
const dappName = item.dapp?.name || t`Unknown Hook`
2530

@@ -37,8 +42,8 @@ export function HookItem({ details, item, index }: { details?: CowHookDetails; i
3742
<styledEl.HookNumber>{index + 1}</styledEl.HookNumber>
3843
{item.dapp ? (
3944
<>
40-
<img src={item.dapp.image} alt={i18n._(item.dapp.name)} />
41-
<span>{i18n._(item.dapp.name)}</span>
45+
<img src={item.dapp.image} alt={item.dapp.name} />
46+
<span>{item.dapp.name}</span>
4247
</>
4348
) : (
4449
<span>
@@ -79,7 +84,7 @@ export function HookItem({ details, item, index }: { details?: CowHookDetails; i
7984
<b>
8085
<Trans>Description</Trans>:
8186
</b>{' '}
82-
{item.dapp?.descriptionShort ? i18n._(item.dapp.descriptionShort) : ''}
87+
{item.dapp?.descriptionShort}
8388
</p>
8489
<p>
8590
<b>

apps/cowswap-frontend/src/modules/hooksStore/containers/HookRegistryList/index.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Command } from '@cowprotocol/types'
66
import { BannerOrientation, DismissableInlineBanner } from '@cowprotocol/ui'
77

88
import { t } from '@lingui/core/macro'
9-
import { Trans, useLingui } from '@lingui/react/macro'
9+
import { Trans } from '@lingui/react/macro'
1010

1111
import { NewModal } from 'common/pure/NewModal'
1212

@@ -46,7 +46,6 @@ export function HookRegistryList({ onDismiss, isPreHook, hookToEdit, walletType
4646
const customHookDapps = useCustomHookDapps(isPreHook)
4747
const hookToEditDetails = useHookById(hookToEdit, isPreHook)
4848
const internalHookDapps = useInternalHookDapps(isPreHook)
49-
const { i18n } = useLingui()
5049

5150
const currentDapps = useMemo(
5251
() => (isAllHooksTab ? [...internalHookDapps, ...customHookDapps] : customHookDapps),
@@ -57,19 +56,17 @@ export function HookRegistryList({ onDismiss, isPreHook, hookToEdit, walletType
5756
const lowerQuery = searchQuery?.toLowerCase()
5857

5958
return currentDapps.filter((item) => {
60-
const { name = undefined, descriptionShort = undefined } = item
59+
const { name = '', descriptionShort = '' } = item
6160

6261
const instance = isHookDappIframe(item) ? item.url : item.component
6362

6463
if (!instance) return false
6564

6665
if (!lowerQuery) return true
6766

68-
return [name ? i18n._(name) : '', descriptionShort ? i18n._(descriptionShort) : ''].some((text) =>
69-
text.toLowerCase().includes(lowerQuery),
70-
)
67+
return [name, descriptionShort].some((text) => text.toLowerCase().includes(lowerQuery))
7168
})
72-
}, [currentDapps, i18n, searchQuery])
69+
}, [currentDapps, searchQuery])
7370

7471
const sortedFilteredDapps = useMemo(() => {
7572
return filteredDapps.sort((a, b) => {
@@ -82,8 +79,7 @@ export function HookRegistryList({ onDismiss, isPreHook, hookToEdit, walletType
8279
const customHooksCount = customHookDapps.length
8380
const allHooksCount = internalHookDapps.length + customHooksCount
8481

85-
const title =
86-
(selectedDapp?.name ? i18n._(selectedDapp?.name) : undefined) || (dappDetails ? t`Hook description` : t`Hook Store`)
82+
const title = selectedDapp?.name || (dappDetails ? t`Hook description` : t`Hook Store`)
8783

8884
const onDismissModal = useCallback(() => {
8985
if (hookToEdit) {
@@ -157,7 +153,7 @@ export function HookRegistryList({ onDismiss, isPreHook, hookToEdit, walletType
157153
<HookDappsList>
158154
{sortedFilteredDapps.map((dapp) => (
159155
<HookListItem
160-
key={isHookDappIframe(dapp) ? dapp.url : i18n._(dapp.name)}
156+
key={isHookDappIframe(dapp) ? dapp.url : dapp.name}
161157
dapp={dapp}
162158
walletType={walletType}
163159
onRemove={!isAllHooksTab ? () => removeCustomHookDapp(dapp as HookDappIframe) : undefined}
@@ -178,7 +174,6 @@ export function HookRegistryList({ onDismiss, isPreHook, hookToEdit, walletType
178174
handleAddCustomHook,
179175
sortedFilteredDapps,
180176
emptyListMessage,
181-
i18n,
182177
walletType,
183178
removeCustomHookDapp,
184179
],

apps/cowswap-frontend/src/modules/hooksStore/pure/HookDetailHeader/index.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { ReactNode } from 'react'
2+
13
import { HookDappWalletCompatibility } from '@cowprotocol/hook-dapp-lib'
24

35
import { t } from '@lingui/core/macro'
4-
import { Trans, useLingui } from '@lingui/react/macro'
6+
import { Trans } from '@lingui/react/macro'
57

68
import * as styled from './styled'
79

@@ -17,20 +19,23 @@ interface HookDetailHeaderProps {
1719
padding?: string
1820
}
1921

20-
// TODO: Add proper return type annotation
21-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
22-
export function HookDetailHeader({ dapp, walletType, onSelect, iconSize, gap, padding }: HookDetailHeaderProps) {
23-
const { name, image, descriptionShort } = dapp
22+
export function HookDetailHeader({
23+
dapp,
24+
walletType,
25+
onSelect,
26+
iconSize,
27+
gap,
28+
padding,
29+
}: HookDetailHeaderProps): ReactNode {
30+
const { name: dAppName, image, descriptionShort } = dapp
2431
const isCompatible = isHookCompatible(dapp, walletType)
25-
const { i18n } = useLingui()
26-
const dAppName = i18n._(name)
2732

2833
return (
2934
<styled.Header iconSize={iconSize} gap={gap} padding={padding}>
3035
<img src={image} alt={dAppName} />
3136
<styled.Content>
3237
<h3>{dAppName}</h3>
33-
<styled.Description>{descriptionShort ? i18n._(descriptionShort) : ''}</styled.Description>
38+
<styled.Description>{descriptionShort}</styled.Description>
3439
{onSelect &&
3540
(isCompatible ? (
3641
<styled.AddButton onClick={onSelect}>

apps/cowswap-frontend/src/modules/hooksStore/pure/HookListItem/index.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { ReactNode } from 'react'
2+
13
import ICON_INFO from '@cowprotocol/assets/cow-swap/info.svg'
24
import { HookDappWalletCompatibility } from '@cowprotocol/hook-dapp-lib'
35
import { Command } from '@cowprotocol/types'
46

57
import { t } from '@lingui/core/macro'
6-
import { Trans, useLingui } from '@lingui/react/macro'
8+
import { Trans } from '@lingui/react/macro'
79
import SVG from 'react-inlinesvg'
810

911
import * as styled from './styled'
@@ -19,25 +21,18 @@ interface HookListItemProps {
1921
onRemove?: Command
2022
}
2123

22-
// TODO: Add proper return type annotation
23-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
24-
export function HookListItem({ dapp, walletType, onSelect, onOpenDetails, onRemove }: HookListItemProps) {
25-
const { name, descriptionShort, image, version } = dapp
26-
const { i18n } = useLingui()
24+
export function HookListItem({ dapp, walletType, onSelect, onOpenDetails, onRemove }: HookListItemProps): ReactNode {
25+
const { name: dAppName, descriptionShort, image, version } = dapp
2726
const isCompatible = isHookCompatible(dapp, walletType)
2827

29-
// TODO: Add proper return type annotation
30-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
31-
const handleItemClick = (event: React.MouseEvent<HTMLLIElement>) => {
28+
const handleItemClick = (event: React.MouseEvent<HTMLLIElement>): void => {
3229
const target = event.target as HTMLElement
3330
// Check if the click target is not a button or the info icon
3431
if (!target.closest('.link-button') && !target.closest('.remove-button') && !target.closest('i')) {
3532
onOpenDetails()
3633
}
3734
}
3835

39-
const dAppName = i18n._(name)
40-
4136
return (
4237
<styled.HookDappListItem
4338
onClick={handleItemClick}
@@ -49,7 +44,7 @@ export function HookListItem({ dapp, walletType, onSelect, onOpenDetails, onRemo
4944
<styled.HookDappDetails onClick={onOpenDetails}>
5045
<h3>{dAppName}</h3>
5146
<p>
52-
{descriptionShort ? i18n._(descriptionShort) : ''}
47+
{descriptionShort}
5348
<styled.Version>{version}</styled.Version>
5449
</p>
5550
</styled.HookDappDetails>

apps/explorer/src/components/orders/OrderHooksDetails/HookItem/index.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { useState } from 'react'
1+
import { ReactNode, useState } from 'react'
22

33
import { HookToDappMatch } from '@cowprotocol/hook-dapp-lib'
44

55
import { Item, Wrapper, ToggleButton, Details } from './styled'
66

7-
// TODO: Add proper return type annotation
8-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
9-
export function HookItem({ item, number }: { item: HookToDappMatch; number: number }) {
7+
export function HookItem({ item, number }: { item: HookToDappMatch; number: number }): ReactNode {
108
const [showDetails, setShowDetails] = useState(false)
119

1210
// TODO: Add proper return type annotation
@@ -20,8 +18,7 @@ export function HookItem({ item, number }: { item: HookToDappMatch; number: numb
2018
#{number} -{' '}
2119
{item.dapp ? (
2220
<>
23-
{/* Note: use MessageDescriptor.message, it contains the original not localized string. */}
24-
<img src={item.dapp.image} alt={item.dapp.name.message} /> <strong>{item.dapp.name.message}</strong>{' '}
21+
<img src={item.dapp.image} alt={item.dapp.name} /> <strong>{item.dapp.name}</strong>{' '}
2522
</>
2623
) : (
2724
'Unknown hook dapp'
@@ -37,7 +34,7 @@ export function HookItem({ item, number }: { item: HookToDappMatch; number: numb
3734
<i>Version:</i> {item.dapp.version}
3835
</p>
3936
<p>
40-
<i>Description:</i> {item.dapp.descriptionShort?.message}
37+
<i>Description:</i> {item.dapp.descriptionShort}
4138
</p>
4239
<p>
4340
<i>Website: </i>

0 commit comments

Comments
 (0)