Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add featured-community data #16015 #16232

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/status_im/multiaccounts/login/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
[status-im2.contexts.contacts.events :as contacts]
[status-im2.navigation.events :as navigation]
[status-im2.contexts.shell.constants :as shell.constants]
[status-im2.contexts.communities.discover.events :as contract-communities]
erikseppanen marked this conversation as resolved.
Show resolved Hide resolved
[status-im2.common.log :as logging]
[taoensso.timbre :as log]
[status-im2.contexts.shell.utils :as shell.utils]
Expand Down Expand Up @@ -449,6 +450,7 @@
(initialize-wallet-connect)
(get-node-config)
(communities/fetch)
(contract-communities/fetch-contract-communities)
(communities/fetch-collapsed-community-categories)
(communities/check-and-delete-pending-request-to-join)
(logging/set-log-level (:log-level multiaccount))
Expand Down
45 changes: 45 additions & 0 deletions src/status_im2/contexts/communities/discover/events.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(ns status-im2.contexts.communities.discover.events
(:require [camel-snake-kebab.core :as csk]
[clojure.string :as string]
[taoensso.timbre :as log]
[utils.re-frame :as rf]))

(defn rename-contract-community-key
[k]
(let [s (name k)
lower-cased (csk/->kebab-case-string s)
starts-with-digit? (re-matches #"^\d.*" s)
predicate? (some #(string/starts-with? lower-cased %)
["can-" "is-"])]
(cond starts-with-digit? s
predicate? (keyword (str lower-cased "?"))
:else (keyword lower-cased))))

(defn rename-contract-community-keys
[m]
(reduce (fn [acc [k v]]
(let [new-key (if (keyword? k) (rename-contract-community-key k) k)]
(cond
(map? v) (assoc acc new-key (rename-contract-community-keys v))
:else (assoc acc new-key v))))
{}
m))

(rf/defn handle-contract-communities
{:events [:fetched-contract-communities]}
erikseppanen marked this conversation as resolved.
Show resolved Hide resolved
[{:keys [db]} contract-communities]
(let [cc (rename-contract-community-keys contract-communities)
featured (:contract-featured-communities cc)
other (remove (set featured) (:contract-communities cc))]
{:db (assoc db
:contract-communities
{:featured (select-keys (:communities cc) featured)
:other (select-keys (:communities cc) other)})}))

(rf/defn fetch-contract-communities
[_]
{:json-rpc/call [{:method "wakuext_curatedCommunities"
:params []
:on-success #(rf/dispatch [:fetched-contract-communities %])
:on-error #(log/error "failed to fetch contract communities" %)}]})

91 changes: 91 additions & 0 deletions src/status_im2/contexts/communities/discover/events_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
(ns status-im2.contexts.communities.discover.events-test
(:require [cljs.test :refer-macros [deftest are]]
[status-im2.contexts.communities.discover.events :as events]))

(deftest rename-contract-community-key-test
(are [i e] (= (events/rename-contract-community-key i) e)
:foo :foo
:fooBar :foo-bar
:fooBarBaz :foo-bar-baz
:isFoo :is-foo?
:isFooBar :is-foo-bar?
:canFoo :can-foo?
:canFooBar :can-foo-bar?
:0x025d27e58 "0x025d27e58"
:093b4684-92f0 "093b4684-92f0"
:3f9e77b8-97c7 "3f9e77b8-97c7"))

(deftest rename-contract-community-keys-test
(are [i e] (= (events/rename-contract-community-keys i) e)

{:contractCommunities
["0x032aa2439b14eb2caaf724223951da89de1530fbfa5d5a639b93b82cd5341713fd"
"0x025d27e58f1bece7d9675e6fe907da6e3b5007f06a327dd20db04d68851b9c153d"
"0x03769999b26cfd88788c882b56232fa5f58735795bdd463820d127b9a23d4415d4"]
:contractFeaturedCommunities
["0x03769999b26cfd88788c882b56232fa5f58735795bdd463820d127b9a23d4415d4"]
:communities
{:0x025d27e58f1bece7d9675e6fe907da6e3b5007f06a327dd20db04d68851b9c153d
{:name "foo"
:tokenPermissions nil
:isMember false
:canDeleteMessageForEveryone false}
:0x032aa2439b14eb2caaf724223951da89de1530fbfa5d5a639b93b82cd5341713fd
{:name "bar"
:adminSettings {:pinMessageAllMembersEnabled false}
:chats
{:8aa21892-a768-488a-8655-7ed31f527642
{:name "web"
:categoryID "d87621f7-315a-4579-a800-fde42d86ddf2"
:canPost false}
:6efc1767-22e5-46c1-9865-87206e04c9f9
{:name "mobile-ui"
:categoryID "7445461a-bd10-4c54-86fe-70403913faf4"
:canPost false}}}
:0x03769999b26cfd88788c882b56232fa5f58735795bdd463820d127b9a23d4415d4
{:name "baz"
:categories
{:18444776-8720-4955-b200-a55758889f43 {:name "bar" :position 0}
:093b4684-92f0-42dd-977c-05affc451ec8 {:name "foo" :position 1}}
:members
{:0x04a25e0a58ab97c6f93298ad87ab73aae5995365088a1ba150633ea25ff0b80cc1ddba18b122d117e477963cec1962219362a9a77226a6bf9a15d8d02c35fe8c9b
{}
:0x0490d2bb47388504e4b615052566e5830662bf202eb179251e9118587ce628c6c76e1f4550f9cd52058cf9dbdb5b788eea10b7c765cd7565675daa5f822acab8f4
{}}}}
:unknownCommunities nil}

{:contract-communities
["0x032aa2439b14eb2caaf724223951da89de1530fbfa5d5a639b93b82cd5341713fd"
"0x025d27e58f1bece7d9675e6fe907da6e3b5007f06a327dd20db04d68851b9c153d"
"0x03769999b26cfd88788c882b56232fa5f58735795bdd463820d127b9a23d4415d4"]
:contract-featured-communities
["0x03769999b26cfd88788c882b56232fa5f58735795bdd463820d127b9a23d4415d4"]
:communities
{"0x025d27e58f1bece7d9675e6fe907da6e3b5007f06a327dd20db04d68851b9c153d"
{:name "foo"
:token-permissions nil
:is-member? false
:can-delete-message-for-everyone? false}
"0x032aa2439b14eb2caaf724223951da89de1530fbfa5d5a639b93b82cd5341713fd"
{:name "bar"
:admin-settings {:pin-message-all-members-enabled false}
:chats
{"8aa21892-a768-488a-8655-7ed31f527642"
{:name "web"
:category-id "d87621f7-315a-4579-a800-fde42d86ddf2"
:can-post? false}
"6efc1767-22e5-46c1-9865-87206e04c9f9"
{:name "mobile-ui"
:category-id "7445461a-bd10-4c54-86fe-70403913faf4"
:can-post? false}}}
"0x03769999b26cfd88788c882b56232fa5f58735795bdd463820d127b9a23d4415d4"
{:name "baz"
:categories
{"18444776-8720-4955-b200-a55758889f43" {:name "bar" :position 0}
"093b4684-92f0-42dd-977c-05affc451ec8" {:name "foo" :position 1}}
:members
{"0x04a25e0a58ab97c6f93298ad87ab73aae5995365088a1ba150633ea25ff0b80cc1ddba18b122d117e477963cec1962219362a9a77226a6bf9a15d8d02c35fe8c9b"
{}
"0x0490d2bb47388504e4b615052566e5830662bf202eb179251e9118587ce628c6c76e1f4550f9cd52058cf9dbdb5b788eea10b7c765cd7565675daa5f822acab8f4"
{}}}}
:unknown-communities nil}))
5 changes: 2 additions & 3 deletions src/status_im2/contexts/communities/discover/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
:label (i18n/label :t/gated)
:accessibility-label :gated-communities-tab}]}]])


