From b23cca14699b6c6a8c843c9cc020ec96fe758822 Mon Sep 17 00:00:00 2001 From: Evgeniy Filatov Date: Sun, 19 Aug 2018 20:25:33 +0300 Subject: [PATCH 1/3] implemented improvements to RPC history --- app/scripts/controllers/preferences.js | 2 +- test/e2e/beta/metamask-beta-ui.spec.js | 60 +++++++++++++++++++ .../components/dropdowns/network-dropdown.js | 10 ++-- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 707fd7de9..7456a7a7c 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -338,7 +338,7 @@ class PreferencesController { if (_url !== 'http://localhost:8545') { rpcList.push(_url) } - if (rpcList.length > 2) { + if (rpcList.length > 3) { rpcList.shift() } return Promise.resolve(rpcList) diff --git a/test/e2e/beta/metamask-beta-ui.spec.js b/test/e2e/beta/metamask-beta-ui.spec.js index 40ef90506..bb562c83a 100644 --- a/test/e2e/beta/metamask-beta-ui.spec.js +++ b/test/e2e/beta/metamask-beta-ui.spec.js @@ -1011,4 +1011,64 @@ describe('MetaMask', function () { 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) + } + }) + }) }) \ No newline at end of file diff --git a/ui/app/components/dropdowns/network-dropdown.js b/ui/app/components/dropdowns/network-dropdown.js index e5363ff56..003ec1b98 100644 --- a/ui/app/components/dropdowns/network-dropdown.js +++ b/ui/app/components/dropdowns/network-dropdown.js @@ -275,7 +275,9 @@ NetworkDropdown.prototype.renderCommonRpc = function (rpcList, provider) { const rpcTarget = provider.rpcTarget return rpcList.map((rpc) => { - if ((rpc === 'http://localhost:8545') || (rpc === rpcTarget)) { + const currentRpcTarget = provider.type === 'rpc' && rpc === rpcTarget + + if ((rpc === 'http://localhost:8545') || currentRpcTarget) { return null } else { return h( @@ -291,17 +293,17 @@ 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('span.network-name-item', { style: { - color: rpcTarget === rpc ? '#ffffff' : '#9b9b9b', + color: currentRpcTarget ? '#ffffff' : '#9b9b9b', }, }, rpc), ] ) } - }) + }).reverse() } NetworkDropdown.prototype.renderCustomOption = function (provider) { From c0b5e8a088b7ed2ac557ad2b6bc6b55d9bae1919 Mon Sep 17 00:00:00 2001 From: Evgeniy Filatov Date: Sun, 19 Aug 2018 21:02:30 +0300 Subject: [PATCH 2/3] backported RPC improvements to oldui --- old-ui/app/components/app-bar.js | 8 +++++--- ui/app/components/dropdowns/network-dropdown.js | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/old-ui/app/components/app-bar.js b/old-ui/app/components/app-bar.js index 8ab647efd..684dfbe19 100644 --- a/old-ui/app/components/app-bar.js +++ b/old-ui/app/components/app-bar.js @@ -350,11 +350,13 @@ module.exports = class AppBar extends Component { } } - renderCommonRpc (rpcList, {rpcTarget}) { + renderCommonRpc (rpcList, provider) { const {dispatch} = this.props return rpcList.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 } else { return h(DropdownMenuItem, { @@ -364,7 +366,7 @@ module.exports = class AppBar extends Component { }, [ h('i.fa.fa-question-circle.fa-lg.menu-icon'), rpc, - rpcTarget === rpc + currentRpcTarget ? h('.check', '✓') : null, ]) diff --git a/ui/app/components/dropdowns/network-dropdown.js b/ui/app/components/dropdowns/network-dropdown.js index 003ec1b98..b1aeed376 100644 --- a/ui/app/components/dropdowns/network-dropdown.js +++ b/ui/app/components/dropdowns/network-dropdown.js @@ -272,10 +272,9 @@ NetworkDropdown.prototype.getNetworkName = function () { NetworkDropdown.prototype.renderCommonRpc = function (rpcList, provider) { const props = this.props - const rpcTarget = provider.rpcTarget return rpcList.map((rpc) => { - const currentRpcTarget = provider.type === 'rpc' && rpc === rpcTarget + const currentRpcTarget = provider.type === 'rpc' && rpc === provider.rpcTarget if ((rpc === 'http://localhost:8545') || currentRpcTarget) { return null From 9a80d6e8598850fec00471c6101c194e90c30353 Mon Sep 17 00:00:00 2001 From: Evgeniy Filatov Date: Thu, 23 Aug 2018 01:26:30 +0300 Subject: [PATCH 3/3] updated docs, small improvement of recent RPC rendering --- app/scripts/controllers/preferences.js | 2 +- old-ui/app/components/app-bar.js | 3 ++- ui/app/components/dropdowns/network-dropdown.js | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 7456a7a7c..1b85e4fd1 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -322,7 +322,7 @@ class PreferencesController { /** * 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. * * @param {string} _url The rpc url to add to the frequentRpcList. diff --git a/old-ui/app/components/app-bar.js b/old-ui/app/components/app-bar.js index 684dfbe19..234c06a01 100644 --- a/old-ui/app/components/app-bar.js +++ b/old-ui/app/components/app-bar.js @@ -352,8 +352,9 @@ module.exports = class AppBar extends Component { renderCommonRpc (rpcList, provider) { const {dispatch} = this.props + const reversedRpcList = rpcList.slice().reverse() - return rpcList.map((rpc) => { + return reversedRpcList.map((rpc) => { const currentRpcTarget = provider.type === 'rpc' && rpc === provider.rpcTarget if ((rpc === LOCALHOST_RPC_URL) || currentRpcTarget) { diff --git a/ui/app/components/dropdowns/network-dropdown.js b/ui/app/components/dropdowns/network-dropdown.js index b1aeed376..63a30dd82 100644 --- a/ui/app/components/dropdowns/network-dropdown.js +++ b/ui/app/components/dropdowns/network-dropdown.js @@ -272,8 +272,9 @@ NetworkDropdown.prototype.getNetworkName = function () { NetworkDropdown.prototype.renderCommonRpc = function (rpcList, provider) { const props = this.props + const reversedRpcList = rpcList.slice().reverse() - return rpcList.map((rpc) => { + return reversedRpcList.map((rpc) => { const currentRpcTarget = provider.type === 'rpc' && rpc === provider.rpcTarget if ((rpc === 'http://localhost:8545') || currentRpcTarget) { @@ -302,7 +303,7 @@ NetworkDropdown.prototype.renderCommonRpc = function (rpcList, provider) { ] ) } - }).reverse() + }) } NetworkDropdown.prototype.renderCustomOption = function (provider) {