[BUG #2156] Fixed incorrect address parsing

This commit is contained in:
Julien Eluard 2017-10-16 14:10:31 +02:00 committed by Roman Volosovskyi
parent 8a0607654e
commit e5c7d81b65
2 changed files with 11 additions and 3 deletions

View File

@ -13,11 +13,18 @@
(defn choose-address-and-name [db address name]
(update db :wallet/send-transaction assoc :to-address address :to-name name))
(defn- extract-address [s]
;; First try to parse as EIP67 URI, if not assume this is an address directly
(if-let [m (eip67/parse-uri s)]
(:address m)
s))
(handlers/register-handler-fx
:choose-recipient
(fn [{{:keys [web3] :as db} :db} [_ data name]]
(let [{:keys [view-id]} db
address (:address (eip67/parse-uri data))
address (extract-address data)
;; isAddress works with or without address with leading '0x'
valid-address? (.isAddress web3 address)]
(cond-> {:db db}
(= :choose-recipient view-id) (assoc :dispatch [:navigate-back])

View File

@ -1,6 +1,7 @@
(ns status-im.ui.screens.wallet.choose-recipient.views
(:require-macros [status-im.utils.views :refer [defview letsubs]])
(:require [re-frame.core :as re-frame]
(:require [clojure.string :as string]
[re-frame.core :as re-frame]
[status-im.components.camera :as camera]
[status-im.components.icons.vector-icons :as vector-icons]
[status-im.components.react :as react]
@ -40,7 +41,7 @@
[react/touchable-highlight {:style (styles/recipient-touchable true)
:on-press #(react/get-from-clipboard
(fn [clipboard]
(re-frame/dispatch [:choose-recipient clipboard nil])))}
(re-frame/dispatch [:choose-recipient (string/trim clipboard) nil])))}
[react/view {:style styles/recipient-button}
[react/text {:style styles/recipient-button-text}
(i18n/label :t/wallet-address-from-clipboard)]