fix: handle unknown contract community

Signed-off-by: yqrashawn <namy.19@gmail.com>
This commit is contained in:
yqrashawn 2024-05-29 17:54:58 +08:00 committed by GitHub
parent 76a61bc56c
commit c3dc78648a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 101 additions and 6 deletions

View File

@ -84,7 +84,9 @@
(local-notifications/process cofx (transforms/js->clj event-js))
"community.found"
(link-preview/cache-community-preview-data (transforms/js->clj event-js))
(let [community (transforms/js->clj event-js)]
(link-preview/cache-community-preview-data community)
{:fx [[:dispatch [:discover-community/maybe-found-unknown-contract-community community]]]})
"status.updates.timedout"
(visibility-status-updates/handle-visibility-status-updates cofx (transforms/js->clj event-js))

View File

@ -50,16 +50,38 @@
{}
m))
(rf/defn handle-contract-communities
{:events [:fetched-contract-communities]}
[{:keys [db]} contract-communities]
(defn maybe-found-unknown-contract-community
[{:keys [db]} [{:keys [id] :as community}]]
(let [{:keys [contract-communities]} db
{:keys [unknown-featured unknown-other]} contract-communities]
{:db (cond-> db
((set unknown-featured) id)
(assoc-in [:contract-communities :featured id] community)
((set unknown-featured) id)
(assoc-in [:contract-communities :unknown-featured] (remove #{id} unknown-featured))
((set unknown-other) id)
(assoc-in [:contract-communities :other id] community)
((set unknown-other) id)
(assoc-in [:contract-communities :unknown-other] (remove #{id} unknown-other)))}))
(rf/reg-event-fx :discover-community/maybe-found-unknown-contract-community
maybe-found-unknown-contract-community)
(defn handle-contract-communities
[{:keys [db]} [contract-communities]]
(let [cc (rename-contract-community-keys contract-communities)
featured (:contract-featured-communities cc)
unknown (:unknown-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)})}))
{:featured (select-keys (:communities cc) featured)
:unknown-featured (filter (set unknown) featured)
:unknown-other (filter (set unknown) other)
:other (select-keys (:communities cc) other)})}))
(rf/reg-event-fx :fetched-contract-communities handle-contract-communities)
(rf/defn fetch-contract-communities
{:events [:fetch-contract-communities]}

View File

@ -87,3 +87,74 @@
"0x0490d2bb47388504e4b615052566e5830662bf202eb179251e9118587ce628c6c76e1f4550f9cd52058cf9dbdb5b788eea10b7c765cd7565675daa5f822acab8f4"
{}}}}
:unknown-communities nil}))
(deftest handle-contract-communities-test
(are [input-contract-communities
expected-contract-communities-in-db]
(match?
(get-in (events/handle-contract-communities {:db nil} [input-contract-communities])
[:db :contract-communities])
expected-contract-communities-in-db)
{:communities {}
:contractFeaturedCommunities []
:contractCommunities []
:unknownCommunities []}
{:featured {}
:other {}
:unknown-featured '()
:unknown-other '()}
{:communities {"a" {:id "a"}}
:contractFeaturedCommunities ["a" "b"]
:contractCommunities ["a" "b" "c"]
:unknownCommunities ["b" "c"]}
{:featured {"a" {:id "a"}}
:other {}
:unknown-featured '("b")
:unknown-other '("c")}))
(deftest maybe-found-unknown-contract-community-test
(are [contract-communities-already-in-db
input-found-community
expected-contract-communities-in-db]
(match?
(get-in (events/maybe-found-unknown-contract-community
{:db {:contract-communities contract-communities-already-in-db}}
[input-found-community])
[:db :contract-communities])
expected-contract-communities-in-db)
nil {:id "community-a"} nil
{:featured {"a" {:id "a"}}
:other {"b" {:id "b"}}
:unknown-featured '("c")
:unknown-other '("d")}
{:id "c"}
{:featured {"a" {:id "a"}
"c" {:id "c"}}
:other {"b" {:id "b"}}
:unknown-featured '()
:unknown-other '("d")}
{:featured {"a" {:id "a"}}
:other {"b" {:id "b"}}
:unknown-featured '("c")
:unknown-other '("d")}
{:id "d"}
{:featured {"a" {:id "a"}}
:other {"b" {:id "b"}
"d" {:id "d"}}
:unknown-featured '("c")
:unknown-other '()}
{:featured {"a" {:id "a"}}
:other {"b" {:id "b"}}
:unknown-featured '("c")
:unknown-other '("d")}
{:id "e"}
{:featured {"a" {:id "a"}}
:other {"b" {:id "b"}}
:unknown-featured '("c")
:unknown-other '("d")}))