From 8ed7eb240b46aabdd8a07ddccb72f128e0ebf83a Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Tue, 11 Aug 2020 12:51:22 +0300 Subject: [PATCH] Searching results: improve ordering: token holders desc, name asc --- CHANGELOG.md | 2 +- .../templates/layout/_topnav.html.eex | 15 ++++++++++++++- apps/block_scout_web/priv/gettext/default.pot | 2 +- .../priv/gettext/en/LC_MESSAGES/default.po | 2 +- apps/explorer/lib/explorer/chain.ex | 8 +++++++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d6e5e4231..3aec245318 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ ### Fixes - [#3231](https://github.com/poanetwork/blockscout/pull/3231) - Improve search: unlimited number of searching results - [#3231](https://github.com/poanetwork/blockscout/pull/3231) - Improve search: allow search with space -- [#3231](https://github.com/poanetwork/blockscout/pull/3231) - Improve search: order by token holders in descendant order +- [#3231](https://github.com/poanetwork/blockscout/pull/3231) - Improve search: order by token holders in descending order and token/contract name is ascending order - [#3226](https://github.com/poanetwork/blockscout/pull/3226) - Fix notifier query for live update of token transfers - [#3220](https://github.com/poanetwork/blockscout/pull/3220) - Allow interaction with navbar menu at block-not-found page diff --git a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex index abe4e6e9b6..4d0ef2d6c9 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex @@ -179,7 +179,20 @@ value: "contract_address_hash", label: "contract_address_hash", descrSearch: true, - descr: "name" + descr: "name", + sort: "function(x1, x2){ + const tokenName1 = x1.split('').length > 1 ? x1.split('')[1].split('')[0].toLowerCase() : '' + const tokenName2 = x2.split('').length > 1 ? x2.split('')[1].split('')[0].toLowerCase() : '' + const holdersCount1 = x1.split('').length > 1 ? parseInt(x1.split('')[1].split('')[0].split('holder')[0], 10) : null + const holdersCount2 = x2.split('').length > 1 ? parseInt(x2.split('')[1].split('')[0].split('holder')[0], 10) : null + if (holdersCount1 && holdersCount2 && holdersCount1 !== holdersCount2 || (holdersCount1 && !holdersCount2) || (!holdersCount1 && holdersCount2)) { + holdersCount1 > holdersCount2 + } else { + if (tokenName1 < tokenName2) { return -1 } + if (tokenName1 > tokenName2) { return 1 } + return 0 + } + }" ]) %>