Merge pull request #403 from status-im/feature/discard-tx
Add discardTransaction method to react-native-status module
This commit is contained in:
commit
255040e304
|
@ -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')
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>status-im</groupId>
|
||||
<artifactId>status-go-ios</artifactId>
|
||||
<version>tx-complete-updates-3</version>
|
||||
<artifactId>status-go-ios-simulator</artifactId>
|
||||
<version>tx-discard</version>
|
||||
<type>zip</type>
|
||||
<overWrite>true</overWrite>
|
||||
<outputDirectory>./</outputDirectory>
|
||||
|
|
|
@ -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))))
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue