From 4000a5e8ee87a0f0ca27564861cf2a3568c71f54 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 7 Mar 2017 20:55:45 +0200 Subject: [PATCH] fix #856 --- src/status_im/chat/handlers/webview_bridge.cljs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/status_im/chat/handlers/webview_bridge.cljs b/src/status_im/chat/handlers/webview_bridge.cljs index 4a7a319486..b9fcbb27f8 100644 --- a/src/status_im/chat/handlers/webview_bridge.cljs +++ b/src/status_im/chat/handlers/webview_bridge.cljs @@ -7,6 +7,7 @@ [taoensso.timbre :as log] [status-im.models.commands :as commands] [status-im.commands.utils :as cu] + [status-im.contacts.validations :as v] [status-im.components.status :as s] [status-im.components.nfc :as nfc] [status-im.constants :as c] @@ -19,18 +20,25 @@ (when-let [{:keys [address]} (contacts public-key)] (when address {:address address}))) +(defn wrap-hex [s] + (if (js/isNaN (.parseInt js/Number s)) + s + (str "\"" s "\""))) + (defn scan-qr-handler [{:keys [contacts]} [_ _ data]] - (let [data' (read-string data) + (let [data' (try (read-string (wrap-hex data)) + (catch :default e data)) data'' (cond (map? data') data' - (.isAddress web3.prototype data') {:address data'} + (v/is-address? data') {:address data'} (string? data') (by-public-key data' contacts) :else nil)] (when data'' (dispatch [:send-to-webview-bridge {:params data'' - :event (name :webview-send-transaction)}])))) + :event (name :webview-send-transaction)}])) + (dispatch [:navigate-back]))) (register-handler :webview-address-from-qr (u/side-effect! scan-qr-handler))