-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d43b73b
commit 13041b0
Showing
6 changed files
with
59 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
(ns status-im2.contexts.communities.discover.events | ||
(:require [clojure.set :as set] | ||
[clojure.string :as string] | ||
[taoensso.timbre :as log] | ||
[utils.re-frame :as rf])) | ||
|
||
(defn camel->kebab | ||
[k] | ||
(let [s (name k) | ||
lower-cased (string/lower-case | ||
(string/replace s #"([a-z])([A-Z])" "$1-$2")) | ||
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-keys | ||
[m] | ||
(reduce (fn [acc [k v]] | ||
(let [new-key (if (keyword? k) (camel->kebab k) k)] | ||
(cond | ||
(map? v) (assoc acc new-key (rename-keys v)) | ||
:else (assoc acc new-key v)))) | ||
{} | ||
m)) | ||
|
||
(rf/defn handle-contract-communities | ||
{:events [:fetched-contract-communities]} | ||
[{:keys [db]} contract-communities] | ||
(let [cc (rename-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" %)}]}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters