fix(community): remove non operable accounts in the selection of sharing addresses with the community (#20636)

This commit removes the non-operable accounts in the "Addresses for permission" and "Airdrop address" selections while joining a community

Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com>
This commit is contained in:
Mohamed Javid 2024-07-12 16:29:43 +05:30 committed by GitHub
parent d2e975f6d9
commit 1c85b292f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 212 additions and 188 deletions

View File

@ -18,7 +18,7 @@
(defn do-init-permission-addresses (defn do-init-permission-addresses
[{:keys [db]} [community-id revealed-accounts]] [{:keys [db]} [community-id revealed-accounts]]
(let [wallet-accounts (utils/sorted-non-watch-only-accounts db) (let [wallet-accounts (utils/sorted-operable-non-watch-only-accounts db)
addresses-to-reveal (if (seq revealed-accounts) addresses-to-reveal (if (seq revealed-accounts)
(set (keys revealed-accounts)) (set (keys revealed-accounts))
;; Reveal all addresses as fallback. ;; Reveal all addresses as fallback.
@ -62,7 +62,7 @@
status-go will default to all available." status-go will default to all available."
[{:keys [db]} [{:keys [community-id password on-success addresses airdrop-address]}]] [{:keys [db]} [{:keys [community-id password on-success addresses airdrop-address]}]]
(let [pub-key (get-in db [:profile/profile :public-key]) (let [pub-key (get-in db [:profile/profile :public-key])
wallet-accounts (utils/sorted-non-watch-only-accounts db) wallet-accounts (utils/sorted-operable-non-watch-only-accounts db)
addresses-to-reveal (if (seq addresses) addresses-to-reveal (if (seq addresses)
(set addresses) (set addresses)
(get-in db [:communities/all-addresses-to-reveal community-id])) (get-in db [:communities/all-addresses-to-reveal community-id]))

View File

@ -9,17 +9,25 @@
(def wallet-accounts (def wallet-accounts
{"0xA" {:address "0xA" {"0xA" {:address "0xA"
:watch-only? true :watch-only? true
:operable? true
:position 2 :position 2
:color :red :color :red
:emoji "🦇"} :emoji "🦇"}
"0xB" {:address "0xB" "0xB" {:address "0xB"
:operable? true
:position 0 :position 0
:color :blue :color :blue
:emoji "🐈"} :emoji "🐈"}
"0xC" {:address "0xC" "0xC" {:address "0xC"
:operable? true
:position 1 :position 1
:color :orange :color :orange
:emoji "🛏️"}}) :emoji "🛏️"}
"0xD" {:address "0xD"
:operable? false
:position 3
:color :flamingo
:emoji "🦩"}})
(def permissioned-accounts (def permissioned-accounts
[{:address "0xB" [{:address "0xB"

View File

@ -22,7 +22,7 @@
airdrop-account (rf/sub [:communities/airdrop-account id]) airdrop-account (rf/sub [:communities/airdrop-account id])
revealed-accounts (rf/sub [:communities/accounts-to-reveal id]) revealed-accounts (rf/sub [:communities/accounts-to-reveal id])
revealed-accounts-count (count revealed-accounts) revealed-accounts-count (count revealed-accounts)
wallet-accounts-count (count (rf/sub [:wallet/accounts-without-watched-accounts])) wallet-accounts-count (count (rf/sub [:wallet/operable-accounts-without-watched-accounts]))
addresses-shared-text (if (= revealed-accounts-count wallet-accounts-count) addresses-shared-text (if (= revealed-accounts-count wallet-accounts-count)
(i18n/label :t/all-addresses) (i18n/label :t/all-addresses)
(i18n/label-pluralize (i18n/label-pluralize

View File

@ -120,7 +120,7 @@
(defn set-permissioned-accounts (defn set-permissioned-accounts
[{:keys [db]} [community-id addresses-to-reveal]] [{:keys [db]} [community-id addresses-to-reveal]]
(let [addresses-to-reveal (set addresses-to-reveal) (let [addresses-to-reveal (set addresses-to-reveal)
wallet-accounts (utils/sorted-non-watch-only-accounts db) wallet-accounts (utils/sorted-operable-non-watch-only-accounts db)
current-airdrop-address (get-in db [:communities/all-airdrop-addresses community-id]) current-airdrop-address (get-in db [:communities/all-airdrop-addresses community-id])
new-airdrop-address (if (contains? addresses-to-reveal current-airdrop-address) new-airdrop-address (if (contains? addresses-to-reveal current-airdrop-address)
current-airdrop-address current-airdrop-address
@ -142,7 +142,7 @@
[{:keys [db]} [community-id new-value]] [{:keys [db]} [community-id new-value]]
(let [current-addresses (get-in db [:communities/all-addresses-to-reveal community-id]) (let [current-addresses (get-in db [:communities/all-addresses-to-reveal community-id])
addresses-to-reveal (if new-value addresses-to-reveal (if new-value
(->> (utils/sorted-non-watch-only-accounts db) (->> (utils/sorted-operable-non-watch-only-accounts db)
(map :address) (map :address)
set) set)
current-addresses)] current-addresses)]

View File

@ -33,9 +33,15 @@
(let [cofx (let [cofx
{:db {:communities/all-addresses-to-reveal {community-id #{"0xA" "0xB" "0xC"}} {:db {:communities/all-addresses-to-reveal {community-id #{"0xA" "0xB" "0xC"}}
:communities/all-airdrop-addresses {community-id "0xB"} :communities/all-airdrop-addresses {community-id "0xB"}
:wallet {:accounts {"0xB" {:address "0xB" :position 0} :wallet {:accounts {"0xB" {:address "0xB"
"0xA" {:address "0xA" :position 1} :operable? true
"0xC" {:address "0xC" :position 2}}}}} :position 0}
"0xA" {:address "0xA"
:operable? true
:position 1}
"0xC" {:address "0xC"
:operable? true
:position 2}}}}}
addresses-to-reveal ["0xA" "0xC"]] addresses-to-reveal ["0xA" "0xC"]]
(is (match? (is (match?
{:db {:communities/all-addresses-to-reveal {:db {:communities/all-addresses-to-reveal
@ -52,9 +58,9 @@
(testing "sets flag from false -> true will mark all addresses to be revealed" (testing "sets flag from false -> true will mark all addresses to be revealed"
(let [cofx {:db (let [cofx {:db
{:wallet {:wallet
{:accounts {"0xB" {:address "0xB" :position 0} {:accounts {"0xB" {:address "0xB" :operable? true :position 0}
"0xA" {:address "0xA" :position 1} "0xA" {:address "0xA" :operable? true :position 1}
"0xC" {:address "0xC" :position 2}}} "0xC" {:address "0xC" :operable? true :position 2}}}
:communities/all-addresses-to-reveal {community-id #{"0xA"}} :communities/all-addresses-to-reveal {community-id #{"0xA"}}
:communities/selected-share-all-addresses {community-id false}}} :communities/selected-share-all-addresses {community-id false}}}
addresses-to-reveal #{"0xA" "0xB" "0xC"}] addresses-to-reveal #{"0xA" "0xB" "0xC"}]

View File

@ -260,7 +260,7 @@
can-edit-addresses? (rf/sub [:communities/can-edit-shared-addresses? id]) can-edit-addresses? (rf/sub [:communities/can-edit-shared-addresses? id])
wallet-accounts (rf/sub [:wallet/accounts-without-watched-accounts]) wallet-accounts (rf/sub [:wallet/operable-accounts-without-watched-accounts])
unmodified-addresses-to-reveal (rf/sub [:communities/addresses-to-reveal id]) unmodified-addresses-to-reveal (rf/sub [:communities/addresses-to-reveal id])
[addresses-to-reveal set-addresses-to-reveal] (rn/use-state unmodified-addresses-to-reveal) [addresses-to-reveal set-addresses-to-reveal] (rn/use-state unmodified-addresses-to-reveal)

View File

@ -154,7 +154,7 @@
(defn update-previous-permission-addresses (defn update-previous-permission-addresses
[{:keys [db]} [community-id]] [{:keys [db]} [community-id]]
(when community-id (when community-id
(let [accounts (utils/sorted-non-watch-only-accounts db) (let [accounts (utils/sorted-operable-non-watch-only-accounts db)
selected-permission-addresses (get-in db selected-permission-addresses (get-in db
[:communities community-id [:communities community-id
:selected-permission-addresses]) :selected-permission-addresses])
@ -198,7 +198,7 @@
[{:keys [db]} [community-id]] [{:keys [db]} [community-id]]
(let [share-all-addresses? (get-in db [:communities community-id :share-all-addresses?]) (let [share-all-addresses? (get-in db [:communities community-id :share-all-addresses?])
next-share-all-addresses? (not share-all-addresses?) next-share-all-addresses? (not share-all-addresses?)
accounts (utils/sorted-non-watch-only-accounts db) accounts (utils/sorted-operable-non-watch-only-accounts db)
addresses (set (map :address accounts))] addresses (set (map :address accounts))]
{:db (update-in db {:db (update-in db
[:communities community-id] [:communities community-id]

View File

@ -51,7 +51,7 @@
(rf/reg-event-fx :communities/check-permissions-to-join-community-with-all-addresses (rf/reg-event-fx :communities/check-permissions-to-join-community-with-all-addresses
(fn [{:keys [db]} [community-id]] (fn [{:keys [db]} [community-id]]
(let [accounts (utils/sorted-non-watch-only-accounts db) (let [accounts (utils/sorted-operable-non-watch-only-accounts db)
addresses (set (map :address accounts))] addresses (set (map :address accounts))]
{:db (assoc-in db [:communities/permissions-check community-id :checking?] true) {:db (assoc-in db [:communities/permissions-check community-id :checking?] true)
:json-rpc/call [{:method "wakuext_checkPermissionsToJoinCommunity" :json-rpc/call [{:method "wakuext_checkPermissionsToJoinCommunity"

View File

@ -12,9 +12,10 @@
constants/community-token-permission-become-member :t/member constants/community-token-permission-become-member :t/member
fallback-to))) fallback-to)))
(defn sorted-non-watch-only-accounts (defn sorted-operable-non-watch-only-accounts
[db] [db]
(->> (get-in db [:wallet :accounts]) (->> (get-in db [:wallet :accounts])
(vals) (vals)
(remove :watch-only?) (remove :watch-only?)
(filter :operable?)
(sort-by :position))) (sort-by :position)))

View File

@ -23,6 +23,7 @@
(defn add-keys-to-account (defn add-keys-to-account
[account] [account]
(-> account (-> account
(assoc :operable? (not= (:operable account) :no))
(assoc :watch-only? (= (:type account) :watch)) (assoc :watch-only? (= (:type account) :watch))
(assoc :default-account? (:wallet account)))) (assoc :default-account? (:wallet account))))
@ -67,7 +68,7 @@
:color :colorId}) :color :colorId})
(update :prodPreferredChainIds chain-ids-set->string) (update :prodPreferredChainIds chain-ids-set->string)
(update :testPreferredChainIds chain-ids-set->string) (update :testPreferredChainIds chain-ids-set->string)
(dissoc :watch-only? :default-account? :tokens :collectibles))) (dissoc :watch-only? :default-account? :operable? :tokens :collectibles)))
(defn- rpc->balances-per-chain (defn- rpc->balances-per-chain
[token] [token]

View File

@ -32,6 +32,7 @@
:watch-only? false :watch-only? false
:prod-preferred-chain-ids #{1 42161} :prod-preferred-chain-ids #{1 42161}
:created-at 1716548742000 :created-at 1716548742000
:operable? true
:operable :fully :operable :fully
:removed false}) :removed false})
@ -173,6 +174,7 @@
"1x456" (merge account "1x456" (merge account
{:key-uid "0x456" {:key-uid "0x456"
:address "1x456" :address "1x456"
:operable? false
:operable :no})} :operable :no})}
:updated-keypairs-by-id {"0x123" {:key-uid "0x123" :updated-keypairs-by-id {"0x123" {:key-uid "0x123"
:type :seed :type :seed
@ -186,6 +188,7 @@
:accounts [(merge account :accounts [(merge account
{:key-uid "0x456" {:key-uid "0x456"
:address "1x456" :address "1x456"
:operable? false
:operable :no})]}}}) :operable :no})]}}})
(sut/reconcile-keypairs [raw-keypair-seed-phrase (sut/reconcile-keypairs [raw-keypair-seed-phrase
raw-keypair-private-key])))) raw-keypair-private-key]))))

View File

@ -87,6 +87,13 @@
[:dispatch [:wallet/request-collectibles-for-all-accounts {:new-request? true}]] [:dispatch [:wallet/request-collectibles-for-all-accounts {:new-request? true}]]
[:dispatch [:wallet/check-recent-history-for-all-accounts]]]) [:dispatch [:wallet/check-recent-history-for-all-accounts]]])
(rf/reg-event-fx
:wallet/fetch-assets-for-address
(fn [_ [address]]
{:fx [[:dispatch [:wallet/get-wallet-token-for-account address]]
[:dispatch [:wallet/request-new-collectibles-for-account-from-signal address]]
[:dispatch [:wallet/check-recent-history-for-account address]]]}))
(rf/reg-event-fx (rf/reg-event-fx
:wallet/get-accounts-success :wallet/get-accounts-success
(fn [{:keys [db]} [accounts]] (fn [{:keys [db]} [accounts]]
@ -112,9 +119,7 @@
(rf/reg-event-fx :wallet/process-account-from-signal (rf/reg-event-fx :wallet/process-account-from-signal
(fn [{:keys [db]} [{:keys [address] :as account}]] (fn [{:keys [db]} [{:keys [address] :as account}]]
{:db (assoc-in db [:wallet :accounts address] (data-store/rpc->account account)) {:db (assoc-in db [:wallet :accounts address] (data-store/rpc->account account))
:fx [[:dispatch [:wallet/get-wallet-token-for-account address]] :fx [[:dispatch [:wallet/fetch-assets-for-address address]]]}))
[:dispatch [:wallet/request-new-collectibles-for-account-from-signal address]]
[:dispatch [:wallet/check-recent-history-for-account address]]]}))
(rf/reg-event-fx (rf/reg-event-fx
:wallet/save-account :wallet/save-account
@ -575,18 +580,17 @@
updated-account-addresses (set (map :address updated-accounts)) updated-account-addresses (set (map :address updated-accounts))
new-account-addresses (clojure.set/difference updated-account-addresses new-account-addresses (clojure.set/difference updated-account-addresses
existing-account-addresses)] existing-account-addresses)]
{:db (update-in db (cond-> {:db (update-in db
[:wallet :accounts] [:wallet :accounts]
(fn [existing-accounts] (fn [existing-accounts]
(merge-with merge (merge-with merge
(apply dissoc existing-accounts removed-account-addresses) (apply dissoc existing-accounts removed-account-addresses)
(utils.collection/index-by :address updated-accounts)))) (utils.collection/index-by :address updated-accounts))))}
:fx (mapcat (fn [address]
[[:dispatch [:wallet/get-wallet-token-for-account address]] (seq new-account-addresses)
[:dispatch (assoc :fx
[:wallet/request-new-collectibles-for-account-from-signal address]] (mapv (fn [address] [:dispatch [:wallet/fetch-assets-for-address address]])
[:dispatch [:wallet/check-recent-history-for-account address]]]) new-account-addresses)))))
new-account-addresses)}))
(rf/reg-event-fx :wallet/reconcile-watch-only-accounts reconcile-watch-only-accounts) (rf/reg-event-fx :wallet/reconcile-watch-only-accounts reconcile-watch-only-accounts)
@ -621,13 +625,10 @@
(into removed-account-addresses (into removed-account-addresses
old-account-addresses)) old-account-addresses))
updated-accounts-by-address)))} updated-accounts-by-address)))}
(seq new-account-addresses) (seq new-account-addresses)
(assoc :fx (assoc :fx
(mapcat (fn [address] (mapv (fn [address] [:dispatch [:wallet/fetch-assets-for-address address]])
[[:dispatch [:wallet/get-wallet-token-for-account address]]
[:dispatch
[:wallet/request-new-collectibles-for-account-from-signal address]]
[:dispatch [:wallet/check-recent-history-for-account address]]])
new-account-addresses))))) new-account-addresses)))))
(rf/reg-event-fx :wallet/reconcile-keypairs reconcile-keypairs) (rf/reg-event-fx :wallet/reconcile-keypairs reconcile-keypairs)

View File

@ -40,6 +40,7 @@
:color :purple :color :purple
:wallet true :wallet true
:default-account? true :default-account? true
:operable? true
:name "Ethereum account" :name "Ethereum account"
:type :generated :type :generated
:chat false :chat false
@ -145,10 +146,7 @@
(h/deftest-event :wallet/process-account-from-signal (h/deftest-event :wallet/process-account-from-signal
[event-id dispatch] [event-id dispatch]
(let [expected-effects {:db {:wallet {:accounts {address account}}} (let [expected-effects {:db {:wallet {:accounts {address account}}}
:fx [[:dispatch [:wallet/get-wallet-token-for-account address]] :fx [[:dispatch [:wallet/fetch-assets-for-address address]]]}]
[:dispatch
[:wallet/request-new-collectibles-for-account-from-signal address]]
[:dispatch [:wallet/check-recent-history-for-account address]]]}]
(reset! rf-db/app-db {:wallet {:accounts {}}}) (reset! rf-db/app-db {:wallet {:accounts {}}})
(is (match? expected-effects (dispatch [event-id raw-account]))))) (is (match? expected-effects (dispatch [event-id raw-account])))))
@ -169,9 +167,7 @@
:type :seed :type :seed
:lowest-operability :fully :lowest-operability :fully
:accounts [account]}}}} :accounts [account]}}}}
:fx [[:dispatch [:wallet/get-wallet-token-for-account address]] :fx [[:dispatch [:wallet/fetch-assets-for-address address]]]})
[:dispatch [:wallet/request-new-collectibles-for-account-from-signal address]]
[:dispatch [:wallet/check-recent-history-for-account address]]]})
(dispatch [event-id (dispatch [event-id
[{:key-uid keypair-key-uid [{:key-uid keypair-key-uid
:type "seed" :type "seed"
@ -292,6 +288,7 @@
(assoc raw-account (assoc raw-account
:address "1x001" :address "1x001"
:chat true)]}]])))))) :chat true)]}]]))))))
(h/deftest-event :wallet/reconcile-watch-only-accounts (h/deftest-event :wallet/reconcile-watch-only-accounts
[event-id dispatch] [event-id dispatch]
(testing "event adds new watch-only accounts" (testing "event adds new watch-only accounts"
@ -303,10 +300,7 @@
vector? matchers/equals vector? matchers/equals
map? matchers/equals] map? matchers/equals]
{:db {:wallet {:accounts {(:address account) account}}} {:db {:wallet {:accounts {(:address account) account}}}
:fx [[:dispatch [:wallet/get-wallet-token-for-account address]] :fx [[:dispatch [:wallet/fetch-assets-for-address address]]]})
[:dispatch
[:wallet/request-new-collectibles-for-account-from-signal address]]
[:dispatch [:wallet/check-recent-history-for-account address]]]})
(dispatch [event-id [raw-account]])))) (dispatch [event-id [raw-account]]))))
(testing "event removes watch-only accounts that are marked as removed" (testing "event removes watch-only accounts that are marked as removed"
(reset! rf-db/app-db {:wallet {:accounts {(:address account) account}}}) (reset! rf-db/app-db {:wallet {:accounts {(:address account) account}}})
@ -316,8 +310,7 @@
[set? matchers/set-equals [set? matchers/set-equals
vector? matchers/equals vector? matchers/equals
map? matchers/equals] map? matchers/equals]
{:db {:wallet {:accounts {}}} {:db {:wallet {:accounts {}}}})
:fx []})
(dispatch [event-id [(assoc raw-account :removed true)]])))) (dispatch [event-id [(assoc raw-account :removed true)]]))))
(testing "event updates existing watch-only accounts" (testing "event updates existing watch-only accounts"
(reset! rf-db/app-db {:wallet (reset! rf-db/app-db {:wallet
@ -328,10 +321,8 @@
[set? matchers/set-equals [set? matchers/set-equals
vector? matchers/equals vector? matchers/equals
map? matchers/equals] map? matchers/equals]
{:db {:wallet {:accounts {address (assoc account :name "Test")}}} {:db {:wallet {:accounts {address (assoc account :name "Test")}}}})
:fx []})
(dispatch [event-id (dispatch [event-id
[(assoc raw-account [(assoc raw-account
:address address :address address
:name "Test")]]))))) :name "Test")]])))))
(cljs.test/run-tests)

