Skip to content

Commit

Permalink
fix: test networks short-name->id (#18692)
Browse files Browse the repository at this point in the history
* fix: test networks short-name->id
  • Loading branch information
OmarBasem authored Feb 5, 2024
1 parent 154fbb1 commit a6565b5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
30 changes: 20 additions & 10 deletions src/status_im/contexts/wallet/common/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion src/status_im/contexts/wallet/send/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/status_im/subs/wallet/networks.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit a6565b5

Please sign in to comment.