Skip to content
This repository has been archived by the owner on Feb 27, 2021. It is now read-only.

Commit

Permalink
fix: get stable erpc fetching for pages
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas committed Jun 26, 2019
1 parent e8f21cf commit a855187
Show file tree
Hide file tree
Showing 13 changed files with 2,265 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# dependencies
/node_modules
/services

# testing
/coverage
Expand Down
2,006 changes: 1,983 additions & 23 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
"build": "react-scripts build",
"start": "react-scripts start",
"test": "react-scripts test",
"service-runner": "jade-service-runner",
"lint": "tslint -p tsconfig.json"
},
"dependencies": {
"@etclabscore/ethereum-json-rpc": "^1.0.10",
"@etclabscore/jade-service-runner-client": "^1.0.12",
"@material-ui/core": "^1.4.3",
"bignumber.js": "^4.1.0",
"ethereumjs-util": "^5.2.0",
Expand All @@ -35,6 +37,7 @@
"victory": "^31.3.0"
},
"devDependencies": {
"@etclabscore/jade-service-runner": "^1.1.0",
"@types/bignumber.js": "^4.0.3",
"@types/jest": "^21.1.6",
"@types/node": "^8.0.51",
Expand Down
182 changes: 182 additions & 0 deletions service-runner-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
"$schema": "./lib/service-runner-schema.json",
"services": [
{
"name": "multi-geth",
"rpcPort": "${DYNAMIC_TCP_PORT_1}",
"version": "1.9.2",
"environments": [{
"name": "mainnet",
"args": {
"start": [
"--classic",
"--datadir",
"${SERVICE_DIR}/multi-geth/1.9.0/classic",
"--rpc",
"--rpcport",
"${DYNAMIC_TCP_PORT_1}",
"--rpccorsdomain",
"*"
],
"stop": [],
"teardown": []
},
"health": {
"interval": 20000,
"retries": 5,
"port": "${DYNAMIC_TCP_PORT_1}",
"protocol": "tcp"
}
},
{
"name": "kotti",
"args": {
"start": [
"--kotti",
"--datadir",
"${SERVICE_DIR}/multi-geth/1.9.0/kotti",
"--rpc",
"--rpcport",
"${DYNAMIC_TCP_PORT_1}",
"--rpcaddr",
"localhost",
"--rpccorsdomain",
"*"
],
"stop": [],
"teardown": []
},
"health": {
"interval": 20000,
"retries": 5,
"port": "${DYNAMIC_TCP_PORT_1}",
"protocol": "tcp"
}
},
{
"name": "dev",
"args": {
"start": [
"--dev",
"--datadir",
"${SERVICE_DIR}/multi-geth/1.9.0/dev",
"--rpc",
"--rpcport",
"${DYNAMIC_TCP_PORT_1}",
"--rpccorsdomain",
"*"
],
"stop": [],
"teardown": []
},
"health": {
"interval": 20000,
"retries": 5,
"port": "${DYNAMIC_TCP_PORT_1}",
"protocol": "tcp"
}
},
{
"name": "ethereum",
"args": {
"start": [
"--datadir",
"${SERVICE_DIR}/multi-geth/1.9.0/ethereum",
"--rpc",
"--rpcport",
"${DYNAMIC_TCP_PORT_1}",
"--rpccorsdomain",
"*"
],
"stop": [],
"teardown": []
},
"health": {
"interval": 20000,
"retries": 5,
"port": "${DYNAMIC_TCP_PORT_1}",
"protocol": "tcp"
}
},
{
"name": "goerli",
"args": {
"start": [
"--goerli",
"--datadir",
"${SERVICE_DIR}/multi-geth/1.9.0/goerli",
"--rpc",
"--rpcport",
"${DYNAMIC_TCP_PORT_1}",
"--rpccorsdomain",
"*"
],
"stop": [],
"teardown": []
},
"health": {
"interval": 20000,
"retries": 5,
"port": "${DYNAMIC_TCP_PORT_1}",
"protocol": "tcp"
}
},
{
"name": "rinkeby",
"args": {
"start": [
"--rinkeby",
"--datadir",
"${SERVICE_DIR}/multi-geth/1.9.0/rinkeby",
"--rpc",
"--rpcport",
"${DYNAMIC_TCP_PORT_1}",
"--rpccorsdomain",
"*"
],
"stop": [],
"teardown": []
},
"health": {
"interval": 20000,
"retries": 5,
"port": "${DYNAMIC_TCP_PORT_1}",
"protocol": "tcp"
}
}
],
"os": {
"osx": {
"commands": {
"setup": [
{
"cmd": "chmod",
"args": [
"+x",
"${SERVICE_DIR}/geth"
]
}
],
"start": "${SERVICE_DIR}/geth",
"stop": "",
"teardown": ""
},
"assets": [
"https://github.com/multi-geth/multi-geth/releases/download/v1.9.2/multi-geth-osx.zip"
]
},
"linux": {
"commands": {
"setup": [],
"start": "geth",
"stop": "",
"teardown": ""
},
"assets": [
"https://github.com/multi-geth/multi-geth/releases/download/v1.9.2/multi-geth-linux.zip"
]
}
}
}
]
}
4 changes: 3 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import NodeView from "./containers/NodeView";
import Transaction from "./containers/Transaction";

