diff --git a/src/status_im/contexts/wallet/accounts/add_account/address_to_watch/events.cljs b/src/status_im/contexts/wallet/accounts/add_account/address_to_watch/events.cljs index c2d7c9b077..2900c20ef2 100644 --- a/src/status_im/contexts/wallet/accounts/add_account/address_to_watch/events.cljs +++ b/src/status_im/contexts/wallet/accounts/add_account/address_to_watch/events.cljs @@ -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)) diff --git a/src/status_im/contexts/wallet/common/utils.cljs b/src/status_im/contexts/wallet/common/utils.cljs index 30e0187a32..eb228fd2c1 100644 --- a/src/status_im/contexts/wallet/common/utils.cljs +++ b/src/status_im/contexts/wallet/common/utils.cljs @@ -201,31 +201,36 @@ mainnet-chain-id)) (defn network->chain-id - [{:keys [network testnet-enabled? goerli-enabled?]}] - (condp contains? (keyword network) - #{constants/mainnet-network-name (keyword constants/mainnet-short-name)} - (get-chain-id - {:mainnet-chain-id constants/ethereum-mainnet-chain-id - :sepolia-chain-id constants/ethereum-sepolia-chain-id - :goerli-chain-id constants/ethereum-goerli-chain-id - :testnet-enabled? testnet-enabled? - :goerli-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 + {:mainnet-chain-id constants/ethereum-mainnet-chain-id + :sepolia-chain-id constants/ethereum-sepolia-chain-id + :goerli-chain-id constants/ethereum-goerli-chain-id + :testnet-enabled? testnet-enabled? + :goerli-enabled? goerli-enabled?}) - #{constants/optimism-network-name (keyword constants/optimism-short-name)} - (get-chain-id - {:mainnet-chain-id constants/optimism-mainnet-chain-id - :sepolia-chain-id constants/optimism-sepolia-chain-id - :goerli-chain-id constants/optimism-goerli-chain-id - :testnet-enabled? testnet-enabled? - :goerli-enabled? goerli-enabled?}) + #{constants/optimism-network-name (keyword constants/optimism-short-name)} + (get-chain-id + {:mainnet-chain-id constants/optimism-mainnet-chain-id + :sepolia-chain-id constants/optimism-sepolia-chain-id + :goerli-chain-id constants/optimism-goerli-chain-id + :testnet-enabled? testnet-enabled? + :goerli-enabled? goerli-enabled?}) - #{constants/arbitrum-network-name (keyword constants/arbitrum-short-name)} - (get-chain-id - {:mainnet-chain-id constants/arbitrum-mainnet-chain-id - :sepolia-chain-id constants/arbitrum-sepolia-chain-id - :goerli-chain-id constants/arbitrum-goerli-chain-id - :testnet-enabled? testnet-enabled? - :goerli-enabled? goerli-enabled?}))) + #{constants/arbitrum-network-name (keyword constants/arbitrum-short-name)} + (get-chain-id + {:mainnet-chain-id constants/arbitrum-mainnet-chain-id + :sepolia-chain-id constants/arbitrum-sepolia-chain-id + :goerli-chain-id constants/arbitrum-goerli-chain-id + :testnet-enabled? testnet-enabled? + :goerli-enabled? goerli-enabled?})))) (defn get-standard-fiat-format [crypto-value currency-symbol fiat-value] diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 10b3ff35f1..be8d07f885 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -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 - [{: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)))})) + (let [suggestion (if result + [{:type item-types/address + :ens ens + :address (eip55/address->checksum result) + :networks [:ethereum :optimism]}] + [])] + {: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]] diff --git a/src/status_im/contexts/wallet/send/select_address/view.cljs b/src/status_im/contexts/wallet/send/select_address/view.cljs index c787c32c09..c8ce59f5b0 100644 --- a/src/status_im/contexts/wallet/send/select_address/view.cljs +++ b/src/status_im/contexts/wallet/send/select_address/view.cljs @@ -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)