Fix Unlock Bugs (#183)

* Remove unused imports.

* Create and use .toPrecision forwarding method for `Unit`

* Error handling when unlocking trezor devices.

* Use translateRaw to fulfill string req;
This commit is contained in:
Daniel Ternyak 2017-09-11 20:29:07 -05:00 committed by GitHub
parent 481e6e89b6
commit f34811546a
7 changed files with 14 additions and 8 deletions

View File

@ -4,7 +4,6 @@ import React from 'react';
import translate from 'translations';
import { Identicon } from 'components/ui';
import { formatNumber } from 'utils/formatters';
import type Big from 'bignumber.js';
import type { IWallet } from 'libs/wallet';
import type { NetworkConfig } from 'config/data';
import { Ether } from 'libs/units';

View File

@ -1,6 +1,5 @@
// @flow
import React from 'react';
import Big from 'bignumber.js';
import { IWallet } from 'libs/wallet';
import type { NetworkConfig } from 'config/data';
import type { State } from 'reducers';

View File

@ -142,9 +142,7 @@ class DeterministicWalletsModal extends React.Component {
const { selectedAddress } = this.state;
// Get renderable values, but keep 'em short
const value = wallet.value
? toUnit(wallet.value, 'wei', 'ether').toPrecision(4)
: '';
const value = wallet.value ? wallet.value.toEther().toPrecision(4) : '';
const tokenValue = wallet.tokenValues[desiredToken]
? wallet.tokenValues[desiredToken].toPrecision(4)
: '';

View File

@ -116,7 +116,7 @@ export default class TrezorDecrypt extends Component {
onCancel={this._handleCancel}
onConfirmAddress={this._handleUnlock}
onPathChange={this._handlePathChange}
walletType={translate('x_Trezor')}
walletType={translate('x_Trezor', true)}
/>
</section>
);

View File

@ -11,6 +11,7 @@ import ViewOnlyDecrypt from './ViewOnly';
import map from 'lodash/map';
import { unlockPrivateKey, unlockKeystore, setWallet } from 'actions/wallet';
import { connect } from 'react-redux';
import isEmpty from 'lodash/isEmpty';
const WALLETS = {
'keystore-file': {
@ -164,8 +165,14 @@ export class WalletDecrypt extends Component {
};
onUnlock = (payload: any) => {
// 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 =
this.state.value && !isEmpty(this.state.value)
? this.state.value
: payload;
this.props.dispatch(
WALLETS[this.state.selectedWalletKey].unlock(this.state.value || payload)
WALLETS[this.state.selectedWalletKey].unlock(unlockValue)
);
};
}

View File

@ -47,6 +47,10 @@ class Unit {
return this.amount.toString(base);
}
toPrecision(precision?: number) {
return this.amount.toPrecision(precision);
}
toWei(): Wei {
return new Wei(toWei(this.amount, this.unit));
}

View File

@ -6,7 +6,6 @@ import type {
SetTokenBalancesAction
} from 'actions/wallet';
import { IWallet } from 'libs/wallet';
import { toUnit } from 'libs/units';
import Big from 'bignumber.js';
import { getTxFromBroadcastTransactionStatus } from 'selectors/wallet';
import type { BroadcastTransactionStatus } from 'libs/transaction';