This commit is contained in:
marcosrdz 2020-11-20 21:47:13 -05:00
parent 490a1441b6
commit 54db77e582
4 changed files with 12 additions and 16 deletions

View File

@ -5,7 +5,6 @@ import { FiatServerResponse, FiatUnit } from '../models/fiatUnit';
import DefaultPreference from 'react-native-default-preference';
import RNWidgetCenter from 'react-native-widget-center';
import * as RNLocalize from 'react-native-localize';
import { report } from 'process';
const BigNumber = require('bignumber.js');
let preferredFiatCurrency = FiatUnit.USD;
const exchangeRates = {};
@ -63,8 +62,7 @@ async function updateExchangeRate() {
baseURI: fiatServerResponse.baseURI(),
});
response = await api.get(fiatServerResponse.endPoint());
console.warn(JSON.parse(response.body))
// fiatServerResponse.isErrorFound(response);
fiatServerResponse.isErrorFound(response);
} catch (Err) {
console.warn(Err);
const lastSavedExchangeRate = JSON.parse(await AsyncStorage.getItem(AppStorage.EXCHANGE_RATES));

View File

@ -1,6 +1,6 @@
export const FiatUnit = Object.freeze({
USD: { endPointKey: 'USD', symbol: '$', locale: 'en-US' },
ARS: { endPointKey: 'ARS', symbol: '$', locale: 'es-AR', dataSource: 'https://api.yadio.io/rate/', rateKey: 'rate' },
ARS: { endPointKey: 'ARS', symbol: '$', locale: 'es-AR', dataSource: 'https://api.yadio.io/rate', rateKey: 'rate' },
AUD: { endPointKey: 'AUD', symbol: '$', locale: 'en-AU' },
BRL: { endPointKey: 'BRL', symbol: 'R$', locale: 'pt-BR' },
CAD: { endPointKey: 'CAD', symbol: '$', locale: 'en-CA' },
@ -33,11 +33,11 @@ export const FiatUnit = Object.freeze({
TWD: { endPointKey: 'TWD', symbol: 'NT$', locale: 'zh-Hant-TW' },
UAH: { endPointKey: 'UAH', symbol: '₴', locale: 'uk-UA' },
VEF: { endPointKey: 'VEF', symbol: 'Bs.', locale: 'es-VE' },
VES: { endPointKey: 'VES', symbol: 'Bs.', locale: 'es-VE', dataSource: 'https://api.yadio.io/rate', rateKey: 'btc' },
ZAR: { endPointKey: 'ZAR', symbol: 'R', locale: 'en-ZA' },
});
export class FiatServerResponse {
constructor(fiatUnit) {
this.fiatUnit = fiatUnit;
}
@ -52,15 +52,14 @@ export class FiatServerResponse {
endPoint = () => {
if (this.fiatUnit.dataSource) {
return this.fiatUnit.endPointKey;
return `/${this.fiatUnit.endPointKey}`;
} else {
return '/v1/bpi/currentprice/' + this.fiatUnit.endPointKey + '.json';
}
};
rate = response => {
const json = JSON.parse(response.body);
console.error(json);
const json = typeof response.body === 'string' ? JSON.parse(response.body) : response.body;
if (this.fiatUnit.dataSource) {
return json[this.fiatUnit.rateKey] * 1;
} else {
@ -69,15 +68,15 @@ export class FiatServerResponse {
};
isErrorFound = response => {
const json = JSON.parse(response.body);
const json = typeof response.body === 'string' ? JSON.parse(response.body) : response.body;
if (this.fiatUnit.dataSource) {
if (!json || !json[this.fiatUnit.rateKey]) {
throw new Error('Could not update currency rate: ' + response.err);
}
} else {
if (!json || !json.bpi || !json.bpi[this.fiatUnit.endPointKey] || !json.bpi[this.fiatUnit.endPointKey].rate_float) {
if (!json || !json.bpi || !json.bpi[this.fiatUnit.endPointKey] || !json.bpi[this.fiatUnit.endPointKey].rate_float) {
throw new Error('Could not update currency rate: ' + response.err);
}
}
};
};
}

View File

@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
import { FlatList, TouchableOpacity, ActivityIndicator, View, StyleSheet } from 'react-native';
import { FlatList, ActivityIndicator, View, StyleSheet } from 'react-native';
import { SafeBlueArea, BlueListItem, BlueTextHooks, BlueCard, BlueNavigationStyle } from '../../BlueComponents';
import PropTypes from 'prop-types';
import { FiatUnit } from '../../models/fiatUnit';
@ -48,16 +48,14 @@ const Currency = () => {
style={styles.flex}
keyExtractor={(_item, index) => `${index}`}
data={data}
initialNumToRender={25}
extraData={data}
renderItem={({ item }) => {
return (
<BlueListItem
disabled={isSavingNewPreferredCurrency}
title={`${item.endPointKey} (${item.symbol})`}
{...(selectedCurrency.endPointKey === item.endPointKey
? { rightIcon: { name: 'check', type: 'octaicon', color: '#0070FF' } }
: { hideChevron: true })}
Component={TouchableOpacity}
checkmark={selectedCurrency.endPointKey === item.endPointKey}
onPress={async () => {
setIsSavingNewPreferredCurrency(true);
setSelectedCurrency(item);

View File

@ -6,6 +6,7 @@ vim ios/BlueWallet.xcodeproj/project.pbxproj
vim ios/WalletInformationWidget/Widgets/MarketWidget/Info.plist
vim ios/WalletInformationWidget/Widgets/WalletInformationAndMarketWidget/Info.plist
vim ios/WalletInformationWidget/Info.plist
vim ios/WalletInformationWidget/Widgets/PriceWidget/Info.plist
vim android/app/build.gradle
vim package.json
vim package-lock.json