Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Aug 14, 2023
1 parent 5aaf785 commit 4e7d336
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 70 deletions.
2 changes: 1 addition & 1 deletion packages/browser-client/src/Components/CircleNetwork.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ENR } from 'portalnetwork'
import { lightblue } from '../App'

import React from 'react'
interface NetworkProps {
peers: ENR[] | undefined
distances: [number, string[]][]
Expand Down
4 changes: 2 additions & 2 deletions packages/browser-client/src/Components/ContentManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default function ContentManager() {
type: StateChange.SETBLOCK,
payload: await ethJsBlockToEthersBlockWithTxs(
Block.fromRLPSerializedBlock(Buffer.from(fromHexString(last[1].rlp)), {
hardforkByBlockNumber: true,
})
setHardfork: true,
}),
),
})
}
Expand Down
6 changes: 3 additions & 3 deletions packages/browser-client/src/Components/GetByButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo, useState } from 'react'
import { Box, MenuButton, Menu, MenuList, Button, MenuItem, HStack } from '@chakra-ui/react'
import React, { useState } from 'react'
import { MenuButton, Menu, MenuList, Button, MenuItem, HStack } from '@chakra-ui/react'
import { ChevronDownIcon } from '@chakra-ui/icons'
import GetBlockByNumber from './GetBlockByNumber'
import GetEpoch from './GetEpoch'
Expand All @@ -11,7 +11,7 @@ export default function GetByButtons() {
eth_getBlockByHash = 1,
portal_getEpochByIndex = 2,
}
const buttons: Record<GetBy, JSX.Element> = {
const buttons: Record<GetBy, React.JSX.Element> = {
0: <GetBlockByNumber />,
1: <GetBlockByHash />,
2: <GetEpoch />,
Expand Down
6 changes: 2 additions & 4 deletions packages/browser-client/src/Components/GetEpoch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import {
ContentLookup,
ContentType,
EpochAccumulator,
epochRootByBlocknumber,
epochRootByIndex,
fromHexString,
getContentId,
getContentKey,
HistoryProtocol,
MAX_HISTORICAL_EPOCHS,
Expand All @@ -25,11 +23,11 @@ export default function GetEpoch() {
async function sendFindEpoch(): Promise<string> {
const epochRootHash = await epochRootByIndex(epochIndex)
const protocol = state.provider!.portal.protocols.get(
ProtocolId.HistoryNetwork
ProtocolId.HistoryNetwork,
) as HistoryProtocol
const lookup = new ContentLookup(
protocol,
fromHexString(getContentKey(ContentType.EpochAccumulator, epochRootHash))
fromHexString(getContentKey(ContentType.EpochAccumulator, epochRootHash)),
)
const epoch = await lookup.startLookup()
if (epoch !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-client/src/Components/PeerButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function PeerButtons() {
peerState,
peerDispatch,
},
state.provider!.historyProtocol
state.provider!.historyProtocol,
)

useEffect(() => {
Expand Down
15 changes: 11 additions & 4 deletions packages/browser-client/src/Components/PortalButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ import {
import { ChevronDownIcon, SearchIcon } from '@chakra-ui/icons'
import { AppContext, AppContextType, StateChange } from '../globalReducer'
import { PeerActions } from '../peerActions'
import { ENR, fromHexString, getContentId, getContentKey, ContentType } from 'portalnetwork'
import {
ENR,
fromHexString,
getContentId,
getContentKey,
ContentType,
ProtocolId,
} from 'portalnetwork'
import { PeerContext, PeerContextType, PeerStateChange } from '../peerReducer'

enum GetBy {
Expand Down Expand Up @@ -51,11 +58,11 @@ export function PortalButton(props: IPortalButton) {
peerState,
peerDispatch,
},
state.provider!.historyProtocol
state.provider!.historyProtocol,
)
const [offer, setOffer] = useState<string[]>([])
const [blockHash, setBlockhash] = useState<string>(
'0x2d33dc73755afbbbeb6ec4885f2923398901bf1ad94beb325a4c4ecad5bf0f1c'
'0x2d33dc73755afbbbeb6ec4885f2923398901bf1ad94beb325a4c4ecad5bf0f1c',
)
useEffect(() => {
setInput(blockHash)
Expand All @@ -64,7 +71,7 @@ export function PortalButton(props: IPortalButton) {
const addToOffer = async (type: ContentType) => {
const contentKey = getContentKey(type, Buffer.from(fromHexString(blockHash)))
const contentId = getContentId(type, blockHash)
if (await state.provider?.historyProtocol.get(contentKey)) {
if (await state.provider?.historyProtocol.get(ProtocolId.HistoryNetwork, contentKey)) {
setOffer([...offer, contentId])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import PeerButtons from './PeerButtons'
import { AppContext, AppContextType, StateChange } from '../globalReducer'
import { PeerContext, peerInitialState, peerReducer } from '../peerReducer'
import { ENR } from 'portalnetwork'

export default function RoutingTableView() {
const { state, dispatch } = useContext(AppContext as React.Context<AppContextType>)
Expand Down
20 changes: 2 additions & 18 deletions packages/browser-client/src/Components/SelectTx.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import {
Menu,
MenuButton,
Button,
MenuList,
MenuOptionGroup,
MenuItemOption,
VStack,
Heading,
Box,
HStack,
Input,
Select,
Text,
} from '@chakra-ui/react'
// eslint-disable-next-line implicit-dependencies/no-implicit
import { useContext, useEffect, useMemo, useState } from 'react'
import { VStack, Box, HStack, Input, Text } from '@chakra-ui/react'
import React, { useContext, useEffect, useMemo, useState } from 'react'
import DisplayTx from './DisplayTx'
import React from 'react'
import { AppContext, AppContextType } from '../globalReducer'
import { ExtendedEthersBlockWithTransactions } from 'portalnetwork'

Expand Down
34 changes: 0 additions & 34 deletions packages/browser-client/src/Components/ValidateAccumulator.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions packages/browser-client/src/Components/getBlockByHash.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { SearchIcon } from '@chakra-ui/icons'
import { Button, FormControl, HStack, IconButton, Input } from '@chakra-ui/react'
import { FormControl, HStack, IconButton, Input } from '@chakra-ui/react'
import React, { useContext, useEffect, useState } from 'react'
import { AppContext, AppContextType, StateChange } from '../globalReducer'

export default function GetBlockByHash() {
const { state, dispatch } = useContext(AppContext as React.Context<AppContextType>)
const [blockHash, setBlockhash] = useState(
'0xb495a1d7e6663152ae92708da4843337b958146015a2802f4193a410044698c9'
'0xb495a1d7e6663152ae92708da4843337b958146015a2802f4193a410044698c9',
)
async function eth_getBlockByHash(blockHash: string, includeTransactions: boolean) {
try {
Expand Down

0 comments on commit 4e7d336

Please sign in to comment.