1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-28 09:58:23 +00:00

fix fiat rate value in reducer

This commit is contained in:
Szymon Lesisz 2018-11-12 12:39:24 +01:00
parent 8e13b49d2e
commit d3093313d6
4 changed files with 10 additions and 20 deletions

View File

@ -13,23 +13,14 @@ export type Fiat = {
export const initialState: Array<Fiat> = [];
const update = (state: Array<Fiat>, action: FiatRateAction): Array<Fiat> => {
const newState: Array<Fiat> = [...state];
let exists: ?Fiat = newState.find(f => f.network === action.network);
const affected = state.find(f => f.network === action.network);
const otherRates = state.filter(d => d !== affected);
const { network, rate } = action;
if (exists) {
exists = {
network,
value: rate,
};
} else {
newState.push({
network,
value: rate,
});
}
return newState;
return otherRates.concat([{
network,
value: rate.toFixed(2),
}]);
};
export default (state: Array<Fiat> = initialState, action: Action): Array<Fiat> => {

View File

@ -19,7 +19,7 @@ export const RATE_UPDATE: 'rate__update' = 'rate__update';
export type FiatRateAction = {
type: typeof RATE_UPDATE;
network: string;
rate: any;
rate: number;
}
const loadRateAction = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {

View File

@ -136,7 +136,7 @@ const AccountMenu = (props: Props) => {
balance = `${availableBalance} ${network.symbol}`;
if (fiatRate) {
const accountBalance = new BigNumber(availableBalance);
const fiat = accountBalance.times(parseInt(fiatRate.value, 10)).toFixed(2);
const fiat = accountBalance.times(fiatRate.value).toFixed(2);
balance = `${availableBalance} ${network.symbol} / $${fiat}`;
}
}

View File

@ -106,14 +106,13 @@ class AccountBalance extends PureComponent<Props, State> {
render() {
const { network } = this.props;
const fiatRate: any = this.props.fiat.find(f => f.network === network.shortcut);
const fiatRate = this.props.fiat.find(f => f.network === network.shortcut);
let accountBalance = '';
let fiatRateValue = '';
let fiat = '';
if (fiatRate) {
const fiatValue = Math.round(fiatRate.value * 100) / 100;
accountBalance = new BigNumber(this.props.balance);
fiatRateValue = new BigNumber(fiatValue).toFixed(2);
fiatRateValue = new BigNumber(fiatRate.value).toFixed(2);
fiat = accountBalance.times(fiatRateValue).toFixed(2);
}