Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async _ethConnect(): Promise {
this.debug('connecting to gateway', this.config.ethereum.gateway)
const provider = ETHProvider(this.config.ethereum.gateway)
const spinner = ora('Connecting to Ethereum').start()
while (true) {
try {
const accounts = await provider.send('eth_accounts')
spinner.stop()
for (const account of accounts) {
if (account === this.config.ethereum.account) return provider
}
this._die("Failed to access your Ethereum account. Update your gateway configuration or run 'git pando config' to select another account.")
} catch (err) {
if (err.code === 4100 || err.code === 4001) {
spinner.text = `Error connecting to Ethereum. ${err.message}.`
await _timeout(2000)
} else {
spinner.stop()
export default async (): Promise => {
const configuration = {
ethereum: {
account: undefined as any,
gateway: undefined as any,
},
ipfs: {
gateway: undefined as any,
},
}
const type = (await inquirer.prompt(questions.ethereum.type)).result
configuration.ethereum.gateway = type === 'Frame' ? FRAME_ENDPOINT : (await inquirer.prompt(questions.ethereum.gateway)).result
const provider = ETHProvider(configuration.ethereum.gateway)
const message = type === 'Frame' ? 'Connecting to Frame' : 'Connecting to Ethereum gateway'
const spinner = ora(message).start()
while (true) {
try {
const accounts = await provider.send('eth_accounts')
spinner.stop()
configuration.ethereum.account = (await inquirer.prompt(await questions.ethereum.account(accounts))).result
break
} catch (err) {
spinner.text = message + ': ' + err.message
await _timeout(2000)
}
}
configuration.ipfs.gateway = (await inquirer.prompt(questions.ipfs.gateway)).result
private static async _provider(options: IPandoOptions): Promise {
const provider = ETHProvider(options.ethereum.gateway)
const spinner = ora('Connecting to Ethereum').start()
while (true) {
try {
const accounts = await provider.send('eth_accounts')
spinner.stop()
for (const account of accounts) {
if (account === options.ethereum.account) return provider
}
die("Failed to access your Ethereum account. Update your gateway configuration or run 'git pando config' to select another account.")
} catch (err) {
if (err.code === 4100 || err.code === 4001) {
spinner.text = `Error connecting to Ethereum. ${err.message}.`
await _timeout(2000)
} else {
spinner.stop()
public async activate(): Promise {
if (!this.provider) {
this.provider = ethProvider('frame')
}
this.provider
.on('networkChanged', this.handleNetworkChanged)
.on('chainChanged', this.handleChainChanged)
.on('accountsChanged', this.handleAccountsChanged)
.on('close', this.handleClose)
const account = await this.provider
.enable()
.then((accounts: string[]): string => accounts[0])
.catch((error: Error): void => {
if (error && (error as any).code === 4001) {
throw new UserRejectedRequestError()
} else {
throw error