Skip to content

Commit

Permalink
[#9025] fix keycard pairings persistence
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Novotochinov <dmitry.novot@gmail.com>
  • Loading branch information
dmitryn committed Oct 8, 2019
1 parent 696df8e commit 7252ae5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/status_im/hardwallet/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@
[{:keys [db] :as cofx} flow instance-uid]
(if (= flow :import)
(navigation/navigate-to-cofx cofx :keycard-recovery-no-key nil)
(let [pairing-data (get-in db [:hardwallet :pairings (keyword instance-uid)])]
(let [pairing-data (get-in db [:hardwallet :pairings instance-uid])]
(if pairing-data
(fx/merge cofx
{:db (update-in db [:hardwallet :secrets] merge pairing-data)}
Expand Down Expand Up @@ -1499,21 +1499,27 @@
{:db (assoc-in db [:hardwallet :pairings] pairings)})

(fx/defn on-pair-success
"When pairing to device has completed, we need to persist pairing data to
local storage. That's needed to ensure that during keycard setup
keycard won't run out of pairings slots, ie. we don't pair the same
card to the same device more than one time. Also, this allows the user to proceed
with setup and skip the pairing step if the pairing was already done during a previous
unfinished setup."
[{:keys [db] :as cofx} pairing]
(let [setup-step (get-in db [:hardwallet :setup-step])
flow (get-in db [:hardwallet :flow])
instance-uid (get-in db [:hardwallet :application-info :instance-uid])
multiaccount (find-multiaccount-by-keycard-instance-uid db instance-uid)
paired-on (utils.datetime/timestamp)
pairings (get-in db [:hardwallet :pairings])
instance-uid (get-in db [:hardwallet :application-info :instance-uid])
pairings (assoc (get-in db [:hardwallet :pairings]) instance-uid {:pairing pairing
:paired-on paired-on})
next-step (if (= setup-step :pair)
:begin
:card-ready)]
(fx/merge cofx
{:hardwallet/persist-pairings (assoc pairings instance-uid {:pairing pairing
:paired-on paired-on})
{:hardwallet/persist-pairings pairings
: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)
Expand Down

0 comments on commit 7252ae5

Please sign in to comment.