From de03fc2d6a8619860ee9333a787345dae84bca37 Mon Sep 17 00:00:00 2001 From: Andrey Shovkoplyas Date: Thu, 3 May 2018 13:04:42 +0300 Subject: [PATCH] fixed error on invalid utf-8 from dapp Signed-off-by: Andrey Shovkoplyas --- src/status_im/transport/utils.cljs | 4 +++- src/status_im/ui/screens/wallet/send/events.cljs | 15 +++++++++------ src/status_im/ui/screens/wallet/send/views.cljs | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/status_im/transport/utils.cljs b/src/status_im/transport/utils.cljs index 6fb3d49a4d..32604cb38e 100644 --- a/src/status_im/transport/utils.cljs +++ b/src/status_im/transport/utils.cljs @@ -20,7 +20,9 @@ (.toAscii dependencies/Web3.prototype s)) (defn to-utf8 [s] - (.toUtf8 dependencies/Web3.prototype (str s))) + (try + (.toUtf8 dependencies/Web3.prototype (str s)) + (catch :default err nil))) (defn sha3 [s] (.sha3 dependencies/Web3.prototype s)) diff --git a/src/status_im/ui/screens/wallet/send/events.cljs b/src/status_im/ui/screens/wallet/send/events.cljs index 96776f3779..1f3a4a8891 100644 --- a/src/status_im/ui/screens/wallet/send/events.cljs +++ b/src/status_im/ui/screens/wallet/send/events.cljs @@ -13,7 +13,8 @@ [status-im.utils.money :as money] [status-im.utils.types :as types] [status-im.utils.utils :as utils] - [status-im.constants :as constants])) + [status-im.constants :as constants] + [status-im.transport.utils :as transport.utils])) ;;;; FX @@ -158,11 +159,13 @@ (= method constants/web3-personal-sign) - (let [{:keys [data]} args] - {:db (-> db - (assoc-in [:wallet :transactions-unsigned id] {:data data :id id}) - (assoc-in [:wallet :send-transaction] {:id id :method method})) - :dispatch [:navigate-to-modal :wallet-sign-message-modal]})))) + (let [{:keys [data]} args + data' (transport.utils/to-utf8 data)] + (when data' + {:db (-> db + (assoc-in [:wallet :transactions-unsigned id] {:data data' :id id}) + (assoc-in [:wallet :send-transaction] {:id id :method method})) + :dispatch [:navigate-to-modal :wallet-sign-message-modal]}))))) (defn this-transaction-signing? [id signing-id view-id modal] (and (= signing-id id) diff --git a/src/status_im/ui/screens/wallet/send/views.cljs b/src/status_im/ui/screens/wallet/send/views.cljs index bb0013601c..4ef83e3e3c 100644 --- a/src/status_im/ui/screens/wallet/send/views.cljs +++ b/src/status_im/ui/screens/wallet/send/views.cljs @@ -273,7 +273,7 @@ (i18n/label :t/message) [components/amount-input {:disabled? true :input-options {:multiline true - :default-value (transport.utils/to-utf8 data)}}]]]] + :default-value data}}]]]] [signing-buttons #(re-frame/dispatch [:wallet/discard-transaction-navigate-back]) #(re-frame/dispatch [:wallet/sign-transaction-modal])