Equivalent Value in services
This commit is contained in:
parent
3005b60935
commit
322ffed6b9
4 changed files with 108 additions and 2 deletions
|
@ -1,6 +1,5 @@
|
||||||
package cy.agorise.crystalwallet.apigenerator;
|
package cy.agorise.crystalwallet.apigenerator;
|
||||||
|
|
||||||
import android.arch.lifecycle.LiveData;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -21,6 +20,8 @@ import cy.agorise.crystalwallet.network.WebSocketThread;
|
||||||
import cy.agorise.graphenej.Address;
|
import cy.agorise.graphenej.Address;
|
||||||
import cy.agorise.graphenej.Asset;
|
import cy.agorise.graphenej.Asset;
|
||||||
import cy.agorise.graphenej.AssetAmount;
|
import cy.agorise.graphenej.AssetAmount;
|
||||||
|
import cy.agorise.graphenej.Converter;
|
||||||
|
import cy.agorise.graphenej.LimitOrder;
|
||||||
import cy.agorise.graphenej.ObjectType;
|
import cy.agorise.graphenej.ObjectType;
|
||||||
import cy.agorise.graphenej.Transaction;
|
import cy.agorise.graphenej.Transaction;
|
||||||
import cy.agorise.graphenej.UserAccount;
|
import cy.agorise.graphenej.UserAccount;
|
||||||
|
@ -29,6 +30,8 @@ import cy.agorise.graphenej.api.GetAccountByName;
|
||||||
import cy.agorise.graphenej.api.GetAccounts;
|
import cy.agorise.graphenej.api.GetAccounts;
|
||||||
import cy.agorise.graphenej.api.GetBlockHeader;
|
import cy.agorise.graphenej.api.GetBlockHeader;
|
||||||
import cy.agorise.graphenej.api.GetKeyReferences;
|
import cy.agorise.graphenej.api.GetKeyReferences;
|
||||||
|
import cy.agorise.graphenej.api.GetLimitOrders;
|
||||||
|
import cy.agorise.graphenej.api.GetMarketHistory;
|
||||||
import cy.agorise.graphenej.api.GetRelativeAccountHistory;
|
import cy.agorise.graphenej.api.GetRelativeAccountHistory;
|
||||||
import cy.agorise.graphenej.api.ListAssets;
|
import cy.agorise.graphenej.api.ListAssets;
|
||||||
import cy.agorise.graphenej.api.LookupAssetSymbols;
|
import cy.agorise.graphenej.api.LookupAssetSymbols;
|
||||||
|
@ -455,4 +458,25 @@ public abstract class GrapheneApiGenerator {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void getEquivalentValue(String baseId, String quoteId, final ApiRequest request){
|
||||||
|
WebSocketThread thread = new WebSocketThread(new GetLimitOrders(baseId, quoteId, 100, new WitnessResponseListener() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(WitnessResponse response) {
|
||||||
|
List<LimitOrder> orders = (List<LimitOrder>) response.result;
|
||||||
|
for(LimitOrder order : orders){
|
||||||
|
Converter converter = new Converter();
|
||||||
|
double equiValue = converter.getConversionRate(order.getSellPrice(),Converter.BASE_TO_QUOTE);
|
||||||
|
request.getListener().success(equiValue,request.getId());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(BaseResponse.Error error) {
|
||||||
|
request.getListener().fail(request.getId());
|
||||||
|
}
|
||||||
|
}),url);
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package cy.agorise.crystalwallet.cryptonetinforequests;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import cy.agorise.crystalwallet.enums.CryptoCoin;
|
||||||
|
import cy.agorise.crystalwallet.models.CryptoCurrency;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by henry on 6/11/2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class CryptoNetEquivalentRequest extends CryptoNetInfoRequest {
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
private CryptoCurrency fromCurrency;
|
||||||
|
private CryptoCurrency toCurrency;
|
||||||
|
private long price = -1;
|
||||||
|
|
||||||
|
public CryptoNetEquivalentRequest(CryptoCoin coin, Context context, CryptoCurrency fromCurrency, CryptoCurrency toCurrency) {
|
||||||
|
super(coin);
|
||||||
|
this.context = context;
|
||||||
|
this.fromCurrency = fromCurrency;
|
||||||
|
this.toCurrency = toCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Context getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContext(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CryptoCurrency getFromCurrency() {
|
||||||
|
return fromCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFromCurrency(CryptoCurrency fromCurrency) {
|
||||||
|
this.fromCurrency = fromCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CryptoCurrency getToCurrency() {
|
||||||
|
return toCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToCurrency(CryptoCurrency toCurrency) {
|
||||||
|
this.toCurrency = toCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrice(long price) {
|
||||||
|
this.price = price;
|
||||||
|
this._fireOnCarryOutEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import cy.agorise.crystalwallet.apigenerator.ApiRequest;
|
||||||
import cy.agorise.crystalwallet.apigenerator.ApiRequestListener;
|
import cy.agorise.crystalwallet.apigenerator.ApiRequestListener;
|
||||||
import cy.agorise.crystalwallet.apigenerator.BitsharesFaucetApiGenerator;
|
import cy.agorise.crystalwallet.apigenerator.BitsharesFaucetApiGenerator;
|
||||||
import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator;
|
import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator;
|
||||||
|
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetEquivalentRequest;
|
||||||
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequest;
|
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequest;
|
||||||
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestsListener;
|
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestsListener;
|
||||||
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest;
|
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest;
|
||||||
|
@ -166,6 +167,10 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
this.validateExistAcccount((ValidateExistBitsharesAccountRequest) request);
|
this.validateExistAcccount((ValidateExistBitsharesAccountRequest) request);
|
||||||
} else if (request instanceof ValidateBitsharesSendRequest){
|
} else if (request instanceof ValidateBitsharesSendRequest){
|
||||||
this.validateSendRequest((ValidateBitsharesSendRequest) request);
|
this.validateSendRequest((ValidateBitsharesSendRequest) request);
|
||||||
|
}else if (request instanceof CryptoNetEquivalentRequest){
|
||||||
|
this.getEquivalentValue((CryptoNetEquivalentRequest) request);
|
||||||
|
}else{
|
||||||
|
//TODO not implemented
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +310,6 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void refreshAccountTransactions(long idAccount, Context context){
|
public static void refreshAccountTransactions(long idAccount, Context context){
|
||||||
System.out.println("Call refresh Account transactions from " + idAccount);
|
|
||||||
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
|
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
|
||||||
List<CryptoCoinTransaction> transactions = db.transactionDao().getByIdAccount(idAccount);
|
List<CryptoCoinTransaction> transactions = db.transactionDao().getByIdAccount(idAccount);
|
||||||
CryptoNetAccount account = db.cryptoNetAccountDao().getById(idAccount);
|
CryptoNetAccount account = db.cryptoNetAccountDao().getById(idAccount);
|
||||||
|
@ -410,6 +414,27 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void getEquivalentValue(final CryptoNetEquivalentRequest request){
|
||||||
|
if(request.getFromCurrency() instanceof BitsharesAsset && request.getToCurrency() instanceof BitsharesAsset) {
|
||||||
|
BitsharesAsset fromAsset = (BitsharesAsset) request.getFromCurrency();
|
||||||
|
BitsharesAsset toAsset = (BitsharesAsset) request.getToCurrency();
|
||||||
|
ApiRequest getEquivalentRequest = new ApiRequest(0, new ApiRequestListener() {
|
||||||
|
@Override
|
||||||
|
public void success(Object answer, int idPetition) {
|
||||||
|
request.setPrice((Long)answer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fail(int idPetition) {
|
||||||
|
//TODO error
|
||||||
|
}
|
||||||
|
});
|
||||||
|
GrapheneApiGenerator.getEquivalentValue(fromAsset.getBitsharesId(),toAsset.getBitsharesId(), getEquivalentRequest);
|
||||||
|
}else{
|
||||||
|
//TODO error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class AccountIdOrNameListener implements ApiRequestListener{
|
private class AccountIdOrNameListener implements ApiRequestListener{
|
||||||
Object SYNC;
|
Object SYNC;
|
||||||
boolean ready = false;
|
boolean ready = false;
|
||||||
|
|
|
@ -33,4 +33,6 @@ public interface CryptoAccountManager {
|
||||||
* @param account The CryptoNetAccount to be loaded
|
* @param account The CryptoNetAccount to be loaded
|
||||||
*/
|
*/
|
||||||
public void loadAccountFromDB(CryptoNetAccount account, Context context);
|
public void loadAccountFromDB(CryptoNetAccount account, Context context);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue