From fdca72830bc3f98aa2451f08bf521ef31ff1c7d6 Mon Sep 17 00:00:00 2001 From: Arjun Porwal <65214523+ap211unitech@users.noreply.github.com> Date: Tue, 21 Jan 2025 18:35:32 +0530 Subject: [PATCH] fix: default asset selection (#11222) --- packages/page-assets/src/Balances/index.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/page-assets/src/Balances/index.tsx b/packages/page-assets/src/Balances/index.tsx index 11b9332914..208f1b3de9 100644 --- a/packages/page-assets/src/Balances/index.tsx +++ b/packages/page-assets/src/Balances/index.tsx @@ -66,11 +66,17 @@ function Balances ({ className, infos = [] }: Props): React.ReactElement ); 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 (