From 7a6ee483af699cd2bc595c989452c4c0f0c12e10 Mon Sep 17 00:00:00 2001 From: jinchung Date: Tue, 19 Nov 2019 15:40:01 -0500 Subject: [PATCH] Fix: alphabetization of swap receive inputs --- src/hoc/withUniswapAssets.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/hoc/withUniswapAssets.js b/src/hoc/withUniswapAssets.js index 1531d93b9c7..708e7195bbd 100644 --- a/src/hoc/withUniswapAssets.js +++ b/src/hoc/withUniswapAssets.js @@ -2,11 +2,11 @@ import { concat, filter, get, - indexOf, + includes, map, partition, - property, sortBy, + toLower, values, } from 'lodash'; import { connect } from 'react-redux'; @@ -22,28 +22,30 @@ const uniswapFavoritesSelector = state => state.favorites; const filterUniswapAssetsByAvailability = ({ address }) => uniswapAssetAddresses.includes(address); +const includeExchangeAddress = asset => ({ + ...asset, + exchangeAddress: get(uniswapAssetsClean, `${asset.address}.exchangeAddress`), +}); + +const lowerAssetName = asset => toLower(asset.name); + +const includeFavorite = asset => ({ + ...asset, + favorite: true, +}); + const withAssetsAvailableOnUniswap = allAssets => { const availableAssets = filter(allAssets, filterUniswapAssetsByAvailability); - const assetsAvailableOnUniswap = map(availableAssets, asset => ({ - ...asset, - exchangeAddress: get( - uniswapAssetsClean, - `${asset.address}.exchangeAddress` - ), - })); + const assetsAvailableOnUniswap = map(availableAssets, includeExchangeAddress); return { assetsAvailableOnUniswap }; }; const withSortedUniswapAssets = (unsortedUniswapAssets, favorites) => { - const sortedAssets = sortBy(values(unsortedUniswapAssets), property('name')); - const [favoriteAssets, remainingAssets] = partition( - sortedAssets, - asset => indexOf(favorites, asset.address) > -1 + const sortedAssets = sortBy(values(unsortedUniswapAssets), lowerAssetName); + const [favoriteAssets, remainingAssets] = partition(sortedAssets, asset => + includes(favorites, asset.address) ); - const labeledFavorites = map(favoriteAssets, asset => ({ - ...asset, - favorite: true, - })); + const labeledFavorites = map(favoriteAssets, includeFavorite); return { sortedUniswapAssets: concat(labeledFavorites, remainingAssets), };