Skip to content

Commit

Permalink
feat: default to highest eth and respective network (#1736)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Sinclair <[email protected]>
  • Loading branch information
derHowie and DanielSinclair authored Oct 21, 2024
1 parent c56dbbe commit 1009d6a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/entries/popup/pages/swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1009d6a

Please sign in to comment.