mirror of
https://github.com/trezor/trezor-wallet
synced 2025-01-16 02:51:03 +00:00
Propagate rate to ui
This commit is contained in:
parent
9498a4effa
commit
eaede07068
@ -8,7 +8,7 @@ import type { FiatRateAction } from 'services/TickerService';
|
|||||||
export type Fiat = {
|
export type Fiat = {
|
||||||
+network: string;
|
+network: string;
|
||||||
value: string;
|
value: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const initialState: Array<Fiat> = [];
|
export const initialState: Array<Fiat> = [];
|
||||||
|
|
||||||
@ -18,7 +18,6 @@ const update = (state: Array<Fiat>, action: FiatRateAction): Array<Fiat> => {
|
|||||||
network: action.network,
|
network: action.network,
|
||||||
value: action.rate.current_price.usd,
|
value: action.rate.current_price.usd,
|
||||||
});
|
});
|
||||||
console.log('newState', newState);
|
|
||||||
return newState;
|
return newState;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
/* @flow */
|
|
||||||
|
|
||||||
import { httpRequest } from 'utils/networkUtils';
|
|
||||||
import { resolveAfter } from 'utils/promiseUtils';
|
|
||||||
import { READY } from 'actions/constants/localStorage';
|
|
||||||
|
|
||||||
import type {
|
|
||||||
Middleware,
|
|
||||||
MiddlewareAPI,
|
|
||||||
MiddlewareDispatch,
|
|
||||||
Dispatch,
|
|
||||||
Action,
|
|
||||||
AsyncAction,
|
|
||||||
GetState,
|
|
||||||
} from 'flowtype';
|
|
||||||
|
|
||||||
export const RATE_UPDATE: 'rate__update' = 'rate__update';
|
|
||||||
|
|
||||||
export type FiatRateAction = {
|
|
||||||
type: typeof RATE_UPDATE;
|
|
||||||
network: string;
|
|
||||||
rate: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadRateAction = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
|
||||||
const { config } = getState().localStorage;
|
|
||||||
if (!config) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
config.fiatValueTickers.forEach(async (ticker) => {
|
|
||||||
// const rate: ?Array<any> = await JSONRequest(`${ticker.url}?convert=USD`, 'json');
|
|
||||||
const rate: ?Array<any> = await httpRequest(`${ticker.url}?convert=USD`, 'json');
|
|
||||||
console.log('rate');
|
|
||||||
if (rate) {
|
|
||||||
dispatch({
|
|
||||||
type: RATE_UPDATE,
|
|
||||||
network: ticker.network,
|
|
||||||
rate: rate[0],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
// ignore error
|
|
||||||
}
|
|
||||||
|
|
||||||
await resolveAfter(50000);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Middleware
|
|
||||||
*/
|
|
||||||
const CoinmarketcapService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => (action: Action): Action => {
|
|
||||||
next(action);
|
|
||||||
|
|
||||||
if (action.type === READY) {
|
|
||||||
api.dispatch(loadRateAction());
|
|
||||||
}
|
|
||||||
|
|
||||||
return action;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default CoinmarketcapService;
|
|
@ -30,7 +30,7 @@ const loadRateAction = (): AsyncAction => async (dispatch: Dispatch, getState: G
|
|||||||
config.fiatValueTickers.forEach(async (ticker) => {
|
config.fiatValueTickers.forEach(async (ticker) => {
|
||||||
const response: ?Array<any> = await httpRequest(`${ticker.url}?tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false`, 'json');
|
const response: ?Array<any> = await httpRequest(`${ticker.url}?tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false`, 'json');
|
||||||
if (response) {
|
if (response) {
|
||||||
console.log({
|
dispatch({
|
||||||
type: RATE_UPDATE,
|
type: RATE_UPDATE,
|
||||||
network: response.symbol,
|
network: response.symbol,
|
||||||
rate: response.market_data,
|
rate: response.market_data,
|
||||||
|
@ -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(fiatRate.value).toFixed(2);
|
const fiat = accountBalance.times(parseInt(fiatRate.value, 10)).toFixed(2);
|
||||||
balance = `${availableBalance} ${network.symbol} / $${fiat}`;
|
balance = `${availableBalance} ${network.symbol} / $${fiat}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,17 +107,16 @@ 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: any = 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(fiatRate.value).toFixed(2);
|
fiatRateValue = new BigNumber(fiatValue).toFixed(2);
|
||||||
fiat = accountBalance.times(fiatRateValue).toFixed(2);
|
fiat = accountBalance.times(fiatRateValue).toFixed(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<HideBalanceIconWrapper
|
<HideBalanceIconWrapper
|
||||||
|
Loading…
Reference in New Issue
Block a user