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]
|
2023-09-27 09:57:51 +00:00
|
|
|
[status-im2.config :as config]
|
|
|
|
[utils.ethereum.chain :as chain]))
|
2022-09-21 14:03:06 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn- filter-networks
|
|
|
|
[network-type]
|
2022-09-21 14:03:06 +00:00
|
|
|
(fn [network]
|
2023-09-27 09:57:51 +00:00
|
|
|
(let [chain-id (chain/network->chain-id network)
|
|
|
|
testnet? (chain/testnet? chain-id)
|
2022-09-21 14:03:06 +00:00
|
|
|
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))))
|