|
12 | 12 | status-im.contexts.communities.actions.addresses-for-permissions.events
|
13 | 13 | status-im.contexts.communities.actions.community-options.events
|
14 | 14 | status-im.contexts.communities.actions.leave.events
|
15 |
| - [status-im.contexts.communities.utils :as utils] |
16 | 15 | [status-im.navigation.events :as navigation]
|
17 | 16 | [taoensso.timbre :as log]
|
18 | 17 | [utils.i18n :as i18n]
|
|
164 | 163 | (defn initialize-permission-addresses
|
165 | 164 | [{:keys [db]} [community-id]]
|
166 | 165 | (when community-id
|
167 |
| - (let [accounts (utils/sorted-non-watch-only-accounts db) |
168 |
| - addresses (set (map :address accounts))] |
| 166 | + (let [accounts (get-in db [:wallet :accounts]) |
| 167 | + sorted-accounts (sort-by :position (vals accounts)) |
| 168 | + addresses (set (map :address sorted-accounts))] |
169 | 169 | {:db (update-in db
|
170 | 170 | [:communities community-id]
|
171 | 171 | assoc
|
172 |
| - :previous-share-all-addresses? true |
173 |
| - :share-all-addresses? true |
174 | 172 | :previous-permission-addresses addresses
|
175 | 173 | :selected-permission-addresses addresses
|
176 |
| - :airdrop-address (:address (first accounts)))}))) |
| 174 | + :airdrop-address (:address (first sorted-accounts)))}))) |
177 | 175 |
|
178 | 176 | (rf/reg-event-fx :communities/initialize-permission-addresses
|
179 | 177 | initialize-permission-addresses)
|
180 | 178 |
|
181 | 179 | (defn update-previous-permission-addresses
|
182 | 180 | [{:keys [db]} [community-id]]
|
183 | 181 | (when community-id
|
184 |
| - (let [accounts (utils/sorted-non-watch-only-accounts db) |
| 182 | + (let [accounts (get-in db [:wallet :accounts]) |
| 183 | + sorted-accounts (sort-by :position (vals accounts)) |
185 | 184 | selected-permission-addresses (get-in db
|
186 | 185 | [:communities community-id
|
187 | 186 | :selected-permission-addresses])
|
188 | 187 | selected-accounts (filter #(contains? selected-permission-addresses (:address %))
|
189 |
| - accounts) |
190 |
| - current-airdrop-address (get-in db [:communities community-id :airdrop-address]) |
191 |
| - share-all-addresses? (get-in db [:communities community-id :share-all-addresses?])] |
| 188 | + sorted-accounts) |
| 189 | + current-airdrop-address (get-in db [:communities community-id :airdrop-address])] |
192 | 190 | {:db (update-in db
|
193 | 191 | [:communities community-id]
|
194 | 192 | assoc
|
195 |
| - :previous-share-all-addresses? share-all-addresses? |
196 | 193 | :previous-permission-addresses selected-permission-addresses
|
197 | 194 | :airdrop-address (if (contains? selected-permission-addresses
|
198 | 195 | current-airdrop-address)
|
|
221 | 218 | (rf/reg-event-fx :communities/toggle-selected-permission-address
|
222 | 219 | toggle-selected-permission-address)
|
223 | 220 |
|
224 |
| -(defn toggle-share-all-addresses |
225 |
| - [{:keys [db]} [community-id]] |
226 |
| - (let [share-all-addresses? (get-in db [:communities community-id :share-all-addresses?]) |
227 |
| - accounts (utils/sorted-non-watch-only-accounts db) |
228 |
| - addresses (set (map :address accounts))] |
229 |
| - {:db (update-in db |
230 |
| - [:communities community-id] |
231 |
| - (fn [community] |
232 |
| - (-> community |
233 |
| - (assoc :share-all-addresses? (not share-all-addresses?)) |
234 |
| - (cond-> (not share-all-addresses?) |
235 |
| - (assoc :selected-permission-addresses addresses)))))})) |
236 |
| - |
237 |
| -(rf/reg-event-fx :communities/toggle-share-all-addresses |
238 |
| - toggle-share-all-addresses) |
239 |
| - |
240 | 221 | (rf/reg-event-fx :communities/reset-selected-permission-addresses
|
241 | 222 | (fn [{:keys [db]} [community-id]]
|
242 | 223 | (when community-id
|
243 |
| - {:db (update-in db |
244 |
| - [:communities community-id] |
245 |
| - assoc |
246 |
| - :selected-permission-addresses |
247 |
| - (get-in db [:communities community-id :previous-permission-addresses]) |
248 |
| - :share-all-addresses? |
249 |
| - (get-in db [:communities community-id :previous-share-all-addresses?])) |
| 224 | + {:db (assoc-in db |
| 225 | + [:communities community-id :selected-permission-addresses] |
| 226 | + (get-in db [:communities community-id :previous-permission-addresses])) |
250 | 227 | :fx [[:dispatch [:communities/check-permissions-to-join-community community-id]]]})))
|
251 | 228 |
|
252 |
| -(rf/reg-event-fx :communities/share-community-channel-url-with-data |
253 |
| - (fn [_ [chat-id]] |
254 |
| - (let [{:keys [community-id channel-id]} (data-store.chats/decode-chat-id chat-id) |
255 |
| - title (i18n/label :t/channel-on-status)] |
| 229 | +(rf/reg-event-fx :communities/get-community-channel-share-data |
| 230 | + (fn [_ [chat-id on-success]] |
| 231 | + (let [{:keys [community-id channel-id]} (data-store.chats/decode-chat-id chat-id)] |
256 | 232 | {:json-rpc/call
|
257 | 233 | [{:method "wakuext_shareCommunityChannelURLWithData"
|
258 | 234 | :params [{:CommunityID community-id :ChannelID channel-id}]
|
259 |
| - :on-success (fn [url] |
| 235 | + :on-success on-success |
| 236 | + :on-error (fn [err] |
| 237 | + (log/error "failed to retrieve community channel url with data" |
| 238 | + {:error err |
| 239 | + :chat-id chat-id |
| 240 | + :event :communities/get-community-channel-share-data}))}]}))) |
| 241 | + |
| 242 | +(rf/reg-event-fx :communities/share-community-channel-url-with-data |
| 243 | + (fn [_ [chat-id]] |
| 244 | + (let [title (i18n/label :t/channel-on-status) |
| 245 | + on-success (fn [url] |
260 | 246 | (share/open
|
261 | 247 | (if platform/ios?
|
262 | 248 | {:activityItemSources [{:placeholderItem {:type "text"
|
|
268 | 254 | :subject title
|
269 | 255 | :message url
|
270 | 256 | :url url
|
271 |
| - :isNewTask true}))) |
272 |
| - :on-error (fn [err] |
273 |
| - (log/error "failed to retrieve community channel url with data" |
274 |
| - {:error err |
275 |
| - :chat-id chat-id |
276 |
| - :event "share-community-channel-url-with-data"}))}]}))) |
| 257 | + :isNewTask true})))] |
| 258 | + {:fx [[:dispatch [:communities/get-community-channel-share-data chat-id on-success]]]}))) |
277 | 259 |
|
278 |
| -(rf/reg-event-fx :communities/community-channel-url-qr-code-with-data |
| 260 | +(rf/reg-event-fx :communities/share-community-channel-url-qr-code |
279 | 261 | (fn [_ [chat-id]]
|
280 |
| - (let [{:keys [community-id channel-id]} (data-store.chats/decode-chat-id chat-id)] |
281 |
| - {:json-rpc/call |
282 |
| - [{:method "wakuext_shareCommunityChannelURLWithData" |
283 |
| - :params [{:CommunityID community-id |
284 |
| - :ChannelID channel-id}] |
285 |
| - :on-success (fn [url] |
286 |
| - (rf/dispatch [:open-modal :share-community-channel {:url url}])) |
287 |
| - :on-error (fn [err] |
288 |
| - (log/error "failed to retrieve community channel url with data" |
289 |
| - {:error err |
290 |
| - :chat-id chat-id |
291 |
| - :event [:communities/community-channel-url-qr-code-with-data]}))}]}))) |
| 262 | + (let [on-success #(rf/dispatch [:open-modal :share-community-channel |
| 263 | + {:chat-id chat-id |
| 264 | + :url %}])] |
| 265 | + {:fx [[:dispatch [:communities/get-community-channel-share-data chat-id on-success]]]}))) |
292 | 266 |
|
293 | 267 | (rf/reg-event-fx :communities/set-airdrop-address
|
294 | 268 | (fn [{:keys [db]} [address community-id]]
|
|
0 commit comments