Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: alphabetization of swap receive inputs #243

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions src/hoc/withUniswapAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import {
concat,
filter,
get,
indexOf,
includes,
map,
partition,
property,
sortBy,
toLower,
values,
} from 'lodash';
import { connect } from 'react-redux';
Expand All @@ -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),
};
Expand Down