Allow currency and block explorer details for custom provider

pull/4060/head
aniket-engg 1 year ago committed by Aniket
parent 573dfa93c9
commit 839f318054
  1. 25
      apps/remix-ide/src/app/providers/injected-custom-provider.tsx
  2. 15
      apps/remix-ide/src/app/providers/injected-ephemery-testnet-provider.tsx

@ -4,23 +4,27 @@ export class InjectedCustomProvider extends InjectedProviderDefaultBase {
chainName: string
chainId: string
rpcUrls: Array<string>
nativeCurrency: Record<string, any>
blockExplorerUrls: Array<string>
constructor(profile: any, chainName: string, chainId: string, rpcUrls: Array<string>) {
constructor(profile: any, chainName: string, chainId: string, rpcUrls: Array<string>, nativeCurrency?: Record<string, any>, blockExplorerUrls?: Array<string>) {
super(profile)
this.chainName = chainName
this.chainId = chainId
this.rpcUrls = rpcUrls
this.nativeCurrency = nativeCurrency
this.blockExplorerUrls = blockExplorerUrls
}
async init() {
await super.init()
if (this.chainName && this.rpcUrls && this.rpcUrls.length > 0) await addCustomNetwork(this.chainName, this.chainId, this.rpcUrls)
if (this.chainName && this.rpcUrls && this.rpcUrls.length > 0) await addCustomNetwork(this.chainName, this.chainId, this.rpcUrls, this.nativeCurrency, this.blockExplorerUrls)
else throw new Error('Cannot add the custom network to main injected provider')
return {}
}
}
export const addCustomNetwork = async (chainName: string, chainId: string, rpcUrls: Array<string>) => {
export const addCustomNetwork = async (chainName: string, chainId: string, rpcUrls: Array<string>, nativeCurrency?: Record<string, any>, blockExplorerUrls?: Array<string>) => {
try {
await (window as any).ethereum.request({
method: 'wallet_switchEthereumChain',
@ -30,15 +34,16 @@ export const addCustomNetwork = async (chainName: string, chainId: string, rpcUr
// This error code indicates that the chain has not been added to MetaMask.
if (switchError.code === 4902) {
try {
let paramsObj: Record<string, any> = {
chainId: chainId,
chainName: chainName,
rpcUrls: rpcUrls,
}
if (nativeCurrency) paramsObj.nativeCurrency = nativeCurrency
if (blockExplorerUrls) paramsObj.blockExplorerUrls = blockExplorerUrls
await (window as any).ethereum.request({
method: 'wallet_addEthereumChain',
params: [
{
chainId: chainId,
chainName: chainName,
rpcUrls: rpcUrls
}
]
params: [ paramsObj ]
})
await (window as any).ethereum.request({

@ -12,6 +12,19 @@ const profile = {
export class InjectedEphemeryTestnetProvider extends InjectedCustomProvider {
constructor() {
super(profile, 'Ephemery Testnet', '0x259C709', ['https://otter.bordel.wtf/erigon', 'https://eth.ephemeral.zeus.fyi'])
super(profile,
'Ephemery Testnet',
'',
['https://otter.bordel.wtf/erigon', 'https://eth.ephemeral.zeus.fyi'],
{
"name": "Ephemery ETH",
"symbol": "ETH",
"decimals": 18
},
[
'https://otter.bordel.wtf/',
'https://explorer.ephemery.dev/'
]
)
}
}

Loading…
Cancel
Save