mirror of
https://github.com/status-im/status-react.git
synced 2025-01-11 03:26:31 +00:00
This commit is contained in:
parent
5a6a0f7e3d
commit
8d4f1f9b38
@ -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)
|
||||
|
||||
|
@ -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 $)))
|
||||
|
@ -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"))
|
||||
|
@ -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)
|
||||
|
@ -15,3 +15,7 @@
|
||||
{:justify-self :flex-end
|
||||
:margin-bottom 20
|
||||
:margin-horizontal 20})
|
||||
|
||||
(def network-text-container
|
||||
{:padding-horizontal 12
|
||||
:padding-top 4})
|
||||
|
@ -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}
|
||||
|
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user