Only enable faucets on chains explicitly flagged as network === testnet

This commit is contained in:
Willian Mitsuda 2022-04-11 01:04:56 -03:00
parent d29b3fdfb3
commit d198a5c5b2
3 changed files with 14 additions and 8 deletions

View File

@ -88,7 +88,7 @@ const Address: React.FC = () => {
? metadatas[checksummedAddress] ? metadatas[checksummedAddress]
: undefined; : undefined;
const { faucets } = useChainInfo(); const { network, faucets } = useChainInfo();
// Search address by nonce === transaction @ nonce // Search address by nonce === transaction @ nonce
const rawNonce = searchParams.get("nonce"); const rawNonce = searchParams.get("nonce");
@ -124,7 +124,7 @@ const Address: React.FC = () => {
</span> </span>
<Copy value={checksummedAddress} rounded /> <Copy value={checksummedAddress} rounded />
{/* Only display faucets for testnets who actually have any */} {/* Only display faucets for testnets who actually have any */}
{faucets && faucets.length > 0 && ( {network === "testnet" && faucets && faucets.length > 0 && (
<Faucet address={checksummedAddress} rounded /> <Faucet address={checksummedAddress} rounded />
)} )}
{isENS && ( {isENS && (

View File

@ -8,17 +8,21 @@ import ContentFrame from "./ContentFrame";
import StandardFrame from "./StandardFrame"; import StandardFrame from "./StandardFrame";
import StandardSubtitle from "./StandardSubtitle"; import StandardSubtitle from "./StandardSubtitle";
import { useChainInfo } from "./useChainInfo"; import { useChainInfo } from "./useChainInfo";
const Faucets: React.FC = () => { const Faucets: React.FC = () => {
const { faucets } = useChainInfo(); const { network, faucets } = useChainInfo();
const loc = useLocation(); const loc = useLocation();
const urls = useMemo(() => { const urls = useMemo(() => {
const s = new URLSearchParams(loc.search); const s = new URLSearchParams(loc.search);
const address = s.get("address"); const address = s.get("address");
const _urls = faucets.map((u) => const _urls: string[] =
// eslint-disable-next-line no-template-curly-in-string network === "testnet"
address !== null ? u.replaceAll("${ADDRESS}", address) : u ? faucets.map((u) =>
); // eslint-disable-next-line no-template-curly-in-string
address !== null ? u.replaceAll("${ADDRESS}", address) : u
)
: [];
// Shuffle faucets to avoid UI bias // Shuffle faucets to avoid UI bias
for (let i = _urls.length - 1; i > 0; i--) { for (let i = _urls.length - 1; i > 0; i--) {
@ -27,7 +31,7 @@ const Faucets: React.FC = () => {
} }
return _urls; return _urls;
}, [faucets, loc]); }, [network, faucets, loc]);
return ( return (
<StandardFrame> <StandardFrame>

View File

@ -3,6 +3,7 @@ import { chainInfoURL } from "./url";
import { OtterscanRuntime } from "./useRuntime"; import { OtterscanRuntime } from "./useRuntime";
export type ChainInfo = { export type ChainInfo = {
network: string | undefined;
faucets: string[]; faucets: string[];
nativeCurrency: { nativeCurrency: {
name: string; name: string;
@ -12,6 +13,7 @@ export type ChainInfo = {
}; };
export const defaultChainInfo: ChainInfo = { export const defaultChainInfo: ChainInfo = {
network: undefined,
faucets: [], faucets: [],
nativeCurrency: { nativeCurrency: {
name: "Ether", name: "Ether",