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"
:position 0 :operable? true
:color :blue :position 0
:emoji "🐈"} :color :blue
"0xC" {:address "0xC" :emoji "🐈"}
:position 1 "0xC" {:address "0xC"
:color :orange :operable? true
:emoji "🛏️"}}) :position 1
:color :orange
: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})
@ -171,9 +172,10 @@
{:key-uid "0x123" {:key-uid "0x123"
:address "1x123"}) :address "1x123"})
"1x456" (merge account "1x456" (merge account
{:key-uid "0x456" {:key-uid "0x456"
:address "1x456" :address "1x456"
:operable :no})} :operable? false
:operable :no})}
:updated-keypairs-by-id {"0x123" {:key-uid "0x123" :updated-keypairs-by-id {"0x123" {:key-uid "0x123"
:type :seed :type :seed
:lowest-operability :fully :lowest-operability :fully
@ -184,9 +186,10 @@
:type :key :type :key
:lowest-operability :no :lowest-operability :no
:accounts [(merge account :accounts [(merge account
{:key-uid "0x456" {:key-uid "0x456"
:address "1x456" :address "1x456"
:operable :no})]}}}) :operable? false
:operable :no})]}}})
(sut/reconcile-keypairs [raw-keypair-seed-phrase (sut/reconcile-keypairs [raw-keypair-seed-phrase
raw-keypair-private-key])))) raw-keypair-private-key]))))
(testing "reconcile-keypairs represents removed key pairs and accounts" (testing "reconcile-keypairs represents removed key pairs and accounts"

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]] new-account-addresses)))))
[:dispatch
[:wallet/request-new-collectibles-for-account-from-signal address]]
[:dispatch [:wallet/check-recent-history-for-account address]]])
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

@ -108,9 +108,8 @@
[] []
(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,29 +315,30 @@
(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"
:wallet false :wallet false
:name "Account One" :name "Account One"
:type :generated :type :generated
:watch-only? false :watch-only? false
:chat false :operable? true
:test-preferred-chain-ids #{5 420 421613} :chat false
:color :blue :test-preferred-chain-ids #{5 420 421613}
:hidden false :color :blue
:prod-preferred-chain-ids #{1 10 42161} :hidden false
:network-preferences-names #{:mainnet :arbitrum :optimism} :prod-preferred-chain-ids #{1 10 42161}
:position 0 :network-preferences-names #{:mainnet :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
(dissoc result :balance :formatted-balance))) :tokens tokens-0x1}
(dissoc result :balance :formatted-balance)))
(is (money/equal-to (:balance result) (money/bignumber 3250))) (is (money/equal-to (:balance result) (money/bignumber 3250)))
(is (match? (:formatted-balance result) "$3250.00"))))) (is (match? (:formatted-balance result) "$3250.00")))))
@ -367,62 +376,7 @@
(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?
{:path "m/44'/60'/0'/0/0"
:emoji "😃"
:key-uid "0x2f5ea39"
:address "0x1"
:wallet false
:name "Account One"
:type :generated
:watch-only? false
:chat false
:test-preferred-chain-ids #{5 420 421613}
:color :blue
:hidden false
:prod-preferred-chain-ids #{1 10 42161}
:network-preferences-names #{:mainnet :arbitrum :optimism}
:position 0
:clock 1698945829328
:created-at 1698928839000
:operable :fully
:mixedcase-address "0x7bcDfc75c431"
:public-key "0x04371e2d9d66b82f056bc128064"
:removed false
:tokens tokens-0x1}
{:path ""
:emoji "🎉"
:key-uid "0x2f5ea39"
:address "0x3"
:wallet false
:name "Watched Account 1"
:type :watch
:watch-only? true
:chat false
:test-preferred-chain-ids #{0}
:color :magenta
:hidden false
:prod-preferred-chain-ids #{0}
:network-preferences-names #{}
:position 2
:clock 1698945829328
:created-at 1698928839000
:operable :fully
:mixedcase-address "0x7bcDfc75c431"
:public-key "0x"
:removed false
:tokens tokens-0x3})
(rf/sub [sub-name])))))
(h/deftest-sub :wallet/accounts-without-watched-accounts
[sub-name]
(testing "returns the accounts list without the watched accounts in it"
(swap! rf-db/app-db
#(-> %
(assoc-in [:wallet :accounts] accounts)
(assoc-in [:wallet :networks] network-data)))
(is
(=
(list (list
{:path "m/44'/60'/0'/0/0" {:path "m/44'/60'/0'/0/0"
:emoji "😃" :emoji "😃"
@ -432,6 +386,65 @@
:name "Account One" :name "Account One"
:type :generated :type :generated
:watch-only? false :watch-only? false
:operable? true
:chat false
:test-preferred-chain-ids #{5 420 421613}
:color :blue
:hidden false
:prod-preferred-chain-ids #{1 10 42161}
:network-preferences-names #{:mainnet :arbitrum :optimism}
:position 0
:clock 1698945829328
:created-at 1698928839000
:operable :fully
:mixedcase-address "0x7bcDfc75c431"
:public-key "0x04371e2d9d66b82f056bc128064"
:removed false
:tokens tokens-0x1}
{:path ""
:emoji "🎉"
:key-uid "0x2f5ea39"
:address "0x3"
:wallet false
:name "Watched Account 1"
:type :watch
:watch-only? true
:operable? true
:chat false
:test-preferred-chain-ids #{0}
:color :magenta
:hidden false
:prod-preferred-chain-ids #{0}
:network-preferences-names #{}
:position 2
:clock 1698945829328
:created-at 1698928839000
:operable :fully
:mixedcase-address "0x7bcDfc75c431"
:public-key "0x"
:removed false
:tokens tokens-0x3})
(rf/sub [sub-name])))))
(h/deftest-sub :wallet/accounts-without-watched-accounts
[sub-name]
(testing "returns the accounts list without the watched accounts in it"
(swap! rf-db/app-db
#(-> %
(assoc-in [:wallet :accounts] accounts)
(assoc-in [:wallet :networks] network-data)))
(is
(match?
(list
{:path "m/44'/60'/0'/0/0"
:emoji "😃"
:key-uid "0x2f5ea39"
:address "0x1"
:wallet false
:name "Account One"
:type :generated
: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,19 +592,19 @@
(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}))
(-> accounts (-> accounts
(get "0x2") (get "0x2")
(assoc :customization-color :purple) (assoc :customization-color :purple)
(assoc :network-preferences-names #{:mainnet :arbitrum :optimism})) (assoc :network-preferences-names #{:mainnet :arbitrum :optimism}))
(-> accounts (-> accounts
(get "0x3") (get "0x3")
(assoc :customization-color :magenta) (assoc :customization-color :magenta)
(assoc :network-preferences-names #{}))] (assoc :network-preferences-names #{}))]
(rf/sub [sub-name]))))) (rf/sub [sub-name])))))
(h/deftest-sub :wallet/watch-only-accounts (h/deftest-sub :wallet/watch-only-accounts
[sub-name] [sub-name]
@ -598,10 +614,10 @@
(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])))))
(def chat-account (def chat-account
{:path "m/43'/60'/1581'/0'/0" {:path "m/43'/60'/1581'/0'/0"
@ -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]