From c06b4c8d2366f3066ac7980e9699e68cf74f5414 Mon Sep 17 00:00:00 2001 From: PhilReact Date: Mon, 23 Jun 2025 14:34:03 +0300 Subject: [PATCH] fix userlookup address --- src/background/background.ts | 2 +- src/components/UserLookup.tsx/UserLookup.tsx | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/background/background.ts b/src/background/background.ts index 9a56706..cd8a8f8 100644 --- a/src/background/background.ts +++ b/src/background/background.ts @@ -832,7 +832,7 @@ export async function getAddressInfo(address) { const data = await response.json(); if (!response?.ok && data?.error !== 124) - throw new Error('Cannot fetch address info'); // TODO translate + throw new Error('Cannot retrieve address info'); // TODO translate if (data?.error === 124) { return { address, diff --git a/src/components/UserLookup.tsx/UserLookup.tsx b/src/components/UserLookup.tsx/UserLookup.tsx index bab5370..dc63094 100644 --- a/src/components/UserLookup.tsx/UserLookup.tsx +++ b/src/components/UserLookup.tsx/UserLookup.tsx @@ -38,6 +38,7 @@ import { } from '../../utils/events'; import { useNameSearch } from '../../hooks/useNameSearch'; import { useTranslation } from 'react-i18next'; +import { validateAddress } from '../../utils/validateAddress.ts'; function formatAddress(str) { if (str.length <= 12) return str; @@ -60,7 +61,11 @@ export const UserLookup = ({ isOpenDrawerLookup, setIsOpenDrawerLookup }) => { const [nameOrAddress, setNameOrAddress] = useState(''); const [inputValue, setInputValue] = useState(''); const { results, isLoading } = useNameSearch(inputValue); - const options = useMemo(() => results?.map((item) => item.name), [results]); + const options = useMemo(() => { + const isAddress = validateAddress(inputValue); + if (isAddress) return [inputValue]; + return results?.map((item) => item.name); + }, [results, inputValue]); const [errorMessage, setErrorMessage] = useState(''); const [addressInfo, setAddressInfo] = useState(null); const [isLoadingUser, setIsLoadingUser] = useState(false); @@ -99,8 +104,10 @@ export const UserLookup = ({ isOpenDrawerLookup, setIsOpenDrawerLookup }) => { }) ); } - - const name = await getNameInfo(owner); + const isAddress = validateAddress(messageAddressOrName); + const name = !isAddress + ? messageAddressOrName + : await getNameInfo(owner); const balanceRes = await fetch( `${getBaseApiReact()}/addresses/balance/${owner}` ); @@ -209,7 +216,7 @@ export const UserLookup = ({ isOpenDrawerLookup, setIsOpenDrawerLookup }) => { postProcess: 'capitalizeFirstChar', })} onKeyDown={(e) => { - if (e.key === 'Enter' && nameOrAddress) { + if (e.key === 'Enter' && inputValue) { lookupFunc(inputValue); } }}