From 0b818125b3d7d0887601ac7548ab4904cbd485bc Mon Sep 17 00:00:00 2001 From: Viktor Baranov Date: Thu, 22 Jul 2021 22:54:09 +0300 Subject: [PATCH] Add creation time of contract in the results of the search --- CHANGELOG.md | 1 + apps/block_scout_web/assets/js/lib/autocomplete.js | 8 ++++++-- apps/block_scout_web/assets/package-lock.json | 14 ++++++++++++++ apps/block_scout_web/assets/package.json | 1 + apps/explorer/lib/explorer/chain.ex | 10 ++++++++-- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d14b89b8a..6592b5a14b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#4423](https://github.com/blockscout/blockscout/pull/4423) - Add creation time of contract in the results of the search - [#4391](https://github.com/blockscout/blockscout/pull/4391) - Add batched transactions on the `address/{addressHash}/transactions` page - [#4353](https://github.com/blockscout/blockscout/pull/4353) - Added live-reload on the token holders page diff --git a/apps/block_scout_web/assets/js/lib/autocomplete.js b/apps/block_scout_web/assets/js/lib/autocomplete.js index 67ea2aaf19..3fbe65cf13 100644 --- a/apps/block_scout_web/assets/js/lib/autocomplete.js +++ b/apps/block_scout_web/assets/js/lib/autocomplete.js @@ -1,4 +1,5 @@ import AutoComplete from '@tarekraafat/autocomplete.js/dist/autoComplete.js' +import { DateTime } from 'luxon' const placeHolder = 'Search by address, token symbol, name, transaction hash, or block number' const dataSrc = async (query, id) => { @@ -44,10 +45,13 @@ const searchEngine = (query, record) => { record.contract_address_hash.toLowerCase().includes(query.toLowerCase())) { var searchResult = `${record.contract_address_hash}
${record.name}` if (record.symbol) { - searchResult = searchResult + ` (${record.symbol})` + searchResult += ` (${record.symbol})` } if (record.holder_count) { - searchResult = searchResult + ` ${record.holder_count} holder(s)` + searchResult += ` ${record.holder_count} holder(s)` + } + if (record.inserted_at) { + searchResult += ` (${DateTime.fromISO(record.inserted_at).toLocaleString(DateTime.DATETIME_SHORT)})` } var re = new RegExp(query, 'ig') searchResult = searchResult.replace(re, '$&') diff --git a/apps/block_scout_web/assets/package-lock.json b/apps/block_scout_web/assets/package-lock.json index ff056099e4..681ff5f269 100644 --- a/apps/block_scout_web/assets/package-lock.json +++ b/apps/block_scout_web/assets/package-lock.json @@ -24,6 +24,7 @@ "humps": "^2.0.1", "jquery": "^3.4.0", "lodash": "^4.17.19", + "luxon": "^2.0.1", "moment": "^2.29.1", "nanomorph": "^5.4.0", "numeral": "^2.0.6", @@ -11161,6 +11162,14 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, + "node_modules/luxon": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-2.0.1.tgz", + "integrity": "sha512-8Eawf81c9ZlQj62W3eq4mp+C7SAIAnmaS7ZuEAiX503YMcn+0C1JnMQRtfaQj6B5qTZLgHv0F4H5WabBCvi1fw==", + "engines": { + "node": "*" + } + }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -26650,6 +26659,11 @@ } } }, + "luxon": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-2.0.1.tgz", + "integrity": "sha512-8Eawf81c9ZlQj62W3eq4mp+C7SAIAnmaS7ZuEAiX503YMcn+0C1JnMQRtfaQj6B5qTZLgHv0F4H5WabBCvi1fw==" + }, "make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", diff --git a/apps/block_scout_web/assets/package.json b/apps/block_scout_web/assets/package.json index a5e3f92338..0d58582f10 100644 --- a/apps/block_scout_web/assets/package.json +++ b/apps/block_scout_web/assets/package.json @@ -36,6 +36,7 @@ "humps": "^2.0.1", "jquery": "^3.4.0", "lodash": "^4.17.19", + "luxon": "^2.0.1", "moment": "^2.29.1", "nanomorph": "^5.4.0", "numeral": "^2.0.6", diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 0ffe32e2d0..7f55374e14 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -1130,8 +1130,14 @@ defmodule Explorer.Chain do {:some, term} -> query = from(smart_contract in SmartContract, - where: fragment("to_tsvector(name) @@ to_tsquery(?)", ^term), - select: %{contract_address_hash: smart_contract.address_hash, name: smart_contract.name}, + left_join: address in Address, + on: smart_contract.address_hash == address.hash, + where: fragment("to_tsvector(name ) @@ to_tsquery(?)", ^term), + select: %{ + contract_address_hash: smart_contract.address_hash, + name: smart_contract.name, + inserted_at: address.inserted_at + }, order_by: [desc: smart_contract.inserted_at] )