import "./App.css";
import useMultiGeth from "./erpc";

const routes = [
{ path: "/", component: Dashboard, title: "Dashboard", exact: true },
Expand All @@ -18,6 +19,7 @@ const routes = [
];

function App(props: any) {
const [erpc] = useMultiGeth("1.9.1", "mainnet");
return (
<>
<AppBar position="static" color="default" elevation={0}>
Expand All @@ -33,7 +35,7 @@ function App(props: any) {
<Card>
<CardHeader title={routeProps.title} />
<CardContent>
{routeProps.component({ ...p })}
{routeProps.component({ ...p, erpc })}
</CardContent>
</Card>
);
Expand Down
14 changes: 8 additions & 6 deletions src/containers/Address.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import ERPC from "@etclabscore/ethereum-json-rpc";
import { CircularProgress } from "@material-ui/core";
import * as React from "react";
import usePromise from "react-use-promise";
import AddressView from "../components/AddressView";
import erpc from "../erpc";
import { useBlockNumber } from "../helpers";

const unit = require("ethjs-unit");

export default function Address(props: any) {
const { address } = props.match.params;
const [blockNumber] = useBlockNumber();
export default function Address({erpc, match}: {erpc: ERPC, match: {params: {address: string}}}) {
const { address } = match.params;
const [blockNumber] = useBlockNumber(erpc);
const [result, error, state] = usePromise(
async () => {
if (blockNumber === undefined) {
if (blockNumber === undefined || !erpc) {
return;
}
const hexBlockNumber = `0x${blockNumber.toString(16)}`;
Expand All @@ -26,7 +28,7 @@ export default function Address(props: any) {
return (<div>Oops. there was an error. try again later: {error.message}</div>)
}
if (!result) {
return null;
return <CircularProgress />;
}
const { transactionCount, balance, code } = result;
return (
Expand Down
11 changes: 7 additions & 4 deletions src/containers/Block.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { CircularProgress } from "@material-ui/core";
import * as React from "react";
import usePromise from "react-use-promise";
import BlockView from "../components/BlockView";
import erpc from "../erpc";

export default function Block(props: any) {
const { match: { params: { hash } } } = props;
const [block, error, state] = usePromise(() => erpc.eth_getBlockByHash(hash, true), [hash]);
const { erpc, match: { params: { hash } } } = props;
const [block, error, state] = usePromise(() => {
if (!erpc) { return; }
return erpc.eth_getBlockByHash(hash, true);
}, [hash]);
if (error) { return (<div> Error: {error} </div>); }
if (!block) { return; }
if (!block) { return (<CircularProgress />); }
return (<BlockView block={block} />);
}
11 changes: 8 additions & 3 deletions src/containers/BlockList.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import ERPC from "@etclabscore/ethereum-json-rpc";
import { CircularProgress } from "@material-ui/core";
import * as React from "react";
import usePromise from "react-use-promise";
import BlockList from "../components/BlockList";
import getBlocks from "../helpers";
import { CircularProgress } from "@material-ui/core";

interface IProps {
from: number;
to: number;
erpc: ERPC;
}

export default function BlockListContainer(props: IProps) {
const { from, to } = props;
const [blocks, error, state] = usePromise(() => getBlocks(from, to), [from, to]);
const { from, to, erpc } = props;
const [blocks, error, state] = usePromise(async () => {
if (!erpc) { return; }
return getBlocks(from, to, erpc);
}, [from, to]);
if (!blocks && state === "pending") {
return <CircularProgress />;
}
Expand Down
13 changes: 7 additions & 6 deletions src/containers/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ERPC from "@etclabscore/ethereum-json-rpc";
import { Button, Grid, Typography, CircularProgress } from "@material-ui/core";
import BigNumber from "bignumber.js";
import * as React from "react";
Expand All @@ -6,7 +7,6 @@ import { VictoryBar, VictoryChart, VictoryLabel } from "victory";
import { hashesToGH, weiToGwei } from "../components/formatters";
import HashChart from "../components/HashChart";
import HashRate from "../components/HashRate";
import erpc from "../erpc";
import getBlocks, { useBlockNumber } from "../helpers";
import BlockList from "./BlockList";

Expand Down Expand Up @@ -55,7 +55,7 @@ const getStyles = () => {
};
};

const useDashboardInfo = (blockNumber: number): any => {
const useDashboardInfo = (blockNumber: number, erpc: any): any => {
const [dashboardResults, setDashboardResults] = React.useState();

const [, error, state] = usePromise(async () => {
Expand All @@ -65,6 +65,7 @@ const useDashboardInfo = (blockNumber: number): any => {
const rangeOfBlocks: any[] = await getBlocks(
Math.max(blockNumber - config.blockHistoryLength + 1, 0),
blockNumber,
erpc,
);
const gp: number = parseInt(await erpc.eth_gasPrice(), 16);
const r = {
Expand All @@ -81,10 +82,10 @@ const useDashboardInfo = (blockNumber: number): any => {
return [dashboardResults, error, state];
};

export default (props: any) => {
export default ({erpc}: {erpc: ERPC}) => {
const styles = getStyles();
const [blockNumber] = useBlockNumber();
const [results, error, state] = useDashboardInfo(blockNumber);
const [blockNumber] = useBlockNumber(erpc);
const [results, error, state] = useDashboardInfo(blockNumber, erpc);
if (error && !results) {
return (<div>Oops. Something went wrong. Please try again. <br /><br /><code>{error.message}</code></div>);
}
Expand Down Expand Up @@ -170,7 +171,7 @@ export default (props: any) => {
Last 10 blocks
</Typography>
<Button href={"/blocks"}>View All</Button>
<BlockList from={Math.max(blockNumber - 11, 0)} to={blockNumber} />
<BlockList from={Math.max(blockNumber - 11, 0)} to={blockNumber} erpc={erpc}/>
</Grid>
</Grid>
</div>
Expand Down
15 changes: 9 additions & 6 deletions src/containers/NodeView.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import ERPC from "@etclabscore/ethereum-json-rpc";
import { CircularProgress } from "@material-ui/core";
import * as React from "react";
import { useBlockNumber } from "../helpers";
import BlockList from "./BlockList";

import usePromise from "react-use-promise";
import erpc from "../erpc";

export default function NodeView(props: any) {
const [blockNumber, error, state] = usePromise(() => erpc.eth_blockNumber(), []);
export default function NodeView({erpc}: {erpc: ERPC}) {
const [blockNumber] = useBlockNumber(erpc);
if (!blockNumber) {
return (<CircularProgress />);
}
return (
<BlockList from={Math.max(parseInt(blockNumber, 16) - 15, 0)} to={parseInt(blockNumber, 16)} />
<BlockList from={Math.max(blockNumber - 15, 0)} to={blockNumber} erpc={erpc}/>
);
}
Loading

0 comments on commit a855187

Please sign in to comment.