2022-11-14 18:16:55 +00:00
|
|
|
(ns status-im2.subs.networks
|
2022-12-20 14:45:37 +00:00
|
|
|
(:require [re-frame.core :as re-frame]
|
|
|
|
[status-im.ethereum.core :as ethereum]
|
2022-09-21 14:03:06 +00:00
|
|
|
[status-im.utils.config :as config]))
|
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn- filter-networks
|
|
|
|
[network-type]
|
2022-09-21 14:03:06 +00:00
|
|
|
(fn [network]
|
|
|
|
(let [chain-id (ethereum/network->chain-id network)
|
|
|
|
testnet? (ethereum/testnet? chain-id)
|
|
|
|
custom? (:custom? network)]
|
|
|
|
(case network-type
|
2022-12-20 14:45:37 +00:00
|
|
|
:custom custom?
|
2022-09-21 14:03:06 +00:00
|
|
|
:mainnet (and (not custom?) (not testnet?))
|
|
|
|
:testnet (and (not custom?) testnet?)))))
|
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn- label-networks
|
|
|
|
[default-networks]
|
2022-09-21 14:03:06 +00:00
|
|
|
(fn [network]
|
|
|
|
(let [custom? (not (default-networks (:id network)))]
|
|
|
|
(assoc network :custom? custom?))))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:get-networks
|
|
|
|
:<- [:networks/networks]
|
|
|
|
(fn [networks]
|
2022-12-20 14:45:37 +00:00
|
|
|
(let [networks (map (label-networks (into #{} (map :id config/default-networks)))
|
|
|
|
(sort-by :name (vals networks)))
|
2022-09-21 14:03:06 +00:00
|
|
|
types [:mainnet :testnet :custom]]
|
|
|
|
(zipmap
|
|
|
|
types
|
|
|
|
(map #(filter (filter-networks %) networks) types)))))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:manage-network-valid?
|
|
|
|
:<- [:networks/manage]
|
|
|
|
(fn [manage]
|
2022-10-21 09:08:34 +00:00
|
|
|
(not-any? :error (vals manage))))
|