clean and fix discrepancy between injected keyword and specific extension

cli_integ_desktop
yann300 7 months ago
parent e27425312d
commit 883461f075
  1. 2
      apps/remix-ide/src/app/providers/injected-provider-default.tsx
  2. 18
      apps/remix-ide/src/app/udapp/run-tab.js
  3. 48
      apps/remix-ide/src/blockchain/blockchain.tsx
  4. 4
      apps/remix-ide/src/blockchain/providers/injected.ts
  5. 4
      apps/remix-ide/src/blockchain/providers/node.ts
  6. 6
      apps/remix-ide/src/blockchain/providers/vm.ts
  7. 2
      apps/remix-ide/src/remixAppManager.js
  8. 2
      libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx
  9. 2
      libs/remix-ui/run-tab/src/lib/actions/account.ts
  10. 47
      libs/remix-ui/run-tab/src/lib/actions/events.ts
  11. 118
      libs/remix-ui/run-tab/src/lib/components/account.tsx
  12. 2
      libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx
  13. 2
      libs/remix-ui/run-tab/src/lib/types/blockchain.d.ts
  14. 1
      libs/remix-ui/run-tab/src/lib/types/injected.d.ts
  15. 1
      libs/remix-ui/run-tab/src/lib/types/node.d.ts
  16. 1
      libs/remix-ui/run-tab/src/lib/types/vm.d.ts

