Skip to content

Commit

Permalink
feat: use certificate subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiendan committed Jan 29, 2024
1 parent a4f98eb commit d276a0f
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 275 deletions.
74 changes: 22 additions & 52 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import {
import useToposSubnetGetFromEndpoint from './hooks/useToposSubnetGetFromEndpoint'
import AppInternals from './AppInternals'
import { TourRefsContext } from './contexts/tourRefs'
import useSubnetGetLatestBlockNumber from './hooks/useSubnetGetLatestBlockNumber'
import { CrossSubnetMessagesGraphContext } from './contexts/crossSubnetMessagesGraph'

const Errors = styled.div`
margin: 1rem auto;
Expand All @@ -52,9 +50,6 @@ const App = () => {
const [errors, setErrors] = useState<string[]>([])
const { registeredSubnets } = useRegisteredSubnets(selectedToposSubnet)
const { getToposSubnetFromEndpoint } = useToposSubnetGetFromEndpoint()
const [subnetsLatestBlockNumbers, setSubnetsLatestBlockNumbers] =
useState<Map<string, number>>()
const { getSubnetLatestBlockNumber } = useSubnetGetLatestBlockNumber()

const tourRefs = {
MenuRef: useRef<HTMLDivElement>(null),
Expand Down Expand Up @@ -127,27 +122,6 @@ const App = () => {
[routeParamsProcessing, subnets]
)

useEffect(() => {
async function getSubnetsLatestBlockNumbers() {
if (subnets) {
const newSubnetsLatestBlockNumbers = new Map<string, number>()
await Promise.all(
subnets.map(async (subnet) => {
const latestBlockNumber = await getSubnetLatestBlockNumber(subnet)

if (latestBlockNumber !== undefined) {
newSubnetsLatestBlockNumbers.set(subnet.id, latestBlockNumber)
}
})
)

setSubnetsLatestBlockNumbers(newSubnetsLatestBlockNumbers)
}
}

getSubnetsLatestBlockNumbers()
}, [subnets])

return (
<ThemeProvider theme={theme}>
<BrowserRouter>
Expand All @@ -168,32 +142,28 @@ const App = () => {
>
<SubnetsContext.Provider value={{ data: subnets }}>
<BlocksContext.Provider value={blocks}>
<CrossSubnetMessagesGraphContext.Provider
value={{ subnetsLatestBlockNumbers }}
>
<TourRefsContext.Provider value={tourRefs}>
<AppInternals>
<Layout>
<Header />
{Boolean(errors.length) && (
<Errors>
{errors.map((e) => (
<Alert
type="error"
showIcon
closable
message={e}
key={e}
/>
))}
</Errors>
)}
<Content />
<Footer />
</Layout>
</AppInternals>
</TourRefsContext.Provider>
</CrossSubnetMessagesGraphContext.Provider>
<TourRefsContext.Provider value={tourRefs}>
<AppInternals>
<Layout>
<Header />
{Boolean(errors.length) && (
<Errors>
{errors.map((e) => (
<Alert
type="error"
showIcon
closable
message={e}
key={e}
/>
))}
</Errors>
)}
<Content />
<Footer />
</Layout>
</AppInternals>
</TourRefsContext.Provider>
</BlocksContext.Provider>
</SubnetsContext.Provider>
</SelectedNetworksContext.Provider>
Expand Down
14 changes: 3 additions & 11 deletions src/AppInternals.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ReactNode, useContext } from 'react'

import { BlocksContext } from './contexts/blocks'
import { SelectedNetworksContext } from './contexts/selectedNetworks'
import useSubnetSubscribeToCertificates from './hooks/useSubnetSubscribeToCertificates'
import { CertificatesContext } from './contexts/certificates'
Expand All @@ -18,17 +17,10 @@ interface Props {

const AppInternals = ({ children }: Props) => {
const { selectedSubnet } = useContext(SelectedNetworksContext)
const blocks = useContext(BlocksContext)
const { certificates } = useSubnetSubscribeToCertificates({
sourceSubnetIds: selectedSubnet
? [
{
position: blocks[0]?.number,
sourceSubnetId: { value: selectedSubnet.id },
},
]
: undefined,
limit: 1,
filter: {
source: selectedSubnet?.id,
},
})

return (
Expand Down
12 changes: 6 additions & 6 deletions src/__generated__/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d276a0f

Please sign in to comment.