Related status-go PR: https://github.com/status-im/status-go/pull/5354
6e056348...8458cafe
Signed-off-by: Vitaly Vlasov <mail@vitv.ly>
This commit is contained in:
parent
97b19c5440
commit
2b0847ef76
|
@ -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,7 +41,7 @@
|
|||
: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
|
||||
|
@ -49,7 +49,8 @@
|
|||
:params [{:communityId community-id
|
||||
:signatures signatures
|
||||
:addressesToReveal addresses-to-reveal
|
||||
:airdropAddress airdrop-address}]
|
||||
: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?]]]
|
||||
|
|
|
@ -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,7 +56,8 @@
|
|||
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]}]]
|
||||
[{: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)
|
||||
|
@ -71,16 +68,22 @@
|
|||
(->> wallet-accounts
|
||||
(filter #(contains? addresses-to-reveal (:address %)))
|
||||
first
|
||||
:address))]
|
||||
: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
|
||||
: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))
|
||||
(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]}]]}))
|
||||
|
@ -88,8 +91,9 @@
|
|||
(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
|
||||
|
|
|
@ -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"
|
||||
|
@ -119,6 +120,7 @@
|
|||
[{: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)))}])
|
||||
|
||||
|
@ -129,6 +131,7 @@
|
|||
: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]}]]}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,9 +373,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])]
|
||||
:js-response true
|
||||
[{: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"
|
||||
|
@ -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]]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -117,12 +117,13 @@
|
|||
{: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
|
||||
:shareFutureAddresses share-future-addresses?
|
||||
:airdropAddress (first addresses-to-reveal)}]
|
||||
:js-response true
|
||||
:on-success [:communities/requested-to-join]
|
||||
|
@ -155,6 +156,7 @@
|
|||
[{: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])
|
||||
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
|
||||
|
@ -162,6 +164,7 @@
|
|||
: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]}]]}))
|
||||
|
||||
|
|
|
@ -39,12 +39,14 @@
|
|||
(deftest request-to-join-with-signatures-test
|
||||
(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]
|
||||
|
@ -52,4 +54,5 @@
|
|||
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?])))))
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
|
||||
"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"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue