feature #4747 - ens usernames in wallet send

Signed-off-by: Dmitry Novotochinov <dmitry.novot@gmail.com>
This commit is contained in:
Goran Jovic 2018-09-04 12:48:56 +02:00 committed by Dmitry Novotochinov
parent fe822e5bc8
commit 89bf1b728d
No known key found for this signature in database
GPG Key ID: 43D1DAF5AD39C927
5 changed files with 38 additions and 16 deletions

View File

@ -4,7 +4,9 @@
[status-im.utils.ethereum.core :as ethereum]
[status-im.utils.ethereum.eip681 :as eip681]
[status-im.utils.handlers :as handlers]
[status-im.utils.money :as money]))
[status-im.utils.money :as money]
[status-im.utils.ethereum.ens :as ens]
[re-frame.core :as re-frame]))
(handlers/register-handler-db
:wallet/toggle-flashlight
@ -57,6 +59,27 @@
(assoc-in fx [:db :wallet :send-transaction :gas]
ethereum/default-transaction-gas))
(re-frame/reg-fx
:resolve-address
(fn [{:keys [web3 registry ens-name cb]}]
(ens/get-addr web3 registry ens-name cb)))
(handlers/register-handler-fx
:wallet.send/set-recipient
(fn [{:keys [db]} [_ recipient]]
(let [{:keys [web3 network]} db
network-info (get-in db [:account/account :networks network])
chain (ethereum/network->chain-keyword network-info)]
(if (ens/is-valid-eth-name? recipient)
{:resolve-address {:web3 web3
:registry (get ens/ens-registries chain)
:ens-name recipient
:cb #(re-frame/dispatch [:wallet.send/set-recipient %])}}
(if (ethereum/address? recipient)
{:db (assoc-in db [:wallet :send-transaction :to] recipient)
:dispatch [:navigate-back]}
{:show-error (i18n/label :t/wallet-invalid-address {:data recipient})})))))
(handlers/register-handler-fx
:wallet/fill-request-from-url
(fn [{{:keys [network] :as db} :db} [_ data origin]]

View File

@ -234,7 +234,7 @@
:accessibility-label :recipient-address-input}]]
[bottom-buttons/bottom-button
[button/button {:disabled? (string/blank? @content)
:on-press #(re-frame/dispatch [:wallet/fill-request-from-url @content :code])
:on-press #(re-frame/dispatch [:wallet.send/set-recipient @content])
:fit-to-text? false}
(i18n/label :t/done)]]]])))

View File

@ -27,11 +27,6 @@
[::wallet-send-chat-request (name symbol) (str (money/internal->formatted amount symbol decimals))]]
[:start-chat whisper-identity]]}))
(handlers/register-handler-fx
:wallet.request/set-recipient
(fn [{:keys [db]} [_ s]]
{:db (assoc-in db [:wallet :request-transaction :to] s)}))
(handlers/register-handler-fx
:wallet.request/set-and-validate-amount
(fn [{:keys [db]} [_ amount symbol decimals]]

View File

@ -89,4 +89,15 @@
(namehash ens-name))
(fn [_ key] (cb (add-uncompressed-public-key-prefix key)))))
(defn is-valid-eth-name? [ens-name]
(and ens-name
(string/ends-with? ens-name ".eth")))
(defn get-addr [web3 registry ens-name cb]
{:pre [(is-valid-eth-name? ens-name)]}
(resolver web3
registry
ens-name
#(addr web3 % ens-name cb)))
;; TODO ABI, pubkey

View File

@ -1,18 +1,11 @@
(ns status-im.utils.ethereum.stateofus
(:refer-clojure :exclude [name])
(:require [clojure.string :as string]
[status-im.utils.ethereum.core :as ethereum]
[status-im.utils.ethereum.ens :as ens]))
(defn is-valid-name? [ens-name]
(string/ends-with? ens-name ".stateofus.eth"))
(defn addr [web3 registry ens-name cb]
{:pre [(is-valid-name? ens-name)]}
(ens/resolver web3
registry
ens-name
#(ens/addr web3 % ens-name cb)))
(and ens-name
(string/ends-with? ens-name ".stateofus.eth")))
(defn pubkey
[web3 registry ens-name cb]