mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-11 19:44:21 +00:00
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:
parent
481e6e89b6
commit
f34811546a
@ -4,7 +4,6 @@ import React from 'react';
|
|||||||
import translate from 'translations';
|
import translate from 'translations';
|
||||||
import { Identicon } from 'components/ui';
|
import { Identicon } from 'components/ui';
|
||||||
import { formatNumber } from 'utils/formatters';
|
import { formatNumber } from 'utils/formatters';
|
||||||
import type Big from 'bignumber.js';
|
|
||||||
import type { IWallet } from 'libs/wallet';
|
import type { IWallet } from 'libs/wallet';
|
||||||
import type { NetworkConfig } from 'config/data';
|
import type { NetworkConfig } from 'config/data';
|
||||||
import { Ether } from 'libs/units';
|
import { Ether } from 'libs/units';
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Big from 'bignumber.js';
|
|
||||||
import { IWallet } from 'libs/wallet';
|
import { IWallet } from 'libs/wallet';
|
||||||
import type { NetworkConfig } from 'config/data';
|
import type { NetworkConfig } from 'config/data';
|
||||||
import type { State } from 'reducers';
|
import type { State } from 'reducers';
|
||||||
|
@ -142,9 +142,7 @@ class DeterministicWalletsModal extends React.Component {
|
|||||||
const { selectedAddress } = this.state;
|
const { selectedAddress } = this.state;
|
||||||
|
|
||||||
// Get renderable values, but keep 'em short
|
// Get renderable values, but keep 'em short
|
||||||
const value = wallet.value
|
const value = wallet.value ? wallet.value.toEther().toPrecision(4) : '';
|
||||||
? toUnit(wallet.value, 'wei', 'ether').toPrecision(4)
|
|
||||||
: '';
|
|
||||||
const tokenValue = wallet.tokenValues[desiredToken]
|
const tokenValue = wallet.tokenValues[desiredToken]
|
||||||
? wallet.tokenValues[desiredToken].toPrecision(4)
|
? wallet.tokenValues[desiredToken].toPrecision(4)
|
||||||
: '';
|
: '';
|
||||||
|
@ -116,7 +116,7 @@ export default class TrezorDecrypt extends Component {
|
|||||||
onCancel={this._handleCancel}
|
onCancel={this._handleCancel}
|
||||||
onConfirmAddress={this._handleUnlock}
|
onConfirmAddress={this._handleUnlock}
|
||||||
onPathChange={this._handlePathChange}
|
onPathChange={this._handlePathChange}
|
||||||
walletType={translate('x_Trezor')}
|
walletType={translate('x_Trezor', true)}
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
@ -11,6 +11,7 @@ import ViewOnlyDecrypt from './ViewOnly';
|
|||||||
import map from 'lodash/map';
|
import map from 'lodash/map';
|
||||||
import { unlockPrivateKey, unlockKeystore, setWallet } from 'actions/wallet';
|
import { unlockPrivateKey, unlockKeystore, setWallet } from 'actions/wallet';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
import isEmpty from 'lodash/isEmpty';
|
||||||
|
|
||||||
const WALLETS = {
|
const WALLETS = {
|
||||||
'keystore-file': {
|
'keystore-file': {
|
||||||
@ -164,8 +165,14 @@ export class WalletDecrypt extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onUnlock = (payload: any) => {
|
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(
|
this.props.dispatch(
|
||||||
WALLETS[this.state.selectedWalletKey].unlock(this.state.value || payload)
|
WALLETS[this.state.selectedWalletKey].unlock(unlockValue)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,10 @@ class Unit {
|
|||||||
return this.amount.toString(base);
|
return this.amount.toString(base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toPrecision(precision?: number) {
|
||||||
|
return this.amount.toPrecision(precision);
|
||||||
|
}
|
||||||
|
|
||||||
toWei(): Wei {
|
toWei(): Wei {
|
||||||
return new Wei(toWei(this.amount, this.unit));
|
return new Wei(toWei(this.amount, this.unit));
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import type {
|
|||||||
SetTokenBalancesAction
|
SetTokenBalancesAction
|
||||||
} from 'actions/wallet';
|
} from 'actions/wallet';
|
||||||
import { IWallet } from 'libs/wallet';
|
import { IWallet } from 'libs/wallet';
|
||||||
import { toUnit } from 'libs/units';
|
|
||||||
import Big from 'bignumber.js';
|
import Big from 'bignumber.js';
|
||||||
import { getTxFromBroadcastTransactionStatus } from 'selectors/wallet';
|
import { getTxFromBroadcastTransactionStatus } from 'selectors/wallet';
|
||||||
import type { BroadcastTransactionStatus } from 'libs/transaction';
|
import type { BroadcastTransactionStatus } from 'libs/transaction';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user