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

Add delete to custom rpc form #6650

Closed
wants to merge 4 commits into from
Closed
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/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@
"defaultNetwork": {
"message": "The default network for Ether transactions is Main Net."
},
"delete": {
"message": "Delete"
},
"denExplainer": {
"message": "Your DEN is your password-encrypted storage within MetaMask."
},
Expand Down
3 changes: 3 additions & 0 deletions app/_locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@
"defaultNetwork": {
"message": "預設乙太幣交易網路為主網路"
},
"delete": {
"message": "刪除"
},
"denExplainer": {
"message": "您的 DEN 是 MetaMask 中您的的密碼加密儲存庫。"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class PageContainerFooter extends Component {
children: PropTypes.node,
onCancel: PropTypes.func,
cancelText: PropTypes.string,
cancelButtonType: PropTypes.string,
onSubmit: PropTypes.func,
submitText: PropTypes.string,
disabled: PropTypes.bool,
Expand All @@ -29,14 +30,15 @@ export default class PageContainerFooter extends Component {
disabled,
submitButtonType,
hideCancel,
cancelButtonType,
} = this.props

return (
<div className="page-container__footer">

<header>
{!hideCancel && <Button
type="default"
type={cancelButtonType || 'default'}
large
className="page-container__footer-button"
onClick={e => onCancel(e)}
Expand Down
10 changes: 6 additions & 4 deletions ui/app/pages/settings/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
font-size: 20px;
border-bottom: 1px solid $alto;
margin-right: 24px;
height: 72px;
align-items: center;
display: flex;
flex-flow: row nowrap;

@media screen and (max-width: 575px) {
display: none;
Expand All @@ -52,9 +56,7 @@
font-family: Roboto;
font-style: normal;
font-weight: normal;
font-size: 24px;
line-height: 24px;
color: black;
font-size: 20px;

@media screen and (max-width: 575px) {
font-size: 16px;
Expand Down Expand Up @@ -123,7 +125,7 @@

&__body {
padding: 12px 24px;

@media screen and (min-width: 576px) {
padding: 12px;
}
Expand Down
30 changes: 25 additions & 5 deletions ui/app/pages/settings/networks-tab/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}

&__body {
padding: 12px 24px;
padding-right: 24px;
height: 100%;
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -118,12 +118,12 @@
}

&__add-network-header-button-wrapper {
padding-top: 15px;
padding-bottom: 21px;
justify-content: center;

.button {
width: 178px;
width: 138px;
padding: 10px;
line-height: 20px;
}

@media screen and (max-width: 575px) {
Expand Down Expand Up @@ -197,4 +197,24 @@
font-weight: bold;
color: #000000;
}
}
}

.network-form {
&__footer {
display: flex;
flex-flow: row nowrap;
margin: .75rem 0;

.btn-default {
margin-right: .375rem;
}

.btn-secondary {
margin-left: .375rem;
}

.btn-danger {
margin-right: 3.75rem;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import PropTypes from 'prop-types'
import validUrl from 'valid-url'
import PageContainerFooter from '../../../../components/ui/page-container/page-container-footer'
import TextField from '../../../../components/ui/text-field'
import Button from "../../../../components/ui/button";

export default class NetworksTab extends PureComponent {
export default class NetworkForm extends PureComponent {
static contextTypes = {
t: PropTypes.func.isRequired,
metricsEvent: PropTypes.func.isRequired,
}

static propTypes = {
editRpc: PropTypes.func.isRequired,
delRpcTarget: PropTypes.func.isRequired,
rpcUrl: PropTypes.string,
chainId: PropTypes.string,
ticker: PropTypes.string,
Expand All @@ -20,6 +22,7 @@ export default class NetworksTab extends PureComponent {
onClear: PropTypes.func.isRequired,
setRpcTarget: PropTypes.func.isRequired,
networksTabIsInAddMode: PropTypes.bool,
isCurrentRpcTarget: PropTypes.bool,
blockExplorerUrl: PropTypes.string,
rpcPrefs: PropTypes.object,
}
Expand Down Expand Up @@ -70,6 +73,71 @@ export default class NetworksTab extends PureComponent {
})
}

resetForm () {
const {
rpcUrl,
chainId,
ticker,
networkName,
blockExplorerUrl,
} = this.props

this.setState({ rpcUrl, chainId, ticker, networkName, blockExplorerUrl, errors: {} })
}

onSubmit = () => {
const {
setRpcTarget,
rpcUrl: propsRpcUrl,
editRpc,
rpcPrefs = {},
onClear,
networksTabIsInAddMode,
} = this.props
const {
networkName,
rpcUrl,
chainId,
ticker,
blockExplorerUrl,
} = this.state
if (propsRpcUrl && rpcUrl !== propsRpcUrl) {
editRpc(propsRpcUrl, rpcUrl, chainId, ticker, networkName, {
blockExplorerUrl: blockExplorerUrl || rpcPrefs.blockExplorerUrl,
...rpcPrefs,
})
} else {
setRpcTarget(rpcUrl, chainId, ticker, networkName, {
blockExplorerUrl: blockExplorerUrl || rpcPrefs.blockExplorerUrl,
...rpcPrefs,
})
}

if (networksTabIsInAddMode) {
onClear()
}
}

onCancel = () => {
const {
networksTabIsInAddMode,
onClear,
} = this.props

if (networksTabIsInAddMode) {
onClear()
} else {
this.resetForm()
}
}

onDelete = () => {
const { delRpcTarget, rpcUrl, onClear } = this.props
delRpcTarget(rpcUrl)
this.resetForm()
onClear()
}

stateIsUnchanged () {
const {
rpcUrl,
Expand Down Expand Up @@ -152,16 +220,29 @@ export default class NetworksTab extends PureComponent {
}

render () {
const { setRpcTarget, viewOnly, rpcUrl: propsRpcUrl, editRpc, rpcPrefs = {} } = this.props
const { t } = this.context
const {
setRpcTarget,
delRpcTarget,
viewOnly,
isCurrentRpcTarget,
rpcUrl: propsRpcUrl,
editRpc,
rpcPrefs = {},
onCancel,
networksTabIsInAddMode,
} = this.props
const {
networkName,
rpcUrl,
chainId,
chainId = '',
ticker,
blockExplorerUrl,
errors,
} = this.state

const isSubmitDisabled = viewOnly || this.stateIsUnchanged() || Object.values(errors).some(x => x) || !rpcUrl
const deletable = !networksTabIsInAddMode && !isCurrentRpcTarget && !viewOnly;

return (
<div className="networks-tab__network-form">
Expand Down Expand Up @@ -198,26 +279,32 @@ export default class NetworksTab extends PureComponent {
blockExplorerUrl,
'optionalBlockExplorerUrl',
)}
<PageContainerFooter
cancelText={this.context.t('cancel')}
hideCancel={true}
onSubmit={() => {
if (propsRpcUrl && rpcUrl !== propsRpcUrl) {
editRpc(propsRpcUrl, rpcUrl, chainId, ticker, networkName, {
blockExplorerUrl: blockExplorerUrl || rpcPrefs.blockExplorerUrl,
...rpcPrefs,
})
} else {
setRpcTarget(rpcUrl, chainId, ticker, networkName, {
blockExplorerUrl: blockExplorerUrl || rpcPrefs.blockExplorerUrl,
...rpcPrefs,
})
}
}}
submitText={this.context.t('save')}
submitButtonType={'confirm'}
disabled={viewOnly || this.stateIsUnchanged() || Object.values(errors).some(x => x) || !rpcUrl}
/>
<div className="network-form__footer">
{
deletable && (
<Button
type="danger"
onClick={this.onDelete}
>
{ t('delete') }
</Button>
)
}
<Button
type="default"
onClick={this.onCancel}
disabled={viewOnly || this.stateIsUnchanged()}
>
{ t('cancel') }
</Button>
<Button
type="secondary"
disabled={isSubmitDisabled}
onClick={this.onSubmit}
>
{ t('save') }
</Button>
</div>
</div>
)
}
Expand Down
Loading