* Resolve ENS on address-to-watch screen based on test-net settings * Resolve ENS on `:wallet/search-ens` event based on test-net settings
This commit is contained in:
parent
ec53f17897
commit
ce7912632c
|
@ -1,6 +1,6 @@
|
|||
(ns status-im.contexts.wallet.accounts.add-account.address-to-watch.events
|
||||
(:require [clojure.string :as string]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.contexts.wallet.common.utils :as utils]
|
||||
[taoensso.timbre :as log]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
|
@ -33,9 +33,10 @@
|
|||
|
||||
(rf/reg-event-fx
|
||||
:wallet/get-address-details
|
||||
(fn [{:keys [db]} [address-or-ens]]
|
||||
(let [request-params [constants/ethereum-mainnet-chain-id address-or-ens]
|
||||
ens? (string/includes? address-or-ens ".")]
|
||||
(fn [{db :db} [address-or-ens]]
|
||||
(let [ens? (string/includes? address-or-ens ".")
|
||||
chain-id (utils/network->chain-id db :mainnet)
|
||||
request-params [chain-id address-or-ens]]
|
||||
{:db (-> db
|
||||
(assoc-in [:wallet :ui :add-address-to-watch :activity-state] :scanning)
|
||||
(assoc-in [:wallet :ui :add-address-to-watch :validated-address] nil))
|
||||
|
|
|
@ -201,7 +201,12 @@
|
|||
mainnet-chain-id))
|
||||
|
||||
(defn network->chain-id
|
||||
[{:keys [network testnet-enabled? goerli-enabled?]}]
|
||||
([db network]
|
||||
(let [{:keys [test-networks-enabled? is-goerli-enabled?]} (:profile/profile db)]
|
||||
(network->chain-id {:network network
|
||||
:testnet-enabled? test-networks-enabled?
|
||||
:goerli-enabled? is-goerli-enabled?})))
|
||||
([{:keys [network testnet-enabled? goerli-enabled?]}]
|
||||
(condp contains? (keyword network)
|
||||
#{constants/mainnet-network-name (keyword constants/mainnet-short-name)}
|
||||
(get-chain-id
|
||||
|
@ -225,7 +230,7 @@
|
|||
:sepolia-chain-id constants/arbitrum-sepolia-chain-id
|
||||
:goerli-chain-id constants/arbitrum-goerli-chain-id
|
||||
:testnet-enabled? testnet-enabled?
|
||||
:goerli-enabled? goerli-enabled?})))
|
||||
:goerli-enabled? goerli-enabled?}))))
|
||||
|
||||
(defn get-standard-fiat-format
|
||||
[crypto-value currency-symbol fiat-value]
|
||||
|
|
|
@ -281,46 +281,50 @@
|
|||
data)}]
|
||||
{:db (assoc-in db [:wallet :networks] network-data)})))
|
||||
|
||||
(rf/reg-event-fx :wallet/find-ens
|
||||
(fn [{:keys [db]} [input contacts chain-id cb]]
|
||||
(rf/reg-event-fx
|
||||
:wallet/find-ens
|
||||
(fn [{:keys [db]} [input contacts on-error-fn]]
|
||||
(let [result (if (empty? input)
|
||||
[]
|
||||
(filter #(string/starts-with? (or (:ens-name %) "") input) contacts))]
|
||||
(if (and input (empty? result))
|
||||
(rf/dispatch [:wallet/search-ens input chain-id cb ".stateofus.eth"])
|
||||
(rf/dispatch [:wallet/search-ens input on-error-fn ".stateofus.eth"])
|
||||
{:db (-> db
|
||||
(assoc-in [:wallet :ui :search-address :local-suggestions]
|
||||
(map #(assoc % :type item-types/saved-address) result))
|
||||
(assoc-in [:wallet :ui :search-address :valid-ens-or-address?]
|
||||
(not-empty result)))}))))
|
||||
|
||||
(rf/reg-event-fx :wallet/search-ens
|
||||
(fn [_ [input chain-id cb domain]]
|
||||
(let [ens (if (string/includes? input ".") input (str input domain))]
|
||||
(rf/reg-event-fx
|
||||
:wallet/search-ens
|
||||
(fn [{db :db} [input on-error-fn domain]]
|
||||
(let [ens (if (string/includes? input ".")
|
||||
input
|
||||
(str input domain))
|
||||
chain-id (utils/network->chain-id db :mainnet)]
|
||||
{:fx [[:json-rpc/call
|
||||
[{:method "ens_addressOf"
|
||||
:params [chain-id ens]
|
||||
:on-success #(rf/dispatch [:wallet/set-ens-address % ens])
|
||||
:on-error (fn []
|
||||
(if (= domain ".stateofus.eth")
|
||||
(rf/dispatch [:wallet/search-ens input chain-id cb ".eth"])
|
||||
(rf/dispatch [:wallet/search-ens input on-error-fn ".eth"])
|
||||
(do
|
||||
(rf/dispatch [:wallet/set-ens-address nil ens])
|
||||
(cb))))}]]]})))
|
||||
(on-error-fn))))}]]]})))
|
||||
|
||||
(rf/reg-event-fx :wallet/set-ens-address
|
||||
(rf/reg-event-fx
|
||||
:wallet/set-ens-address
|
||||
(fn [{:keys [db]} [result ens]]
|
||||
{:db
|
||||
(-> db
|
||||
(assoc-in [:wallet :ui :search-address :local-suggestions]
|
||||
(if result
|
||||
(let [suggestion (if result
|
||||
[{:type item-types/address
|
||||
:ens ens
|
||||
:address (eip55/address->checksum result)
|
||||
:networks [:ethereum :optimism]}]
|
||||
[]))
|
||||
(assoc-in [:wallet :ui :search-address :valid-ens-or-address?]
|
||||
(boolean result)))}))
|
||||
[])]
|
||||
{:db (-> db
|
||||
(assoc-in [:wallet :ui :search-address :local-suggestions] suggestion)
|
||||
(assoc-in [:wallet :ui :search-address :valid-ens-or-address?] (boolean result)))})))
|
||||
|
||||
(rf/reg-event-fx :wallet/fetch-address-suggestions
|
||||
(fn [{:keys [db]} [_address]]
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
recipient (rf/sub [:wallet/wallet-send-recipient])
|
||||
recipient-plain-address? (= send-address recipient)
|
||||
valid-ens-or-address? (rf/sub [:wallet/valid-ens-or-address?])
|
||||
chain-id (rf/sub [:chain-id])
|
||||
contacts (rf/sub [:contacts/active])]
|
||||
[quo/address-input
|
||||
{:on-focus #(reset! input-focused? true)
|
||||
|
@ -58,7 +57,7 @@
|
|||
; is loaded but not being shown to the user (deep in the
|
||||
; navigation stack) and avoid undesired behaviors
|
||||
(debounce/debounce-and-dispatch
|
||||
[:wallet/find-ens text contacts chain-id cb]
|
||||
[:wallet/find-ens text contacts cb]
|
||||
300)))
|
||||
:on-change-text (fn [text]
|
||||
(when (empty? text)
|
||||
|
|
Loading…
Reference in New Issue