fix qr code decoding and remove extra data

This commit is contained in:
Adrian Tiberius 2016-06-01 14:01:58 +03:00
parent c81276e3b7
commit 755e9bf2b3
3 changed files with 15 additions and 12 deletions

View File

@ -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}]]]])

View File

@ -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}]
[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]))
(dispatch [:navigate-back])))
:style st/barcode-scanner}]
[view st/rectangle-container
[view st/rectangle

View File

@ -8,5 +8,8 @@
(defn to-edn-string [value]
(with-out-str (pr value)))
(defn clj->json [ds]
(.stringify js/JSON (clj->js ds)))
(defn clj->json [data]
(.stringify js/JSON (clj->js data)))
(defn json->clj [data]
(js->clj (.parse js/JSON data)))