Skip to content

Commit

Permalink
fix: default asset selection (#11222)
Browse files Browse the repository at this point in the history
  • Loading branch information
ap211unitech authored Jan 21, 2025
1 parent 724f04c commit fdca728
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/page-assets/src/Balances/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit fdca728

Please sign in to comment.