-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23a043a
commit 964102c
Showing
9 changed files
with
175 additions
and
209 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/alphawallet/app/entity/ticker/BaseTicker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.alphawallet.app.entity.ticker; | ||
|
||
import android.text.TextUtils; | ||
|
||
import com.alphawallet.app.entity.tokendata.TokenTicker; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
|
||
public abstract class BaseTicker | ||
{ | ||
public final String address; | ||
public final double fiatPrice; | ||
public final BigDecimal fiatChange; | ||
|
||
public BaseTicker(String address, double fiatPrice, BigDecimal fiatChange) | ||
{ | ||
this.address = address; | ||
this.fiatPrice = fiatPrice; | ||
this.fiatChange = fiatChange; | ||
} | ||
|
||
protected static BigDecimal getFiatChange(String fiatChangeStr) | ||
{ | ||
if (TextUtils.isEmpty(fiatChangeStr)) return BigDecimal.ZERO; | ||
|
||
try | ||
{ | ||
return new BigDecimal(fiatChangeStr); | ||
} | ||
catch (Exception e) | ||
{ | ||
return BigDecimal.ZERO; | ||
} | ||
} | ||
|
||
public TokenTicker toTokenTicker(String currentCurrencySymbolTxt) | ||
{ | ||
return new TokenTicker(String.valueOf(fiatPrice), | ||
fiatChange.setScale(3, RoundingMode.DOWN).toString(), currentCurrencySymbolTxt, "", System.currentTimeMillis()); | ||
} | ||
|
||
public TokenTicker toTokenTicker(String currentCurrencySymbolTxt, double conversionRate) | ||
{ | ||
return new TokenTicker(String.valueOf(fiatPrice * conversionRate), | ||
fiatChange.setScale(3, RoundingMode.DOWN).toString(), currentCurrencySymbolTxt, "", System.currentTimeMillis()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/alphawallet/app/entity/ticker/TNDiscoveryTicker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.alphawallet.app.entity.ticker; | ||
|
||
|
||
import com.alphawallet.app.entity.tokendata.TokenTicker; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Map; | ||
|
||
public class TNDiscoveryTicker extends BaseTicker | ||
{ | ||
public TNDiscoveryTicker(String address, double fiatPrice, BigDecimal fiatChange) | ||
{ | ||
super(address, fiatPrice, fiatChange); | ||
} | ||
|
||
public TNDiscoveryTicker(JSONObject result, String address) throws JSONException | ||
{ | ||
super(address, result.getDouble("usdPrice"), getFiatChange(result.getString("24hrPercentChange"))); | ||
} | ||
|
||
public static void toTokenTickers(Map<String, TokenTicker> tickers, JSONArray result, String currentCurrencySymbolTxt, double currentConversionRate) throws JSONException | ||
{ | ||
for (int i = 0; i < result.length(); i++) | ||
{ | ||
JSONObject thisTickerObject = result.getJSONObject(i); | ||
TNDiscoveryTicker thisTicker = new TNDiscoveryTicker(thisTickerObject, thisTickerObject.getString("contract")); | ||
tickers.put(thisTickerObject.getString("contract"), thisTicker.toTokenTicker(currentCurrencySymbolTxt, currentConversionRate)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.