From 755e9bf2b3afe92d0bf426cd47b7bbfa572f7c82 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Wed, 1 Jun 2016 14:01:58 +0300 Subject: [PATCH] fix qr code decoding and remove extra data --- src/status_im/profile/screen.cljs | 6 ++---- src/status_im/qr_scanner/screen.cljs | 14 ++++++++------ src/status_im/utils/types.cljs | 7 +++++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/status_im/profile/screen.cljs b/src/status_im/profile/screen.cljs index 072f82a2c2..4451febd36 100644 --- a/src/status_im/profile/screen.cljs +++ b/src/status_im/profile/screen.cljs @@ -67,7 +67,7 @@ phone-number [:get :phone-number] email [:get :email] status [:get :status] - identity [:get :identity]] + identity [:get-in [:user-identity :public]]] [view {:style st/profile} [touchable-highlight {:style st/back-btn-touchable :on-press #(dispatch [:navigate-back])} @@ -93,7 +93,5 @@ :value email}] [view st/qr-code-container [qr-code {:value (clj->json {:name username - :phone-number phone-number - :address email :whisper-identity identity}) - :size 150}]]]]) + :size 200}]]]]) diff --git a/src/status_im/qr_scanner/screen.cljs b/src/status_im/qr_scanner/screen.cljs index 79be0aef07..a791042f87 100644 --- a/src/status_im/qr_scanner/screen.cljs +++ b/src/status_im/qr_scanner/screen.cljs @@ -13,6 +13,7 @@ [status-im.components.styles :refer [color-blue]] [status-im.i18n :refer [label]] [status-im.qr-scanner.styles :as st] + [status-im.utils.types :refer [json->clj]] [status-im.utils.logging :as log])) (defn qr-scanner-toolbar [] @@ -23,12 +24,13 @@ [] [view st/barcode-scanner-container [qr-scanner-toolbar] - [camera {:onBarCodeRead (fn [{:keys [name address whisper-identity phone-number] :as contact}] - (when name (dispatch [:set-in [:new-contact :name] name])) - (when address (dispatch [:set-in [:new-contact :address] address])) - (when whisper-identity (dispatch [:set-in [:new-contact :whisper-identity] whisper-identity])) - (when phone-number (dispatch [:set-in [:new-contact :phone-number] phone-number])) - (dispatch [:navigate-back])) + [camera {:onBarCodeRead (fn [data] + (let [{:keys [name address whisper-identity phone-number] :as contact} (json->clj (.-data data))] + (when name (dispatch [:set-in [:new-contact :name] name])) + (when address (dispatch [:set-in [:new-contact :address] address])) + (when whisper-identity (dispatch [:set-in [:new-contact :whisper-identity] whisper-identity])) + (when phone-number (dispatch [:set-in [:new-contact :phone-number] phone-number])) + (dispatch [:navigate-back]))) :style st/barcode-scanner}] [view st/rectangle-container [view st/rectangle diff --git a/src/status_im/utils/types.cljs b/src/status_im/utils/types.cljs index 5476d58b27..6ce9fdfce8 100644 --- a/src/status_im/utils/types.cljs +++ b/src/status_im/utils/types.cljs @@ -8,5 +8,8 @@ (defn to-edn-string [value] (with-out-str (pr value))) -(defn clj->json [ds] - (.stringify js/JSON (clj->js ds))) \ No newline at end of file +(defn clj->json [data] + (.stringify js/JSON (clj->js data))) + +(defn json->clj [data] + (js->clj (.parse js/JSON data))) \ No newline at end of file