Skip to content

Commit

Permalink
Merge pull request #220 from rsksmart/develop
Browse files Browse the repository at this point in the history
RNS integration + fixes
  • Loading branch information
ezequiel-rodriguez authored Jun 7, 2024
2 parents bc4ff33 + 5637f21 commit d92cba3
Show file tree
Hide file tree
Showing 26 changed files with 653 additions and 340 deletions.
369 changes: 230 additions & 139 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"env-cmd": "^10.1.0",
"highlight.js": "^9.18.3",
"highlightjs-solidity": "git+https://github.com/highlightjs/highlightjs-solidity.git",
"keccak": "^3.0.4",
"moment": "^2.27.0",
"socket.io-client": "^2.3.0",
"streamsaver": "^2.0.5",
Expand All @@ -36,7 +37,8 @@
"vue-hotjar": "^1.2.0",
"vue-router": "^3.4.3",
"vuex": "^3.5.1",
"vuex-router-sync": "^5.0.0"
"vuex-router-sync": "^5.0.0",
"@rsksmart/rns-resolver.js": "^1.1.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.5.12",
Expand Down
11 changes: 7 additions & 4 deletions src/components/DataPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ export default {
data () {
return {
storedTitle: '',
storedParamAddress: null,
storedRouteName: null,
storedUrlParam: null,
PAGE_COLORS
}
},
Expand Down Expand Up @@ -300,11 +301,13 @@ export default {
const { module, action, params } = this
const key = this.reqKey
if (!module || !action) return
const paramsAddress = this.$route.params?.address
const routeName = this.$route.name
const urlParam = this.$route.params.address
// If the parameters are the same when the router changes, we do not request the address information.
if (this.storedParamAddress !== paramsAddress) {
if (this.storedRouteName !== routeName || !urlParam || this.storedRouteName !== urlParam) {
// use Date for a random info
this.storedParamAddress = paramsAddress || new Date()
this.storedRouteName = routeName || new Date()
this.storedUrlParam = urlParam
return this.fetchRouteData({ action, params, module, key })
}
},
Expand Down
24 changes: 2 additions & 22 deletions src/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
</div>
</template>
<script>
import { mapState, mapGetters, mapActions } from 'vuex'
import { mapState, mapGetters } from 'vuex'
import LastBlocks from '@/components/home/Block/LastBlocks.vue'
import { ROUTES as r } from '../config/types'
import StatsContent from '@/components/home/StatsContent.vue'
import LastBlock from '@/components/home/Block/LastBlock.vue'
import TxDensityChart from '@/components/Charts/TxDensityChart.vue'
Expand All @@ -28,32 +27,13 @@ export default {
LastBlock,
TxDensityChart
},
data () {
return {
topBoxHeight: 0,
r
}
},
computed: {
...mapState({
lastBlocks: state => state.backend.lastBlocks,
autoUpdate: state => state.config.autoUpdateBlocks
lastBlocks: state => state.backend.lastBlocks
}),
...mapGetters({
pending: 'pendingBlocks',
appSize: 'getSize'
})
},
methods: {
...mapActions([
'updateBlocks',
'setAutoUpdate'
]),
setAupdate (value) {
this.updateBlocks()
this.setAutoUpdate(value)
}
}
}
</script>
168 changes: 116 additions & 52 deletions src/components/Search/CtrlSearch.vue
Original file line number Diff line number Diff line change
@@ -1,46 +1,60 @@
<template>
<div class="search-content">
<button v-if="!expandSearch" @click="setExpand" class="btn-search">
<img src="@/assets/svg/search.svg" alt="">
</button>
<button v-else class="btn-close" @click="setExpand">X</button>
<div class="content-input">
<input
class="search-input bg-primary"
type="text"
:value="value"
@input.prevent="input"
@keyup.enter="changeInput"
@keyup.stop="onKey"
:placeholder="onFocusValue ? placeholder : null"
:class="cssClass"
@focus="onFocusValue = false"
@blur="onFocusValue = true"
>
<button class="btn-clear" @click="clear" v-if="value">
x
<div class="search-container">
<div class="search-content" :class="`${onFocusValue ? 'search-content-focus' : ''}`">
<button v-if="!expandSearch" @click="setExpand" class="btn-search">
<img src="@/assets/svg/search.svg" alt="">
</button>
<Spinner v-if="isLoading" :width="20" :height="20" :border="2" />
</div>
<div class="search-results bg-secondary" v-if="results.length" ref="results">
<template v-for="(result, i) in results">
<div v-if="result.link && result.value"
:class="{ selected: selectedResult === i+1 }"
:key="`${result.value}${i}`"
:ref="`result-${i}`">
<a
:href="result.link"
@touchend.passive="gotoResult($event, i)"
@click="gotoResult($event, i)">
{{ result.name || result.value }}
</a>
<button v-else class="btn-close" @click="setExpand">X</button>
<div class="content-input">
<input
class="search-input"
type="text"
v-model="value"
ref="inputRef"
@input.prevent="handleInput"
@keyup.enter="debouncedChangeInput"
@keyup.stop="debouncedOnKey"
:placeholder="!onFocusValue ? placeholder : null"
:class="cssClass"
@focus="onFocus(true)"
@blur="isSearchPage ? onFocus(false) : null"
>
<button class="btn-clear" @click="btnClear" v-if="value">
x
</button>
<Spinner v-if="isLoading || typing" :width="20" :height="20" :border="2" />
</div>
<div class="search-results bg-secondary" v-if="value && onFocusValue && !isSearchPage && !typing && !isLoading">
<template v-if="(currentType && searchedTypes.length > 0)">
<div class="title-address capitalize">{{ currentType }}</div>
<router-link :to="`${linkToSearch}`" class="search-address">{{ value }}</router-link>
</template>
<div v-else-if="results.length" ref="results">
<div class="title-address capitalize">Result:</div>
<template v-for="(result, i) in results">
<div v-if="result.link && result.value"
:class="{ selected: selectedResult === i+1 }"
:key="`${result.value}${i}`"
:ref="`result-${i}`">
<a
:href="result.link"
@touchend.passive="gotoResult($event, i)"
@click="gotoResult($event, i)">
{{ result.name || result.value }}
</a>
</div>
</template>
</div>
<div class="no-results bg-secondary" v-else-if="onFocusValue && value && !typing && !isLoading && !isSearchPage">
<div class="title-address">No results found.</div>
</div>
</template>
</div>
</div>
<div class="search-background" v-if="onFocusValue && !isSearchPage" @click="onFocus(false)"></div>
</div>
</template>
<script>
import { mapActions } from 'vuex'
import { mapActions, mapGetters } from 'vuex'
import { clamp } from '../../lib/js/utils'
import Spinner from '../Loaders/Spinner.vue'
import { ROUTES } from '../../config/types'
Expand All @@ -57,15 +71,39 @@ export default {
resultEmitted: null,
focused: undefined,
expandSearch: false,
onFocusValue: true
onFocusValue: false,
debounceTime: 800,
typing: false
}
},
created () {
const { searchValue } = this
if (searchValue) this.value = searchValue
this.debouncedOnKey = this.debounce(this.onKey, this.debounceTime)
this.debouncedInput = this.debounce(this.input, this.debounceTime)
this.debouncedChangeInput = this.debounce(this.changeInput, this.debounceTime)
},
methods: {
...mapActions(['searchExpand', 'clearSearchedResults']),
...mapActions([
'searchExpand',
'clearSearchedResults',
'prepareSearch',
'searchTypes',
'fetchSearch'
]),
btnClear () {
this.clear()
this.$refs.inputRef.focus()
},
handleInput (event) {
this.debouncedInput(event)
this.typing = true
},
onFocus (value) {
setTimeout(() => {
this.onFocusValue = value
}, 100)
},
setExpand () {
if (window.innerWidth > 600) return
this.expandSearch = !this.expandSearch
Expand All @@ -80,26 +118,26 @@ export default {
this.selectResult(0)
const value = event.target.value
this.value = value
const typeEvent = this.value.length > 10 ? 'change' : type
this.emit(event, typeEvent, value)
this.emit(event, type, value)
this.emit(event, 'change', value)
},
emit (event, type, value) {
type = type || event.type
this.$emit(type, { value, event })
let timer = 0
if (value.includes('.rsk')) timer = 1500
setTimeout(() => {
this.typing = false
}, timer)
},
changeInput (event) {
const { fullPath } = this.$route
const vm = this
setTimeout(() => {
if (!vm.selectedResult) {
if (fullPath === vm.$route.fullPath) {
vm.onChange(event)
} else {
this.value = ''
vm.emitResult(event, null)
}
}
}, 200)
this.onFocus(false)
if (this.currentType && this.searchedTypes.length) {
this.$router.push(this.linkToSearch, () => { })
} else {
const link = `/${ROUTES.search}/${this.value}`
this.$router.push(link, () => { })
}
},
onChange (event) {
const value = this.value
Expand All @@ -109,6 +147,7 @@ export default {
this.selectedResult = result
},
gotoResult (event, key) {
this.onFocus(false)
const result = this.results[key]
const { link } = result
if (link) this.$router.push(link)
Expand Down Expand Up @@ -138,19 +177,44 @@ export default {
},
onShowMore (event) {
this.emit(event, 'showMore', this.value)
},
debounce (func, wait, immediate) {
let timeout
return function () {
const context = this
const args = arguments
const later = function () {
timeout = null
if (!immediate) func.apply(context, args)
}
const callNow = immediate && !timeout
clearTimeout(timeout)
timeout = setTimeout(later, wait)
if (callNow) func.apply(context, args)
}
}
},
computed: {
...mapGetters({
searchedTypes: 'searchedTypes',
currentType: 'searchedType',
linkToSearch: 'linkToSearch'
}),
totalResults () {
const { results } = this
return (results) ? results.length : 0
},
isLoading () {
return !!this.loading
},
isSearchPage () {
return this.$route.name.toLowerCase() === ROUTES.search.toLowerCase()
}
},
watch: {
$route () {
this.$refs.inputRef.blur()
this.onFocus(false)
if (this.$route.name.toLowerCase() !== ROUTES.search.toLowerCase()) {
this.clearSearchedResults()
this.value = ''
Expand Down
22 changes: 3 additions & 19 deletions src/components/Search/SearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
</div>
</template>
<script>
import { ROUTES as r } from '../../config/types'
import { mapState, mapGetters, mapActions } from 'vuex'
import CtrlSearch from './CtrlSearch.vue'
// const RESULTS_LENGTH = 10
export default {
name: 'search-box',
components: {
Expand All @@ -24,7 +22,7 @@ export default {
data () {
return {
value: undefined,
msg: 'Search by address, block, tx, token name',
msg: 'Search by address, block, tx, token name, rns domain',
msgTimeout: null,
requestingTimeout: null
}
Expand Down Expand Up @@ -77,26 +75,16 @@ export default {
this.clearSearchedResults()
},
goTo ({ type, value }) {
const link = this.getSearchLink()({ type, value })
if (!link) return
this.clearRequests()
this.$router.push(link, () => { })
},
goToSearchPage (value) {
const link = `/${r.search}/${value}`
this.$router.push(link, () => { })
this.getSearchLink()({ type, value })
},
setValue (value) {
this.value = value
if (this.isSearchPage) {
history.pushState({}, document.title, value)
}
},
onResult ({ event, value }) {
this.setValue(value)
// if (value) this.clearRequests()
},
onInput ({ event, value }) {
this.clearRequests()
Expand All @@ -108,9 +96,7 @@ export default {
await this.prepareSearch({ value })
value = this.searched
const { types } = this
if (!types || !types.length) {
return this.goToSearchPage(value)
} else if (types.length === 1) {
if (types.length === 1) {
const type = types[0]
return this.goTo({ type, value })
} else {
Expand All @@ -120,8 +106,6 @@ export default {
// redirect when there is only one result
if (results && results.length === 1) {
return this.goTo(results[0])
} else {
this.goToSearchPage(value)
}
}
},
Expand Down
Loading

0 comments on commit d92cba3

Please sign in to comment.