2018-01-01 19:46:28 +00:00
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
2018-01-24 22:23:20 +00:00
|
|
|
|
import { Link } from 'react-router-dom';
|
2018-01-01 19:46:28 +00:00
|
|
|
|
import isEmpty from 'lodash/isEmpty';
|
|
|
|
|
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
|
|
|
|
import {
|
|
|
|
|
setWallet,
|
|
|
|
|
TSetWallet,
|
|
|
|
|
unlockKeystore,
|
|
|
|
|
TUnlockKeystore,
|
|
|
|
|
unlockMnemonic,
|
|
|
|
|
TUnlockMnemonic,
|
|
|
|
|
unlockPrivateKey,
|
|
|
|
|
TUnlockPrivateKey,
|
|
|
|
|
unlockWeb3,
|
|
|
|
|
TUnlockWeb3,
|
|
|
|
|
resetWallet,
|
|
|
|
|
TResetWallet
|
|
|
|
|
} from 'actions/wallet';
|
2018-03-02 21:57:17 +00:00
|
|
|
|
import { reset, TReset, ResetAction } from 'actions/transaction';
|
2018-01-01 19:46:28 +00:00
|
|
|
|
import translate from 'translations';
|
|
|
|
|
import {
|
|
|
|
|
KeystoreDecrypt,
|
|
|
|
|
LedgerNanoSDecrypt,
|
|
|
|
|
MnemonicDecrypt,
|
|
|
|
|
PrivateKeyDecrypt,
|
|
|
|
|
PrivateKeyValue,
|
|
|
|
|
TrezorDecrypt,
|
|
|
|
|
ViewOnlyDecrypt,
|
|
|
|
|
Web3Decrypt,
|
2018-01-24 22:23:20 +00:00
|
|
|
|
WalletButton,
|
|
|
|
|
InsecureWalletWarning
|
2018-01-01 19:46:28 +00:00
|
|
|
|
} from './components';
|
|
|
|
|
import { AppState } from 'reducers';
|
2018-01-11 06:44:13 +00:00
|
|
|
|
import { showNotification, TShowNotification } from 'actions/notifications';
|
2018-01-26 20:08:39 +00:00
|
|
|
|
import { getDisabledWallets } from 'selectors/wallet';
|
|
|
|
|
import { DisabledWallets } from './disables';
|
2018-01-20 20:06:28 +00:00
|
|
|
|
import {
|
|
|
|
|
SecureWalletName,
|
|
|
|
|
InsecureWalletName,
|
|
|
|
|
MiscWalletName,
|
|
|
|
|
WalletName,
|
2018-02-07 04:28:28 +00:00
|
|
|
|
knowledgeBaseURL,
|
|
|
|
|
donationAddressMap
|
2018-01-20 20:06:28 +00:00
|
|
|
|
} from 'config';
|
2018-02-12 20:43:07 +00:00
|
|
|
|
import { isWeb3NodeAvailable } from 'libs/nodes/web3';
|
2018-02-18 00:25:01 +00:00
|
|
|
|
import CipherIcon from 'assets/images/wallets/cipher.svg';
|
2018-02-07 04:28:28 +00:00
|
|
|
|
import LedgerIcon from 'assets/images/wallets/ledger.svg';
|
|
|
|
|
import MetamaskIcon from 'assets/images/wallets/metamask.svg';
|
|
|
|
|
import MistIcon from 'assets/images/wallets/mist.svg';
|
|
|
|
|
import TrezorIcon from 'assets/images/wallets/trezor.svg';
|
|
|
|
|
import './WalletDecrypt.scss';
|
|
|
|
|
|
2018-01-20 20:06:28 +00:00
|
|
|
|
interface OwnProps {
|
|
|
|
|
hidden?: boolean;
|
2018-01-26 20:08:39 +00:00
|
|
|
|
disabledWallets?: DisabledWallets;
|
2018-01-24 22:23:20 +00:00
|
|
|
|
showGenerateLink?: boolean;
|
2018-03-02 21:57:17 +00:00
|
|
|
|
resetIncludeExcludeProperties?: ResetAction['payload'];
|
2018-01-20 20:06:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface DispatchProps {
|
2018-01-01 19:46:28 +00:00
|
|
|
|
unlockKeystore: TUnlockKeystore;
|
|
|
|
|
unlockMnemonic: TUnlockMnemonic;
|
|
|
|
|
unlockPrivateKey: TUnlockPrivateKey;
|
|
|
|
|
unlockWeb3: TUnlockWeb3;
|
2018-01-20 20:06:28 +00:00
|
|
|
|
setWallet: TSetWallet;
|
2018-01-01 19:46:28 +00:00
|
|
|
|
resetWallet: TResetWallet;
|
2018-01-20 20:06:28 +00:00
|
|
|
|
resetTransactionState: TReset;
|
2018-01-11 06:44:13 +00:00
|
|
|
|
showNotification: TShowNotification;
|
2018-01-20 20:06:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface StateProps {
|
2018-01-26 20:08:39 +00:00
|
|
|
|
computedDisabledWallets: DisabledWallets;
|
2018-01-11 06:44:13 +00:00
|
|
|
|
isWalletPending: AppState['wallet']['isWalletPending'];
|
|
|
|
|
isPasswordPending: AppState['wallet']['isPasswordPending'];
|
2018-01-01 19:46:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-20 20:06:28 +00:00
|
|
|
|
type Props = OwnProps & StateProps & DispatchProps;
|
|
|
|
|
|
2018-01-11 18:04:11 +00:00
|
|
|
|
type UnlockParams = {} | PrivateKeyValue;
|
2018-01-01 19:46:28 +00:00
|
|
|
|
interface State {
|
2018-01-20 20:06:28 +00:00
|
|
|
|
selectedWalletKey: WalletName | null;
|
2018-01-01 19:46:28 +00:00
|
|
|
|
value: UnlockParams | null;
|
2018-01-24 22:23:20 +00:00
|
|
|
|
hasAcknowledgedInsecure: boolean;
|
2018-01-01 19:46:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface BaseWalletInfo {
|
|
|
|
|
lid: string;
|
|
|
|
|
component: any;
|
|
|
|
|
initialParams: object;
|
|
|
|
|
unlock: any;
|
2018-01-20 20:06:28 +00:00
|
|
|
|
helpLink: string;
|
2018-01-01 19:46:28 +00:00
|
|
|
|
isReadOnly?: boolean;
|
|
|
|
|
attemptUnlock?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface SecureWalletInfo extends BaseWalletInfo {
|
2018-01-20 20:06:28 +00:00
|
|
|
|
icon?: string;
|
2018-01-01 19:46:28 +00:00
|
|
|
|
description: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface InsecureWalletInfo extends BaseWalletInfo {
|
|
|
|
|
example: string;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-20 20:06:28 +00:00
|
|
|
|
// tslint:disable-next-line:no-empty-interface
|
|
|
|
|
interface MiscWalletInfo extends InsecureWalletInfo {}
|
|
|
|
|
|
2018-01-01 19:46:28 +00:00
|
|
|
|
const WEB3_TYPES = {
|
2018-02-18 00:25:01 +00:00
|
|
|
|
CipherProvider: {
|
|
|
|
|
lid: 'x_Cipher',
|
|
|
|
|
icon: CipherIcon
|
|
|
|
|
},
|
2018-01-01 19:46:28 +00:00
|
|
|
|
MetamaskInpageProvider: {
|
|
|
|
|
lid: 'x_MetaMask',
|
|
|
|
|
icon: MetamaskIcon
|
|
|
|
|
},
|
|
|
|
|
EthereumProvider: {
|
|
|
|
|
lid: 'x_Mist',
|
|
|
|
|
icon: MistIcon
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-01-20 20:06:28 +00:00
|
|
|
|
|
|
|
|
|
type SecureWallets = { [key in SecureWalletName]: SecureWalletInfo };
|
|
|
|
|
type InsecureWallets = { [key in InsecureWalletName]: InsecureWalletInfo };
|
|
|
|
|
type MiscWallet = { [key in MiscWalletName]: MiscWalletInfo };
|
|
|
|
|
type Wallets = SecureWallets & InsecureWallets & MiscWallet;
|
|
|
|
|
|
2018-01-01 19:46:28 +00:00
|
|
|
|
const WEB3_TYPE: string | false =
|
|
|
|
|
(window as any).web3 && (window as any).web3.currentProvider.constructor.name;
|
|
|
|
|
|
2018-01-24 22:23:20 +00:00
|
|
|
|
const SECURE_WALLETS = Object.values(SecureWalletName);
|
|
|
|
|
const INSECURE_WALLETS = Object.values(InsecureWalletName);
|
|
|
|
|
const MISC_WALLETS = Object.values(MiscWalletName);
|
|
|
|
|
|
2018-01-01 19:46:28 +00:00
|
|
|
|
export class WalletDecrypt extends Component<Props, State> {
|
2018-01-20 20:06:28 +00:00
|
|
|
|
// https://github.com/Microsoft/TypeScript/issues/13042
|
|
|
|
|
// index signature should become [key: Wallets] (from config) once typescript bug is fixed
|
|
|
|
|
public WALLETS: Wallets = {
|
|
|
|
|
[SecureWalletName.WEB3]: {
|
2018-02-18 00:48:31 +00:00
|
|
|
|
lid: WEB3_TYPE && WEB3_TYPES[WEB3_TYPE] ? WEB3_TYPES[WEB3_TYPE].lid : 'x_Web3',
|
|
|
|
|
icon: WEB3_TYPE && WEB3_TYPES[WEB3_TYPE] && WEB3_TYPES[WEB3_TYPE].icon,
|
2018-01-01 19:46:28 +00:00
|
|
|
|
description: 'ADD_Web3Desc',
|
|
|
|
|
component: Web3Decrypt,
|
|
|
|
|
initialParams: {},
|
|
|
|
|
unlock: this.props.unlockWeb3,
|
|
|
|
|
attemptUnlock: true,
|
|
|
|
|
helpLink: `${knowledgeBaseURL}/migration/moving-from-private-key-to-metamask`
|
|
|
|
|
},
|
2018-01-20 20:06:28 +00:00
|
|
|
|
[SecureWalletName.LEDGER_NANO_S]: {
|
2018-01-01 19:46:28 +00:00
|
|
|
|
lid: 'x_Ledger',
|
|
|
|
|
icon: LedgerIcon,
|
|
|
|
|
description: 'ADD_HardwareDesc',
|
|
|
|
|
component: LedgerNanoSDecrypt,
|
|
|
|
|
initialParams: {},
|
|
|
|
|
unlock: this.props.setWallet,
|
2018-02-10 19:24:05 +00:00
|
|
|
|
helpLink: 'https://support.ledgerwallet.com/hc/en-us/articles/115005200009'
|
2018-01-01 19:46:28 +00:00
|
|
|
|
},
|
2018-01-20 20:06:28 +00:00
|
|
|
|
[SecureWalletName.TREZOR]: {
|
2018-01-01 19:46:28 +00:00
|
|
|
|
lid: 'x_Trezor',
|
|
|
|
|
icon: TrezorIcon,
|
|
|
|
|
description: 'ADD_HardwareDesc',
|
|
|
|
|
component: TrezorDecrypt,
|
|
|
|
|
initialParams: {},
|
|
|
|
|
unlock: this.props.setWallet,
|
|
|
|
|
helpLink: 'https://doc.satoshilabs.com/trezor-apps/mew.html'
|
|
|
|
|
},
|
2018-01-20 20:06:28 +00:00
|
|
|
|
[InsecureWalletName.KEYSTORE_FILE]: {
|
2018-01-01 19:46:28 +00:00
|
|
|
|
lid: 'x_Keystore2',
|
|
|
|
|
example: 'UTC--2017-12-15T17-35-22.547Z--6be6e49e82425a5aa56396db03512f2cc10e95e8',
|
|
|
|
|
component: KeystoreDecrypt,
|
|
|
|
|
initialParams: {
|
|
|
|
|
file: '',
|
|
|
|
|
password: ''
|
|
|
|
|
},
|
|
|
|
|
unlock: this.props.unlockKeystore,
|
|
|
|
|
helpLink: `${knowledgeBaseURL}/private-keys-passwords/difference-beween-private-key-and-keystore-file.html`
|
|
|
|
|
},
|
2018-01-20 20:06:28 +00:00
|
|
|
|
[InsecureWalletName.MNEMONIC_PHRASE]: {
|
2018-01-01 19:46:28 +00:00
|
|
|
|
lid: 'x_Mnemonic',
|
|
|
|
|
example: 'brain surround have swap horror cheese file distinct',
|
|
|
|
|
component: MnemonicDecrypt,
|
|
|
|
|
initialParams: {},
|
|
|
|
|
unlock: this.props.unlockMnemonic,
|
|
|
|
|
helpLink: `${knowledgeBaseURL}/private-keys-passwords/difference-beween-private-key-and-keystore-file.html`
|
|
|
|
|
},
|
2018-01-20 20:06:28 +00:00
|
|
|
|
[InsecureWalletName.PRIVATE_KEY]: {
|
2018-01-01 19:46:28 +00:00
|
|
|
|
lid: 'x_PrivKey2',
|
|
|
|
|
example: 'f1d0e0789c6d40f399ca90cc674b7858de4c719e0d5752a60d5d2f6baa45d4c9',
|
|
|
|
|
component: PrivateKeyDecrypt,
|
|
|
|
|
initialParams: {
|
|
|
|
|
key: '',
|
|
|
|
|
password: ''
|
|
|
|
|
},
|
|
|
|
|
unlock: this.props.unlockPrivateKey,
|
|
|
|
|
helpLink: `${knowledgeBaseURL}/private-keys-passwords/difference-beween-private-key-and-keystore-file.html`
|
|
|
|
|
},
|
2018-01-20 20:06:28 +00:00
|
|
|
|
[MiscWalletName.VIEW_ONLY]: {
|
2018-01-01 19:46:28 +00:00
|
|
|
|
lid: 'View Address',
|
2018-02-07 04:28:28 +00:00
|
|
|
|
example: donationAddressMap.ETH,
|
2018-01-01 19:46:28 +00:00
|
|
|
|
component: ViewOnlyDecrypt,
|
|
|
|
|
initialParams: {},
|
|
|
|
|
unlock: this.props.setWallet,
|
|
|
|
|
helpLink: '',
|
|
|
|
|
isReadOnly: true
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-01-20 20:06:28 +00:00
|
|
|
|
|
2018-01-01 19:46:28 +00:00
|
|
|
|
public state: State = {
|
|
|
|
|
selectedWalletKey: null,
|
2018-01-24 22:23:20 +00:00
|
|
|
|
value: null,
|
|
|
|
|
hasAcknowledgedInsecure: false
|
2018-01-01 19:46:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
2018-01-20 20:06:28 +00:00
|
|
|
|
public componentWillReceiveProps(nextProps: Props) {
|
2018-01-01 19:46:28 +00:00
|
|
|
|
// Reset state when unlock is hidden / revealed
|
|
|
|
|
if (nextProps.hidden !== this.props.hidden) {
|
|
|
|
|
this.setState({
|
|
|
|
|
value: null,
|
|
|
|
|
selectedWalletKey: null
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getSelectedWallet() {
|
|
|
|
|
const { selectedWalletKey } = this.state;
|
|
|
|
|
if (!selectedWalletKey) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.WALLETS[selectedWalletKey];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getDecryptionComponent() {
|
2018-01-24 22:23:20 +00:00
|
|
|
|
const { selectedWalletKey, hasAcknowledgedInsecure } = this.state;
|
2018-01-01 19:46:28 +00:00
|
|
|
|
const selectedWallet = this.getSelectedWallet();
|
2018-01-24 22:23:20 +00:00
|
|
|
|
if (!selectedWalletKey || !selectedWallet) {
|
2018-01-01 19:46:28 +00:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-24 22:23:20 +00:00
|
|
|
|
if (INSECURE_WALLETS.includes(selectedWalletKey) && !hasAcknowledgedInsecure) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="WalletDecrypt-decrypt">
|
|
|
|
|
<InsecureWalletWarning
|
|
|
|
|
walletType={translate(selectedWallet.lid)}
|
|
|
|
|
onContinue={this.handleAcknowledgeInsecure}
|
|
|
|
|
onCancel={this.clearWalletChoice}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-01 19:46:28 +00:00
|
|
|
|
return (
|
2018-01-24 22:23:20 +00:00
|
|
|
|
<div className="WalletDecrypt-decrypt">
|
|
|
|
|
<button className="WalletDecrypt-decrypt-back" onClick={this.clearWalletChoice}>
|
|
|
|
|
<i className="fa fa-arrow-left" /> {translate('Change Wallet')}
|
|
|
|
|
</button>
|
|
|
|
|
<h2 className="WalletDecrypt-decrypt-title">
|
|
|
|
|
{!selectedWallet.isReadOnly && 'Unlock your'} {translate(selectedWallet.lid)}
|
|
|
|
|
</h2>
|
|
|
|
|
<section className="WalletDecrypt-decrypt-form">
|
|
|
|
|
<selectedWallet.component
|
|
|
|
|
value={this.state.value}
|
|
|
|
|
onChange={this.onChange}
|
|
|
|
|
onUnlock={this.onUnlock}
|
|
|
|
|
showNotification={this.props.showNotification}
|
|
|
|
|
isWalletPending={
|
|
|
|
|
this.state.selectedWalletKey === InsecureWalletName.KEYSTORE_FILE
|
|
|
|
|
? this.props.isWalletPending
|
|
|
|
|
: undefined
|
|
|
|
|
}
|
|
|
|
|
isPasswordPending={
|
|
|
|
|
this.state.selectedWalletKey === InsecureWalletName.KEYSTORE_FILE
|
|
|
|
|
? this.props.isPasswordPending
|
|
|
|
|
: undefined
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
2018-01-01 19:46:28 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-24 22:23:20 +00:00
|
|
|
|
public handleAcknowledgeInsecure = () => {
|
|
|
|
|
this.setState({ hasAcknowledgedInsecure: true });
|
|
|
|
|
};
|
2018-01-01 19:46:28 +00:00
|
|
|
|
|
2018-01-24 22:23:20 +00:00
|
|
|
|
public buildWalletOptions() {
|
2018-01-26 20:08:39 +00:00
|
|
|
|
const { computedDisabledWallets } = this.props;
|
|
|
|
|
const { reasons } = computedDisabledWallets;
|
|
|
|
|
|
2018-01-01 19:46:28 +00:00
|
|
|
|
return (
|
|
|
|
|
<div className="WalletDecrypt-wallets">
|
|
|
|
|
<h2 className="WalletDecrypt-wallets-title">{translate('decrypt_Access')}</h2>
|
|
|
|
|
|
|
|
|
|
<div className="WalletDecrypt-wallets-row">
|
2018-01-20 20:06:28 +00:00
|
|
|
|
{SECURE_WALLETS.map((walletType: SecureWalletName) => {
|
|
|
|
|
const wallet = this.WALLETS[walletType];
|
2018-01-01 19:46:28 +00:00
|
|
|
|
return (
|
|
|
|
|
<WalletButton
|
2018-01-20 20:06:28 +00:00
|
|
|
|
key={walletType}
|
2018-01-01 19:46:28 +00:00
|
|
|
|
name={translate(wallet.lid)}
|
|
|
|
|
description={translate(wallet.description)}
|
|
|
|
|
icon={wallet.icon}
|
|
|
|
|
helpLink={wallet.helpLink}
|
2018-01-20 20:06:28 +00:00
|
|
|
|
walletType={walletType}
|
2018-01-01 19:46:28 +00:00
|
|
|
|
isSecure={true}
|
2018-01-20 20:06:28 +00:00
|
|
|
|
isDisabled={this.isWalletDisabled(walletType)}
|
2018-01-26 20:08:39 +00:00
|
|
|
|
disableReason={reasons[walletType]}
|
2018-01-01 19:46:28 +00:00
|
|
|
|
onClick={this.handleWalletChoice}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="WalletDecrypt-wallets-row">
|
2018-01-20 20:06:28 +00:00
|
|
|
|
{INSECURE_WALLETS.map((walletType: InsecureWalletName) => {
|
|
|
|
|
const wallet = this.WALLETS[walletType];
|
2018-01-01 19:46:28 +00:00
|
|
|
|
return (
|
|
|
|
|
<WalletButton
|
2018-01-20 20:06:28 +00:00
|
|
|
|
key={walletType}
|
2018-01-01 19:46:28 +00:00
|
|
|
|
name={translate(wallet.lid)}
|
|
|
|
|
example={wallet.example}
|
|
|
|
|
helpLink={wallet.helpLink}
|
2018-01-20 20:06:28 +00:00
|
|
|
|
walletType={walletType}
|
2018-01-01 19:46:28 +00:00
|
|
|
|
isSecure={false}
|
2018-01-20 20:06:28 +00:00
|
|
|
|
isDisabled={this.isWalletDisabled(walletType)}
|
2018-01-26 20:08:39 +00:00
|
|
|
|
disableReason={reasons[walletType]}
|
2018-01-01 19:46:28 +00:00
|
|
|
|
onClick={this.handleWalletChoice}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
|
2018-01-20 20:06:28 +00:00
|
|
|
|
{MISC_WALLETS.map((walletType: MiscWalletName) => {
|
|
|
|
|
const wallet = this.WALLETS[walletType];
|
|
|
|
|
return (
|
|
|
|
|
<WalletButton
|
|
|
|
|
key={walletType}
|
|
|
|
|
name={translate(wallet.lid)}
|
|
|
|
|
example={wallet.example}
|
|
|
|
|
helpLink={wallet.helpLink}
|
|
|
|
|
walletType={walletType}
|
|
|
|
|
isReadOnly={true}
|
|
|
|
|
isDisabled={this.isWalletDisabled(walletType)}
|
2018-01-26 20:08:39 +00:00
|
|
|
|
disableReason={reasons[walletType]}
|
2018-01-20 20:06:28 +00:00
|
|
|
|
onClick={this.handleWalletChoice}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2018-01-01 19:46:28 +00:00
|
|
|
|
</div>
|
2018-01-24 22:23:20 +00:00
|
|
|
|
|
|
|
|
|
{this.props.showGenerateLink && (
|
|
|
|
|
<div className="WalletDecrypt-wallets-generate">
|
|
|
|
|
Don’t have a wallet? <Link to="/generate">Click here to get one</Link>.
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2018-01-01 19:46:28 +00:00
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-20 20:06:28 +00:00
|
|
|
|
public handleWalletChoice = async (walletType: WalletName) => {
|
2018-01-01 19:46:28 +00:00
|
|
|
|
const wallet = this.WALLETS[walletType];
|
2018-01-20 20:06:28 +00:00
|
|
|
|
|
2018-01-01 19:46:28 +00:00
|
|
|
|
if (!wallet) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let timeout = 0;
|
2018-01-08 01:21:11 +00:00
|
|
|
|
const web3Available = await isWeb3NodeAvailable();
|
|
|
|
|
if (wallet.attemptUnlock && web3Available) {
|
|
|
|
|
// timeout is only the maximum wait time before secondary view is shown
|
|
|
|
|
// send view will be shown immediately on web3 resolve
|
|
|
|
|
timeout = 1000;
|
2018-01-01 19:46:28 +00:00
|
|
|
|
wallet.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-20 20:06:28 +00:00
|
|
|
|
window.setTimeout(() => {
|
2018-01-01 19:46:28 +00:00
|
|
|
|
this.setState({
|
|
|
|
|
selectedWalletKey: walletType,
|
2018-01-24 22:23:20 +00:00
|
|
|
|
value: wallet.initialParams,
|
|
|
|
|
hasAcknowledgedInsecure: false
|
2018-01-01 19:46:28 +00:00
|
|
|
|
});
|
|
|
|
|
}, timeout);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public clearWalletChoice = () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
selectedWalletKey: null,
|
2018-01-24 22:23:20 +00:00
|
|
|
|
value: null,
|
|
|
|
|
hasAcknowledgedInsecure: false
|
2018-01-01 19:46:28 +00:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public render() {
|
2018-01-04 16:31:22 +00:00
|
|
|
|
const { hidden } = this.props;
|
2018-01-01 19:46:28 +00:00
|
|
|
|
const selectedWallet = this.getSelectedWallet();
|
|
|
|
|
const decryptionComponent = this.getDecryptionComponent();
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
{!hidden && (
|
|
|
|
|
<article className="Tab-content-pane">
|
|
|
|
|
<div className="WalletDecrypt">
|
|
|
|
|
<TransitionGroup>
|
|
|
|
|
{decryptionComponent && selectedWallet ? (
|
|
|
|
|
<CSSTransition classNames="DecryptContent" timeout={500} key="decrypt">
|
2018-01-24 22:23:20 +00:00
|
|
|
|
{decryptionComponent}
|
2018-01-01 19:46:28 +00:00
|
|
|
|
</CSSTransition>
|
|
|
|
|
) : (
|
|
|
|
|
<CSSTransition classNames="DecryptContent" timeout={500} key="wallets">
|
|
|
|
|
{this.buildWalletOptions()}
|
|
|
|
|
</CSSTransition>
|
|
|
|
|
)}
|
|
|
|
|
</TransitionGroup>
|
|
|
|
|
</div>
|
|
|
|
|
</article>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onChange = (value: UnlockParams) => {
|
|
|
|
|
this.setState({ value });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public onUnlock = (payload: any) => {
|
|
|
|
|
const { value, selectedWalletKey } = this.state;
|
|
|
|
|
if (!selectedWalletKey) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// some components (TrezorDecrypt) don't take an onChange prop, and thus
|
|
|
|
|
// this.state.value will remain unpopulated. in this case, we can expect
|
|
|
|
|
// the payload to contain the unlocked wallet info.
|
|
|
|
|
const unlockValue = value && !isEmpty(value) ? value : payload;
|
|
|
|
|
this.WALLETS[selectedWalletKey].unlock(unlockValue);
|
2018-03-02 21:57:17 +00:00
|
|
|
|
this.props.resetTransactionState(this.props.resetIncludeExcludeProperties);
|
2018-01-01 19:46:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
2018-01-20 20:06:28 +00:00
|
|
|
|
private isWalletDisabled = (walletKey: WalletName) => {
|
2018-01-26 20:08:39 +00:00
|
|
|
|
return this.props.computedDisabledWallets.wallets.indexOf(walletKey) !== -1;
|
2018-01-01 19:46:28 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-20 20:06:28 +00:00
|
|
|
|
function mapStateToProps(state: AppState, ownProps: Props) {
|
|
|
|
|
const { disabledWallets } = ownProps;
|
2018-01-26 20:08:39 +00:00
|
|
|
|
let computedDisabledWallets = getDisabledWallets(state);
|
|
|
|
|
|
|
|
|
|
if (disabledWallets) {
|
|
|
|
|
computedDisabledWallets = {
|
|
|
|
|
wallets: [...computedDisabledWallets.wallets, ...disabledWallets.wallets],
|
|
|
|
|
reasons: {
|
|
|
|
|
...computedDisabledWallets.reasons,
|
|
|
|
|
...disabledWallets.reasons
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-01 19:46:28 +00:00
|
|
|
|
return {
|
2018-01-20 20:06:28 +00:00
|
|
|
|
computedDisabledWallets,
|
2018-01-11 06:44:13 +00:00
|
|
|
|
isWalletPending: state.wallet.isWalletPending,
|
|
|
|
|
isPasswordPending: state.wallet.isPasswordPending
|
2018-01-01 19:46:28 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-20 20:06:28 +00:00
|
|
|
|
export default connect<StateProps, DispatchProps>(mapStateToProps, {
|
2018-01-01 19:46:28 +00:00
|
|
|
|
unlockKeystore,
|
|
|
|
|
unlockMnemonic,
|
|
|
|
|
unlockPrivateKey,
|
|
|
|
|
unlockWeb3,
|
|
|
|
|
setWallet,
|
|
|
|
|
resetWallet,
|
2018-01-11 06:44:13 +00:00
|
|
|
|
resetTransactionState: reset,
|
|
|
|
|
showNotification
|
2018-01-01 19:46:28 +00:00
|
|
|
|
})(WalletDecrypt);
|