|
42 | 42 | community-id %])
|
43 | 43 | :on-error #(log/error "failed to request to join community" community-id %)}]})
|
44 | 44 |
|
| 45 | +(defn request-to-join |
| 46 | + [{:keys [db]} [{:keys [community-id password]}]] |
| 47 | + (let [pub-key (get-in db [:profile/profile :public-key]) |
| 48 | + addresses-to-reveal []] |
| 49 | + {:fx [[:json-rpc/call |
| 50 | + [{:method "wakuext_generateJoiningCommunityRequestsForSigning" |
| 51 | + :params [pub-key community-id addresses-to-reveal] |
| 52 | + :on-success [:communities/sign-data community-id password] |
| 53 | + :on-error [:communities/requested-to-join-error community-id]}]]]})) |
| 54 | + |
45 | 55 | ;; Event to be called to request to join a community.
|
46 | 56 | ;; This event will generate the data to be signed and then call the sign-data event.
|
47 | 57 | ;; This is the only event that should be called from the UI.
|
48 |
| -(rf/reg-event-fx :communities/request-to-join |
49 |
| - (fn [{:keys [db]} [{:keys [community-id password]}]] |
50 |
| - (let [pub-key (get-in db [:profile/profile :public-key]) |
51 |
| - addresses-to-reveal []] |
52 |
| - {:fx [[:json-rpc/call |
53 |
| - [{:method "wakuext_generateJoiningCommunityRequestsForSigning" |
54 |
| - :params [pub-key community-id addresses-to-reveal] |
55 |
| - :on-success [:communities/sign-data community-id password] |
56 |
| - :on-error [:communities/requested-to-join-error community-id]}]]]}))) |
| 58 | +(rf/reg-event-fx :communities/request-to-join request-to-join) |
57 | 59 |
|
58 |
| -(rf/reg-event-fx :communities/sign-data |
59 |
| - (fn [_ [community-id password sign-params]] |
60 |
| - {:fx [[:json-rpc/call |
61 |
| - [{:method "wakuext_signData" |
62 |
| - :params [(map #(assoc % :password password) sign-params)] |
63 |
| - :on-success [:communities/request-to-join-with-signatures community-id] |
64 |
| - :on-error [:communities/requested-to-join-error community-id]}]]]})) |
| 60 | +(defn sign-data |
| 61 | + [_ [community-id password sign-params]] |
| 62 | + (let [addresses-to-reveal (map :account sign-params)] |
| 63 | + {:fx [[:json-rpc/call |
| 64 | + [{:method "wakuext_signData" |
| 65 | + :params [(map #(assoc % :password password) sign-params)] |
| 66 | + :on-success [:communities/request-to-join-with-signatures community-id addresses-to-reveal] |
| 67 | + :on-error [:communities/requested-to-join-error community-id]}]]]})) |
| 68 | + |
| 69 | +(rf/reg-event-fx :communities/sign-data sign-data) |
65 | 70 |
|
66 | 71 | (rf/reg-event-fx :communities/requested-to-join-error
|
67 | 72 | (fn [{:keys [db]} [community-id error]]
|
|
71 | 76 | :event :communities/requested-to-join-error})
|
72 | 77 | {:db (assoc-in db [:password-authentication :error] error)}))
|
73 | 78 |
|
74 |
| -(rf/reg-event-fx :communities/request-to-join-with-signatures |
75 |
| - (fn [_ [community-id signatures]] |
76 |
| - {:fx [[:json-rpc/call |
77 |
| - [{:method "wakuext_requestToJoinCommunity" |
78 |
| - :params [{:communityId community-id :signatures signatures}] |
79 |
| - :js-response true |
80 |
| - :on-success [:communities/requested-to-join] |
81 |
| - :on-error [:communities/requested-to-join-error community-id]}]]]})) |
| 79 | +(defn request-to-join-with-signatures |
| 80 | + [_ [community-id addresses-to-reveal signatures]] |
| 81 | + {:fx [[:json-rpc/call |
| 82 | + [{:method "wakuext_requestToJoinCommunity" |
| 83 | + :params [{:communityId community-id |
| 84 | + :signatures signatures |
| 85 | + :addressesToReveal addresses-to-reveal |
| 86 | + ;; NOTE: At least one airdrop address is required. |
| 87 | + ;; This is a temporary solution while the address |
| 88 | + ;; selection feature is not implemented in mobile. |
| 89 | + :airdropAddress (first addresses-to-reveal)}] |
| 90 | + :js-response true |
| 91 | + :on-success [:communities/requested-to-join] |
| 92 | + :on-error [:communities/requested-to-join-error community-id]}]]]}) |
| 93 | + |
| 94 | +(rf/reg-event-fx :communities/request-to-join-with-signatures request-to-join-with-signatures) |
0 commit comments