2020
2121import net .khirr .library .foreground .Foreground ;
2222
23+ import io .multy .Multy ;
2324import io .multy .R ;
2425import io .multy .api .MultyApi ;
2526import io .multy .model .entities .wallet .Wallet ;
2627import io .multy .model .responses .SingleWalletResponse ;
27- import io .multy .storage .RealmManager ;
28+ import io .multy .storage .AssetsDao ;
2829import io .multy .ui .activities .AssetActivity ;
2930import io .multy .ui .activities .MainActivity ;
3031import io .multy .util .Constants ;
3132import io .multy .util .CryptoFormatUtils ;
3233import io .multy .util .NativeDataHelper ;
3334import io .multy .util .analytics .Analytics ;
3435import io .multy .util .analytics .AnalyticsConstants ;
36+ import io .realm .Realm ;
3537import retrofit2 .Call ;
3638import retrofit2 .Callback ;
3739import 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
0 commit comments