Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rpc list #68

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6b2ed4d
Revert "Shutdown notice."
0xngmi Mar 6, 2022
6dd9534
remove multichain & add sorting by chain
0xngmi Mar 6, 2022
f3120c6
add SSR and optimize
0xngmi Mar 6, 2022
c2ab136
change favicon
0xngmi Mar 6, 2022
d063d33
move chains.js
0xngmi Mar 6, 2022
211de94
add yarn.lock
0xngmi Mar 6, 2022
83e4cca
remove unused code
0xngmi Mar 6, 2022
0f96aba
add fathom
0xngmi Mar 6, 2022
4ba7128
add testnets switch
mintdart Mar 6, 2022
d89f901
add chainlist.org domain
0xngmi Mar 7, 2022
ac9d711
add chain icons
mintdart Mar 7, 2022
b5be804
rework chain icons
0xngmi Mar 8, 2022
ea313b4
move testnet toggle to header
mintdart Mar 8, 2022
15a06d1
add rpc list url table
mintdart Mar 12, 2022
48183db
fix sorting url list by height and latency
mintdart Mar 12, 2022
7124483
add loading indicator
mintdart Mar 13, 2022
f43f870
try using axios to calc latency
mintdart Mar 14, 2022
ee04ded
add extra rpcs
0xngmi Mar 14, 2022
2cbf2f1
update rpcs
0xngmi Mar 14, 2022
d00a250
update header styles
mintdart Mar 15, 2022
5bc4549
include option to add network with different rpc urls
mintdart Mar 15, 2022
e0fdea5
cleanup
mintdart Mar 15, 2022
426c57a
show data of websocket server nodes
mintdart Mar 16, 2022
a4b3957
add trust score sto rpc urls
mintdart Mar 17, 2022
3b31001
Update index.js
0xngmi Mar 17, 2022
a6b1b75
smol fix
0xngmi Mar 18, 2022
c4a998b
update table header
mintdart Mar 18, 2022
3e1bce4
fix harmony rpcs
0xngmi Mar 18, 2022
001eaf5
remove add to wallet buttons for eth mainnet urls
mintdart Mar 18, 2022
2646662
add link to docs on how to add endpoints manually
mintdart Mar 18, 2022
49e4131
cleanup
mintdart Mar 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions components/RPCList/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Paper } from '@material-ui/core';
import { useEffect } from 'react';
import { useRPCData } from '../../utils/utils';
import classes from './index.module.css';

