From 886a2a613012e5080a2c0b4c127a13b1da9b37e2 Mon Sep 17 00:00:00 2001 From: Carlos Rosado Date: Wed, 7 Aug 2024 08:06:45 -0600 Subject: [PATCH 1/5] fix: rns block and date issues fixed --- src/components/Search/CtrlSearch.vue | 14 ++++++++++---- src/filters/TimeFilters.js | 2 +- src/lib/js/validate.js | 4 +++- src/store/modules/backend/actions.js | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/components/Search/CtrlSearch.vue b/src/components/Search/CtrlSearch.vue index 204e2378..45975fe1 100644 --- a/src/components/Search/CtrlSearch.vue +++ b/src/components/Search/CtrlSearch.vue @@ -91,6 +91,9 @@ export default { 'searchTypes', 'fetchSearch' ]), + formatValue (value) { + return value.toString().replaceAll(',', '') + }, btnClear () { this.clear() this.$refs.inputRef.focus() @@ -123,7 +126,8 @@ export default { }, emit (event, type, value) { type = type || event.type - this.$emit(type, { value, event }) + const newValue = this.formatValue(value) + this.$emit(type, { value: newValue, event }) let timer = 0 if (value.includes('.rsk')) timer = 1500 setTimeout(() => { @@ -131,16 +135,17 @@ export default { }, timer) }, changeInput (event) { + const newValue = this.formatValue(this.value) this.onFocus(false) if (this.currentType && this.searchedTypes.length) { this.$router.push(this.linkToSearch, () => { }) } else { - const link = `/${ROUTES.search}/${this.value}` + const link = `/${ROUTES.search}/${newValue}` this.$router.push(link, () => { }) } }, onChange (event) { - const value = this.value + const value = this.formatValue(this.value) this.emit(event, 'change', value) }, selectResult (result) { @@ -176,7 +181,8 @@ export default { this.selectResult(selectedResult) }, onShowMore (event) { - this.emit(event, 'showMore', this.value) + const value = this.formatValue(this.value) + this.emit(event, 'showMore', value) }, debounce (func, wait, immediate) { let timeout diff --git a/src/filters/TimeFilters.js b/src/filters/TimeFilters.js index db50494b..ee389eed 100644 --- a/src/filters/TimeFilters.js +++ b/src/filters/TimeFilters.js @@ -62,7 +62,7 @@ export const sSeconds = Vue.filter('s-seconds', time => { return moment.duration(Math.round(time), 's').humanize() }) -export const formatDate = (timestamp, format = 'YYYY/MM/DD HH:mm:ss Z') => { +export const formatDate = (timestamp, format = 'YYYY/MM/DD') => { timestamp = Number(timestamp) let date = new Date(timestamp) date = String(date.toISOString()) diff --git a/src/lib/js/validate.js b/src/lib/js/validate.js index 64ffa633..9699bdc7 100644 --- a/src/lib/js/validate.js +++ b/src/lib/js/validate.js @@ -2,7 +2,9 @@ import { isAddress } from '@rsksmart/rsk-utils/dist/addresses' import { isHexString, isTxOrBlockHash, add0x } from '@rsksmart/rsk-utils/dist/strings' export const isValidBlockNumber = (value, lastBlock) => { - const number = parseInt(value) + let newValue = value + if (value.toString().includes(',')) newValue = value.toString().replaceAll(',', '') + const number = Number(newValue) // optional checks lastBlock lastBlock = lastBlock || number return number > -1 && number <= lastBlock diff --git a/src/store/modules/backend/actions.js b/src/store/modules/backend/actions.js index 7efb4b43..9c50b100 100644 --- a/src/store/modules/backend/actions.js +++ b/src/store/modules/backend/actions.js @@ -63,7 +63,7 @@ export const socketData = ({ state, commit, getters, dispatch }, res) => { if (res.action === 'getAddress') { const domain = getters.getDomain(req.params.address) - res.data.rns = domain + if (domain) res.data.rns = domain } const response = Object.assign({}, state.responses[key]) From 98e4a97dbe300dc2e18a6fad58ec198df278c2ee Mon Sep 17 00:00:00 2001 From: Carlos Rosado Date: Wed, 7 Aug 2024 09:39:53 -0600 Subject: [PATCH 2/5] fix: console.log deleted --- src/components/ImplementationAddressField.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/ImplementationAddressField.vue b/src/components/ImplementationAddressField.vue index c0728327..c75078ef 100644 --- a/src/components/ImplementationAddressField.vue +++ b/src/components/ImplementationAddressField.vue @@ -104,8 +104,6 @@ export default { const implementationAddress = await this.getImplementationAddress() this.setImplementationAddress(implementationAddress) - - console.log({ implementationAddress: this.implementationAddress }) } } From e2d034a1a4452000d7192e16d0bf0b1f861aa6b5 Mon Sep 17 00:00:00 2001 From: Carlos Rosado Date: Wed, 7 Aug 2024 19:38:47 -0600 Subject: [PATCH 3/5] fix: console.log added --- src/components/ImplementationAddressField.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/ImplementationAddressField.vue b/src/components/ImplementationAddressField.vue index c75078ef..c0728327 100644 --- a/src/components/ImplementationAddressField.vue +++ b/src/components/ImplementationAddressField.vue @@ -104,6 +104,8 @@ export default { const implementationAddress = await this.getImplementationAddress() this.setImplementationAddress(implementationAddress) + + console.log({ implementationAddress: this.implementationAddress }) } } From ebc1137016ace1e6891dedc51639b7788efb5b78 Mon Sep 17 00:00:00 2001 From: Carlos Rosado Date: Wed, 14 Aug 2024 11:20:50 -0600 Subject: [PATCH 4/5] feat: search rns from Search page --- src/components/Search/CtrlSearch.vue | 3 +- src/components/SearchPage.vue | 51 +++++++++++++++++++++++++--- src/store/modules/search/actions.js | 5 +-- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/components/Search/CtrlSearch.vue b/src/components/Search/CtrlSearch.vue index 45975fe1..35d24302 100644 --- a/src/components/Search/CtrlSearch.vue +++ b/src/components/Search/CtrlSearch.vue @@ -136,6 +136,7 @@ export default { }, changeInput (event) { const newValue = this.formatValue(this.value) + if (!newValue) return this.onFocus(false) if (this.currentType && this.searchedTypes.length) { this.$router.push(this.linkToSearch, () => { }) @@ -224,7 +225,7 @@ export default { if (this.$route.name.toLowerCase() !== ROUTES.search.toLowerCase()) { this.clearSearchedResults() this.value = '' - } + } else if (this.$route.params?.value) this.value = this.$route.params?.value } } } diff --git a/src/components/SearchPage.vue b/src/components/SearchPage.vue index dd8cc337..2919df03 100644 --- a/src/components/SearchPage.vue +++ b/src/components/SearchPage.vue @@ -9,7 +9,12 @@ {{ result.name }} -
+ +

The search didn't match any element

@@ -34,7 +39,10 @@ export default { results: 'getSearchedResults', searched: 'searchedValue', requesting: 'requestingSearches', - types: 'searchedTypes' + types: 'searchedTypes', + searchedTypes: 'searchedTypes', + currentType: 'searchedType', + linkToSearch: 'linkToSearch' }), isSearching () { return this.requesting.length @@ -44,12 +52,45 @@ export default { ...mapActions([ 'fetchSearch', 'prepareSearch', - 'searchTypes']), + 'searchTypes' + ]), + ...mapGetters([ + 'getPage', + 'getSearchLink' + ]), + goTo ({ type, value }) { + this.getSearchLink()({ type, value }) + }, async search (value) { await this.prepareSearch({ value }) + value = this.searched const { types } = this - if (types.length) await this.searchTypes({ types, value }) - else await this.fetchSearch({ value }) + if (types.length === 1) { + const type = types[0] + return this.goTo({ type, value }) + } else { + await this.searchTypes({ types, value }) + await this.waitForResults() + const { results } = this + // redirect when there is only one result + if (results && results.length === 1) { + return this.goTo(results[0]) + } + } + }, + waitForResults () { + const vm = this + return new Promise((resolve) => { + return vm.createTimeout(() => { + if (vm.isLoading) resolve(vm.waitForResults()) + else resolve(vm.results) + }) + }) + }, + createTimeout (cb) { + const { requestingTimeout } = this + if (requestingTimeout) clearTimeout(requestingTimeout) + this.requestingTimeout = setTimeout(cb, 200) } } } diff --git a/src/store/modules/search/actions.js b/src/store/modules/search/actions.js index 50a9478e..f5fca86d 100644 --- a/src/store/modules/search/actions.js +++ b/src/store/modules/search/actions.js @@ -18,7 +18,8 @@ export const clearSearchedResults = async ({ commit, dispatch, getters }) => { } export const updateSearchedValue = async ({ commit, dispatch, state }, value) => { - if (value.match(/.rsk/)) { + if (!value) return + if (value?.match(/.rsk/)) { try { const address = await getAddr(value) store.commit('SET_DOMAIN', { domain: value, address }) @@ -28,7 +29,7 @@ export const updateSearchedValue = async ({ commit, dispatch, state }, value) => // console.error(error.message, value) } } - const lcValue = value.toLowerCase() + const lcValue = value?.toLowerCase() value = (isHexString(value) && isTxOrBlockHash(lcValue)) ? lcValue : value if (state.value !== value) { commit('SET_SEARCH_VALUE', value) From 849fac304c4d5e8248e239d0f222df3d5ee057fb Mon Sep 17 00:00:00 2001 From: Carlos Rosado Date: Thu, 15 Aug 2024 10:30:31 -0600 Subject: [PATCH 5/5] fix: validating route If the user is typing, we send him to the search page so that it does not overlap with the previous data searched. --- src/components/Search/CtrlSearch.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Search/CtrlSearch.vue b/src/components/Search/CtrlSearch.vue index 35d24302..59c0bc35 100644 --- a/src/components/Search/CtrlSearch.vue +++ b/src/components/Search/CtrlSearch.vue @@ -138,7 +138,7 @@ export default { const newValue = this.formatValue(this.value) if (!newValue) return this.onFocus(false) - if (this.currentType && this.searchedTypes.length) { + if (this.currentType && this.searchedTypes.length && !this.isLoading && !this.typing) { this.$router.push(this.linkToSearch, () => { }) } else { const link = `/${ROUTES.search}/${newValue}`