@ -25,7 +25,7 @@ export class InjectedProviderDefaultBase extends InjectedProvider {
} }
const profile = { const profile = {
name: 'injected', name: 'injected', // the name will be overwritten in the constructor.
displayName: 'Injected Provider', displayName: 'Injected Provider',
kind: 'provider', kind: 'provider',
description: 'injected Provider', description: 'injected Provider',

@ -155,26 +155,28 @@ export class RunTab extends ViewPlugin {
}) })
} }
const addCustomInjectedProvider = async (position, event, name, networkId, urls, nativeCurrency) => { const addCustomInjectedProvider = async (position, event, name, displayName, networkId, urls, nativeCurrency) => {
// name = `${name} through ${event.detail.info.name}` // name = `${name} through ${event.detail.info.name}`
await this.engine.register([new InjectedCustomProvider(event.detail.provider, name, networkId, urls, nativeCurrency)]) await this.engine.register([new InjectedCustomProvider(event.detail.provider, name, networkId, urls, nativeCurrency)])
await addProvider(position, name, name, true, false, false) await addProvider(position, name, displayName, true, false, false)
} }
const registerInjectedProvider = async (event) => { const registerInjectedProvider = async (event) => {
console.log('registerInjectedProvider', event) console.log('registerInjectedProvider', event)
await this.engine.register([new InjectedProviderDefault(event.detail.provider, event.detail.info.name)]) const name = 'injected-' + event.detail.info.name
await addProvider(0, event.detail.info.name, 'Injected Provider - ' + event.detail.info.name, true, false, false) const displayName = 'Injected Provider - ' + event.detail.info.name
await this.engine.register([new InjectedProviderDefault(event.detail.provider, name)])
await addProvider(0, name, displayName, true, false, false)
if (event.detail.info.name === 'MetaMask') { if (event.detail.info.name === 'MetaMask') {
await addCustomInjectedProvider(5, event, 'L2 - Optimism', '0xa', ['https://mainnet.optimism.io']) await addCustomInjectedProvider(5, event, 'injected-metamask-optimism', 'L2 - Optimism', '0xa', ['https://mainnet.optimism.io'])
await addCustomInjectedProvider(6, event, 'L2 - Arbitrum One', '0xa4b1', ['https://arb1.arbitrum.io/rpc']) await addCustomInjectedProvider(6, event, 'injected-metamask-arbitrum', '0xa4b1', ['https://arb1.arbitrum.io/rpc'])
await addCustomInjectedProvider(7, event, 'Sepolia Testnet', '0xaa36a7', [], await addCustomInjectedProvider(7, event, 'injected-metamask-sepolia', '0xaa36a7', [],
{ {
"name": "Sepolia ETH", "name": "Sepolia ETH",
"symbol": "ETH", "symbol": "ETH",
"decimals": 18 "decimals": 18
}) })
await addCustomInjectedProvider(8, event, 'Ephemery Testnet', '', ['https://otter.bordel.wtf/erigon', 'https://eth.ephemeral.zeus.fyi'], await addCustomInjectedProvider(8, event, 'injected-metamask-ephemery', 'Ephemery Testnet', '', ['https://otter.bordel.wtf/erigon', 'https://eth.ephemeral.zeus.fyi'],
{ {
"name": "Ephemery ETH", "name": "Ephemery ETH",
"symbol": "ETH", "symbol": "ETH",

@ -61,6 +61,7 @@ export class Blockchain extends Plugin {
} }
providers: {[key: string]: VMProvider | InjectedProvider | NodeProvider} providers: {[key: string]: VMProvider | InjectedProvider | NodeProvider}
transactionContextAPI: TransactionContextAPI transactionContextAPI: TransactionContextAPI
registeredPluginEvents: string[]
// NOTE: the config object will need to be refactored out in remix-lib // NOTE: the config object will need to be refactored out in remix-lib
constructor(config: Config) { constructor(config: Config) {
@ -91,6 +92,7 @@ export class Blockchain extends Plugin {
this.networkcallid = 0 this.networkcallid = 0
this.networkStatus = {network: {name: ' - ', id: ' - '}} this.networkStatus = {network: {name: ' - ', id: ' - '}}
this.registeredPluginEvents = []
this.setupEvents() this.setupEvents()
this.setupProviders() this.setupProviders()
} }
@ -103,34 +105,23 @@ export class Blockchain extends Plugin {
onActivation() { onActivation() {
this.active = true this.active = true
this.on('injected', 'chainChanged', () => { this.on('manager', 'pluginActivated', (plugin) => {
this.detectNetwork((error, network) => { if (plugin && plugin.name && (plugin.name.startsWith('injected') || plugin.name === 'walletconnect')) {
this.networkStatus = {network, error} this.on(plugin.name, 'chainChanged', () => {
this._triggerEvent('networkStatus', [this.networkStatus]) this.detectNetwork((error, network) => {
}) this.networkStatus = {network, error}
}) this._triggerEvent('networkStatus', [this.networkStatus])
})
this.on('injected-trustwallet', 'chainChanged', () => { })
this.detectNetwork((error, network) => { }
this.networkStatus = {network, error}
this._triggerEvent('networkStatus', [this.networkStatus])
})
})
this.on('walletconnect', 'chainChanged', () => {
this.detectNetwork((error, network) => {
this.networkStatus = {network, error}
this._triggerEvent('networkStatus', [this.networkStatus])
})
}) })
} }
onDeactivation() { onDeactivation() {
this.active = false this.active = false
this.off('injected', 'chainChanged') for (const plugin of this.registeredPluginEvents) {
this.off('injected-trustwallet', 'chainChanged') this.off(plugin, 'chainChanged')
this.off('walletconnect', 'chainChanged') }
this.off('walletconnect', 'accountsChanged')
} }
setupEvents() { setupEvents() {
@ -175,6 +166,7 @@ export class Blockchain extends Plugin {
getCurrentProvider() { getCurrentProvider() {
const provider = this.getProvider() const provider = this.getProvider()
if (provider && provider.startsWith('vm')) return this.providers['vm'] if (provider && provider.startsWith('vm')) return this.providers['vm']
if (provider && provider.startsWith('injected')) return this.providers['injected']
if (this.providers[provider]) return this.providers[provider] if (this.providers[provider]) return this.providers[provider]
return this.providers.web3 // default to the common type of provider return this.providers.web3 // default to the common type of provider
} }
@ -534,16 +526,6 @@ export class Blockchain extends Plugin {
return this.executionContext.getCurrentFork() return this.executionContext.getCurrentFork()
} }
isWeb3Provider() {
const isVM = this.executionContext.isVM()
const isInjected = this.getProvider() === 'injected'
return !isVM && !isInjected
}
isInjectedWeb3() {
return this.getProvider() === 'injected'
}
signMessage(message, account, passphrase, cb) { signMessage(message, account, passphrase, cb) {
this.getCurrentProvider().signMessage(message, account, passphrase, cb) this.getCurrentProvider().signMessage(message, account, passphrase, cb)
} }

@ -48,8 +48,4 @@ export class InjectedProvider {
cb(e.message) cb(e.message)
} }
} }
getProvider () {
return 'injected'
}
} }

@ -55,8 +55,4 @@ export class NodeProvider {
cb(e.message) cb(e.message)
} }
} }
getProvider () {
return this.executionContext.getProvider()
}
} }

@ -134,9 +134,5 @@ export class VMProvider {
this.web3.eth.sign(message, account) this.web3.eth.sign(message, account)
.then(signedData => cb(null, bytesToHex(messageHash), signedData)) .then(signedData => cb(null, bytesToHex(messageHash), signedData))
.catch(error => cb(error)) .catch(error => cb(error))
} }
getProvider () {
return this.executionContext.getProvider()
}
} }

