Skip to content

Commit

Permalink
skip requesting testnet invocation stats (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje authored Jun 4, 2024
1 parent 38dd3f3 commit 0e481cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
25 changes: 9 additions & 16 deletions src/actions/contractActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,31 +232,24 @@ export function fetchContracts(network: string, protocol: string, page = 1) {
}
}

export function fetchContractsInvocations() {
export function fetchMainnetContractsInvocations() {
return async (
dispatch: ThunkDispatch<State, void, Action>,
getState: () => { contract: State },
): Promise<void> => {
if (shouldFetchContractsInvocations(getState())) {
dispatch(requestContractsInvocations())
try {
const res = await Promise.all(
SUPPORTED_PLATFORMS.map(async ({ network, protocol }) => {
const result = await NeoRest.invocationStats(network)
if (result) {
return result.map(d => ({
...d,
network,
protocol,
}))
}
}),
)
const cleanedContracts = res.flat().filter(r => r !== undefined)
const sortedContract = cleanedContracts
const invocationResponse = await NeoRest.invocationStats('mainnet')
const result = invocationResponse.map(r => ({
...r,
network: 'mainnet',
protocol: 'neo3',
}))
const sortedContracts = result
.flat()
.sort((a, b) => (a!.count < b!.count ? 1 : -1))
dispatch(requestContractsInvocationsSuccess(sortedContract))
dispatch(requestContractsInvocationsSuccess(sortedContracts))
} catch (e: any) {
dispatch(requestContractsInvocationsError(e))
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/contract-invocation/ContractsInvocations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MOCK_CONTRACTS_INVOCATIONS_DATA } from '../../utils/mockData'
import List from '../../components/list/List'
import './ContractsInvocations.scss'
import { State as ContractState } from '../../reducers/contractReducer'
import { fetchContractsInvocations } from '../../actions/contractActions'
import { fetchMainnetContractsInvocations } from '../../actions/contractActions'
import useWindowWidth from '../../hooks/useWindowWidth'
import { Link } from 'react-router-dom'
import { ROUTES } from '../../constants'
Expand Down Expand Up @@ -101,7 +101,8 @@ const ContractsInvocations: React.FC<{}> = () => {
}

useEffect(() => {
if (!contractsInvocations.length) dispatch(fetchContractsInvocations())
if (!contractsInvocations.length)
dispatch(fetchMainnetContractsInvocations())
}, [contractsInvocations, dispatch])

const columns =
Expand Down

0 comments on commit 0e481cc

Please sign in to comment.