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

(Feature) Remove custom RPC from the list of networks #66

Merged
merged 2 commits into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/images/remove.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions old-ui/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ App.prototype.renderNetworkDropdown = function () {
position: 'absolute',
left: '2px',
top: '36px',
width: '270px',
},
innerStyle: {
padding: '2px 16px 2px 0px',
Expand Down Expand Up @@ -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))
},
}),
]
)
}
Expand Down Expand Up @@ -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))
},
}),
]
)
}
Expand Down
6 changes: 4 additions & 2 deletions old-ui/app/components/delete-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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())
})
Expand Down
12 changes: 12 additions & 0 deletions old-ui/app/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 7 additions & 4 deletions ui/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions ui/app/reducers/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ function reduceApp (state, action) {
context: appState.currentView.context,
},
transForward: action.value,
RPC_URL: action.RPC_URL,
})

default:
Expand Down