UNPKG

autemaliquam

Version:

A simple, maximally extensible, dependency minimized framework for building modern Ethereum dApps

64 lines (49 loc) 1.51 kB
import { ConnectorUpdate } from '@web3-react-wan/types' import { AbstractConnector } from '@web3-react-wan/abstract-connector' const chainIdToNetwork: { [network: number]: string } = { 1: 'mainnet', 3: 'testnet', 6: 'pluto-dev' } interface AuthereumConnectorArguments { chainId: number config?: any } export class AuthereumConnector extends AbstractConnector { private readonly chainId: number private readonly config: any public authereum: any constructor({ chainId, config = {} }: AuthereumConnectorArguments) { super({ supportedChainIds: [chainId] }) this.chainId = chainId this.config = config } public async activate(): Promise<ConnectorUpdate> { if (!this.authereum) { const Authereum = await import('authereum').then(m => m?.default ?? m) this.authereum = new Authereum({ networkName: chainIdToNetwork[this.chainId], ...this.config }) } await this.authereum .getProvider() .enable() .then((accounts: string[]): string => accounts[0]) return { provider: this.authereum.getProvider() } } public async getProvider(): Promise<any> { return this.authereum.getProvider() } public async getChainId(): Promise<number | string> { return this.authereum.getNetworkId() } public async getAccount(): Promise<null | string> { return this.authereum.getAccountAddress() } public deactivate() {} public async close() { this.authereum.logout() this.emitDeactivate() } }