feature #4959 - eip-55 in wallet send and request
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
62e94ed4d4
commit
d326148ad6
|
@ -84,9 +84,7 @@
|
||||||
:ens-name recipient
|
:ens-name recipient
|
||||||
:cb #(re-frame/dispatch [:wallet.send/set-recipient %])}}
|
:cb #(re-frame/dispatch [:wallet.send/set-recipient %])}}
|
||||||
(if (ethereum/address? recipient)
|
(if (ethereum/address? recipient)
|
||||||
(if (-> recipient
|
(if (eip55/valid-address-checksum? recipient)
|
||||||
ethereum/address->checksum
|
|
||||||
eip55/valid-address-checksum?)
|
|
||||||
{:db (assoc-in db [:wallet :send-transaction :to] recipient)
|
{:db (assoc-in db [:wallet :send-transaction :to] recipient)
|
||||||
:dispatch [:navigate-back]}
|
:dispatch [:navigate-back]}
|
||||||
{:ui/show-error (i18n/label :t/wallet-invalid-address-checksum {:data recipient})})
|
{:ui/show-error (i18n/label :t/wallet-invalid-address-checksum {:data recipient})})
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
[status-im.ui.components.toolbar.actions :as actions]
|
[status-im.ui.components.toolbar.actions :as actions]
|
||||||
[status-im.ui.components.toolbar.view :as toolbar]
|
[status-im.ui.components.toolbar.view :as toolbar]
|
||||||
[status-im.ui.components.status-bar.view :as status-bar]
|
[status-im.ui.components.status-bar.view :as status-bar]
|
||||||
[status-im.ui.components.icons.vector-icons :as vector-icons]))
|
[status-im.ui.components.icons.vector-icons :as vector-icons]
|
||||||
|
[status-im.utils.ethereum.eip55 :as eip55]))
|
||||||
|
|
||||||
;; Wallet tab has a different coloring scheme (dark) that forces color changes (background, text)
|
;; Wallet tab has a different coloring scheme (dark) that forces color changes (background, text)
|
||||||
;; It might be replaced by some theme mechanism
|
;; It might be replaced by some theme mechanism
|
||||||
|
@ -176,7 +177,7 @@
|
||||||
(defn- recipient-address [address modal?]
|
(defn- recipient-address [address modal?]
|
||||||
[react/text {:style (merge styles/recipient-address (when-not address styles/recipient-no-address))
|
[react/text {:style (merge styles/recipient-address (when-not address styles/recipient-no-address))
|
||||||
:accessibility-label :recipient-address-text}
|
:accessibility-label :recipient-address-text}
|
||||||
(or (ethereum/normalized-address address)
|
(or (eip55/address->checksum (ethereum/normalized-address address))
|
||||||
(if modal?
|
(if modal?
|
||||||
(i18n/label :t/new-contract)
|
(i18n/label :t/new-contract)
|
||||||
(i18n/label :t/specify-recipient)))])
|
(i18n/label :t/specify-recipient)))])
|
||||||
|
@ -195,7 +196,7 @@
|
||||||
name]
|
name]
|
||||||
[react/text {:style (styles/participant (and (not name) address?))
|
[react/text {:style (styles/participant (and (not name) address?))
|
||||||
:accessibility-label (if request? :contact-address-text :recipient-address-text)}
|
:accessibility-label (if request? :contact-address-text :recipient-address-text)}
|
||||||
(ethereum/normalized-address address)]]])))
|
(eip55/address->checksum (ethereum/normalized-address address))]]])))
|
||||||
|
|
||||||
(defn render-contact [contact request?]
|
(defn render-contact [contact request?]
|
||||||
[list/touchable-item #(re-frame/dispatch [:wallet/fill-request-from-contact contact request?])
|
[list/touchable-item #(re-frame/dispatch [:wallet/fill-request-from-contact contact request?])
|
||||||
|
@ -206,7 +207,7 @@
|
||||||
(:name contact)]
|
(:name contact)]
|
||||||
[react/text {:style list.styles/secondary-text
|
[react/text {:style list.styles/secondary-text
|
||||||
:accessibility-label :contact-address-text}
|
:accessibility-label :contact-address-text}
|
||||||
(ethereum/normalized-address (:address contact))]]]])
|
(eip55/address->checksum (ethereum/normalized-address (:address contact)))]]]])
|
||||||
|
|
||||||
(views/defview recent-recipients []
|
(views/defview recent-recipients []
|
||||||
(views/letsubs [contacts [:contacts/active]
|
(views/letsubs [contacts [:contacts/active]
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
[status-im.utils.ethereum.tokens :as tokens]
|
[status-im.utils.ethereum.tokens :as tokens]
|
||||||
[status-im.ui.screens.wallet.utils :as wallet.utils]
|
[status-im.ui.screens.wallet.utils :as wallet.utils]
|
||||||
[status-im.ui.screens.chat.photos :as photos]
|
[status-im.ui.screens.chat.photos :as photos]
|
||||||
[status-im.ui.components.list.styles :as list.styles]))
|
[status-im.ui.components.list.styles :as list.styles]
|
||||||
|
[status-im.utils.ethereum.eip55 :as eip55]))
|
||||||
|
|
||||||
;; Request screen
|
;; Request screen
|
||||||
|
|
||||||
|
@ -94,4 +95,4 @@
|
||||||
:footer-button send-transaction-request-button
|
:footer-button send-transaction-request-button
|
||||||
:value (eip681/generate-uri address-hex {:chain-id chain-id})
|
:value (eip681/generate-uri address-hex {:chain-id chain-id})
|
||||||
:hint (i18n/label :t/request-qr-legend)
|
:hint (i18n/label :t/request-qr-legend)
|
||||||
:legend address-hex}]]]))
|
:legend (eip55/address->checksum address-hex)}]]]))
|
||||||
|
|
|
@ -50,10 +50,6 @@
|
||||||
(when s
|
(when s
|
||||||
(.isAddress dependencies/Web3.prototype s)))
|
(.isAddress dependencies/Web3.prototype s)))
|
||||||
|
|
||||||
(defn address->checksum [s]
|
|
||||||
(when s
|
|
||||||
(.toChecksumAddress dependencies/Web3.prototype s)))
|
|
||||||
|
|
||||||
(defn network->chain-id [network]
|
(defn network->chain-id [network]
|
||||||
(get-in network [:config :NetworkId]))
|
(get-in network [:config :NetworkId]))
|
||||||
|
|
||||||
|
|
|
@ -5,18 +5,17 @@
|
||||||
|
|
||||||
e.g. 0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"
|
e.g. 0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"
|
||||||
(:require [clojure.string :as string]
|
(:require [clojure.string :as string]
|
||||||
[status-im.utils.ethereum.core :as ethereum]))
|
[status-im.js-dependencies :as dependencies]))
|
||||||
|
|
||||||
(defn valid-address-checksum? [address]
|
(def utils dependencies/web3-utils)
|
||||||
"verify address checksum according to EIP 55"
|
|
||||||
(let [adHash (ethereum/naked-address (ethereum/sha3
|
(defn address->checksum
|
||||||
(string/lower-case (ethereum/naked-address address))))]
|
"Converts an arbitrary case address to one with correct checksum case."
|
||||||
(every? true?
|
[address]
|
||||||
(map-indexed (fn [idx char]
|
(when address
|
||||||
(if (> (compare char "9") 0)
|
(.toChecksumAddress utils address)))
|
||||||
(if (>= (js/parseInt (nth adHash idx) 16) 8)
|
|
||||||
; If true should be upper case
|
(defn valid-address-checksum?
|
||||||
(<= (compare char "Z") 0)
|
"Checks address checksum validity."
|
||||||
; If not should be lower case
|
[address]
|
||||||
(> (compare char "Z") 0))
|
(.checkAddressChecksum utils address))
|
||||||
true)) (ethereum/naked-address address)))))
|
|
Loading…
Reference in New Issue