export default function RPCList({ chain }) {
const { data } = useRPCData(chain.rpc);
const darkMode = window.localStorage.getItem('yearn.finance-dark-mode') === 'dark';

useEffect(() => {
// clear network resources list for better performance to find latency of each rpc url
window.performance.clearResourceTimings();

const interval = setInterval(() => {
window.performance.clearResourceTimings();
}, 15000);

return () => clearInterval(interval);
}, []);

return (
<Paper elevation={1} className={classes.disclosure}>
<table
className={classes.table}
style={{ '--border-color': darkMode ? 'hsl(0deg 0% 39% / 33%)' : 'hsl(0deg 0% 17% / 4%)' }}
>
<caption>{`${chain.name} RPC URL List`}</caption>
<thead>
<tr>
<th>RPC Server Address</th>
<th>Height</th>
<th>Latency</th>
<th></th>
</tr>
</thead>
<tbody>
{data?.map((item, index) => (
<tr key={index}>
<td>{item.url}</td>
<td>{item.height}</td>
<td>{item.latency}</td>
<td>Add to Wallet</td>
</tr>
))}
</tbody>
</table>
</Paper>
);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32 changes: 32 additions & 0 deletions components/RPCList/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.disclosure {
grid-column: 1 / -1;
position: relative;
padding: 30px;
overflow-x: auto;
}

.table {
border-collapse: collapse;
margin: 0 auto;
}

.table {
white-space: nowrap;
}

.table caption,
.table th,
.table td {
padding: 2px 12px;
border: 1px solid var(--border-color);
}

.table caption {
font-size: 1rem;
font-weight: 500;
border-bottom: 0;
}

.table th {
font-weight: 500;
}
147 changes: 84 additions & 63 deletions components/chain/chain.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import React, { useState, useEffect, useMemo } from "react";
import { Typography, Paper, Grid, Button, Tooltip } from "@material-ui/core";
import Skeleton from "@material-ui/lab/Skeleton";
import { useRouter } from "next/router";
import Web3 from "web3";

import classes from "./chain.module.css";

import stores from "../../stores/index.js";
import { getProvider } from "../../utils";

import { ERROR, CONNECT_WALLET, TRY_CONNECT_WALLET, ACCOUNT_CONFIGURED } from "../../stores/constants";
import Image from "next/image";
import React, { useState, useEffect, useMemo } from 'react';
import { Typography, Paper, Button, Tooltip, withStyles } from '@material-ui/core';
import classes from './chain.module.css';
import stores, { useChain } from '../../stores/index.js';
import { getProvider } from '../../utils';
import { ERROR, TRY_CONNECT_WALLET, ACCOUNT_CONFIGURED } from '../../stores/constants';
import Image from 'next/image';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import RPCList from '../RPCList';

const ExpandButton = withStyles((theme) => ({
root: {
width: '100%',
marginTop: '12px',
marginBottom: '-24px',
},
}))(Button);

export default function Chain({ chain }) {
const router = useRouter();

const [account, setAccount] = useState(null);

useEffect(() => {
const accountConfigure = () => {
const accountStore = stores.accountStore.getStore("account");
const accountStore = stores.accountStore.getStore('account');
setAccount(accountStore);
};

stores.emitter.on(ACCOUNT_CONFIGURED, accountConfigure);

const accountStore = stores.accountStore.getStore("account");
const accountStore = stores.accountStore.getStore('account');
setAccount(accountStore);

return () => {
Expand All @@ -34,7 +36,7 @@ export default function Chain({ chain }) {
}, []);

const toHex = (num) => {
return "0x" + num.toString(16);
return '0x' + num.toString(16);
};

const addToNetwork = () => {
Expand Down Expand Up @@ -62,7 +64,7 @@ export default function Chain({ chain }) {
window.web3.eth.getAccounts((error, accounts) => {
window.ethereum
.request({
method: "wallet_addEthereumChain",
method: 'wallet_addEthereumChain',
params: [params, accounts[0]],
})
.then((result) => {
Expand All @@ -78,65 +80,84 @@ export default function Chain({ chain }) {
const renderProviderText = () => {
if (account && account.address) {
const providerTextList = {
Metamask: "Add to Metamask",
imToken: "Add to imToken",
Wallet: "Add to Wallet",
Metamask: 'Add to Metamask',
imToken: 'Add to imToken',
Wallet: 'Add to Wallet',
};
return providerTextList[getProvider()];
} else {
return "Connect wallet";
return 'Connect wallet';
}
};

const icon = useMemo(() => {
return chain.chainSlug ? `https://defillama.com/chain-icons/rsz_${chain.chainSlug}.jpg` : "/unknown-logo.png";
return chain.chainSlug ? `https://defillama.com/chain-icons/rsz_${chain.chainSlug}.jpg` : '/unknown-logo.png';
}, [chain]);

const chainId = useChain((state) => state.id);
const updateChain = useChain((state) => state.updateChain);

const handleClick = () => {
if (chain.chainId === chainId) {
updateChain(null);
} else {
updateChain(chain.chainId);
}
};

const showAddlInfo = chain.chainId === chainId;

if (!chain) {
return <div></div>;
}

return (
<Paper elevation={1} className={classes.chainContainer} key={chain.chainId}>
<div className={classes.chainNameContainer}>
<Image
src={icon}
onError={(e) => {
e.target.onerror = null;
e.target.src = "/chains/unknown-logo.png";
}}
width={28}
height={28}
className={classes.avatar}
/>

<Tooltip title={chain.name}>
<Typography variant="h3" className={classes.name} noWrap style={{ marginLeft: "24px" }}>
<a href={chain.infoURL} target="_blank" rel="noreferrer">
{chain.name}
</a>
</Typography>
</Tooltip>
</div>
<div className={classes.chainInfoContainer}>
<div className={classes.dataPoint}>
<Typography variant="subtitle1" color="textSecondary" className={classes.dataPointHeader}>
ChainID
</Typography>
<Typography variant="h5">{chain.chainId}</Typography>
<>
<Paper elevation={1} className={classes.chainContainer} key={chain.chainId}>
<div className={classes.chainNameContainer}>
<Image
src={icon}
onError={(e) => {
e.target.onerror = null;
e.target.src = '/chains/unknown-logo.png';
}}
width={28}
height={28}
className={classes.avatar}
/>

<Tooltip title={chain.name}>
<Typography variant="h3" className={classes.name} noWrap style={{ marginLeft: '24px' }}>
<a href={chain.infoURL} target="_blank" rel="noreferrer">
{chain.name}
</a>
</Typography>
</Tooltip>
</div>
<div className={classes.chainInfoContainer}>
<div className={classes.dataPoint}>
<Typography variant="subtitle1" color="textSecondary" className={classes.dataPointHeader}>
ChainID
</Typography>
<Typography variant="h5">{chain.chainId}</Typography>
</div>
<div className={classes.dataPoint}>
<Typography variant="subtitle1" color="textSecondary" className={classes.dataPointHeader}>
Currency
</Typography>
<Typography variant="h5">{chain.nativeCurrency ? chain.nativeCurrency.symbol : 'none'}</Typography>
</div>
</div>
<div className={classes.dataPoint}>
<Typography variant="subtitle1" color="textSecondary" className={classes.dataPointHeader}>
Currency
</Typography>
<Typography variant="h5">{chain.nativeCurrency ? chain.nativeCurrency.symbol : "none"}</Typography>
<div className={classes.addButton}>
<Button variant="outlined" color="primary" onClick={addToNetwork}>
{renderProviderText()}
</Button>
</div>
</div>
<div className={classes.addButton}>
<Button variant="outlined" color="primary" onClick={addToNetwork}>
{renderProviderText()}
</Button>
</div>
</Paper>
<ExpandButton onClick={handleClick}>
<ExpandMoreIcon style={{ transform: showAddlInfo ? 'rotate(180deg)' : '', transition: 'all 0.2s ease' }} />
</ExpandButton>
</Paper>
{showAddlInfo && <RPCList chain={chain} />}
</>
);
}
Loading