Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add microblocks transactions filtering #562

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/components/MicroblockTransactionsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
v-model:page-index="pageIndex"
:entities="transactions"
pagination-style="history"
:total-count="microblockDetails.transactions_count"
:limit="limit"
@prev-clicked="loadPrevTransactions"
@next-clicked="loadNextTransactions">
<template #header>
<transactions-select v-model="selectedTxType"/>
</template>
<microblock-transactions-table
:transactions="transactions"
class="u-hidden-mobile"/>
Expand All @@ -20,13 +22,16 @@
<script setup>
import { storeToRefs } from 'pinia'
import { ref } from 'vue'
import { useRouter } from '#app'
import { useMicroblockDetailsStore } from '@/stores/microblockDetails'
import PaginatedContent from '@/components/PaginatedContent'
import { TX_TYPES_OPTIONS } from '~/utils/constants'

const { push } = useRouter()
const microblockDetailsStore = useMicroblockDetailsStore()
const { microblockTransactions: transactions, microblockDetails } = storeToRefs(microblockDetailsStore)
const { microblockTransactions: transactions } = storeToRefs(microblockDetailsStore)
const { fetchMicroblockTransactions } = microblockDetailsStore

const selectedTxType = ref(TX_TYPES_OPTIONS[0])
const route = useRoute()
const pageIndex = ref(1)
const limit = computed(() => process.client && isDesktop() ? 10 : 3)
Expand All @@ -39,10 +44,24 @@ function loadNextTransactions() {
fetchMicroblockTransactions({ queryParameters: transactions.value.next })
}

async function loadTransactions() {
const { txType } = route.query
const txTypeOption = TX_TYPES_OPTIONS.find(option => option.typeQuery === txType)
selectedTxType.value = txTypeOption || TX_TYPES_OPTIONS[0]
await fetchMicroblockTransactions({ queryParameters: `/v2/micro-blocks/${route.params.id}/txs/?limit=${limit.value}${selectedTxType.value.typeQuery ? '&type=' + selectedTxType.value.typeQuery : ''}` })
pageIndex.value = 1
}

if (process.client) {
fetchMicroblockTransactions({
limit: limit.value,
microblockHash: route.params.id,
watch(() => route.fullPath, () => {
loadTransactions()
})
watch(selectedTxType, () => {
const typeQuery = selectedTxType.value?.typeQuery
const slug = `${typeQuery ? '?txType=' + typeQuery : ''}`
push(`/microblocks/${route.params.id}${slug}`)
})

loadTransactions()
}
</script>
1 change: 1 addition & 0 deletions src/components/TransactionsSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:options="TX_TYPES_OPTIONS"
track-by="typeQuery"
label="label"
:hide-selected="true"
placeholder="Select Tx Type"/>
</template>

Expand Down
Loading