15c3012199
* explorer-api: add nym node endpoints + UI to show nym-nodes and account balances * explorer-api: add endpoints to get operator rewards explorer-ui: show delegations on nym-nodes, show operator rewards, bug fixes * explorer-ui: change summary screen to only show nym-node stats * explorer-api: add unstable routes to get legacy mixnodes and gateways from the contract instead of the Nym API explorer-ui: adapt front-end to show less information in legacy nodes with plain bond types * explorer-ui: fix up source of legacy mixnode data * explorer-ui: add more account page null and undefined checks * explorer-ui: filter out null gateway versions * explorer-ui: sanitise gateway versions * explorer-ui: add more guards on the balance parts to check that greater than 0 * explorer-api: make /tmp/unstable/gateways endpoint compatible with the current Harbour Master API * explorer-ui: fix typo * cargo fmt * Add node-id, total stake and links to nodes list --------- Co-authored-by: Mark Sinclair <mmsinclair@users.noreply.github.com> Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com>
78 lines
2.0 KiB
TypeScript
78 lines
2.0 KiB
TypeScript
'use client'
|
|
|
|
import * as React from 'react'
|
|
import {
|
|
ApiState,
|
|
NymNodeReportResponse,
|
|
UptimeStoryResponse,
|
|
} from '@/app/typeDefs/explorer-api'
|
|
import { Api } from '@/app/api'
|
|
import { useApiState } from './hooks'
|
|
|
|
/**
|
|
* This context provides the state for a single gateway by identity key.
|
|
*/
|
|
|
|
interface NymNodeState {
|
|
uptimeReport?: ApiState<NymNodeReportResponse>
|
|
uptimeHistory?: ApiState<UptimeStoryResponse>
|
|
}
|
|
|
|
export const NymNodeContext = React.createContext<NymNodeState>({})
|
|
|
|
export const useNymNodeContext = (): React.ContextType<typeof NymNodeContext> =>
|
|
React.useContext<NymNodeState>(NymNodeContext)
|
|
|
|
/**
|
|
* Provides a state context for a gateway by identity
|
|
* @param gatewayIdentityKey The identity key of the gateway
|
|
*/
|
|
export const NymNodeContextProvider = ({
|
|
nymNodeId,
|
|
children,
|
|
}: {
|
|
nymNodeId: string
|
|
children: JSX.Element
|
|
}) => {
|
|
const [uptimeReport, fetchUptimeReportById, clearUptimeReportById] =
|
|
useApiState<any>(
|
|
nymNodeId,
|
|
Api.fetchNymNodePerformanceById,
|
|
'Failed to fetch gateway uptime report by id'
|
|
)
|
|
|
|
const [uptimeHistory, fetchUptimeHistory, clearUptimeHistory] =
|
|
useApiState<UptimeStoryResponse>(
|
|
nymNodeId,
|
|
async (arg) => {
|
|
const res = await Api.fetchNymNodeUptimeHistoryById(arg);
|
|
const uptimeHistory: UptimeStoryResponse = {
|
|
history: res.history.data,
|
|
identity: '',
|
|
owner: '',
|
|
}
|
|
return uptimeHistory;
|
|
},
|
|
'Failed to fetch gateway uptime history'
|
|
)
|
|
|
|
React.useEffect(() => {
|
|
// when the identity key changes, remove all previous data
|
|
clearUptimeReportById()
|
|
clearUptimeHistory()
|
|
Promise.all([fetchUptimeReportById(), fetchUptimeHistory()])
|
|
}, [nymNodeId])
|
|
|
|
const state = React.useMemo<NymNodeState>(
|
|
() => ({
|
|
uptimeReport,
|
|
uptimeHistory,
|
|
}),
|
|
[uptimeReport, uptimeHistory]
|
|
)
|
|
|
|
return (
|
|
<NymNodeContext.Provider value={state}>{children}</NymNodeContext.Provider>
|
|
)
|
|
}
|