From c6893eb0380de832d4cc4e775d8b8ad3a892b063 Mon Sep 17 00:00:00 2001 From: Vitaly Vlasov Date: Mon, 24 Jun 2024 18:46:52 +0300 Subject: [PATCH] fix_: share-all-future-addresses storage https://github.com/status-im/status-go/compare/b665d68d...12acf753 --- .../actions/accounts_selection/effects.cljs | 23 ++++--- .../actions/accounts_selection/events.cljs | 64 ++++++++++--------- .../accounts_selection/events_test.cljs | 35 +++++----- .../addresses_for_permissions/view.cljs | 4 +- .../contexts/communities/events.cljs | 24 +++---- .../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, 123 insertions(+), 101 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 0be9019961..af485434e8 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-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-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-non-watch-only-accounts db) + addresses-to-reveal (if (seq addresses) + (set addresses) + (get-in db [:communities/all-addresses-to-reveal community-id])) + share-future-addresses? (if (nil? share-future-addresses?) + (get-in db [:communities/selected-share-all-addresses community-id]) + share-future-addresses?) + new-airdrop-address (if (contains? addresses-to-reveal airdrop-address) + airdrop-address + (->> wallet-accounts + (filter #(contains? addresses-to-reveal (:address %))) + first + :address))] {: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 db933aaa7b..6a33189144 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 @@ -62,7 +62,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 @@ -74,7 +74,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. @@ -85,7 +85,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 @@ -93,7 +93,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 @@ -101,6 +101,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" @@ -108,22 +109,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 0bd4849c02..08d1e2c9f4 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)] diff --git a/src/status_im/contexts/communities/events.cljs b/src/status_im/contexts/communities/events.cljs index 1b750a4f01..1a8ae54bd3 100644 --- a/src/status_im/contexts/communities/events.cljs +++ b/src/status_im/contexts/communities/events.cljs @@ -372,8 +372,8 @@ (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])] + [{:method "wakuext_latestRequestToJoinForCommunity" + :params [community-id] :js-response true :on-success [:communities/get-revealed-accounts-success community-id on-success] :on-error (fn [err] @@ -399,22 +399,24 @@ [: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 latest-request-to-join-js]] (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 [request-to-join (js->clj latest-request-to-join-js :keywordize-keys true) + revealed-accounts ( + reduce + (fn [acc {:keys [address] :as revealed-account}] + (assoc acc address revealed-account)) + {} + (js->clj (:revealedAccounts request-to-join) :keywordize-keys true)) + 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 6761a8bc6a..ad6408bad0 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 62115adb5c..fbdfe94b5f 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.181.31", - "commit-sha1": "6e056348e6d28f962167118612826f1ef0e47b22", - "src-sha256": "1qvfwk28sg93basjzy8r55qz8pk9xg0h7kxv5ykxkbfh4q17a1ns" + "version": "feature/edit-permissions-rebased", + "commit-sha1": "12acf753884fecd01c96bb6c0914a08b992fa429", + "src-sha256": "0y0x98axbb2ln12x98bpj793wpzal9dbq5bhngbpn0ffhb3sdr50" }