mirror of
https://github.com/status-im/status-mobile.git
synced 2025-03-01 16:50:58 +00:00
fix(key-pairs)_: error message on scanning different key pair QR (#20612)
This commit: - update the connection string validation method to use the method from status-go - updates the error message if the user tries to scan a different key pair QR for importing a missing key pair - updates the text for exporting an individual key pair Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com>
This commit is contained in:
parent
072370b0d6
commit
866b854ee0
@ -153,4 +153,9 @@ class Utils(private val reactContext: ReactApplicationContext) : ReactContextBas
|
|||||||
|
|
||||||
return strArray
|
return strArray
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
||||||
|
fun validateConnectionString(connectionString: String): String {
|
||||||
|
return Statusgo.validateConnectionString(connectionString)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,4 +128,8 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(toChecksumAddress:(NSString *)address) {
|
|||||||
return StatusgoToChecksumAddress(address);
|
return StatusgoToChecksumAddress(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(validateConnectionString:(NSString *)cs) {
|
||||||
|
return StatusgoValidateConnectionString(cs);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -543,6 +543,13 @@
|
|||||||
(log/debug "[native-module] validate-mnemonic")
|
(log/debug "[native-module] validate-mnemonic")
|
||||||
(.validateMnemonic ^js (utils) mnemonic callback)))
|
(.validateMnemonic ^js (utils) mnemonic callback)))
|
||||||
|
|
||||||
|
(defn validate-connection-string
|
||||||
|
[connection-string]
|
||||||
|
(log/debug "[native-module] validate-connection-string")
|
||||||
|
(->> connection-string
|
||||||
|
(.validateConnectionString ^js (utils))
|
||||||
|
types/json->clj))
|
||||||
|
|
||||||
(defn delete-multiaccount
|
(defn delete-multiaccount
|
||||||
"Delete multiaccount from database, deletes multiaccount's database and
|
"Delete multiaccount from database, deletes multiaccount's database and
|
||||||
key files."
|
key files."
|
||||||
@ -653,7 +660,6 @@
|
|||||||
(native-utils/promisify-native-module-call create-account-from-private-key private-key))
|
(native-utils/promisify-native-module-call create-account-from-private-key private-key))
|
||||||
([private-key callback]
|
([private-key callback]
|
||||||
(log/debug "[native-module] create-account-from-private-key")
|
(log/debug "[native-module] create-account-from-private-key")
|
||||||
|
|
||||||
(.createAccountFromPrivateKey ^js (account-manager)
|
(.createAccountFromPrivateKey ^js (account-manager)
|
||||||
(types/clj->json {:privateKey private-key})
|
(types/clj->json {:privateKey private-key})
|
||||||
callback)))
|
callback)))
|
||||||
|
@ -35,7 +35,9 @@
|
|||||||
user-in-syncing-devices-screen? (or (= (:view-id db) :screen/onboarding.syncing-progress)
|
user-in-syncing-devices-screen? (or (= (:view-id db) :screen/onboarding.syncing-progress)
|
||||||
(= (:view-id db) :screen/profile.profiles)
|
(= (:view-id db) :screen/profile.profiles)
|
||||||
(= (:view-id db) :screen/onboarding.syncing-progress-intro))
|
(= (:view-id db) :screen/onboarding.syncing-progress-intro))
|
||||||
user-in-sign-in-intro-screen? (= (:view-id db) :screen/onboarding.sign-in-intro)]
|
user-in-sign-in-intro-screen? (= (:view-id db) :screen/onboarding.sign-in-intro)
|
||||||
|
keystore-files-transfer-action? (= action
|
||||||
|
constants/local-pairing-action-keystore-files-transfer)]
|
||||||
(merge {:db (cond-> db
|
(merge {:db (cond-> db
|
||||||
connection-success?
|
connection-success?
|
||||||
(assoc-in [:syncing :pairing-status] :connected)
|
(assoc-in [:syncing :pairing-status] :connected)
|
||||||
@ -61,7 +63,7 @@
|
|||||||
(and completed-pairing? receiver?)
|
(and completed-pairing? receiver?)
|
||||||
{:dispatch [:profile.login/local-paired-user]}
|
{:dispatch [:profile.login/local-paired-user]}
|
||||||
|
|
||||||
(and error-on-pairing? (some? error))
|
(and error-on-pairing? (some? error) (not keystore-files-transfer-action?))
|
||||||
{:dispatch [:toasts/upsert
|
{:dispatch [:toasts/upsert
|
||||||
{:type :negative
|
{:type :negative
|
||||||
:text error}]}))))
|
:text error}]}))))
|
||||||
|
@ -370,16 +370,18 @@
|
|||||||
(def ^:const local-pairing-role-receiver "receiver")
|
(def ^:const local-pairing-role-receiver "receiver")
|
||||||
|
|
||||||
;; sender and receiver events
|
;; sender and receiver events
|
||||||
|
(def ^:const local-pairing-event-peer-discovered "peer-discovered")
|
||||||
(def ^:const local-pairing-event-connection-success "connection-success")
|
(def ^:const local-pairing-event-connection-success "connection-success")
|
||||||
(def ^:const local-pairing-event-connection-error "connection-error")
|
(def ^:const local-pairing-event-connection-error "connection-error")
|
||||||
(def ^:const local-pairing-event-transfer-success "transfer-success")
|
(def ^:const local-pairing-event-transfer-success "transfer-success")
|
||||||
(def ^:const local-pairing-event-transfer-error "transfer-error")
|
(def ^:const local-pairing-event-transfer-error "transfer-error")
|
||||||
|
(def ^:const local-pairing-event-received-installation "received-installation")
|
||||||
|
|
||||||
;; receiver events
|
;; receiver events
|
||||||
(def ^:const local-pairing-event-received-account "received-account")
|
(def ^:const local-pairing-event-received-account "received-account")
|
||||||
(def ^:const local-pairing-event-process-success "process-success")
|
(def ^:const local-pairing-event-process-success "process-success")
|
||||||
(def ^:const local-pairing-event-process-error "process-error")
|
(def ^:const local-pairing-event-process-error "process-error")
|
||||||
(def ^:const local-pairing-event-received-installation "received-installation")
|
(def ^:const local-pairing-event-received-keystore-files "received-keystore-files")
|
||||||
|
|
||||||
(def ^:const local-pairing-event-errors
|
(def ^:const local-pairing-event-errors
|
||||||
#{local-pairing-event-connection-error
|
#{local-pairing-event-connection-error
|
||||||
@ -390,6 +392,8 @@
|
|||||||
(def ^:const local-pairing-action-pairing-account 2)
|
(def ^:const local-pairing-action-pairing-account 2)
|
||||||
(def ^:const local-pairing-action-sync-device 3)
|
(def ^:const local-pairing-action-sync-device 3)
|
||||||
(def ^:const local-pairing-action-pairing-installation 4)
|
(def ^:const local-pairing-action-pairing-installation 4)
|
||||||
|
(def ^:const local-pairing-action-peer-discovery 5)
|
||||||
|
(def ^:const local-pairing-action-keystore-files-transfer 6)
|
||||||
|
|
||||||
(def ^:const serialization-key
|
(def ^:const serialization-key
|
||||||
"We pass this serialization key as a parameter to MultiformatSerializePublicKey
|
"We pass this serialization key as a parameter to MultiformatSerializePublicKey
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
(ns status-im.contexts.settings.wallet.events
|
(ns status-im.contexts.settings.wallet.events
|
||||||
(:require
|
(:require
|
||||||
|
[clojure.string :as string]
|
||||||
[native-module.core :as native-module]
|
[native-module.core :as native-module]
|
||||||
[status-im.contexts.settings.wallet.data-store :as data-store]
|
[status-im.contexts.settings.wallet.data-store :as data-store]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
@ -91,7 +92,37 @@
|
|||||||
|
|
||||||
(rf/reg-event-fx :wallet/make-keypairs-accounts-fully-operable make-keypairs-accounts-fully-operable)
|
(rf/reg-event-fx :wallet/make-keypairs-accounts-fully-operable make-keypairs-accounts-fully-operable)
|
||||||
|
|
||||||
(defn connection-string-for-import-keypair
|
|
||||||
|
(rf/reg-event-fx :wallet/connection-string-for-import-keypairs-failed
|
||||||
|
(fn [{:keys [db]} [keypairs-key-uids error]]
|
||||||
|
(let [error-message (-> error ex-data :error)
|
||||||
|
incorrect-keypair? (string/includes?
|
||||||
|
error-message
|
||||||
|
"one or more expected keystore files are not found among the sent files")
|
||||||
|
single-keypair-to-update? (= (count keypairs-key-uids) 1)
|
||||||
|
keypair-name (when single-keypair-to-update?
|
||||||
|
(let [key-uid (first keypairs-key-uids)]
|
||||||
|
(get-in db [:wallet :keypairs key-uid :name])))
|
||||||
|
toast-message (cond
|
||||||
|
(and single-keypair-to-update? incorrect-keypair?)
|
||||||
|
(i18n/label
|
||||||
|
:t/this-qr-does-not-contain-key-pair
|
||||||
|
{:name keypair-name})
|
||||||
|
|
||||||
|
(and (not single-keypair-to-update?) incorrect-keypair?)
|
||||||
|
(i18n/label
|
||||||
|
:t/this-qr-does-not-contain-any-missing-key-pair)
|
||||||
|
|
||||||
|
:else
|
||||||
|
error-message)]
|
||||||
|
(log/error "failed to import missing key pairs with connection string"
|
||||||
|
{:error error-message})
|
||||||
|
(rf/dispatch [:toasts/upsert
|
||||||
|
{:type :negative
|
||||||
|
:theme :dark
|
||||||
|
:text toast-message}]))))
|
||||||
|
|
||||||
|
(defn connection-string-for-import-keypairs
|
||||||
[{:keys [db]} [{:keys [sha3-pwd keypairs-key-uids connection-string]}]]
|
[{:keys [db]} [{:keys [sha3-pwd keypairs-key-uids connection-string]}]]
|
||||||
(let [key-uid (get-in db [:profile/profile :key-uid])]
|
(let [key-uid (get-in db [:profile/profile :key-uid])]
|
||||||
{:fx [[:effects.syncing/import-keypairs-keystores
|
{:fx [[:effects.syncing/import-keypairs-keystores
|
||||||
@ -102,14 +133,11 @@
|
|||||||
:on-success (fn [key-uids]
|
:on-success (fn [key-uids]
|
||||||
(rf/dispatch [:wallet/make-keypairs-accounts-fully-operable key-uids]))
|
(rf/dispatch [:wallet/make-keypairs-accounts-fully-operable key-uids]))
|
||||||
:on-fail (fn [error]
|
:on-fail (fn [error]
|
||||||
(log/error "failed to import missing key pairs with connection string"
|
(rf/dispatch [:wallet/connection-string-for-import-keypairs-failed
|
||||||
{:error error})
|
keypairs-key-uids
|
||||||
(rf/dispatch [:toasts/upsert
|
error]))}]]}))
|
||||||
{:type :negative
|
|
||||||
:theme :dark
|
|
||||||
:text (i18n/label :t/incorrect-qr-code)}]))}]]}))
|
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/connection-string-for-import-keypair connection-string-for-import-keypair)
|
(rf/reg-event-fx :wallet/connection-string-for-import-keypairs connection-string-for-import-keypairs)
|
||||||
|
|
||||||
(defn success-keypair-qr-scan
|
(defn success-keypair-qr-scan
|
||||||
[_ [connection-string keypairs-key-uids]]
|
[_ [connection-string keypairs-key-uids]]
|
||||||
@ -121,7 +149,7 @@
|
|||||||
:on-auth-success (fn [password]
|
:on-auth-success (fn [password]
|
||||||
(rf/dispatch [:hide-bottom-sheet])
|
(rf/dispatch [:hide-bottom-sheet])
|
||||||
(rf/dispatch
|
(rf/dispatch
|
||||||
[:wallet/connection-string-for-import-keypair
|
[:wallet/connection-string-for-import-keypairs
|
||||||
{:connection-string connection-string
|
{:connection-string connection-string
|
||||||
:keypairs-key-uids keypairs-key-uids
|
:keypairs-key-uids keypairs-key-uids
|
||||||
:sha3-pwd password}]))}]]]})
|
:sha3-pwd password}]))}]]]})
|
||||||
|
@ -83,7 +83,7 @@
|
|||||||
:on-success fn?
|
:on-success fn?
|
||||||
:on-fail fn?}]]}]
|
:on-fail fn?}]]}]
|
||||||
(is (match? expected
|
(is (match? expected
|
||||||
(sut/connection-string-for-import-keypair cofx
|
(sut/connection-string-for-import-keypairs cofx
|
||||||
[{:sha3-pwd sha3-pwd
|
[{:sha3-pwd sha3-pwd
|
||||||
:keypairs-key-uids [test-keypair-key-uid]
|
:keypairs-key-uids [test-keypair-key-uid]
|
||||||
:connection-string
|
:connection-string
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
[{:blur? true
|
[{:blur? true
|
||||||
:icon :i/qr-code
|
:icon :i/qr-code
|
||||||
:accessibility-label :show-key-pr-qr
|
:accessibility-label :show-key-pr-qr
|
||||||
:label (i18n/label :t/show-encrypted-qr-of-key-pairs)
|
:label (i18n/label :t/show-encrypted-qr-of-key-pair)
|
||||||
:on-press on-show-qr}]
|
:on-press on-show-qr}]
|
||||||
[{:blur? true
|
[{:blur? true
|
||||||
:icon :i/scan
|
:icon :i/scan
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
(ns status-im.contexts.syncing.utils
|
(ns status-im.contexts.syncing.utils
|
||||||
(:require
|
(:require
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[status-im.constants :as constants]
|
[native-module.core :as native-module]
|
||||||
[utils.transforms :as transforms]))
|
[utils.transforms :as transforms]))
|
||||||
|
|
||||||
|
(defn validate-connection-string
|
||||||
|
[connection-string]
|
||||||
|
(native-module/validate-connection-string
|
||||||
|
connection-string))
|
||||||
|
|
||||||
(defn valid-connection-string?
|
(defn valid-connection-string?
|
||||||
[connection-string]
|
[connection-string]
|
||||||
(when connection-string
|
(some-> connection-string
|
||||||
(string/starts-with?
|
validate-connection-string
|
||||||
connection-string
|
string/blank?))
|
||||||
constants/local-pairing-connection-string-identifier)))
|
|
||||||
|
|
||||||
(defn extract-error
|
(defn extract-error
|
||||||
[json-str]
|
[json-str]
|
||||||
|
@ -1311,7 +1311,8 @@
|
|||||||
"scan-key-pairs-qr-code": "Scan key pairs QR code",
|
"scan-key-pairs-qr-code": "Scan key pairs QR code",
|
||||||
"invalid-qr": "Oops! This QR doesn’t work with Status",
|
"invalid-qr": "Oops! This QR doesn’t work with Status",
|
||||||
"invalid-key-pair-qr": "This does not look like a key pair QR code",
|
"invalid-key-pair-qr": "This does not look like a key pair QR code",
|
||||||
"incorrect-qr-code": "This is not the QR code you are looking for",
|
"this-qr-does-not-contain-key-pair": "This QR does not contain {{name}} key pair",
|
||||||
|
"this-qr-does-not-contain-any-missing-key-pair": "This QR does not contain any missing key pairs",
|
||||||
"search": "Search",
|
"search": "Search",
|
||||||
"search-discover-communities": "Search communities or categories",
|
"search-discover-communities": "Search communities or categories",
|
||||||
"secret-keys-confirmation-text": "You will need them to continue to use your Keycard in case you ever lose your phone.",
|
"secret-keys-confirmation-text": "You will need them to continue to use your Keycard in case you ever lose your phone.",
|
||||||
@ -1363,7 +1364,7 @@
|
|||||||
"show-more": "Show more",
|
"show-more": "Show more",
|
||||||
"show-qr": "Show QR code",
|
"show-qr": "Show QR code",
|
||||||
"show-transaction-data": "Show transaction data",
|
"show-transaction-data": "Show transaction data",
|
||||||
"show-encrypted-qr-of-key-pairs": "Show encrypted QR of key pairs on device",
|
"show-encrypted-qr-of-key-pair": "Show encrypted QR of key pair",
|
||||||
"sign-and-send": "Sign and send",
|
"sign-and-send": "Sign and send",
|
||||||
"sign-in": "Sign in",
|
"sign-in": "Sign in",
|
||||||
"sign-message": "Sign Message",
|
"sign-message": "Sign Message",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user