mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-06-24 00:21:22 +00:00
fix userlookup address
This commit is contained in:
parent
0a04b484d7
commit
c06b4c8d23
@ -832,7 +832,7 @@ export async function getAddressInfo(address) {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (!response?.ok && data?.error !== 124)
|
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) {
|
if (data?.error === 124) {
|
||||||
return {
|
return {
|
||||||
address,
|
address,
|
||||||
|
@ -38,6 +38,7 @@ import {
|
|||||||
} from '../../utils/events';
|
} from '../../utils/events';
|
||||||
import { useNameSearch } from '../../hooks/useNameSearch';
|
import { useNameSearch } from '../../hooks/useNameSearch';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { validateAddress } from '../../utils/validateAddress.ts';
|
||||||
|
|
||||||
function formatAddress(str) {
|
function formatAddress(str) {
|
||||||
if (str.length <= 12) return str;
|
if (str.length <= 12) return str;
|
||||||
@ -60,7 +61,11 @@ export const UserLookup = ({ isOpenDrawerLookup, setIsOpenDrawerLookup }) => {
|
|||||||
const [nameOrAddress, setNameOrAddress] = useState('');
|
const [nameOrAddress, setNameOrAddress] = useState('');
|
||||||
const [inputValue, setInputValue] = useState('');
|
const [inputValue, setInputValue] = useState('');
|
||||||
const { results, isLoading } = useNameSearch(inputValue);
|
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 [errorMessage, setErrorMessage] = useState('');
|
||||||
const [addressInfo, setAddressInfo] = useState(null);
|
const [addressInfo, setAddressInfo] = useState(null);
|
||||||
const [isLoadingUser, setIsLoadingUser] = useState(false);
|
const [isLoadingUser, setIsLoadingUser] = useState(false);
|
||||||
@ -99,8 +104,10 @@ export const UserLookup = ({ isOpenDrawerLookup, setIsOpenDrawerLookup }) => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const isAddress = validateAddress(messageAddressOrName);
|
||||||
const name = await getNameInfo(owner);
|
const name = !isAddress
|
||||||
|
? messageAddressOrName
|
||||||
|
: await getNameInfo(owner);
|
||||||
const balanceRes = await fetch(
|
const balanceRes = await fetch(
|
||||||
`${getBaseApiReact()}/addresses/balance/${owner}`
|
`${getBaseApiReact()}/addresses/balance/${owner}`
|
||||||
);
|
);
|
||||||
@ -209,7 +216,7 @@ export const UserLookup = ({ isOpenDrawerLookup, setIsOpenDrawerLookup }) => {
|
|||||||
postProcess: 'capitalizeFirstChar',
|
postProcess: 'capitalizeFirstChar',
|
||||||
})}
|
})}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
if (e.key === 'Enter' && nameOrAddress) {
|
if (e.key === 'Enter' && inputValue) {
|
||||||
lookupFunc(inputValue);
|
lookupFunc(inputValue);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user