Skip to content

Commit

Permalink
feat: Live update transaction details (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
janmichek authored Nov 15, 2023
1 parent 74321b7 commit f80dda8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/stores/recentBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const useRecentBlocksStore = defineStore('recentBlocks', () => {
const rawSelectedMicroblockTransactions = ref(null)
const rawSelectedKeyblock = ref(null)
const rawSelectedMicroblock = ref(null)
const blockHeight = ref(null)

const selectedKeyblock = computed(() => {
return adaptKeyblock(rawSelectedKeyblock.value || keyblocks.value?.[0])
Expand Down Expand Up @@ -57,9 +58,6 @@ export const useRecentBlocksStore = defineStore('recentBlocks', () => {
const latestKeyblockTransactionsCount = computed(() => {
return keyblocks.value?.[0].transactionsCount
})
const blockHeight = computed(() => {
return keyblocks.value?.[0].height
})

/* USER INTERACTION */

Expand Down Expand Up @@ -94,6 +92,11 @@ export const useRecentBlocksStore = defineStore('recentBlocks', () => {
async function fetchKeyblocks() {
const { data } = await axios.get(`${MIDDLEWARE_URL}/v2/key-blocks?&limit=${VISIBLE_KEYBLOCKS_LIMIT}`)
keyblocks.value = data.data
blockHeight.value = data.data[0].height
}

function updateBlockHeight(websocketMessage) {
blockHeight.value = websocketMessage.height
}

// correct transactions and microblock count in past keyblocks to account for microfork changes
Expand Down Expand Up @@ -191,5 +194,6 @@ export const useRecentBlocksStore = defineStore('recentBlocks', () => {
selectedMicroblock,
selectedMicroblockTransactionsCount,
selectedMicroblockTransactions,
updateBlockHeight,
}
})
7 changes: 5 additions & 2 deletions src/stores/webSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTransactionDetailsStore } from '@/stores/transactionDetails'

export const useWebSocket = defineStore('webSocket', () => {
const { WEBSOCKET_URL } = useRuntimeConfig().public
const { processSocketMessage } = useRecentBlocksStore()
const { processSocketMessage, updateBlockHeight } = useRecentBlocksStore()
const { updateTransactionTypeData } = useTransactionDetailsStore()

const webSocket = shallowRef()
Expand Down Expand Up @@ -73,8 +73,11 @@ export const useWebSocket = defineStore('webSocket', () => {
const parsedData = camelcaseKeysDeep(JSON.parse(data))
const isSpecificEntityMessage = parsedData.subscription === 'Object'
const isSubscribedTransactionMessage = parsedData.payload?.hash === subscribedTransactionId.value
const isSubscribedKeyblockMessage = parsedData.subscription === 'KeyBlocks'

if (isSpecificEntityMessage && isSubscribedTransactionMessage) {
if (isSubscribedKeyblockMessage) {
updateBlockHeight(parsedData.payload)
} else if (isSpecificEntityMessage && isSubscribedTransactionMessage) {
updateTransactionTypeData(parsedData.payload)
} else {
await processSocketMessage(parsedData)
Expand Down

0 comments on commit f80dda8

Please sign in to comment.