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