From 2b0847ef76899ef3a3aeb948c2389c6e7c44104d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vit=E2=88=80ly=20Vlasov?= Date: Thu, 18 Jul 2024 15:36:38 +0300 Subject: [PATCH] fix_: ui part for share-all-future-addresses storage (PR #20549) (#20549) Related status-go PR: https://github.com/status-im/status-go/pull/5354 https://github.com/status-im/status-go/compare/6e056348...8458cafe Signed-off-by: Vitaly Vlasov --- .../actions/accounts_selection/effects.cljs | 23 ++++--- .../actions/accounts_selection/events.cljs | 64 ++++++++++--------- .../accounts_selection/events_test.cljs | 35 +++++----- .../addresses_for_permissions/view.cljs | 7 +- .../contexts/communities/events.cljs | 32 ++++------ .../contexts/communities/events_test.cljs | 4 +- .../contexts/communities/overview/events.cljs | 33 +++++----- .../communities/overview/events_test.cljs | 31 +++++---- status-go-version.json | 6 +- 9 files changed, 126 insertions(+), 109 deletions(-) diff --git a/src/status_im/contexts/communities/actions/accounts_selection/effects.cljs b/src/status_im/contexts/communities/actions/accounts_selection/effects.cljs index 55242b30a7..20e51630ba 100644 --- a/src/status_im/contexts/communities/actions/accounts_selection/effects.cljs +++ b/src/status_im/contexts/communities/actions/accounts_selection/effects.cljs @@ -27,7 +27,7 @@ :on-error #(p-reject (str "failed to sign data\n" %))})))) (defn- edit-shared-addresses-for-community - [community-id signatures addresses-to-reveal airdrop-address] + [community-id signatures addresses-to-reveal airdrop-address _share-future-addresses?] (promesa/create (fn [p-resolve p-reject] (rpc/call @@ -41,15 +41,16 @@ :on-error p-reject})))) (defn- request-to-join - [community-id signatures addresses-to-reveal airdrop-address] + [community-id signatures addresses-to-reveal airdrop-address share-future-addresses?] (promesa/create (fn [p-resolve p-reject] (rpc/call {:method :wakuext_requestToJoinCommunity - :params [{:communityId community-id - :signatures signatures - :addressesToReveal addresses-to-reveal - :airdropAddress airdrop-address}] + :params [{:communityId community-id + :signatures signatures + :addressesToReveal addresses-to-reveal + :airdropAddress airdrop-address + :shareFutureAddresses share-future-addresses?}] :js-response true :on-success p-resolve :on-error p-reject})))) @@ -64,15 +65,18 @@ (defn- sign-and-call-endpoint [{:keys [community-id password pub-key - addresses-to-reveal airdrop-address + addresses-to-reveal airdrop-address share-future-addresses? on-success on-error callback]}] - (-> (promesa/let [sign-params (generate-requests-for-signing pub-key community-id addresses-to-reveal) + (-> (promesa/let [sign-params (generate-requests-for-signing pub-key + community-id + addresses-to-reveal) signatures (sign-data sign-params password) result (callback community-id signatures addresses-to-reveal - airdrop-address)] + airdrop-address + share-future-addresses?)] (run-callback-or-event on-success result)) (promesa/catch #(run-callback-or-event on-error %)))) @@ -87,6 +91,7 @@ [:or [:set string?] [:sequential string?]]] [:airdrop-address string?] + [:share-future-addresses? boolean?] [:on-success [:or fn? :schema.re-frame/event]] [:on-error [:or fn? :schema.re-frame/event]] [:callback fn?]]] diff --git a/src/status_im/contexts/communities/actions/accounts_selection/events.cljs b/src/status_im/contexts/communities/actions/accounts_selection/events.cljs index 3a0847df51..33a26ef04f 100644 --- a/src/status_im/contexts/communities/actions/accounts_selection/events.cljs +++ b/src/status_im/contexts/communities/actions/accounts_selection/events.cljs @@ -17,13 +17,12 @@ (rf/reg-event-fx :communities/initialize-permission-addresses initialize-permission-addresses) (defn do-init-permission-addresses - [{:keys [db]} [community-id revealed-accounts]] + [{:keys [db]} [community-id revealed-accounts share-future-addresses?]] (let [wallet-accounts (utils/sorted-operable-non-watch-only-accounts db) addresses-to-reveal (if (seq revealed-accounts) (set (keys revealed-accounts)) ;; Reveal all addresses as fallback. (set (map :address wallet-accounts))) - ;; When there are no revealed addresses, such as when joining a ;; community, use first address for airdrops. airdrop-address (or (->> revealed-accounts @@ -35,10 +34,7 @@ first :address))] {:db (-> db - ;; Set to false by default while we don't persist the user's choice - ;; in status-go, otherwise whenever the view is mounted, the choice - ;; of selected addresses won't be respected. - (assoc-in [:communities/selected-share-all-addresses community-id] false) + (assoc-in [:communities/selected-share-all-addresses community-id] share-future-addresses?) (assoc-in [:communities/all-addresses-to-reveal community-id] addresses-to-reveal) (assoc-in [:communities/all-airdrop-addresses community-id] airdrop-address)) :fx [[:dispatch @@ -60,36 +56,44 @@ is selecting an airdrop address, we must submit to status-go the current choice of addresses to share, and vice-versa. If we omit addresses to share, status-go will default to all available." - [{:keys [db]} [{:keys [community-id password on-success addresses airdrop-address]}]] - (let [pub-key (get-in db [:profile/profile :public-key]) - wallet-accounts (utils/sorted-operable-non-watch-only-accounts db) - addresses-to-reveal (if (seq addresses) - (set addresses) - (get-in db [:communities/all-addresses-to-reveal community-id])) - new-airdrop-address (if (contains? addresses-to-reveal airdrop-address) - airdrop-address - (->> wallet-accounts - (filter #(contains? addresses-to-reveal (:address %))) - first - :address))] + [{:keys [db]} + [{:keys [community-id password on-success addresses airdrop-address share-future-addresses?]}]] + (let [pub-key (get-in db [:profile/profile :public-key]) + wallet-accounts (utils/sorted-operable-non-watch-only-accounts db) + addresses-to-reveal (if (seq addresses) + (set addresses) + (get-in db [:communities/all-addresses-to-reveal community-id])) + new-airdrop-address (if (contains? addresses-to-reveal airdrop-address) + airdrop-address + (->> wallet-accounts + (filter #(contains? addresses-to-reveal (:address %))) + first + :address)) + share-future-addresses? (if (nil? share-future-addresses?) + (get-in db [:communities/selected-share-all-addresses community-id]) + share-future-addresses?)] {:fx [[:effects.community/edit-shared-addresses - {:community-id community-id - :password password - :pub-key pub-key - :addresses-to-reveal addresses-to-reveal - :airdrop-address new-airdrop-address - :on-success (fn [] - (when (fn? on-success) - (on-success addresses-to-reveal new-airdrop-address)) - (rf/dispatch [:communities/edit-shared-addresses-success - community-id addresses-to-reveal airdrop-address])) - :on-error [:communities/edit-shared-addresses-failure community-id]}]]})) + {:community-id community-id + :password password + :pub-key pub-key + :addresses-to-reveal addresses-to-reveal + :share-future-addresses? share-future-addresses? + :airdrop-address new-airdrop-address + :on-success (fn [] + (when (fn? on-success) + (on-success addresses-to-reveal + new-airdrop-address + share-future-addresses?)) + (rf/dispatch [:communities/edit-shared-addresses-success + community-id addresses-to-reveal airdrop-address])) + :on-error [:communities/edit-shared-addresses-failure community-id]}]]})) (rf/reg-event-fx :communities/edit-shared-addresses edit-shared-addresses) (rf/reg-event-fx :communities/edit-shared-addresses-success - (fn [_ [community-id addresses-to-reveal airdrop-address]] + (fn [_ [community-id addresses-to-reveal airdrop-address share-future-addresses?]] {:fx [[:dispatch [:communities/set-airdrop-address community-id airdrop-address]] + [:dispatch [:communities/set-share-all-addresses community-id share-future-addresses?]] [:dispatch [:communities/set-addresses-to-reveal community-id addresses-to-reveal]]]})) (rf/reg-event-fx :communities/edit-shared-addresses-failure diff --git a/src/status_im/contexts/communities/actions/accounts_selection/events_test.cljs b/src/status_im/contexts/communities/actions/accounts_selection/events_test.cljs index 81a6ff06e5..8174c4930f 100644 --- a/src/status_im/contexts/communities/actions/accounts_selection/events_test.cljs +++ b/src/status_im/contexts/communities/actions/accounts_selection/events_test.cljs @@ -70,7 +70,7 @@ (is (match? {:db (-> (:db cofx) - (assoc-in [:communities/selected-share-all-addresses community-id] false) + (assoc-in [:communities/selected-share-all-addresses community-id] true) (assoc-in [:communities/all-addresses-to-reveal community-id] addresses-to-reveal) (assoc-in [:communities/all-airdrop-addresses community-id] airdrop-address)) :fx [[:dispatch @@ -82,7 +82,7 @@ [:dispatch [:communities/check-permissions-to-join-during-selection community-id addresses-to-reveal]]]} - (sut/do-init-permission-addresses cofx [community-id revealed-accounts]))))) + (sut/do-init-permission-addresses cofx [community-id revealed-accounts true]))))) ;; Expect to mark all addresses to be revealed and first one to receive ;; airdrops when no addresses were previously revealed. @@ -93,7 +93,7 @@ (is (match? {:db (-> (:db cofx) - (assoc-in [:communities/selected-share-all-addresses community-id] false) + (assoc-in [:communities/selected-share-all-addresses community-id] true) (assoc-in [:communities/all-addresses-to-reveal community-id] addresses-to-reveal)) :fx [[:dispatch [:communities/check-permissions-to-join-community @@ -101,7 +101,7 @@ [:dispatch [:communities/check-permissions-to-join-during-selection community-id addresses-to-reveal]]]} - (sut/do-init-permission-addresses cofx [community-id revealed-accounts])))))) + (sut/do-init-permission-addresses cofx [community-id revealed-accounts true])))))) (deftest edit-shared-addresses-test (testing @@ -109,6 +109,7 @@ fallback to all wallet addresses" (let [pub-key "abcdef" revealed-addresses #{"0xB" "0xC"} + share-future-addresses? true cofx {:db {:profile/profile {:public-key pub-key} :communities/all-addresses-to-reveal {community-id revealed-addresses}}} airdrop-address "0xB" @@ -116,22 +117,24 @@ actual (sut/edit-shared-addresses cofx - [{:community-id community-id - :password password - :airdrop-address airdrop-address - :on-success (fn [new-addresses-to-reveal] - (is (match? revealed-addresses new-addresses-to-reveal)))}]) + [{:community-id community-id + :password password + :airdrop-address airdrop-address + :share-future-addresses? share-future-addresses? + :on-success (fn [new-addresses-to-reveal] + (is (match? revealed-addresses new-addresses-to-reveal)))}]) on-success-wrapper (-> actual :fx first second :on-success)] (is (match? {:fx [[:effects.community/edit-shared-addresses - {:community-id community-id - :password password - :pub-key pub-key - :addresses-to-reveal revealed-addresses - :airdrop-address airdrop-address - :on-success fn? - :on-error [:communities/edit-shared-addresses-failure community-id]}]]} + {:community-id community-id + :password password + :pub-key pub-key + :addresses-to-reveal revealed-addresses + :share-future-addresses? share-future-addresses? + :airdrop-address airdrop-address + :on-success fn? + :on-error [:communities/edit-shared-addresses-failure community-id]}]]} actual)) (on-success-wrapper))) diff --git a/src/status_im/contexts/communities/actions/addresses_for_permissions/view.cljs b/src/status_im/contexts/communities/actions/addresses_for_permissions/view.cljs index b37337966d..591c89233c 100644 --- a/src/status_im/contexts/communities/actions/addresses_for_permissions/view.cljs +++ b/src/status_im/contexts/communities/actions/addresses_for_permissions/view.cljs @@ -203,7 +203,9 @@ :addresses-for-permissions]) (rf/dispatch [:hide-bottom-sheet]))}]))}]) (rf/dispatch [:communities/set-share-all-addresses id flag-share-all-addresses])) - (rf/dispatch [:communities/set-addresses-to-reveal id addresses-to-reveal]))) + (do + (rf/dispatch [:communities/set-share-all-addresses id flag-share-all-addresses]) + (rf/dispatch [:communities/set-addresses-to-reveal id addresses-to-reveal])))) highest-role (rf/sub [:communities/highest-role-for-selection id]) [unmodified-role _] (rn/use-state highest-role)] @@ -261,6 +263,7 @@ can-edit-addresses? (rf/sub [:communities/can-edit-shared-addresses? id]) wallet-accounts (rf/sub [:wallet/operable-accounts-without-watched-accounts]) + joined (rf/sub [:communities/community-joined 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) @@ -285,7 +288,6 @@ (set-flag-share-all-addresses new-value) (when new-value (set-addresses-to-reveal (set (map :address wallet-accounts))))))] - (rn/use-mount (fn [] (when-not flag-share-all-addresses @@ -310,6 +312,7 @@ flag-share-all-addresses] :header [quo/page-setting {:checked? flag-share-all-addresses + :disabled? joined :customization-color color :on-change toggle-flag-share-all-addresses :setting-text (i18n/label diff --git a/src/status_im/contexts/communities/events.cljs b/src/status_im/contexts/communities/events.cljs index 139d4debf0..07414ab4b2 100644 --- a/src/status_im/contexts/communities/events.cljs +++ b/src/status_im/contexts/communities/events.cljs @@ -16,6 +16,7 @@ [status-im.navigation.events :as navigation] [status-im.navigation.transitions :as transitions] [taoensso.timbre :as log] + [utils.collection :as collection-utils] [utils.re-frame :as rf])) (defn handle-community @@ -372,15 +373,14 @@ (when (and community joined (not fetching-revealed-accounts)) {:db (assoc-in db [:communities community-id :fetching-revealed-accounts] true) :json-rpc/call - [{:method "wakuext_getRevealedAccounts" - :params [community-id (get-in db [:profile/profile :public-key])] - :js-response true - :on-success [:communities/get-revealed-accounts-success community-id on-success] - :on-error (fn [err] - (log/error {:message "failed to fetch revealed accounts" - :community-id community-id - :err err}) - (rf/dispatch [:communities/get-revealed-accounts-failed community-id]))}]}))) + [{:method "wakuext_latestRequestToJoinForCommunity" + :params [community-id] + :on-success [:communities/get-revealed-accounts-success community-id on-success] + :on-error (fn [err] + (log/error {:message "failed to fetch revealed accounts" + :community-id community-id + :err err}) + (rf/dispatch [:communities/get-revealed-accounts-failed community-id]))}]}))) (rf/reg-event-fx :communities/get-revealed-accounts get-revealed-accounts) @@ -399,22 +399,18 @@ [:json-rpc/call :schema.common/rpc-call]]]]) (rf/reg-event-fx :communities/get-revealed-accounts-success - (fn [{:keys [db]} [community-id on-success revealed-accounts-js]] + (fn [{:keys [db]} [community-id on-success request-to-join]] (when-let [community (get-in db [:communities community-id])] - (let [revealed-accounts - (reduce - (fn [acc {:keys [address] :as revealed-account}] - (assoc acc address revealed-account)) - {} - (data-store.communities/<-revealed-accounts-rpc revealed-accounts-js)) - + (let [revealed-accounts (collection-utils/index-by :address (:revealedAccounts request-to-join)) + share-future-addresses? (:shareFutureAddresses request-to-join) community-with-revealed-accounts (-> community (assoc :revealed-accounts revealed-accounts) + (assoc :share-future-addresses? share-future-addresses?) (dissoc :fetching-revealed-accounts))] {:db (assoc-in db [:communities community-id] community-with-revealed-accounts) :fx [(when (vector? on-success) - [:dispatch (conj on-success revealed-accounts)])]})))) + [:dispatch (conj on-success revealed-accounts share-future-addresses?)])]})))) (rf/reg-event-fx :communities/get-revealed-accounts-failed (fn [{:keys [db]} [community-id]] diff --git a/src/status_im/contexts/communities/events_test.cljs b/src/status_im/contexts/communities/events_test.cljs index 0d2d55ac2e..4fb45e2435 100644 --- a/src/status_im/contexts/communities/events_test.cljs +++ b/src/status_im/contexts/communities/events_test.cljs @@ -146,8 +146,8 @@ effects (events/get-revealed-accounts {:db db} [community-id])] (is (match? (assoc-in db [:communities community-id :fetching-revealed-accounts] true) (:db effects))) - (is (match? {:method "wakuext_getRevealedAccounts" - :params [community-id "profile-public-key"]} + (is (match? {:method "wakuext_latestRequestToJoinForCommunity" + :params [community-id]} (-> effects :json-rpc/call first (select-keys [:method :params])))))))) (deftest handle-community-test diff --git a/src/status_im/contexts/communities/overview/events.cljs b/src/status_im/contexts/communities/overview/events.cljs index d9f69b30f3..37f1a5a174 100644 --- a/src/status_im/contexts/communities/overview/events.cljs +++ b/src/status_im/contexts/communities/overview/events.cljs @@ -117,13 +117,14 @@ {:community community-name})}]]]}))) (defn request-to-join-with-signatures - [_ [community-id addresses-to-reveal signatures]] + [_ [community-id addresses-to-reveal signatures share-future-addresses?]] {:fx [[:json-rpc/call [{:method "wakuext_requestToJoinCommunity" - :params [{:communityId community-id - :signatures signatures - :addressesToReveal addresses-to-reveal - :airdropAddress (first addresses-to-reveal)}] + :params [{:communityId community-id + :signatures signatures + :addressesToReveal addresses-to-reveal + :shareFutureAddresses share-future-addresses? + :airdropAddress (first addresses-to-reveal)}] :js-response true :on-success [:communities/requested-to-join] :on-error [:communities/requested-to-join-error community-id]}]]]}) @@ -153,16 +154,18 @@ (defn request-to-join-with-addresses [{:keys [db]} [{:keys [community-id password]}]] - (let [pub-key (get-in db [:profile/profile :public-key]) - addresses-to-reveal (get-in db [:communities/all-addresses-to-reveal community-id]) - airdrop-address (get-in db [:communities/all-airdrop-addresses community-id])] + (let [pub-key (get-in db [:profile/profile :public-key]) + addresses-to-reveal (get-in db [:communities/all-addresses-to-reveal community-id]) + share-future-addresses? (get-in db [:communities/selected-share-all-addresses community-id]) + airdrop-address (get-in db [:communities/all-airdrop-addresses community-id])] {:fx [[:effects.community/request-to-join - {:community-id community-id - :password password - :pub-key pub-key - :addresses-to-reveal addresses-to-reveal - :airdrop-address airdrop-address - :on-success [:communities/requested-to-join] - :on-error [:communities/requested-to-join-error community-id]}]]})) + {:community-id community-id + :password password + :pub-key pub-key + :addresses-to-reveal addresses-to-reveal + :airdrop-address airdrop-address + :share-future-addresses? share-future-addresses? + :on-success [:communities/requested-to-join] + :on-error [:communities/requested-to-join-error community-id]}]]})) (rf/reg-event-fx :communities/request-to-join-with-addresses request-to-join-with-addresses) diff --git a/src/status_im/contexts/communities/overview/events_test.cljs b/src/status_im/contexts/communities/overview/events_test.cljs index 2be10a1dda..17be7ec3d5 100644 --- a/src/status_im/contexts/communities/overview/events_test.cljs +++ b/src/status_im/contexts/communities/overview/events_test.cljs @@ -37,19 +37,22 @@ (sut/sign-data cofx [community-id password sign-params]))))) (deftest request-to-join-with-signatures-test - (let [cofx {:db {}} - addresses-to-reveal [account-pub-key "0x2"] - signatures ["11111" "222222"] - expected {:fx [[:json-rpc/call - [{:method "wakuext_requestToJoinCommunity" - :params [{:communityId community-id - :signatures signatures - :addressesToReveal addresses-to-reveal - :airdropAddress "0x1"}] - :js-response true - :on-success [:communities/requested-to-join] - :on-error [:communities/requested-to-join-error - community-id]}]]]}] + (let [cofx {:db {}} + addresses-to-reveal [account-pub-key "0x2"] + share-future-addresses? true + signatures ["11111" "222222"] + expected {:fx [[:json-rpc/call + [{:method "wakuext_requestToJoinCommunity" + :params [{:communityId community-id + :signatures signatures + :addressesToReveal addresses-to-reveal + :shareFutureAddresses share-future-addresses? + :airdropAddress "0x1"}] + :js-response true + :on-success [:communities/requested-to-join] + :on-error [:communities/requested-to-join-error + community-id]}]]]}] (is (match? expected (sut/request-to-join-with-signatures cofx - [community-id addresses-to-reveal signatures]))))) + [community-id addresses-to-reveal signatures + share-future-addresses?]))))) diff --git a/status-go-version.json b/status-go-version.json index 1226d81ffe..1c8e4ea8b6 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v0.182.35", - "commit-sha1": "484b8aca1a12718c9b3940f8a398e60ee4419600", - "src-sha256": "1xnpx86k54lnsw93xw6la0sggd9y0nm7hn70cm0qgmq2qg8pzb3a" + "version": "v0.182.36", + "commit-sha1": "8458cafef9f876c11a58dc9ede14fc58a5a0f968", + "src-sha256": "0nkb0zpqgpklh8mlrgcglh5v32qlfly9hd7ia3a1icx5kdp2q2wp" }