From 0f386ee8815a208afbe5b85224c66083681961ae Mon Sep 17 00:00:00 2001 From: vbaranov Date: Mon, 6 Aug 2018 15:47:42 +0300 Subject: [PATCH 1/2] Remove custom RPC from the list of networks --- app/images/remove.svg | 3 +++ old-ui/app/app.js | 17 +++++++++++++++++ old-ui/app/components/delete-rpc.js | 6 ++++-- old-ui/app/css/index.css | 12 ++++++++++++ ui/app/actions.js | 11 +++++++---- ui/app/reducers/app.js | 1 + 6 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 app/images/remove.svg diff --git a/app/images/remove.svg b/app/images/remove.svg new file mode 100644 index 000000000000..038fb96a7616 --- /dev/null +++ b/app/images/remove.svg @@ -0,0 +1,3 @@ + + + diff --git a/old-ui/app/app.js b/old-ui/app/app.js index 54296c251a2f..cef5a8ab247a 100644 --- a/old-ui/app/app.js +++ b/old-ui/app/app.js @@ -266,6 +266,7 @@ App.prototype.renderNetworkDropdown = function () { position: 'absolute', left: '2px', top: '36px', + width: '270px', }, innerStyle: { padding: '2px 16px 2px 0px', @@ -706,6 +707,14 @@ App.prototype.renderCustomOption = function (provider) { }, [h('div.selected-network'), label, + h('.remove-rpc', { + onClick: (event) => { + event.preventDefault() + event.stopPropagation() + this.setState({ isNetworkMenuOpen: false }) + props.dispatch(actions.showDeleteRPC(label)) + } + }) ] ) } @@ -757,6 +766,14 @@ App.prototype.renderCommonRpc = function (rpcList, provider) { }, [ rpc, + h('.remove-rpc', { + onClick: (event) => { + event.preventDefault() + event.stopPropagation() + this.setState({ isNetworkMenuOpen: false }) + props.dispatch(actions.showDeleteRPC(rpc)) + } + }) ] ) } diff --git a/old-ui/app/components/delete-rpc.js b/old-ui/app/components/delete-rpc.js index 304c996e10af..6f5583bf3652 100644 --- a/old-ui/app/components/delete-rpc.js +++ b/old-ui/app/components/delete-rpc.js @@ -8,7 +8,9 @@ module.exports = connect(mapStateToProps)(DeleteRpc) function mapStateToProps (state) { return { - url: state.metamask.provider.rpcTarget, + metamask: state.metamask, + url: state.appState.RPC_URL ? state.appState.RPC_URL : state.metamask.provider.rpcTarget, + provider: state.metamask.provider } } @@ -51,7 +53,7 @@ DeleteRpc.prototype.render = function () { margin: '20px', }, onClick: () => { - this.props.dispatch(actions.removeCustomRPC(this.props.url)) + this.props.dispatch(actions.removeCustomRPC(this.props.url, this.props.provider)) .then(() => { this.props.dispatch(actions.showConfigPage()) }) diff --git a/old-ui/app/css/index.css b/old-ui/app/css/index.css index 214c2e9314f6..457c5f645b77 100644 --- a/old-ui/app/css/index.css +++ b/old-ui/app/css/index.css @@ -329,6 +329,18 @@ app sections background-position: right; } +.remove-rpc { + background-image: url('../images/remove.svg'); + background-size: 12px 12px; + background-repeat: no-repeat; + background-position: center; + width: 12px; + height: 12px; + position: absolute; + right: 0; +} + + @media (min--moz-device-pixel-ratio: 1.3), (-o-min-device-pixel-ratio: 2.6/2), (-webkit-min-device-pixel-ratio: 1.3), diff --git a/ui/app/actions.js b/ui/app/actions.js index acf70be563fd..74605a91b52e 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -2279,19 +2279,22 @@ function clearPendingTokens () { } } -function showDeleteRPC (transitionForward = true) { +function showDeleteRPC (RPC_URL, transitionForward = true) { return { type: actions.SHOW_DELETE_RPC, value: transitionForward, + RPC_URL, } } -function removeCustomRPC (url) { +function removeCustomRPC (url, provider) { return (dispatch) => { dispatch(actions.showLoadingIndication()) return new Promise((resolve, reject) => { - background.removeRpcUrl(url, (err, url) => { - dispatch(actions.setProviderType('poa')) + background.removeRpcUrl(url, (err, _url) => { + if ( provider.type === 'rpc' && url === provider.rpcTarget ) { + dispatch(actions.setProviderType('poa')) + } dispatch(actions.hideLoadingIndication()) if (err) { dispatch(actions.displayWarning(err.message)) diff --git a/ui/app/reducers/app.js b/ui/app/reducers/app.js index 2cd2210a73d8..2d2dcbb4a6ee 100644 --- a/ui/app/reducers/app.js +++ b/ui/app/reducers/app.js @@ -717,6 +717,7 @@ function reduceApp (state, action) { context: appState.currentView.context, }, transForward: action.value, + RPC_URL: action.RPC_URL, }) default: From 99e7d2d591740a9db7074b0b7c36676b3bba803e Mon Sep 17 00:00:00 2001 From: vbaranov Date: Mon, 6 Aug 2018 15:55:58 +0300 Subject: [PATCH 2/2] Linter fixes --- old-ui/app/app.js | 8 ++++---- old-ui/app/components/delete-rpc.js | 2 +- ui/app/actions.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/old-ui/app/app.js b/old-ui/app/app.js index cef5a8ab247a..00276694f7dc 100644 --- a/old-ui/app/app.js +++ b/old-ui/app/app.js @@ -713,8 +713,8 @@ App.prototype.renderCustomOption = function (provider) { event.stopPropagation() this.setState({ isNetworkMenuOpen: false }) props.dispatch(actions.showDeleteRPC(label)) - } - }) + }, + }), ] ) } @@ -772,8 +772,8 @@ App.prototype.renderCommonRpc = function (rpcList, provider) { event.stopPropagation() this.setState({ isNetworkMenuOpen: false }) props.dispatch(actions.showDeleteRPC(rpc)) - } - }) + }, + }), ] ) } diff --git a/old-ui/app/components/delete-rpc.js b/old-ui/app/components/delete-rpc.js index 6f5583bf3652..cefa1e16d23e 100644 --- a/old-ui/app/components/delete-rpc.js +++ b/old-ui/app/components/delete-rpc.js @@ -10,7 +10,7 @@ function mapStateToProps (state) { return { metamask: state.metamask, url: state.appState.RPC_URL ? state.appState.RPC_URL : state.metamask.provider.rpcTarget, - provider: state.metamask.provider + provider: state.metamask.provider, } } diff --git a/ui/app/actions.js b/ui/app/actions.js index 74605a91b52e..a8c1ab3205b7 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -2292,7 +2292,7 @@ function removeCustomRPC (url, provider) { dispatch(actions.showLoadingIndication()) return new Promise((resolve, reject) => { background.removeRpcUrl(url, (err, _url) => { - if ( provider.type === 'rpc' && url === provider.rpcTarget ) { + if (provider.type === 'rpc' && url === provider.rpcTarget) { dispatch(actions.setProviderType('poa')) } dispatch(actions.hideLoadingIndication())