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: Live update transaction details #569

Merged
merged 3 commits into from
Nov 15, 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
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
Loading