diff --git a/src/status_im/data_store/switcher_cards.cljs b/src/status_im/data_store/switcher_cards.cljs new file mode 100644 index 0000000000..4cfa48d777 --- /dev/null +++ b/src/status_im/data_store/switcher_cards.cljs @@ -0,0 +1,41 @@ +(ns status-im.data-store.switcher-cards + (:require [clojure.set :as set] + [clojure.walk :as walk] + [utils.re-frame :as rf] + [taoensso.timbre :as log])) + +(defn <-rpc + [switcher-cards] + (walk/postwalk-replace + {:cardId :card-id + :screenId :screen-id} + switcher-cards)) + +(defn rpc-> + [switcher-card] + (set/rename-keys switcher-card + {:card-id :cardId + :screen-id :screenId})) + +(rf/defn upsert-switcher-card-rpc + [_ switcher-card] + {:json-rpc/call [{:method "wakuext_upsertSwitcherCard" + :params [(rpc-> switcher-card)] + :on-success #() + :on-error #()}]}) + +(rf/defn delete-switcher-card-rpc + [_ card-id] + {:json-rpc/call [{:method "wakuext_deleteSwitcherCard" + :params [card-id] + :on-success #() + :on-error #()}]}) + +(rf/defn fetch-switcher-cards-rpc + [_] + {:json-rpc/call [{:method "wakuext_switcherCards" + :params [] + :on-success #(rf/dispatch + [:shell/switcher-cards-loaded + (:switcherCards ^js %)]) + :on-error #(log/error "Failed to fetch switcher cards" %)}]}) diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index 5e53d33bfe..6b64a3bf02 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -9,6 +9,7 @@ [status-im.data-store.chats :as data-store.chats] [status-im.data-store.invitations :as data-store.invitations] [status-im.data-store.settings :as data-store.settings] + [status-im.data-store.switcher-cards :as switcher-cards-store] [status-im.data-store.visibility-status-updates :as visibility-status-updates-store] [status-im.ethereum.core :as ethereum] [status-im.ethereum.eip55 :as eip55] @@ -473,7 +474,8 @@ (multiaccounts/get-profile-picture) (multiaccounts/switch-preview-privacy-mode-flag) (link-preview/request-link-preview-whitelist) - (visibility-status-updates-store/fetch-visibility-status-updates-rpc)))) + (visibility-status-updates-store/fetch-visibility-status-updates-rpc) + (switcher-cards-store/fetch-switcher-cards-rpc)))) (defn get-new-auth-method [auth-method save-password?] diff --git a/src/status_im2/contexts/shell/events.cljs b/src/status_im2/contexts/shell/events.cljs index 3fc8f320cf..32c2805938 100644 --- a/src/status_im2/contexts/shell/events.cljs +++ b/src/status_im2/contexts/shell/events.cljs @@ -1,10 +1,12 @@ (ns status-im2.contexts.shell.events (:require [utils.re-frame :as rf] [re-frame.core :as re-frame] + [status-im.utils.core :as utils] [status-im2.common.constants :as constants] [status-im2.navigation.events :as navigation] [status-im2.contexts.shell.animation :as animation] - [status-im2.contexts.shell.constants :as shell.constants])) + [status-im2.contexts.shell.constants :as shell.constants] + [status-im.data-store.switcher-cards :as switcher-cards-store])) ;; Effects @@ -29,59 +31,76 @@ ;; Events -(rf/defn add-switcher-card - {:events [:shell/add-switcher-card]} - [{:keys [db now] :as cofx} view-id id] +(rf/defn switcher-cards-loaded + {:events [:shell/switcher-cards-loaded]} + [{:keys [db]} loaded-switcher-cards] + {:db (assoc db + :shell/switcher-cards + (utils/index-by :card-id (switcher-cards-store/<-rpc loaded-switcher-cards)))}) + +(defn calculate-card-data + [db now view-id id] (case view-id :chat (let [chat (get-in db [:chats id])] (case (:chat-type chat) constants/one-to-one-chat-type - {:shell/navigate-from-shell-fx :chats-stack - :db (assoc-in - db - [:shell/switcher-cards id] - {:type shell.constants/one-to-one-chat-card - :id id - :clock now})} + {:navigate-from :chats-stack + :card-id id + :switcher-card {:type shell.constants/one-to-one-chat-card + :card-id id + :clock now + :screen-id id}} constants/private-group-chat-type - {:shell/navigate-from-shell-fx :chats-stack - :db (assoc-in - db - [:shell/switcher-cards id] - {:type shell.constants/private-group-chat-card - :id id - :clock now})} + {:navigate-from :chats-stack + :card-id id + :switcher-card {:type shell.constants/private-group-chat-card + :card-id id + :clock now + :screen-id id}} constants/community-chat-type - {:shell/navigate-from-shell-fx :communities-stack - :db (assoc-in - db - [:shell/switcher-cards (:community-id chat)] - {:type shell.constants/community-channel-card - :id (:community-id chat) - :clock now - :channel-id (:chat-id chat)})} + {:navigate-from :communities-stack + :card-id (:community-id chat) + :switcher-card {:type shell.constants/community-channel-card + :card-id (:community-id chat) + :clock now + :screen-id (:chat-id chat)}} nil)) :community - {:shell/navigate-from-shell-fx :communities-stack - :db (assoc-in - db - [:shell/switcher-cards (:community-id id)] - {:type shell.constants/community-card - :id (:community-id id) - :clock now - :channel-id nil})} - + {:navigate-from :communities-stack + :card-id (:community-id id) + :switcher-card {:type shell.constants/community-card + :card-id (:community-id id) + :clock now + :screen-id (:community-id id)}} nil)) +(rf/defn add-switcher-card + {:events [:shell/add-switcher-card]} + [{:keys [db now] :as cofx} view-id id] + (let [card-data (calculate-card-data db now view-id id) + switcher-card (:switcher-card card-data)] + (when card-data + (rf/merge + cofx + {:db (assoc-in + db + [:shell/switcher-cards (:card-id card-data)] + switcher-card) + :shell/navigate-from-shell-fx (:navigate-from card-data)} + (switcher-cards-store/upsert-switcher-card-rpc switcher-card))))) + (rf/defn close-switcher-card {:events [:shell/close-switcher-card]} - [{:keys [db]} id] - {:db (update-in db [:shell/switcher-cards] dissoc id)}) + [{:keys [db] :as cofx} card-id] + (rf/merge + cofx + {:db (update db :shell/switcher-cards dissoc card-id)} + (switcher-cards-store/delete-switcher-card-rpc card-id))) (rf/defn navigate-to-jump-to {:events [:shell/navigate-to-jump-to]} diff --git a/src/status_im2/contexts/shell/view.cljs b/src/status_im2/contexts/shell/view.cljs index bb65f591a6..3630bd4615 100644 --- a/src/status_im2/contexts/shell/view.cljs +++ b/src/status_im2/contexts/shell/view.cljs @@ -47,19 +47,19 @@ (i18n/label :t/jump-to)]) (defn render-card - [{:keys [id type channel-id] :as card}] + [{:keys [type screen-id] :as card}] (let [card-data (case type shell.constants/one-to-one-chat-card - (rf/sub [:shell/one-to-one-chat-card id]) + (rf/sub [:shell/one-to-one-chat-card screen-id]) shell.constants/private-group-chat-card - (rf/sub [:shell/private-group-chat-card id]) + (rf/sub [:shell/private-group-chat-card screen-id]) shell.constants/community-card - (rf/sub [:shell/community-card id]) + (rf/sub [:shell/community-card screen-id]) shell.constants/community-channel-card - (rf/sub [:shell/community-channel-card channel-id]) + (rf/sub [:shell/community-channel-card screen-id]) nil)] [switcher-cards/card (merge card card-data)])) diff --git a/status-go-version.json b/status-go-version.json index 938093d16c..bb3f832218 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "d43e06f4c27a900641cd55c2a46002e6f0909c95", - "commit-sha1": "d43e06f4c27a900641cd55c2a46002e6f0909c95", - "src-sha256": "18n5h3yx6wxb5l1nvra868dhnyl732zvpdn3mqg4zfsjxmx82np7" + "version": "v0.117.3", + "commit-sha1": "d40290a649133eb7b7f450b5c5b74eec28ba232d", + "src-sha256": "140j0gbp8nxzncya9mcpvlxnax5ajfl8c32ih20b29n8j525gw66" }