mirror of
https://github.com/status-im/status-mobile.git
synced 2025-02-06 13:54:01 +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})
|
#{ethereum-sepolia-chain-id arbitrum-sepolia-chain-id optimism-sepolia-chain-id})
|
||||||
|
|
||||||
(def ^:const mainnet-short-name "eth")
|
(def ^:const mainnet-short-name "eth")
|
||||||
|
(def ^:const ethereum-short-name "eth")
|
||||||
(def ^:const optimism-short-name "opt")
|
(def ^:const optimism-short-name "opt")
|
||||||
(def ^:const arbitrum-short-name "arb1")
|
(def ^:const arbitrum-short-name "arb1")
|
||||||
|
|
||||||
@ -474,6 +475,7 @@
|
|||||||
(def ^:const arbitrum-abbreviated-name "Arb1.")
|
(def ^:const arbitrum-abbreviated-name "Arb1.")
|
||||||
|
|
||||||
(def ^:const mainnet-network-name :mainnet)
|
(def ^:const mainnet-network-name :mainnet)
|
||||||
|
(def ^:const ethereum-network-name :ethereum)
|
||||||
(def ^:const optimism-network-name :optimism)
|
(def ^:const optimism-network-name :optimism)
|
||||||
(def ^:const arbitrum-network-name :arbitrum)
|
(def ^:const arbitrum-network-name :arbitrum)
|
||||||
|
|
||||||
|
@ -92,3 +92,24 @@
|
|||||||
{:network %
|
{:network %
|
||||||
:testnet-enabled? testnet-enabled?
|
:testnet-enabled? testnet-enabled?
|
||||||
:goerli-enabled? goerli-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
|
(ns status-im.contexts.wallet.common.utils.networks-test
|
||||||
(:require
|
(:require
|
||||||
[cljs.test :refer [deftest is testing]]
|
[cljs.test :refer [are deftest is testing]]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
[status-im.contexts.wallet.common.utils.networks :as utils]))
|
[status-im.contexts.wallet.common.utils.networks :as utils]))
|
||||||
|
|
||||||
@ -20,3 +20,26 @@
|
|||||||
constants/arbitrum-mainnet-chain-id))
|
constants/arbitrum-mainnet-chain-id))
|
||||||
(is (= (utils/network->chain-id {:network :arbitrum :testnet-enabled? true :goerli-enabled? false})
|
(is (= (utils/network->chain-id {:network :arbitrum :testnet-enabled? true :goerli-enabled? false})
|
||||||
constants/arbitrum-sepolia-chain-id))))
|
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])
|
(rf/dispatch [:wallet/set-ens-address nil ens])
|
||||||
(on-error-fn))))}]]]})))
|
(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
|
(rf/reg-event-fx
|
||||||
:wallet/set-ens-address
|
:wallet/set-ens-address
|
||||||
(fn [{:keys [db]} [result ens]]
|
(fn [{:keys [db]} [result ens]]
|
||||||
(let [suggestion (if result
|
(let [networks [constants/ethereum-network-name constants/optimism-network-name]
|
||||||
[{:type item-types/address
|
suggestion (if result
|
||||||
:ens ens
|
[{:type item-types/address
|
||||||
:address (eip55/address->checksum result)
|
:ens ens
|
||||||
:networks [:ethereum :optimism]}]
|
:address (eip55/address->checksum result)
|
||||||
|
:networks networks
|
||||||
|
:full-address (resolved-address->prefixed-address result networks)}]
|
||||||
[])]
|
[])]
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
(assoc-in [:wallet :ui :search-address :local-suggestions] suggestion)
|
(assoc-in [:wallet :ui :search-address :local-suggestions] suggestion)
|
||||||
|
@ -15,3 +15,7 @@
|
|||||||
{:justify-self :flex-end
|
{:justify-self :flex-end
|
||||||
:margin-bottom 20
|
:margin-bottom 20
|
||||||
:margin-horizontal 20})
|
:margin-horizontal 20})
|
||||||
|
|
||||||
|
(def network-text-container
|
||||||
|
{:padding-horizontal 12
|
||||||
|
:padding-top 4})
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
(:require
|
(:require
|
||||||
[quo.core :as quo]
|
[quo.core :as quo]
|
||||||
[quo.foundations.colors :as colors]
|
[quo.foundations.colors :as colors]
|
||||||
|
[quo.theme]
|
||||||
[react-native.core :as rn]
|
[react-native.core :as rn]
|
||||||
[react-native.safe-area :as safe-area]
|
[react-native.safe-area :as safe-area]
|
||||||
[reagent.core :as reagent]
|
[reagent.core :as reagent]
|
||||||
@ -78,23 +79,22 @@
|
|||||||
:valid-ens-or-address? valid-ens-or-address?}])))
|
:valid-ens-or-address? valid-ens-or-address?}])))
|
||||||
|
|
||||||
(defn- ens-linked-address
|
(defn- ens-linked-address
|
||||||
[{:keys [address networks theme]}]
|
[{:keys [address networks]}]
|
||||||
[quo/text
|
(let [theme (quo.theme/use-theme)]
|
||||||
{:size :paragraph-2
|
[quo/text
|
||||||
:style {:padding-horizontal 12
|
{:size :paragraph-2
|
||||||
:padding-top 4}}
|
:style style/network-text-container}
|
||||||
(map (fn [network]
|
(map (fn [network]
|
||||||
^{:key (str network)}
|
^{:key (str network)}
|
||||||
[quo/text
|
[quo/text
|
||||||
{:size :paragraph-2
|
{:size :paragraph-2
|
||||||
:style {:color (colors/resolve-color network theme)}}
|
:style {:color (colors/resolve-color network theme)}}
|
||||||
(str (subs (name network) 0 3) ":")])
|
(str (subs (name network) 0 3) ":")])
|
||||||
networks)
|
networks)
|
||||||
[quo/text
|
[quo/text
|
||||||
{:size :paragraph-2
|
{:size :paragraph-2
|
||||||
:weight :monospace
|
:weight :monospace}
|
||||||
:style {:color (colors/theme-colors colors/neutral-100 colors/white theme)}}
|
address]]))
|
||||||
address]])
|
|
||||||
|
|
||||||
(defn- suggestion-component
|
(defn- suggestion-component
|
||||||
[]
|
[]
|
||||||
@ -151,9 +151,10 @@
|
|||||||
input-value (reagent/atom "")
|
input-value (reagent/atom "")
|
||||||
input-focused? (reagent/atom false)]
|
input-focused? (reagent/atom false)]
|
||||||
(fn []
|
(fn []
|
||||||
(let [selected-tab (or (rf/sub [:wallet/send-tab]) (:id (first tabs-data)))
|
(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?]))
|
valid-ens-or-address? (boolean (rf/sub [:wallet/valid-ens-or-address?]))
|
||||||
{:keys [color]} (rf/sub [:wallet/current-viewing-account])]
|
local-suggestion-address (rf/sub [:wallet/local-suggestions->full-address])
|
||||||
|
color (rf/sub [:wallet/current-viewing-account-color])]
|
||||||
[floating-button-page/view
|
[floating-button-page/view
|
||||||
{:footer-container-padding 0
|
{:footer-container-padding 0
|
||||||
:header [account-switcher/view
|
:header [account-switcher/view
|
||||||
@ -167,7 +168,8 @@
|
|||||||
:disabled? (not valid-ens-or-address?)
|
:disabled? (not valid-ens-or-address?)
|
||||||
:on-press #(rf/dispatch
|
:on-press #(rf/dispatch
|
||||||
[:wallet/select-send-address
|
[:wallet/select-send-address
|
||||||
{:address @input-value
|
{:address (or local-suggestion-address
|
||||||
|
@input-value)
|
||||||
:stack-id
|
:stack-id
|
||||||
:screen/wallet.select-address}])
|
:screen/wallet.select-address}])
|
||||||
:customization-color color}
|
:customization-color color}
|
||||||
|
@ -262,6 +262,11 @@
|
|||||||
(assoc :balance balance
|
(assoc :balance balance
|
||||||
:formatted-balance formatted-balance)))))
|
:formatted-balance formatted-balance)))))
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:wallet/current-viewing-account-color
|
||||||
|
:<- [:wallet/current-viewing-account]
|
||||||
|
:-> :color)
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:wallet/current-viewing-account-keypair
|
:wallet/current-viewing-account-keypair
|
||||||
:<- [:wallet/current-viewing-account]
|
:<- [:wallet/current-viewing-account]
|
||||||
@ -397,6 +402,12 @@
|
|||||||
:<- [:wallet/search-address]
|
:<- [:wallet/search-address]
|
||||||
:-> :local-suggestions)
|
:-> :local-suggestions)
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:wallet/local-suggestions->full-address
|
||||||
|
:<- [:wallet/local-suggestions]
|
||||||
|
(fn [local-suggestions]
|
||||||
|
(:full-address (first local-suggestions))))
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:wallet/valid-ens-or-address?
|
:wallet/valid-ens-or-address?
|
||||||
:<- [:wallet/search-address]
|
:<- [:wallet/search-address]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user