[#13992] Delete account only after moving keys to keyacard
This commit is contained in:
parent
faaf6d5f94
commit
7f1e83672e
|
@ -505,3 +505,6 @@
|
||||||
|
|
||||||
(defn set-nfc-message [args]
|
(defn set-nfc-message [args]
|
||||||
(keycard/set-nfc-message card args))
|
(keycard/set-nfc-message card args))
|
||||||
|
|
||||||
|
(defn delete-multiaccount-before-migration [args]
|
||||||
|
(keycard/delete-multiaccount-before-migration card args))
|
||||||
|
|
|
@ -210,3 +210,7 @@
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:keycard/save-multiaccount-and-login
|
:keycard/save-multiaccount-and-login
|
||||||
card/save-multiaccount-and-login)
|
card/save-multiaccount-and-login)
|
||||||
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
:keycard/delete-multiaccount-before-migration
|
||||||
|
card/delete-multiaccount-before-migration)
|
||||||
|
|
|
@ -38,4 +38,5 @@
|
||||||
(sign-typed-data [this args])
|
(sign-typed-data [this args])
|
||||||
(save-multiaccount-and-login [this args])
|
(save-multiaccount-and-login [this args])
|
||||||
(login [this args])
|
(login [this args])
|
||||||
(send-transaction-with-signature [this args]))
|
(send-transaction-with-signature [this args])
|
||||||
|
(delete-multiaccount-before-migration [this args]))
|
||||||
|
|
|
@ -269,7 +269,9 @@
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:keycard/generate-and-load-key
|
{:keycard/generate-and-load-key
|
||||||
{:mnemonic mnemonic
|
{:mnemonic mnemonic
|
||||||
:pin pin'}})))
|
:pin pin'
|
||||||
|
:key-uid (:key-uid multiaccount)
|
||||||
|
:delete-multiaccount? (get-in db [:keycard :delete-account?])}})))
|
||||||
|
|
||||||
(fx/defn factory-reset-card-toggle
|
(fx/defn factory-reset-card-toggle
|
||||||
{:events [:keycard.onboarding.intro.ui/factory-reset-card-toggle]}
|
{:events [:keycard.onboarding.intro.ui/factory-reset-card-toggle]}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
[status-im.native-module.core :as status]
|
[status-im.native-module.core :as status]
|
||||||
[status-im.utils.platform :as platform]
|
[status-im.utils.platform :as platform]
|
||||||
[status-im.utils.types :as types]
|
[status-im.utils.types :as types]
|
||||||
|
[clojure.string :as string]
|
||||||
[taoensso.timbre :as log]))
|
[taoensso.timbre :as log]))
|
||||||
|
|
||||||
(defonce event-emitter (if platform/ios?
|
(defonce event-emitter (if platform/ios?
|
||||||
|
@ -296,6 +297,16 @@
|
||||||
[{:keys [transaction signature on-completed]}]
|
[{:keys [transaction signature on-completed]}]
|
||||||
(status/send-transaction-with-signature transaction signature on-completed))
|
(status/send-transaction-with-signature transaction signature on-completed))
|
||||||
|
|
||||||
|
(defn delete-multiaccount-before-migration
|
||||||
|
[{:keys [key-uid on-success on-error]}]
|
||||||
|
(status/delete-multiaccount
|
||||||
|
key-uid
|
||||||
|
(fn [result]
|
||||||
|
(let [{:keys [error]} (types/json->clj result)]
|
||||||
|
(if-not (string/blank? error)
|
||||||
|
(on-error error)
|
||||||
|
(on-success))))))
|
||||||
|
|
||||||
(defrecord RealKeycard []
|
(defrecord RealKeycard []
|
||||||
keycard/Keycard
|
keycard/Keycard
|
||||||
(keycard/start-nfc [_this args]
|
(keycard/start-nfc [_this args]
|
||||||
|
@ -373,4 +384,6 @@
|
||||||
(keycard/login [_this args]
|
(keycard/login [_this args]
|
||||||
(login args))
|
(login args))
|
||||||
(keycard/send-transaction-with-signature [_this args]
|
(keycard/send-transaction-with-signature [_this args]
|
||||||
(send-transaction-with-signature args)))
|
(send-transaction-with-signature args))
|
||||||
|
(keycard/delete-multiaccount-before-migration [_ args]
|
||||||
|
(delete-multiaccount-before-migration args)))
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
[status-im.ethereum.core :as ethereum]
|
[status-im.ethereum.core :as ethereum]
|
||||||
[status-im.bottom-sheet.core :as bottom-sheet]
|
[status-im.bottom-sheet.core :as bottom-sheet]
|
||||||
[status-im.native-module.core :as status]
|
[status-im.native-module.core :as status]
|
||||||
|
[status-im.popover.core :as popover]
|
||||||
[status-im.utils.types :as types]
|
[status-im.utils.types :as types]
|
||||||
[status-im.utils.security :as security]
|
[status-im.utils.security :as security]
|
||||||
[status-im.utils.keychain.core :as keychain]
|
[status-im.utils.keychain.core :as keychain]
|
||||||
|
@ -146,6 +147,9 @@
|
||||||
(intro-wizard)))
|
(intro-wizard)))
|
||||||
|
|
||||||
(fx/defn create-keycard-multiaccount
|
(fx/defn create-keycard-multiaccount
|
||||||
|
{:events [::create-keycard-multiaccount]
|
||||||
|
:interceptors [(re-frame/inject-cofx :random-guid-generator)
|
||||||
|
(re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]}
|
||||||
[{:keys [db] :as cofx}]
|
[{:keys [db] :as cofx}]
|
||||||
(let [{{:keys [multiaccount secrets flow]} :keycard} db
|
(let [{{:keys [multiaccount secrets flow]} :keycard} db
|
||||||
{:keys [address
|
{:keys [address
|
||||||
|
@ -271,6 +275,19 @@
|
||||||
(dissoc :recovered-account?))
|
(dissoc :recovered-account?))
|
||||||
::finish-migration [account settings password encryption-pass login-params]}))
|
::finish-migration [account settings password encryption-pass login-params]}))
|
||||||
|
|
||||||
|
(fx/defn delete-multiaccount
|
||||||
|
[{:keys [db]}]
|
||||||
|
(let [key-uid (get-in db [:multiaccounts/login :key-uid])]
|
||||||
|
{:keycard/delete-multiaccount-before-migration
|
||||||
|
{:key-uid key-uid
|
||||||
|
:on-error #(re-frame/dispatch [::delete-multiaccount-error %])
|
||||||
|
:on-success #(re-frame/dispatch [::create-keycard-multiaccount])}}))
|
||||||
|
|
||||||
|
(fx/defn handle-delete-multiaccount-error
|
||||||
|
{:events [::delete-multiaccount-error]}
|
||||||
|
[cofx _]
|
||||||
|
(popover/show-popover cofx {:view :transfer-multiaccount-unknown-error}))
|
||||||
|
|
||||||
(fx/defn on-generate-and-load-key-success
|
(fx/defn on-generate-and-load-key-success
|
||||||
{:events [:keycard.callback/on-generate-and-load-key-success]
|
{:events [:keycard.callback/on-generate-and-load-key-success]
|
||||||
:interceptors [(re-frame/inject-cofx :random-guid-generator)
|
:interceptors [(re-frame/inject-cofx :random-guid-generator)
|
||||||
|
@ -304,6 +321,10 @@
|
||||||
(common/hide-connection-sheet)
|
(common/hide-connection-sheet)
|
||||||
(cond backup? (on-backup-success backup?)
|
(cond backup? (on-backup-success backup?)
|
||||||
migration? (migrate-account)
|
migration? (migrate-account)
|
||||||
|
|
||||||
|
(get-in db [:keycard :delete-account?])
|
||||||
|
(delete-multiaccount)
|
||||||
|
|
||||||
:else (create-keycard-multiaccount)))))
|
:else (create-keycard-multiaccount)))))
|
||||||
|
|
||||||
(fx/defn on-generate-and-load-key-error
|
(fx/defn on-generate-and-load-key-error
|
||||||
|
@ -330,7 +351,8 @@
|
||||||
(assoc-in [:keycard :pin :status] :verifying)
|
(assoc-in [:keycard :pin :status] :verifying)
|
||||||
(assoc-in [:keycard :secrets] {:pairing pairing'
|
(assoc-in [:keycard :secrets] {:pairing pairing'
|
||||||
:paired-on (utils.datetime/timestamp)}))
|
:paired-on (utils.datetime/timestamp)}))
|
||||||
:keycard/import-keys {:pin pin
|
:keycard/import-keys
|
||||||
|
{:pin pin
|
||||||
:on-success :keycard.callback/on-generate-and-load-key-success}})))
|
:on-success :keycard.callback/on-generate-and-load-key-success}})))
|
||||||
|
|
||||||
(fx/defn load-recovering-key-screen
|
(fx/defn load-recovering-key-screen
|
||||||
|
|
|
@ -247,13 +247,27 @@
|
||||||
(later #(on-success (str (rand-int 10000000))))))
|
(later #(on-success (str (rand-int 10000000))))))
|
||||||
|
|
||||||
(defn generate-and-load-key
|
(defn generate-and-load-key
|
||||||
[{:keys [pin on-success]}]
|
[{:keys [pin on-success key-uid delete-multiaccount?]}]
|
||||||
(when (= pin (get @state :pin))
|
(when (= pin (get @state :pin))
|
||||||
(let [[id response] (multiaccount->keys
|
(let [[id response] (multiaccount->keys
|
||||||
(:intro-wizard @re-frame.db/app-db))]
|
(:intro-wizard @re-frame.db/app-db))]
|
||||||
(log/debug "[simulated kk] generate-and-load-key response" response)
|
(log/debug "[simulated kk] generate-and-load-key response" response)
|
||||||
(swap! state assoc-in
|
(swap! state assoc-in
|
||||||
[:application-info :key-uid] (:key-uid response))
|
[:application-info :key-uid] (:key-uid response))
|
||||||
|
(let [deletion-wrapper
|
||||||
|
(if delete-multiaccount?
|
||||||
|
(fn [on-deletion-success]
|
||||||
|
(js/alert "OH SHEET")
|
||||||
|
(status/delete-multiaccount
|
||||||
|
key-uid
|
||||||
|
(fn [result]
|
||||||
|
(let [{:keys [error]} (types/json->clj result)]
|
||||||
|
(if-not (string/blank? error)
|
||||||
|
(log/error error)
|
||||||
|
(on-deletion-success))))))
|
||||||
|
(fn [cb] (cb)))]
|
||||||
|
(deletion-wrapper
|
||||||
|
(fn []
|
||||||
(status/multiaccount-store-derived
|
(status/multiaccount-store-derived
|
||||||
id
|
id
|
||||||
(:key-uid response)
|
(:key-uid response)
|
||||||
|
@ -262,7 +276,7 @@
|
||||||
constants/path-whisper
|
constants/path-whisper
|
||||||
constants/path-default-wallet]
|
constants/path-default-wallet]
|
||||||
account-password
|
account-password
|
||||||
#(on-success response)))))
|
#(on-success response))))))))
|
||||||
|
|
||||||
(defn unblock-pin
|
(defn unblock-pin
|
||||||
[{:keys [puk new-pin on-success on-failure]}]
|
[{:keys [puk new-pin on-success on-failure]}]
|
||||||
|
@ -438,6 +452,10 @@
|
||||||
[{:keys [transaction on-completed]}]
|
[{:keys [transaction on-completed]}]
|
||||||
(status/send-transaction transaction account-password on-completed))
|
(status/send-transaction transaction account-password on-completed))
|
||||||
|
|
||||||
|
(defn delete-multiaccount-before-migration
|
||||||
|
[{:keys [on-success]}]
|
||||||
|
(on-success))
|
||||||
|
|
||||||
(defrecord SimulatedKeycard []
|
(defrecord SimulatedKeycard []
|
||||||
keycard/Keycard
|
keycard/Keycard
|
||||||
(keycard/start-nfc [_this args]
|
(keycard/start-nfc [_this args]
|
||||||
|
@ -547,4 +565,7 @@
|
||||||
(login args))
|
(login args))
|
||||||
(keycard/send-transaction-with-signature [_this args]
|
(keycard/send-transaction-with-signature [_this args]
|
||||||
(log/debug "simulated card send-transaction-with-signature")
|
(log/debug "simulated card send-transaction-with-signature")
|
||||||
(send-transaction-with-signature args)))
|
(send-transaction-with-signature args))
|
||||||
|
(keycard/delete-multiaccount-before-migration [_ args]
|
||||||
|
(log/debug "simulated card delete-multiaccount-before-migration")
|
||||||
|
(delete-multiaccount-before-migration args)))
|
||||||
|
|
|
@ -133,17 +133,6 @@
|
||||||
[{:keys [db]} selected?]
|
[{:keys [db]} selected?]
|
||||||
{:db (assoc-in db [:multiaccounts/key-storage :keycard-storage-selected?] selected?)})
|
{:db (assoc-in db [:multiaccounts/key-storage :keycard-storage-selected?] selected?)})
|
||||||
|
|
||||||
(re-frame/reg-fx
|
|
||||||
::delete-multiaccount
|
|
||||||
(fn [{:keys [key-uid on-success on-error]}]
|
|
||||||
(native-module/delete-multiaccount
|
|
||||||
key-uid
|
|
||||||
(fn [result]
|
|
||||||
(let [{:keys [error]} (types/json->clj result)]
|
|
||||||
(if-not (string/blank? error)
|
|
||||||
(on-error error)
|
|
||||||
(on-success)))))))
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::delete-imported-key
|
::delete-imported-key
|
||||||
(fn [{:keys [key-uid address password on-success on-error]}]
|
(fn [{:keys [key-uid address password on-success on-error]}]
|
||||||
|
@ -158,15 +147,6 @@
|
||||||
(on-error error)
|
(on-error error)
|
||||||
(on-success))))))))
|
(on-success))))))))
|
||||||
|
|
||||||
(fx/defn delete-multiaccount-and-init-keycard-onboarding
|
|
||||||
{:events [::delete-multiaccount-and-init-keycard-onboarding]}
|
|
||||||
[{:keys [db] :as cofx}]
|
|
||||||
(let [{:keys [key-uid]} (-> db :multiaccounts/login)]
|
|
||||||
{:db (assoc-in db [:multiaccounts/key-storage :reset-db-checked?] true)
|
|
||||||
::delete-multiaccount {:key-uid key-uid
|
|
||||||
:on-error #(re-frame/dispatch [::delete-multiaccount-error %])
|
|
||||||
:on-success #(re-frame/dispatch [::delete-multiaccount-success])}}))
|
|
||||||
|
|
||||||
#_"Multiaccount has been deleted from device. We now need to emulate the restore seed phrase process, and make the user land on Keycard setup screen.
|
#_"Multiaccount has been deleted from device. We now need to emulate the restore seed phrase process, and make the user land on Keycard setup screen.
|
||||||
To ensure that keycard setup works, we need to:
|
To ensure that keycard setup works, we need to:
|
||||||
1. Import multiaccount, derive required keys and save them at the correct location in app-db
|
1. Import multiaccount, derive required keys and save them at the correct location in app-db
|
||||||
|
@ -182,13 +162,21 @@ The exact events dispatched for this flow if consumed from the UI are:
|
||||||
We don't need to take the exact steps, just set the required state and redirect to correct screen
|
We don't need to take the exact steps, just set the required state and redirect to correct screen
|
||||||
"
|
"
|
||||||
(fx/defn import-multiaccount
|
(fx/defn import-multiaccount
|
||||||
{:events [::delete-multiaccount-success]}
|
|
||||||
[{:keys [db] :as cofx}]
|
[{:keys [db] :as cofx}]
|
||||||
{:dispatch [:bottom-sheet/hide]
|
{:dispatch [:bottom-sheet/hide]
|
||||||
::multiaccounts.recover/import-multiaccount {:passphrase (get-in db [:multiaccounts/key-storage :seed-phrase])
|
::multiaccounts.recover/import-multiaccount
|
||||||
|
{:passphrase (get-in db [:multiaccounts/key-storage :seed-phrase])
|
||||||
:password nil
|
:password nil
|
||||||
:success-event ::import-multiaccount-success}})
|
:success-event ::import-multiaccount-success}})
|
||||||
|
|
||||||
|
(fx/defn delete-multiaccount-and-init-keycard-onboarding
|
||||||
|
{:events [::delete-multiaccount-and-init-keycard-onboarding]}
|
||||||
|
[{:keys [db] :as cofx}]
|
||||||
|
(fx/merge
|
||||||
|
{:dispatch [:bottom-sheet/hide]
|
||||||
|
:db (assoc-in db [:multiaccounts/key-storage :reset-db-checked?] true)}
|
||||||
|
(import-multiaccount)))
|
||||||
|
|
||||||
(fx/defn storage-selected
|
(fx/defn storage-selected
|
||||||
{:events [::storage-selected]}
|
{:events [::storage-selected]}
|
||||||
[{:keys [db] :as cofx}]
|
[{:keys [db] :as cofx}]
|
||||||
|
@ -243,16 +231,13 @@ We don't need to take the exact steps, just set the required state and redirect
|
||||||
(assoc-in [:keycard :flow] :recovery)
|
(assoc-in [:keycard :flow] :recovery)
|
||||||
(assoc-in [:keycard :from-key-storage-and-migration?] true)
|
(assoc-in [:keycard :from-key-storage-and-migration?] true)
|
||||||
(assoc-in [:keycard :converting-account?] (not (get-in db [:multiaccounts/key-storage :reset-db-checked?])))
|
(assoc-in [:keycard :converting-account?] (not (get-in db [:multiaccounts/key-storage :reset-db-checked?])))
|
||||||
|
(assoc-in [:keycard :delete-account?]
|
||||||
|
(true? (get-in db [:multiaccounts/key-storage :reset-db-checked?])))
|
||||||
(dissoc :multiaccounts/key-storage))}
|
(dissoc :multiaccounts/key-storage))}
|
||||||
(popover/hide-popover)
|
(popover/hide-popover)
|
||||||
(common/listen-to-hardware-back-button)
|
(common/listen-to-hardware-back-button)
|
||||||
(navigation/navigate-to-cofx :keycard-onboarding-intro nil)))
|
(navigation/navigate-to-cofx :keycard-onboarding-intro nil)))
|
||||||
|
|
||||||
(fx/defn handle-delete-multiaccount-error
|
|
||||||
{:events [::delete-multiaccount-error]}
|
|
||||||
[cofx _]
|
|
||||||
(popover/show-popover cofx {:view :transfer-multiaccount-unknown-error}))
|
|
||||||
|
|
||||||
(fx/defn goto-multiaccounts-screen
|
(fx/defn goto-multiaccounts-screen
|
||||||
{:events [::hide-popover-and-goto-multiaccounts-screen]}
|
{:events [::hide-popover-and-goto-multiaccounts-screen]}
|
||||||
[cofx _]
|
[cofx _]
|
||||||
|
|
Loading…
Reference in New Issue