diff --git a/src/components/Search/CtrlSearch.vue b/src/components/Search/CtrlSearch.vue
index 204e2378..59c0bc35 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,18 @@ export default {
}, timer)
},
changeInput (event) {
+ 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}/${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 +182,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
@@ -218,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/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])
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)