|
|
@ -1,9 +1,9 @@ |
|
|
|
import {PluginClient} from '@remixproject/plugin' |
|
|
|
import { PluginClient } from '@remixproject/plugin' |
|
|
|
import {createClient} from '@remixproject/plugin-webview' |
|
|
|
import { createClient } from '@remixproject/plugin-webview' |
|
|
|
import { createWeb3Modal, defaultConfig } from '@web3modal/ethers5/react' |
|
|
|
import { createWeb3Modal, defaultConfig } from '@web3modal/ethers5/react' |
|
|
|
import { constants } from '../utils/constants' |
|
|
|
import { constants } from '../utils/constants' |
|
|
|
import EventManager from 'events' |
|
|
|
import EventManager from 'events' |
|
|
|
import {PROJECT_ID as projectId, METADATA as metadata} from './constant' |
|
|
|
import { PROJECT_ID as projectId, METADATA as metadata } from './constant' |
|
|
|
import { Chain, RequestArguments } from '../types' |
|
|
|
import { Chain, RequestArguments } from '../types' |
|
|
|
|
|
|
|
|
|
|
|
export class WalletConnectRemixClient extends PluginClient { |
|
|
|
export class WalletConnectRemixClient extends PluginClient { |
|
|
@ -50,7 +50,7 @@ export class WalletConnectRemixClient extends PluginClient { |
|
|
|
|
|
|
|
|
|
|
|
subscribeToEvents() { |
|
|
|
subscribeToEvents() { |
|
|
|
this.web3modal.subscribeProvider(({ address, isConnected, chainId })=>{ |
|
|
|
this.web3modal.subscribeProvider(({ address, isConnected, chainId })=>{ |
|
|
|
if(isConnected){ |
|
|
|
if (isConnected){ |
|
|
|
if (address !== this.currentAccount) { |
|
|
|
if (address !== this.currentAccount) { |
|
|
|
this.currentAccount = address |
|
|
|
this.currentAccount = address |
|
|
|
this.emit('accountsChanged', [address]) |
|
|
|
this.emit('accountsChanged', [address]) |
|
|
@ -59,7 +59,7 @@ export class WalletConnectRemixClient extends PluginClient { |
|
|
|
this.currentChain = chainId |
|
|
|
this.currentChain = chainId |
|
|
|
this.emit('chainChanged', chainId) |
|
|
|
this.emit('chainChanged', chainId) |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
this.emit('accountsChanged', []) |
|
|
|
this.emit('accountsChanged', []) |
|
|
|
this.currentAccount = '' |
|
|
|
this.currentAccount = '' |
|
|
|
this.emit('chainChanged', 0) |
|
|
|
this.emit('chainChanged', 0) |
|
|
@ -114,16 +114,16 @@ export class WalletConnectRemixClient extends PluginClient { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const message = await provider.request(data) |
|
|
|
const message = await provider.request(data) |
|
|
|
return {jsonrpc: '2.0', result: message, id: data.id} |
|
|
|
return { jsonrpc: '2.0', result: message, id: data.id } |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
return {jsonrpc: '2.0', error: { message: e.message, code: -32603 }, id: data.id} |
|
|
|
return { jsonrpc: '2.0', error: { message: e.message, code: -32603 }, id: data.id } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const err = `Cannot make ${data.method} request. Remix client is not connected to walletconnect client` |
|
|
|
const err = `Cannot make ${data.method} request. Remix client is not connected to walletconnect client` |
|
|
|
console.error(err) |
|
|
|
console.error(err) |
|
|
|
return {jsonrpc: '2.0', error: { message: err, code: -32603 }, id: data.id} |
|
|
|
return { jsonrpc: '2.0', error: { message: err, code: -32603 }, id: data.id } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|