From 8a50bd423bf454fb8e9c1de40a6ca76913fe1ce1 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 1 Nov 2016 18:08:16 +0200 Subject: [PATCH] add discardTransaction method to react-native-status module Former-commit-id: cf12c7951d2e706232657e2a9b3f26d000ca24cb --- .../react-native-status/android/build.gradle | 2 +- .../com/statusim/module/StatusConnector.java | 9 ++++++++ .../com/statusim/module/StatusMessages.java | 5 ++++- .../com/statusim/module/StatusModule.java | 12 +++++++++++ .../com/statusim/module/StatusService.java | 17 ++++++++++++--- .../ios/RCTStatus/RCTStatus.m | 12 ++++++++++- .../react-native-status/ios/RCTStatus/pom.xml | 4 ++-- src/status_im/components/status.cljs | 6 ++++++ src/status_im/transactions/handlers.cljs | 21 ++++++++++++++++--- 9 files changed, 77 insertions(+), 11 deletions(-) diff --git a/modules/react-native-status/android/build.gradle b/modules/react-native-status/android/build.gradle index 693742cdd0..7cbdccfdb2 100644 --- a/modules/react-native-status/android/build.gradle +++ b/modules/react-native-status/android/build.gradle @@ -14,5 +14,5 @@ android { dependencies { compile 'com.facebook.react:react-native:+' - compile(group: 'status-im', name: 'status-go', version: 'tx-complete-updates-3', ext: 'aar') + compile(group: 'status-im', name: 'status-go', version: 'tx-discard', ext: 'aar') } diff --git a/modules/react-native-status/android/src/main/java/com/statusim/module/StatusConnector.java b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusConnector.java index 23cd3f9171..14d821c3fb 100644 --- a/modules/react-native-status/android/src/main/java/com/statusim/module/StatusConnector.java +++ b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusConnector.java @@ -71,6 +71,15 @@ public class StatusConnector extends ServiceConnector { } } + public void discardTransaction(String id){ + + if (checkBound()) { + Bundle data = new Bundle(); + data.putString("id", id); + sendMessage(null, StatusMessages.MSG_DISCARD_TRANSACTION, data); + } + } + public void initJail(String callbackIdentifier, String js){ if (checkBound()) { diff --git a/modules/react-native-status/android/src/main/java/com/statusim/module/StatusMessages.java b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusMessages.java index 6365a45a20..36ec5473a7 100644 --- a/modules/react-native-status/android/src/main/java/com/statusim/module/StatusMessages.java +++ b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusMessages.java @@ -54,6 +54,9 @@ public class StatusMessages { */ public static final int MSG_JAIL_CALL = 10; - + /** + * Account discard transaction event + */ + public static final int MSG_DISCARD_TRANSACTION = 11; } diff --git a/modules/react-native-status/android/src/main/java/com/statusim/module/StatusModule.java b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusModule.java index 762b288092..d761d0da62 100644 --- a/modules/react-native-status/android/src/main/java/com/statusim/module/StatusModule.java +++ b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusModule.java @@ -205,6 +205,18 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL status.completeTransaction(callbackIdentifier, hash, password); } + + @ReactMethod + public void discardTransaction(String id) { + Log.d(TAG, "discardTransaction"); + if (!checkAvailability()) { + return; + } + + Log.d(TAG, "Discard transaction: " + id); + status.discardTransaction(id); + } + // Jail @ReactMethod diff --git a/modules/react-native-status/android/src/main/java/com/statusim/module/StatusService.java b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusService.java index c1c6e5c5b6..114db76ef5 100644 --- a/modules/react-native-status/android/src/main/java/com/statusim/module/StatusService.java +++ b/modules/react-native-status/android/src/main/java/com/statusim/module/StatusService.java @@ -125,6 +125,10 @@ public class StatusService extends Service { completeTransaction(message); break; + case StatusMessages.MSG_DISCARD_TRANSACTION: + discardTransaction(message); + break; + case StatusMessages.MSG_JAIL_INIT: initJail(message); break; @@ -220,9 +224,6 @@ public class StatusService extends Service { Bundle replyData = new Bundle(); replyData.putString("data", result); createAndSendReply(message, StatusMessages.MSG_LOGIN, replyData); - - // Test signalEvent - //signalEvent("{ \"type\": \"test\", \"event\": \"test event\" }"); } private void completeTransaction(Message message){ @@ -240,6 +241,16 @@ public class StatusService extends Service { createAndSendReply(message, StatusMessages.MSG_COMPLETE_TRANSACTION, replyData); } + private void discardTransaction(Message message){ + + Bundle data = message.getData(); + String id = data.getString("id"); + + Log.d(TAG, "Before DiscardTransaction: " + id); + String result = Statusgo.DiscardTransaction(id); + Log.d(TAG, "After DiscardTransaction: " + result); + } + private void initJail(Message message){ Bundle data = message.getData(); diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.m b/modules/react-native-status/ios/RCTStatus/RCTStatus.m index 86c7ea77cb..f78d422d05 100644 --- a/modules/react-native-status/ios/RCTStatus/RCTStatus.m +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.m @@ -144,7 +144,7 @@ RCT_EXPORT_METHOD(login:(NSString *)address } //////////////////////////////////////////////////////////////////// -#pragma mark - Transaction +#pragma mark - Complete Transaction //////////////////////////////////////////////////////////////////// completeTransaction RCT_EXPORT_METHOD(completeTransaction:(NSString *)hash password:(NSString *)password @@ -156,6 +156,16 @@ RCT_EXPORT_METHOD(completeTransaction:(NSString *)hash callback(@[[NSString stringWithUTF8String: result]]); } +//////////////////////////////////////////////////////////////////// +#pragma mark - Discard Transaction +//////////////////////////////////////////////////////////////////// completeTransaction +RCT_EXPORT_METHOD(discardTransaction:(NSString *)id) { +#if DEBUG + NSLog(@"DiscardTransaction() method called"); +#endif + DiscardTransaction((char *) [id UTF8String]); +} + //////////////////////////////////////////////////////////////////// #pragma mark - only android methods //////////////////////////////////////////////////////////////////// diff --git a/modules/react-native-status/ios/RCTStatus/pom.xml b/modules/react-native-status/ios/RCTStatus/pom.xml index 3469204d7d..c622c9f65d 100644 --- a/modules/react-native-status/ios/RCTStatus/pom.xml +++ b/modules/react-native-status/ios/RCTStatus/pom.xml @@ -24,8 +24,8 @@ status-im - status-go-ios - tx-complete-updates-3 + status-go-ios-simulator + tx-discard zip true ./ diff --git a/src/status_im/components/status.cljs b/src/status_im/components/status.cljs index e0923169d5..e6a44d9f01 100644 --- a/src/status_im/components/status.cljs +++ b/src/status_im/components/status.cljs @@ -76,6 +76,12 @@ (when status (call-module #(.completeTransaction status hash password callback)))) +(defn discard-transaction + [id] + (log/debug :discard-transaction id) + (when status + (call-module #(.discardTransaction status id)))) + (defn parse-jail [chat-id file callback] (when status (call-module #(.parseJail status chat-id file callback)))) diff --git a/src/status_im/transactions/handlers.cljs b/src/status_im/transactions/handlers.cljs index d60112aa36..24be4ea57f 100644 --- a/src/status_im/transactions/handlers.cljs +++ b/src/status_im/transactions/handlers.cljs @@ -56,6 +56,8 @@ ids (map :id transactions')] (dispatch [::remove-pending-messages messages-ids]) (dispatch [::remove-transactions ids]) + (doseq [id ids] + (dispatch [::discard-transaction id])) (dispatch [:navigate-back]))))) (register-handler :deny-transaction @@ -64,7 +66,13 @@ (let [{:keys [message-id] :as transaction} (get transactions id)] (when transaction (dispatch [::remove-pending-message message-id]) - (dispatch [::remove-transaction id])))))) + (dispatch [::remove-transaction id]) + (dispatch [::discard-transaction id])))))) + +(register-handler ::discard-transaction + (u/side-effect! + (fn [db [_ id]] + (status/discard-transaction id)))) (register-handler ::remove-transactions (fn [db [_ hashes]] @@ -173,15 +181,22 @@ (dispatch [::remove-transaction id])))))) (def wrong-password-code "2") +(def discard-code "4") (register-handler :transaction-failed (u/side-effect! (fn [_ [_ {:keys [id message_id error_code]}]] - (if-not (= wrong-password-code error_code) + (cond + + (= error_code wrong-password-code) + (dispatch [:set-wrong-password!]) + + (not= discard-code error_code) (do (when message_id (dispatch [::remove-pending-message message_id])) (dispatch [::remove-transaction id])) - (dispatch [:set-wrong-password!]))))) + + :else nil)))) (def attempts-limit 3)