2019-07-02 16:12:57 +03:00
|
|
|
/* eslint-disable no-return-await */
|
|
|
|
const { MetaMask } = require('./MetaMask.js')
|
|
|
|
const { MainPage } = require('./mainPage.js')
|
2019-05-09 13:03:18 +03:00
|
|
|
|
|
|
|
class User {
|
2019-07-02 16:12:57 +03:00
|
|
|
constructor(driver, obj) {
|
|
|
|
try {
|
|
|
|
this.driver = driver
|
|
|
|
this.account = obj.account
|
|
|
|
this.privateKey = obj.privateKey
|
|
|
|
this.networkID = obj.networkID
|
|
|
|
this.accountOrderInMetamask = 'undefined' // for MetaMaskPage usage only
|
|
|
|
} catch (err) {
|
|
|
|
console.log('instance User was not created')
|
|
|
|
console.log(err)
|
|
|
|
}
|
|
|
|
}
|
2019-05-09 13:03:18 +03:00
|
|
|
|
2019-07-02 16:12:57 +03:00
|
|
|
async transferTokens(amount) {
|
|
|
|
const mainPage = new MainPage(this.driver)
|
|
|
|
const metaMask = new MetaMask(this.driver)
|
|
|
|
return (
|
|
|
|
(await mainPage.fillFieldAmount(amount)) &&
|
|
|
|
(await mainPage.clickButtonTransfer()) &&
|
|
|
|
(await mainPage.waitUntilShowUpButtonTransferConfirm()) &&
|
|
|
|
(await mainPage.clickButtonTransferConfirm()) &&
|
|
|
|
(await metaMask.signTransaction()) &&
|
|
|
|
(await mainPage.waitUntilTransactionDone()) &&
|
|
|
|
(await mainPage.waitUntilShowUpButtonOk()) &&
|
|
|
|
(await mainPage.clickButtonOk())
|
|
|
|
)
|
|
|
|
}
|
2019-05-09 13:03:18 +03:00
|
|
|
|
2019-07-02 16:12:57 +03:00
|
|
|
async setMetaMaskNetwork() {
|
|
|
|
const metaMask = new MetaMask(this.driver)
|
|
|
|
return (
|
|
|
|
(await metaMask.switchToNextPage()) &&
|
|
|
|
(await metaMask.setNetwork(this.networkID)) &&
|
|
|
|
(await metaMask.switchToNextPage())
|
|
|
|
)
|
|
|
|
}
|
2019-05-09 13:03:18 +03:00
|
|
|
|
2019-07-02 16:12:57 +03:00
|
|
|
async setMetaMaskAccount() {
|
|
|
|
const metaMask = new MetaMask(this.driver)
|
|
|
|
if (this.accountOrderInMetamask === 'undefined') {
|
|
|
|
return await metaMask.importAccount(this)
|
|
|
|
} else return await metaMask.selectAccount(this)
|
|
|
|
}
|
2019-05-09 13:03:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2019-07-02 16:12:57 +03:00
|
|
|
User
|
|
|
|
}
|