From 4f95e0bcf4ee84d9601b40db521f7a322c1edab1 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 5 Mar 2020 15:20:16 +0200 Subject: [PATCH] [#10011] Listen to nfc state changes --- mobile/js_files/package.json | 2 +- mobile/js_files/yarn.lock | 4 ++-- src/status_im/hardwallet/card.cljs | 14 +++++++++++++- src/status_im/hardwallet/core.cljs | 9 ++------- src/status_im/ui/screens/events.cljs | 1 - 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/mobile/js_files/package.json b/mobile/js_files/package.json index dfa7572bc2..c0ba6aa56b 100644 --- a/mobile/js_files/package.json +++ b/mobile/js_files/package.json @@ -38,7 +38,7 @@ "react-native-screens": "^1.0.0-alpha.23", "react-native-shake": "^3.3.1", "react-native-splash-screen": "^3.2.0", - "react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.5.19", + "react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.5.20", "react-native-svg": "^9.8.4", "react-native-touch-id": "^4.4.1", "react-native-webview": "^6.11.1", diff --git a/mobile/js_files/yarn.lock b/mobile/js_files/yarn.lock index 88195162f5..64de98eb9e 100644 --- a/mobile/js_files/yarn.lock +++ b/mobile/js_files/yarn.lock @@ -4900,9 +4900,9 @@ react-native-splash-screen@^3.2.0: resolved "https://registry.yarnpkg.com/react-native-splash-screen/-/react-native-splash-screen-3.2.0.tgz#d47ec8557b1ba988ee3ea98d01463081b60fff45" integrity sha512-Ls9qiNZzW/OLFoI25wfjjAcrf2DZ975hn2vr6U9gyuxi2nooVbzQeFoQS5vQcbCt9QX5NY8ASEEAtlLdIa6KVg== -"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.5.19": +"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.5.20": version "2.5.17" - resolved "git+https://github.com/status-im/react-native-status-keycard.git#8fb12850d72918d3e89e4fcfc8fa699c2ce3f203" + resolved "git+https://github.com/status-im/react-native-status-keycard.git#38ca8597e26472f0d257467652544df084de6345" react-native-svg@^9.8.4: version "9.11.1" diff --git a/src/status_im/hardwallet/card.cljs b/src/status_im/hardwallet/card.cljs index 1a4fc44a6a..f77b455e3d 100644 --- a/src/status_im/hardwallet/card.cljs +++ b/src/status_im/hardwallet/card.cljs @@ -51,12 +51,24 @@ platform/android?) (.addListener event-emitter "keyCardOnDisconnected" callback))) +(defn on-nfc-enabled [callback] + (when (and config/hardwallet-enabled? + platform/android?) + (.addListener event-emitter "keyCardOnNFCEnabled" callback))) + +(defn on-nfc-disabled [callback] + (when (and config/hardwallet-enabled? + platform/android?) + (.addListener event-emitter "keyCardOnNFCDisabled" callback))) + (defn register-card-events [] (doseq [listener @active-listeners] (remove-event-listener listener)) (reset! active-listeners [(on-card-connected #(re-frame/dispatch [:hardwallet.callback/on-card-connected])) - (on-card-disconnected #(re-frame/dispatch [:hardwallet.callback/on-card-disconnected]))])) + (on-card-disconnected #(re-frame/dispatch [:hardwallet.callback/on-card-disconnected])) + (on-nfc-enabled #(re-frame/dispatch [:hardwallet.callback/check-nfc-enabled-success true])) + (on-nfc-disabled #(re-frame/dispatch [:hardwallet.callback/check-nfc-enabled-success false]))])) (defn get-application-info [{:keys [pairing on-success]}] (log/debug "[keycard] get-application-info") diff --git a/src/status_im/hardwallet/core.cljs b/src/status_im/hardwallet/core.cljs index cb87c3ab95..b91931b6fc 100644 --- a/src/status_im/hardwallet/core.cljs +++ b/src/status_im/hardwallet/core.cljs @@ -119,15 +119,10 @@ (fx/defn on-check-nfc-enabled-success {:events [:hardwallet.callback/check-nfc-enabled-success]} [{:keys [db]} nfc-enabled?] + (log/debug "[hardwallet] check-nfc-enabled-success" + "nfc-enabled?" nfc-enabled?) {:db (assoc-in db [:hardwallet :nfc-enabled?] nfc-enabled?)}) -(fx/defn return-back-from-nfc-settings [{:keys [db]}] - (when (or (get-in db [:hardwallet :flow]) - (get-in db [:hardwallet :pin :enter-step]) - (get-in db [:hardwallet :on-card-connected]) - (get-in db [:hardwallet :on-card-read])) - {:hardwallet/check-nfc-enabled nil})) - (defn- proceed-to-pin-confirmation [fx] (assoc-in fx [:db :hardwallet :pin :enter-step] :confirmation)) diff --git a/src/status_im/ui/screens/events.cljs b/src/status_im/ui/screens/events.cljs index d163ba6191..d54204f334 100644 --- a/src/status_im/ui/screens/events.cljs +++ b/src/status_im/ui/screens/events.cljs @@ -150,7 +150,6 @@ (dissoc :app-in-background-since) (assoc :app-active-since now))} (mailserver/process-next-messages-request) - (hardwallet/return-back-from-nfc-settings) #(when requires-bio-auth (biometric/authenticate % on-biometric-auth-result authentication-options)))))