Skip to content

Commit

Permalink
fix: handle removing old accounts not associated with the updated key…
Browse files Browse the repository at this point in the history
…-pair
  • Loading branch information
seanstrom committed Jun 24, 2024
1 parent 7cab9da commit 12a707b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/status_im/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -560,17 +560,25 @@
removed-account-addresses
updated-keypairs-by-id
updated-accounts-by-address]} (data-store/process-keypairs keypairs)
new-account-addresses (clojure.set/difference
(set (keys updated-accounts-by-address))
(set (keys existing-accounts-by-address)))]
updated-keypair-ids (set (keys updated-keypairs-by-id))
updated-account-addresses (set (keys updated-accounts-by-address))
existing-account-addresses (set (keys existing-accounts-by-address))
new-account-addresses (clojure.set/difference updated-account-addresses
existing-account-addresses)
old-account-addresses (->> (vals existing-accounts-by-address)
(filter (fn [{:keys [address key-uid]}]
(and (contains? updated-keypair-ids key-uid)
(nil? (get updated-accounts-by-address
address)))))
(map :address))]
(cond-> {:db (-> db
(assoc-in [:wallet :keypairs]
(-> (partial dissoc existing-keypairs-by-id)
(apply removed-keypairs-ids)
(merge updated-keypairs-by-id)))
(assoc-in [:wallet :accounts]
(-> (partial dissoc existing-accounts-by-address)
(apply removed-account-addresses)
(apply (into removed-account-addresses old-account-addresses))
(merge updated-accounts-by-address))))}
(seq new-account-addresses)
(assoc :fx refresh-accounts-fx-dispatches))))
Expand Down
33 changes: 33 additions & 0 deletions src/status_im/contexts/wallet/events_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,39 @@
:type "seed"
:removed true
:accounts [raw-account]}]]))))
(testing "event removes accounts not present with key pair"
(reset! rf-db/app-db {:wallet {:accounts {(:address account) account
"1x001" (assoc account
:address "1x001"
:key-uid "0x001")}
:keypairs {keypair-key-uid
{:key-uid keypair-key-uid
:type :seed
:lowest-operability :fully
:accounts [account]}
"0x001"
{:key-uid "0x001"
:type :seed
:lowest-operability :fully
:accounts [(assoc account
:address "1x001"
:key-uid "0x001")]}}}})
(is
(match? {:db {:wallet {:accounts {(:address account) account}
:keypairs {keypair-key-uid
{:key-uid keypair-key-uid
:type :seed
:lowest-operability :fully
:accounts [account]}
"0x001"
{:key-uid "0x001"
:type :seed
:lowest-operability :fully
:accounts []}}}}}
(dispatch [event-id
[{:key-uid "0x001"
:type "seed"
:accounts []}]]))))
(testing "event updates existing key pairs"
(reset! rf-db/app-db {:wallet {:accounts {(:address account)
(assoc account :operable :no)}
Expand Down

0 comments on commit 12a707b

Please sign in to comment.