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

Displayed the digital assets orderly based on the pinned assets #2799

Merged
merged 1 commit into from
May 9, 2024
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
40 changes: 26 additions & 14 deletions web/src/containers/DigitalAssets/components/AssetsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const AssetsList = ({
icons,
}) => {
const [isOndDaySort, setIsOneDaySort] = useState(false);
let listData = [];
const handleClickChange = () => {
setIsOneDaySort(false);
if (mode === SORT.CHANGESEVENDAY) {
Expand Down Expand Up @@ -88,21 +89,32 @@ const AssetsList = ({
};

const getSortedList = () => {
return movePinnedItems(
coinsListData.sort((a, b) => {
const aVal = parseFloat(
isOndDaySort
? a.oneDayPriceDifferencePercenVal
: a.priceDifferencePercentVal
);
const bVal = parseFloat(
isOndDaySort
? b.oneDayPriceDifferencePercenVal
: b.priceDifferencePercentVal
);
return is_descending ? bVal - aVal : aVal - bVal;
})
const topAssets = [];

pinned_assets.forEach((pin) => {
const asset = coinsListData.find(({ symbol }) => symbol === pin);
if (asset) {
topAssets.push(asset);
}
});
const restAssets = coinsListData.filter(
(item) => !pinned_assets.includes(item.symbol)
);
const sortedValues = restAssets.sort((a, b) => {
const aVal = parseFloat(
isOndDaySort
? a.oneDayPriceDifferencePercenVal
: a.priceDifferencePercentVal
);
const bVal = parseFloat(
isOndDaySort
? b.oneDayPriceDifferencePercenVal
: b.priceDifferencePercentVal
);
return is_descending ? bVal - aVal : aVal - bVal;
});
listData = [...topAssets, ...sortedValues];
return movePinnedItems(listData);
};

const totalPages = Math.ceil(count / pageSize);
Expand Down