Adapt to status-go API Changes for Request to Join Community Flow (#17800)

This commit is contained in:
Ajay Sivan 2023-11-03 08:57:56 -07:00 committed by GitHub
parent 2a4bb84e35
commit aa6d44bee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 31 deletions

View File

@ -220,32 +220,6 @@
(log/error "failed to import community" %)
(re-frame/dispatch [::failed-to-import %]))}]})
(rf/defn request-to-join
{:events [:communities/request-to-join]}
[_ community-id]
{:json-rpc/call [{:method "wakuext_requestToJoinCommunity"
:params [{:communityId community-id}]
:js-response true
:on-success #(re-frame/dispatch [:communities/requested-to-join %])
:on-error #(log/error "failed to request to join community" community-id)}]})
(rf/defn requested-to-join-with-password-error
{:events [:communities/requested-to-join-with-password-error]}
[{:keys [db]} error]
{:db (assoc-in db [:password-authentication :error] error)})
(rf/defn request-to-join-with-password
{:events [:communities/request-to-join-with-password]}
[_ community-id password]
{:json-rpc/call [{:method "wakuext_requestToJoinCommunity"
:params [{:communityId community-id :password password}]
:js-response true
:on-success #(re-frame/dispatch [:communities/requested-to-join %])
:on-error (fn [error]
(log/error "failed to request to join community" community-id error)
(re-frame/dispatch [:communities/requested-to-join-with-password-error
error]))}]})
(rf/defn get-user-requests-to-join
{:events [:communities/get-user-requests-to-join]}
[_]

View File

@ -14,7 +14,8 @@
(rf/dispatch [:password-authentication/show
{:content (fn [] [password-authentication/view])}
{:label (i18n/label :t/join-open-community)
:on-press #(rf/dispatch [:communities/request-to-join-with-password id %])}])
:on-press #(rf/dispatch [:communities/request-to-join
{:community-id id :password %}])}])
(rf/dispatch [:navigate-back]))
(defn request-to-join

View File

@ -21,3 +21,41 @@
:on-success #(rf/dispatch [:communities/check-permissions-to-join-community-success
community-id %])
:on-error #(log/error "failed to request to join community" community-id %)}]})
;; Event to be called to request to join a community.
;; This event will generate the data to be signed and then call the sign-data event.
;; This is the only event that should be called from the UI.
(rf/reg-event-fx :communities/request-to-join
(fn [{:keys [db]} [{:keys [community-id password]}]]
(let [pub-key (get-in db [:profile/profile :public-key])
addresses-to-reveal []]
{:fx [[:json-rpc/call
[{:method "wakuext_generateJoiningCommunityRequestsForSigning"
:params [pub-key community-id addresses-to-reveal]
:on-success [:communities/sign-data community-id password]
:on-error [:communities/requested-to-join-error community-id]}]]]})))
(rf/reg-event-fx :communities/sign-data
(fn [_ [community-id password sign-params]]
{:fx [[:json-rpc/call
[{:method "wakuext_signData"
:params [(map #(assoc % :password password) sign-params)]
:on-success [:communities/request-to-join-with-signatures community-id]
:on-error [:communities/requested-to-join-error community-id]}]]]}))
(rf/reg-event-fx :communities/requested-to-join-error
(fn [{:keys [db]} [community-id error]]
(log/error "failed to request to join community"
{:community-id community-id
:error error
:event :communities/requested-to-join-error})
{:db (assoc-in db [:password-authentication :error] error)}))
(rf/reg-event-fx :communities/request-to-join-with-signatures
(fn [_ [community-id signatures]]
{:fx [[:json-rpc/call
[{:method "wakuext_requestToJoinCommunity"
:params [{:communityId community-id :signatures signatures}]
:js-response true
:on-success [:communities/requested-to-join]
:on-error [:communities/requested-to-join-error community-id]}]]]}))

View File

@ -113,7 +113,8 @@
(rf/dispatch [:password-authentication/show
{:content (fn [] [password-authentication/view])}
{:label (i18n/label :t/join-open-community)
:on-press #(rf/dispatch [:communities/request-to-join-with-password id %])}]))
:on-press #(rf/dispatch [:communities/request-to-join
{:community-id id :password %}])}]))
(defn info-button
[]

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.171.8",
"commit-sha1": "678fc03b376e02df7142e89f2c626e3ba1c03807",
"src-sha256": "0bapjbyyyrvg2k3jimpfshcwc77lylamhlm9si3mbnrbm1dl89xc"
"version": "v0.171.9",
"commit-sha1": "af0c8c33b2d00930ef19448ed146c542b1346cce",
"src-sha256": "0gc4gymby0ghg59wzv6537qg9a9hgz1kkfmdrpif3lrq32d98lmk"
}