Merge pull request #5096 from evgeniuz/develop

implemented improvements to RPC history
feature/default_network_editable
Dan J Miller 6 years ago committed by GitHub
commit 3ae082aad8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/scripts/controllers/preferences.js
  2. 11
      old-ui/app/components/app-bar.js
  3. 60
      test/e2e/beta/metamask-beta-ui.spec.js
  4. 12
      ui/app/components/dropdowns/network-dropdown.js

@ -322,7 +322,7 @@ class PreferencesController {
/** /**
* Returns an updated rpcList based on the passed url and the current list. * Returns an updated rpcList based on the passed url and the current list.
* The returned list will have a max length of 2. If the _url currently exists it the list, it will be moved to the * The returned list will have a max length of 3. If the _url currently exists it the list, it will be moved to the
* end of the list. The current list is modified and returned as a promise. * end of the list. The current list is modified and returned as a promise.
* *
* @param {string} _url The rpc url to add to the frequentRpcList. * @param {string} _url The rpc url to add to the frequentRpcList.
@ -338,7 +338,7 @@ class PreferencesController {
if (_url !== 'http://localhost:8545') { if (_url !== 'http://localhost:8545') {
rpcList.push(_url) rpcList.push(_url)
} }
if (rpcList.length > 2) { if (rpcList.length > 3) {
rpcList.shift() rpcList.shift()
} }
return Promise.resolve(rpcList) return Promise.resolve(rpcList)

@ -350,11 +350,14 @@ module.exports = class AppBar extends Component {
} }
} }
renderCommonRpc (rpcList, {rpcTarget}) { renderCommonRpc (rpcList, provider) {
const {dispatch} = this.props const {dispatch} = this.props
const reversedRpcList = rpcList.slice().reverse()
return rpcList.map((rpc) => { return reversedRpcList.map((rpc) => {
if ((rpc === LOCALHOST_RPC_URL) || (rpc === rpcTarget)) { const currentRpcTarget = provider.type === 'rpc' && rpc === provider.rpcTarget
if ((rpc === LOCALHOST_RPC_URL) || currentRpcTarget) {
return null return null
} else { } else {
return h(DropdownMenuItem, { return h(DropdownMenuItem, {
@ -364,7 +367,7 @@ module.exports = class AppBar extends Component {
}, [ }, [
h('i.fa.fa-question-circle.fa-lg.menu-icon'), h('i.fa.fa-question-circle.fa-lg.menu-icon'),
rpc, rpc,
rpcTarget === rpc currentRpcTarget
? h('.check', '✓') ? h('.check', '✓')
: null, : null,
]) ])

@ -1011,4 +1011,64 @@ describe('MetaMask', function () {
await delay(regularDelayMs) await delay(regularDelayMs)
}) })
}) })
describe('Stores custom RPC history', () => {
const customRpcUrls = [
'https://mainnet.infura.io/1',
'https://mainnet.infura.io/2',
'https://mainnet.infura.io/3',
'https://mainnet.infura.io/4',
]
customRpcUrls.forEach(customRpcUrl => {
it('creates custom RPC: ' + customRpcUrl, async () => {
const networkDropdown = await findElement(driver, By.css('.network-name'))
await networkDropdown.click()
await delay(regularDelayMs)
const customRpcButton = await findElement(driver, By.xpath(`//span[contains(text(), 'Custom RPC')]`))
await customRpcButton.click()
await delay(regularDelayMs)
const customRpcInput = await findElement(driver, By.css('input[placeholder="New RPC URL"]'))
await customRpcInput.clear()
await customRpcInput.sendKeys(customRpcUrl)
const customRpcSave = await findElement(driver, By.css('.settings__rpc-save-button'))
await customRpcSave.click()
await delay(largeDelayMs * 2)
})
})
it('selects another provider', async () => {
const networkDropdown = await findElement(driver, By.css('.network-name'))
await networkDropdown.click()
await delay(regularDelayMs)
const customRpcButton = await findElement(driver, By.xpath(`//span[contains(text(), 'Main Ethereum Network')]`))
await customRpcButton.click()
await delay(largeDelayMs * 2)
})
it('finds 3 recent RPCs in history', async () => {
const networkDropdown = await findElement(driver, By.css('.network-name'))
await networkDropdown.click()
await delay(regularDelayMs)
// oldest selected RPC is not found
await assertElementNotPresent(webdriver, driver, By.xpath(`//span[contains(text(), '${customRpcUrls[0]}')]`))
// only recent 3 are found and in correct order (most recent at the top)
const customRpcs = await findElements(driver, By.xpath(`//span[contains(text(), 'https://mainnet.infura.io/')]`))
assert.equal(customRpcs.length, 3)
for (let i = 0; i < customRpcs.length; i++) {
const linkText = await customRpcs[i].getText()
const rpcUrl = customRpcUrls[customRpcUrls.length - i - 1]
assert.notEqual(linkText.indexOf(rpcUrl), -1)
}
})
})
}) })

@ -272,10 +272,12 @@ NetworkDropdown.prototype.getNetworkName = function () {
NetworkDropdown.prototype.renderCommonRpc = function (rpcList, provider) { NetworkDropdown.prototype.renderCommonRpc = function (rpcList, provider) {
const props = this.props const props = this.props
const rpcTarget = provider.rpcTarget const reversedRpcList = rpcList.slice().reverse()
return rpcList.map((rpc) => { return reversedRpcList.map((rpc) => {
if ((rpc === 'http://localhost:8545') || (rpc === rpcTarget)) { const currentRpcTarget = provider.type === 'rpc' && rpc === provider.rpcTarget
if ((rpc === 'http://localhost:8545') || currentRpcTarget) {
return null return null
} else { } else {
return h( return h(
@ -291,11 +293,11 @@ NetworkDropdown.prototype.renderCommonRpc = function (rpcList, provider) {
}, },
}, },
[ [
rpcTarget === rpc ? h('i.fa.fa-check') : h('.network-check__transparent', '✓'), currentRpcTarget ? h('i.fa.fa-check') : h('.network-check__transparent', '✓'),
h('i.fa.fa-question-circle.fa-med.menu-icon-circle'), h('i.fa.fa-question-circle.fa-med.menu-icon-circle'),
h('span.network-name-item', { h('span.network-name-item', {
style: { style: {
color: rpcTarget === rpc ? '#ffffff' : '#9b9b9b', color: currentRpcTarget ? '#ffffff' : '#9b9b9b',
}, },
}, rpc), }, rpc),
] ]

Loading…
Cancel
Save