Files
js/@3rdweb-sdk/react/hooks/useWeb3.ts
T
1064350681 Any EVM + middleware (#814)
* homepage: infinite looping logo carousel

* split partners logo among two rows on mobile

* remove lazy loading from partner logos

* Fix partner logo cut off on safari

* fade-in logo carousel at the container edge

* v1

* v2

* remove temp code changes

* switch network *technically* works, and new chains package

* Fix src warning in AsyncContractTypeCell

* Updated Design for config form, fix metadata error

* add initial deployment status modal

* Fix contract duplication bug in dashboard

* Make RPC url always editable

* v3 - middleware + refactor

* reset form when selecting custom option

* Fix crash on sources tab for unsupported chains

* add missing deps in effects

* /evm - use SSG with fallback

* /evm - add ensQuery dehydration back

* /solana - fix program page loading issue

* Allow editing details for custom chains

* solana program context

* fix build crash

* fix all the networkOrAddress getters

* use chain icons from chains package

* separation of fallback and final page

* Fix wrong default network type in form

* validation improvements in configure network form

* disable custom chains from dropdown on On non thirdweb contracts deploy page

* Fix wrong network slug

* custom chain improvement

* Fix Lightmode UI of Network Config Form

* UI improvements for network search dropdown

* UI tweaks

* code review cleanup

* UI tweaks

* Network Config Form: Better Keyboard UX

* fix broken /contracts/release and /contracts/deploy routes

* add configure networks button for custom contract deployment page

* UI tweaks for network configurator

* fix merge

* add the icon to the custom chain

* Bunch of Improvements

* Improve auto chain configuration
* Do not allow adding custom network with existing chain id
* Show delete default chains with 1-click add
* Convert delete dialog to a popover
* Retain all fields when selecting a chain from list
* Allow configuring chain Icons
* Allow using chainId as network slug for custom networks
* Remove unnecessary chainInfos object passed in provider

* configurable slug + prefill form

* improve scrollbar styling

* upgrade to newer sdk etc

* make it work

* Various testjame improvements

* Stop form submit event propagation
* preselect “testnet” for custom network based on name
* Clear form errors when selecting a network from list
* Improved UI for Delete network popover
* Disable “Add Network” button when on add network page
* Change fallback chain icon

* custom and search tabs

* reduce layout shift when switching tabs

* allChains caching with idb

* Add IPFS upload button for icon input

* Deploy Modal, chain icon, code cleanup

* Fix Deploy Modal not working for custom contract deployment
* Fix Fantom testnet icon
* Remove useDashboardNetwork()
* Update Deploy Modal wording in case for 3 prompt scenario
* Remove hardhat and localhost from CURRENCIES object
* Remove gateway.ipfscdn.io from images.remotePatterns in next config

* add chain config tracking

* remove useChainInfos()

* Remove EVM_RPC_URL_MAP usage as much as possible

* Fix Network Switcher for non-default chains

* upgrade new dev sdk versions

* fix versions

* Fix contractInfo.chain not available on contract page of custom chain

* Fix contract page links in overview page

* Update default chain Icon

* bunch of UI improvements for network configuration modal

* Better active state for add network button and chains
* Suggest a slug for custom network
* Show chain id next to network names in list
* Allow searching by chain id
* Autofocus on first input of the form
* Add cross button for clearing search input
* Toggle search results open state with chevron icon
* Add icons in chain list

* handle wallet connected to unsupported network in <SupportedNetworkSelect/>

* No reload required after adding a network

* revert last commit - reload still required

* handle case where wallet is connected to an auto configured chain - show it as unknown network

* update dependencies and switch to activeChain and supportedChains

* nightly sdk versions

* Improved Icon Uploader

* always use default chains for polygon registry work

* dev version & updated list fetching

* Improved Chain ID input in Network Configurator

* Improved Network ID validation and prefill

* Hide etherscan verification button for non-default chains

* Form Refactor + network type toolip

* update deps

* update package versions

* upgrade dependencies

* show "create custom"  when no search results found

* slug calculated from prefillName should not be considered dirty

* open edit screen when selecting already configured network from list

* fuzzy search with fuse.js

* replace thirdweb key with it's value in form

* temp fix for getChainRPC throwing error

* update to newer chains package

* lots of rpc cleanup etc

* fix nightly maybe?

* upgrade to nightly packages

* add initial import contract search input

* fix localhost

* clean up smoe more stuff

* lots of updates

* Show "Request Testnet Funds" button in wallet when applicable (#856)

* fix crash on events page

* Fix Links in Overview page

* import contract improvements

* Fix wrong explorer tab link in ContractPermissionsPage

* make search faster (individual queries)

* properly split contract and program routing

* remove all via stuff etc

* various further improvements

* add a proxy and setup storage to hit that proxy

* further cleanup

---------

Co-authored-by: Jonas Daniels <[email protected]>
Co-authored-by: Joaquim Verges <[email protected]>
2023-02-14 09:37:47 +00:00

69 lines
2.0 KiB
TypeScript

import { ChainId } from "@thirdweb-dev/react";
import { useConfiguredChainsRecord } from "hooks/chains/configureChains";
import { useCallback } from "react";
interface NetworkMetadata {
chainName: string;
icon?: string;
symbol: string;
isTestnet: boolean | "unknown";
chainId: ChainId;
iconSizes?: readonly number[];
}
export const FAUCETS: Partial<Record<ChainId, string>> = {
[ChainId.Goerli]: "https://faucet.paradigm.xyz/",
[ChainId.Mumbai]: "https://mumbaifaucet.com",
[ChainId.AvalancheFujiTestnet]: "https://faucet.avax.network/",
[ChainId.FantomTestnet]: "https://faucet.fantom.network/",
[ChainId.BinanceSmartChainTestnet]:
"https://testnet.binance.org/faucet-smart",
[ChainId.OptimismGoerli]: "https://app.optimism.io/bridge/deposit",
[ChainId.ArbitrumGoerli]: "https://bridge.arbitrum.io/?l2ChainId=421613",
};
const defaultIcon = `https://gateway.ipfscdn.io/ipfs/QmNTemZCjCGyN8x9vFQFyAHVeZc9QZu4nCiSANNaZX5Buq/unknown-logo.png`;
export function useWeb3() {
const configuredChainsRecord = useConfiguredChainsRecord();
const getNetworkMetadata = useCallback(
(chainId: number, includeAutoConfiguredChains = true): NetworkMetadata => {
const isKnown = chainId in configuredChainsRecord;
const canUse =
isKnown &&
(includeAutoConfiguredChains ||
!configuredChainsRecord[chainId].isAutoConfigured);
if (canUse) {
const configuredChain = configuredChainsRecord[chainId];
const iconUrl = configuredChain.icon?.url;
return {
chainName: configuredChain.name,
icon: iconUrl,
isTestnet: configuredChain.testnet,
symbol: configuredChain.nativeCurrency.symbol,
chainId,
iconSizes: configuredChain.icon?.sizes,
};
}
// Defaults for Unresolved chain
return {
chainName: `Chain ID #${chainId}`,
icon: defaultIcon,
isTestnet: "unknown",
symbol: "",
chainId,
};
},
[configuredChainsRecord],
);
return {
getNetworkMetadata,
};
}