Skip to content

Commit

Permalink
switched to different fiat conversion rate service since yahoo discon…
Browse files Browse the repository at this point in the history
…tinued theirs
  • Loading branch information
manuelsc committed Nov 9, 2017
1 parent 734f4f6 commit da97ec6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public void run() {
public void run() {
if (fragments != null) {
if (fragments[0] != null)
((FragmentPrice) fragments[0]).update();
((FragmentPrice) fragments[0]).update(true);
if (fragments[1] != null) {
((FragmentWallets) fragments[1]).updateBalanceText();
((FragmentWallets) fragments[1]).notifyDataSetChanged();
Expand Down Expand Up @@ -481,7 +481,7 @@ public void onUpdate(Response s) {
public void run() {
broadCastDataSetChanged();
if (fragments != null && fragments[0] != null) {
((FragmentPrice) fragments[0]).update();
((FragmentPrice) fragments[0]).update(true);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
@Override
public void onClick(View view) {
displayInUsd = !displayInUsd;
update();
update(true);
general();

if (ac != null && ac.getPreferences() != null) {
Expand Down Expand Up @@ -145,19 +145,21 @@ public void onRefresh() {

swipeLayout.setRefreshing(true);
general();
update();
update(true);
priceChart.setVisibility(View.INVISIBLE);
return rootView;
}

private void next() {
displayType = (displayType + 1) % PERIOD.length;
general();
update(true);
}

private void previous() {
displayType = displayType > 0 ? displayType - 1 : PERIOD.length - 1;
general();
update(true);
}

private void general() {
Expand All @@ -169,13 +171,6 @@ private void general() {
editor.putInt("displaytype_chart", displayType);
editor.apply();
}

//swipeLayout.setRefreshing(true);
try {
loadPriceData(TIMESTAMPS[displayType], PERIOD[displayType]);
} catch (IOException e) {
e.printStackTrace();
}
}

private void loadPriceData(final long time, int period) throws IOException {
Expand Down Expand Up @@ -203,15 +198,15 @@ public void onResponse(Call call, Response response) throws IOException {
JSONObject o = data.getJSONObject(i);
yVals.add(new Entry(o.getLong("date"), (float) Math.floor(o.getDouble("high") * exchangeRate * commas) / commas));
}

if(ac == null) return;
ac.runOnUiThread(new Runnable() {
@Override
public void run() {
priceChart.setVisibility(View.VISIBLE);
onItemsLoadComplete();
if (isAdded()) {
setupChart(priceChart, getData(yVals), getResources().getColor(R.color.colorPrimaryLittleDarker));
update();
update(false);
}
}
});
Expand Down Expand Up @@ -309,19 +304,27 @@ public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProv
public void updateExchangeRates() {
try {
ExchangeCalculator.getInstance().updateExchangeRates(ac != null ? ac.getPreferences().getString("maincurrency", "USD") : "USD", ac);
update();
update(true);
onItemsLoadComplete();
} catch (IOException e) {
e.printStackTrace();
}
}

public void update() {
public void update(boolean updateChart) {
if (price != null)
price.setText(displayInUsd ?
ExchangeCalculator.getInstance().displayUsdNicely(ExchangeCalculator.getInstance().getUSDPrice()) + " " + ExchangeCalculator.getInstance().getMainCurreny().getName() :
ExchangeCalculator.getInstance().displayEthNicely(ExchangeCalculator.getInstance().getBTCPrice()) + " BTC"
);

if(updateChart) {
try {
loadPriceData(TIMESTAMPS[displayType], PERIOD[displayType]);
} catch (IOException e) {
e.printStackTrace();
}
}
onItemsLoadComplete();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void getNonceForAddress(String address, Callback b) throws IOException {


public void getPriceConversionRates(String currencyConversion, Callback b) throws IOException {
get("http://download.finance.yahoo.com/d/quotes.csv?s=" + currencyConversion + "=X&f=snl1", b);
get("https://api.fixer.io/latest?base=USD&symbols=" + currencyConversion, b);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void onResponse(Call call, final Response response) throws IOException {
}

private void convert(final String currency, final NetworkUpdateListener update) throws IOException {
EtherscanAPI.getInstance().getPriceConversionRates("USD" + currency, new Callback() {
EtherscanAPI.getInstance().getPriceConversionRates(currency, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ public static BigInteger parseGasPrice(String response) throws Exception {

public static double parsePriceConversionRate(String response) {
try {
return Double.parseDouble(response.split(",")[2]);
JSONObject jo = new JSONObject(response).getJSONObject("rates");
String key = jo.keys().next();
return jo.getDouble(key);
} catch (Exception e) {
return 1;
}
Expand Down

0 comments on commit da97ec6

Please sign in to comment.