Skip to content

Commit

Permalink
feat: Implement counter in oracles page (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
janmichek committed Oct 19, 2023
1 parent df5fa97 commit 9489d33
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/components/OraclesPanel.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<template>
<app-panel>
<paginated-content
v-model:page-index="pageIndex"
:entities="oracles"
:limit="limit"
:total-count="getOraclesCount(selectedOracleState.stateQuery)"
@prev-clicked="loadPrevOracles"
@next-clicked="loadNextOracles">
<template #header>
Expand All @@ -20,7 +22,7 @@

<script setup>
import { storeToRefs } from 'pinia'
import { computed } from 'vue'
import { computed, ref } from 'vue'
import { useRoute, useRouter } from 'nuxt/app'
import { useOraclesStore } from '@/stores/oracles'
import OraclesTableCondensed from '@/components/OraclesTableCondensed'
Expand All @@ -29,12 +31,13 @@ import PaginatedContent from '@/components/PaginatedContent'
import { isDesktop } from '@/utils/screen'
const oraclesStore = useOraclesStore()
const { fetchOracles } = oraclesStore
const { fetchOracles, fetchOraclesCount, getOraclesCount } = oraclesStore
const { oracles } = storeToRefs(oraclesStore)
const route = useRoute()
const { push, replace } = useRouter()
const limit = computed(() => process.client && isDesktop() ? 10 : 3)
const pageIndex = ref(1)
function loadPrevOracles() {
fetchOracles(oracles.value.prev)
Expand All @@ -49,6 +52,8 @@ async function loadOracles() {
const oracleStateOption = ORACLE_STATES_OPTIONS.find(option => option.stateQuery === state)
selectedOracleState.value = oracleStateOption || ORACLE_STATES_OPTIONS[0]
await fetchOracles(`/v2/oracles?limit=${limit.value}${selectedOracleState.value.stateQuery ? '&state=' + selectedOracleState.value.stateQuery : ''}`)
await fetchOraclesCount()
pageIndex.value = 1
}
const selectedOracleState = computed({
Expand Down
24 changes: 24 additions & 0 deletions src/stores/oracles.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,29 @@ export const useOraclesStore = defineStore('oracles', () => {
const { blockHeight } = storeToRefs(recentBlocksStore)

const rawOracles = ref(null)
const rawOraclesCount = ref(null)

const activeOraclesCount = computed(() => {
return rawOraclesCount.value?.activeOracles
})
const inativeOracles = computed(() => {
return rawOraclesCount.value?.inactiveOracles
})

const oracles = computed(() => {
return rawOracles.value
? adaptOracles(rawOracles.value, blockHeight.value)
: null
})

function getOraclesCount(state) {
if (state === 'active') {
return activeOraclesCount.value
} else {
return inativeOracles.value
}
}

async function fetchOracles(queryParameters = null) {
rawOracles.value = null
const defaultParameters = '/v2/oracles?direction=backward&limit=10'
Expand All @@ -27,8 +43,16 @@ export const useOraclesStore = defineStore('oracles', () => {
rawOracles.value = data
}

async function fetchOraclesCount() {
rawOraclesCount.value = null
const { data } = await axios.get(`${MIDDLEWARE_URL}/v2/totalstats?limit=1`)
rawOraclesCount.value = data.data[0]
}

return {
oracles,
fetchOracles,
fetchOraclesCount,
getOraclesCount,
}
})

0 comments on commit 9489d33

Please sign in to comment.