(defn featured-list
[communities view-type]
(let [view-size (reagent/atom 0)]
Expand Down Expand Up @@ -158,7 +157,7 @@
[rn/view {:style {:flex 1}}
(case @selected-tab
:all
(other-communities-list {:communities (rf/sub [:communities/sorted-communities])
(other-communities-list {:communities (rf/sub [:communities/other-contract-communities])
:view-type view-type})

:open
Expand Down Expand Up @@ -227,7 +226,7 @@

(defn discover
[]
(let [featured-communities (rf/sub [:communities/featured-communities])]
(let [featured-communities (rf/sub [:communities/featured-contract-communities])]
[rn/view
{:style (style/discover-screen-container (colors/theme-colors
colors/white
Expand Down
16 changes: 8 additions & 8 deletions src/status_im2/subs/communities.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@
(sort-by #(visibility-status-utils/visibility-status-order (get % 0)))))))

(re-frame/reg-sub
:communities/featured-communities
:<- [:communities]
(fn [communities]
(vals communities)))
:communities/featured-contract-communities
:<- [:contract-communities]
(fn [contract-communities]
(sort-by :name (vals (:featured contract-communities)))))

(re-frame/reg-sub
:communities/sorted-communities
:<- [:communities]
(fn [communities]
(sort-by :name (vals communities))))
:communities/other-contract-communities
:<- [:contract-communities]
(fn [contract-communities]
(sort-by :name (vals (:other contract-communities)))))

(re-frame/reg-sub
:communities/community-ids
Expand Down
19 changes: 0 additions & 19 deletions src/status_im2/subs/communities_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,6 @@
:unviewed-mentions-count 0}
(rf/sub [sub-name community-id])))))

(h/deftest-sub :communities/sorted-communities
[sub-name]
(testing "Empty communities list"
(swap! rf-db/app-db assoc
:communities
{})
(is (= []
(rf/sub [sub-name]))))
(testing "communities sorted by name"
(swap! rf-db/app-db assoc
:communities
{"0x1" {:id "0x1" :name "Civilized monkeys"}
"0x2" {:id "0x2" :name "Civilized rats"}
"0x3" {:id "0x3" :name "Civilized dolphins"}})
(is (= [{:id "0x3" :name "Civilized dolphins"}
{:id "0x1" :name "Civilized monkeys"}
{:id "0x2" :name "Civilized rats"}]
(rf/sub [sub-name])))))

(h/deftest-sub :communities/categorized-channels
[sub-name]
(testing "Channels with categories"
Expand Down
2 changes: 2 additions & 0 deletions src/status_im2/subs/root.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@
(reg-root-key-sub :communities/collapsed-categories :communities/collapsed-categories)
(reg-root-key-sub :communities/selected-tab :communities/selected-tab)

(reg-root-key-sub :contract-communities :contract-communities)

erikseppanen marked this conversation as resolved.
Show resolved Hide resolved
(reg-root-key-sub :activity-center :activity-center)

(reg-root-key-sub :bug-report/description-error :bug-report/description-error)
Expand Down