-
Notifications
You must be signed in to change notification settings - Fork 523
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
Whitevotex
wants to merge
31
commits into
antonnell:main
Choose a base branch
from
DefiLlama:rpc-list
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Rpc list #68
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
6b2ed4d
Revert "Shutdown notice."
0xngmi 6dd9534
remove multichain & add sorting by chain
0xngmi f3120c6
add SSR and optimize
0xngmi c2ab136
change favicon
0xngmi d063d33
move chains.js
0xngmi 211de94
add yarn.lock
0xngmi 83e4cca
remove unused code
0xngmi 0f96aba
add fathom
0xngmi 4ba7128
add testnets switch
mintdart d89f901
add chainlist.org domain
0xngmi ac9d711
add chain icons
mintdart b5be804
rework chain icons
0xngmi ea313b4
move testnet toggle to header
mintdart 15a06d1
add rpc list url table
mintdart 48183db
fix sorting url list by height and latency
mintdart 7124483
add loading indicator
mintdart f43f870
try using axios to calc latency
mintdart ee04ded
add extra rpcs
0xngmi 2cbf2f1
update rpcs
0xngmi d00a250
update header styles
mintdart 5bc4549
include option to add network with different rpc urls
mintdart e0fdea5
cleanup
mintdart 426c57a
show data of websocket server nodes
mintdart a4b3957
add trust score sto rpc urls
mintdart 3b31001
Update index.js
0xngmi a6b1b75
smol fix
0xngmi c4a998b
update table header
mintdart 3e1bce4
fix harmony rpcs
0xngmi 001eaf5
remove add to wallet buttons for eth mainnet urls
mintdart 2646662
add link to docs on how to add endpoints manually
mintdart 49e4131
cleanup
mintdart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import { Button, Paper } from '@material-ui/core'; | ||
import { useEffect, useMemo } from 'react'; | ||
import useRPCData from '../../hooks/useRPCData'; | ||
import { useAccount, useRpcStore } from '../../stores'; | ||
import { addToNetwork, renderProviderText } from '../../utils/utils'; | ||
import classes from './index.module.css'; | ||
import FiberManualRecordIcon from '@material-ui/icons/FiberManualRecord'; | ||
|
||
export default function RPCList({ chain }) { | ||
const chains = useRPCData(chain.rpc); | ||
|
||
const data = useMemo(() => { | ||
const sortedData = chains?.sort((a, b) => { | ||
if (a.isLoading) { | ||
return 1; | ||
} | ||
|
||
const h1 = a?.data?.height; | ||
const h2 = b?.data?.height; | ||
const l1 = a?.data?.latency; | ||
const l2 = b?.data?.latency; | ||
|
||
if (!h2) { | ||
return -1; | ||
} | ||
|
||
if (h2 - h1 > 0) { | ||
return 1; | ||
} | ||
if (h2 - h1 < 0) { | ||
return -1; | ||
} | ||
if (h1 === h2) { | ||
if (l1 - l2 < 0) { | ||
return -1; | ||
} else { | ||
return 1; | ||
} | ||
} | ||
}); | ||
|
||
const topRpc = sortedData[0]?.data ?? {}; | ||
|
||
return sortedData.map(({ data, ...rest }) => { | ||
const { height = null, latency = null, url = '' } = data || {}; | ||
|
||
let trust = 'transparent'; | ||
let disableConnect = false; | ||
|
||
if (!height || !latency || topRpc.height - height > 3 || topRpc.latency - latency > 5000) { | ||
trust = 'red'; | ||
} else if (topRpc.height - height < 2 && topRpc.latency - latency > -600) { | ||
trust = 'green'; | ||
} else { | ||
trust = 'orange'; | ||
} | ||
|
||
if (url.includes('wss://') || url.includes('API_KEY')) disableConnect = true; | ||
|
||
const lat = latency ? (latency / 1000).toFixed(3) + 's' : null; | ||
|
||
return { ...rest, data: { ...data, height, latency: lat, trust, disableConnect } }; | ||
}); | ||
}, [chains]); | ||
|
||
const darkMode = window.localStorage.getItem('yearn.finance-dark-mode') === 'dark'; | ||
|
||
const isEthMainnet = chain?.name === 'Ethereum Mainnet'; | ||
|
||
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>Score</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{data.map((item, index) => ( | ||
<Row values={item} chain={chain} isEthMainnet={isEthMainnet} key={index} /> | ||
))} | ||
</tbody> | ||
</table> | ||
</Paper> | ||
); | ||
} | ||
|
||
const Shimmer = () => { | ||
const darkMode = window.localStorage.getItem('yearn.finance-dark-mode') === 'dark'; | ||
const linearGradient = darkMode | ||
? 'linear-gradient(90deg, rgb(255 247 247 / 7%) 0px, rgb(85 85 85 / 80%) 40px, rgb(255 247 247 / 7%) 80px)' | ||
: 'linear-gradient(90deg, #f4f4f4 0px, rgba(229, 229, 229, 0.8) 40px, #f4f4f4 80px)'; | ||
return <div className={classes.shimmer} style={{ '--linear-gradient': linearGradient }}></div>; | ||
}; | ||
|
||
const Row = ({ values, chain, isEthMainnet }) => { | ||
const { data, isLoading, refetch } = values; | ||
|
||
const rpcs = useRpcStore((state) => state.rpcs); | ||
const addRpc = useRpcStore((state) => state.addRpc); | ||
const account = useAccount((state) => state.account); | ||
|
||
useEffect(() => { | ||
// ignore first request to a url and refetch to calculate latency which doesn't include DNS lookup | ||
if (data && !rpcs.includes(data.url)) { | ||
refetch(); | ||
addRpc(data.url); | ||
} | ||
}, [data, rpcs, addRpc, refetch]); | ||
|
||
return ( | ||
<tr> | ||
<td>{isLoading ? <Shimmer /> : data?.url}</td> | ||
<td>{isLoading ? <Shimmer /> : data?.height}</td> | ||
<td>{isLoading ? <Shimmer /> : data?.latency}</td> | ||
<td className={classes.trustScore} style={{ '--trust-color': data?.trust ?? 'transparent' }}> | ||
{isLoading ? <Shimmer /> : <FiberManualRecordIcon />} | ||
</td> | ||
<td> | ||
{isLoading ? ( | ||
<Shimmer /> | ||
) : ( | ||
<> | ||
{isEthMainnet ? ( | ||
<CopyUrl url={data?.url} /> | ||
) : ( | ||
!data.disableConnect && ( | ||
<Button style={{ padding: '0 8px' }} onClick={() => addToNetwork(account, chain, data?.url)}> | ||
{renderProviderText(account)} | ||
</Button> | ||
) | ||
)} | ||
</> | ||
)} | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
const CopyUrl = ({ url = '' }) => { | ||
return ( | ||
<Button style={{ padding: '0 8px' }} onClick={() => navigator.clipboard.writeText(url)}> | ||
Copy URL | ||
</Button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
.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: 4px 12px; | ||
border: 1px solid var(--border-color); | ||
} | ||
|
||
.table caption { | ||
font-size: 1rem; | ||
font-weight: 500; | ||
border-bottom: 0; | ||
} | ||
|
||
.table th { | ||
font-weight: 500; | ||
} | ||
|
||
.shimmer { | ||
border-radius: 4px; | ||
height: 20px; | ||
width: 100%; | ||
min-width: 40px; | ||
background-image: var(--linear-gradient); | ||
background-size: 600px; | ||
animation: loading 2s infinite; | ||
} | ||
|
||
.trustScore { | ||
text-align: center; | ||
color: var(--trust-color); | ||
} | ||
|
||
.helperText { | ||
text-align: center; | ||
} | ||
|
||
.helperText a { | ||
text-decoration: underline; | ||
} | ||
|
||
@keyframes loading { | ||
0% { | ||
background-position: -100px; | ||
} | ||
40%, | ||
100% { | ||
background-position: 140px; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://rpc.ankr.com/avalanche