This commit is contained in:
Javier Varona 2017-11-07 22:18:51 -04:00
commit 6dae8cb681
4 changed files with 108 additions and 2 deletions

View file

@ -1,6 +1,5 @@
package cy.agorise.crystalwallet.apigenerator;
import android.arch.lifecycle.LiveData;
import android.content.Context;
import java.io.Serializable;
@ -21,6 +20,8 @@ import cy.agorise.crystalwallet.network.WebSocketThread;
import cy.agorise.graphenej.Address;
import cy.agorise.graphenej.Asset;
import cy.agorise.graphenej.AssetAmount;
import cy.agorise.graphenej.Converter;
import cy.agorise.graphenej.LimitOrder;
import cy.agorise.graphenej.ObjectType;
import cy.agorise.graphenej.Transaction;
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.GetBlockHeader;
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.ListAssets;
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();
}
}

View file

@ -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();
}
}

View file

@ -19,6 +19,7 @@ import cy.agorise.crystalwallet.apigenerator.ApiRequest;
import cy.agorise.crystalwallet.apigenerator.ApiRequestListener;
import cy.agorise.crystalwallet.apigenerator.BitsharesFaucetApiGenerator;
import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator;
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetEquivalentRequest;
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequest;
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestsListener;
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest;
@ -166,6 +167,10 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
this.validateExistAcccount((ValidateExistBitsharesAccountRequest) request);
} else if (request instanceof ValidateBitsharesSendRequest){
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){
System.out.println("Call refresh Account transactions from " + idAccount);
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
List<CryptoCoinTransaction> transactions = db.transactionDao().getByIdAccount(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{
Object SYNC;
boolean ready = false;

View file

@ -33,4 +33,6 @@ public interface CryptoAccountManager {
* @param account The CryptoNetAccount to be loaded
*/
public void loadAccountFromDB(CryptoNetAccount account, Context context);
}