Skip to content

Commit

Permalink
feat: Contract calls chart page (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
janmichek authored May 16, 2024
1 parent ef48878 commit a1ddc72
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 32 deletions.
5 changes: 5 additions & 0 deletions src/components/ChartsNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
class="charts-navigation__link">
Keyblocks
</app-link>
<app-link
to="/charts/contracts"
class="charts-navigation__link">
Smart Contracts
</app-link>
</app-panel>
</nav>
</template>
Expand Down
20 changes: 13 additions & 7 deletions src/components/ContractsChartPanel.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<app-panel>
<template #heading>
CONTRACT CALLS
SMART CONTRACT CALLS
</template>
<template #header>
<chart-controls
Expand All @@ -23,15 +23,21 @@

<script setup>
import { storeToRefs } from 'pinia'
import { useContractsStore } from '@/stores/contracts'
import { useChartsStore } from '@/stores/charts'
import LineChart from '@/components/LineChart'
import { CHART_INTERVALS_OPTIONS } from '@/utils/constants'
const contractsStore = useContractsStore()
const { contractsStatistics } = storeToRefs(contractsStore)
const { fetchContractsStatistics } = contractsStore
const chartsStore = useChartsStore()
const { contractsStatistics } = storeToRefs(chartsStore)
const { fetchContractsStatistics } = chartsStore
const selectedRange = ref(CHART_INTERVALS_OPTIONS[0])
const props = defineProps({
range: {
required: true,
type: Object,
},
})
const selectedRange = ref(props.range)
await useAsyncData(async() => {
await loadContractsStatistics()
Expand Down
4 changes: 4 additions & 0 deletions src/components/TheNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ const menuOptions = ref([{
name: 'Keyblocks',
path: '/charts/keyblocks',
},
{
name: 'Smart Contracts',
path: '/charts/contracts',
},
],
}])
Expand Down
4 changes: 2 additions & 2 deletions src/components/TransactionsChartPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
v-if="hasSelect"
v-model="selectedTxType"
size="sm"
class="charts-transactions-chart-panel__select
charts-transactions-chart-panel__select--desktop
class="transactions-chart-panel__select
transactions-chart-panel__select--desktop
u-hidden-mobile"/>

<chart-controls
Expand Down
27 changes: 27 additions & 0 deletions src/pages/charts/contracts.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<Head>
<Title>Charts</Title>
</Head>

<page-header>
Charts
<template #tooltip>
{{ chartsHints.charts }}
</template>
</page-header>

<NuxtLayout name="master-detail">
<template #master>
<charts-navigation/>
</template>
<template #detail>
<contracts-chart-panel :range="CHART_INTERVALS_OPTIONS[4]"/>
</template>
</NuxtLayout>
</template>

<script setup>
import { chartsHints } from '@/utils/hints/chartsHints'
import { CHART_INTERVALS_OPTIONS } from '@/utils/constants'
</script>
4 changes: 1 addition & 3 deletions src/pages/charts/keyblocks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
<charts-navigation/>
</template>
<template #detail>
<keyblocks-chart-panel v-if="!isLoading"/>
<loader-panel v-else/>
<keyblocks-chart-panel/>
</template>
</NuxtLayout>
</template>

<script setup>
import { chartsHints } from '@/utils/hints/chartsHints'
const { isLoading } = useLoading()
</script>
6 changes: 1 addition & 5 deletions src/pages/charts/transactions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@
</template>
<template #detail>
<transactions-chart-panel
v-if="!isLoading"
:has-select="true"
:range="CHART_INTERVALS_OPTIONS[4]"/>
<loader-panel v-else/>
</template>
</NuxtLayout>
</template>

<script setup>
import { chartsHints } from '@/utils/hints/chartsHints'
import { CHART_INTERVALS_OPTIONS } from '~/utils/constants'
const { isLoading } = useLoading()
import { CHART_INTERVALS_OPTIONS } from '@/utils/constants'
</script>
5 changes: 4 additions & 1 deletion src/pages/contracts/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
</page-header>

<template v-if="!isLoading">
<contracts-chart-panel class="contracts-panel"/>
<contracts-chart-panel
class="contracts-panel"
:range="CHART_INTERVALS_OPTIONS[0]"/>
<contracts-panel class="contracts-panel"/>
</template>
<loader-panel v-else/>
Expand All @@ -26,6 +28,7 @@
import ContractsPanel from '@/components/ContractsPanel'
import PageHeader from '@/components/PageHeader'
import { contractsHints } from '@/utils/hints/contractsHints'
import { CHART_INTERVALS_OPTIONS } from '@/utils/constants'
const { isLoading } = useLoading()
</script>
Expand Down
16 changes: 16 additions & 0 deletions src/stores/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const useChartsStore = defineStore('charts', () => {

const transactionsStatistics = ref(null)
const keyblocksStatistics = ref(null)
const contractsStatistics = ref(null)

async function fetchTransactionsStatistics(interval, limit, customInterval, txType) {
transactionsStatistics.value = null
Expand Down Expand Up @@ -37,10 +38,25 @@ export const useChartsStore = defineStore('charts', () => {
keyblocksStatistics.value = customInterval ? data.data.reverse() : data.data.slice(1).reverse()
}

async function fetchContractsStatistics(interval, limit, customInterval) {
contractsStatistics.value = null

const intervalSlug = customInterval
? `&min_start_date=${customInterval.minStart}&max_start_date=${customInterval.maxStart}&limit=1000`
: `&interval_by=${interval}&limit=${parseInt(limit) + 1}`

const { data } = await axios.get(`${MIDDLEWARE_URL}/v3/statistics/transactions?tx_type=contract_call${intervalSlug}`)

// remove last interval from the response not to show current interval that is being built
contractsStatistics.value = customInterval ? data.data.reverse() : data.data.slice(1).reverse()
}

return {
keyblocksStatistics,
transactionsStatistics,
contractsStatistics,
fetchKeyblocksStatistics,
fetchTransactionsStatistics,
fetchContractsStatistics,
}
})
14 changes: 0 additions & 14 deletions src/stores/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ export const useContractsStore = defineStore('contracts', () => {
rawContracts.value = data
}

async function fetchContractsStatistics(interval, limit, customInterval) {
contractsStatistics.value = null

const slug = customInterval
? `&min_start_date=${customInterval.minStart}&max_start_date=${customInterval.maxStart}&limit=1000`
: `&interval_by=${interval}&limit=${limit}`

const { data } = await axios.get(`${MIDDLEWARE_URL}/v3/statistics/transactions?tx_type=contract_call${slug}`)

// remove last interval from the response not to show current interval that is being built
contractsStatistics.value = customInterval ? data.data.reverse() : data.data.slice(1).reverse()
}

async function fetchContractsCount() {
contractsCount.value = null
const { data } = await axios.get(`${MIDDLEWARE_URL}/v3/transactions/count?type=contract_create`)
Expand All @@ -65,6 +52,5 @@ export const useContractsStore = defineStore('contracts', () => {
contractsStatistics,
fetchContracts,
fetchContractsCount,
fetchContractsStatistics,
}
})

0 comments on commit a1ddc72

Please sign in to comment.