From 1009d6a756642b24d43359223cb5f5a675ac72fd Mon Sep 17 00:00:00 2001 From: Christopher Howard Date: Mon, 21 Oct 2024 18:50:24 -0400 Subject: [PATCH] feat: default to highest eth and respective network (#1736) Co-authored-by: Daniel Sinclair <4412473+DanielSinclair@users.noreply.github.com> --- src/entries/popup/pages/swap/index.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/entries/popup/pages/swap/index.tsx b/src/entries/popup/pages/swap/index.tsx index 9b57f71ecb..ebf560cd38 100644 --- a/src/entries/popup/pages/swap/index.tsx +++ b/src/entries/popup/pages/swap/index.tsx @@ -453,6 +453,17 @@ export function Swap({ bridge = false }: { bridge?: boolean }) { [assetsToSell, isHidden], ); + const highestEth = useMemo(() => { + const eths = unhiddenAssetsToSell.filter((asset) => asset.symbol === 'ETH'); + return eths?.length + ? eths.reduce((highest, next) => { + return Number(highest.balance.amount) > Number(next.balance.amount) + ? highest + : next; + }) + : null; + }, [unhiddenAssetsToSell]); + const unhiddenAssetsToBuy = useMemo(() => { return assetsToBuy.map((assets) => { return { @@ -618,7 +629,11 @@ export function Swap({ bridge = false }: { bridge?: boolean }) { if (savedTokenToSell) { setAssetToSell(savedTokenToSell); } else { - setAssetToSell(unhiddenAssetsToSell[0]); + if (highestEth) { + setAssetToSell(highestEth); + } else { + setAssetToSell(unhiddenAssetsToSell[0]); + } setDefaultAssetWasSet(true); } setDidPopulateSavedTokens(true);