From 76182a4efebb88d6aa309586b030407a6af0fc41 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Sat, 24 Jul 2021 00:21:15 -0300 Subject: [PATCH 1/3] Remove safeguards and fix small bugs to allow running otterscan against testnets; testing on goerli --- src/Block.tsx | 8 ++++++-- src/Title.tsx | 6 ++++-- src/useProvider.ts | 5 +---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Block.tsx b/src/Block.tsx index 87da28d..3064c99 100644 --- a/src/Block.tsx +++ b/src/Block.tsx @@ -67,8 +67,12 @@ const Block: React.FC = () => { const _block = provider.formatter.block(_rawBlock); const extBlock: ExtendedBlock = { - blockReward: provider.formatter.bigNumber(_rawIssuance.blockReward), - unclesReward: provider.formatter.bigNumber(_rawIssuance.uncleReward), + blockReward: provider.formatter.bigNumber( + _rawIssuance.blockReward ?? 0 + ), + unclesReward: provider.formatter.bigNumber( + _rawIssuance.uncleReward ?? 0 + ), feeReward: fees, size: provider.formatter.number(_rawBlock.size), sha3Uncles: _rawBlock.sha3Uncles, diff --git a/src/Title.tsx b/src/Title.tsx index c64fdbd..46e1e5c 100644 --- a/src/Title.tsx +++ b/src/Title.tsx @@ -1,9 +1,11 @@ -import React, { useState, useRef } from "react"; +import React, { useState, useRef, useContext } from "react"; import { Link, useHistory } from "react-router-dom"; import useKeyboardShortcut from "use-keyboard-shortcut"; import PriceBox from "./PriceBox"; +import { RuntimeContext } from "./useRuntime"; const Title: React.FC = () => { + const { provider } = useContext(RuntimeContext); const [search, setSearch] = useState(); const [canSubmit, setCanSubmit] = useState(false); const history = useHistory(); @@ -43,7 +45,7 @@ const Title: React.FC = () => {
- + {provider?.network.chainId === 1 && }
{ - const provider = new ethers.providers.JsonRpcProvider( - erigonURL, - "mainnet" - ); + const provider = new ethers.providers.JsonRpcProvider(erigonURL); // Check if it is at least a regular ETH node let blockNumber: number = 0; From 26f66cb4fb6bdf8318b3fef3221aa75b267bfd0f Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Sat, 24 Jul 2021 05:33:13 -0300 Subject: [PATCH 2/3] Add different highlight color on testnets --- src/Footer.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Footer.tsx b/src/Footer.tsx index 61d59d7..a934b37 100644 --- a/src/Footer.tsx +++ b/src/Footer.tsx @@ -5,7 +5,13 @@ const Footer: React.FC = () => { const { provider } = useContext(RuntimeContext); return ( -
+
{provider ? ( <>Using Erigon node at {provider.connection.url} ) : ( From fddfbfc29b9c54cab27fec6a5200a86c0dad7b81 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Sat, 24 Jul 2021 05:46:48 -0300 Subject: [PATCH 3/3] Display warning header when not on mainnet --- src/App.tsx | 2 ++ src/WarningHeader.tsx | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/WarningHeader.tsx diff --git a/src/App.tsx b/src/App.tsx index 4a4c323..72326ee 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,6 @@ import React, { Suspense } from "react"; import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; +import WarningHeader from "./WarningHeader"; import Home from "./Home"; import Search from "./Search"; import Title from "./Title"; @@ -26,6 +27,7 @@ const App = () => { ) : (
+ diff --git a/src/WarningHeader.tsx b/src/WarningHeader.tsx new file mode 100644 index 0000000..b21c249 --- /dev/null +++ b/src/WarningHeader.tsx @@ -0,0 +1,28 @@ +import React, { useContext } from "react"; +import { RuntimeContext } from "./useRuntime"; + +const WarningHeader: React.FC = () => { + const { provider } = useContext(RuntimeContext); + const chainId = provider?.network.chainId; + if (chainId === 1) { + return <>; + } + + let chainMsg = `ChainID: ${chainId}`; + if (chainId === 3) { + chainMsg = "Ropsten Testnet"; + } else if (chainId === 4) { + chainMsg = "Rinkeby Testnet"; + } else if (chainId === 5) { + chainMsg = "Görli Testnet"; + } else if (chainId === 42) { + chainMsg = "Kovan Testnet"; + } + return ( +
+ You are on {chainMsg} +
+ ); +}; + +export default React.memo(WarningHeader);