mirror of
https://github.com/status-im/status-mobile.git
synced 2025-01-13 02:04:28 +00:00
feat(wallet) - implement network configuration on an account (#17862)
This commit is contained in:
parent
f1bcc6259a
commit
7564113cb5
@ -23,7 +23,8 @@
|
|||||||
|
|
||||||
(defn- options
|
(defn- options
|
||||||
[{:keys [theme show-account-selector? options-height]}]
|
[{:keys [theme show-account-selector? options-height]}]
|
||||||
(let [{:keys [name color emoji address]} (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])]
|
||||||
[rn/view
|
[rn/view
|
||||||
{:on-layout #(reset! options-height (oops/oget % "nativeEvent.layout.height"))
|
{:on-layout #(reset! options-height (oops/oget % "nativeEvent.layout.height"))
|
||||||
:style (when show-account-selector? style/options-container)}
|
:style (when show-account-selector? style/options-container)}
|
||||||
@ -44,9 +45,7 @@
|
|||||||
[quo/drawer-top
|
[quo/drawer-top
|
||||||
{:title name
|
{:title name
|
||||||
:type :account
|
:type :account
|
||||||
:networks [{:network-name :ethereum :short-name "eth"}
|
:networks network-preference-details
|
||||||
{:network-name :optimism :short-name "opt"}
|
|
||||||
{:network-name :arbitrum :short-name "arb1"}]
|
|
||||||
:description address
|
:description address
|
||||||
:account-avatar-emoji emoji
|
:account-avatar-emoji emoji
|
||||||
:customization-color color}]
|
:customization-color color}]
|
||||||
|
@ -1,70 +1,104 @@
|
|||||||
(ns status-im2.contexts.wallet.common.sheets.network-preferences.view
|
(ns status-im2.contexts.wallet.common.sheets.network-preferences.view
|
||||||
(:require [quo.core :as quo]
|
(:require [clojure.string :as string]
|
||||||
|
[quo.core :as quo]
|
||||||
[quo.foundations.colors :as colors]
|
[quo.foundations.colors :as colors]
|
||||||
[quo.foundations.resources :as resources]
|
[quo.foundations.resources :as resources]
|
||||||
[quo.theme :as quo.theme]
|
[quo.theme :as quo.theme]
|
||||||
|
[reagent.core :as reagent]
|
||||||
[status-im2.contexts.wallet.common.sheets.network-preferences.style :as style]
|
[status-im2.contexts.wallet.common.sheets.network-preferences.style :as style]
|
||||||
[utils.i18n :as i18n]
|
[utils.i18n :as i18n]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(defn- mainnet
|
|
||||||
[account-color]
|
|
||||||
[{:title "Mainnet"
|
|
||||||
:image :icon-avatar
|
|
||||||
:image-props {:icon (resources/get-network :ethereum)
|
|
||||||
:size :size-20}
|
|
||||||
:action :selector
|
|
||||||
:action-props {:type :checkbox
|
|
||||||
:customization-color account-color}}])
|
|
||||||
|
|
||||||
(defn- networks-list
|
(defn- make-network-item
|
||||||
[account-color]
|
[{:keys [network-name] :as _network}
|
||||||
[{:title "Optimism"
|
{:keys [title color on-change network-preferences state] :as _options}]
|
||||||
:image :icon-avatar
|
{:title (or title (string/capitalize (name network-name)))
|
||||||
:image-props {:icon (resources/get-network :optimism)
|
:image :icon-avatar
|
||||||
:size :size-20}
|
:image-props {:icon (resources/get-network network-name)
|
||||||
:action :selector
|
:size :size-20}
|
||||||
:action-props {:type :checkbox
|
:action :selector
|
||||||
:customization-color account-color}}
|
:action-props {:type (if (= :default state)
|
||||||
{:title "Arbitrum"
|
:filled-checkbox
|
||||||
:image :icon-avatar
|
:checkbox)
|
||||||
:image-props {:icon (resources/get-network :arbitrum)
|
:customization-color color
|
||||||
:size :size-20}
|
:checked? (contains? network-preferences network-name)
|
||||||
:action :selector
|
:on-change on-change}})
|
||||||
:action-props {:type :checkbox
|
|
||||||
:customization-color account-color}}])
|
|
||||||
|
|
||||||
(defn- view-internal
|
(defn- view-internal
|
||||||
[{:keys [on-save theme]}]
|
[]
|
||||||
(let [{:keys [color address]} (rf/sub [:wallet/current-viewing-account])]
|
(let [state (reagent/atom :default)
|
||||||
[:<>
|
{:keys [color address
|
||||||
[quo/drawer-top
|
network-preferences-names]} (rf/sub [:wallet/current-viewing-account])
|
||||||
{:title (i18n/label :t/network-preferences)
|
initial-network-preferences-names network-preferences-names
|
||||||
:description (i18n/label :t/network-preferences-desc)}]
|
network-preferences-names-state (reagent/atom #{})
|
||||||
[quo/data-item
|
toggle-network (fn [network-name]
|
||||||
{:status :default
|
(reset! state :changed)
|
||||||
:size :default
|
(if (contains? @network-preferences-names-state
|
||||||
:label :none
|
network-name)
|
||||||
:blur? false
|
(swap! network-preferences-names-state disj
|
||||||
:card? true
|
network-name)
|
||||||
:title (i18n/label :t/address)
|
(swap! network-preferences-names-state conj
|
||||||
:subtitle address
|
network-name)))
|
||||||
:subtitle-type :default
|
get-current-preferences-names (fn []
|
||||||
:container-style (merge style/data-item
|
(if (= @state :default)
|
||||||
{:background-color (colors/theme-colors colors/neutral-2_5
|
initial-network-preferences-names
|
||||||
colors/neutral-90
|
@network-preferences-names-state))]
|
||||||
theme)})}]
|
(fn [{:keys [on-save theme]}]
|
||||||
[quo/category
|
(let [network-details (rf/sub [:wallet/network-details])
|
||||||
{:list-type :settings
|
mainnet (first network-details)
|
||||||
:data (mainnet color)}]
|
layer-2-networks (rest network-details)
|
||||||
[quo/category
|
current-networks (filter (fn [network]
|
||||||
{:list-type :settings
|
(contains? (get-current-preferences-names)
|
||||||
:label (i18n/label :t/layer-2)
|
(:network-name network)))
|
||||||
:data (networks-list color)}]
|
network-details)]
|
||||||
[quo/bottom-actions
|
[:<>
|
||||||
{:button-one-label (i18n/label :t/update)
|
[quo/drawer-top
|
||||||
:button-one-props {:disabled? true
|
{:title (i18n/label :t/network-preferences)
|
||||||
:on-press on-save
|
:description (i18n/label :t/network-preferences-desc)}]
|
||||||
:customization-color color}}]]))
|
[quo/data-item
|
||||||
|
{:status :default
|
||||||
|
:size :default
|
||||||
|
:description :default
|
||||||
|
:label :none
|
||||||
|
:blur? false
|
||||||
|
:card? true
|
||||||
|
:title (i18n/label :t/address)
|
||||||
|
:custom-subtitle (fn []
|
||||||
|
[quo/address-text
|
||||||
|
{:networks current-networks
|
||||||
|
:address address
|
||||||
|
:format :long}])
|
||||||
|
:container-style (merge style/data-item
|
||||||
|
{:background-color (colors/theme-colors colors/neutral-2_5
|
||||||
|
colors/neutral-90
|
||||||
|
theme)})}]
|
||||||
|
[quo/category
|
||||||
|
{:list-type :settings
|
||||||
|
:data [(make-network-item mainnet
|
||||||
|
{:state @state
|
||||||
|
:title (i18n/label :t/mainnet)
|
||||||
|
:color color
|
||||||
|
:network-preferences (get-current-preferences-names)
|
||||||
|
:on-change #(toggle-network (:network-name
|
||||||
|
mainnet))})]}]
|
||||||
|
[quo/category
|
||||||
|
{:list-type :settings
|
||||||
|
:label (i18n/label :t/layer-2)
|
||||||
|
:data (mapv (fn [network]
|
||||||
|
(make-network-item network
|
||||||
|
{:state @state
|
||||||
|
:color color
|
||||||
|
:network-preferences (get-current-preferences-names)
|
||||||
|
:on-change #(toggle-network (:network-name
|
||||||
|
network))}))
|
||||||
|
layer-2-networks)}]
|
||||||
|
[quo/bottom-actions
|
||||||
|
{:button-one-label (i18n/label :t/confirm)
|
||||||
|
:button-one-props {:disabled? (= @state :default)
|
||||||
|
:on-press (fn []
|
||||||
|
(let [chain-ids (map :chain-id current-networks)]
|
||||||
|
(on-save chain-ids)))
|
||||||
|
:customization-color color}}]]))))
|
||||||
|
|
||||||
(def view (quo.theme/with-theme view-internal))
|
(def view (quo.theme/with-theme view-internal))
|
||||||
|
@ -42,6 +42,10 @@
|
|||||||
(total-raw-balance-in-all-chains)
|
(total-raw-balance-in-all-chains)
|
||||||
(money/token->unit decimals)))
|
(money/token->unit decimals)))
|
||||||
|
|
||||||
|
(defn get-account-by-address
|
||||||
|
[accounts address]
|
||||||
|
(some #(when (= (:address %) address) %) accounts))
|
||||||
|
|
||||||
(defn calculate-raw-balance
|
(defn calculate-raw-balance
|
||||||
[raw-balance decimals]
|
[raw-balance decimals]
|
||||||
(if-let [n (utils.number/parse-int raw-balance nil)]
|
(if-let [n (utils.number/parse-int raw-balance nil)]
|
||||||
|
@ -15,9 +15,10 @@
|
|||||||
(defn- show-save-account-toast
|
(defn- show-save-account-toast
|
||||||
[updated-key theme]
|
[updated-key theme]
|
||||||
(let [message (case updated-key
|
(let [message (case updated-key
|
||||||
:name :t/edit-wallet-account-name-updated-message
|
:name :t/edit-wallet-account-name-updated-message
|
||||||
:color :t/edit-wallet-account-colour-updated-message
|
:color :t/edit-wallet-account-colour-updated-message
|
||||||
:emoji :t/edit-wallet-account-emoji-updated-message
|
:emoji :t/edit-wallet-account-emoji-updated-message
|
||||||
|
:prod-preferred-chain-ids :t/edit-wallet-network-preferences-updated-message
|
||||||
nil)]
|
nil)]
|
||||||
(rf/dispatch [:toasts/upsert
|
(rf/dispatch [:toasts/upsert
|
||||||
{:id :edit-account
|
{:id :edit-account
|
||||||
@ -55,10 +56,11 @@
|
|||||||
:new-value @edited-account-name
|
:new-value @edited-account-name
|
||||||
:theme theme}))]
|
:theme theme}))]
|
||||||
(fn []
|
(fn []
|
||||||
(let [{:keys [name emoji address color]
|
(let [{:keys [name emoji address color] :as account} (rf/sub [:wallet/current-viewing-account])
|
||||||
:as account} (rf/sub [:wallet/current-viewing-account])
|
network-details (rf/sub [:wallet/network-preference-details])
|
||||||
account-name (or @edited-account-name name)
|
account-name (or @edited-account-name name)
|
||||||
button-disabled? (or (nil? @edited-account-name) (= name @edited-account-name))]
|
button-disabled? (or (nil? @edited-account-name)
|
||||||
|
(= name @edited-account-name))]
|
||||||
[create-or-edit-account/view
|
[create-or-edit-account/view
|
||||||
{:page-nav-right-side [{:icon-name :i/delete
|
{:page-nav-right-side [{:icon-name :i/delete
|
||||||
:on-press #(js/alert "Delete account: to be implemented")}]
|
:on-press #(js/alert "Delete account: to be implemented")}]
|
||||||
@ -86,18 +88,22 @@
|
|||||||
:right-icon :i/advanced
|
:right-icon :i/advanced
|
||||||
:card? true
|
:card? true
|
||||||
:title (i18n/label :t/address)
|
:title (i18n/label :t/address)
|
||||||
:custom-subtitle (fn []
|
:custom-subtitle (fn [] [quo/address-text
|
||||||
[quo/address-text
|
{:networks network-details
|
||||||
{:networks [{:network-name :ethereum :short-name "eth"}
|
:address address
|
||||||
{:network-name :optimism :short-name "opt"}
|
:format :long}])
|
||||||
{:network-name :arbitrum :short-name "arb1"}]
|
|
||||||
:address address
|
|
||||||
:format :long}])
|
|
||||||
:on-press (fn []
|
:on-press (fn []
|
||||||
(rf/dispatch [:show-bottom-sheet
|
(rf/dispatch [:show-bottom-sheet
|
||||||
{:content (fn []
|
{:content
|
||||||
[network-preferences/view
|
(fn []
|
||||||
{:on-save #(js/alert "calling on save")}])}]))
|
[network-preferences/view
|
||||||
|
{:on-save (fn [chain-ids]
|
||||||
|
(rf/dispatch [:hide-bottom-sheet])
|
||||||
|
(save-account
|
||||||
|
{:account account
|
||||||
|
:updated-key :prod-preferred-chain-ids
|
||||||
|
:new-value chain-ids
|
||||||
|
:theme theme}))}])}]))
|
||||||
:container-style style/data-item}]]))))
|
:container-style style/data-item}]]))))
|
||||||
|
|
||||||
(def view (quo.theme/with-theme view-internal))
|
(def view (quo.theme/with-theme view-internal))
|
||||||
|
@ -34,13 +34,15 @@
|
|||||||
:wallet/network-details
|
:wallet/network-details
|
||||||
:<- [:wallet/filtered-networks-by-mode false]
|
:<- [:wallet/filtered-networks-by-mode false]
|
||||||
(fn [networks]
|
(fn [networks]
|
||||||
(keep
|
(->> networks
|
||||||
(fn [{:keys [chain-id related-chain-id test?]}]
|
(keep
|
||||||
(let [network-details (get network-list (if test? related-chain-id chain-id))]
|
(fn [{:keys [chain-id related-chain-id layer test?]}]
|
||||||
(assoc network-details
|
(let [network-details (get network-list (if test? related-chain-id chain-id))]
|
||||||
:chain-id chain-id
|
(assoc network-details
|
||||||
:related-chain-id related-chain-id)))
|
:chain-id chain-id
|
||||||
networks)))
|
:related-chain-id related-chain-id
|
||||||
|
:layer layer))))
|
||||||
|
(sort-by (juxt :layer :short-name)))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:wallet/network-details-by-chain-id
|
:wallet/network-details-by-chain-id
|
||||||
|
@ -11,22 +11,28 @@
|
|||||||
{:test [{:test? true
|
{:test [{:test? true
|
||||||
:short-name "eth"
|
:short-name "eth"
|
||||||
:network-name :ethereum
|
:network-name :ethereum
|
||||||
:related-chain-id 1}
|
:related-chain-id 1
|
||||||
|
:layer 1}
|
||||||
{:test? true
|
{:test? true
|
||||||
:short-name "arb1"
|
:short-name "arb1"
|
||||||
:related-chain-id 42161}
|
:related-chain-id 42161
|
||||||
|
:layer 2}
|
||||||
{:test? true
|
{:test? true
|
||||||
:short-name "opt"
|
:short-name "opt"
|
||||||
:related-chain-id 10}]
|
:related-chain-id 10
|
||||||
|
:layer 2}]
|
||||||
:prod [{:test? false
|
:prod [{:test? false
|
||||||
:short-name "eth"
|
:short-name "eth"
|
||||||
:chain-id 1}
|
:chain-id 1
|
||||||
|
:layer 1}
|
||||||
{:test? false
|
{:test? false
|
||||||
:short-name "arb1"
|
:short-name "arb1"
|
||||||
:chain-id 42161}
|
:chain-id 42161
|
||||||
|
:layer 2}
|
||||||
{:test? false
|
{:test? false
|
||||||
:short-name "opt"
|
:short-name "opt"
|
||||||
:chain-id 10}]})
|
:chain-id 10
|
||||||
|
:layer 2}]})
|
||||||
|
|
||||||
(h/deftest-sub :wallet/network-details
|
(h/deftest-sub :wallet/network-details
|
||||||
[sub-name]
|
[sub-name]
|
||||||
@ -34,11 +40,14 @@
|
|||||||
(swap! rf-db/app-db assoc :wallet/networks network-data)
|
(swap! rf-db/app-db assoc :wallet/networks network-data)
|
||||||
(is (= [{:network-name :ethereum
|
(is (= [{:network-name :ethereum
|
||||||
:short-name "eth"
|
:short-name "eth"
|
||||||
:chain-id 1}
|
:chain-id 1
|
||||||
|
:layer 1}
|
||||||
{:network-name :arbitrum
|
{:network-name :arbitrum
|
||||||
:short-name "arb1"
|
:short-name "arb1"
|
||||||
:chain-id 42161}
|
:chain-id 42161
|
||||||
|
:layer 2}
|
||||||
{:network-name :optimism
|
{:network-name :optimism
|
||||||
:short-name "opt"
|
:short-name "opt"
|
||||||
:chain-id 10}]
|
:chain-id 10
|
||||||
|
:layer 2}]
|
||||||
(map #(dissoc % :source :related-chain-id) (rf/sub [sub-name]))))))
|
(map #(dissoc % :source :related-chain-id) (rf/sub [sub-name]))))))
|
||||||
|
@ -4,6 +4,25 @@
|
|||||||
[status-im2.contexts.wallet.common.utils :as utils]
|
[status-im2.contexts.wallet.common.utils :as utils]
|
||||||
[utils.number]))
|
[utils.number]))
|
||||||
|
|
||||||
|
(defn- filter-networks
|
||||||
|
[chain-ids network-details]
|
||||||
|
(filter (fn [{:keys [chain-id]}]
|
||||||
|
(contains? chain-ids chain-id))
|
||||||
|
network-details))
|
||||||
|
|
||||||
|
(defn- assoc-network-preferences-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-preferences-names (->> network-details
|
||||||
|
(filter-networks current-chain-ids)
|
||||||
|
(map :network-name)
|
||||||
|
(set))]
|
||||||
|
(assoc account :network-preferences-names network-preferences-names)))
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:wallet/ui
|
:wallet/ui
|
||||||
:<- [:wallet]
|
:<- [:wallet]
|
||||||
@ -14,6 +33,12 @@
|
|||||||
:<- [:wallet/ui]
|
:<- [:wallet/ui]
|
||||||
:-> :tokens-loading?)
|
:-> :tokens-loading?)
|
||||||
|
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:wallet/current-viewing-account-address
|
||||||
|
:<- [:wallet]
|
||||||
|
:-> :current-viewing-account-address)
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:wallet/watch-address-activity-state
|
:wallet/watch-address-activity-state
|
||||||
:<- [:wallet/ui]
|
:<- [:wallet/ui]
|
||||||
@ -22,10 +47,16 @@
|
|||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:wallet/accounts
|
:wallet/accounts
|
||||||
:<- [:wallet]
|
:<- [:wallet]
|
||||||
:-> #(->> %
|
:<- [:wallet/network-details]
|
||||||
:accounts
|
(fn [[wallet network-details]]
|
||||||
vals
|
;; TODO(@rende11): `testnet?` value would be relevant after this implementation,
|
||||||
(sort-by :position)))
|
;; https://github.com/status-im/status-mobile/issues/17826
|
||||||
|
(let [testnet? false]
|
||||||
|
(->> wallet
|
||||||
|
:accounts
|
||||||
|
vals
|
||||||
|
(map #(assoc-network-preferences-names network-details % testnet?))
|
||||||
|
(sort-by :position)))))
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:wallet/addresses
|
:wallet/addresses
|
||||||
@ -59,12 +90,13 @@
|
|||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:wallet/current-viewing-account
|
:wallet/current-viewing-account
|
||||||
:<- [:wallet]
|
:<- [:wallet/accounts]
|
||||||
|
:<- [:wallet/current-viewing-account-address]
|
||||||
:<- [:wallet/balances]
|
:<- [:wallet/balances]
|
||||||
(fn [[{:keys [current-viewing-account-address] :as wallet} balances]]
|
(fn [[accounts current-viewing-account-address balances]]
|
||||||
(-> wallet
|
(let [current-viewing-account (utils/get-account-by-address accounts current-viewing-account-address)]
|
||||||
(get-in [:accounts current-viewing-account-address])
|
(-> current-viewing-account
|
||||||
(assoc :balance (get balances current-viewing-account-address)))))
|
(assoc :balance (get balances current-viewing-account-address))))))
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:wallet/tokens-filtered
|
:wallet/tokens-filtered
|
||||||
@ -85,11 +117,6 @@
|
|||||||
sorted-tokens)]
|
sorted-tokens)]
|
||||||
filtered-tokens)))
|
filtered-tokens)))
|
||||||
|
|
||||||
(rf/reg-sub
|
|
||||||
:wallet/current-viewing-account-address
|
|
||||||
:<- [:wallet]
|
|
||||||
:-> :current-viewing-account-address)
|
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:wallet/accounts-without-current-viewing-account
|
:wallet/accounts-without-current-viewing-account
|
||||||
:<- [:wallet/accounts]
|
:<- [:wallet/accounts]
|
||||||
@ -122,3 +149,11 @@
|
|||||||
:<- [:chain-id]
|
:<- [:chain-id]
|
||||||
(fn [[current-account chain-id]]
|
(fn [[current-account chain-id]]
|
||||||
(mapv #(calc-token-value % chain-id) (:tokens current-account))))
|
(mapv #(calc-token-value % chain-id) (:tokens current-account))))
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:wallet/network-preference-details
|
||||||
|
:<- [:wallet/current-viewing-account]
|
||||||
|
:<- [:wallet/network-details]
|
||||||
|
(fn [[current-viewing-account network-details]]
|
||||||
|
(let [network-preferences-names (:network-preferences-names current-viewing-account)]
|
||||||
|
(filter #(contains? network-preferences-names (:network-name %)) network-details))))
|
||||||
|
@ -82,6 +82,33 @@
|
|||||||
:removed false
|
:removed false
|
||||||
:tokens tokens-0x2}})
|
:tokens tokens-0x2}})
|
||||||
|
|
||||||
|
(def network-data
|
||||||
|
{:test [{:test? true
|
||||||
|
:short-name "eth"
|
||||||
|
:network-name :ethereum
|
||||||
|
:related-chain-id 1
|
||||||
|
:layer 1}
|
||||||
|
{:test? true
|
||||||
|
:short-name "arb1"
|
||||||
|
:related-chain-id 42161
|
||||||
|
:layer 2}
|
||||||
|
{:test? true
|
||||||
|
:short-name "opt"
|
||||||
|
:related-chain-id 10
|
||||||
|
:layer 2}]
|
||||||
|
:prod [{:test? false
|
||||||
|
:short-name "eth"
|
||||||
|
:chain-id 1
|
||||||
|
:layer 1}
|
||||||
|
{:test? false
|
||||||
|
:short-name "arb1"
|
||||||
|
:chain-id 42161
|
||||||
|
:layer 2}
|
||||||
|
{:test? false
|
||||||
|
:short-name "opt"
|
||||||
|
:chain-id 10
|
||||||
|
:layer 2}]})
|
||||||
|
|
||||||
(h/deftest-sub :wallet/balances
|
(h/deftest-sub :wallet/balances
|
||||||
[sub-name]
|
[sub-name]
|
||||||
(testing "a map: address->balance"
|
(testing "a map: address->balance"
|
||||||
@ -96,86 +123,96 @@
|
|||||||
(h/deftest-sub :wallet/accounts
|
(h/deftest-sub :wallet/accounts
|
||||||
[sub-name]
|
[sub-name]
|
||||||
(testing "returns all accounts without balance"
|
(testing "returns all accounts without balance"
|
||||||
(swap! rf-db/app-db #(assoc-in % [:wallet :accounts] accounts))
|
(swap! rf-db/app-db
|
||||||
|
#(-> %
|
||||||
|
(assoc-in [:wallet :accounts] accounts)
|
||||||
|
(assoc :wallet/networks network-data)))
|
||||||
(is
|
(is
|
||||||
(= (list {:path "m/44'/60'/0'/0/0"
|
(= (list {:path "m/44'/60'/0'/0/0"
|
||||||
:emoji "😃"
|
:emoji "😃"
|
||||||
:key-uid "0x2f5ea39"
|
:key-uid "0x2f5ea39"
|
||||||
:address "0x1"
|
:address "0x1"
|
||||||
:wallet false
|
:wallet false
|
||||||
:name "Account One"
|
:name "Account One"
|
||||||
:type :generated
|
:type :generated
|
||||||
:chat false
|
:chat false
|
||||||
:test-preferred-chain-ids #{5 420 421613}
|
:test-preferred-chain-ids #{5 420 421613}
|
||||||
:color :blue
|
:color :blue
|
||||||
:hidden false
|
:hidden false
|
||||||
:prod-preferred-chain-ids #{1 10 42161}
|
:prod-preferred-chain-ids #{1 10 42161}
|
||||||
:position 0
|
:network-preferences-names #{:ethereum :arbitrum :optimism}
|
||||||
:clock 1698945829328
|
:position 0
|
||||||
:created-at 1698928839000
|
:clock 1698945829328
|
||||||
:operable "fully"
|
:created-at 1698928839000
|
||||||
:mixedcase-address "0x7bcDfc75c431"
|
:operable "fully"
|
||||||
:public-key "0x04371e2d9d66b82f056bc128064"
|
:mixedcase-address "0x7bcDfc75c431"
|
||||||
:removed false
|
:public-key "0x04371e2d9d66b82f056bc128064"
|
||||||
:tokens tokens-0x1}
|
:removed false
|
||||||
{:path "m/44'/60'/0'/0/1"
|
:tokens tokens-0x1}
|
||||||
:emoji "💎"
|
{:path "m/44'/60'/0'/0/1"
|
||||||
:key-uid "0x2f5ea39"
|
:emoji "💎"
|
||||||
:address "0x2"
|
:key-uid "0x2f5ea39"
|
||||||
:wallet false
|
:address "0x2"
|
||||||
:name "Account Two"
|
:wallet false
|
||||||
:type :generated
|
:name "Account Two"
|
||||||
:chat false
|
:type :generated
|
||||||
:test-preferred-chain-ids #{5 420 421613}
|
:chat false
|
||||||
:color :purple
|
:test-preferred-chain-ids #{5 420 421613}
|
||||||
:hidden false
|
:color :purple
|
||||||
:prod-preferred-chain-ids #{1 10 42161}
|
:hidden false
|
||||||
:position 1
|
:prod-preferred-chain-ids #{1 10 42161}
|
||||||
:clock 1698945829328
|
:network-preferences-names #{:ethereum :arbitrum :optimism}
|
||||||
:created-at 1698928839000
|
:position 1
|
||||||
:operable "fully"
|
:clock 1698945829328
|
||||||
:mixedcase-address "0x7bcDfc75c431"
|
:created-at 1698928839000
|
||||||
:public-key "0x04371e2d9d66b82f056bc128064"
|
:operable "fully"
|
||||||
:removed false
|
:mixedcase-address "0x7bcDfc75c431"
|
||||||
:tokens tokens-0x2})
|
:public-key "0x04371e2d9d66b82f056bc128064"
|
||||||
|
:removed false
|
||||||
|
:tokens tokens-0x2})
|
||||||
(rf/sub [sub-name])))))
|
(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
|
(h/deftest-sub :wallet/current-viewing-account
|
||||||
[sub-name]
|
[sub-name]
|
||||||
(testing "returns current account with balance base"
|
(testing "returns current account with balance base"
|
||||||
(swap! rf-db/app-db
|
(swap! rf-db/app-db
|
||||||
#(-> %
|
#(-> %
|
||||||
(assoc-in [:wallet :accounts] accounts)
|
(assoc-in [:wallet :accounts] accounts)
|
||||||
(assoc-in [:wallet :current-viewing-account-address] "0x1")))
|
(assoc-in [:wallet :current-viewing-account-address] "0x1")
|
||||||
|
(assoc :wallet/networks network-data)))
|
||||||
(let [result (rf/sub [sub-name])]
|
(let [result (rf/sub [sub-name])]
|
||||||
|
|
||||||
(is
|
(is
|
||||||
(= {:path "m/44'/60'/0'/0/0"
|
(= {:path "m/44'/60'/0'/0/0"
|
||||||
:emoji "😃"
|
:emoji "😃"
|
||||||
:key-uid "0x2f5ea39"
|
:key-uid "0x2f5ea39"
|
||||||
:address "0x1"
|
:address "0x1"
|
||||||
:wallet false
|
:wallet false
|
||||||
:name "Account One"
|
:name "Account One"
|
||||||
:type :generated
|
:type :generated
|
||||||
:chat false
|
:chat false
|
||||||
:test-preferred-chain-ids #{5 420 421613}
|
:test-preferred-chain-ids #{5 420 421613}
|
||||||
:color :blue
|
:color :blue
|
||||||
:hidden false
|
:hidden false
|
||||||
:prod-preferred-chain-ids #{1 10 42161}
|
:prod-preferred-chain-ids #{1 10 42161}
|
||||||
:position 0
|
:network-preferences-names #{:ethereum :arbitrum :optimism}
|
||||||
:clock 1698945829328
|
:position 0
|
||||||
:created-at 1698928839000
|
:clock 1698945829328
|
||||||
:operable "fully"
|
:created-at 1698928839000
|
||||||
:mixedcase-address "0x7bcDfc75c431"
|
:operable "fully"
|
||||||
:public-key "0x04371e2d9d66b82f056bc128064"
|
:mixedcase-address "0x7bcDfc75c431"
|
||||||
:removed false
|
:public-key "0x04371e2d9d66b82f056bc128064"
|
||||||
:tokens tokens-0x1}
|
:removed false
|
||||||
|
:tokens tokens-0x1}
|
||||||
(dissoc result :balance)))
|
(dissoc result :balance)))
|
||||||
|
|
||||||
(is (money/equal-to (:balance result) (money/bignumber 3250))))))
|
(is (money/equal-to (:balance result) (money/bignumber 3250))))))
|
||||||
|
|
||||||
|
|
||||||
(h/deftest-sub :wallet/addresses
|
(h/deftest-sub :wallet/addresses
|
||||||
[sub-name]
|
[sub-name]
|
||||||
(testing "returns all addresses"
|
(testing "returns all addresses"
|
||||||
@ -201,39 +238,63 @@
|
|||||||
(swap! rf-db/app-db #(assoc-in % [:wallet :ui :watch-address-activity-state] :has-activity))
|
(swap! rf-db/app-db #(assoc-in % [:wallet :ui :watch-address-activity-state] :has-activity))
|
||||||
(is (= :has-activity (rf/sub [sub-name])))))
|
(is (= :has-activity (rf/sub [sub-name])))))
|
||||||
|
|
||||||
(h/deftest-sub :wallet/current-viewing-account-address
|
|
||||||
[sub-name]
|
|
||||||
(testing "returns the address of the current viewing account"
|
|
||||||
(swap! rf-db/app-db #(assoc-in % [:wallet :current-viewing-account-address] "0x1"))
|
|
||||||
(is (= "0x1" (rf/sub [sub-name])))))
|
|
||||||
|
|
||||||
(h/deftest-sub :wallet/accounts-without-current-viewing-account
|
(h/deftest-sub :wallet/accounts-without-current-viewing-account
|
||||||
[sub-name]
|
[sub-name]
|
||||||
(testing "returns the accounts list without the current viewing account in it"
|
(testing "returns the accounts list without the current viewing account in it"
|
||||||
(swap! rf-db/app-db
|
(swap! rf-db/app-db
|
||||||
#(-> %
|
#(-> %
|
||||||
(assoc-in [:wallet :accounts] accounts)
|
(assoc-in [:wallet :accounts] accounts)
|
||||||
(assoc-in [:wallet :current-viewing-account-address] "0x2")))
|
(assoc-in [:wallet :current-viewing-account-address] "0x2")
|
||||||
|
(assoc :wallet/networks network-data)))
|
||||||
(is
|
(is
|
||||||
(= (list
|
(= (list
|
||||||
{:path "m/44'/60'/0'/0/0"
|
{:path "m/44'/60'/0'/0/0"
|
||||||
:emoji "😃"
|
:emoji "😃"
|
||||||
:key-uid "0x2f5ea39"
|
:key-uid "0x2f5ea39"
|
||||||
:address "0x1"
|
:address "0x1"
|
||||||
:wallet false
|
:wallet false
|
||||||
:name "Account One"
|
:name "Account One"
|
||||||
:type :generated
|
:type :generated
|
||||||
:chat false
|
:chat false
|
||||||
:test-preferred-chain-ids #{5 420 421613}
|
:test-preferred-chain-ids #{5 420 421613}
|
||||||
:color :blue
|
:color :blue
|
||||||
:hidden false
|
:hidden false
|
||||||
:prod-preferred-chain-ids #{1 10 42161}
|
:prod-preferred-chain-ids #{1 10 42161}
|
||||||
:position 0
|
:network-preferences-names #{:ethereum :arbitrum :optimism}
|
||||||
:clock 1698945829328
|
:position 0
|
||||||
:created-at 1698928839000
|
:clock 1698945829328
|
||||||
:operable "fully"
|
:created-at 1698928839000
|
||||||
:mixedcase-address "0x7bcDfc75c431"
|
:operable "fully"
|
||||||
:public-key "0x04371e2d9d66b82f056bc128064"
|
:mixedcase-address "0x7bcDfc75c431"
|
||||||
:removed false
|
:public-key "0x04371e2d9d66b82f056bc128064"
|
||||||
:tokens tokens-0x1})
|
:removed false
|
||||||
|
:tokens tokens-0x1})
|
||||||
(rf/sub [sub-name])))))
|
(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/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)))))))
|
||||||
|
@ -2375,7 +2375,7 @@
|
|||||||
"account-info": "Account info",
|
"account-info": "Account info",
|
||||||
"account-name-input-placeholder": "Account name",
|
"account-name-input-placeholder": "Account name",
|
||||||
"network-preferences": "Network preferences",
|
"network-preferences": "Network preferences",
|
||||||
"network-preferences-desc": "Select which network this address is happy to receive funds on",
|
"network-preferences-desc": "Select which networks to receive funds on",
|
||||||
"layer-2": "Layer 2",
|
"layer-2": "Layer 2",
|
||||||
"manage-tokens": "Manage tokens",
|
"manage-tokens": "Manage tokens",
|
||||||
"edit-derivation-path": "Edit derivation path",
|
"edit-derivation-path": "Edit derivation path",
|
||||||
@ -2389,6 +2389,7 @@
|
|||||||
"edit-wallet-account-emoji-updated-message": "Account emoji has been updated",
|
"edit-wallet-account-emoji-updated-message": "Account emoji has been updated",
|
||||||
"edit-wallet-account-name-updated-message": "Account name has been updated",
|
"edit-wallet-account-name-updated-message": "Account name has been updated",
|
||||||
"edit-wallet-account-colour-updated-message": "Account colour has been updated",
|
"edit-wallet-account-colour-updated-message": "Account colour has been updated",
|
||||||
|
"edit-wallet-network-preferences-updated-message": "Account network preferences has been updated",
|
||||||
"search-assets": "Search assets",
|
"search-assets": "Search assets",
|
||||||
"address-activity": "This address has activity",
|
"address-activity": "This address has activity",
|
||||||
"keypairs": "Keypairs",
|
"keypairs": "Keypairs",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user