From 45c645082ee2883a47c52df8ec35dcd7c7fe5199 Mon Sep 17 00:00:00 2001 From: pacamara Date: Mon, 28 May 2018 18:37:11 +0100 Subject: [PATCH] Fixes #4223: No error when scanning incorrect public key QR code Signed-off-by: Pedro Pombeiro --- src/status_im/translations/en.cljs | 3 ++- src/status_im/ui/screens/contacts/events.cljs | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index 8d5c709028..1d74a9018f 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -342,7 +342,8 @@ :name "Name" :specify-name "Specify a name" :address-explication "Your public key is used to generate your address on Ethereum and is a series of numbers and letters. You can find it easily in your profile" - :use-valid-contact-code "Please enter a valid contact code" + :unable-to-read-this-code "Unable to read this code" + :use-valid-contact-code "Please scan a valid contact code" :enter-valid-public-key "Please enter a valid public key or scan a QR code" :contact-already-added "The contact has already been added" :can-not-add-yourself "You can't add yourself" diff --git a/src/status_im/ui/screens/contacts/events.cljs b/src/status_im/ui/screens/contacts/events.cljs index 9246944cb1..550034258c 100644 --- a/src/status_im/ui/screens/contacts/events.cljs +++ b/src/status_im/ui/screens/contacts/events.cljs @@ -1,5 +1,6 @@ (ns status-im.ui.screens.contacts.events (:require [re-frame.core :as re-frame] + [status-im.i18n :as i18n] [status-im.chat.events :as chat.events] [status-im.data-store.contacts :as contacts-store] [status-im.transport.message.core :as transport] @@ -10,7 +11,8 @@ [status-im.utils.contacts :as utils.contacts] [status-im.utils.handlers :as handlers] [status-im.utils.handlers-macro :as handlers-macro] - [status-im.utils.js-resources :as js-res])) + [status-im.utils.js-resources :as js-res] + [status-im.utils.utils :as utils])) (re-frame/reg-cofx :get-default-contacts @@ -89,9 +91,10 @@ [(re-frame/inject-cofx :random-id)] (fn [{:keys [db] :as cofx} [_ _ contact-identity]] (let [current-account (:account/account db) - fx {:db (assoc db :contacts/new-identity contact-identity)}] - (if (new-chat.db/validate-pub-key contact-identity current-account) - fx + fx {:db (assoc db :contacts/new-identity contact-identity)} + validation-result (new-chat.db/validate-pub-key contact-identity current-account)] + (if (some? validation-result) + (utils/show-popup (i18n/label :t/unable-to-read-this-code) validation-result #(re-frame/dispatch [:navigate-to-clean :home])) (handlers-macro/merge-fx cofx fx (add-contact-and-open-chat contact-identity))))))