switch to completeTransactions exposed method

This commit is contained in:
Gustavo Nunes 2017-04-24 22:51:52 -03:00 committed by Roman Volosovskyi
parent 8c262d0b07
commit 441ca66e96
4 changed files with 29 additions and 36 deletions

View File

@ -277,8 +277,8 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
} }
@ReactMethod @ReactMethod
public void completeTransaction(final String hash, final String password, final Callback callback) { public void completeTransactions(final String hashes, final String password, final Callback callback) {
Log.d(TAG, "completeTransaction"); Log.d(TAG, "completeTransactions");
if (!checkAvailability()) { if (!checkAvailability()) {
callback.invoke(false); callback.invoke(false);
return; return;
@ -287,8 +287,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
Thread thread = new Thread() { Thread thread = new Thread() {
@Override @Override
public void run() { public void run() {
String res = Statusgo.CompleteTransaction(hash, password); String res = Statusgo.CompleteTransactions(hashes, password);
callback.invoke(res); callback.invoke(res);
} }
}; };

View File

@ -249,21 +249,21 @@ RCT_EXPORT_METHOD(login:(NSString *)address
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#pragma mark - Complete Transaction #pragma mark - Complete Transactions
//////////////////////////////////////////////////////////////////// completeTransaction //////////////////////////////////////////////////////////////////// completeTransactions
RCT_EXPORT_METHOD(completeTransaction:(NSString *)hash RCT_EXPORT_METHOD(completeTransactions:(NSString *)hashes
password:(NSString *)password password:(NSString *)password
callback:(RCTResponseSenderBlock)callback) { callback:(RCTResponseSenderBlock)callback) {
#if DEBUG #if DEBUG
NSLog(@"CompleteTransaction() method called"); NSLog(@"CompleteTransactions() method called");
#endif #endif
char * result = CompleteTransaction((char *) [hash UTF8String], (char *) [password UTF8String]); char * result = CompleteTransactions((char *) [hashes UTF8String], (char *) [password UTF8String]);
callback(@[[NSString stringWithUTF8String: result]]); callback(@[[NSString stringWithUTF8String: result]]);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#pragma mark - Discard Transaction #pragma mark - Discard Transaction
//////////////////////////////////////////////////////////////////// completeTransaction //////////////////////////////////////////////////////////////////// discardTransaction
RCT_EXPORT_METHOD(discardTransaction:(NSString *)id) { RCT_EXPORT_METHOD(discardTransaction:(NSString *)id) {
#if DEBUG #if DEBUG
NSLog(@"DiscardTransaction() method called"); NSLog(@"DiscardTransaction() method called");

View File

@ -10,6 +10,9 @@
[status-im.i18n :as i] [status-im.i18n :as i]
[status-im.utils.platform :as p])) [status-im.utils.platform :as p]))
(defn cljs->json [data]
(.stringify js/JSON (clj->js data)))
;; if StatusModule is not initialized better to store ;; if StatusModule is not initialized better to store
;; calls and make them only when StatusModule is ready ;; calls and make them only when StatusModule is ready
;; this flag helps to handle this ;; this flag helps to handle this
@ -108,11 +111,11 @@
(when status (when status
(call-module #(.login status address password on-result)))) (call-module #(.login status address password on-result))))
(defn complete-transaction (defn complete-transactions
[hash password callback] [hashes password callback]
(log/debug :complete-transaction (boolean status) hash password) (log/debug :complete-transactions (boolean status) hashes password)
(when status (when status
(call-module #(.completeTransaction status (str hash) password callback)))) (call-module #(.completeTransactions status (cljs->json hashes) password callback))))
(defn discard-transaction (defn discard-transaction
[id] [id]
@ -124,9 +127,6 @@
(when status (when status
(call-module #(.parseJail status chat-id file callback)))) (call-module #(.parseJail status chat-id file callback))))
(defn cljs->json [data]
(.stringify js/JSON (clj->js data)))
(defn call-jail [chat-id path params callback] (defn call-jail [chat-id path params callback]
(when status (when status
(call-module (call-module

View File

@ -38,27 +38,22 @@
:wrong-password? false) :wrong-password? false)
(assoc-in [:confirm-transactions :password] ""))) (assoc-in [:confirm-transactions :password] "")))
(defn on-unlock (defn on-transactions-completed [raw-results]
[ids password] (let [results (:results (t/json->clj raw-results))]
(dispatch [:set :wrong-password? false]) (doseq [result results]
(doseq [id ids] (dispatch [:transaction-completed {:id (name (key result)) :response (second result)}]))))
(status/complete-transaction
id
password
#(dispatch [:transaction-completed
{:id id
:response %}]))))
(register-handler :accept-transactions (register-handler :accept-transactions
(u/side-effect! (u/side-effect!
(fn [{:keys [transactions]} [_ password]] (fn [{:keys [transactions]} [_ password]]
(let [ids (keys transactions)] (dispatch [:set :wrong-password? false])
(on-unlock ids password))))) (status/complete-transactions (keys transactions) password on-transactions-completed))))
(register-handler :accept-transaction (register-handler :accept-transaction
(u/side-effect! (u/side-effect!
(fn [{:keys [transactions]} [_ password id]] (fn [_ [_ password id]]
(on-unlock (list id) password)))) (dispatch [:set :wrong-password? false])
(status/complete-transactions (list id) password on-transactions-completed))))
(register-handler :deny-transactions (register-handler :deny-transactions
(u/side-effect! (u/side-effect!
@ -146,16 +141,15 @@
(register-handler :transaction-completed (register-handler :transaction-completed
(u/side-effect! (u/side-effect!
(fn [{:keys [transactions modal]} [_ {:keys [id response]}]] (fn [{:keys [transactions modal]} [_ {:keys [id response]}]]
(let [{:keys [hash error] :as parsed-response} (t/json->clj response) (let [{:keys [hash error]} response
{:keys [message-id]} (transactions id)] {:keys [message-id]} (transactions id)]
(log/debug :parsed-response parsed-response) (log/debug :parsed-response response)
(when-not (and error (string? error) (not (s/blank? error))) (when-not (and error (string? error) (not (s/blank? error)))
(if (and message-id (not (s/blank? message-id))) (if (and message-id (not (s/blank? message-id)))
(do (dispatch [::add-transactions-hash {:id id (do (dispatch [::add-transactions-hash {:id id
:hash hash :hash hash
:message-id message-id}]) :message-id message-id}])
(dispatch [::check-completed-transaction! (dispatch [::check-completed-transaction! {:message-id message-id}]))
{:message-id message-id}]))
(dispatch [::remove-transaction id])) (dispatch [::remove-transaction id]))
(when (#{:unsigned-transactions :transaction-details} modal) (when (#{:unsigned-transactions :transaction-details} modal)
(dispatch [:navigate-to-modal :confirmation-success]))))))) (dispatch [:navigate-to-modal :confirmation-success])))))))