Skip to content

Commit

Permalink
Merge pull request #234 from rsksmart/staging
Browse files Browse the repository at this point in the history
fix: rns block and date issues
  • Loading branch information
ezequiel-rodriguez authored Aug 15, 2024
2 parents c3b955e + 849fac3 commit ee6e6cc
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 16 deletions.
19 changes: 13 additions & 6 deletions src/components/Search/CtrlSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export default {
'searchTypes',
'fetchSearch'
]),
formatValue (value) {
return value.toString().replaceAll(',', '')
},
btnClear () {
this.clear()
this.$refs.inputRef.focus()
Expand Down Expand Up @@ -123,24 +126,27 @@ 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(() => {
this.typing = false
}, 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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}
Expand Down
51 changes: 46 additions & 5 deletions src/components/SearchPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
<a :href="result.link">{{ result.name }}</a>
</li>
</ul>
<div class="not-found" v-if="!results.length && !isSearching">
<ul class="results" v-else-if="types.length">
<li>
<a :href="linkToSearch">{{ currentType }} {{ searched }}</a>
</li>
</ul>
<div class="not-found" v-if="!results.length && !isSearching && !types.length">
<p>The search didn't match any element</p>
</div>
</div>
Expand All @@ -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
Expand All @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/filters/TimeFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion src/lib/js/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/backend/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
5 changes: 3 additions & 2 deletions src/store/modules/search/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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)
Expand Down

0 comments on commit ee6e6cc

Please sign in to comment.