1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 04:20:53 +01:00

Added Confirmation Modal for Delete Network (#6776)

This commit is contained in:
Akshit Kr Nagpal 2019-07-02 17:43:02 +05:30 committed by Whymarrh Whitby
parent 9fd8a3d46e
commit 687984a938
10 changed files with 114 additions and 17 deletions

View File

@ -1208,6 +1208,12 @@
"resetAccountDescription": { "resetAccountDescription": {
"message": "Resetting your account will clear your transaction history." "message": "Resetting your account will clear your transaction history."
}, },
"deleteNetwork": {
"message": "Delete Network?"
},
"deleteNetworkDescription": {
"message": "Are you sure you want to delete this network?"
},
"restoreFromSeed": { "restoreFromSeed": {
"message": "Restore account?" "message": "Restore account?"
}, },

View File

@ -1522,6 +1522,15 @@ describe('MetaMask', function () {
const deleteButton = await findElement(driver, By.css('.btn-danger')) const deleteButton = await findElement(driver, By.css('.btn-danger'))
await deleteButton.click() await deleteButton.click()
await delay(regularDelayMs) await delay(regularDelayMs)
const confirmDeleteNetworkModal = await findElement(driver, By.css('span .modal'))
const byConfirmDeleteNetworkButton = By.css('.button.btn-danger.modal-container__footer-button')
const confirmDeleteNetworkButton = await driver.wait(until.elementLocated(byConfirmDeleteNetworkButton))
await confirmDeleteNetworkButton.click()
await driver.wait(until.stalenessOf(confirmDeleteNetworkModal))
const newNetworkListItems = await findElements(driver, By.css('.networks-tab__networks-list-name')) const newNetworkListItems = await findElements(driver, By.css('.networks-tab__networks-list-name'))
assert.equal(networkListItems.length - 1, newNetworkListItems.length) assert.equal(networkListItems.length - 1, newNetworkListItems.length)

View File

@ -0,0 +1,43 @@
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import Modal, { ModalContent } from '../../modal'
export default class ConfirmDeleteNetwork extends PureComponent {
static propTypes = {
hideModal: PropTypes.func.isRequired,
delRpcTarget: PropTypes.func.isRequired,
onConfirm: PropTypes.func.isRequired,
target: PropTypes.string.isRequired,
}
static contextTypes = {
t: PropTypes.func,
}
handleDelete = () => {
this.props.delRpcTarget(this.props.target)
.then(() => {
this.props.onConfirm()
this.props.hideModal()
})
}
render () {
const { t } = this.context
return (
<Modal
onSubmit={this.handleDelete}
onCancel={() => this.props.hideModal()}
submitText={t('delete')}
cancelText={t('cancel')}
submitType="danger"
>
<ModalContent
title={t('deleteNetwork')}
description={t('deleteNetworkDescription')}
/>
</Modal>
)
}
}

View File

@ -0,0 +1,16 @@
import { connect } from 'react-redux'
import { compose } from 'recompose'
import withModalProps from '../../../../helpers/higher-order-components/with-modal-props'
import ConfirmDeleteNetwork from './confirm-delete-network.component'
import { delRpcTarget } from '../../../../store/actions'
const mapDispatchToProps = dispatch => {
return {
delRpcTarget: (target) => dispatch(delRpcTarget(target)),
}
}
export default compose(
withModalProps,
connect(null, mapDispatchToProps)
)(ConfirmDeleteNetwork)

View File

@ -0,0 +1 @@
export { default } from './confirm-delete-network.container'

View File

@ -29,6 +29,7 @@ import MetaMetricsOptInModal from './metametrics-opt-in-modal'
import RejectTransactions from './reject-transactions' import RejectTransactions from './reject-transactions'
import ClearApprovedOrigins from './clear-approved-origins' import ClearApprovedOrigins from './clear-approved-origins'
import ConfirmCustomizeGasModal from '../gas-customization/gas-modal-page-container' import ConfirmCustomizeGasModal from '../gas-customization/gas-modal-page-container'
import ConfirmDeleteNetwork from './confirm-delete-network'
const modalContainerBaseStyle = { const modalContainerBaseStyle = {
transform: 'translate3d(-50%, 0, 0px)', transform: 'translate3d(-50%, 0, 0px)',
@ -301,6 +302,19 @@ const MODALS = {
}, },
}, },
CONFIRM_DELETE_NETWORK: {
contents: h(ConfirmDeleteNetwork),
mobileModalStyle: {
...modalContainerMobileStyle,
},
laptopModalStyle: {
...modalContainerLaptopStyle,
},
contentStyle: {
borderRadius: '8px',
},
},
NEW_ACCOUNT: { NEW_ACCOUNT: {
contents: [ contents: [
h(NewAccountModal, {}, []), h(NewAccountModal, {}, []),

View File

@ -12,7 +12,7 @@ export default class NetworkForm extends PureComponent {
static propTypes = { static propTypes = {
editRpc: PropTypes.func.isRequired, editRpc: PropTypes.func.isRequired,
delRpcTarget: PropTypes.func.isRequired, showConfirmDeleteNetworkModal: PropTypes.func.isRequired,
rpcUrl: PropTypes.string, rpcUrl: PropTypes.string,
chainId: PropTypes.string, chainId: PropTypes.string,
ticker: PropTypes.string, ticker: PropTypes.string,
@ -131,10 +131,14 @@ export default class NetworkForm extends PureComponent {
} }
onDelete = () => { onDelete = () => {
const { delRpcTarget, rpcUrl, onClear } = this.props const { showConfirmDeleteNetworkModal, rpcUrl, onClear } = this.props
delRpcTarget(rpcUrl) showConfirmDeleteNetworkModal({
target: rpcUrl,
onConfirm: () => {
this.resetForm() this.resetForm()
onClear() onClear()
},
})
} }
stateIsUnchanged () { stateIsUnchanged () {

View File

@ -25,7 +25,7 @@ export default class NetworksTab extends PureComponent {
setNetworksTabAddMode: PropTypes.func.isRequired, setNetworksTabAddMode: PropTypes.func.isRequired,
setRpcTarget: PropTypes.func.isRequired, setRpcTarget: PropTypes.func.isRequired,
setSelectedSettingsRpcUrl: PropTypes.func.isRequired, setSelectedSettingsRpcUrl: PropTypes.func.isRequired,
delRpcTarget: PropTypes.func.isRequired, showConfirmDeleteNetworkModal: PropTypes.func.isRequired,
providerUrl: PropTypes.string, providerUrl: PropTypes.string,
providerType: PropTypes.string, providerType: PropTypes.string,
networkDefaultedToProvider: PropTypes.bool, networkDefaultedToProvider: PropTypes.bool,
@ -160,7 +160,7 @@ export default class NetworksTab extends PureComponent {
const { t } = this.context const { t } = this.context
const { const {
setRpcTarget, setRpcTarget,
delRpcTarget, showConfirmDeleteNetworkModal,
setSelectedSettingsRpcUrl, setSelectedSettingsRpcUrl,
setNetworksTabAddMode, setNetworksTabAddMode,
selectedNetwork: { selectedNetwork: {
@ -199,7 +199,7 @@ export default class NetworksTab extends PureComponent {
setNetworksTabAddMode(false) setNetworksTabAddMode(false)
setSelectedSettingsRpcUrl(null) setSelectedSettingsRpcUrl(null)
}} }}
delRpcTarget={delRpcTarget} showConfirmDeleteNetworkModal={showConfirmDeleteNetworkModal}
viewOnly={viewOnly} viewOnly={viewOnly}
isCurrentRpcTarget={providerUrl === rpcUrl} isCurrentRpcTarget={providerUrl === rpcUrl}
networksTabIsInAddMode={networksTabIsInAddMode} networksTabIsInAddMode={networksTabIsInAddMode}

View File

@ -8,7 +8,7 @@ import {
displayWarning, displayWarning,
setNetworksTabAddMode, setNetworksTabAddMode,
editRpc, editRpc,
delRpcTarget, showModal,
} from '../../../store/actions' } from '../../../store/actions'
import { defaultNetworksData } from './networks-tab.constants' import { defaultNetworksData } from './networks-tab.constants'
const defaultNetworks = defaultNetworksData.map(network => ({ ...network, viewOnly: true })) const defaultNetworks = defaultNetworksData.map(network => ({ ...network, viewOnly: true }))
@ -64,8 +64,8 @@ const mapDispatchToProps = dispatch => {
setRpcTarget: (newRpc, chainId, ticker, nickname, rpcPrefs) => { setRpcTarget: (newRpc, chainId, ticker, nickname, rpcPrefs) => {
dispatch(updateAndSetCustomRpc(newRpc, chainId, ticker, nickname, rpcPrefs)) dispatch(updateAndSetCustomRpc(newRpc, chainId, ticker, nickname, rpcPrefs))
}, },
delRpcTarget: (target) => { showConfirmDeleteNetworkModal: ({ target, onConfirm }) => {
dispatch(delRpcTarget(target)) return dispatch(showModal({ name: 'CONFIRM_DELETE_NETWORK', target, onConfirm }))
}, },
displayWarning: warning => dispatch(displayWarning(warning)), displayWarning: warning => dispatch(displayWarning(warning)),
setNetworksTabAddMode: isInAddMode => dispatch(setNetworksTabAddMode(isInAddMode)), setNetworksTabAddMode: isInAddMode => dispatch(setNetworksTabAddMode(isInAddMode)),

View File

@ -2037,12 +2037,16 @@ function setRpcTarget (newRpc, chainId, ticker = 'ETH', nickname) {
function delRpcTarget (oldRpc) { function delRpcTarget (oldRpc) {
return (dispatch) => { return (dispatch) => {
log.debug(`background.delRpcTarget: ${oldRpc}`) log.debug(`background.delRpcTarget: ${oldRpc}`)
return new Promise((resolve, reject) => {
background.delCustomRpc(oldRpc, (err) => { background.delCustomRpc(oldRpc, (err) => {
if (err) { if (err) {
log.error(err) log.error(err)
return dispatch(self.displayWarning('Had a problem removing network!')) dispatch(self.displayWarning('Had a problem removing network!'))
return reject(err)
} }
dispatch(actions.setSelectedToken()) dispatch(actions.setSelectedToken())
resolve()
})
}) })
} }
} }