Merge pull request #403 from status-im/feature/discard-tx
Add discardTransaction method to react-native-status module
Former-commit-id: 255040e304
This commit is contained in:
commit
65db1a3347
|
@ -14,5 +14,5 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.facebook.react:react-native:+'
|
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){
|
public void initJail(String callbackIdentifier, String js){
|
||||||
|
|
||||||
if (checkBound()) {
|
if (checkBound()) {
|
||||||
|
|
|
@ -54,6 +54,9 @@ public class StatusMessages {
|
||||||
*/
|
*/
|
||||||
public static final int MSG_JAIL_CALL = 10;
|
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);
|
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
|
// Jail
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
|
|
|
@ -125,6 +125,10 @@ public class StatusService extends Service {
|
||||||
completeTransaction(message);
|
completeTransaction(message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case StatusMessages.MSG_DISCARD_TRANSACTION:
|
||||||
|
discardTransaction(message);
|
||||||
|
break;
|
||||||
|
|
||||||
case StatusMessages.MSG_JAIL_INIT:
|
case StatusMessages.MSG_JAIL_INIT:
|
||||||
initJail(message);
|
initJail(message);
|
||||||
break;
|
break;
|
||||||
|
@ -220,9 +224,6 @@ public class StatusService extends Service {
|
||||||
Bundle replyData = new Bundle();
|
Bundle replyData = new Bundle();
|
||||||
replyData.putString("data", result);
|
replyData.putString("data", result);
|
||||||
createAndSendReply(message, StatusMessages.MSG_LOGIN, replyData);
|
createAndSendReply(message, StatusMessages.MSG_LOGIN, replyData);
|
||||||
|
|
||||||
// Test signalEvent
|
|
||||||
//signalEvent("{ \"type\": \"test\", \"event\": \"test event\" }");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void completeTransaction(Message message){
|
private void completeTransaction(Message message){
|
||||||
|
@ -240,6 +241,16 @@ public class StatusService extends Service {
|
||||||
createAndSendReply(message, StatusMessages.MSG_COMPLETE_TRANSACTION, replyData);
|
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){
|
private void initJail(Message message){
|
||||||
|
|
||||||
Bundle data = message.getData();
|
Bundle data = message.getData();
|
||||||
|
|
|
@ -144,7 +144,7 @@ RCT_EXPORT_METHOD(login:(NSString *)address
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
#pragma mark - Transaction
|
#pragma mark - Complete Transaction
|
||||||
//////////////////////////////////////////////////////////////////// completeTransaction
|
//////////////////////////////////////////////////////////////////// completeTransaction
|
||||||
RCT_EXPORT_METHOD(completeTransaction:(NSString *)hash
|
RCT_EXPORT_METHOD(completeTransaction:(NSString *)hash
|
||||||
password:(NSString *)password
|
password:(NSString *)password
|
||||||
|
@ -156,6 +156,16 @@ RCT_EXPORT_METHOD(completeTransaction:(NSString *)hash
|
||||||
callback(@[[NSString stringWithUTF8String: result]]);
|
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
|
#pragma mark - only android methods
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
<artifactItems>
|
<artifactItems>
|
||||||
<artifactItem>
|
<artifactItem>
|
||||||
<groupId>status-im</groupId>
|
<groupId>status-im</groupId>
|
||||||
<artifactId>status-go-ios</artifactId>
|
<artifactId>status-go-ios-simulator</artifactId>
|
||||||
<version>tx-complete-updates-3</version>
|
<version>tx-discard</version>
|
||||||
<type>zip</type>
|
<type>zip</type>
|
||||||
<overWrite>true</overWrite>
|
<overWrite>true</overWrite>
|
||||||
<outputDirectory>./</outputDirectory>
|
<outputDirectory>./</outputDirectory>
|
||||||
|
|
|
@ -76,6 +76,12 @@
|
||||||
(when status
|
(when status
|
||||||
(call-module #(.completeTransaction status hash password callback))))
|
(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]
|
(defn parse-jail [chat-id file callback]
|
||||||
(when status
|
(when status
|
||||||
(call-module #(.parseJail status chat-id file callback))))
|
(call-module #(.parseJail status chat-id file callback))))
|
||||||
|
|
|
@ -56,6 +56,8 @@
|
||||||
ids (map :id transactions')]
|
ids (map :id transactions')]
|
||||||
(dispatch [::remove-pending-messages messages-ids])
|
(dispatch [::remove-pending-messages messages-ids])
|
||||||
(dispatch [::remove-transactions ids])
|
(dispatch [::remove-transactions ids])
|
||||||
|
(doseq [id ids]
|
||||||
|
(dispatch [::discard-transaction id]))
|
||||||
(dispatch [:navigate-back])))))
|
(dispatch [:navigate-back])))))
|
||||||
|
|
||||||
(register-handler :deny-transaction
|
(register-handler :deny-transaction
|
||||||
|
@ -64,7 +66,13 @@
|
||||||
(let [{:keys [message-id] :as transaction} (get transactions id)]
|
(let [{:keys [message-id] :as transaction} (get transactions id)]
|
||||||
(when transaction
|
(when transaction
|
||||||
(dispatch [::remove-pending-message message-id])
|
(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
|
(register-handler ::remove-transactions
|
||||||
(fn [db [_ hashes]]
|
(fn [db [_ hashes]]
|
||||||
|
@ -173,15 +181,22 @@
|
||||||
(dispatch [::remove-transaction id]))))))
|
(dispatch [::remove-transaction id]))))))
|
||||||
|
|
||||||
(def wrong-password-code "2")
|
(def wrong-password-code "2")
|
||||||
|
(def discard-code "4")
|
||||||
|
|
||||||
(register-handler :transaction-failed
|
(register-handler :transaction-failed
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [_ [_ {:keys [id message_id error_code]}]]
|
(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
|
(do (when message_id
|
||||||
(dispatch [::remove-pending-message message_id]))
|
(dispatch [::remove-pending-message message_id]))
|
||||||
(dispatch [::remove-transaction id]))
|
(dispatch [::remove-transaction id]))
|
||||||
(dispatch [:set-wrong-password!])))))
|
|
||||||
|
:else nil))))
|
||||||
|
|
||||||
(def attempts-limit 3)
|
(def attempts-limit 3)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue