Skip to content

Commit 237d20b

Browse files
authored
Merge pull request #32 from Anschutz1927/bugfix
open missing transactions
2 parents 284d310 + c2b0eb9 commit 237d20b

File tree

3 files changed

+50
-26
lines changed

3 files changed

+50
-26
lines changed

app/src/main/java/io/multy/fcm/MultyFirebaseMessagingService.java

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@
2020

2121
import net.khirr.library.foreground.Foreground;
2222

23+
import io.multy.Multy;
2324
import io.multy.R;
2425
import io.multy.api.MultyApi;
2526
import io.multy.model.entities.wallet.Wallet;
2627
import io.multy.model.responses.SingleWalletResponse;
27-
import io.multy.storage.RealmManager;
28+
import io.multy.storage.AssetsDao;
2829
import io.multy.ui.activities.AssetActivity;
2930
import io.multy.ui.activities.MainActivity;
3031
import io.multy.util.Constants;
3132
import io.multy.util.CryptoFormatUtils;
3233
import io.multy.util.NativeDataHelper;
3334
import io.multy.util.analytics.Analytics;
3435
import io.multy.util.analytics.AnalyticsConstants;
36+
import io.realm.Realm;
3537
import retrofit2.Call;
3638
import retrofit2.Callback;
3739
import retrofit2.Response;
@@ -56,25 +58,31 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
5658
MultyApi.INSTANCE.getWalletVerbose(walletIndex, currencyId, networkId).enqueue(new Callback<SingleWalletResponse>() {
5759
@Override
5860
public void onResponse(Call<SingleWalletResponse> call, Response<SingleWalletResponse> response) {
59-
if (response.isSuccessful() && response.body().getWallets() != null) {
60-
RealmManager.getAssetsDao().saveWallet(response.body().getWallets().get(0));
61-
String amount = "";
62-
switch (NativeDataHelper.Blockchain.valueOf(currencyId)) {
63-
case BTC:
64-
amount = CryptoFormatUtils.satoshiToBtcLabel(Long.parseLong(remoteMessage.getData().get(KEY_AMOUNT)));
65-
break;
66-
case ETH:
67-
amount = CryptoFormatUtils.weiToEthLabel(remoteMessage.getData().get(KEY_AMOUNT));
68-
break;
61+
Realm realm = Realm.getInstance(Multy.getRealmConfiguration());
62+
try {
63+
if (response.isSuccessful() && response.body().getWallets() != null) {
64+
AssetsDao dao = new AssetsDao(realm);
65+
dao.saveWallet(response.body().getWallets().get(0));
66+
String amount = "";
67+
switch (NativeDataHelper.Blockchain.valueOf(currencyId)) {
68+
case BTC:
69+
amount = CryptoFormatUtils.satoshiToBtcLabel(Long.parseLong(remoteMessage.getData().get(KEY_AMOUNT)));
70+
break;
71+
case ETH:
72+
amount = CryptoFormatUtils.weiToEthLabel(remoteMessage.getData().get(KEY_AMOUNT));
73+
break;
74+
}
75+
final String notification = String.format(getString(R.string.push_new_transaction_notification), amount);
76+
Wallet wallet = dao.getWallet(currencyId, networkId, walletIndex);
77+
final String txHash = remoteMessage.getData().get(KEY_TX_HASH);
78+
sendNotification(notification, wallet.getId(), txHash);
79+
} else {
80+
Log.e(TAG, "get wallet verbose error. walletId = " + String.valueOf(walletIndex) +
81+
", currencyId = " + String.valueOf(currencyId) +
82+
", networkId = " + String.valueOf(networkId));
6983
}
70-
final String notification = String.format(getString(R.string.push_new_transaction_notification), amount);
71-
Wallet wallet = RealmManager.getAssetsDao().getWallet(currencyId, networkId, walletIndex);
72-
final String txHash = remoteMessage.getData().get(KEY_TX_HASH);
73-
sendNotification(notification, wallet.getId(), txHash);
74-
} else {
75-
Log.e(TAG, "get wallet verbose error. walletId = " + String.valueOf(walletIndex) +
76-
", currencyId = " + String.valueOf(currencyId) +
77-
", networkId = " + String.valueOf(networkId));
84+
} finally {
85+
realm.close();
7886
}
7987
}
8088

app/src/main/java/io/multy/ui/fragments/asset/EthTransactionInfoFragment.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package io.multy.ui.fragments.asset;
88

99
import android.arch.lifecycle.ViewModelProviders;
10+
import android.content.Intent;
1011
import android.os.Bundle;
1112
import android.support.annotation.NonNull;
1213
import android.support.annotation.Nullable;
@@ -28,6 +29,7 @@
2829
import io.multy.R;
2930
import io.multy.model.entities.TransactionHistory;
3031
import io.multy.model.entities.wallet.Wallet;
32+
import io.multy.ui.activities.AssetActivity;
3133
import io.multy.ui.fragments.BaseFragment;
3234
import io.multy.ui.fragments.WebFragment;
3335
import io.multy.ui.fragments.dialogs.AddressActionsDialogFragment;
@@ -170,22 +172,28 @@ private void onTransactions(List<TransactionHistory> transactionHistories) {
170172
return;
171173
}
172174
if (selectedPosition == TransactionInfoFragment.NO_POSITION) {
173-
initTransactionFromHash(transactionHistories);
175+
if (!initTransactionFromHash(transactionHistories)) {
176+
getActivity().finish();
177+
startActivity(new Intent(getActivity(), AssetActivity.class)
178+
.putExtra(Constants.EXTRA_WALLET_ID, viewModel.getWalletLive().getValue().getId()));
179+
return;
180+
}
174181
} else {
175182
transaction = transactionHistories.get(selectedPosition);
176183
}
177184
setData();
178185
}
179186

180-
private void initTransactionFromHash(List<TransactionHistory> transactionHistories) {
187+
private boolean initTransactionFromHash(List<TransactionHistory> transactionHistories) {
181188
for (TransactionHistory transaction : transactionHistories) {
182189
if (transaction.getTxHash().equals(txHash)) {
183190
this.transaction = transaction;
184191
progress.setVisibility(View.GONE);
185192
groupDataViews.setVisibility(View.VISIBLE);
186-
break;
193+
return true;
187194
}
188195
}
196+
return false;
189197
}
190198

191199
private void setData() {

app/src/main/java/io/multy/ui/fragments/asset/TransactionInfoFragment.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package io.multy.ui.fragments.asset;
88

99
import android.arch.lifecycle.ViewModelProviders;
10+
import android.content.Intent;
1011
import android.os.Bundle;
1112
import android.support.annotation.NonNull;
1213
import android.support.annotation.Nullable;
@@ -32,6 +33,7 @@
3233
import io.multy.model.entities.TransactionHistory;
3334
import io.multy.model.entities.wallet.Wallet;
3435
import io.multy.model.entities.wallet.WalletAddress;
36+
import io.multy.ui.activities.AssetActivity;
3537
import io.multy.ui.activities.BaseActivity;
3638
import io.multy.ui.adapters.TransactionAddressAdapter;
3739
import io.multy.ui.fragments.BaseFragment;
@@ -185,30 +187,36 @@ private void loadData() {
185187
private void loadTransactionHistory(final int currencyId, final int networkId, final int walletIndex) {
186188
this.networkId = networkId;
187189
viewModel.getTransactionsHistory(currencyId, networkId, walletIndex).observe(this, transactionHistories -> {
188-
if (transactionHistories == null || transactionHistories.size() == 0) {
190+
if (transactionHistories == null || transactionHistories.size() == 0 || getActivity() == null) {
189191
return;
190192
} else if (transaction != null) {
191193
setData();
192194
return;
193195
}
194196
if (selectedPosition == NO_POSITION) {
195-
initTransactionFromHash(transactionHistories);
197+
if (!initTransactionFromHash(transactionHistories)) {
198+
getActivity().finish();
199+
startActivity(new Intent(getActivity(), AssetActivity.class)
200+
.putExtra(Constants.EXTRA_WALLET_ID, viewModel.getWalletLive().getValue().getId()));
201+
return;
202+
}
196203
} else {
197204
transaction = transactionHistories.get(selectedPosition);
198205
}
199206
setData();
200207
});
201208
}
202209

203-
private void initTransactionFromHash(List<TransactionHistory> transactionHistories) {
210+
private boolean initTransactionFromHash(List<TransactionHistory> transactionHistories) {
204211
for (TransactionHistory transaction : transactionHistories) {
205212
if (transaction.getTxId().equals(txid)) {
206213
this.transaction = transaction;
207214
progress.setVisibility(View.GONE);
208215
groupDataViews.setVisibility(View.VISIBLE);
209-
break;
216+
return true;
210217
}
211218
}
219+
return false;
212220
}
213221

214222
private long getOutComingAmount(TransactionHistory transactionHistory, List<String> walletAddresses, double exchangeRate) {

0 commit comments

Comments
 (0)