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

add ephemery provider #4026

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
240 changes: 109 additions & 131 deletions apps/remix-ide/src/app.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as packageJson from '../../../../../package.json'
import {InjectedL2Provider} from './injected-L2-provider'
import {InjectedCustomProvider} from './injected-custom-provider'

const profile = {
name: 'injected-arbitrum-one-provider',
Expand All @@ -10,7 +10,7 @@ const profile = {
version: packageJson.version
}

export class InjectedArbitrumOneProvider extends InjectedL2Provider {
export class InjectedArbitrumOneProvider extends InjectedCustomProvider {
constructor() {
super(profile, 'Arbitrum One', '0xa4b1', ['https://arb1.arbitrum.io/rpc'])
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {InjectedProviderDefaultBase} from './injected-provider-default'

export class InjectedL2Provider extends InjectedProviderDefaultBase {
export class InjectedCustomProvider extends InjectedProviderDefaultBase {
chainName: string
chainId: string
rpcUrls: Array<string>
Expand All @@ -14,13 +14,13 @@ export class InjectedL2Provider extends InjectedProviderDefaultBase {

async init() {
await super.init()
if (this.chainName && this.rpcUrls && this.rpcUrls.length > 0) await addL2Network(this.chainName, this.chainId, this.rpcUrls)
else throw new Error('Cannot add the L2 network to main injected provider')
if (this.chainName && this.rpcUrls && this.rpcUrls.length > 0) await addCustomNetwork(this.chainName, this.chainId, this.rpcUrls)
else throw new Error('Cannot add the custom network to main injected provider')
return {}
}
}

export const addL2Network = async (chainName: string, chainId: string, rpcUrls: Array<string>) => {
export const addCustomNetwork = async (chainName: string, chainId: string, rpcUrls: Array<string>) => {
try {
await (window as any).ethereum.request({
method: 'wallet_switchEthereumChain',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as packageJson from '../../../../../package.json'
import {InjectedCustomProvider} from './injected-custom-provider'

const profile = {
name: 'injected-ephemery-testnet-provider',
displayName: 'Injected Ephemery Testnet Provider',
kind: 'provider',
description: 'Injected Ephemery Testnet Provider',
methods: ['sendAsync', 'init'],
version: packageJson.version
}

export class InjectedEphemeryTestnetProvider extends InjectedCustomProvider {
constructor() {
super(profile, 'Ephemery Testnet', '0x259C709', ['https://otter.bordel.wtf/erigon', 'https://eth.ephemeral.zeus.fyi'])
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as packageJson from '../../../../../package.json'
import {InjectedL2Provider} from './injected-L2-provider'
import {InjectedCustomProvider} from './injected-custom-provider'

const profile = {
name: 'injected-optimism-provider',
Expand All @@ -10,7 +10,7 @@ const profile = {
version: packageJson.version
}

export class Injected0ptimismProvider extends InjectedL2Provider {
export class Injected0ptimismProvider extends InjectedCustomProvider {
constructor() {
super(profile, 'Optimism', '0xa', ['https://mainnet.optimism.io'])
}
Expand Down
92 changes: 58 additions & 34 deletions apps/remix-ide/src/app/udapp/run-tab.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react' // eslint-disable-line
import { RunTabUI } from '@remix-ui/run-tab'
import { ViewPlugin } from '@remixproject/engine-web'
import { addressToString } from '@remix-ui/helper'
import {RunTabUI} from '@remix-ui/run-tab'
import {ViewPlugin} from '@remixproject/engine-web'
import {addressToString} from '@remix-ui/helper'
import * as packageJson from '../../../../../package.json'

const EventManager = require('../../lib/events')
const Recorder = require('../tabs/runTab/model/recorder.js')
const _paq = window._paq = window._paq || []
const _paq = (window._paq = window._paq || [])

const profile = {
name: 'udapp',
Expand All @@ -20,11 +20,21 @@ const profile = {
maintainedBy: 'Remix',
permission: true,
events: ['newTransaction'],
methods: ['createVMAccount', 'sendTransaction', 'getAccounts', 'pendingTransactionsCount', 'getSettings', 'setEnvironmentMode', 'clearAllInstances', 'addInstance', 'resolveContractAndAddInstance']
methods: [
'createVMAccount',
'sendTransaction',
'getAccounts',
'pendingTransactionsCount',
'getSettings',
'setEnvironmentMode',
'clearAllInstances',
'addInstance',
'resolveContractAndAddInstance'
]
}

export class RunTab extends ViewPlugin {
constructor (blockchain, config, fileManager, editor, filePanel, compilersArtefacts, networkModule, fileProvider) {
constructor(blockchain, config, fileManager, editor, filePanel, compilersArtefacts, networkModule, fileProvider) {
super(profile)
this.event = new EventManager()
this.config = config
Expand All @@ -41,13 +51,13 @@ export class RunTab extends ViewPlugin {
this.el = document.createElement('div')
}

setupEvents () {
setupEvents() {
this.blockchain.events.on('newTransaction', (tx, receipt) => {
this.emit('newTransaction', tx, receipt)
})
}

getSettings () {
getSettings() {
return new Promise((resolve, reject) => {
resolve({
selectedAccount: this.REACT_API.accounts.selectedAccount,
Expand All @@ -57,48 +67,52 @@ export class RunTab extends ViewPlugin {
})
}

async setEnvironmentMode (env) {
async setEnvironmentMode(env) {
const canCall = await this.askUserPermission('setEnvironmentMode', 'change the environment used')
if (canCall) {
env = typeof env === 'string' ? { context: env } : env
env = typeof env === 'string' ? {context: env} : env
this.emit('setEnvironmentModeReducer', env, this.currentRequest.from)
}
}

clearAllInstances () {
clearAllInstances() {
this.emit('clearAllInstancesReducer')
}

addInstance (address, abi, name) {
addInstance(address, abi, name) {
this.emit('addInstanceReducer', address, abi, name)
}

createVMAccount (newAccount) {
createVMAccount(newAccount) {
return this.blockchain.createVMAccount(newAccount)
}

sendTransaction (tx) {
sendTransaction(tx) {
_paq.push(['trackEvent', 'udapp', 'sendTx', 'udappTransaction'])
return this.blockchain.sendTransaction(tx)
}

getAccounts (cb) {
getAccounts(cb) {
return this.blockchain.getAccounts(cb)
}

pendingTransactionsCount () {
pendingTransactionsCount() {
return this.blockchain.pendingTransactionsCount()
}

render () {
return <div><RunTabUI plugin={this} /></div>
render() {
return (
<div>
<RunTabUI plugin={this} />
</div>
)
}

onReady (api) {
onReady(api) {
this.REACT_API = api
}

async onInitDone () {
async onInitDone() {
const udapp = this // eslint-disable-line

const addProvider = async (name, displayName, isInjected, isVM, fork = '', dataId = '', title = '') => {
Expand All @@ -113,13 +127,13 @@ export class RunTab extends ViewPlugin {
title,
init: async function () {
const options = await udapp.call(name, 'init')
if (options) {
if (options) {
this.options = options
if (options['fork']) this.fork = options['fork']
}
},
provider: {
async sendAsync (payload, callback) {
async sendAsync(payload, callback) {
try {
const result = await udapp.call(name, 'sendAsync', payload)
callback(null, result)
Expand All @@ -134,21 +148,28 @@ export class RunTab extends ViewPlugin {
// basic injected
// if it's the trust wallet provider, we have a specific provider for that, see below
if (window && window.ethereum && !(window.ethereum.isTrustWallet || window.ethereum.selectedProvider?.isTrustWallet)) {
const displayNameInjected = `Injected Provider${(window && window.ethereum && !(window.ethereum.providers && !window.ethereum.selectedProvider)) ?
window.ethereum.isCoinbaseWallet || window.ethereum.selectedProvider?.isCoinbaseWallet ? ' - Coinbase' :
window.ethereum.isBraveWallet || window.ethereum.selectedProvider?.isBraveWallet ? ' - Brave' :
window.ethereum.isMetaMask || window.ethereum.selectedProvider?.isMetaMask ? ' - MetaMask' : '' : ''}`
const displayNameInjected = `Injected Provider${
window && window.ethereum && !(window.ethereum.providers && !window.ethereum.selectedProvider)
? window.ethereum.isCoinbaseWallet || window.ethereum.selectedProvider?.isCoinbaseWallet
? ' - Coinbase'
: window.ethereum.isBraveWallet || window.ethereum.selectedProvider?.isBraveWallet
? ' - Brave'
: window.ethereum.isMetaMask || window.ethereum.selectedProvider?.isMetaMask
? ' - MetaMask'
: ''
: ''
}`
await addProvider('injected', displayNameInjected, true, false)
} else if (window && !window.ethereum) {
// we still add "injected" if there's no provider (just so it's visible to the user).
await addProvider('injected', 'Injected Provider', true, false)
}

if (window && window.trustwallet) {
const displayNameInjected = `Injected Provider - TrustWallet`
const displayNameInjected = `Injected Provider - TrustWallet`
await addProvider('injected-trustwallet', displayNameInjected, true, false)
}

// VM
const titleVM = 'Execution environment is local to Remix. Data is only saved to browser memory and will vanish upon reload.'
await addProvider('vm-shanghai', 'Remix VM (Shanghai)', false, true, 'shanghai', 'settingsVMShanghaiMode', titleVM)
Expand All @@ -163,26 +184,29 @@ export class RunTab extends ViewPlugin {
// wallet connect
await addProvider('walletconnect', 'WalletConnect', false, false)

// testnet
await addProvider('injected-ephemery-testnet-provider', 'Ephemery Testnet', true, false)

// external provider
await addProvider('basic-http-provider', 'Custom - External Http Provider', false, false)
await addProvider('hardhat-provider', 'Dev - Hardhat Provider', false, false)
await addProvider('ganache-provider', 'Dev - Ganache Provider', false, false)
await addProvider('foundry-provider', 'Dev - Foundry Provider', false, false)
// injected provider
await addProvider('foundry-provider', 'Dev - Foundry Provider', false, false)

// injected provider
await addProvider('injected-optimism-provider', 'L2 - Optimism Provider', true, false)
await addProvider('injected-arbitrum-one-provider', 'L2 - Arbitrum One Provider', true, false)
}

writeFile (fileName, content) {
writeFile(fileName, content) {
return this.call('fileManager', 'writeFile', fileName, content)
}

readFile (fileName) {
readFile(fileName) {
return this.call('fileManager', 'readFile', fileName)
}

async resolveContractAndAddInstance (contractObject, address) {
async resolveContractAndAddInstance(contractObject, address) {
const data = await this.compilersArtefacts.getCompilerAbstract(contractObject.contract.file)

this.compilersArtefacts.addResolvedContract(addressToString(address), data)
Expand Down
Loading
Loading