1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-15 21:08:57 +00:00

Merge pull request #236 from trezor/fix/coinmarketcap-api

Coinmarketcap api → coingecko api [WIP]
This commit is contained in:
Vladimir Volek 2018-11-12 12:51:41 +01:00 committed by GitHub
commit 7f3745c621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 30 deletions

View File

@ -59,11 +59,11 @@
"fiatValueTickers": [
{
"network": "eth",
"url": "https://api.coinmarketcap.com/v1/ticker/ethereum/"
"url": "https://api.coingecko.com/api/v3/coins/ethereum"
},
{
"network": "etc",
"url": "https://api.coinmarketcap.com/v1/ticker/ethereum-classic/"
"url": "https://api.coingecko.com/api/v3/coins/ethereum-classic"
}
],

View File

@ -31,7 +31,7 @@ import type { TokenAction } from 'actions/TokenActions';
import type { TrezorConnectAction } from 'actions/TrezorConnectActions';
import type { WalletAction } from 'actions/WalletActions';
import type { Web3Action } from 'actions/Web3Actions';
import type { FiatRateAction } from 'services/CoinmarketcapService'; // this service has no action file, all is written inside one file
import type { FiatRateAction } from 'services/CoingeckoService'; // this service has no action file, all is written inside one file
import type {
Device,

View File

@ -1,29 +1,26 @@
/* @flow */
import { RATE_UPDATE } from 'services/CoinmarketcapService';
import { RATE_UPDATE } from 'services/CoingeckoService';
import type { Action } from 'flowtype';
import type { FiatRateAction } from 'services/CoinmarketcapService';
import type { FiatRateAction } from 'services/CoingeckoService';
export type Fiat = {
+network: string;
value: string;
}
};
export const initialState: Array<Fiat> = [];
const update = (state: Array<Fiat>, action: FiatRateAction): Array<Fiat> => {
const newState: Array<Fiat> = [...state];
const exists: ?Fiat = newState.find(f => f.network === action.network);
if (exists) {
exists.value = action.rate.price_usd;
} else {
newState.push({
network: action.network,
value: action.rate.price_usd,
});
}
return newState;
const affected = state.find(f => f.network === action.network);
const otherRates = state.filter(d => d !== affected);
const { network, rate } = action;
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> => {
@ -28,13 +28,12 @@ const loadRateAction = (): AsyncAction => async (dispatch: Dispatch, getState: G
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');
if (rate) {
const response = await httpRequest(`${ticker.url}?tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false`, 'json');
if (response) {
dispatch({
type: RATE_UPDATE,
network: ticker.network,
rate: rate[0],
network: response.symbol,
rate: response.market_data.current_price.usd,
});
}
});
@ -48,7 +47,7 @@ const loadRateAction = (): AsyncAction => async (dispatch: Dispatch, getState: G
/**
* Middleware
*/
const CoinmarketcapService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => (action: Action): Action => {
const CoingeckoService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => (action: Action): Action => {
next(action);
if (action.type === READY) {
@ -58,4 +57,4 @@ const CoinmarketcapService: Middleware = (api: MiddlewareAPI) => (next: Middlewa
return action;
};
export default CoinmarketcapService;
export default CoingeckoService;

View File

@ -2,7 +2,7 @@ import WalletService from './WalletService';
import LogService from './LogService';
import RouterService from './RouterService';
import LocalStorageService from './LocalStorageService';
import CoinmarketcapService from './CoinmarketcapService';
import CoingeckoService from './CoingeckoService';
import TrezorConnectService from './TrezorConnectService';
export default [
@ -11,5 +11,5 @@ export default [
RouterService,
LocalStorageService,
TrezorConnectService,
CoinmarketcapService,
CoingeckoService,
];

View File

@ -106,8 +106,7 @@ 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 = '';
@ -117,7 +116,6 @@ class AccountBalance extends PureComponent<Props, State> {
fiat = accountBalance.times(fiatRateValue).toFixed(2);
}
return (
<Wrapper>
<HideBalanceIconWrapper