Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Rende11 committed Nov 13, 2023
1 parent fc2505f commit 0a8a4ab
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

(defn view
[]
(let [{:keys [name color emoji address networks]} (rf/sub [:wallet/current-viewing-account])]
(let [{:keys [name color emoji address]} (rf/sub [:wallet/current-viewing-account])
network-preference-details (rf/sub [:wallet/network-preference-details])]
[:<>
[quo/drawer-top
{:title name
:type :account
:networks networks
:networks network-preference-details
:description address
:account-avatar-emoji emoji
:customization-color color}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,22 @@

(defn- view-internal
[]
(let [{:keys [color address network-preferences]} (rf/sub [:wallet/current-viewing-account])
network-preferences network-preferences
network-preferences-state (reagent/atom network-preferences)
toggle-network (fn [network-name]
(if (contains? @network-preferences-state
network-name)
(swap! network-preferences-state disj
network-name)
(swap! network-preferences-state conj
network-name)))]
(let [{:keys [color address network-preference-names]} (rf/sub [:wallet/current-viewing-account])
network-preference-names-state (reagent/atom (set network-preference-names))
toggle-network (fn [network-name]
(if (contains? @network-preference-names-state
network-name)
(swap! network-preference-names-state disj
network-name)
(swap! network-preference-names-state conj
network-name)))]
(fn [{:keys [on-save theme]}]
(let [network-details (rf/sub [:wallet/network-details])
mainnet (first (filter #(= 1 (:layer %)) network-details))
layer-2-networks (remove #(= 1 (:layer %)) network-details)
mainnet (first network-details)
layer-2-networks (rest network-details)
current-networks (->> network-details
(filter
#(contains? @network-preferences-state (:network-name %))))]
#(contains? @network-preference-names-state (:network-name %))))]
[:<>
[quo/drawer-top
{:title (i18n/label :t/network-preferences)
Expand All @@ -68,22 +67,23 @@
{:list-type :settings
:data [(make-network-item mainnet
{:color color
:network-preferences @network-preferences-state
:network-preferences @network-preference-names-state
:on-change #(toggle-network (:network-name
mainnet))})]}]
[quo/category
{:list-type :settings
:label (i18n/label :t/layer-2)
:data (mapv #(make-network-item %
{:color color
:network-preferences @network-preferences-state
:network-preferences @network-preference-names-state
:on-change (fn [_]
(toggle-network (:network-name
%)))})
layer-2-networks)}]
[quo/bottom-actions
{:button-one-label (i18n/label :t/update)
:button-one-props {:disabled? (= @network-preferences-state network-preferences)
:button-one-props {:disabled? (= @network-preference-names-state
network-preference-names)
:on-press (fn []
(let [chain-ids (map :chain-id current-networks)]
(on-save chain-ids)))
Expand Down
11 changes: 6 additions & 5 deletions src/status_im2/contexts/wallet/edit_account/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@
:value @edited-account-name
:theme theme}))]
(fn []
(let [{:keys [name emoji address color networks]
:as account} (rf/sub [:wallet/current-viewing-account])
account-name (or @edited-account-name name)
button-disabled? (or (nil? @edited-account-name) (= name @edited-account-name))]
(let [{:keys [name emoji address color] :as account} (rf/sub [:wallet/current-viewing-account])
network-details (rf/sub [:wallet/network-preference-details])
account-name (or @edited-account-name name)
button-disabled? (or (nil? @edited-account-name)
(= name @edited-account-name))]
[create-or-edit-account/view
{:page-nav-right-side [{:icon-name :i/delete
:on-press #(js/alert "Delete account: to be implemented")}]
Expand Down Expand Up @@ -85,7 +86,7 @@
:card? true
:title (i18n/label :t/address)
:custom-subtitle (fn [] [quo/address-text
{:networks networks
{:networks network-details
:address address
:format :long}])
:on-press (fn []
Expand Down
18 changes: 10 additions & 8 deletions src/status_im2/subs/wallet/networks.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
:wallet/network-details
:<- [:wallet/filtered-networks-by-mode false]
(fn [networks]
(keep
(fn [{:keys [chain-id related-chain-id layer test?]}]
(let [network-details (get network-list (if test? related-chain-id chain-id))]
(assoc network-details
:chain-id chain-id
:related-chain-id related-chain-id
:layer layer)))
networks)))
(->>
networks
(keep
(fn [{:keys [chain-id related-chain-id layer test?]}]
(let [network-details (get network-list (if test? related-chain-id chain-id))]
(assoc network-details
:chain-id chain-id
:related-chain-id related-chain-id
:layer layer))))
(sort-by (juxt :layer :short-name)))))
2 changes: 1 addition & 1 deletion src/status_im2/subs/wallet/networks_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
:layer 2}
{:test? false
:short-name "opt"
:chain-id 10
:chain-id 10
:layer 2}]})

(h/deftest-sub :wallet/network-details
Expand Down
62 changes: 39 additions & 23 deletions src/status_im2/subs/wallet/wallet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,35 @@
(contains? chain-ids chain-id))
network-details))

(defn- assoc-network-preference-names
[network-details account testnet?]
(let [{:keys [prod-preferred-chain-ids
test-preferred-chain-ids]} account
current-chain-ids (if testnet?
test-preferred-chain-ids
prod-preferred-chain-ids)
network-preference-names (->> network-details
(filter-networks current-chain-ids)
(map :network-name))]
(assoc account :network-preference-names network-preference-names)))

(re-frame/reg-sub
:wallet/current-viewing-account-address
:<- [:wallet]
:-> :current-viewing-account-address)

(re-frame/reg-sub
:wallet/accounts
:<- [:wallet]
:-> #(->> %
:accounts
vals
(sort-by :position)))
:<- [:wallet/network-details]
(fn [[wallet network-details]]
;; will get in follow up
(let [testnet? false]
(->> wallet
:accounts
vals
(map #(assoc-network-preference-names network-details % testnet?))
(sort-by :position)))))

(re-frame/reg-sub
:wallet/balances
Expand All @@ -55,24 +77,18 @@

(re-frame/reg-sub
:wallet/current-viewing-account
:<- [:wallet]
:<- [:wallet/accounts]
:<- [:wallet/current-viewing-account-address]
:<- [:wallet/balances]
:<- [:wallet/network-details]
(fn [[{:keys [current-viewing-account-address] :as wallet} balances network-details]]
(let [testnet? false ; will get from sub in follow up
current-viewing-account (get-in wallet [:accounts current-viewing-account-address])
{:keys [prod-preferred-chain-ids
test-preferred-chain-ids]} current-viewing-account
current-chain-ids (if testnet?
test-preferred-chain-ids
prod-preferred-chain-ids)
networks (->> network-details
(filter-networks current-chain-ids)
(set))
network-preferences (->> networks
(map :network-name)
(set))]
(fn [[accounts current-viewing-account-address balances]]
(let [current-viewing-account (utils/get-account-by-address accounts current-viewing-account-address)]
(-> current-viewing-account
(assoc :balance (utils/get-balance-by-address balances current-viewing-account-address))
(assoc :networks networks)
(assoc :network-preferences network-preferences)))))
(assoc :balance (utils/get-balance-by-address balances current-viewing-account-address))))))

(re-frame/reg-sub
:wallet/network-preference-details
:<- [:wallet/current-viewing-account]
:<- [: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))))
34 changes: 18 additions & 16 deletions src/status_im2/subs/wallet/wallet_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
:layer 2}
{:test? false
:short-name "opt"
:chain-id 10
:chain-id 10
:layer 2}]})

(h/deftest-sub :wallet/balances
Expand Down Expand Up @@ -204,21 +204,23 @@
: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
:networks #{{:short-name "opt"
:network-name :optimism
:chain-id 10
:related-chain-id nil
:layer 1}
{:short-name "arb1"
:network-name :arbitrum
:chain-id 42161
:layer 2}
{:short-name "eth"
:network-name :ethereum
:chain-id 1
:related-chain-id nil
:layer 2}}}
: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))))))))
:networks
(fn [nx]
;; Exclude `:source` for the correct equality check
(set (map #(dissoc % :source) nx))))))))

0 comments on commit 0a8a4ab

Please sign in to comment.