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 New Networks #1259

Merged
merged 14 commits into from
Apr 6, 2018
19 changes: 12 additions & 7 deletions common/components/WalletDecrypt/components/LedgerNano.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import './LedgerNano.scss';
import React, { PureComponent } from 'react';
import translate from 'translations';
import ledger from 'ledgerco';
import translate, { translateRaw } from 'translations';
import DeterministicWalletsModal from './DeterministicWalletsModal';
import UnsupportedNetwork from './UnsupportedNetwork';
import { LedgerWallet } from 'libs/wallet';
import ledger from 'ledgerco';
import { Spinner, NewTabLink } from 'components/ui';
import { connect } from 'react-redux';
import { AppState } from 'reducers';
import { SecureWalletName, ledgerReferralURL } from 'config';
import { getPaths, getSingleDPath } from 'selectors/config/wallet';
import './LedgerNano.scss';

interface OwnProps {
onUnlock(param: any): void;
}

interface StateProps {
dPath: DPath;
dPath: DPath | undefined;
dPaths: DPath[];
}

Expand All @@ -34,7 +35,7 @@ class LedgerNanoSDecryptClass extends PureComponent<Props, State> {
public state: State = {
publicKey: '',
chainCode: '',
dPath: this.props.dPath.value,
dPath: this.props.dPath ? this.props.dPath.value : '',
error: null,
isLoading: false,
showTip: false
Expand All @@ -48,14 +49,18 @@ class LedgerNanoSDecryptClass extends PureComponent<Props, State> {

public componentWillReceiveProps(nextProps: Props) {
if (this.props.dPath !== nextProps.dPath) {
this.setState({ dPath: nextProps.dPath.value });
this.setState({ dPath: nextProps.dPath ? nextProps.dPath.value : '' });
}
}

public render() {
const { dPath, publicKey, chainCode, error, isLoading, showTip } = this.state;
const showErr = error ? 'is-showing' : '';

if (!dPath) {
return <UnsupportedNetwork walletType={translateRaw('x_Ledger')} />;
}

if (window.location.protocol !== 'https:') {
return (
<div className="LedgerDecrypt">
Expand Down Expand Up @@ -167,7 +172,7 @@ class LedgerNanoSDecryptClass extends PureComponent<Props, State> {
this.setState({
publicKey: '',
chainCode: '',
dPath: this.props.dPath.value
dPath: this.props.dPath ? this.props.dPath.value : ''
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion common/components/WalletDecrypt/components/Mnemonic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ class MnemonicDecryptClass extends PureComponent<Props, State> {

function mapStateToProps(state: AppState): StateProps {
return {
dPath: getSingleDPath(state, InsecureWalletName.MNEMONIC_PHRASE),
// Mnemonic dPath is guaranteed to always be provided
dPath: getSingleDPath(state, InsecureWalletName.MNEMONIC_PHRASE) as DPath,
dPaths: getPaths(state, InsecureWalletName.MNEMONIC_PHRASE)
};
}
Expand Down
17 changes: 11 additions & 6 deletions common/components/WalletDecrypt/components/Trezor.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { TrezorWallet, TREZOR_MINIMUM_FIRMWARE } from 'libs/wallet';
import React, { PureComponent } from 'react';
import translate from 'translations';
import translate, { translateRaw } from 'translations';
import TrezorConnect from 'vendor/trezor-connect';
import DeterministicWalletsModal from './DeterministicWalletsModal';
import './Trezor.scss';
import UnsupportedNetwork from './UnsupportedNetwork';
import { Spinner, NewTabLink } from 'components/ui';
import { AppState } from 'reducers';
import { connect } from 'react-redux';
import { SecureWalletName, trezorReferralURL } from 'config';
import { getSingleDPath, getPaths } from 'selectors/config/wallet';
import './Trezor.scss';

//todo: conflicts with comment in walletDecrypt -> onUnlock method
interface OwnProps {
onUnlock(param: any): void;
}

interface StateProps {
dPath: DPath;
dPath: DPath | undefined;
dPaths: DPath[];
}

Expand All @@ -35,21 +36,25 @@ class TrezorDecryptClass extends PureComponent<Props, State> {
public state: State = {
publicKey: '',
chainCode: '',
dPath: this.props.dPath.value,
dPath: this.props.dPath ? this.props.dPath.value : '',
error: null,
isLoading: false
};

public componentWillReceiveProps(nextProps: Props) {
if (this.props.dPath !== nextProps.dPath) {
this.setState({ dPath: nextProps.dPath.value });
this.setState({ dPath: nextProps.dPath ? nextProps.dPath.value : '' });
}
}

public render() {
const { dPath, publicKey, chainCode, error, isLoading } = this.state;
const showErr = error ? 'is-showing' : '';

if (!dPath) {
return <UnsupportedNetwork walletType={translateRaw('x_Trezor')} />;
}

return (
<div className="TrezorDecrypt">
<button
Expand Down Expand Up @@ -141,7 +146,7 @@ class TrezorDecryptClass extends PureComponent<Props, State> {
this.setState({
publicKey: '',
chainCode: '',
dPath: this.props.dPath.value
dPath: this.props.dPath ? this.props.dPath.value : ''
});
}
}
Expand Down
27 changes: 27 additions & 0 deletions common/components/WalletDecrypt/components/UnsupportedNetwork.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { connect } from 'react-redux';
import { getNetworkConfig } from 'selectors/config';
import { NetworkConfig } from 'types/network';
import { AppState } from 'reducers';

interface StateProps {
network: NetworkConfig;
}

interface OwnProps {
walletType: string | React.ReactElement<string>;
}

type Props = OwnProps & StateProps;

const UnsupportedNetwork: React.SFC<Props> = ({ walletType, network }) => {
return (
<h2>
{walletType} does not support the {network.name} network
</h2>
);
};

export default connect((state: AppState): StateProps => ({
network: getNetworkConfig(state)
}))(UnsupportedNetwork);
20 changes: 19 additions & 1 deletion common/config/dpaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ export const UBQ_DEFAULT: DPath = {
value: "m/44'/108'/0'/0"
};

export const POA_DEFAULT: DPath = {
label: 'Default (POA)',
value: "m/44'/60'/0'/0"
};

export const TOMO_DEFAULT: DPath = {
label: 'Default (TOMO)',
value: "m/44'/1'/0'/0"
};

export const ELLA_DEFAULT: DPath = {
label: 'Default (ELLA)',
value: "m/44'/163'/0'/0"
};

export const ETH_SINGULAR: DPath = {
label: 'SingularDTV',
value: "m/0'/0'/0'"
Expand All @@ -51,7 +66,10 @@ export const DPaths: DPath[] = [
ETC_TREZOR,
ETH_TESTNET,
EXP_DEFAULT,
UBQ_DEFAULT
UBQ_DEFAULT,
POA_DEFAULT,
TOMO_DEFAULT,
ELLA_DEFAULT
];

// PATHS TO BE INCLUDED REGARDLESS OF WALLET FORMAT
Expand Down
Loading