mirror of
https://github.com/Qortal/chrome-extension.git
synced 2025-06-24 00:21:22 +00:00
fix userlookup address
This commit is contained in:
parent
5fffc92eb1
commit
5504c1cfe0
@ -1008,7 +1008,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");
|
throw new Error("Cannot retrieve address info");
|
||||||
if (data?.error === 124) {
|
if (data?.error === 124) {
|
||||||
return {
|
return {
|
||||||
address,
|
address,
|
||||||
|
@ -28,6 +28,7 @@ import CloseFullscreenIcon from '@mui/icons-material/CloseFullscreen';
|
|||||||
import SearchIcon from '@mui/icons-material/Search';
|
import SearchIcon from '@mui/icons-material/Search';
|
||||||
import { executeEvent, subscribeToEvent, unsubscribeFromEvent } from "../../utils/events";
|
import { executeEvent, subscribeToEvent, unsubscribeFromEvent } from "../../utils/events";
|
||||||
import { useNameSearch } from "../../hooks/useNameSearch";
|
import { useNameSearch } from "../../hooks/useNameSearch";
|
||||||
|
import { validateAddress } from "../../utils/validateAddress";
|
||||||
|
|
||||||
function formatAddress(str) {
|
function formatAddress(str) {
|
||||||
if (str.length <= 12) return str;
|
if (str.length <= 12) return str;
|
||||||
@ -42,7 +43,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);
|
||||||
@ -63,7 +68,10 @@ export const UserLookup = ({ isOpenDrawerLookup, setIsOpenDrawerLookup }) => {
|
|||||||
if (!addressInfoRes?.publicKey) {
|
if (!addressInfoRes?.publicKey) {
|
||||||
throw new Error("Address does not exist on blockchain");
|
throw new Error("Address does not exist on blockchain");
|
||||||
}
|
}
|
||||||
const name = await getNameInfo(owner);
|
const isAddress = validateAddress(messageAddressOrName);
|
||||||
|
const name = !isAddress
|
||||||
|
? messageAddressOrName
|
||||||
|
: await getNameInfo(owner);
|
||||||
const balanceRes = await fetch(
|
const balanceRes = await fetch(
|
||||||
`${getBaseApiReact()}/addresses/balance/${owner}`
|
`${getBaseApiReact()}/addresses/balance/${owner}`
|
||||||
);
|
);
|
||||||
@ -165,7 +173,7 @@ export const UserLookup = ({ isOpenDrawerLookup, setIsOpenDrawerLookup }) => {
|
|||||||
{...params}
|
{...params}
|
||||||
label="Address or Name"
|
label="Address or Name"
|
||||||
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