diff --git a/common/components/Header/components/CustomNodeModal.tsx b/common/components/Header/components/CustomNodeModal.tsx index d4b63800..fae273eb 100644 --- a/common/components/Header/components/CustomNodeModal.tsx +++ b/common/components/Header/components/CustomNodeModal.tsx @@ -35,7 +35,7 @@ export default class CustomNodeModal extends React.Component { network: NETWORK_KEYS[0], hasAuth: false, username: '', - password: '', + password: '' }; public render() { @@ -43,15 +43,18 @@ export default class CustomNodeModal extends React.Component { const isHttps = window.location.protocol.includes('https'); const invalids = this.getInvalids(); - const buttons: IButton[] = [{ - type: 'primary', - text: translate('NODE_CTA'), - onClick: this.saveAndAdd, - disabled: !!Object.keys(invalids).length, - }, { - text: translate('x_Cancel'), - onClick: handleClose - }]; + const buttons: IButton[] = [ + { + type: 'primary', + text: translate('NODE_CTA'), + onClick: this.saveAndAdd, + disabled: !!Object.keys(invalids).length + }, + { + text: translate('x_Cancel'), + onClick: handleClose + } + ]; return ( { handleClose={handleClose} >
- {isHttps && + {isHttps && (
{translate('NODE_Warning')}
- } + )}
- {this.renderInput({ - name: 'name', - placeholder: 'My Node', - }, invalids)} + {this.renderInput( + { + name: 'name', + placeholder: 'My Node' + }, + invalids + )}
@@ -84,9 +90,11 @@ export default class CustomNodeModal extends React.Component { value={this.state.network} onChange={this.handleChange} > - {NETWORK_KEYS.map((net) => - - )} + {NETWORK_KEYS.map(net => ( + + ))}
@@ -94,19 +102,25 @@ export default class CustomNodeModal extends React.Component {
- {this.renderInput({ - name: 'url', - placeholder: 'http://127.0.0.1/', - }, invalids)} + {this.renderInput( + { + name: 'url', + placeholder: 'http://127.0.0.1/' + }, + invalids + )}
- {this.renderInput({ - name: 'port', - placeholder: '8545', - type: 'number', - }, invalids)} + {this.renderInput( + { + name: 'port', + placeholder: '8545', + type: 'number' + }, + invalids + )}
@@ -117,13 +131,12 @@ export default class CustomNodeModal extends React.Component { name="hasAuth" checked={this.state.hasAuth} onChange={this.handleCheckbox} - /> - {' '} + />{' '} HTTP Basic Authentication
- {this.state.hasAuth && + {this.state.hasAuth && (
@@ -131,13 +144,16 @@ export default class CustomNodeModal extends React.Component {
- {this.renderInput({ - name: 'password', - type: 'password', - }, invalids)} + {this.renderInput( + { + name: 'password', + type: 'password' + }, + invalids + )}
- } + )}
@@ -145,30 +161,26 @@ export default class CustomNodeModal extends React.Component { } private renderInput(input: Input, invalids: { [key: string]: boolean }) { - return ; + return ( + + ); } private getInvalids(): { [key: string]: boolean } { - const { - url, - port, - hasAuth, - username, - password, - } = this.state; - const required = ["name", "url", "port", "network"]; + const { url, port, hasAuth, username, password } = this.state; + const required = ['name', 'url', 'port', 'network']; const invalids: { [key: string]: boolean } = {}; // Required fields - required.forEach((field) => { + required.forEach(field => { if (!this.state[field]) { invalids[field] = true; } @@ -198,9 +210,9 @@ export default class CustomNodeModal extends React.Component { return invalids; } - private handleChange = (ev: React.FormEvent< - HTMLInputElement | HTMLSelectElement - >) => { + private handleChange = ( + ev: React.FormEvent + ) => { const { name, value } = ev.currentTarget; this.setState({ [name as any]: value }); }; @@ -215,13 +227,13 @@ export default class CustomNodeModal extends React.Component { name: this.state.name.trim(), url: this.state.url.trim(), port: parseInt(this.state.port, 10), - network: this.state.network, + network: this.state.network }; if (this.state.hasAuth) { node.auth = { username: this.state.username, - password: this.state.password, + password: this.state.password }; } diff --git a/common/components/WalletDecrypt/ViewOnly.tsx b/common/components/WalletDecrypt/ViewOnly.tsx index d19dfa0a..aa0cefe5 100644 --- a/common/components/WalletDecrypt/ViewOnly.tsx +++ b/common/components/WalletDecrypt/ViewOnly.tsx @@ -1,29 +1,60 @@ import React, { Component } from 'react'; import translate from 'translations'; +import { donationAddressMap } from 'config/data'; +import { isValidETHAddress } from 'libs/validators'; +import { AddressOnlyWallet } from 'libs/wallet'; + +interface Props { + onUnlock(param: any): void; +} + +interface State { + address: string; +} + +export default class ViewOnlyDecrypt extends Component { + public state = { + address: '' + }; -export default class ViewOnlyDecrypt extends Component { public render() { + const { address } = this.state; + const isValid = isValidETHAddress(address); + return (
-

- {translate('ADD_Radio_2_alt')} -

+

{translate('MYWAL_Address')}

- + +
); } + + private changeAddress = (ev: React.FormEvent) => { + this.setState({ address: ev.currentTarget.value }); + }; + + private openWallet = (ev: React.SyntheticEvent) => { + const { address } = this.state; + ev.preventDefault(); + if (isValidETHAddress(address)) { + const wallet = new AddressOnlyWallet(address); + this.props.onUnlock(wallet); + } + }; } diff --git a/common/components/WalletDecrypt/index.tsx b/common/components/WalletDecrypt/index.tsx index fbb77890..9531010b 100644 --- a/common/components/WalletDecrypt/index.tsx +++ b/common/components/WalletDecrypt/index.tsx @@ -30,7 +30,6 @@ const WALLETS = { component: Web3Decrypt, initialParams: {}, unlock: unlockWeb3, - disabled: false, helpLink: 'https://myetherwallet.github.io/knowledge-base/migration/moving-from-private-key-to-metamask.html' }, @@ -39,7 +38,6 @@ const WALLETS = { component: LedgerNanoSDecrypt, initialParams: {}, unlock: setWallet, - disabled: false, helpLink: 'https://ledger.zendesk.com/hc/en-us/articles/115005200009-How-to-use-MyEtherWallet-with-Ledger' }, @@ -48,7 +46,6 @@ const WALLETS = { component: TrezorDecrypt, initialParams: {}, unlock: setWallet, - disabled: false, helpLink: 'https://doc.satoshilabs.com/trezor-apps/mew.html' }, 'keystore-file': { @@ -59,7 +56,6 @@ const WALLETS = { password: '' }, unlock: unlockKeystore, - disabled: false, helpLink: 'https://myetherwallet.github.io/knowledge-base/private-keys-passwords/difference-beween-private-key-and-keystore-file.html' }, @@ -68,7 +64,6 @@ const WALLETS = { component: MnemonicDecrypt, initialParams: {}, unlock: unlockMnemonic, - disabled: false, helpLink: 'https://myetherwallet.github.io/knowledge-base/private-keys-passwords/difference-beween-private-key-and-keystore-file.html' }, @@ -80,14 +75,14 @@ const WALLETS = { password: '' }, unlock: unlockPrivateKey, - disabled: false, helpLink: 'https://myetherwallet.github.io/knowledge-base/private-keys-passwords/difference-beween-private-key-and-keystore-file.html' }, 'view-only': { lid: 'View with Address Only', component: ViewOnlyDecrypt, - disabled: true, + initialParams: {}, + unlock: setWallet, helpLink: '' } }; @@ -100,6 +95,7 @@ interface Props { UnlockKeystoreAction | UnlockMnemonicAction | UnlockPrivateKeyAction >; offline: boolean; + allowReadOnly?: boolean; } interface State { @@ -139,8 +135,12 @@ export class WalletDecrypt extends Component { public buildWalletOptions() { return map(WALLETS, (wallet, key) => { - const isSelected = this.state.selectedWalletKey === key; const { helpLink } = wallet; + const isSelected = this.state.selectedWalletKey === key; + const isDisabled = + this.isOnlineRequiredWalletAndOffline(key) || + (!this.props.allowReadOnly && wallet.component === ViewOnlyDecrypt); + return (