Skip to content

Commit

Permalink
Store as set
Browse files Browse the repository at this point in the history
  • Loading branch information
Rende11 committed Nov 13, 2023
1 parent f7680bf commit 2717291
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
(defn- view-internal
[]
(let [{:keys [color address network-preference-names]} (rf/sub [:wallet/current-viewing-account])
network-preference-names-state (reagent/atom (set network-preference-names))
network-preference-names-state (reagent/atom network-preference-names)
toggle-network (fn [network-name]
(if (contains? @network-preference-names-state
network-name)
Expand Down
5 changes: 3 additions & 2 deletions src/status_im2/subs/wallet/wallet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
prod-preferred-chain-ids)
network-preference-names (->> network-details
(filter-networks current-chain-ids)
(map :network-name))]
(map :network-name)
(set))]
(assoc account :network-preference-names network-preference-names)))

(re-frame/reg-sub
Expand Down Expand Up @@ -91,4 +92,4 @@
:<- [:wallet/network-details]
(fn [[current-viewing-account network-details]]
(let [network-preference-names (:network-preference-names current-viewing-account)]
(filter #(contains? (set network-preference-names) (:network-name %)) network-details))))
(filter #(contains? network-preference-names (:network-name %)) network-details))))
149 changes: 84 additions & 65 deletions src/status_im2/subs/wallet/wallet_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@
(swap! rf-db/app-db #(-> %
(assoc-in [:wallet :accounts] accounts)
(assoc :wallet/tokens tokens)))
(is (= `({:address "0x1"
:balance 3250}
{:address "0x2"
:balance 2100})
(is (= [{:address "0x1"
:balance 3250}
{:address "0x2"
:balance 2100}]
(rf/sub [sub-name])))))

(h/deftest-sub :wallet/accounts
Expand All @@ -131,48 +131,57 @@
(swap! rf-db/app-db
#(-> %
(assoc-in [:wallet :accounts] accounts)
(assoc :wallet/tokens tokens)))
(assoc :wallet/tokens tokens)
(assoc :wallet/networks network-data)))
(is
(= `({:path "m/44'/60'/0'/0/0"
:emoji "😃"
:key-uid "0x2f5ea39"
:address "0x1"
:wallet false
:name "Account One"
:type :generated
:chat false
:test-preferred-chain-ids #{5 420 421613}
:color :blue
:hidden false
:prod-preferred-chain-ids #{1 10 42161}
:position 0
:clock 1698945829328
:created-at 1698928839000
:operable "fully"
:mixedcase-address "0x7bcDfc75c431"
:public-key "0x04371e2d9d66b82f056bc128064"
:removed false}
{:path "m/44'/60'/0'/0/1"
:emoji "💎"
:key-uid "0x2f5ea39"
:address "0x2"
:wallet false
:name "Account Two"
:type :generated
:chat false
:test-preferred-chain-ids #{5 420 421613}
:color :purple
:hidden false
:prod-preferred-chain-ids #{1 10 42161}
:position 1
:clock 1698945829328
:created-at 1698928839000
:operable "fully"
:mixedcase-address "0x7bcDfc75c431"
:public-key "0x04371e2d9d66b82f056bc128064"
:removed false})
(= [{:path "m/44'/60'/0'/0/0"
:emoji "😃"
:key-uid "0x2f5ea39"
:address "0x1"
:wallet false
:name "Account One"
:type :generated
:chat false
:test-preferred-chain-ids #{5 420 421613}
:color :blue
:hidden false
:prod-preferred-chain-ids #{1 10 42161}
:network-preference-names #{:ethereum :arbitrum :optimism}
:position 0
:clock 1698945829328
:created-at 1698928839000
:operable "fully"
:mixedcase-address "0x7bcDfc75c431"
:public-key "0x04371e2d9d66b82f056bc128064"
:removed false}
{:path "m/44'/60'/0'/0/1"
:emoji "💎"
:key-uid "0x2f5ea39"
:address "0x2"
:wallet false
:name "Account Two"
:type :generated
:chat false
:test-preferred-chain-ids #{5 420 421613}
:color :purple
:hidden false
:prod-preferred-chain-ids #{1 10 42161}
:network-preference-names #{:ethereum :arbitrum :optimism}
:position 1
:clock 1698945829328
:created-at 1698928839000
:operable "fully"
:mixedcase-address "0x7bcDfc75c431"
:public-key "0x04371e2d9d66b82f056bc128064"
:removed false}]
(rf/sub [sub-name])))))

(h/deftest-sub :wallet/current-viewing-account-address
[sub-name]
(testing "returns current viewing account address"
(swap! rf-db/app-db #(assoc-in % [:wallet :current-viewing-account-address] "0x1"))
(is (= "0x1" (rf/sub [sub-name])))))

(h/deftest-sub :wallet/current-viewing-account
[sub-name]
(testing "returns current account with balance base"
Expand All @@ -195,32 +204,42 @@
:color :blue
:hidden false
:prod-preferred-chain-ids #{1 10 42161}
:network-preference-names #{:ethereum :arbitrum :optimism}
:position 0
:clock 1698945829328
:created-at 1698928839000
:operable "fully"
:mixedcase-address "0x7bcDfc75c431"
:public-key "0x04371e2d9d66b82f056bc128064"
:removed false
:balance 3250
:network-preferences #{:ethereum :arbitrum :optimism}
:networks #{{:short-name "opt"
:network-name :optimism
:chain-id 10
:related-chain-id nil
:layer 2}
{:short-name "eth"
:network-name :ethereum
:chain-id 1
:related-chain-id nil
:layer 1}
{:short-name "arb1"
:network-name :arbitrum
:chain-id 42161
:related-chain-id nil
:layer 2}}}
(update (rf/sub [sub-name])
:networks
(fn [nx]
;; Exclude `:source` for the correct equality check
(set (map #(dissoc % :source) nx))))))))
:balance 3250}
(rf/sub [sub-name])))))

(h/deftest-sub :wallet/network-preference-details
[sub-name]
(testing "returns current viewing account address"
(swap! rf-db/app-db
#(-> %
(assoc-in [:wallet :accounts] accounts)
(assoc-in [:wallet :current-viewing-account-address] "0x1")
(assoc :wallet/tokens tokens)
(assoc :wallet/networks network-data)))
(is
(= [{:short-name "eth"
:network-name :ethereum
:chain-id 1
:related-chain-id nil
:layer 1}
{:short-name "arb1"
:network-name :arbitrum
:chain-id 42161
:related-chain-id nil
:layer 2}
{:short-name "opt"
:network-name :optimism
:chain-id 10
:related-chain-id nil
:layer 2}]
(->> (rf/sub [sub-name])
;; Removed `#js source` property for correct compare
(map #(dissoc % :source)))))))

0 comments on commit 2717291

Please sign in to comment.