fix: default asset selection (#11222)

This commit is contained in:
Arjun Porwal 2025-01-21 18:35:32 +05:30 committed by GitHub
parent 724f04c423
commit fdca72830b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -66,11 +66,17 @@ function Balances ({ className, infos = [] }: Props): React.ReactElement<Props>
);
useEffect((): void => {
setInfo(() =>
infoIndex >= 0
? completeInfos.find(({ id }) => id.toString() === infoIndex.toString()) ?? null
: null
);
const info = infoIndex >= 0
? completeInfos.find(({ id }) => id.toString() === infoIndex.toString()) ?? null
: null;
// if no info found (usually happens on first load), select the first one automatically
if (!info) {
setInfo(completeInfos.at(0) ?? null);
setInfoIndex(completeInfos.at(0)?.id?.toNumber() ?? 0);
} else {
setInfo(info);
}
}, [completeInfos, infoIndex]);
return (