|
|
@ -3,21 +3,27 @@ import { createClient } from '@remixproject/plugin-webview' |
|
|
|
import { w3mConnectors, w3mProvider } from '@web3modal/ethereum' |
|
|
|
import { w3mConnectors, w3mProvider } from '@web3modal/ethereum' |
|
|
|
import { configureChains, createClient as wagmiCreateClient } from 'wagmi' |
|
|
|
import { configureChains, createClient as wagmiCreateClient } from 'wagmi' |
|
|
|
import { arbitrum, mainnet, polygon, optimism, Chain, goerli, sepolia } from 'wagmi/chains' |
|
|
|
import { arbitrum, mainnet, polygon, optimism, Chain, goerli, sepolia } from 'wagmi/chains' |
|
|
|
|
|
|
|
import EventManager from "events" |
|
|
|
import { PROJECT_ID } from './constant' |
|
|
|
import { PROJECT_ID } from './constant' |
|
|
|
|
|
|
|
|
|
|
|
export class RemixClient extends PluginClient { |
|
|
|
export class RemixClient extends PluginClient { |
|
|
|
wagmiClient |
|
|
|
wagmiClient |
|
|
|
chains: Chain[] |
|
|
|
chains: Chain[] |
|
|
|
|
|
|
|
internalEvents: EventManager |
|
|
|
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
constructor() { |
|
|
|
super() |
|
|
|
super() |
|
|
|
createClient(this) |
|
|
|
createClient(this) |
|
|
|
|
|
|
|
this.internalEvents = new EventManager() |
|
|
|
this.methods = ["sendAsync", "init"] |
|
|
|
this.methods = ["sendAsync", "init"] |
|
|
|
this.onload() |
|
|
|
this.onload() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onActivation () { |
|
|
|
onActivation () { |
|
|
|
this.subscribeToEvents() |
|
|
|
this.subscribeToEvents() |
|
|
|
|
|
|
|
this.call('theme', 'currentTheme').then((theme: any) => { |
|
|
|
|
|
|
|
this.internalEvents.emit('themeChanged', theme.quality.toLowerCase()) |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
init () { |
|
|
|
init () { |
|
|
@ -30,7 +36,7 @@ export class RemixClient extends PluginClient { |
|
|
|
const { provider } = configureChains(this.chains, [w3mProvider({ projectId: PROJECT_ID })]) |
|
|
|
const { provider } = configureChains(this.chains, [w3mProvider({ projectId: PROJECT_ID })]) |
|
|
|
|
|
|
|
|
|
|
|
this.wagmiClient = wagmiCreateClient({ |
|
|
|
this.wagmiClient = wagmiCreateClient({ |
|
|
|
autoConnect: true, |
|
|
|
autoConnect: false, |
|
|
|
connectors: w3mConnectors({ projectId: PROJECT_ID, version: 1, chains: this.chains }), |
|
|
|
connectors: w3mConnectors({ projectId: PROJECT_ID, version: 1, chains: this.chains }), |
|
|
|
provider |
|
|
|
provider |
|
|
|
}) |
|
|
|
}) |
|
|
@ -49,6 +55,9 @@ export class RemixClient extends PluginClient { |
|
|
|
this.emit('chainChanged', 0) |
|
|
|
this.emit('chainChanged', 0) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
this.on('theme', 'themeChanged', (theme: any) => { |
|
|
|
|
|
|
|
this.internalEvents.emit('themeChanged', theme.quality) |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sendAsync = (data: { method: string, params: string, id: string }) => { |
|
|
|
sendAsync = (data: { method: string, params: string, id: string }) => { |
|
|
|