mirror of
https://github.com/trezor/trezor-wallet
synced 2025-06-11 10:38:54 +00:00
fix fiat rate value in reducer
This commit is contained in:
parent
8e13b49d2e
commit
d3093313d6
@ -13,23 +13,14 @@ export type Fiat = {
|
|||||||
export const initialState: Array<Fiat> = [];
|
export const initialState: Array<Fiat> = [];
|
||||||
|
|
||||||
const update = (state: Array<Fiat>, action: FiatRateAction): Array<Fiat> => {
|
const update = (state: Array<Fiat>, action: FiatRateAction): Array<Fiat> => {
|
||||||
const newState: Array<Fiat> = [...state];
|
const affected = state.find(f => f.network === action.network);
|
||||||
let exists: ?Fiat = newState.find(f => f.network === action.network);
|
const otherRates = state.filter(d => d !== affected);
|
||||||
const { network, rate } = action;
|
const { network, rate } = action;
|
||||||
|
|
||||||
if (exists) {
|
return otherRates.concat([{
|
||||||
exists = {
|
network,
|
||||||
network,
|
value: rate.toFixed(2),
|
||||||
value: rate,
|
}]);
|
||||||
};
|
|
||||||
} else {
|
|
||||||
newState.push({
|
|
||||||
network,
|
|
||||||
value: rate,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return newState;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (state: Array<Fiat> = initialState, action: Action): Array<Fiat> => {
|
export default (state: Array<Fiat> = initialState, action: Action): Array<Fiat> => {
|
||||||
|
@ -19,7 +19,7 @@ export const RATE_UPDATE: 'rate__update' = 'rate__update';
|
|||||||
export type FiatRateAction = {
|
export type FiatRateAction = {
|
||||||
type: typeof RATE_UPDATE;
|
type: typeof RATE_UPDATE;
|
||||||
network: string;
|
network: string;
|
||||||
rate: any;
|
rate: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadRateAction = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
const loadRateAction = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||||
|
@ -136,7 +136,7 @@ const AccountMenu = (props: Props) => {
|
|||||||
balance = `${availableBalance} ${network.symbol}`;
|
balance = `${availableBalance} ${network.symbol}`;
|
||||||
if (fiatRate) {
|
if (fiatRate) {
|
||||||
const accountBalance = new BigNumber(availableBalance);
|
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}`;
|
balance = `${availableBalance} ${network.symbol} / $${fiat}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,14 +106,13 @@ class AccountBalance extends PureComponent<Props, State> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { network } = this.props;
|
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 accountBalance = '';
|
||||||
let fiatRateValue = '';
|
let fiatRateValue = '';
|
||||||
let fiat = '';
|
let fiat = '';
|
||||||
if (fiatRate) {
|
if (fiatRate) {
|
||||||
const fiatValue = Math.round(fiatRate.value * 100) / 100;
|
|
||||||
accountBalance = new BigNumber(this.props.balance);
|
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);
|
fiat = accountBalance.times(fiatRateValue).toFixed(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user