- Fixing inconsistent loading of transactions
This commit is contained in:
parent
d549e3af8d
commit
270f2d40b6
4 changed files with 66 additions and 28 deletions
|
@ -1,6 +1,7 @@
|
|||
package cy.agorise.crystalwallet.apigenerator;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
@ -380,10 +381,20 @@ public abstract class GrapheneApiGenerator {
|
|||
public void success(Object answer, int idPetition) {
|
||||
ArrayList<BitsharesAsset> assets = (ArrayList<BitsharesAsset>) answer;
|
||||
for(BitsharesAsset asset : assets){
|
||||
long idCryptoCurrency = cryptoCurrencyDao.insertCryptoCurrency(asset)[0];
|
||||
|
||||
long currencyId = -1;
|
||||
CryptoCurrency cryptoCurrencyDb = cryptoCurrencyDao.getByNameAndCryptoNet(((BitsharesAsset) answer).getName(),((BitsharesAsset) answer).getCryptoNet().name());
|
||||
|
||||
if (cryptoCurrencyDb != null){
|
||||
currencyId = cryptoCurrencyDb.getId();
|
||||
} else {
|
||||
long idCryptoCurrency = cryptoCurrencyDao.insertCryptoCurrency(asset)[0];
|
||||
currencyId = idCryptoCurrency;
|
||||
}
|
||||
|
||||
BitsharesAssetInfo info = new BitsharesAssetInfo(asset);
|
||||
info.setCryptoCurrencyId(idCryptoCurrency);
|
||||
asset.setId((int)idCryptoCurrency);
|
||||
info.setCryptoCurrencyId(currencyId);
|
||||
asset.setId((int)currencyId);
|
||||
bitsharesAssetDao.insertBitsharesAssetInfo(info);
|
||||
saveTransaction(transaction,cryptoCurrencyDao.getById(info.getCryptoCurrencyId()),accountBitsharesId,tOperation,context);
|
||||
}
|
||||
|
@ -484,10 +495,19 @@ public abstract class GrapheneApiGenerator {
|
|||
List<BitsharesAsset> assets = (List<BitsharesAsset>) answer;
|
||||
for(BitsharesAsset asset : assets) {
|
||||
BitsharesAssetInfo info = new BitsharesAssetInfo(asset);
|
||||
long[] cryptoCurrencyId = cryptoCurrencyDao.insertCryptoCurrency((CryptoCurrency) asset);
|
||||
info.setCryptoCurrencyId(cryptoCurrencyId[0]);
|
||||
|
||||
long currencyId = -1;
|
||||
CryptoCurrency cryptoCurrencyDb = cryptoCurrencyDao.getByNameAndCryptoNet(asset.getName(),asset.getCryptoNet().name());
|
||||
|
||||
if (cryptoCurrencyDb != null){
|
||||
currencyId = cryptoCurrencyDb.getId();
|
||||
} else {
|
||||
long[] cryptoCurrencyId = cryptoCurrencyDao.insertCryptoCurrency((CryptoCurrency) asset);
|
||||
currencyId = cryptoCurrencyId[0];
|
||||
}
|
||||
info.setCryptoCurrencyId(currencyId);
|
||||
bitsharesAssetDao.insertBitsharesAssetInfo(info);
|
||||
ccBalance.setCryptoCurrencyId(cryptoCurrencyId[0]);
|
||||
ccBalance.setCryptoCurrencyId(currencyId);
|
||||
balanceDao.insertCryptoCoinBalance(ccBalance);
|
||||
}
|
||||
}
|
||||
|
@ -616,8 +636,18 @@ public abstract class GrapheneApiGenerator {
|
|||
public void success(Object answer, int idPetition) {
|
||||
if(answer instanceof BitsharesAsset){
|
||||
BitsharesAssetInfo info = new BitsharesAssetInfo((BitsharesAsset) answer);
|
||||
long cryptoCurrencyId = cryptoCurrencyDao.insertCryptoCurrency((CryptoCurrency)answer )[0];
|
||||
info.setCryptoCurrencyId(cryptoCurrencyId);
|
||||
|
||||
long currencyId = -1;
|
||||
CryptoCurrency cryptoCurrencyDb = cryptoCurrencyDao.getByNameAndCryptoNet(((BitsharesAsset) answer).getName(),((BitsharesAsset) answer).getCryptoNet().name());
|
||||
|
||||
if (cryptoCurrencyDb != null){
|
||||
currencyId = cryptoCurrencyDb.getId();
|
||||
} else {
|
||||
long cryptoCurrencyId = cryptoCurrencyDao.insertCryptoCurrency((CryptoCurrency)answer )[0];
|
||||
currencyId = cryptoCurrencyId;
|
||||
}
|
||||
|
||||
info.setCryptoCurrencyId(currencyId);
|
||||
bitsharesAssetDao.insertBitsharesAssetInfo(info);
|
||||
GrapheneApiGenerator.getEquivalentValue((BitsharesAsset) answer, quoteAssets, context);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,6 @@ public interface BitsharesAssetDao {
|
|||
@Query("SELECT * FROM bitshares_asset WHERE bitshares_id = :bitsharesId")
|
||||
BitsharesAssetInfo getBitsharesAssetInfoById(String bitsharesId);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
public long[] insertBitsharesAssetInfo(BitsharesAssetInfo... accounts);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public interface CryptoCurrencyDao {
|
|||
@Query("SELECT * FROM crypto_currency WHERE name = :name")
|
||||
CryptoCurrency getByName(String name);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
public long[] insertCryptoCurrency(CryptoCurrency... currencies);
|
||||
|
||||
}
|
||||
|
|
|
@ -333,23 +333,21 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
|||
GrapheneAccount account = new GrapheneAccount();
|
||||
account.setName(createRequest.getAccountName());
|
||||
account.setSeedId(idSeed);
|
||||
account.setAccountIndex(0);
|
||||
account.setCryptoNet(CryptoNet.BITSHARES);
|
||||
this.createAccountFromSeed(account, new ManagerRequest() {
|
||||
|
||||
@Override
|
||||
public void success(Object answer) {
|
||||
createRequest.setAccount((GrapheneAccount) answer);
|
||||
createRequest.setStatus(ValidateCreateBitsharesAccountRequest.StatusCode.SUCCEEDED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail() {
|
||||
createRequest.setStatus(ValidateCreateBitsharesAccountRequest.StatusCode.ACCOUNT_EXIST);
|
||||
}
|
||||
}, context);
|
||||
account.setAccountIndex(0);
|
||||
account.setCryptoNet(CryptoNet.BITSHARES);
|
||||
this.createAccountFromSeed(account, new ManagerRequest() {
|
||||
|
||||
@Override
|
||||
public void success(Object answer) {
|
||||
createRequest.setAccount((GrapheneAccount) answer);
|
||||
createRequest.setStatus(ValidateCreateBitsharesAccountRequest.StatusCode.SUCCEEDED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail() {
|
||||
createRequest.setStatus(ValidateCreateBitsharesAccountRequest.StatusCode.ACCOUNT_EXIST);
|
||||
}
|
||||
}, context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -681,10 +679,20 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
|||
public void success(Object answer, int idPetition) {
|
||||
ArrayList<BitsharesAsset> assets = (ArrayList<BitsharesAsset>) answer;
|
||||
for(BitsharesAsset asset : assets){
|
||||
long idCryptoCurrency = db.cryptoCurrencyDao().insertCryptoCurrency(asset)[0];
|
||||
long currencyId = -1;
|
||||
CryptoCurrency cryptoCurrencyDb = db.cryptoCurrencyDao().getByNameAndCryptoNet(asset.getName(),asset.getCryptoNet().name());
|
||||
|
||||
if (cryptoCurrencyDb != null){
|
||||
currencyId = cryptoCurrencyDb.getId();
|
||||
} else {
|
||||
long idCryptoCurrency = db.cryptoCurrencyDao().insertCryptoCurrency(asset)[0];
|
||||
currencyId = idCryptoCurrency;
|
||||
}
|
||||
|
||||
|
||||
BitsharesAssetInfo info = new BitsharesAssetInfo(asset);
|
||||
info.setCryptoCurrencyId(idCryptoCurrency);
|
||||
asset.setId((int)idCryptoCurrency);
|
||||
info.setCryptoCurrencyId(currencyId);
|
||||
asset.setId((int)currencyId);
|
||||
db.bitsharesAssetDao().insertBitsharesAssetInfo(info);
|
||||
saveTransaction(transaction,info,transfer);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue