From b42b2e27cea247ccb82fea63762f084729a0eb0d Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 29 Apr 2018 21:50:15 -0400 Subject: [PATCH] Added receive transaction notification --- .../apigenerator/GrapheneApiGenerator.java | 17 +++++++----- .../ReceivedFundsCryptoNetEvent.java | 26 +++++++++++++++++-- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java index 3312030..1e3e618 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -22,6 +22,8 @@ import cy.agorise.crystalwallet.models.CryptoCurrency; import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence; import cy.agorise.crystalwallet.network.CryptoNetManager; import cy.agorise.crystalwallet.network.WebSocketThread; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetEvents; +import cy.agorise.crystalwallet.requestmanagers.ReceivedFundsCryptoNetEvent; import cy.agorise.graphenej.Address; import cy.agorise.graphenej.Asset; import cy.agorise.graphenej.AssetAmount; @@ -383,7 +385,7 @@ public abstract class GrapheneApiGenerator { info.setCryptoCurrencyId(idCryptoCurrency); asset.setId((int)idCryptoCurrency); bitsharesAssetDao.insertBitsharesAssetInfo(info); - saveTransaction(transaction,(int)info.getCryptoCurrencyId(),accountBitsharesId,tOperation,context); + saveTransaction(transaction,cryptoCurrencyDao.getById(info.getCryptoCurrencyId()),accountBitsharesId,tOperation,context); } } @@ -396,7 +398,7 @@ public abstract class GrapheneApiGenerator { assets.add(tOperation.getAssetAmount().getAsset().getObjectId()); GrapheneApiGenerator.getAssetById(assets,assetRequest); }else{ - saveTransaction(transaction,(int)info.getCryptoCurrencyId(),accountBitsharesId,tOperation,context); + saveTransaction(transaction,cryptoCurrencyDao.getById(info.getCryptoCurrencyId()),accountBitsharesId,tOperation,context); } } } @@ -420,23 +422,26 @@ public abstract class GrapheneApiGenerator { } /** - * Fucniton to save a transaction retrieved from the update + * Function to save a transaction retrieved from the update * @param transaction The transaction db object - * @param currencyId The id of the currency on the database + * @param currency The currency of the transaccion * @param accountBitsharesId The id of the account in the bitshares network * @param tOperation The transfer operation fetched from the update * @param context The context of this app */ - private static void saveTransaction(CryptoCoinTransaction transaction, int currencyId, + private static void saveTransaction(CryptoCoinTransaction transaction, CryptoCurrency currency, String accountBitsharesId, TransferOperation tOperation , Context context){ - transaction.setIdCurrency(currencyId); + transaction.setIdCurrency((int)currency.getId()); transaction.setConfirmed(true); //graphene transaction are always confirmed transaction.setFrom(tOperation.getFrom().getObjectId()); transaction.setInput(!tOperation.getFrom().getObjectId().equals(accountBitsharesId)); transaction.setTo(tOperation.getTo().getObjectId()); transaction.setDate(new Date()); CrystalDatabase.getAppDatabase(context).transactionDao().insertTransaction(transaction); + if(transaction.getInput()){ + CryptoNetEvents.getInstance().fireEvent(new ReceivedFundsCryptoNetEvent(transaction.getAccount(),currency,transaction.getAmount())); + } } /** diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ReceivedFundsCryptoNetEvent.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ReceivedFundsCryptoNetEvent.java index ba24dc5..df1026e 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ReceivedFundsCryptoNetEvent.java +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ReceivedFundsCryptoNetEvent.java @@ -16,9 +16,15 @@ public class ReceivedFundsCryptoNetEvent extends CryptoNetEvent { private CryptoNetAccount account; - public ReceivedFundsCryptoNetEvent(CryptoCoin coin, CryptoNetAccount account) { - super(coin); + private CryptoCurrency currency; + + private long amount; + + public ReceivedFundsCryptoNetEvent(CryptoNetAccount account, CryptoCurrency currency, long amount) { + super(CryptoCoin.BITSHARES); this.account = account; + this.currency = currency; + this.amount = amount; } public CryptoNetAccount getAccount() { @@ -28,5 +34,21 @@ public class ReceivedFundsCryptoNetEvent extends CryptoNetEvent { public void setAccount(CryptoNetAccount account) { this.account = account; } + + public CryptoCurrency getCurrency() { + return currency; + } + + public void setCurrency(CryptoCurrency currency) { + this.currency = currency; + } + + public long getAmount() { + return amount; + } + + public void setAmount(long amount) { + this.amount = amount; + } }