From 9ced0e4131277152d22125c2de9d615ff6f4bbcc Mon Sep 17 00:00:00 2001 From: flexsurfer Date: Fri, 13 Dec 2024 19:57:26 +0100 Subject: [PATCH] [#21708] [Android] Login with Keycard stucks on Preparing screen from time to time (#21811) --- package.json | 2 +- src/keycard/keycard.cljs | 4 ++++ src/status_im/contexts/keycard/effects.cljs | 4 +++- src/status_im/contexts/keycard/events.cljs | 25 ++++++++++----------- yarn.lock | 4 ++-- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 8270507531..9bd2a9b595 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "react-native-shake": "^3.3.1", "react-native-share": "10.0.2", "react-native-static-safe-area-insets": "^2.2.0", - "react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.6.3", + "react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.6.4", "react-native-svg": "13.10.0", "react-native-webview": "13.6.3", "react-syntax-highlighter": "^15.5.0" diff --git a/src/keycard/keycard.cljs b/src/keycard/keycard.cljs index 915974050a..d85e1e1e2b 100644 --- a/src/keycard/keycard.cljs +++ b/src/keycard/keycard.cljs @@ -71,6 +71,10 @@ [callback] (.addListener ^js event-emitter "keyCardOnDisconnected" callback)) +(defn on-card-new-pairing + [callback] + (.addListener ^js event-emitter "keyCardNewPairing" callback)) + (defn on-nfc-user-cancelled [callback] (.addListener ^js event-emitter "keyCardOnNFCUserCancelled" callback)) diff --git a/src/status_im/contexts/keycard/effects.cljs b/src/status_im/contexts/keycard/effects.cljs index 6c1d41f767..ed99065952 100644 --- a/src/status_im/contexts/keycard/effects.cljs +++ b/src/status_im/contexts/keycard/effects.cljs @@ -8,7 +8,8 @@ [status-im.contexts.keycard.utils :as keycard.utils] [status-im.contexts.profile.config :as profile.config] [utils.hex :as hex] - [utils.re-frame :as rf])) + [utils.re-frame :as rf] + [utils.transforms :as transforms])) (defonce ^:private active-listeners (atom [])) @@ -24,6 +25,7 @@ (reset! active-listeners [(keycard/on-card-connected #(rf/dispatch [:keycard/on-card-connected])) (keycard/on-card-disconnected #(rf/dispatch [:keycard/on-card-disconnected])) + (keycard/on-card-new-pairing #(rf/dispatch [:keycard/on-card-new-pairing (transforms/js->clj %)])) (when platform/ios? (keycard/on-nfc-user-cancelled #(rf/dispatch [:keycard.ios/on-nfc-user-cancelled]))) (when platform/ios? diff --git a/src/status_im/contexts/keycard/events.cljs b/src/status_im/contexts/keycard/events.cljs index 5d894b7f0d..1363365b0c 100644 --- a/src/status_im/contexts/keycard/events.cljs +++ b/src/status_im/contexts/keycard/events.cljs @@ -25,21 +25,22 @@ :fx [(when-let [event (get-in db [:keycard :on-card-disconnected-event-vector])] [:dispatch event])]})) +(rf/reg-event-fx :keycard/on-card-new-pairing + (fn [{:keys [db]} [{:keys [pairing instanceUID]}]] + (when (and instanceUID pairing) + (let [pairings (get-in db [:keycard :pairings]) + new-pairings (assoc pairings + instanceUID + {:pairing pairing + :paired-on (utils.datetime/timestamp)})] + {:db (assoc-in db [:keycard :pairings] new-pairings) + :keycard/persist-pairings new-pairings})))) + (rf/reg-event-fx :keycard/on-retrieve-pairings-success (fn [{:keys [db]} [pairings]] {:db (assoc-in db [:keycard :pairings] pairings) :fx [[:effects.keycard/set-pairing-to-keycard pairings]]})) -(rf/reg-event-fx :keycard/update-pairings - (fn [{:keys [db]} [instance-uid pairing]] - (let [pairings (get-in db [:keycard :pairings]) - new-pairings (assoc pairings - instance-uid - {:pairing pairing - :paired-on (utils.datetime/timestamp)})] - {:db (assoc-in db [:keycard :pairings] new-pairings) - :keycard/persist-pairings new-pairings}))) - (rf/reg-event-fx :keycard/on-action-with-pin-error (fn [{:keys [db]} [error]] (let [tag-was-lost? (keycard.utils/tag-lost? (:error error)) @@ -126,10 +127,8 @@ (rf/reg-event-fx :keycard/get-application-info (fn [_ [{:keys [key-uid on-success on-error]}]] {:effects.keycard/get-application-info - {:on-success (fn [{:keys [instance-uid new-pairing] :as app-info}] + {:on-success (fn [app-info] (rf/dispatch [:keycard/update-application-info app-info]) - (when (and instance-uid new-pairing) - (rf/dispatch [:keycard/update-pairings instance-uid new-pairing])) (if-let [error (keycard.utils/validate-application-info key-uid app-info)] (if on-error (on-error error) diff --git a/yarn.lock b/yarn.lock index 1b548194e5..cf03c3b7f5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9584,9 +9584,9 @@ react-native-static-safe-area-insets@^2.2.0: resolved "https://registry.yarnpkg.com/react-native-static-safe-area-insets/-/react-native-static-safe-area-insets-2.2.0.tgz#dd86b6a38f43964fac8df8c0e6bc8e062527786c" integrity sha512-TLTW2e2kRK3COSK8gMZzwp4wHguFCtcO18itDLn5av/xQblXt9ylu84o+qD9aKJCBfvtNzGOvqqTKqC5GJRZ/g== -"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.6.3": +"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.6.4": version "2.6.2" - resolved "git+https://github.com/status-im/react-native-status-keycard.git#735bed7f9838b87712f1fd2978208186d28ea61c" + resolved "git+https://github.com/status-im/react-native-status-keycard.git#e78f46de10d65cfef2df2f62b6f41e64e0c332b9" react-native-svg@13.10.0: version "13.10.0"