From ed7463132add63f3dfae7d92a042a868d0ee6ccb Mon Sep 17 00:00:00 2001 From: mmilad75 <55688834+mmilad75@users.noreply.github.com> Date: Wed, 24 Jan 2024 19:17:08 +0330 Subject: [PATCH] The collectibles are not supported on Optimism and Arbitrum #18507 (#18562) * add chain id to the request * add tests * fix lint issues * remove OPENSEA_API_KEY * move subscription to a helper method for chain-ids --- .../contexts/wallet/events/collectibles.cljs | 5 +++-- src/status_im/subs/wallet/networks_test.cljs | 3 +++ src/utils/ethereum/chain.cljs | 7 +++++++ src/utils/ethereum/chain_test.cljs | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/status_im/contexts/wallet/events/collectibles.cljs b/src/status_im/contexts/wallet/events/collectibles.cljs index 477f25dcc3..cc4b0371c3 100644 --- a/src/status_im/contexts/wallet/events/collectibles.cljs +++ b/src/status_im/contexts/wallet/events/collectibles.cljs @@ -2,9 +2,9 @@ (:require [camel-snake-kebab.core :as csk] [camel-snake-kebab.extras :as cske] [clojure.string :as string] - [re-frame.core :as rf] [taoensso.timbre :as log] [utils.ethereum.chain :as chain] + [utils.re-frame :as rf] [utils.transforms :as types])) (def collectible-data-types @@ -66,8 +66,9 @@ data-type (collectible-data-types :header) fetch-criteria {:fetch-type (fetch-type :fetch-if-not-cached) :max-cache-age-seconds max-cache-age-seconds} + chain-ids (chain/chain-ids db) request-params [request-id - [(chain/chain-id db)] + chain-ids (keys (get-in db [:wallet :accounts])) collectibles-filter start-at-index diff --git a/src/status_im/subs/wallet/networks_test.cljs b/src/status_im/subs/wallet/networks_test.cljs index 68e9e099fa..feef9a07ec 100644 --- a/src/status_im/subs/wallet/networks_test.cljs +++ b/src/status_im/subs/wallet/networks_test.cljs @@ -12,14 +12,17 @@ :short-name "eth" :network-name :ethereum :related-chain-id 1 + :chain-id 3 :layer 1} {:test? true :short-name "arb1" :related-chain-id 42161 + :chain-id 4 :layer 2} {:test? true :short-name "opt" :related-chain-id 10 + :chain-id 5 :layer 2}] :prod [{:test? false :short-name "eth" diff --git a/src/utils/ethereum/chain.cljs b/src/utils/ethereum/chain.cljs index ba9a49ce45..a150cb5d71 100644 --- a/src/utils/ethereum/chain.cljs +++ b/src/utils/ethereum/chain.cljs @@ -84,3 +84,10 @@ (defn chain-id [db] (network->chain-id (get-current-network db))) + +(defn chain-ids + [db] + (let [test-networks-enabled? (get-in db [:profile/profile :test-networks-enabled?]) + networks (get-in db [:wallet :networks]) + env-networks (get networks (if test-networks-enabled? :test :prod))] + (map :chain-id env-networks))) diff --git a/src/utils/ethereum/chain_test.cljs b/src/utils/ethereum/chain_test.cljs index 5cbd0d5ca7..2258d68338 100644 --- a/src/utils/ethereum/chain_test.cljs +++ b/src/utils/ethereum/chain_test.cljs @@ -3,7 +3,21 @@ [cljs.test :refer-macros [deftest is]] [utils.ethereum.chain :as chain])) +(defn chain-ids-db + [test-networks-enabled?] + {:profile/profile {:test-networks-enabled? test-networks-enabled?} + :wallet {:networks {:test [{:chain-id 3} + {:chain-id 4} + {:chain-id 5}] + :prod [{:chain-id 1} + {:chain-id 42161} + {:chain-id 10}]}}}) + (deftest chain-id->chain-keyword (is (= (chain/chain-id->chain-keyword 1) :mainnet)) (is (= (chain/chain-id->chain-keyword 5) :goerli)) (is (= (chain/chain-id->chain-keyword 5777) :custom))) + +(deftest chain-ids + (is (= (chain/chain-ids (chain-ids-db false)) [1 42161 10])) + (is (= (chain/chain-ids (chain-ids-db true)) [3 4 5])))