diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 99dc1121f0..dab409eace 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -464,6 +464,7 @@ #{ethereum-sepolia-chain-id arbitrum-sepolia-chain-id optimism-sepolia-chain-id}) (def ^:const mainnet-short-name "eth") +(def ^:const ethereum-short-name "eth") (def ^:const optimism-short-name "opt") (def ^:const arbitrum-short-name "arb1") @@ -474,6 +475,7 @@ (def ^:const arbitrum-abbreviated-name "Arb1.") (def ^:const mainnet-network-name :mainnet) +(def ^:const ethereum-network-name :ethereum) (def ^:const optimism-network-name :optimism) (def ^:const arbitrum-network-name :arbitrum) diff --git a/src/status_im/contexts/wallet/common/utils/networks.cljs b/src/status_im/contexts/wallet/common/utils/networks.cljs index f9dfa5665e..6233d14570 100644 --- a/src/status_im/contexts/wallet/common/utils/networks.cljs +++ b/src/status_im/contexts/wallet/common/utils/networks.cljs @@ -92,3 +92,24 @@ {:network % :testnet-enabled? testnet-enabled? :goerli-enabled? goerli-enabled?}))))) + +(def network->short-name + {constants/mainnet-network-name constants/mainnet-short-name + constants/optimism-network-name constants/optimism-short-name + constants/arbitrum-network-name constants/arbitrum-short-name + constants/ethereum-network-name constants/ethereum-short-name}) + +(def short-name->network + {constants/mainnet-short-name constants/mainnet-network-name + constants/optimism-short-name constants/optimism-network-name + constants/arbitrum-short-name constants/arbitrum-network-name}) + +(defn short-names->network-preference-prefix + [short-names] + (str (string/join ":" short-names) ":")) + +(defn network-preference-prefix->network-names + [prefix] + (as-> prefix $ + (string/split $ ":") + (map short-name->network $))) diff --git a/src/status_im/contexts/wallet/common/utils/networks_test.cljs b/src/status_im/contexts/wallet/common/utils/networks_test.cljs index d89dfe6cd8..cf1903d316 100644 --- a/src/status_im/contexts/wallet/common/utils/networks_test.cljs +++ b/src/status_im/contexts/wallet/common/utils/networks_test.cljs @@ -1,6 +1,6 @@ (ns status-im.contexts.wallet.common.utils.networks-test (:require - [cljs.test :refer [deftest is testing]] + [cljs.test :refer [are deftest is testing]] [status-im.constants :as constants] [status-im.contexts.wallet.common.utils.networks :as utils])) @@ -20,3 +20,26 @@ constants/arbitrum-mainnet-chain-id)) (is (= (utils/network->chain-id {:network :arbitrum :testnet-enabled? true :goerli-enabled? false}) constants/arbitrum-sepolia-chain-id)))) + +(deftest test-network-preference-prefix->network-names + (testing "network-preference-prefix->network-names function" + (is (= (utils/network-preference-prefix->network-names "eth") + (seq [:mainnet]))) + (is (= (utils/network-preference-prefix->network-names "eth:opt") + (seq [:mainnet :optimism]))) + (is (= (utils/network-preference-prefix->network-names "eth:opt:arb1") + (seq [:mainnet :optimism :arbitrum]))))) + +(deftest short-names->network-preference-prefix-test + (are [expected short-names] + (= expected (utils/short-names->network-preference-prefix short-names)) + "eth:" ["eth"] + "eth:opt:" ["eth" "opt"] + "eth:opt:arb1:" ["eth" "opt" "arb1"])) + +(deftest network-preference-prefix->network-names-test + (are [expected short-names] + (= expected (utils/network-preference-prefix->network-names short-names)) + (seq [:mainnet]) "eth" + (seq [:mainnet :optimism]) "eth:opt" + (seq [:mainnet :optimism :arbitrum]) "eth:opt:arb1")) diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 3f31e47b7f..6d6ee73d06 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -325,14 +325,23 @@ (rf/dispatch [:wallet/set-ens-address nil ens]) (on-error-fn))))}]]]}))) +(defn- resolved-address->prefixed-address + [address networks] + (let [prefixes (->> networks + (map network-utils/network->short-name) + network-utils/short-names->network-preference-prefix)] + (str prefixes (eip55/address->checksum address)))) + (rf/reg-event-fx :wallet/set-ens-address (fn [{:keys [db]} [result ens]] - (let [suggestion (if result - [{:type item-types/address - :ens ens - :address (eip55/address->checksum result) - :networks [:ethereum :optimism]}] + (let [networks [constants/ethereum-network-name constants/optimism-network-name] + suggestion (if result + [{:type item-types/address + :ens ens + :address (eip55/address->checksum result) + :networks networks + :full-address (resolved-address->prefixed-address result networks)}] [])] {:db (-> db (assoc-in [:wallet :ui :search-address :local-suggestions] suggestion) diff --git a/src/status_im/contexts/wallet/send/select_address/style.cljs b/src/status_im/contexts/wallet/send/select_address/style.cljs index 037f9cbd98..3cc56aa08d 100644 --- a/src/status_im/contexts/wallet/send/select_address/style.cljs +++ b/src/status_im/contexts/wallet/send/select_address/style.cljs @@ -15,3 +15,7 @@ {:justify-self :flex-end :margin-bottom 20 :margin-horizontal 20}) + +(def network-text-container + {:padding-horizontal 12 + :padding-top 4}) 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 12db42ee7b..439e188088 100644 --- a/src/status_im/contexts/wallet/send/select_address/view.cljs +++ b/src/status_im/contexts/wallet/send/select_address/view.cljs @@ -2,6 +2,7 @@ (:require [quo.core :as quo] [quo.foundations.colors :as colors] + [quo.theme] [react-native.core :as rn] [react-native.safe-area :as safe-area] [reagent.core :as reagent] @@ -78,23 +79,22 @@ :valid-ens-or-address? valid-ens-or-address?}]))) (defn- ens-linked-address - [{:keys [address networks theme]}] - [quo/text - {:size :paragraph-2 - :style {:padding-horizontal 12 - :padding-top 4}} - (map (fn [network] - ^{:key (str network)} - [quo/text - {:size :paragraph-2 - :style {:color (colors/resolve-color network theme)}} - (str (subs (name network) 0 3) ":")]) - networks) - [quo/text - {:size :paragraph-2 - :weight :monospace - :style {:color (colors/theme-colors colors/neutral-100 colors/white theme)}} - address]]) + [{:keys [address networks]}] + (let [theme (quo.theme/use-theme)] + [quo/text + {:size :paragraph-2 + :style style/network-text-container} + (map (fn [network] + ^{:key (str network)} + [quo/text + {:size :paragraph-2 + :style {:color (colors/resolve-color network theme)}} + (str (subs (name network) 0 3) ":")]) + networks) + [quo/text + {:size :paragraph-2 + :weight :monospace} + address]])) (defn- suggestion-component [] @@ -151,9 +151,10 @@ input-value (reagent/atom "") input-focused? (reagent/atom false)] (fn [] - (let [selected-tab (or (rf/sub [:wallet/send-tab]) (:id (first tabs-data))) - valid-ens-or-address? (boolean (rf/sub [:wallet/valid-ens-or-address?])) - {:keys [color]} (rf/sub [:wallet/current-viewing-account])] + (let [selected-tab (or (rf/sub [:wallet/send-tab]) (:id (first tabs-data))) + valid-ens-or-address? (boolean (rf/sub [:wallet/valid-ens-or-address?])) + local-suggestion-address (rf/sub [:wallet/local-suggestions->full-address]) + color (rf/sub [:wallet/current-viewing-account-color])] [floating-button-page/view {:footer-container-padding 0 :header [account-switcher/view @@ -167,7 +168,8 @@ :disabled? (not valid-ens-or-address?) :on-press #(rf/dispatch [:wallet/select-send-address - {:address @input-value + {:address (or local-suggestion-address + @input-value) :stack-id :screen/wallet.select-address}]) :customization-color color} diff --git a/src/status_im/subs/wallet/wallet.cljs b/src/status_im/subs/wallet/wallet.cljs index 6fd98d73fa..93a3ebc102 100644 --- a/src/status_im/subs/wallet/wallet.cljs +++ b/src/status_im/subs/wallet/wallet.cljs @@ -262,6 +262,11 @@ (assoc :balance balance :formatted-balance formatted-balance))))) +(rf/reg-sub + :wallet/current-viewing-account-color + :<- [:wallet/current-viewing-account] + :-> :color) + (rf/reg-sub :wallet/current-viewing-account-keypair :<- [:wallet/current-viewing-account] @@ -397,6 +402,12 @@ :<- [:wallet/search-address] :-> :local-suggestions) +(rf/reg-sub + :wallet/local-suggestions->full-address + :<- [:wallet/local-suggestions] + (fn [local-suggestions] + (:full-address (first local-suggestions)))) + (rf/reg-sub :wallet/valid-ens-or-address? :<- [:wallet/search-address]