Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#9025] fix keycard pairings persistence #9052

Merged
merged 1 commit into from
Oct 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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])
dmitryn marked this conversation as resolved.
Show resolved Hide resolved
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