View File

@ -109,8 +109,7 @@
(let [options-height (reagent/atom 0)] (let [options-height (reagent/atom 0)]
(fn [] (fn []
(let [theme (quo.theme/use-theme) (let [theme (quo.theme/use-theme)
accounts (rf/sub accounts (rf/sub [:wallet/operable-accounts-without-current-viewing-account])
[:wallet/fully-or-partially-operable-accounts-without-current-viewing-account])
show-account-selector? (pos? (count accounts))] show-account-selector? (pos? (count accounts))]
[:<> [:<>
(when show-account-selector? (when show-account-selector?

View File

@ -20,7 +20,7 @@
(defn view (defn view
[] []
(let [selected-account-address (rf/sub [:wallet/current-viewing-account-address]) (let [selected-account-address (rf/sub [:wallet/current-viewing-account-address])
accounts (rf/sub [:wallet/fully-or-partially-operable-accounts-without-watched-accounts])] accounts (rf/sub [:wallet/operable-accounts-without-watched-accounts])]
[:<> [:<>
[quo/drawer-top {:title (i18n/label :t/select-account)}] [quo/drawer-top {:title (i18n/label :t/select-account)}]
[gesture/flat-list [gesture/flat-list

View File

@ -53,7 +53,7 @@
(re-frame/reg-sub :communities/accounts-to-reveal (re-frame/reg-sub :communities/accounts-to-reveal
(fn [[_ community-id]] (fn [[_ community-id]]
[(re-frame/subscribe [:wallet/accounts-without-watched-accounts]) [(re-frame/subscribe [:wallet/operable-accounts-without-watched-accounts])
(re-frame/subscribe [:communities/addresses-to-reveal community-id])]) (re-frame/subscribe [:communities/addresses-to-reveal community-id])])
(fn [[accounts addresses] _] (fn [[accounts addresses] _]
(filter #(contains? addresses (:address %)) (filter #(contains? addresses (:address %))
@ -61,7 +61,7 @@
(re-frame/reg-sub :communities/airdrop-account (re-frame/reg-sub :communities/airdrop-account
(fn [[_ community-id]] (fn [[_ community-id]]
[(re-frame/subscribe [:wallet/accounts-without-watched-accounts]) [(re-frame/subscribe [:wallet/operable-accounts-without-watched-accounts])
(re-frame/subscribe [:communities/airdrop-address community-id])]) (re-frame/subscribe [:communities/airdrop-address community-id])])
(fn [[accounts airdrop-address] _] (fn [[accounts airdrop-address] _]
(->> accounts (->> accounts

View File

@ -24,10 +24,10 @@
(h/deftest-sub :communities/airdrop-account (h/deftest-sub :communities/airdrop-account
[sub-name] [sub-name]
(let [airdrop-account {:address "0xA" :position 1}] (let [airdrop-account {:address "0xA" :operable? true :position 1}]
(reset! rf-db/app-db (reset! rf-db/app-db
{:communities/all-airdrop-addresses {community-id "0xA"} {:communities/all-airdrop-addresses {community-id "0xA"}
:wallet {:accounts {"0xB" {:address "0xB" :position 0} :wallet {:accounts {"0xB" {:address "0xB" :operable? true :position 0}
"0xA" airdrop-account}}}) "0xA" airdrop-account}}})
(is (match? airdrop-account (rf/sub [sub-name community-id]))))) (is (match? airdrop-account (rf/sub [sub-name community-id])))))
@ -36,9 +36,11 @@
[sub-name] [sub-name]
(reset! rf-db/app-db (reset! rf-db/app-db
{:communities/all-addresses-to-reveal {community-id #{"0xC" "0xB"}} {:communities/all-addresses-to-reveal {community-id #{"0xC" "0xB"}}
:wallet {:accounts {"0xB" {:address "0xB" :position 0} :wallet {:accounts {"0xB" {:address "0xB" :operable? true :position 0}
"0xA" {:address "0xA" :position 1} "0xA" {:address "0xA" :operable? true :position 1}
"0xC" {:address "0xC" :position 2}}}}) "0xC" {:address "0xC"
:operable? true
:position 2}}}})
(is (match? [{:address "0xB" :position 0} (is (match? [{:address "0xB" :position 0}
{:address "0xC" :position 2}] {:address "0xC" :position 2}]

View File

@ -454,25 +454,23 @@
(fn [accounts] (fn [accounts]
(remove :watch-only? accounts))) (remove :watch-only? accounts)))
(defn- keep-fully-or-partially-operable-accounts (defn- keep-operable-accounts
[accounts] [accounts]
(filter (fn fully-or-partially-operable? [{:keys [operable]}] (filter :operable? accounts))
(#{:fully :partially} operable))
accounts))
(rf/reg-sub (rf/reg-sub
:wallet/fully-or-partially-operable-accounts-without-current-viewing-account :wallet/operable-accounts-without-current-viewing-account
:<- [:wallet/accounts-without-current-viewing-account] :<- [:wallet/accounts-without-current-viewing-account]
keep-fully-or-partially-operable-accounts) keep-operable-accounts)
(rf/reg-sub (rf/reg-sub
:wallet/fully-or-partially-operable-accounts-without-watched-accounts :wallet/operable-accounts-without-watched-accounts
:<- [:wallet/accounts-without-watched-accounts] :<- [:wallet/accounts-without-watched-accounts]
keep-fully-or-partially-operable-accounts) keep-operable-accounts)
(rf/reg-sub (rf/reg-sub
:wallet/accounts-with-current-asset :wallet/accounts-with-current-asset
:<- [:wallet/fully-or-partially-operable-accounts-without-watched-accounts] :<- [:wallet/operable-accounts-without-watched-accounts]
:<- [:wallet/wallet-send-token-symbol] :<- [:wallet/wallet-send-token-symbol]
:<- [:wallet/wallet-send-token] :<- [:wallet/wallet-send-token]
(fn [[accounts token-symbol token]] (fn [[accounts token-symbol token]]

View File

@ -16,10 +16,12 @@
{:0x1 {:tokens [{:symbol "ETH"} {:symbol "SNT"}] {:0x1 {:tokens [{:symbol "ETH"} {:symbol "SNT"}]
:network-preferences-names #{} :network-preferences-names #{}
:customization-color nil :customization-color nil
:operable? true
:operable :fully} :operable :fully}
:0x2 {:tokens [{:symbol "SNT"}] :0x2 {:tokens [{:symbol "SNT"}]
:network-preferences-names #{} :network-preferences-names #{}
:customization-color nil :customization-color nil
:operable? true
:operable :partially}}) :operable :partially}})
(def tokens-0x1 (def tokens-0x1
@ -106,6 +108,7 @@
:name "Account One" :name "Account One"
:type :generated :type :generated
:watch-only? false :watch-only? false
:operable? true
:chat false :chat false
:test-preferred-chain-ids #{5 420 421613} :test-preferred-chain-ids #{5 420 421613}
:color :blue :color :blue
@ -127,6 +130,7 @@
:name "Account Two" :name "Account Two"
:type :generated :type :generated
:watch-only? false :watch-only? false
:operable? true
:chat false :chat false
:test-preferred-chain-ids #{5 420 421613} :test-preferred-chain-ids #{5 420 421613}
:color :purple :color :purple
@ -148,6 +152,7 @@
:name "Watched Account 1" :name "Watched Account 1"
:type :watch :type :watch
:watch-only? true :watch-only? true
:operable? true
:chat false :chat false
:test-preferred-chain-ids #{0} :test-preferred-chain-ids #{0}
:color :magenta :color :magenta
@ -219,7 +224,7 @@
(assoc-in [:wallet :accounts] accounts) (assoc-in [:wallet :accounts] accounts)
(assoc-in [:wallet :networks] network-data))) (assoc-in [:wallet :networks] network-data)))
(is (is
(= (match?
(list {:path "m/44'/60'/0'/0/0" (list {:path "m/44'/60'/0'/0/0"
:emoji "😃" :emoji "😃"
:key-uid "0x2f5ea39" :key-uid "0x2f5ea39"
@ -228,6 +233,7 @@
:name "Account One" :name "Account One"
:type :generated :type :generated
:watch-only? false :watch-only? false
:operable? true
:chat false :chat false
:test-preferred-chain-ids #{5 420 421613} :test-preferred-chain-ids #{5 420 421613}
:color :blue :color :blue
@ -250,6 +256,7 @@
:name "Account Two" :name "Account Two"
:type :generated :type :generated
:watch-only? false :watch-only? false
:operable? true
:chat false :chat false
:test-preferred-chain-ids #{5 420 421613} :test-preferred-chain-ids #{5 420 421613}
:color :purple :color :purple
@ -272,6 +279,7 @@
:name "Watched Account 1" :name "Watched Account 1"
:type :watch :type :watch
:watch-only? true :watch-only? true
:operable? true
:chat false :chat false
:test-preferred-chain-ids #{0} :test-preferred-chain-ids #{0}
:color :magenta :color :magenta
@ -307,7 +315,7 @@
(let [result (rf/sub [sub-name])] (let [result (rf/sub [sub-name])]
(is (is
(= {:path "m/44'/60'/0'/0/0" (match? {:path "m/44'/60'/0'/0/0"
:emoji "😃" :emoji "😃"
:key-uid "0x2f5ea39" :key-uid "0x2f5ea39"
:address "0x1" :address "0x1"
@ -315,6 +323,7 @@
:name "Account One" :name "Account One"
:type :generated :type :generated
:watch-only? false :watch-only? false
:operable? true
:chat false :chat false
:test-preferred-chain-ids #{5 420 421613} :test-preferred-chain-ids #{5 420 421613}
:color :blue :color :blue
@ -367,7 +376,8 @@
(assoc-in [:wallet :current-viewing-account-address] "0x2") (assoc-in [:wallet :current-viewing-account-address] "0x2")
(assoc-in [:wallet :networks] network-data))) (assoc-in [:wallet :networks] network-data)))
(is (is
(= (list (match?
(list
{:path "m/44'/60'/0'/0/0" {:path "m/44'/60'/0'/0/0"
:emoji "😃" :emoji "😃"
:key-uid "0x2f5ea39" :key-uid "0x2f5ea39"
@ -376,6 +386,7 @@
:name "Account One" :name "Account One"
:type :generated :type :generated
:watch-only? false :watch-only? false
:operable? true
:chat false :chat false
:test-preferred-chain-ids #{5 420 421613} :test-preferred-chain-ids #{5 420 421613}
:color :blue :color :blue
@ -398,6 +409,7 @@
:name "Watched Account 1" :name "Watched Account 1"
:type :watch :type :watch
:watch-only? true :watch-only? true
:operable? true
:chat false :chat false
:test-preferred-chain-ids #{0} :test-preferred-chain-ids #{0}
:color :magenta :color :magenta
@ -422,7 +434,7 @@
(assoc-in [:wallet :accounts] accounts) (assoc-in [:wallet :accounts] accounts)
(assoc-in [:wallet :networks] network-data))) (assoc-in [:wallet :networks] network-data)))
(is (is
(= (match?
(list (list
{:path "m/44'/60'/0'/0/0" {:path "m/44'/60'/0'/0/0"
:emoji "😃" :emoji "😃"
@ -432,6 +444,7 @@
:name "Account One" :name "Account One"
:type :generated :type :generated
:watch-only? false :watch-only? false
:operable? true
:chat false :chat false
:test-preferred-chain-ids #{5 420 421613} :test-preferred-chain-ids #{5 420 421613}
:color :blue :color :blue
@ -455,6 +468,7 @@
:name "Account Two" :name "Account Two"
:type :generated :type :generated
:watch-only? false :watch-only? false
:operable? true
:chat false :chat false
:test-preferred-chain-ids #{5 420 421613} :test-preferred-chain-ids #{5 420 421613}
:color :purple :color :purple
@ -484,6 +498,7 @@
[{:tokens [{:symbol "ETH"} {:symbol "SNT"}] [{:tokens [{:symbol "ETH"} {:symbol "SNT"}]
:network-preferences-names #{} :network-preferences-names #{}
:customization-color nil :customization-color nil
:operable? true
:operable :fully}])))) :operable :fully}]))))
(testing "returns the accounts list with the current asset using token" (testing "returns the accounts list with the current asset using token"
@ -496,6 +511,7 @@
[{:tokens [{:symbol "ETH"} {:symbol "SNT"}] [{:tokens [{:symbol "ETH"} {:symbol "SNT"}]
:network-preferences-names #{} :network-preferences-names #{}
:customization-color nil :customization-color nil
:operable? true
:operable :fully}])))) :operable :fully}]))))
(testing (testing
@ -576,7 +592,7 @@
(assoc-in [:wallet :accounts] accounts) (assoc-in [:wallet :accounts] accounts)
(assoc-in [:wallet :networks] network-data))) (assoc-in [:wallet :networks] network-data)))
(is (is
(= [(-> accounts (match? [(-> accounts
(get "0x1") (get "0x1")
(assoc :customization-color :blue) (assoc :customization-color :blue)
(assoc :network-preferences-names #{:mainnet :arbitrum :optimism})) (assoc :network-preferences-names #{:mainnet :arbitrum :optimism}))
@ -598,7 +614,7 @@
(assoc-in [:wallet :accounts] accounts) (assoc-in [:wallet :accounts] accounts)
(assoc-in [:wallet :networks] network-data))) (assoc-in [:wallet :networks] network-data)))
(is (is
(= [(-> accounts (match? [(-> accounts
(get "0x3") (get "0x3")
(assoc :network-preferences-names #{}))] (assoc :network-preferences-names #{}))]
(rf/sub [sub-name]))))) (rf/sub [sub-name])))))
@ -811,9 +827,7 @@
(testing "returns local suggestions:" (testing "returns local suggestions:"
(swap! rf-db/app-db (swap! rf-db/app-db
#(assoc-in % [:wallet :ui :search-address :local-suggestions] local-suggestions)) #(assoc-in % [:wallet :ui :search-address :local-suggestions] local-suggestions))
(is (is (match? local-suggestions (rf/sub [sub-name])))))
(= local-suggestions
(rf/sub [sub-name])))))
(h/deftest-sub :wallet/valid-ens-or-address? (h/deftest-sub :wallet/valid-ens-or-address?
[sub-name] [sub-name]