[#9446] Resume logging when connection to card is restored
Currently there are two ways to initiate logging in with keycard: - enter PIN code and after that connect card to the phone - connect card to the phone and enter PIN after that Before this commit in both cases when connection to the keyacrd was lost and then restored, logging in didn't resume. In result a user saw a pop-up with endless spinner. The reason of this bug was that `:on-card-connected` and `:on-card-read` actions were not restored in app-db after losing connection to the card. This commit introduces helper functions for both `:on-card-connected` and `:on-card-read` which allow to reset these values and stash them until particular flow of calls to keycard will be finished. In case if connection was lost before the flow is finished the valueas are restored so that it can be succesfully resumed on th next connection. Also a banch of log entries were added to simplify debugging of interactions with keycard and native module. Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
a38df48691
commit
5ecc7590d9
|
@ -2,7 +2,8 @@
|
|||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.react-native.js-dependencies :as js-dependencies]
|
||||
[status-im.utils.config :as config]
|
||||
[status-im.utils.platform :as platform]))
|
||||
[status-im.utils.platform :as platform]
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
(defonce keycard (.-default js-dependencies/status-keycard))
|
||||
(defonce event-emitter (.-DeviceEventEmitter js-dependencies/react-native))
|
||||
|
@ -12,6 +13,7 @@
|
|||
:error (.-message object)})
|
||||
|
||||
(defn check-nfc-support []
|
||||
(log/debug "[keycard] check-nfc-support")
|
||||
(when (and config/hardwallet-enabled?
|
||||
platform/android?)
|
||||
(.. keycard
|
||||
|
@ -19,6 +21,7 @@
|
|||
(then #(re-frame/dispatch [:hardwallet.callback/check-nfc-support-success %])))))
|
||||
|
||||
(defn check-nfc-enabled []
|
||||
(log/debug "[keycard] check-nfc-enabled")
|
||||
(when (and config/hardwallet-enabled?
|
||||
platform/android?)
|
||||
(.. keycard
|
||||
|
@ -26,6 +29,7 @@
|
|||
(then #(re-frame/dispatch [:hardwallet.callback/check-nfc-enabled-success %])))))
|
||||
|
||||
(defn open-nfc-settings []
|
||||
(log/debug "[keycard] open-nfc-settings")
|
||||
(when platform/android?
|
||||
(.openNfcSettings keycard)))
|
||||
|
||||
|
@ -34,6 +38,7 @@
|
|||
(.removeAllListeners event-emitter event)))
|
||||
|
||||
(defn register-card-events []
|
||||
(log/debug "[keycard] register-card-events")
|
||||
(when (and config/hardwallet-enabled?
|
||||
platform/android?)
|
||||
|
||||
|
@ -51,12 +56,14 @@
|
|||
#(re-frame/dispatch [:hardwallet.callback/on-card-disconnected %]))}])))
|
||||
|
||||
(defn get-application-info [{:keys [pairing on-success]}]
|
||||
(log/debug "[keycard] get-application-info")
|
||||
(.. keycard
|
||||
(getApplicationInfo (str pairing))
|
||||
(then #(re-frame/dispatch [:hardwallet.callback/on-get-application-info-success % on-success]))
|
||||
(catch #(re-frame/dispatch [:hardwallet.callback/on-get-application-info-error (error-object->map %)]))))
|
||||
|
||||
(defn install-applet []
|
||||
(log/debug "[keycard] install-applet")
|
||||
(when config/hardwallet-enabled?
|
||||
(.. keycard
|
||||
installApplet
|
||||
|
@ -64,6 +71,7 @@
|
|||
(catch #(re-frame/dispatch [:hardwallet.callback/on-install-applet-error (error-object->map %)])))))
|
||||
|
||||
(defn init-card [pin]
|
||||
(log/debug "[keycard] init-card")
|
||||
(when config/hardwallet-enabled?
|
||||
(.. keycard
|
||||
(init pin)
|
||||
|
@ -71,6 +79,7 @@
|
|||
(catch #(re-frame/dispatch [:hardwallet.callback/on-init-card-error (error-object->map %)])))))
|
||||
|
||||
(defn install-applet-and-init-card [pin]
|
||||
(log/debug "[keycard] install-applet-and-init-card")
|
||||
(when config/hardwallet-enabled?
|
||||
(.. keycard
|
||||
(installAppletAndInitCard pin)
|
||||
|
@ -79,6 +88,7 @@
|
|||
|
||||
(defn pair
|
||||
[{:keys [password]}]
|
||||
(log/debug "[keycard] pair")
|
||||
(when password
|
||||
(.. keycard
|
||||
(pair password)
|
||||
|
@ -87,6 +97,7 @@
|
|||
|
||||
(defn generate-mnemonic
|
||||
[{:keys [pairing words]}]
|
||||
(log/debug "[keycard] generate-mnemonic")
|
||||
(when pairing
|
||||
(.. keycard
|
||||
(generateMnemonic pairing words)
|
||||
|
@ -95,6 +106,7 @@
|
|||
|
||||
(defn generate-and-load-key
|
||||
[{:keys [mnemonic pairing pin]}]
|
||||
(log/debug "[keycard] generate-and-load-key")
|
||||
(when pairing
|
||||
(.. keycard
|
||||
(generateAndLoadKey mnemonic pairing pin)
|
||||
|
@ -103,6 +115,7 @@
|
|||
|
||||
(defn unblock-pin
|
||||
[{:keys [puk new-pin pairing]}]
|
||||
(log/debug "[keycard] unblock-pin")
|
||||
(when (and pairing new-pin puk)
|
||||
(.. keycard
|
||||
(unblockPin pairing puk new-pin)
|
||||
|
@ -111,6 +124,7 @@
|
|||
|
||||
(defn verify-pin
|
||||
[{:keys [pin pairing]}]
|
||||
(log/debug "[keycard] verify-pin")
|
||||
(when (and pairing (not-empty pin))
|
||||
(.. keycard
|
||||
(verifyPin pairing pin)
|
||||
|
@ -119,6 +133,7 @@
|
|||
|
||||
(defn change-pin
|
||||
[{:keys [current-pin new-pin pairing]}]
|
||||
(log/debug "[keycard] change-pin")
|
||||
(when (and pairing current-pin new-pin)
|
||||
(.. keycard
|
||||
(changePin pairing current-pin new-pin)
|
||||
|
@ -127,6 +142,7 @@
|
|||
|
||||
(defn unpair
|
||||
[{:keys [pin pairing]}]
|
||||
(log/debug "[keycard] unpair")
|
||||
(when (and pairing pin)
|
||||
(.. keycard
|
||||
(unpair pairing pin)
|
||||
|
@ -135,6 +151,7 @@
|
|||
|
||||
(defn delete
|
||||
[]
|
||||
(log/debug "[keycard] delete")
|
||||
(.. keycard
|
||||
(delete)
|
||||
(then #(re-frame/dispatch [:hardwallet.callback/on-delete-success %]))
|
||||
|
@ -142,6 +159,7 @@
|
|||
|
||||
(defn remove-key
|
||||
[{:keys [pin pairing]}]
|
||||
(log/debug "[keycard] remove-key")
|
||||
(.. keycard
|
||||
(removeKey pairing pin)
|
||||
(then #(re-frame/dispatch [:hardwallet.callback/on-remove-key-success %]))
|
||||
|
@ -149,6 +167,7 @@
|
|||
|
||||
(defn remove-key-with-unpair
|
||||
[{:keys [pin pairing]}]
|
||||
(log/debug "[keycard] remove-key-with-unpair")
|
||||
(.. keycard
|
||||
(removeKeyWithUnpair pairing pin)
|
||||
(then #(re-frame/dispatch [:hardwallet.callback/on-remove-key-success %]))
|
||||
|
@ -156,6 +175,7 @@
|
|||
|
||||
(defn unpair-and-delete
|
||||
[{:keys [pin pairing]}]
|
||||
(log/debug "[keycard] unpair-and-delete")
|
||||
(when (and pairing pin)
|
||||
(.. keycard
|
||||
(unpairAndDelete pairing pin)
|
||||
|
@ -164,6 +184,7 @@
|
|||
|
||||
(defn get-keys
|
||||
[{:keys [pairing pin on-success]}]
|
||||
(log/debug "[keycard] get-keys")
|
||||
(when (and pairing (not-empty pin))
|
||||
(.. keycard
|
||||
(getKeys pairing pin)
|
||||
|
@ -172,6 +193,7 @@
|
|||
|
||||
(defn sign
|
||||
[{:keys [pairing pin hash]}]
|
||||
(log/debug "[keycard] sign")
|
||||
(when (and pairing pin hash)
|
||||
(.. keycard
|
||||
(sign pairing pin hash)
|
||||
|
|
|
@ -67,6 +67,62 @@
|
|||
(when-let [listener (get-in db [:hardwallet :back-button-listener])]
|
||||
{:hardwallet/remove-listener-to-hardware-back-button listener}))
|
||||
|
||||
(fx/defn set-on-card-connected
|
||||
[{:keys [db]} on-connect]
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] on-connect)
|
||||
(assoc-in [:hardwallet :last-on-card-connected] nil))})
|
||||
|
||||
(fx/defn stash-on-card-connected
|
||||
[{:keys [db]}]
|
||||
(let [on-connect (get-in db [:hardwallet :on-card-connected])]
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :last-on-card-connected] on-connect)
|
||||
(assoc-in [:hardwallet :on-card-connected] nil))}))
|
||||
|
||||
(fx/defn restore-on-card-connected
|
||||
[{:keys [db]}]
|
||||
(let [on-connect (or
|
||||
(get-in db [:hardwallet :on-card-connected])
|
||||
(get-in db [:hardwallet :last-on-card-connected]))]
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] on-connect)
|
||||
(assoc-in [:hardwallet :last-on-card-connect] nil))}))
|
||||
|
||||
(fx/defn clear-on-card-connected
|
||||
[{:keys [db]}]
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(assoc-in [:hardwallet :last-on-card-connected] nil))})
|
||||
|
||||
(fx/defn set-on-card-read
|
||||
[{:keys [db]} on-connect]
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-read] on-connect)
|
||||
(assoc-in [:hardwallet :last-on-card-read] nil))})
|
||||
|
||||
(fx/defn stash-on-card-read
|
||||
[{:keys [db]}]
|
||||
(let [on-connect (get-in db [:hardwallet :on-card-read])]
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :last-on-card-read] on-connect)
|
||||
(assoc-in [:hardwallet :on-card-read] nil))}))
|
||||
|
||||
(fx/defn restore-on-card-read
|
||||
[{:keys [db]}]
|
||||
(let [on-connect (or
|
||||
(get-in db [:hardwallet :on-card-read])
|
||||
(get-in db [:hardwallet :last-on-card-read]))]
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-read] on-connect)
|
||||
(assoc-in [:hardwallet :last-on-card-connect] nil))}))
|
||||
|
||||
(fx/defn clear-on-card-read
|
||||
[{:keys [db]}]
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-read] nil)
|
||||
(assoc-in [:hardwallet :last-on-card-read] nil))})
|
||||
|
||||
(fx/defn on-add-listener-to-hardware-back-button
|
||||
"Adds listener to hardware back button on Android.
|
||||
During keycard setup we show user a warning that setup will be cancelled
|
||||
|
@ -79,7 +135,7 @@
|
|||
(fx/defn hardwallet-connect-navigate-back-button-clicked
|
||||
[{:keys [db] :as cofx}]
|
||||
(fx/merge cofx
|
||||
{:db (assoc-in db [:hardwallet :on-card-connected] nil)}
|
||||
(clear-on-card-connected)
|
||||
(navigation/navigate-back)))
|
||||
|
||||
(fx/defn enter-pin-navigate-back-button-clicked
|
||||
|
@ -88,14 +144,14 @@
|
|||
navigate-to-browser? (contains? screen-before :browser-stack)]
|
||||
(if navigate-to-browser?
|
||||
(fx/merge cofx
|
||||
{:db (assoc-in db [:hardwallet :on-card-connected] nil)}
|
||||
(clear-on-card-connected)
|
||||
;;TODO use new signing flow
|
||||
;;(wallet/discard-transaction)
|
||||
(navigation/navigate-to-cofx :browser nil))
|
||||
(if (= :enter-pin-login (:view-id db))
|
||||
(navigation/navigate-to-cofx cofx :multiaccounts nil)
|
||||
(fx/merge cofx
|
||||
{:db (assoc-in db [:hardwallet :on-card-connected] nil)}
|
||||
(clear-on-card-connected)
|
||||
(navigation/navigate-back))))))
|
||||
|
||||
(fx/defn remove-pairing-from-multiaccount
|
||||
|
@ -114,9 +170,9 @@
|
|||
(fx/defn unauthorized-operation
|
||||
[{:keys [db] :as cofx}]
|
||||
(fx/merge cofx
|
||||
{:db (assoc-in db [:hardwallet :on-card-connected] nil)
|
||||
:utils/show-popup {:title ""
|
||||
{:utils/show-popup {:title ""
|
||||
:content (i18n/label :t/keycard-unauthorized-operation)}}
|
||||
(clear-on-card-connected)
|
||||
(navigation/navigate-to-cofx :keycard-settings nil)))
|
||||
|
||||
(fx/defn show-no-keycard-applet-alert [_]
|
||||
|
@ -179,9 +235,8 @@
|
|||
[{:keys [db] :as cofx}]
|
||||
(let [card-connected? (get-in db [:hardwallet :card-connected?])]
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :setup-step] :preparing)
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/load-preparing-screen))}
|
||||
{:db (assoc-in db [:hardwallet :setup-step] :preparing)}
|
||||
(set-on-card-connected :hardwallet/load-preparing-screen)
|
||||
(when card-connected?
|
||||
(navigation/navigate-to-cofx :keycard-onboarding-preparing nil))
|
||||
(if card-connected?
|
||||
|
@ -200,6 +255,7 @@
|
|||
|
||||
(fx/defn load-pair-screen
|
||||
[{:keys [db] :as cofx}]
|
||||
(log/debug "[hardwallet] load-pair-screen")
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :setup-step] :pair))}
|
||||
|
@ -212,9 +268,8 @@
|
|||
[{:keys [db] :as cofx}]
|
||||
(let [card-connected? (get-in db [:hardwallet :card-connected?])]
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :setup-step] :pairing)
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/load-pairing-screen))}
|
||||
{:db (assoc-in db [:hardwallet :setup-step] :pairing)}
|
||||
(set-on-card-connected :hardwallet/load-pairing-screen)
|
||||
(when card-connected?
|
||||
(navigation/navigate-to-cofx :keycard-pairing nil))
|
||||
(if card-connected?
|
||||
|
@ -260,9 +315,8 @@
|
|||
[{:keys [db] :as cofx}]
|
||||
(let [card-connected? (get-in db [:hardwallet :card-connected?])]
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :setup-step] :loading-keys)
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/load-finishing-screen))}
|
||||
{:db (assoc-in db [:hardwallet :setup-step] :loading-keys)}
|
||||
(set-on-card-connected :hardwallet/load-finishing-screen)
|
||||
(when card-connected?
|
||||
(navigation/navigate-to-cofx :keycard-onboarding-finishing nil))
|
||||
(if card-connected?
|
||||
|
@ -374,8 +428,8 @@
|
|||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :setup-step] :recovery-phrase)
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(assoc-in [:hardwallet :secrets :mnemonic] mnemonic))}
|
||||
(clear-on-card-connected)
|
||||
(navigation/navigate-to-cofx :keycard-onboarding-recovery-phrase nil)))
|
||||
|
||||
(fx/defn set-mnemonic
|
||||
|
@ -412,6 +466,8 @@
|
|||
|
||||
(fx/defn proceed-setup-with-initialized-card
|
||||
[{:keys [db] :as cofx} flow instance-uid]
|
||||
(log/debug "[hardwallet] proceed-setup-with-initialized-card"
|
||||
"instance-uid" instance-uid)
|
||||
(if (= flow :import)
|
||||
(navigation/navigate-to-cofx cofx :keycard-recovery-no-key nil)
|
||||
(let [pairing-data (get-in db [:hardwallet :pairings instance-uid])]
|
||||
|
@ -443,6 +499,9 @@
|
|||
pairing (get-pairing db key-uid)
|
||||
app-info' (if pairing (assoc app-info :paired? true) app-info)
|
||||
card-state (get-card-state app-info')]
|
||||
(log/debug "[hardwallet] check-card-state"
|
||||
"card-state" card-state
|
||||
"flow" flow)
|
||||
(fx/merge cofx
|
||||
{:db (assoc-in db [:hardwallet :card-state] card-state)}
|
||||
(set-setup-step card-state)
|
||||
|
@ -474,8 +533,8 @@
|
|||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :pin :on-verified] nil)
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(assoc-in [:hardwallet :setup-step] nil))}
|
||||
(clear-on-card-connected)
|
||||
(navigation/navigate-to-cofx :keycard-settings nil)))
|
||||
|
||||
(fx/defn navigate-to-enter-pin-screen
|
||||
|
@ -525,11 +584,13 @@
|
|||
#())) ;;TODO with v1 flow
|
||||
|
||||
(defn settings-screen-did-load
|
||||
[{:keys [db]}]
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :pin :on-verified] nil)
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(assoc-in [:hardwallet :setup-step] nil))})
|
||||
[{:keys [db] :as cofx}]
|
||||
(fx/merge
|
||||
cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :pin :on-verified] nil)
|
||||
(assoc-in [:hardwallet :setup-step] nil))}
|
||||
(clear-on-card-connected)))
|
||||
|
||||
(defn reset-card-screen-did-load
|
||||
[{:keys [db]}]
|
||||
|
@ -596,14 +657,6 @@
|
|||
:else
|
||||
(get-keys-from-keycard cofx))))
|
||||
|
||||
(fx/defn clear-on-card-read
|
||||
[{:keys [db]}]
|
||||
{:db (assoc-in db [:hardwallet :on-card-read] nil)})
|
||||
|
||||
(fx/defn clear-on-card-connected
|
||||
[{:keys [db]}]
|
||||
{:db (assoc-in db [:hardwallet :on-card-connected] nil)})
|
||||
|
||||
(fx/defn show-wrong-keycard-alert
|
||||
[_ card-connected?]
|
||||
(when card-connected?
|
||||
|
@ -623,6 +676,9 @@
|
|||
enter-step (if (zero? pin-retry-counter)
|
||||
:puk
|
||||
(get-in db [:hardwallet :pin :enter-step]))]
|
||||
(log/debug "[hardwallet] on-get-application-info-success"
|
||||
"connect-screen?" connect-screen?
|
||||
"on-success" on-success')
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :pin :enter-step] enter-step)
|
||||
|
@ -632,8 +688,7 @@
|
|||
(assoc-in [:hardwallet :application-info] info')
|
||||
(assoc-in [:hardwallet :application-info :applet-installed?] true)
|
||||
(assoc-in [:hardwallet :application-info-error] nil))}
|
||||
(when-not connect-screen?
|
||||
(clear-on-card-read))
|
||||
(stash-on-card-read)
|
||||
(if (zero? puk-retry-counter)
|
||||
{:utils/show-popup {:title (i18n/label :t/error)
|
||||
:content (i18n/label :t/keycard-blocked)}}
|
||||
|
@ -680,10 +735,14 @@
|
|||
(fx/defn keycard-connection-lost-cancel-pressed
|
||||
{:events [:keycard.connection-lost.ui/cancel-pressed]}
|
||||
[{:keys [db] :as cofx}]
|
||||
(if (contains? (set (take 3 (:navigation-stack db)))
|
||||
:keycard-login-pin)
|
||||
(navigation/navigate-to-cofx cofx :multiaccounts nil)
|
||||
(navigation/navigate-back cofx)))
|
||||
(fx/merge
|
||||
cofx
|
||||
(clear-on-card-connected)
|
||||
(clear-on-card-read)
|
||||
(if (contains? (set (take 3 (:navigation-stack db)))
|
||||
:keycard-login-pin)
|
||||
(navigation/navigate-to-cofx :multiaccounts nil)
|
||||
(navigation/navigate-back))))
|
||||
|
||||
(fx/defn start-onboarding-flow
|
||||
{:events [:keycard.recovery.no-key.ui/generate-key-pressed
|
||||
|
@ -707,9 +766,9 @@
|
|||
:multiaccount-whisper-public-key
|
||||
:application-info)
|
||||
(assoc-in [:hardwallet :setup-step] :begin)
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/get-application-info)
|
||||
(assoc-in [:hardwallet :on-card-read] :hardwallet/check-card-state)
|
||||
(assoc-in [:hardwallet :pin :on-verified] nil))}
|
||||
(set-on-card-connected :hardwallet/get-application-info)
|
||||
(set-on-card-read :hardwallet/check-card-state)
|
||||
(if nfc-enabled?
|
||||
(if (= flow :import)
|
||||
(navigation/navigate-to-cofx :keycard-recovery-start nil)
|
||||
|
@ -720,12 +779,11 @@
|
|||
[{:keys [db] :as cofx}]
|
||||
(let [{:keys [card-connected? nfc-enabled?]} (:hardwallet db)]
|
||||
(if nfc-enabled?
|
||||
(if card-connected?
|
||||
(login-with-keycard cofx)
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/get-application-info)
|
||||
(assoc-in [:hardwallet :on-card-read] :hardwallet/login-with-keycard))}
|
||||
(fx/merge cofx
|
||||
(set-on-card-connected :hardwallet/get-application-info)
|
||||
(set-on-card-read :hardwallet/login-with-keycard)
|
||||
(if card-connected?
|
||||
(login-with-keycard)
|
||||
(navigation/navigate-to-cofx :keycard-login-connect-card nil)))
|
||||
(navigation/navigate-to-cofx cofx :keycard-nfc-on nil))))
|
||||
|
||||
|
@ -798,6 +856,7 @@
|
|||
(fx/defn login-pair-card-pressed
|
||||
{:events [:keycard.login.ui/pair-card-pressed]}
|
||||
[{:keys [db] :as cofx}]
|
||||
(log/debug "[hardwallet] load-pair-card-pressed")
|
||||
(fx/merge cofx
|
||||
{:db (assoc-in db [:hardwallet :flow] :login)}
|
||||
(navigation/navigate-to-cofx :keycard-recovery-pair nil)))
|
||||
|
@ -871,7 +930,7 @@
|
|||
{:hardwallet/remove-key-with-unpair {:pin pin
|
||||
:pairing pairing}}
|
||||
(fx/merge cofx
|
||||
{:db (assoc-in db [:hardwallet :on-card-connected] :hardwallet/remove-key-with-unpair)}
|
||||
(set-on-card-connected :hardwallet/remove-key-with-unpair)
|
||||
(navigation/navigate-to-cofx :keycard-connection-lost nil)))))
|
||||
|
||||
(fx/defn on-remove-key-success
|
||||
|
@ -887,7 +946,6 @@
|
|||
(assoc-in [:hardwallet :whisper-public-key] nil)
|
||||
(assoc-in [:hardwallet :wallet-address] nil)
|
||||
(assoc-in [:hardwallet :application-info] nil)
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(assoc-in [:hardwallet :pin] {:status nil
|
||||
:error-label nil
|
||||
:on-verified nil}))
|
||||
|
@ -895,6 +953,7 @@
|
|||
;;FIXME delete multiaccount
|
||||
:utils/show-popup {:title ""
|
||||
:content (i18n/label :t/card-reseted)}}
|
||||
(clear-on-card-connected)
|
||||
(multiaccounts.logout/logout))))
|
||||
|
||||
(fx/defn on-remove-key-error
|
||||
|
@ -904,11 +963,10 @@
|
|||
(fx/merge cofx
|
||||
(if tag-was-lost?
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/remove-key-with-unpair)
|
||||
(assoc-in [:hardwallet :pin :status] nil))
|
||||
{:db (assoc-in db [:hardwallet :pin :status] nil)
|
||||
:utils/show-popup {:title (i18n/label :t/error)
|
||||
:content (i18n/label :t/cannot-read-card)}}
|
||||
(set-on-card-connected :hardwallet/remove-key-with-unpair)
|
||||
(navigation/navigate-to-cofx :keycard-connection-lost nil))
|
||||
(show-wrong-keycard-alert true)))))
|
||||
|
||||
|
@ -920,28 +978,26 @@
|
|||
(update :multiaccounts/multiaccounts dissoc multiaccount-address)
|
||||
(assoc-in [:hardwallet :secrets] nil)
|
||||
(assoc-in [:hardwallet :application-info] nil)
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(assoc-in [:hardwallet :pin] {:status nil
|
||||
:error-label nil
|
||||
:on-verified nil}))
|
||||
;;FIXME delete multiaccount
|
||||
:utils/show-popup {:title ""
|
||||
:content (i18n/label :t/card-reseted)}}
|
||||
|
||||
(clear-on-card-connected)
|
||||
(multiaccounts.logout/logout))))
|
||||
|
||||
(fx/defn on-delete-error
|
||||
[{:keys [db] :as cofx} error]
|
||||
(log/debug "[hardwallet] delete error" error)
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(assoc-in [:hardwallet :pin] {:status nil
|
||||
:error-label nil
|
||||
:on-verified nil}))
|
||||
{:db (assoc-in db [:hardwallet :pin] {:status nil
|
||||
:error-label nil
|
||||
:on-verified nil})
|
||||
:hardwallet/get-application-info nil
|
||||
:utils/show-popup {:title ""
|
||||
:content (i18n/label :t/something-went-wrong)}}
|
||||
(clear-on-card-connected)
|
||||
(navigation/navigate-to-cofx :keycard-settings nil)))
|
||||
|
||||
(fx/defn reset-card-pressed
|
||||
|
@ -972,14 +1028,13 @@
|
|||
(let [pin-retry-counter (get-in db [:hardwallet :application-info :pin-retry-counter])
|
||||
enter-step (if (zero? pin-retry-counter) :puk :current)]
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/navigate-to-enter-pin-screen)
|
||||
(assoc-in [:hardwallet :pin] {:enter-step enter-step
|
||||
:current []
|
||||
:puk []
|
||||
:status nil
|
||||
:error-label nil
|
||||
:on-verified :hardwallet/remove-key-with-unpair}))}
|
||||
{:db (assoc-in db [:hardwallet :pin] {:enter-step enter-step
|
||||
:current []
|
||||
:puk []
|
||||
:status nil
|
||||
:error-label nil
|
||||
:on-verified :hardwallet/remove-key-with-unpair})}
|
||||
(set-on-card-connected :hardwallet/navigate-to-enter-pin-screen)
|
||||
(navigate-to-enter-pin-screen))))
|
||||
|
||||
(fx/defn error-button-pressed
|
||||
|
@ -998,7 +1053,7 @@
|
|||
(let [{:keys [password]} (get-in cofx [:db :hardwallet :secrets])
|
||||
card-connected? (get-in db [:hardwallet :card-connected?])]
|
||||
(fx/merge cofx
|
||||
{:db (assoc-in db [:hardwallet :on-card-connected] :hardwallet/pair)}
|
||||
(set-on-card-connected :hardwallet/pair)
|
||||
(when card-connected?
|
||||
(pair* password))
|
||||
(if card-connected?
|
||||
|
@ -1044,7 +1099,7 @@
|
|||
:current-pin current-pin
|
||||
:pairing pairing}})
|
||||
(fx/merge cofx
|
||||
{:db (assoc-in db [:hardwallet :on-card-connected] :hardwallet/change-pin)}
|
||||
(set-on-card-connected :hardwallet/change-pin)
|
||||
(navigation/navigate-to-cofx :hardwallet-connect nil))))))
|
||||
|
||||
(fx/defn dispatch-on-verified-event
|
||||
|
@ -1096,10 +1151,9 @@
|
|||
(let [on-verified (get-in db [:hardwallet :pin :on-verified])
|
||||
pairing (get-pairing db)]
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(update-in [:hardwallet :pin] merge {:status nil
|
||||
:error-label nil}))}
|
||||
{:db (update-in [:hardwallet :pin] merge {:status nil
|
||||
:error-label nil})}
|
||||
(clear-on-card-connected)
|
||||
(when-not (contains? #{:hardwallet/unpair
|
||||
:hardwallet/generate-and-load-key
|
||||
:hardwallet/remove-key-with-unpair
|
||||
|
@ -1116,11 +1170,10 @@
|
|||
(fx/merge cofx
|
||||
(when tag-was-lost?
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/verify-pin)
|
||||
(assoc-in [:hardwallet :pin :status] nil))
|
||||
{:db (assoc-in db [:hardwallet :pin :status] nil)
|
||||
:utils/show-popup {:title (i18n/label :t/error)
|
||||
:content (i18n/label :t/cannot-read-card)}}
|
||||
(set-on-card-connected :hardwallet/verify-pin)
|
||||
(navigation/navigate-to-cofx (if setup?
|
||||
:keycard-connection-lost-setup
|
||||
:keycard-connection-lost) nil))
|
||||
|
@ -1143,14 +1196,13 @@
|
|||
[{:keys [db] :as cofx}]
|
||||
(let [pin (get-in db [:hardwallet :pin :original])]
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(assoc-in [:hardwallet :pin] {:status nil
|
||||
:login pin
|
||||
:confirmation []
|
||||
:error-label nil}))
|
||||
{:db (assoc-in db [:hardwallet :pin] {:status nil
|
||||
:login pin
|
||||
:confirmation []
|
||||
:error-label nil})
|
||||
:utils/show-popup {:title ""
|
||||
:content (i18n/label :t/pin-changed)}}
|
||||
(clear-on-card-connected)
|
||||
(when (:multiaccounts/login db)
|
||||
(navigation/navigate-to-cofx :keycard-login-pin nil))
|
||||
(when (:multiaccounts/login db)
|
||||
|
@ -1165,11 +1217,10 @@
|
|||
(fx/merge cofx
|
||||
(if tag-was-lost?
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/change-pin)
|
||||
(assoc-in [:hardwallet :pin :status] nil))
|
||||
{:db (assoc-in db [:hardwallet :pin :status] nil)
|
||||
:utils/show-popup {:title (i18n/label :t/error)
|
||||
:content (i18n/label :t/cannot-read-card)}}
|
||||
(set-on-card-connected :hardwallet/change-pin)
|
||||
(navigation/navigate-to-cofx :hardwallet-connect nil))
|
||||
(if (re-matches pin-mismatch-error (:error error))
|
||||
(fx/merge cofx
|
||||
|
@ -1193,13 +1244,13 @@
|
|||
{:db (-> db
|
||||
(assoc-in [:hardwallet :secrets] nil)
|
||||
(update-in [:hardwallet :pairings] dissoc (keyword instance-uid))
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(assoc-in [:hardwallet :pin] {:status nil
|
||||
:error-label nil
|
||||
:on-verified nil}))
|
||||
:hardwallet/persist-pairings (dissoc pairings (keyword instance-uid))
|
||||
:utils/show-popup {:title ""
|
||||
:content (i18n/label :t/card-unpaired)}}
|
||||
(clear-on-card-connected)
|
||||
(remove-pairing-from-multiaccount nil)
|
||||
(navigation/navigate-to-cofx :keycard-settings nil))))
|
||||
|
||||
|
@ -1207,14 +1258,13 @@
|
|||
[{:keys [db] :as cofx} error]
|
||||
(log/debug "[hardwallet] unpair error" error)
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(assoc-in [:hardwallet :pin] {:status nil
|
||||
:error-label nil
|
||||
:on-verified nil}))
|
||||
{:db (assoc-in db [:hardwallet :pin] {:status nil
|
||||
:error-label nil
|
||||
:on-verified nil})
|
||||
:hardwallet/get-application-info nil
|
||||
:utils/show-popup {:title ""
|
||||
:content (i18n/label :t/something-went-wrong)}}
|
||||
(clear-on-card-connected)
|
||||
(navigation/navigate-to-cofx :keycard-settings nil)))
|
||||
|
||||
(defn verify-pin
|
||||
|
@ -1228,7 +1278,7 @@
|
|||
:hardwallet/verify-pin {:pin pin
|
||||
:pairing pairing}}
|
||||
(fx/merge cofx
|
||||
{:db (assoc-in db [:hardwallet :on-card-connected] :hardwallet/verify-pin)}
|
||||
(set-on-card-connected :hardwallet/verify-pin)
|
||||
(navigation/navigate-to-cofx (if setup?
|
||||
:keycard-connection-lost-setup
|
||||
:keycard-connection-lost) nil)))))
|
||||
|
@ -1245,7 +1295,7 @@
|
|||
:new-pin default-pin
|
||||
:pairing pairing}}
|
||||
(fx/merge cofx
|
||||
{:db (assoc-in db [:hardwallet :on-card-connected] :hardwallet/unblock-pin)}
|
||||
(set-on-card-connected :hardwallet/unblock-pin)
|
||||
(navigation/navigate-to-cofx :keycard-connection-lost nil)))))
|
||||
|
||||
(def pin-code-length 6)
|
||||
|
@ -1305,9 +1355,8 @@
|
|||
:pairing pairing
|
||||
:pin pin}}
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:signing/sign :keycard-step] :signing)
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/sign))}
|
||||
{:db (assoc-in db [:signing/sign :keycard-step] :signing)}
|
||||
(set-on-card-connected :hardwallet/sign)
|
||||
(when-not keycard-match?
|
||||
(show-wrong-keycard-alert card-connected?))))))
|
||||
|
||||
|
@ -1321,9 +1370,8 @@
|
|||
{:db (assoc-in db [:signing/sign :keycard-step] :signing)}
|
||||
(get-application-info pairing :hardwallet/sign))
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:signing/sign :keycard-step] :connect)
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/prepare-to-sign))}))))
|
||||
{:db (assoc-in db [:signing/sign :keycard-step] :connect)}
|
||||
(set-on-card-connected :hardwallet/prepare-to-sign)))))
|
||||
|
||||
(fx/defn import-multiaccount
|
||||
{:events [:hardwallet/import-multiaccount]}
|
||||
|
@ -1347,8 +1395,7 @@
|
|||
[{:keys [db] :as cofx}]
|
||||
(let [card-connected? (get-in db [:hardwallet :card-connected?])]
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/load-recovering-key-screen))}
|
||||
(set-on-card-connected :hardwallet/load-recovering-key-screen)
|
||||
(when card-connected?
|
||||
(dispatch-event :hardwallet/import-multiaccount))
|
||||
(if card-connected?
|
||||
|
@ -1413,9 +1460,8 @@
|
|||
[{:keys [db] :as cofx}]
|
||||
(let [card-connected? (get-in db [:hardwallet :card-connected?])]
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :setup-step] :loading-keys)
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/load-loading-keys-screen))}
|
||||
{:db (assoc-in db [:hardwallet :setup-step] :loading-keys)}
|
||||
(set-on-card-connected :hardwallet/load-loading-keys-screen)
|
||||
(if card-connected?
|
||||
(dispatch-event :hardwallet/generate-and-load-key)
|
||||
(navigation/navigate-to-cofx :hardwallet-connect nil)))))
|
||||
|
@ -1424,9 +1470,8 @@
|
|||
[{:keys [db] :as cofx}]
|
||||
(let [card-connected? (get-in db [:hardwallet :card-connected?])]
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :setup-step] :generating-mnemonic)
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/load-generating-mnemonic-screen))}
|
||||
{:db (assoc-in db [:hardwallet :setup-step] :generating-mnemonic)}
|
||||
(set-on-card-connected :hardwallet/load-generating-mnemonic-screen)
|
||||
(if card-connected?
|
||||
(dispatch-event :hardwallet/generate-mnemonic)
|
||||
(navigation/navigate-to-cofx :hardwallet-connect nil)))))
|
||||
|
@ -1443,14 +1488,16 @@
|
|||
should-read-instance-uid? :hardwallet/get-application-info
|
||||
:else (get-in db [:hardwallet :on-card-read]))
|
||||
pairing (get-pairing db key-uid)]
|
||||
(log/debug "[hardwallet] on-card-connected"
|
||||
"on-card-connected" on-card-connected
|
||||
"on-card-read" on-card-read)
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :card-connected?] true)
|
||||
(assoc-in [:hardwallet :card-read-in-progress?] (boolean on-card-read)))}
|
||||
(when on-card-connected
|
||||
(dispatch-event on-card-connected))
|
||||
(when on-card-connected
|
||||
(clear-on-card-connected))
|
||||
(stash-on-card-connected)
|
||||
(when (and on-card-read
|
||||
(nil? on-card-connected))
|
||||
(get-application-info pairing on-card-read)))))
|
||||
|
@ -1464,6 +1511,8 @@
|
|||
{:db (-> db
|
||||
(assoc-in [:hardwallet :card-connected?] false)
|
||||
(assoc-in [:hardwallet :card-read-in-progress?] false))}
|
||||
(restore-on-card-connected)
|
||||
(restore-on-card-read)
|
||||
(when (and setup-running?
|
||||
on-card-connected)
|
||||
(navigation/navigate-to-cofx :keycard-connection-lost-setup nil)))))
|
||||
|
@ -1500,9 +1549,9 @@
|
|||
{:hardwallet/get-application-info nil
|
||||
:db (-> db
|
||||
(assoc-in [:hardwallet :card-state] :init)
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(assoc-in [:hardwallet :setup-step] :secret-keys)
|
||||
(update-in [:hardwallet :secrets] merge secrets'))}
|
||||
(clear-on-card-connected)
|
||||
(listen-to-hardware-back-button)
|
||||
(navigation/navigate-to-cofx :keycard-onboarding-puk-code nil))))
|
||||
|
||||
|
@ -1517,9 +1566,8 @@
|
|||
[{:keys [db] :as cofx} {:keys [code error]}]
|
||||
(log/debug "[hardwallet] install applet and init card error: " error)
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/load-preparing-screen)
|
||||
(assoc-in [:hardwallet :setup-error] error))}
|
||||
{:db (assoc-in db [:hardwallet :setup-error] error)}
|
||||
(set-on-card-connected :hardwallet/load-preparing-screen)
|
||||
(process-error code error)))
|
||||
|
||||
(def on-init-card-error on-install-applet-and-init-card-error)
|
||||
|
@ -1559,10 +1607,10 @@
|
|||
:db (-> db
|
||||
(assoc-in [:hardwallet :pairings] pairings)
|
||||
(assoc-in [:hardwallet :application-info :paired?] true)
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(assoc-in [:hardwallet :setup-step] next-step)
|
||||
(assoc-in [:hardwallet :secrets :pairing] pairing)
|
||||
(assoc-in [:hardwallet :secrets :paired-on] paired-on))}
|
||||
(clear-on-card-connected)
|
||||
(when multiaccount
|
||||
(set-multiaccount-pairing multiaccount pairing paired-on))
|
||||
(when (= flow :login)
|
||||
|
@ -1579,12 +1627,12 @@
|
|||
(log/debug "[hardwallet] pair error: " error)
|
||||
(let [setup-step (get-in db [:hardwallet :setup-step])
|
||||
flow (get-in db [:hardwallet :flow])]
|
||||
(log/debug "[hardwallet] on-pair-error")
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :setup-error] (i18n/label :t/invalid-pairing-password))
|
||||
(assoc-in [:hardwallet :on-card-connected] (if (= setup-step :pairing)
|
||||
:hardwallet/load-pairing-screen
|
||||
:hardwallet/pair)))}
|
||||
{:db (assoc-in db [:hardwallet :setup-error] (i18n/label :t/invalid-pairing-password))}
|
||||
(set-on-card-connected (if (= setup-step :pairing)
|
||||
:hardwallet/load-pairing-screen
|
||||
:hardwallet/pair))
|
||||
(when (= flow :import)
|
||||
(navigation/navigate-to-cofx :keycard-recovery-pair nil))
|
||||
(when (not= setup-step :enter-pair-code)
|
||||
|
@ -1594,9 +1642,8 @@
|
|||
[{:keys [db] :as cofx} {:keys [error code]}]
|
||||
(log/debug "[hardwallet] generate mnemonic error: " error)
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/load-generating-mnemonic-screen)
|
||||
(assoc-in [:hardwallet :setup-error] error))}
|
||||
{:db (assoc-in db [:hardwallet :setup-error] error)}
|
||||
(set-on-card-connected :hardwallet/load-generating-mnemonic-screen)
|
||||
(process-error code error)))
|
||||
|
||||
(defn- show-recover-confirmation []
|
||||
|
@ -1732,11 +1779,11 @@
|
|||
(assoc-in [:hardwallet :multiaccount-wallet-address] (:wallet-address account-data))
|
||||
(assoc-in [:hardwallet :multiaccount-whisper-public-key] (:whisper-public-key account-data))
|
||||
(assoc-in [:hardwallet :application-info :key-uid] (:key-uid account-data))
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(update :hardwallet dissoc :recovery-phrase)
|
||||
(update-in [:hardwallet :secrets] dissoc :pin :puk :password)
|
||||
(assoc :multiaccounts/new-installation-id (random-guid-generator))
|
||||
(update-in [:hardwallet :secrets] dissoc :mnemonic))}
|
||||
(clear-on-card-connected)
|
||||
(remove-listener-to-hardware-back-button)
|
||||
(create-keycard-multiaccount))))
|
||||
|
||||
|
@ -1744,9 +1791,8 @@
|
|||
[{:keys [db] :as cofx} {:keys [error code]}]
|
||||
(log/debug "[hardwallet] generate and load key error: " error)
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/load-loading-keys-screen)
|
||||
(assoc-in [:hardwallet :setup-error] error))}
|
||||
{:db (assoc-in db [:hardwallet :setup-error] error)}
|
||||
(set-on-card-connected :hardwallet/load-loading-keys-screen)
|
||||
(process-error code error)))
|
||||
|
||||
(fx/defn on-login-success
|
||||
|
@ -1775,7 +1821,9 @@
|
|||
:hardwallet/get-application-info {:pairing (get-pairing db key-uid)}
|
||||
:hardwallet/login-with-keycard {:multiaccount-data multiaccount-data
|
||||
:password encryption-public-key
|
||||
:chat-key whisper-private-key}})))
|
||||
:chat-key whisper-private-key}}
|
||||
(clear-on-card-connected)
|
||||
(clear-on-card-read))))
|
||||
|
||||
(fx/defn on-get-keys-error
|
||||
[{:keys [db] :as cofx} error]
|
||||
|
@ -1824,9 +1872,9 @@
|
|||
{:db (-> db
|
||||
(assoc-in [:hardwallet :pin :sign] [])
|
||||
(assoc-in [:hardwallet :pin :status] nil)
|
||||
(assoc-in [:hardwallet :on-card-connected] nil)
|
||||
(assoc-in [:hardwallet :hash] nil)
|
||||
(assoc-in [:hardwallet :transaction] nil))}
|
||||
(clear-on-card-connected)
|
||||
(get-application-info (get-pairing db) nil)
|
||||
(if transaction
|
||||
(send-transaction-with-signature {:transaction (types/clj->json transaction)
|
||||
|
@ -1843,11 +1891,11 @@
|
|||
(fn [{:keys [db] :as cofx}]
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc-in [:hardwallet :on-card-connected] :hardwallet/prepare-to-sign)
|
||||
(assoc-in [:hardwallet :pin :status] nil)
|
||||
(assoc-in [:signing/sign :keycard-step] :connect))
|
||||
:utils/show-popup {:title (i18n/label :t/error)
|
||||
:content (i18n/label :t/cannot-read-card)}})))
|
||||
:content (i18n/label :t/cannot-read-card)}}
|
||||
(set-on-card-connected :hardwallet/prepare-to-sign))))
|
||||
(if (re-matches pin-mismatch-error (:error error))
|
||||
(fn [{:keys [db] :as cofx}]
|
||||
(fx/merge cofx
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
[status-im.react-native.js-dependencies :as rn-dependencies]
|
||||
[status-im.ui.components.react :as react]
|
||||
[status-im.utils.platform :as platform]
|
||||
[status-im.utils.types :as types]))
|
||||
[status-im.utils.types :as types]
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
(defn status []
|
||||
(when (exists? (.-NativeModules rn-dependencies/react-native))
|
||||
|
@ -14,46 +15,56 @@
|
|||
(def adjust-resize 16)
|
||||
|
||||
(defn clear-web-data []
|
||||
(log/debug "[native-module] clear-web-data")
|
||||
(when (status)
|
||||
(.clearCookies (status))
|
||||
(.clearStorageAPIs (status))))
|
||||
|
||||
(defn init-keystore []
|
||||
(log/debug "[native-module] init-keystore")
|
||||
(.initKeystore (status)))
|
||||
|
||||
(defn open-accounts [callback]
|
||||
(log/debug "[native-module] open-accounts")
|
||||
(.openAccounts (status) #(callback (types/json->clj %))))
|
||||
|
||||
(defn prepare-dir-and-update-config
|
||||
[config callback]
|
||||
(log/debug "[native-module] prepare-dir-and-update-config")
|
||||
(.prepareDirAndUpdateConfig (status)
|
||||
config
|
||||
#(callback (types/json->clj %))))
|
||||
|
||||
(defn enable-notifications []
|
||||
(log/debug "[native-module] enable-notifications")
|
||||
(.enableNotifications (status)))
|
||||
|
||||
(defn disable-notifications []
|
||||
(log/debug "[native-module] disable-notifications")
|
||||
(.disableNotifications (status)))
|
||||
|
||||
(defn save-account-and-login
|
||||
"NOTE: beware, the password has to be sha3 hashed"
|
||||
[multiaccount-data hashed-password config accounts-data]
|
||||
(log/debug "[native-module] save-account-and-login")
|
||||
(clear-web-data)
|
||||
(.saveAccountAndLogin (status) multiaccount-data hashed-password config accounts-data))
|
||||
|
||||
(defn save-account-and-login-with-keycard
|
||||
"NOTE: chat-key is a whisper private key sent from keycard"
|
||||
[multiaccount-data password config chat-key]
|
||||
(log/debug "[native-module] save-account-and-login-with-keycard")
|
||||
(.saveAccountAndLoginWithKeycard (status) multiaccount-data password config chat-key))
|
||||
|
||||
(defn login
|
||||
"NOTE: beware, the password has to be sha3 hashed"
|
||||
[account-data hashed-password]
|
||||
(log/debug "[native-module] login")
|
||||
(clear-web-data)
|
||||
(.login (status) account-data hashed-password))
|
||||
|
||||
(defn logout []
|
||||
(log/debug "[native-module] logout")
|
||||
(clear-web-data)
|
||||
(.logout (status)))
|
||||
|
||||
|
@ -68,6 +79,7 @@
|
|||
derive accounts from it, because saving an account flushes the loaded keys
|
||||
from memory"
|
||||
[address hashed-password callback]
|
||||
(log/debug "[native-module] multiaccount-load-account")
|
||||
(.multiAccountLoadAccount (status)
|
||||
(types/clj->json {:address address
|
||||
:password hashed-password})
|
||||
|
@ -77,6 +89,7 @@
|
|||
"TODO: this function is not used anywhere
|
||||
if usage isn't planned, remove"
|
||||
[callback]
|
||||
(log/debug "[native-module] multiaccount-reset")
|
||||
(.multiAccountReset (status)
|
||||
callback))
|
||||
|
||||
|
@ -86,6 +99,7 @@
|
|||
with `multiaccount-store-derived` if you want to be able to
|
||||
reuse the derived addresses later"
|
||||
[account-id paths callback]
|
||||
(log/debug "[native-module] multiaccount-derive-addresses")
|
||||
(when (status)
|
||||
(.multiAccountDeriveAddresses (status)
|
||||
(types/clj->json {:accountID account-id
|
||||
|
@ -101,6 +115,7 @@
|
|||
`multiaccount-load-account` before using `multiaccount-store-derived`
|
||||
and the id of the account stored will have changed"
|
||||
[account-id hashed-password callback]
|
||||
(log/debug "[native-module] multiaccount-store-account")
|
||||
(when (status)
|
||||
(.multiAccountStoreAccount (status)
|
||||
(types/clj->json {:accountID account-id
|
||||
|
@ -110,6 +125,7 @@
|
|||
(defn multiaccount-store-derived
|
||||
"NOTE: beware, the password has to be sha3 hashed"
|
||||
[account-id paths hashed-password callback]
|
||||
(log/debug "[native-module] multiaccount-store-derived")
|
||||
(.multiAccountStoreDerived (status)
|
||||
(types/clj->json {:accountID account-id
|
||||
:paths paths
|
||||
|
@ -123,6 +139,7 @@
|
|||
`multiaccount-store-account` on the selected multiaccount
|
||||
to store the key"
|
||||
[n mnemonic-length paths callback]
|
||||
(log/debug "[native-module] multiaccount-generate-and-derive-addresses")
|
||||
(.multiAccountGenerateAndDeriveAddresses (status)
|
||||
(types/clj->json {:n n
|
||||
:mnemonicPhraseLength mnemonic-length
|
||||
|
@ -132,6 +149,7 @@
|
|||
|
||||
(defn multiaccount-import-mnemonic
|
||||
[mnemonic password callback]
|
||||
(log/debug "[native-module] multiaccount-import-mnemonic")
|
||||
(.multiAccountImportMnemonic (status)
|
||||
(types/clj->json {:mnemonicPhrase mnemonic
|
||||
;;NOTE this is not the multiaccount password
|
||||
|
@ -142,17 +160,22 @@
|
|||
(defn verify
|
||||
"NOTE: beware, the password has to be sha3 hashed"
|
||||
[address hashed-password callback]
|
||||
(log/debug "[native-module] verify")
|
||||
(.verify (status) address hashed-password callback))
|
||||
|
||||
(defn login-with-keycard
|
||||
[{:keys [multiaccount-data password chat-key]}]
|
||||
(log/debug "[native-module] login-with-keycard"
|
||||
"password" password)
|
||||
(clear-web-data)
|
||||
(.loginWithKeycard (status) multiaccount-data password chat-key))
|
||||
|
||||
(defn set-soft-input-mode [mode]
|
||||
(log/debug "[native-module] set-soft-input-mode")
|
||||
(.setSoftInputMode (status) mode))
|
||||
|
||||
(defn call-rpc [payload callback]
|
||||
(log/debug "[native-module] call-rpc")
|
||||
(.callRPC (status) payload callback))
|
||||
|
||||
(defn call-private-rpc [payload callback]
|
||||
|
@ -161,62 +184,77 @@
|
|||
(defn hash-transaction
|
||||
"used for keycard"
|
||||
[rpcParams callback]
|
||||
(log/debug "[native-module] hash-transaction")
|
||||
(.hashTransaction (status) rpcParams callback))
|
||||
|
||||
(defn hash-message
|
||||
"used for keycard"
|
||||
[message callback]
|
||||
(log/debug "[native-module] hash-message")
|
||||
(.hashMessage (status) message callback))
|
||||
|
||||
(defn hash-typed-data
|
||||
"used for keycard"
|
||||
[data callback]
|
||||
(log/debug "[native-module] hash-typed-data")
|
||||
(.hashTypedData (status) data callback))
|
||||
|
||||
(defn send-transaction-with-signature
|
||||
"used for keycard"
|
||||
[rpcParams sig callback]
|
||||
(log/debug "[native-module] send-transaction-with-signature")
|
||||
(.sendTransactionWithSignature (status) rpcParams sig callback))
|
||||
|
||||
(defn sign-message
|
||||
"NOTE: beware, the password in rpcParams has to be sha3 hashed"
|
||||
[rpcParams callback]
|
||||
(log/debug "[native-module] sign-message")
|
||||
(.signMessage (status) rpcParams callback))
|
||||
|
||||
(defn send-transaction
|
||||
"NOTE: beware, the password has to be sha3 hashed"
|
||||
[rpcParams hashed-password callback]
|
||||
(log/debug "[native-module] send-transaction")
|
||||
(.sendTransaction (status) rpcParams hashed-password callback))
|
||||
|
||||
(defn sign-typed-data
|
||||
"NOTE: beware, the password has to be sha3 hashed"
|
||||
[data account hashed-password callback]
|
||||
(log/debug "[native-module] clear-web-data")
|
||||
(.signTypedData (status) data account hashed-password callback))
|
||||
|
||||
(defn send-logs [dbJson js-logs callback]
|
||||
(log/debug "[native-module] send-logs")
|
||||
(.sendLogs (status) dbJson js-logs callback))
|
||||
|
||||
(defn add-peer [enode on-result]
|
||||
(log/debug "[native-module] add-peer")
|
||||
(.addPeer (status) enode on-result))
|
||||
|
||||
(defn close-application []
|
||||
(log/debug "[native-module] close-application")
|
||||
(.closeApplication (status)))
|
||||
|
||||
(defn connection-change [type expensive?]
|
||||
(log/debug "[native-module] connection-change")
|
||||
(.connectionChange (status) type (boolean expensive?)))
|
||||
|
||||
(defn app-state-change [state]
|
||||
(log/debug "[native-module] app-state-change")
|
||||
(.appStateChange (status) state))
|
||||
|
||||
(defn set-blank-preview-flag [flag]
|
||||
(log/debug "[native-module] set-blank-preview-flag")
|
||||
(.setBlankPreviewFlag (status) flag))
|
||||
|
||||
(defn is24Hour []
|
||||
(log/debug "[native-module] is24Hour")
|
||||
;;NOTE: we have to check for status module because of tests
|
||||
(when (status)
|
||||
(.-is24Hour (status))))
|
||||
|
||||
(defn get-device-model-info []
|
||||
(log/debug "[native-module] get-device-model-info")
|
||||
;;NOTE: we have to check for status module because of tests
|
||||
(when (status)
|
||||
{:model (.-model (status))
|
||||
|
@ -226,23 +264,29 @@
|
|||
|
||||
(defn extract-group-membership-signatures
|
||||
[signature-pairs callback]
|
||||
(log/debug "[native-module] extract-group-membership-signatures")
|
||||
(.extractGroupMembershipSignatures (status) signature-pairs callback))
|
||||
|
||||
(defn sign-group-membership [content callback]
|
||||
(log/debug "[native-module] sign-group-membership")
|
||||
(.signGroupMembership (status) content callback))
|
||||
|
||||
(defn update-mailservers
|
||||
[enodes on-result]
|
||||
(log/debug "[native-module] update-mailservers")
|
||||
(.updateMailservers (status) enodes on-result))
|
||||
|
||||
(defn chaos-mode-update [on on-result]
|
||||
(log/debug "[native-module] chaos-mode-update")
|
||||
(.chaosModeUpdate (status) on on-result))
|
||||
|
||||
(defn get-nodes-from-contract
|
||||
[rpc-endpoint contract-address on-result]
|
||||
(log/debug "[native-module] get-nodes-from-contract")
|
||||
(.getNodesFromContract (status) rpc-endpoint contract-address on-result))
|
||||
|
||||
(defn rooted-device? [callback]
|
||||
(log/debug "[native-module] rooted-device?")
|
||||
(cond
|
||||
;; we assume that iOS is safe by default
|
||||
platform/ios?
|
||||
|
@ -267,9 +311,11 @@
|
|||
"Generate a 3 words random name based on the user public-key, synchronously"
|
||||
[public-key]
|
||||
{:pre [(utils.db/valid-public-key? public-key)]}
|
||||
(log/debug "[native-module] generate-gfycat")
|
||||
(.generateAlias (status) public-key))
|
||||
|
||||
(defn identicon
|
||||
"Generate a icon based on a string, synchronously"
|
||||
[seed]
|
||||
(log/debug "[native-module] identicon")
|
||||
(.identicon (status) seed))
|
||||
|
|
Loading…
Reference in New Issue