Skip to content

Commit

Permalink
fix: useSWRImmutable instead of useSwr in some data
Browse files Browse the repository at this point in the history
  • Loading branch information
tiendn committed Mar 27, 2023
1 parent 66be673 commit 5e9a678
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import clsx from 'clsx'
import React, { ReactNode, useEffect } from 'react'
import { setAstraSummary, setValidatorSummary } from 'slices/commonSlice'
import useSWR from 'swr'
import useSWRImmutable from 'swr/immutable'
import { selectTheme } from '../slices/themeSlice'
import { useAppDispatch, useAppSelector } from '../store/hooks'
import styles from './Layout.module.scss'
Expand Down Expand Up @@ -34,7 +35,7 @@ const Layout: React.FC<Props> = props => {
}
}
const { data: marketPriceDataRaw } = useSWR<MarketPriceResponse>(_fetchCondition('market_price'))
const { data: validatorSummaryRaw } = useSWR<ValidatorResponse>(_fetchCondition('validator'), {
const { data: validatorSummaryRaw } = useSWRImmutable<ValidatorResponse>(_fetchCondition('validator'), {
refreshInterval: 60000
})
const validatorSummary = getValidatorSummary(validatorSummaryRaw)
Expand Down
4 changes: 2 additions & 2 deletions views/transactions/hook/useInternalTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import API_LIST from 'api/api_list'
import { formatEther } from 'ethers/lib/utils'
import useDelayUntilDone from 'hooks/useDelayUntilDone'
import { useCallback } from 'react'
import useSWR from 'swr'
import useSWRImmutable from 'swr/immutable'
import { evmInternalTransactionType } from 'utils/evm'
import { upperCaseFirstLetterOfWord } from 'utils/helper'
import { TransactionRowProps } from '../TransactionRow'
Expand All @@ -12,7 +12,7 @@ export default function useInternalTransactions({ hash }: { hash: string }) {
const _fetchCondition = () => {
return !!hash ? [`${API_LIST.EVM_INTERNAL_TRANSACTION}${hash}`] : null
}
const { data, error } = useSWR<InternalTransactionReponse>(_fetchCondition(), {
const { data, error } = useSWRImmutable<InternalTransactionReponse>(_fetchCondition(), {
refreshInterval: 0
})

Expand Down
6 changes: 4 additions & 2 deletions views/transactions/hook/useTxRawTrace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import API_LIST from 'api/api_list'
import { useEffect, useState } from 'react'
import useSWR from 'swr'
import useSWRImmutable from 'swr/immutable'

export default function useTxRawTrace(txhash: string, type: 'evm' | 'cosmos') {
const [hookData, setState] = useState<any>({ result: '' })
Expand All @@ -10,7 +10,9 @@ export default function useTxRawTrace(txhash: string, type: 'evm' | 'cosmos') {

return [`${API_LIST.TRANSACTION_RAW_TRACE}${txhash}`]
}
const { data } = useSWR<TransactionRawTraceResponse>(_fetchCondition())
const { data } = useSWRImmutable<TransactionRawTraceResponse>(_fetchCondition(), {
refreshInterval: 0
})

useEffect(() => {
if (data?.result) {
Expand Down

0 comments on commit 5e9a678

Please sign in to comment.