Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom network and private key import #6

Merged
merged 3 commits into from Nov 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 49 additions & 0 deletions index.js
Expand Up @@ -118,6 +118,55 @@ module.exports = {
await waitForUnlockedScreen(metamaskPage)
},

addNetwork: async (url) => {
await metamaskPage.bringToFront()
const networkSwitcher = await metamaskPage.$('.network-indicator')
await networkSwitcher.click()
await timeout(0.5)
const networkIndex = await metamaskPage.evaluate(network => {
const elements = document.querySelectorAll('li.dropdown-menu-item')
for (let i = 0; i < elements.length; i++) {
const element = elements[i]
if (
element.innerText.toLowerCase().includes(network.toLowerCase())
) {
return i
}
}
return 0
}, 'Custom RPC')
const networkButton = (await metamaskPage.$$('li.dropdown-menu-item'))[
networkIndex
]
await networkButton.click()
await timeout(0.5)
const newRPCInput = await metamaskPage.$('input#new_rpc')
await newRPCInput.type(url)
const saveButton = await metamaskPage.$('input#new_rpc+button')
await saveButton.click()
await timeout(0.5)
const prevButton = await metamaskPage.$('i.fa-arrow-left')
await prevButton.click()
await timeout(0.5)
await waitForEthereum(metamaskPage)
},

importPK: async (pk) => {
await metamaskPage.bringToFront()
const accountSwitcher = await metamaskPage.$('.accounts-selector')
await accountSwitcher.click()
await timeout(0.5)
const addAccount = await metamaskPage.$('.menu-droppo .dropdown-menu-item:last-child')
await addAccount.click()
await timeout(0.5)
const PKInput = await metamaskPage.$('input#private-key-box')
await PKInput.type(pk)
const importButton = await metamaskPage.$('input#private-key-box+button')
await importButton.click()
await timeout(0.5)
await waitForEthereum(metamaskPage)
},

switchNetwork: async (network = 'main') => {
await metamaskPage.bringToFront()
const networkSwitcher = await metamaskPage.$('.network-indicator')
Expand Down