Skip to content

Commit

Permalink
fix(Chat): fix inconsistent transaction status
Browse files Browse the repository at this point in the history
  • Loading branch information
bludnic committed Aug 5, 2024
1 parent 28eff49 commit 2524c8f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/components/transactions/hooks/useTransactionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useTransactionStatus(
if (isFetching.value) return TransactionStatus.PENDING
if (queryStatus.value === 'error') return TransactionStatus.REJECTED
if (queryStatus.value === 'success') {
if (inconsistentStatus?.value) return TransactionStatus.UNKNOWN
if (inconsistentStatus?.value) return TransactionStatus.INVALID

return TransactionStatus.CONFIRMED
}
Expand Down
22 changes: 6 additions & 16 deletions src/hooks/queries/transaction/useTransactionStatusQuery.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
import { computed, MaybeRef, unref } from 'vue'
import { MaybeRef, unref } from 'vue'
import { useInconsistentStatus } from '@/components/transactions/hooks/useInconsistentStatus'
import { CryptoSymbol, TransactionStatus, TransactionStatusType } from '@/lib/constants'
import { useTransactionStatus } from '@/components/transactions/hooks/useTransactionStatus'
import { CryptoSymbol } from '@/lib/constants'
import { useTransactionQuery } from './useTransactionQuery'

export function useTransactionStatusQuery(
transactionId: MaybeRef<string>,
crypto: MaybeRef<CryptoSymbol>
) {
const {
status: fetchStatus,
status: queryStatus,
isFetching,
data: transaction,
refetch
} = useTransactionQuery(transactionId, unref(crypto))
const inconsistentStatus = useInconsistentStatus(transaction, unref(crypto))

const status = computed<TransactionStatusType>(() => {
if (isFetching.value) return TransactionStatus.PENDING
if (fetchStatus.value === 'error') return TransactionStatus.REJECTED
if (fetchStatus.value === 'success') {
if (inconsistentStatus.value) return TransactionStatus.UNKNOWN

return TransactionStatus.CONFIRMED
}

return TransactionStatus.UNKNOWN
})
const status = useTransactionStatus(isFetching, queryStatus, inconsistentStatus)

return {
fetchStatus,
queryStatus,
inconsistentStatus,
status,
refetch
Expand Down
6 changes: 3 additions & 3 deletions src/providers/TransactionProvider.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<slot
:status="status"
:fetch-status="fetchStatus"
:query-status="queryStatus"
:inconsistentStatus="inconsistentStatus"
:refetch="refetch"
/>
Expand All @@ -27,14 +27,14 @@ export default defineComponent({
}
},
setup(props) {
const { fetchStatus, status, inconsistentStatus, refetch } = useTransactionStatusQuery(
const { queryStatus, status, inconsistentStatus, refetch } = useTransactionStatusQuery(
props.txId,
props.crypto
)
const statusIcon = computed(() => tsIcon(status.value))
return {
fetchStatus,
queryStatus,
status,
inconsistentStatus,
statusIcon,
Expand Down

0 comments on commit 2524c8f

Please sign in to comment.