feature #4747 - ens usernames in wallet send
Signed-off-by: Dmitry Novotochinov <dmitry.novot@gmail.com>
This commit is contained in:
parent
fe822e5bc8
commit
89bf1b728d
|
@ -4,7 +4,9 @@
|
||||||
[status-im.utils.ethereum.core :as ethereum]
|
[status-im.utils.ethereum.core :as ethereum]
|
||||||
[status-im.utils.ethereum.eip681 :as eip681]
|
[status-im.utils.ethereum.eip681 :as eip681]
|
||||||
[status-im.utils.handlers :as handlers]
|
[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
|
(handlers/register-handler-db
|
||||||
:wallet/toggle-flashlight
|
:wallet/toggle-flashlight
|
||||||
|
@ -57,6 +59,27 @@
|
||||||
(assoc-in fx [:db :wallet :send-transaction :gas]
|
(assoc-in fx [:db :wallet :send-transaction :gas]
|
||||||
ethereum/default-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
|
(handlers/register-handler-fx
|
||||||
:wallet/fill-request-from-url
|
:wallet/fill-request-from-url
|
||||||
(fn [{{:keys [network] :as db} :db} [_ data origin]]
|
(fn [{{:keys [network] :as db} :db} [_ data origin]]
|
||||||
|
|
|
@ -234,7 +234,7 @@
|
||||||
:accessibility-label :recipient-address-input}]]
|
:accessibility-label :recipient-address-input}]]
|
||||||
[bottom-buttons/bottom-button
|
[bottom-buttons/bottom-button
|
||||||
[button/button {:disabled? (string/blank? @content)
|
[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}
|
:fit-to-text? false}
|
||||||
(i18n/label :t/done)]]]])))
|
(i18n/label :t/done)]]]])))
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,6 @@
|
||||||
[::wallet-send-chat-request (name symbol) (str (money/internal->formatted amount symbol decimals))]]
|
[::wallet-send-chat-request (name symbol) (str (money/internal->formatted amount symbol decimals))]]
|
||||||
[:start-chat whisper-identity]]}))
|
[: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
|
(handlers/register-handler-fx
|
||||||
:wallet.request/set-and-validate-amount
|
:wallet.request/set-and-validate-amount
|
||||||
(fn [{:keys [db]} [_ amount symbol decimals]]
|
(fn [{:keys [db]} [_ amount symbol decimals]]
|
||||||
|
|
|
@ -89,4 +89,15 @@
|
||||||
(namehash ens-name))
|
(namehash ens-name))
|
||||||
(fn [_ key] (cb (add-uncompressed-public-key-prefix key)))))
|
(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
|
;; TODO ABI, pubkey
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
(ns status-im.utils.ethereum.stateofus
|
(ns status-im.utils.ethereum.stateofus
|
||||||
(:refer-clojure :exclude [name])
|
(:refer-clojure :exclude [name])
|
||||||
(:require [clojure.string :as string]
|
(:require [clojure.string :as string]
|
||||||
[status-im.utils.ethereum.core :as ethereum]
|
|
||||||
[status-im.utils.ethereum.ens :as ens]))
|
[status-im.utils.ethereum.ens :as ens]))
|
||||||
|
|
||||||
(defn is-valid-name? [ens-name]
|
(defn is-valid-name? [ens-name]
|
||||||
(string/ends-with? ens-name ".stateofus.eth"))
|
(and 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)))
|
|
||||||
|
|
||||||
(defn pubkey
|
(defn pubkey
|
||||||
[web3 registry ens-name cb]
|
[web3 registry ens-name cb]
|
||||||
|
|
Loading…
Reference in New Issue