@ -52,7 +52,6 @@ let requiredModules = [ // services + layout views + system views
'ganache-provider', 'ganache-provider',
'foundry-provider', 'foundry-provider',
'basic-http-provider', 'basic-http-provider',
'injected',
'injected-trustwallet', 'injected-trustwallet',
'injected-optimism-provider', 'injected-optimism-provider',
'injected-arbitrum-one-provider', 'injected-arbitrum-one-provider',
@ -122,7 +121,6 @@ export function isNative(name) {
'injected-arbitrum-one-provider', 'injected-arbitrum-one-provider',
'injected-skale-chaos-testnet-provider', 'injected-skale-chaos-testnet-provider',
'injected-ephemery-testnet-provider', 'injected-ephemery-testnet-provider',
'injected',
'doc-gen', 'doc-gen',
'doc-viewer', 'doc-viewer',
'circuit-compiler', 'circuit-compiler',

@ -106,7 +106,7 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
const providerChanged = () => { const providerChanged = () => {
debuggerModule.onEnvChanged((provider) => { debuggerModule.onEnvChanged((provider) => {
setState((prevState) => { setState((prevState) => {
const isLocalNodeUsed = !provider.startsWith('vm') && provider !== 'injected' const isLocalNodeUsed = !provider.startsWith('vm') && !provider.startsWith('injected')
return {...prevState, isLocalNodeUsed: isLocalNodeUsed} return {...prevState, isLocalNodeUsed: isLocalNodeUsed}
}) })
}) })

@ -30,7 +30,7 @@ export const fillAccountsList = async (plugin: RunTab, dispatch: React.Dispatch<
} }
const provider = plugin.blockchain.getProvider() const provider = plugin.blockchain.getProvider()
if (provider === 'injected') { if (provider && provider.startsWith('injected')) {
const selectedAddress = plugin.blockchain.getInjectedWeb3Address() const selectedAddress = plugin.blockchain.getInjectedWeb3Address()
if (!(Object.keys(loadedAccounts).includes(toChecksumAddress(selectedAddress)))) setAccount(dispatch, null) if (!(Object.keys(loadedAccounts).includes(toChecksumAddress(selectedAddress)))) setAccount(dispatch, null)
} }

@ -116,9 +116,29 @@ export const setupEvents = (plugin: RunTab, dispatch: React.Dispatch<any>) => {
}) })
}) })
plugin.on('manager', 'pluginActivated', (plugin: Plugin) => { plugin.on('manager', 'pluginActivated', (activatedPlugin: Plugin) => {
if (plugin.name === 'remixd') { if (activatedPlugin.name === 'remixd') {
dispatch(setRemixDActivated(true)) dispatch(setRemixDActivated(true))
} else {
if (activatedPlugin && activatedPlugin.name.startsWith('injected')) {
plugin.on(activatedPlugin.name, 'accountsChanged', (accounts: Array<string>) => {
const accountsMap = {}
accounts.map(account => { accountsMap[account] = shortenAddress(account, '0')})
dispatch(fetchAccountsListSuccess(accountsMap))
})
} else if (activatedPlugin && activatedPlugin.name === 'walletconnect') {
plugin.on('walletconnect', 'accountsChanged', async (accounts: Array<string>) => {
const accountsMap = {}
await Promise.all(accounts.map(async (account) => {
const balance = await plugin.blockchain.getBalanceInEther(account)
const updated = shortenAddress(account, balance)
accountsMap[account] = updated
}))
dispatch(fetchAccountsListSuccess(accountsMap))
})
}
} }
}) })
@ -150,29 +170,6 @@ export const setupEvents = (plugin: RunTab, dispatch: React.Dispatch<any>) => {
dispatch(clearRecorderCount()) dispatch(clearRecorderCount())
}) })
plugin.on('injected', 'accountsChanged', (accounts: Array<string>) => {
const accountsMap = {}
accounts.map(account => { accountsMap[account] = shortenAddress(account, '0')})
dispatch(fetchAccountsListSuccess(accountsMap))
})
plugin.on('injected-trustwallet', 'accountsChanged', (accounts: Array<string>) => {
const accountsMap = {}
accounts.map(account => { accountsMap[account] = shortenAddress(account, '0')})
dispatch(fetchAccountsListSuccess(accountsMap))
})
plugin.on('walletconnect', 'accountsChanged', async (accounts: Array<string>) => {
const accountsMap = {}
await Promise.all(accounts.map(async (account) => {
const balance = await plugin.blockchain.getBalanceInEther(account)
const updated = shortenAddress(account, balance)
accountsMap[account] = updated
}))
dispatch(fetchAccountsListSuccess(accountsMap))
})
setInterval(() => { setInterval(() => {
fillAccountsList(plugin, dispatch) fillAccountsList(plugin, dispatch)

@ -26,69 +26,69 @@ export function AccountUI(props: AccountProps) {
useEffect(() => { useEffect(() => {
props.setAccount('') props.setAccount('')
switch (selectExEnv) { if (selectExEnv && selectExEnv.startsWith('injected')) {
case 'injected':
setPlusOpt({ setPlusOpt({
classList: 'udapp_disableMouseEvents', classList: 'udapp_disableMouseEvents',
title: intl.formatMessage({id: 'udapp.injectedTitle'}) title: intl.formatMessage({id: 'udapp.injectedTitle'})
}) })
break } else {
switch (selectExEnv) {
case 'vm-cancun': case 'vm-cancun':
setPlusOpt({ setPlusOpt({
classList: '', classList: '',
title: intl.formatMessage({id: 'udapp.createNewAccount'}) title: intl.formatMessage({id: 'udapp.createNewAccount'})
}) })
break break
case 'vm-paris': case 'vm-paris':
setPlusOpt({ setPlusOpt({
classList: '', classList: '',
title: intl.formatMessage({id: 'udapp.createNewAccount'}) title: intl.formatMessage({id: 'udapp.createNewAccount'})
}) })
break break
case 'vm-london': case 'vm-london':
setPlusOpt({ setPlusOpt({
classList: '', classList: '',
title: intl.formatMessage({id: 'udapp.createNewAccount'}) title: intl.formatMessage({id: 'udapp.createNewAccount'})
}) })
break break
case 'vm-berlin': case 'vm-berlin':
setPlusOpt({ setPlusOpt({
classList: '', classList: '',
title: intl.formatMessage({id: 'udapp.createNewAccount'}) title: intl.formatMessage({id: 'udapp.createNewAccount'})
}) })
break break
case 'vm-shanghai': case 'vm-shanghai':
setPlusOpt({ setPlusOpt({
classList: '', classList: '',
title: intl.formatMessage({id: 'udapp.createNewAccount'}) title: intl.formatMessage({id: 'udapp.createNewAccount'})
}) })
break break
case 'web3': case 'web3':
if (!personalMode) { if (!personalMode) {
setPlusOpt({ setPlusOpt({
classList: 'disableMouseEvents', classList: 'disableMouseEvents',
title: intl.formatMessage({id: 'udapp.web3Title'}) title: intl.formatMessage({id: 'udapp.web3Title'})
}) })
} else { } else {
setPlusOpt({ setPlusOpt({
classList: '', classList: '',
title: intl.formatMessage({id: 'udapp.createNewAccount'}) title: intl.formatMessage({id: 'udapp.createNewAccount'})
}) })
} }
break break
default: default:
setPlusOpt({ setPlusOpt({
classList: 'disableMouseEvents', classList: 'disableMouseEvents',
title: intl.formatMessage({id: 'udapp.defaultTitle'}, {selectExEnv}) title: intl.formatMessage({id: 'udapp.defaultTitle'}, {selectExEnv})
}) })
} }
}
}, [selectExEnv, personalMode]) }, [selectExEnv, personalMode])
const newAccount = () => { const newAccount = () => {

@ -297,7 +297,7 @@ export function UniversalDappUI(props: UdappProps) {
<label> <label>
<b><FormattedMessage id="udapp.balance" />:</b> {instanceBalance} ETH <b><FormattedMessage id="udapp.balance" />:</b> {instanceBalance} ETH
</label> </label>
{props.exEnvironment === 'injected' && <i className="fas fa-edit btn btn-sm p-0" onClick={() => {props.editInstance(props.instance)}}></i>} {props.exEnvironment.indexOf('Injected Provider') > -1 && <i className="fas fa-edit btn btn-sm p-0" onClick={() => {props.editInstance(props.instance)}}></i>}
</div> </div>
{ props.isPinnedContract && props.instance.pinnedAt ? ( { props.isPinnedContract && props.instance.pinnedAt ? (
<div className="d-flex" data-id="instanceContractPinnedAt"> <div className="d-flex" data-id="instanceContractPinnedAt">

@ -47,8 +47,6 @@ export class Blockchain extends Plugin<any, any> {
* @return {String} - fork name * @return {String} - fork name
*/ */
getCurrentFork(): string; getCurrentFork(): string;
isWeb3Provider(): boolean;
isInjectedWeb3(): boolean;
signMessage(message: any, account: any, passphrase: any, cb: any): void; signMessage(message: any, account: any, passphrase: any, cb: any): void;
web3(): any; web3(): any;
getTxListener(opts: any): any; getTxListener(opts: any): any;

@ -8,5 +8,4 @@ declare class InjectedProvider {
getBalanceInEther(address: any): Promise<string>; getBalanceInEther(address: any): Promise<string>;
getGasPrice(cb: any): void; getGasPrice(cb: any): void;
signMessage(message: any, account: any, _passphrase: any, cb: any): void; signMessage(message: any, account: any, _passphrase: any, cb: any): void;
getProvider(): string;
} }

@ -9,5 +9,4 @@ declare class NodeProvider {
getBalanceInEther(address: any): Promise<string>; getBalanceInEther(address: any): Promise<string>;
getGasPrice(cb: any): void; getGasPrice(cb: any): void;
signMessage(message: any, account: any, passphrase: any, cb: any): void; signMessage(message: any, account: any, passphrase: any, cb: any): void;
getProvider(): any;
} }

@ -12,5 +12,4 @@ declare class VMProvider {
getBalanceInEther(address: any): Promise<string>; getBalanceInEther(address: any): Promise<string>;
getGasPrice(cb: any): void; getGasPrice(cb: any): void;
signMessage(message: any, account: any, _passphrase: any, cb: any): void; signMessage(message: any, account: any, _passphrase: any, cb: any): void;
getProvider(): string;
} }

Loading…
Cancel
Save