fix: test networks short-name->id (#18692)

* fix: test networks short-name->id
This commit is contained in:
Omar Basem 2024-02-05 09:15:30 +04:00 committed by GitHub
parent 154fbb156d
commit a6565b52ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 23 deletions

View File

@ -410,14 +410,14 @@
(def ^:const ens-action-type-set-pub-key 2)
;; wallet
(def ^:const ethereum-mainnet-chain-id 1)
(def ^:const ethereum-goerli-chain-id 5)
(def ^:const ethereum-chain-id 1)
(def ^:const goerli-chain-id 5)
(def ^:const arbitrum-chain-id 42161)
(def ^:const arbitrum-testnet-chain-id 421613)
(def ^:const optimism-chain-id 10)
(def ^:const optimism-testnet-chain-id 420)
(def ^:const ethereum-sepolia-chain-id 11155111)
(def ^:const arbitrum-mainnet-chain-id 42161)
(def ^:const arbitrum-goerli-chain-id 421613)
(def ^:const arbitrum-sepolia-chain-id 421614)
(def ^:const optimism-mainnet-chain-id 10)
(def ^:const optimism-goerli-chain-id 420)
(def ^:const optimism-sepolia-chain-id 11155420)
(def ^:const mainnet-short-name "eth")

View File

@ -190,20 +190,30 @@
address))
(def id->network
{constants/ethereum-mainnet-chain-id :ethereum
constants/ethereum-goerli-chain-id :ethereum
{constants/ethereum-chain-id :ethereum
constants/goerli-chain-id :ethereum
constants/ethereum-sepolia-chain-id :ethereum
constants/optimism-mainnet-chain-id :optimism
constants/optimism-goerli-chain-id :optimism
constants/optimism-chain-id :optimism
constants/optimism-testnet-chain-id :optimism
constants/optimism-sepolia-chain-id :optimism
constants/arbitrum-mainnet-chain-id :arbitrum
constants/arbitrum-goerli-chain-id :arbitrum
constants/arbitrum-chain-id :arbitrum
constants/arbitrum-testnet-chain-id :arbitrum
constants/arbitrum-sepolia-chain-id :arbitrum})
(def short-name->id
{:eth constants/ethereum-mainnet-chain-id
:opt constants/optimism-mainnet-chain-id
:arb1 constants/arbitrum-mainnet-chain-id})
(defn- get-chain-id
[test-net?]
(if test-net?
{:eth constants/goerli-chain-id
:opt constants/optimism-testnet-chain-id
:arb1 constants/arbitrum-testnet-chain-id}
{:eth constants/ethereum-chain-id
:opt constants/optimism-chain-id
:arb1 constants/arbitrum-chain-id}))
(defn short-name->id
[short-name test-net?]
(let [chain-id-map (get-chain-id test-net?)]
(get chain-id-map short-name)))
(defn get-standard-fiat-format
[crypto-value currency-symbol fiat-value]

View File

@ -62,10 +62,11 @@
:wallet/select-send-address
(fn [{:keys [db]} [{:keys [address token recipient stack-id]}]]
(let [[prefix to-address] (utils/split-prefix-and-address address)
test-net? (get-in db [:profile/profile :test-networks-enabled?])
prefix-seq (string/split prefix #":")
selected-networks (->> prefix-seq
(remove string/blank?)
(mapv #(utils/short-name->id (keyword %))))]
(mapv #(utils/short-name->id (keyword %) test-net?)))]
{:db (-> db
(assoc-in [:wallet :ui :send :recipient] (or recipient address))
(assoc-in [:wallet :ui :send :to-address] to-address)

View File

@ -33,16 +33,16 @@
(defn get-network-details
[chain-id]
(case chain-id
(constants/ethereum-mainnet-chain-id constants/ethereum-goerli-chain-id
constants/ethereum-sepolia-chain-id)
(constants/ethereum-chain-id constants/goerli-chain-id
constants/ethereum-sepolia-chain-id)
mainnet-network-details
(constants/arbitrum-mainnet-chain-id constants/arbitrum-goerli-chain-id
constants/arbitrum-sepolia-chain-id)
(constants/arbitrum-chain-id constants/arbitrum-testnet-chain-id
constants/arbitrum-sepolia-chain-id)
arbitrum-network-details
(constants/optimism-mainnet-chain-id constants/optimism-goerli-chain-id
constants/optimism-sepolia-chain-id)
(constants/optimism-chain-id constants/optimism-testnet-chain-id
constants/optimism-sepolia-chain-id)
optimism-network-details
nil))