Skip to content

Commit

Permalink
'No matching clause' error is shown if ENS is entered into 'sent to' …
Browse files Browse the repository at this point in the history
…page #19741 (#19957)
  • Loading branch information
mmilad75 authored May 14, 2024
1 parent 5a6a0f7 commit 8d4f1f9
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)

Expand Down
21 changes: 21 additions & 0 deletions src/status_im/contexts/wallet/common/utils/networks.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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 $)))
25 changes: 24 additions & 1 deletion src/status_im/contexts/wallet/common/utils/networks_test.cljs
Original file line number Diff line number Diff line change
@@ -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]))

Expand All @@ -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"))
19 changes: 14 additions & 5 deletions src/status_im/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/status_im/contexts/wallet/send/select_address/style.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
{:justify-self :flex-end
:margin-bottom 20
:margin-horizontal 20})

(def network-text-container
{:padding-horizontal 12
:padding-top 4})
44 changes: 23 additions & 21 deletions src/status_im/contexts/wallet/send/select_address/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
[]
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down
11 changes: 11 additions & 0 deletions src/status_im/subs/wallet/wallet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 8d4f1f9

Please sign in to comment.