Compare commits

...
Author SHA1 Message Date
Volodymyr Kozieiev 09e922fd05 fx namespaces removed in favor of utils.re-frame 2022-12-16 15:03:55 +00:00
143 changed files with 1935 additions and 2121 deletions
+6 -6
View File
@@ -6,7 +6,7 @@
[status-im.add-new.db :as db] [status-im.add-new.db :as db]
[status-im.utils.random :as random] [status-im.utils.random :as random]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.chat.models :as chat] [status-im.chat.models :as chat]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.contact.core :as contact] [status-im.contact.core :as contact]
@@ -24,7 +24,7 @@
;;NOTE we want to handle only last resolve ;;NOTE we want to handle only last resolve
(def resolve-last-id (atom nil)) (def resolve-last-id (atom nil))
(fx/defn new-chat-set-new-identity (rf/defn new-chat-set-new-identity
{:events [:new-chat/set-new-identity]} {:events [:new-chat/set-new-identity]}
[{db :db} new-identity-raw new-ens-name id] [{db :db} new-identity-raw new-ens-name id]
(let [ens-error (and (= new-identity-raw "0x") (not (string/blank? new-ens-name)))] (let [ens-error (and (= new-identity-raw "0x") (not (string/blank? new-ens-name)))]
@@ -61,12 +61,12 @@
new-identity new-identity
@resolve-last-id])}}))))))) @resolve-last-id])}})))))))
(fx/defn clear-new-identity (rf/defn clear-new-identity
{:events [::clear-new-identity ::new-chat-focus]} {:events [::clear-new-identity ::new-chat-focus]}
[{:keys [db]}] [{:keys [db]}]
{:db (dissoc db :contacts/new-identity)}) {:db (dissoc db :contacts/new-identity)})
(fx/defn qr-code-handled (rf/defn qr-code-handled
{:events [::qr-code-handled]} {:events [::qr-code-handled]}
[{:keys [db] :as cofx} {:keys [type public-key chat-id data ens-name]} {:keys [new-contact? nickname] :as opts}] [{:keys [db] :as cofx} {:keys [type public-key chat-id data ens-name]} {:keys [new-contact? nickname] :as opts}]
(let [public-key? (and (string? data) (let [public-key? (and (string? data)
@@ -79,7 +79,7 @@
validation-result (db/validate-pub-key db chat-key)] validation-result (db/validate-pub-key db chat-key)]
(if-not validation-result (if-not validation-result
(if new-contact? (if new-contact?
(fx/merge cofx (rf/merge cofx
(contact/add-contact chat-key nickname ens-name) (contact/add-contact chat-key nickname ens-name)
(navigation/navigate-to-cofx :contacts-list {})) (navigation/navigate-to-cofx :contacts-list {}))
(chat/start-chat cofx chat-key ens-name)) (chat/start-chat cofx chat-key ens-name))
@@ -91,7 +91,7 @@
(i18n/label :t/can-not-add-yourself)) (i18n/label :t/can-not-add-yourself))
:on-dismiss #(re-frame/dispatch [:pop-to-root-tab :chat-stack])}}))) :on-dismiss #(re-frame/dispatch [:pop-to-root-tab :chat-stack])}})))
(fx/defn qr-code-scanned (rf/defn qr-code-scanned
{:events [:contact/qr-code-scanned]} {:events [:contact/qr-code-scanned]}
[{:keys [db]} data opts] [{:keys [db]} data opts]
{::router/handle-uri {:chain (ethereum/chain-keyword db) {::router/handle-uri {:chain (ethereum/chain-keyword db)
+4 -4
View File
@@ -2,19 +2,19 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx])) [utils.re-frame :as rf]))
(fx/defn handle-backup-failed (rf/defn handle-backup-failed
{:events [::backup-failed]} {:events [::backup-failed]}
[{:keys [db]}] [{:keys [db]}]
{:db (dissoc db :backup/performing-backup)}) {:db (dissoc db :backup/performing-backup)})
(fx/defn handle-backup-perfomed (rf/defn handle-backup-perfomed
{:events [::backup-performed]} {:events [::backup-performed]}
[{:keys [db]}] [{:keys [db]}]
{:db (dissoc db :backup/performing-backup)}) {:db (dissoc db :backup/performing-backup)})
(fx/defn handle-perform-backup-pressed (rf/defn handle-perform-backup-pressed
{:events [:multiaccounts.ui/perform-backup-pressed]} {:events [:multiaccounts.ui/perform-backup-pressed]}
[{:keys [db]}] [{:keys [db]}]
{:db (assoc db :backup/performing-backup true) {:db (assoc db :backup/performing-backup true)
+14 -14
View File
@@ -4,7 +4,7 @@
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.fx :as fx])) [utils.re-frame :as rf]))
(def address-regex #"enode://[a-zA-Z0-9]+:?(.*)\@\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b:(\d{1,5})") (def address-regex #"enode://[a-zA-Z0-9]+:?(.*)\@\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b:(\d{1,5})")
@@ -17,11 +17,11 @@
:id (string/replace id "-" "") :id (string/replace id "-" "")
:name bootnode-name}) :name bootnode-name})
(fx/defn fetch [cofx id] (rf/defn fetch [cofx id]
(let [network (get-in cofx [:db :networks/current-network])] (let [network (get-in cofx [:db :networks/current-network])]
(get-in cofx [:db :multiaccount :custom-bootnodes network id]))) (get-in cofx [:db :multiaccount :custom-bootnodes network id])))
(fx/defn set-input (rf/defn set-input
{:events [:bootnodes.ui/input-changed]} {:events [:bootnodes.ui/input-changed]}
[{:keys [db]} input-key value] [{:keys [db]} input-key value]
{:db (update {:db (update
@@ -35,13 +35,13 @@
:name (string/blank? value) :name (string/blank? value)
:url (not (valid-address? value)))})}) :url (not (valid-address? value)))})})
(fx/defn edit (rf/defn edit
{:events [:bootnodes.ui/add-bootnode-pressed]} {:events [:bootnodes.ui/add-bootnode-pressed]}
[{:keys [db] :as cofx} id] [{:keys [db] :as cofx} id]
(let [{:keys [id (let [{:keys [id
address address
name]} (fetch cofx id) name]} (fetch cofx id)
fxs (fx/merge cofx fxs (rf/merge cofx
(set-input :id id) (set-input :id id)
(set-input :url (str address)) (set-input :url (str address))
(set-input :name (str name)))] (set-input :name (str name)))]
@@ -52,17 +52,17 @@
(let [network (:networks/current-network db)] (let [network (:networks/current-network db)]
(get-in db [:multiaccount :custom-bootnodes-enabled? network]))) (get-in db [:multiaccount :custom-bootnodes-enabled? network])))
(fx/defn delete [{{:keys [multiaccount] :as db} :db :as cofx} id] (rf/defn delete [{{:keys [multiaccount] :as db} :db :as cofx} id]
(let [network (:networks/current-network db) (let [network (:networks/current-network db)
new-multiaccount (update-in multiaccount [:custom-bootnodes network] dissoc id)] new-multiaccount (update-in multiaccount [:custom-bootnodes network] dissoc id)]
(fx/merge cofx (rf/merge cofx
{:db (assoc db :multiaccount new-multiaccount)} {:db (assoc db :multiaccount new-multiaccount)}
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:custom-bootnodes (:custom-bootnodes new-multiaccount) :custom-bootnodes (:custom-bootnodes new-multiaccount)
{:success-event (when (custom-bootnodes-in-use? cofx) {:success-event (when (custom-bootnodes-in-use? cofx)
[:multiaccounts.update.callback/save-settings-success])})))) [:multiaccounts.update.callback/save-settings-success])}))))
(fx/defn upsert (rf/defn upsert
{:events [:bootnodes.ui/save-pressed] {:events [:bootnodes.ui/save-pressed]
:interceptors [(re-frame/inject-cofx :random-id-generator)]} :interceptors [(re-frame/inject-cofx :random-id-generator)]}
[{{:bootnodes/keys [manage] :keys [multiaccount] :as db} :db [{{:bootnodes/keys [manage] :keys [multiaccount] :as db} :db
@@ -79,7 +79,7 @@
[network (:id bootnode)] [network (:id bootnode)]
bootnode)] bootnode)]
(fx/merge cofx (rf/merge cofx
{:db (dissoc db :bootnodes/manage) {:db (dissoc db :bootnodes/manage)
:dispatch [:navigate-back]} :dispatch [:navigate-back]}
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
@@ -87,7 +87,7 @@
{:success-event (when (custom-bootnodes-in-use? cofx) {:success-event (when (custom-bootnodes-in-use? cofx)
[:multiaccounts.update.callback/save-settings-success])})))) [:multiaccounts.update.callback/save-settings-success])}))))
(fx/defn toggle-custom-bootnodes (rf/defn toggle-custom-bootnodes
{:events [:bootnodes.ui/custom-bootnodes-switch-toggled]} {:events [:bootnodes.ui/custom-bootnodes-switch-toggled]}
[{:keys [db] :as cofx} value] [{:keys [db] :as cofx} value]
(let [current-network (:networks/current-network db) (let [current-network (:networks/current-network db)
@@ -97,13 +97,13 @@
:custom-bootnodes-enabled? (assoc bootnodes-settings current-network value) :custom-bootnodes-enabled? (assoc bootnodes-settings current-network value)
{:success-event [:multiaccounts.update.callback/save-settings-success]}))) {:success-event [:multiaccounts.update.callback/save-settings-success]})))
(fx/defn set-bootnodes-from-qr (rf/defn set-bootnodes-from-qr
{:events [:bootnodes.callback/qr-code-scanned]} {:events [:bootnodes.callback/qr-code-scanned]}
[cofx url] [cofx url]
(assoc (set-input cofx :url (string/trim url)) (assoc (set-input cofx :url (string/trim url))
:dispatch [:navigate-back])) :dispatch [:navigate-back]))
(fx/defn show-delete-bootnode-confirmation (rf/defn show-delete-bootnode-confirmation
{:events [:bootnodes.ui/delete-pressed]} {:events [:bootnodes.ui/delete-pressed]}
[_ bootnode-id] [_ bootnode-id]
{:ui/show-confirmation {:title (i18n/label :t/delete-bootnode-title) {:ui/show-confirmation {:title (i18n/label :t/delete-bootnode-title)
@@ -111,9 +111,9 @@
:confirm-button-text (i18n/label :t/delete-bootnode) :confirm-button-text (i18n/label :t/delete-bootnode)
:on-accept #(re-frame/dispatch [:bootnodes.ui/delete-confirmed bootnode-id])}}) :on-accept #(re-frame/dispatch [:bootnodes.ui/delete-confirmed bootnode-id])}})
(fx/defn delete-bootnode (rf/defn delete-bootnode
{:events [:bootnodes.ui/delete-confirmed]} {:events [:bootnodes.ui/delete-confirmed]}
[cofx bootnode-id] [cofx bootnode-id]
(fx/merge cofx (rf/merge cofx
(delete bootnode-id) (delete bootnode-id)
(navigation/navigate-back))) (navigation/navigate-back)))
+4 -4
View File
@@ -1,7 +1,7 @@
(ns status-im.bottom-sheet.core (ns status-im.bottom-sheet.core
(:require [status-im.utils.fx :as fx])) (:require [utils.re-frame :as rf]))
(fx/defn show-bottom-sheet (rf/defn show-bottom-sheet
[{:keys [db]} {:keys [view options]}] [{:keys [db]} {:keys [view options]}]
{:show-bottom-sheet nil {:show-bottom-sheet nil
:db (assoc db :db (assoc db
@@ -9,7 +9,7 @@
:bottom-sheet/view view :bottom-sheet/view view
:bottom-sheet/options options)}) :bottom-sheet/options options)})
(fx/defn show-bottom-sheet-event (rf/defn show-bottom-sheet-event
{:events [:bottom-sheet/show-sheet]} {:events [:bottom-sheet/show-sheet]}
[cofx view options] [cofx view options]
(show-bottom-sheet (show-bottom-sheet
@@ -17,7 +17,7 @@
{:view view {:view view
:options options})) :options options}))
(fx/defn hide-bottom-sheet (rf/defn hide-bottom-sheet
{:events [:bottom-sheet/hide]} {:events [:bottom-sheet/hide]}
[{:keys [db]}] [{:keys [db]}]
{:hide-bottom-sheet nil {:hide-bottom-sheet nil
+56 -56
View File
@@ -10,7 +10,7 @@
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.ui.components.list-selection :as list-selection] [status-im.ui.components.list-selection :as list-selection]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.http :as http] [status-im.utils.http :as http]
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[status-im.utils.random :as random] [status-im.utils.random :as random]
@@ -26,11 +26,11 @@
[status-im.browser.eip3085 :as eip3085] [status-im.browser.eip3085 :as eip3085]
[status-im.browser.eip3326 :as eip3326])) [status-im.browser.eip3326 :as eip3326]))
(fx/defn update-browser-option (rf/defn update-browser-option
[{:keys [db]} option-key option-value] [{:keys [db]} option-key option-value]
{:db (assoc-in db [:browser/options option-key] option-value)}) {:db (assoc-in db [:browser/options option-key] option-value)})
(fx/defn update-browser-options (rf/defn update-browser-options
[{:keys [db]} options] [{:keys [db]} options]
{:db (update db :browser/options merge options)}) {:db (update db :browser/options merge options)})
@@ -48,7 +48,7 @@
(when url (when url
(string/starts-with? url "https://"))))) (string/starts-with? url "https://")))))
(fx/defn remove-browser (rf/defn remove-browser
{:events [:browser.ui/remove-browser-pressed]} {:events [:browser.ui/remove-browser-pressed]}
[{:keys [db]} browser-id] [{:keys [db]} browser-id]
{:db (update-in db [:browser/browsers] dissoc browser-id) {:db (update-in db [:browser/browsers] dissoc browser-id)
@@ -56,7 +56,7 @@
:params [browser-id] :params [browser-id]
:on-success #()}]}) :on-success #()}]})
(fx/defn clear-all-browsers (rf/defn clear-all-browsers
{:events [:browser.ui/clear-all-browsers-pressed]} {:events [:browser.ui/clear-all-browsers-pressed]}
[{:keys [db]}] [{:keys [db]}]
{:db (dissoc db :browser/browsers) {:db (dissoc db :browser/browsers)
@@ -77,7 +77,7 @@
(re-frame/dispatch [:browser.callback/resolve-ens-multihash-success url]) (re-frame/dispatch [:browser.callback/resolve-ens-multihash-success url])
(re-frame/dispatch [:browser.callback/resolve-ens-multihash-error]))) (re-frame/dispatch [:browser.callback/resolve-ens-multihash-error])))
(fx/defn resolve-url (rf/defn resolve-url
[{:keys [db]} {:keys [error? resolved-url]}] [{:keys [db]} {:keys [error? resolved-url]}]
(when (not error?) (when (not error?)
(let [current-url (get-current-url (get-current-browser db)) (let [current-url (get-current-url (get-current-browser db))
@@ -89,7 +89,7 @@
:cb resolve-ens-contenthash-callback}} :cb resolve-ens-contenthash-callback}}
{:db (update db :browser/options assoc :url (or resolved-url current-url) :resolving? false)})))) {:db (update db :browser/options assoc :url (or resolved-url current-url) :resolving? false)}))))
(fx/defn update-browser (rf/defn update-browser
[{:keys [db]} [{:keys [db]}
{:keys [browser-id] :as browser}] {:keys [browser-id] :as browser}]
(let [updated-browser (-> browser (let [updated-browser (-> browser
@@ -102,7 +102,7 @@
:params [(select-keys updated-browser [:browser-id :timestamp :name :dapp? :history :history-index])] :params [(select-keys updated-browser [:browser-id :timestamp :name :dapp? :history :history-index])]
:on-success #()}]})) :on-success #()}]}))
(fx/defn store-bookmark (rf/defn store-bookmark
{:events [:browser/store-bookmark]} {:events [:browser/store-bookmark]}
[{:keys [db]} [{:keys [db]}
{:keys [url] :as bookmark}] {:keys [url] :as bookmark}]
@@ -111,24 +111,24 @@
:params [bookmark] :params [bookmark]
:on-success #()}]}) :on-success #()}]})
(fx/defn update-bookmark (rf/defn update-bookmark
{:events [:browser/update-bookmark]} {:events [:browser/update-bookmark]}
[{:keys [db] :as cofx} [{:keys [db] :as cofx}
{:keys [url] :as bookmark}] {:keys [url] :as bookmark}]
(let [old-bookmark (get-in db [:bookmarks/bookmarks url]) (let [old-bookmark (get-in db [:bookmarks/bookmarks url])
new-bookmark (merge old-bookmark bookmark)] new-bookmark (merge old-bookmark bookmark)]
(fx/merge cofx {:db (assoc-in db [:bookmarks/bookmarks url] new-bookmark) (rf/merge cofx {:db (assoc-in db [:bookmarks/bookmarks url] new-bookmark)
::json-rpc/call [{:method "wakuext_updateBookmark" ::json-rpc/call [{:method "wakuext_updateBookmark"
:params [url bookmark] :params [url bookmark]
:on-success #()}]}))) :on-success #()}]})))
(fx/defn delete-bookmark (rf/defn delete-bookmark
{:events [:browser/delete-bookmark]} {:events [:browser/delete-bookmark]}
[{:keys [db] :as cofx} [{:keys [db] :as cofx}
url] url]
(let [old-bookmark (get-in db [:bookmarks/bookmarks url]) (let [old-bookmark (get-in db [:bookmarks/bookmarks url])
removed-bookmark (merge old-bookmark {:removed true})] removed-bookmark (merge old-bookmark {:removed true})]
(fx/merge cofx {:db (update db :bookmarks/bookmarks dissoc url) (rf/merge cofx {:db (update db :bookmarks/bookmarks dissoc url)
::json-rpc/call [{:method "wakuext_removeBookmark" ::json-rpc/call [{:method "wakuext_removeBookmark"
:params [url] :params [url]
:on-success #()}]}))) :on-success #()}]})))
@@ -136,16 +136,16 @@
(defn can-go-back? [{:keys [history-index]}] (defn can-go-back? [{:keys [history-index]}]
(pos? history-index)) (pos? history-index))
(fx/defn navigate-to-previous-page (rf/defn navigate-to-previous-page
{:events [:browser.ui/previous-page-button-pressed]} {:events [:browser.ui/previous-page-button-pressed]}
[cofx] [cofx]
(let [{:keys [history-index] :as browser} (get-current-browser (:db cofx))] (let [{:keys [history-index] :as browser} (get-current-browser (:db cofx))]
(when (can-go-back? browser) (when (can-go-back? browser)
(fx/merge cofx (rf/merge cofx
(update-browser (assoc browser :history-index (dec history-index))) (update-browser (assoc browser :history-index (dec history-index)))
(resolve-url nil))))) (resolve-url nil)))))
(fx/defn ignore-unsafe (rf/defn ignore-unsafe
{:events [:browser/ignore-unsafe]} {:events [:browser/ignore-unsafe]}
[cofx] [cofx]
(let [browser (get-current-browser (:db cofx)) (let [browser (get-current-browser (:db cofx))
@@ -155,16 +155,16 @@
(defn can-go-forward? [{:keys [history-index history]}] (defn can-go-forward? [{:keys [history-index history]}]
(< history-index (dec (count history)))) (< history-index (dec (count history))))
(fx/defn navigate-to-next-page (rf/defn navigate-to-next-page
{:events [:browser.ui/next-page-button-pressed]} {:events [:browser.ui/next-page-button-pressed]}
[cofx] [cofx]
(let [{:keys [history-index] :as browser} (get-current-browser (:db cofx))] (let [{:keys [history-index] :as browser} (get-current-browser (:db cofx))]
(when (can-go-forward? browser) (when (can-go-forward? browser)
(fx/merge cofx (rf/merge cofx
(update-browser (assoc browser :history-index (inc history-index))) (update-browser (assoc browser :history-index (inc history-index)))
(resolve-url nil))))) (resolve-url nil)))))
(fx/defn update-browser-history (rf/defn update-browser-history
[cofx browser url] [cofx browser url]
(let [history-index (:history-index browser) (let [history-index (:history-index browser)
history (:history browser)] history (:history browser)]
@@ -176,47 +176,47 @@
:history new-history :history new-history
:history-index new-index)))))) :history-index new-index))))))
(fx/defn resolve-ens-multihash-success (rf/defn resolve-ens-multihash-success
{:events [:browser.callback/resolve-ens-multihash-success]} {:events [:browser.callback/resolve-ens-multihash-success]}
[{:keys [db] :as cofx} url] [{:keys [db] :as cofx} url]
(let [current-url (get-current-url (get-current-browser db)) (let [current-url (get-current-url (get-current-browser db))
host (http/url-host current-url) host (http/url-host current-url)
path (subs current-url (+ (.indexOf ^js current-url host) (count host))) path (subs current-url (+ (.indexOf ^js current-url host) (count host)))
gateway url] gateway url]
(fx/merge cofx (rf/merge cofx
{:db (-> (update db :browser/options {:db (-> (update db :browser/options
assoc assoc
:url (str gateway path) :url (str gateway path)
:resolving? false) :resolving? false)
(assoc-in [:browser/options :resolved-ens host] gateway))}))) (assoc-in [:browser/options :resolved-ens host] gateway))})))
(fx/defn resolve-ens-multihash-error (rf/defn resolve-ens-multihash-error
{:events [:browser.callback/resolve-ens-multihash-error]} {:events [:browser.callback/resolve-ens-multihash-error]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(update-browser-options cofx {:url (get-current-url (get-current-browser db)) (update-browser-options cofx {:url (get-current-url (get-current-browser db))
:resolving? false :resolving? false
:error? true})) :error? true}))
(fx/defn handle-browser-error (rf/defn handle-browser-error
{:events [:browser/error-occured]} {:events [:browser/error-occured]}
[cofx] [cofx]
(fx/merge cofx (rf/merge cofx
(update-browser-option :error? true) (update-browser-option :error? true)
(update-browser-option :loading? false))) (update-browser-option :loading? false)))
(fx/defn handle-pdf (rf/defn handle-pdf
[_ url] [_ url]
(when (and platform/android? (string/ends-with? url ".pdf")) (when (and platform/android? (string/ends-with? url ".pdf"))
{:browser/show-web-browser-selection url})) {:browser/show-web-browser-selection url}))
(fx/defn handle-message-link (rf/defn handle-message-link
{:events [:browser.ui/message-link-pressed]} {:events [:browser.ui/message-link-pressed]}
[_ link] [_ link]
(if (links/universal-link? link) (if (links/universal-link? link)
{:dispatch [:universal-links/handle-url link]} {:dispatch [:universal-links/handle-url link]}
{:browser/show-browser-selection link})) {:browser/show-browser-selection link}))
(fx/defn update-browser-on-nav-change (rf/defn update-browser-on-nav-change
[cofx url error?] [cofx url error?]
(let [browser (get-current-browser (:db cofx)) (let [browser (get-current-browser (:db cofx))
options (get-in cofx [:db :browser/options]) options (get-in cofx [:db :browser/options])
@@ -228,18 +228,18 @@
resolved-url (if resolved-ens resolved-url (if resolved-ens
(http/normalize-url (string/replace url (second resolved-ens) (first resolved-ens))) (http/normalize-url (string/replace url (second resolved-ens) (first resolved-ens)))
url)] url)]
(fx/merge cofx (rf/merge cofx
(update-browser-history browser resolved-url) (update-browser-history browser resolved-url)
(handle-pdf url) (handle-pdf url)
(resolve-url {:error? error? :resolved-url (when resolved-ens url)})))))) (resolve-url {:error? error? :resolved-url (when resolved-ens url)}))))))
(fx/defn update-browser-name (rf/defn update-browser-name
[cofx title] [cofx title]
(let [browser (get-current-browser (:db cofx))] (let [browser (get-current-browser (:db cofx))]
(when (and browser (not (:dapp? browser)) title (not (string/blank? title))) (when (and browser (not (:dapp? browser)) title (not (string/blank? title)))
(update-browser cofx (assoc browser :name title))))) (update-browser cofx (assoc browser :name title)))))
(fx/defn navigation-state-changed (rf/defn navigation-state-changed
{:events [:browser/navigation-state-changed]} {:events [:browser/navigation-state-changed]}
[cofx event error?] [cofx event error?]
(let [{:strs [url loading title]} (js->clj event) (let [{:strs [url loading title]} (js->clj event)
@@ -247,12 +247,12 @@
(if (links/universal-link? url) (if (links/universal-link? url)
(when-not (and deep-link? platform/ios?) ;; ios webview handles this (when-not (and deep-link? platform/ios?) ;; ios webview handles this
{:dispatch [:universal-links/handle-url url]}) {:dispatch [:universal-links/handle-url url]})
(fx/merge cofx (rf/merge cofx
(update-browser-option :loading? loading) (update-browser-option :loading? loading)
(update-browser-name title) (update-browser-name title)
(update-browser-on-nav-change url error?))))) (update-browser-on-nav-change url error?)))))
(fx/defn open-url-in-current-browser (rf/defn open-url-in-current-browser
"Opens a url in the current browser, which mean no new entry is added to the home page "Opens a url in the current browser, which mean no new entry is added to the home page
and history of the current browser is updated so that the user can navigate back to the and history of the current browser is updated so that the user can navigate back to the
origin url" origin url"
@@ -262,12 +262,12 @@
normalized-url (http/normalize-and-decode-url url)] normalized-url (http/normalize-and-decode-url url)]
(if (links/universal-link? normalized-url) (if (links/universal-link? normalized-url)
{:dispatch [:universal-links/handle-url normalized-url]} {:dispatch [:universal-links/handle-url normalized-url]}
(fx/merge cofx (rf/merge cofx
(update-browser-option :url-editing? false) (update-browser-option :url-editing? false)
(update-browser-history browser normalized-url) (update-browser-history browser normalized-url)
(resolve-url nil))))) (resolve-url nil)))))
(fx/defn open-url (rf/defn open-url
"Opens a url in the browser. If a host can be extracted from the url and "Opens a url in the browser. If a host can be extracted from the url and
there is already a browser for this host, this browser is reused there is already a browser for this host, this browser is reused
If the browser is reused, the history is flushed" If the browser is reused, the history is flushed"
@@ -279,7 +279,7 @@
:history [normalized-url]}] :history [normalized-url]}]
(if (links/universal-link? normalized-url) (if (links/universal-link? normalized-url)
{:dispatch [:universal-links/handle-url normalized-url]} {:dispatch [:universal-links/handle-url normalized-url]}
(fx/merge cofx (rf/merge cofx
{:db (assoc db :browser/options {:db (assoc db :browser/options
{:browser-id (:browser-id browser)})} {:browser-id (:browser-id browser)})}
(navigation/change-tab :browser) (navigation/change-tab :browser)
@@ -287,19 +287,19 @@
(update-browser browser) (update-browser browser)
(resolve-url nil))))) (resolve-url nil)))))
(fx/defn open-existing-browser (rf/defn open-existing-browser
"Opens an existing browser with it's history" "Opens an existing browser with it's history"
{:events [:browser.ui/browser-item-selected]} {:events [:browser.ui/browser-item-selected]}
[{:keys [db] :as cofx} browser-id] [{:keys [db] :as cofx} browser-id]
(let [browser (get-in db [:browser/browsers browser-id])] (let [browser (get-in db [:browser/browsers browser-id])]
(fx/merge cofx (rf/merge cofx
{:db (assoc db :browser/options {:db (assoc db :browser/options
{:browser-id browser-id})} {:browser-id browser-id})}
(update-browser browser) (update-browser browser)
(navigation/set-stack-root :browser-stack :browser) (navigation/set-stack-root :browser-stack :browser)
(resolve-url nil)))) (resolve-url nil))))
(fx/defn web3-error-callback (rf/defn web3-error-callback
{:events [:browser.dapp/transaction-on-error]} {:events [:browser.dapp/transaction-on-error]}
[_ message-id message] [_ message-id message]
{:browser/send-to-bridge {:browser/send-to-bridge
@@ -307,7 +307,7 @@
:messageId message-id :messageId message-id
:error message}}) :error message}})
(fx/defn dapp-complete-transaction (rf/defn dapp-complete-transaction
{:events [:browser.dapp/transaction-on-result]} {:events [:browser.dapp/transaction-on-result]}
[_ message-id id result] [_ message-id id result]
;;TODO check and test id ;;TODO check and test id
@@ -336,7 +336,7 @@
(ethereum/address? second-param) (ethereum/address? second-param)
[second-param (if typed? first-param (normalize-message first-param))])))) [second-param (if typed? first-param (normalize-message first-param))]))))
(fx/defn send-to-bridge (rf/defn send-to-bridge
{:events [:browser.callback/call-rpc]} {:events [:browser.callback/call-rpc]}
[_ message] [_ message]
{:browser/send-to-bridge message}) {:browser/send-to-bridge message})
@@ -346,7 +346,7 @@
constants/web3-personal-sign constants/web3-personal-sign
constants/web3-eth-sign constants/web3-keycard-sign-typed-data} method)) constants/web3-eth-sign constants/web3-keycard-sign-typed-data} method))
(fx/defn web3-send-async (rf/defn web3-send-async
[cofx dapp-name {:keys [method params id] :as payload} message-id] [cofx dapp-name {:keys [method params id] :as payload} message-id]
(let [message? (web3-sign-message? method) (let [message? (web3-sign-message? method)
dapps-address (get-in cofx [:db :multiaccount :dapps-address]) dapps-address (get-in cofx [:db :multiaccount :dapps-address])
@@ -401,7 +401,7 @@
:error %1 :error %1
:result %2}])]})))) :result %2}])]}))))
(fx/defn handle-no-permissions [cofx {:keys [method id]} message-id] (rf/defn handle-no-permissions [cofx {:keys [method id]} message-id]
(if (= method "eth_accounts") (if (= method "eth_accounts")
;; eth_accounts returns empty array for compatibility with meta-mask ;; eth_accounts returns empty array for compatibility with meta-mask
(send-to-bridge cofx (send-to-bridge cofx
@@ -425,28 +425,28 @@
(and (permissioned-method method) (and (permissioned-method method)
(not (some #{constants/dapp-permission-web3} (get-in permissions [dapp-name :permissions])))))) (not (some #{constants/dapp-permission-web3} (get-in permissions [dapp-name :permissions]))))))
(fx/defn web3-send-async-read-only (rf/defn web3-send-async-read-only
[{:keys [db] :as cofx} dapp-name {:keys [method] :as payload} message-id] [{:keys [db] :as cofx} dapp-name {:keys [method] :as payload} message-id]
(if (has-permissions? db dapp-name method) (if (has-permissions? db dapp-name method)
(handle-no-permissions cofx payload message-id) (handle-no-permissions cofx payload message-id)
(web3-send-async cofx dapp-name payload message-id))) (web3-send-async cofx dapp-name payload message-id)))
(fx/defn handle-scanned-qr-code (rf/defn handle-scanned-qr-code
{:events [:browser.bridge.callback/qr-code-scanned]} {:events [:browser.bridge.callback/qr-code-scanned]}
[cofx data {{:keys [dapp-name permission message-id]} :data}] [cofx data {{:keys [dapp-name permission message-id]} :data}]
(fx/merge (assoc-in cofx [:db :browser/options :yielding-control?] false) (rf/merge (assoc-in cofx [:db :browser/options :yielding-control?] false)
(browser.permissions/send-response-to-bridge permission message-id true data) (browser.permissions/send-response-to-bridge permission message-id true data)
(browser.permissions/process-next-permission dapp-name) (browser.permissions/process-next-permission dapp-name)
(navigation/navigate-back))) (navigation/navigate-back)))
(fx/defn handle-canceled-qr-code (rf/defn handle-canceled-qr-code
{:events [:browser.bridge.callback/qr-code-canceled]} {:events [:browser.bridge.callback/qr-code-canceled]}
[cofx {{:keys [dapp-name permission message-id]} :data}] [cofx {{:keys [dapp-name permission message-id]} :data}]
(fx/merge (assoc-in cofx [:db :browser/options :yielding-control?] false) (rf/merge (assoc-in cofx [:db :browser/options :yielding-control?] false)
(browser.permissions/send-response-to-bridge permission message-id true nil) (browser.permissions/send-response-to-bridge permission message-id true nil)
(browser.permissions/process-next-permission dapp-name))) (browser.permissions/process-next-permission dapp-name)))
(fx/defn process-bridge-message (rf/defn process-bridge-message
{:events [:browser/bridge-message-received]} {:events [:browser/bridge-message-received]}
[{:keys [db] :as cofx} message] [{:keys [db] :as cofx} message]
(let [browser (get-current-browser db) (let [browser (get-current-browser db)
@@ -513,10 +513,10 @@
message (i18n/label :t/share-dapp-text {:link link})] message (i18n/label :t/share-dapp-text {:link link})]
(list-selection/open-share {:message message}))) (list-selection/open-share {:message message})))
(fx/defn dapps-account-selected (rf/defn dapps-account-selected
{:events [:dapps-account-selected]} {:events [:dapps-account-selected]}
[{:keys [db] :as cofx} address] [{:keys [db] :as cofx} address]
(fx/merge cofx (rf/merge cofx
{:browser/clear-web-data nil} {:browser/clear-web-data nil}
(bottom-sheet/hide-bottom-sheet) (bottom-sheet/hide-bottom-sheet)
(browser.permissions/clear-dapps-permissions) (browser.permissions/clear-dapps-permissions)
@@ -525,38 +525,38 @@
(merge (navigation/navigate-back %) (merge (navigation/navigate-back %)
{:dispatch [:browser.ui/browser-item-selected (get-in db [:browser/options :browser-id])]})))) {:dispatch [:browser.ui/browser-item-selected (get-in db [:browser/options :browser-id])]}))))
(fx/defn open-empty-tab (rf/defn open-empty-tab
{:events [:browser.ui/open-empty-tab]} {:events [:browser.ui/open-empty-tab]}
[cofx] [cofx]
(debounce/clear :browser/navigation-state-changed) (debounce/clear :browser/navigation-state-changed)
(navigation/set-stack-root cofx :browser-stack :empty-tab)) (navigation/set-stack-root cofx :browser-stack :empty-tab))
(fx/defn url-input-pressed (rf/defn url-input-pressed
{:events [:browser.ui/url-input-pressed]} {:events [:browser.ui/url-input-pressed]}
[cofx _] [cofx _]
(update-browser-option cofx :url-editing? true)) (update-browser-option cofx :url-editing? true))
(fx/defn url-input-blured (rf/defn url-input-blured
{:events [:browser.ui/url-input-blured]} {:events [:browser.ui/url-input-blured]}
[cofx] [cofx]
(update-browser-option cofx :url-editing? false)) (update-browser-option cofx :url-editing? false))
(fx/defn lock-pressed (rf/defn lock-pressed
{:events [:browser.ui/lock-pressed]} {:events [:browser.ui/lock-pressed]}
[cofx secure?] [cofx secure?]
(update-browser-option cofx :show-tooltip (if secure? :secure :not-secure))) (update-browser-option cofx :show-tooltip (if secure? :secure :not-secure)))
(fx/defn close-tooltip-pressed (rf/defn close-tooltip-pressed
{:events [:browser.ui/close-tooltip-pressed]} {:events [:browser.ui/close-tooltip-pressed]}
[cofx] [cofx]
(update-browser-option cofx :show-tooltip nil)) (update-browser-option cofx :show-tooltip nil))
(fx/defn loading-started (rf/defn loading-started
{:events [:browser/loading-started]} {:events [:browser/loading-started]}
[cofx] [cofx]
(update-browser-options cofx {:error? false :loading? true})) (update-browser-options cofx {:error? false :loading? true}))
(fx/defn handle-bookmarks (rf/defn handle-bookmarks
[{:keys [db]} bookmarks] [{:keys [db]} bookmarks]
(let [changed-bookmarks (reduce (fn [acc {:keys [url] :as bookmark}] (let [changed-bookmarks (reduce (fn [acc {:keys [url] :as bookmark}]
(assoc acc url bookmark)) (assoc acc url bookmark))
+5 -5
View File
@@ -3,14 +3,14 @@
(:require [status-im.constants :as constants] (:require [status-im.constants :as constants]
[clojure.string :as string] [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.network.core :as network] [status-im.network.core :as network]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.utils.random :as random] [status-im.utils.random :as random]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.ui.screens.browser.eip3085.sheet :as sheet])) [status-im.ui.screens.browser.eip3085.sheet :as sheet]))
(fx/defn send-success-call-to-bridge (rf/defn send-success-call-to-bridge
{:events [:eip3085/send-success-call-to-bridge]} {:events [:eip3085/send-success-call-to-bridge]}
[_ id messageId] [_ id messageId]
{:browser/send-to-bridge {:type constants/web3-send-async-callback {:browser/send-to-bridge {:type constants/web3-send-async-callback
@@ -19,7 +19,7 @@
:id (int id) :id (int id)
:result nil}}}) :result nil}}})
(fx/defn allow-permission (rf/defn allow-permission
{:events [:eip3085.ui/dapp-permission-allowed]} {:events [:eip3085.ui/dapp-permission-allowed]}
[{:keys [db] :as cofx} message-id {:keys [new-networks id]}] [{:keys [db] :as cofx} message-id {:keys [new-networks id]}]
{:db (assoc db :networks/networks new-networks) {:db (assoc db :networks/networks new-networks)
@@ -29,7 +29,7 @@
:on-error #(log/error "failed to perform settings_saveSetting" %)}] :on-error #(log/error "failed to perform settings_saveSetting" %)}]
:dispatch [:bottom-sheet/hide]}) :dispatch [:bottom-sheet/hide]})
(fx/defn deny-permission (rf/defn deny-permission
{:events [:eip3085.ui/dapp-permission-denied]} {:events [:eip3085.ui/dapp-permission-denied]}
[_ message-id _] [_ message-id _]
{:browser/send-to-bridge {:type constants/web3-send-async-callback {:browser/send-to-bridge {:type constants/web3-send-async-callback
@@ -38,7 +38,7 @@
:message "User rejected the request."}} :message "User rejected the request."}}
:dispatch [:bottom-sheet/hide]}) :dispatch [:bottom-sheet/hide]})
(fx/defn handle-add-ethereum-chain (rf/defn handle-add-ethereum-chain
{:events [:eip3085/handle-add-ethereum-chain]} {:events [:eip3085/handle-add-ethereum-chain]}
[{{:networks/keys [networks] :as db} :db :as cofx} [{{:networks/keys [networks] :as db} :db :as cofx}
dapp-name id message-id {:keys [chainId blockExplorerUrls chainName iconUrls nativeCurrency rpcUrls] :as params}] dapp-name id message-id {:keys [chainId blockExplorerUrls chainName iconUrls nativeCurrency rpcUrls] :as params}]
+3 -3
View File
@@ -1,11 +1,11 @@
;reference https://eips.ethereum.org/EIPS/eip-3326 EIP-3326: Wallet Switch Ethereum Chain RPC Method (`wallet_switchEthereumChain`) ;reference https://eips.ethereum.org/EIPS/eip-3326 EIP-3326: Wallet Switch Ethereum Chain RPC Method (`wallet_switchEthereumChain`)
(ns status-im.browser.eip3326 (ns status-im.browser.eip3326
(:require [status-im.constants :as constants] (:require [status-im.constants :as constants]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.ui.screens.browser.eip3326.sheet :as sheet])) [status-im.ui.screens.browser.eip3326.sheet :as sheet]))
(fx/defn deny-permission (rf/defn deny-permission
{:events [:eip3326.ui/dapp-permission-denied]} {:events [:eip3326.ui/dapp-permission-denied]}
[{:keys [db] :as cofx} message-id _] [{:keys [db] :as cofx} message-id _]
{:browser/send-to-bridge {:type constants/web3-send-async-callback {:browser/send-to-bridge {:type constants/web3-send-async-callback
@@ -14,7 +14,7 @@
:message "User rejected the request."}} :message "User rejected the request."}}
:dispatch [:bottom-sheet/hide]}) :dispatch [:bottom-sheet/hide]})
(fx/defn handle-switch-ethereum-chain (rf/defn handle-switch-ethereum-chain
{:events [:eip3326/handle-switch-ethereum-chain]} {:events [:eip3326/handle-switch-ethereum-chain]}
[{:keys [db] :as cofx} dapp-name id message-id {:keys [chainId] :as params}] [{:keys [db] :as cofx} dapp-name id message-id {:keys [chainId] :as params}]
(let [target-chain-id (js/parseInt chainId 16) (let [target-chain-id (js/parseInt chainId 16)
+19 -19
View File
@@ -4,7 +4,7 @@
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.qr-scanner.core :as qr-scanner] [status-im.qr-scanner.core :as qr-scanner]
[status-im.utils.fx :as fx])) [utils.re-frame :as rf]))
(declare process-next-permission) (declare process-next-permission)
(declare send-response-to-bridge) (declare send-response-to-bridge)
@@ -21,18 +21,18 @@
:description (i18n/label :t/allowing-authorizes-this-dapp) :description (i18n/label :t/allowing-authorizes-this-dapp)
:icon :main-icons/wallet}}) :icon :main-icons/wallet}})
(fx/defn permission-yield-control (rf/defn permission-yield-control
[{:keys [db] :as cofx} dapp-name permission message-id params] [{:keys [db] :as cofx} dapp-name permission message-id params]
(cond (cond
(= permission constants/dapp-permission-qr-code) (= permission constants/dapp-permission-qr-code)
(fx/merge (assoc-in cofx [:db :browser/options :yielding-control?] true) (rf/merge (assoc-in cofx [:db :browser/options :yielding-control?] true)
(qr-scanner/scan-qr-code {:handler :browser.bridge.callback/qr-code-scanned (qr-scanner/scan-qr-code {:handler :browser.bridge.callback/qr-code-scanned
:cancel-handler :browser.bridge.callback/qr-code-canceled :cancel-handler :browser.bridge.callback/qr-code-canceled
:data {:dapp-name dapp-name :data {:dapp-name dapp-name
:permission permission :permission permission
:message-id message-id}})))) :message-id message-id}}))))
(fx/defn permission-show-permission (rf/defn permission-show-permission
[{:keys [db] :as cofx} dapp-name permission message-id yield-control?] [{:keys [db] :as cofx} dapp-name permission message-id yield-control?]
{:db (assoc-in db [:browser/options :show-permission] {:db (assoc-in db [:browser/options :show-permission]
{:requested-permission permission {:requested-permission permission
@@ -46,7 +46,7 @@
constants/dapp-permission-web3 [(:dapps-address multiaccount)]} constants/dapp-permission-web3 [(:dapps-address multiaccount)]}
allowed-permission))) allowed-permission)))
(fx/defn send-response-to-bridge (rf/defn send-response-to-bridge
"Send response to the bridge. If the permission is allowed, send data associated "Send response to the bridge. If the permission is allowed, send data associated
with the permission" with the permission"
[{:keys [db] :as cofx} permission message-id allowed? data] [{:keys [db] :as cofx} permission message-id allowed? data]
@@ -57,7 +57,7 @@
allowed? allowed?
(assoc :data data))}) (assoc :data data))})
(fx/defn update-dapp-permissions (rf/defn update-dapp-permissions
[{:keys [db]} dapp-name permission allowed?] [{:keys [db]} dapp-name permission allowed?]
(let [dapp-permissions-set (set (get-in db [:dapps/permissions dapp-name :permissions])) (let [dapp-permissions-set (set (get-in db [:dapps/permissions dapp-name :permissions]))
allowed-permissions-set (if allowed? allowed-permissions-set (if allowed?
@@ -70,23 +70,23 @@
:params [allowed-permissions] :params [allowed-permissions]
:on-success #()}]})) :on-success #()}]}))
(fx/defn revoke-permissions (rf/defn revoke-permissions
{:events [:browser/revoke-dapp-permissions]} {:events [:browser/revoke-dapp-permissions]}
[{:keys [db] :as cofx} dapp] [{:keys [db] :as cofx} dapp]
(fx/merge cofx (rf/merge cofx
{:db (update-in db [:dapps/permissions] dissoc dapp) {:db (update-in db [:dapps/permissions] dissoc dapp)
::json-rpc/call [{:method "permissions_deleteDappPermissions" ::json-rpc/call [{:method "permissions_deleteDappPermissions"
:params [dapp] :params [dapp]
:on-success #()}]})) :on-success #()}]}))
(fx/defn revoke-dapp-permissions (rf/defn revoke-dapp-permissions
{:events [:dapps/revoke-access]} {:events [:dapps/revoke-access]}
[cofx dapp] [cofx dapp]
(fx/merge cofx (rf/merge cofx
(revoke-permissions dapp) (revoke-permissions dapp)
(navigation/navigate-back))) (navigation/navigate-back)))
(fx/defn clear-dapps-permissions (rf/defn clear-dapps-permissions
[{:keys [db]}] [{:keys [db]}]
(let [dapp-permissions (keys (:dapps/permissions db))] (let [dapp-permissions (keys (:dapps/permissions db))]
{:db (dissoc db :dapps/permissions) {:db (dissoc db :dapps/permissions)
@@ -95,7 +95,7 @@
:params [dapp] :params [dapp]
:on-success #()})})) :on-success #()})}))
(fx/defn process-next-permission (rf/defn process-next-permission
"Process next permission by removing it from pending permissions and prompting user "Process next permission by removing it from pending permissions and prompting user
if there is no pending permissions left, save all granted permissions if there is no pending permissions left, save all granted permissions
and return the result to the bridge" and return the result to the bridge"
@@ -111,40 +111,40 @@
(permission-yield-control new-cofx dapp-name permission message-id params) (permission-yield-control new-cofx dapp-name permission message-id params)
(permission-show-permission new-cofx dapp-name permission message-id yield-control?))))))) (permission-show-permission new-cofx dapp-name permission message-id yield-control?)))))))
(fx/defn send-response-and-process-next-permission (rf/defn send-response-and-process-next-permission
[{:keys [db] :as cofx} dapp-name requested-permission message-id] [{:keys [db] :as cofx} dapp-name requested-permission message-id]
(fx/merge cofx (rf/merge cofx
(send-response-to-bridge requested-permission (send-response-to-bridge requested-permission
message-id message-id
true true
(get-permission-data cofx requested-permission)) (get-permission-data cofx requested-permission))
(process-next-permission dapp-name))) (process-next-permission dapp-name)))
(fx/defn allow-permission (rf/defn allow-permission
"Add permission to set of allowed permission and process next permission" "Add permission to set of allowed permission and process next permission"
{:events [:browser.permissions.ui/dapp-permission-allowed]} {:events [:browser.permissions.ui/dapp-permission-allowed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [requested-permission message-id dapp-name yield-control? params]} (let [{:keys [requested-permission message-id dapp-name yield-control? params]}
(get-in db [:browser/options :show-permission])] (get-in db [:browser/options :show-permission])]
(fx/merge (assoc-in cofx [:db :browser/options :show-permission] nil) (rf/merge (assoc-in cofx [:db :browser/options :show-permission] nil)
(update-dapp-permissions dapp-name requested-permission true) (update-dapp-permissions dapp-name requested-permission true)
(if yield-control? (if yield-control?
(permission-yield-control dapp-name requested-permission message-id params) (permission-yield-control dapp-name requested-permission message-id params)
(send-response-and-process-next-permission dapp-name requested-permission message-id))))) (send-response-and-process-next-permission dapp-name requested-permission message-id)))))
(fx/defn deny-permission (rf/defn deny-permission
"Add permission to set of allowed permission and process next permission" "Add permission to set of allowed permission and process next permission"
{:events [:browser.permissions.ui/dapp-permission-denied]} {:events [:browser.permissions.ui/dapp-permission-denied]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [requested-permission message-id dapp-name]} (get-in db [:browser/options :show-permission])] (let [{:keys [requested-permission message-id dapp-name]} (get-in db [:browser/options :show-permission])]
(fx/merge (assoc-in cofx [:db :browser/options :show-permission] nil) (rf/merge (assoc-in cofx [:db :browser/options :show-permission] nil)
(send-response-to-bridge requested-permission (send-response-to-bridge requested-permission
message-id message-id
false false
(get-permission-data cofx requested-permission)) (get-permission-data cofx requested-permission))
(process-next-permission dapp-name)))) (process-next-permission dapp-name))))
(fx/defn process-permission (rf/defn process-permission
"Process the permission requested by a dapp "Process the permission requested by a dapp
If supported permission is already granted, return the result immediatly to the bridge If supported permission is already granted, return the result immediatly to the bridge
Otherwise process the first permission which will prompt user" Otherwise process the first permission which will prompt user"
+51 -51
View File
@@ -13,7 +13,7 @@
[quo.design-system.colors :as colors] [quo.design-system.colors :as colors]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.utils.clocks :as utils.clocks] [status-im.utils.clocks :as utils.clocks]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[status-im.add-new.db :as new-public-chat.db] [status-im.add-new.db :as new-public-chat.db]
@@ -107,14 +107,14 @@
(fn [val] (fn [val]
(and (not (get-in db [:chats (:chat-id val)])) (:public? val)))) (and (not (get-in db [:chats (:chat-id val)])) (:public? val))))
(fx/defn leave-removed-chat (rf/defn leave-removed-chat
[{{:keys [view-id current-chat-id chats]} :db [{{:keys [view-id current-chat-id chats]} :db
:as cofx}] :as cofx}]
(when (and (= view-id :chat) (when (and (= view-id :chat)
(not (contains? chats current-chat-id))) (not (contains? chats current-chat-id)))
(navigation/navigate-back cofx))) (navigation/navigate-back cofx)))
(fx/defn ensure-chats (rf/defn ensure-chats
"Add chats to db and update" "Add chats to db and update"
[{:keys [db] :as cofx} chats] [{:keys [db] :as cofx} chats]
(let [{:keys [all-chats chats-home-list removed-chats]} (let [{:keys [all-chats chats-home-list removed-chats]}
@@ -130,7 +130,7 @@
:chats-home-list #{} :chats-home-list #{}
:removed-chats #{}} :removed-chats #{}}
(map (map-chats cofx) chats))] (map (map-chats cofx) chats))]
(fx/merge (rf/merge
cofx cofx
(merge {:db (-> db (merge {:db (-> db
(update :chats merge all-chats) (update :chats merge all-chats)
@@ -143,7 +143,7 @@
(get-in db [:multiaccount :remote-push-notifications-enabled?])]})) (get-in db [:multiaccount :remote-push-notifications-enabled?])]}))
leave-removed-chat))) leave-removed-chat)))
(fx/defn clear-history (rf/defn clear-history
"Clears history of the particular chat" "Clears history of the particular chat"
[{:keys [db] :as cofx} chat-id remove-chat?] [{:keys [db] :as cofx} chat-id remove-chat?]
(let [{:keys [last-message public? (let [{:keys [last-message public?
@@ -165,11 +165,11 @@
:deleted-at-clock-value last-message-clock-value}) :deleted-at-clock-value last-message-clock-value})
chats))))})) chats))))}))
(fx/defn clear-history-handler (rf/defn clear-history-handler
"Clears history of the particular chat" "Clears history of the particular chat"
{:events [:chat.ui/clear-history]} {:events [:chat.ui/clear-history]}
[{:keys [db] :as cofx} chat-id remove-chat?] [{:keys [db] :as cofx} chat-id remove-chat?]
(fx/merge cofx (rf/merge cofx
{:db db {:db db
::json-rpc/call [{:method "wakuext_clearHistory" ::json-rpc/call [{:method "wakuext_clearHistory"
:params [{:id chat-id}] :params [{:id chat-id}]
@@ -177,15 +177,15 @@
:on-error #(log/error "failed to clear history " chat-id %)}]} :on-error #(log/error "failed to clear history " chat-id %)}]}
(clear-history chat-id remove-chat?))) (clear-history chat-id remove-chat?)))
(fx/defn chat-deactivated (rf/defn chat-deactivated
{:events [::chat-deactivated]} {:events [::chat-deactivated]}
[_ chat-id] [_ chat-id]
(log/debug "chat deactivated" chat-id)) (log/debug "chat deactivated" chat-id))
(fx/defn deactivate-chat (rf/defn deactivate-chat
"Deactivate chat in db, no side effects" "Deactivate chat in db, no side effects"
[{:keys [db now] :as cofx} chat-id] [{:keys [db now] :as cofx} chat-id]
(fx/merge (rf/merge
cofx cofx
{:db (-> (if (get-in db [:chats chat-id :muted]) {:db (-> (if (get-in db [:chats chat-id :muted])
(assoc-in db [:chats chat-id :active] false) (assoc-in db [:chats chat-id :active] false)
@@ -198,7 +198,7 @@
:on-error #(log/error "failed to create public chat" chat-id %)}]} :on-error #(log/error "failed to create public chat" chat-id %)}]}
(clear-history chat-id true))) (clear-history chat-id true)))
(fx/defn offload-messages (rf/defn offload-messages
{:events [:offload-messages]} {:events [:offload-messages]}
[{:keys [db]} chat-id] [{:keys [db]} chat-id]
(merge {:db (-> db (merge {:db (-> db
@@ -208,52 +208,52 @@
(when (and (= chat-id constants/timeline-chat-id) (= (:view-id db) :status)) (when (and (= chat-id constants/timeline-chat-id) (= (:view-id db) :status))
{:dispatch [:init-timeline-chat]}))) {:dispatch [:init-timeline-chat]})))
(fx/defn close-chat (rf/defn close-chat
{:events [:close-chat]} {:events [:close-chat]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(when-let [chat-id (:current-chat-id db)] (when-let [chat-id (:current-chat-id db)]
(chat.state/reset-visible-item) (chat.state/reset-visible-item)
(fx/merge cofx (rf/merge cofx
{:db (dissoc db :current-chat-id)} {:db (dissoc db :current-chat-id)}
(delete-for-me/sync-all) (delete-for-me/sync-all)
(delete-message/send-all) (delete-message/send-all)
(offload-messages chat-id)))) (offload-messages chat-id))))
(fx/defn force-close-chat (rf/defn force-close-chat
[{:keys [db] :as cofx} chat-id] [{:keys [db] :as cofx} chat-id]
(do (do
(chat.state/reset-visible-item) (chat.state/reset-visible-item)
(fx/merge cofx (rf/merge cofx
{:db (dissoc db :current-chat-id)} {:db (dissoc db :current-chat-id)}
(offload-messages chat-id)))) (offload-messages chat-id))))
(fx/defn remove-chat (rf/defn remove-chat
"Removes chat completely from app, producing all necessary effects for that" "Removes chat completely from app, producing all necessary effects for that"
{:events [:chat.ui/remove-chat]} {:events [:chat.ui/remove-chat]}
[{:keys [db now] :as cofx} chat-id] [{:keys [db now] :as cofx} chat-id]
(fx/merge cofx (rf/merge cofx
{:clear-message-notifications {:clear-message-notifications
[[chat-id] (get-in db [:multiaccount :remote-push-notifications-enabled?])]} [[chat-id] (get-in db [:multiaccount :remote-push-notifications-enabled?])]}
(deactivate-chat chat-id) (deactivate-chat chat-id)
(offload-messages chat-id))) (offload-messages chat-id)))
(fx/defn show-more-chats (rf/defn show-more-chats
{:events [:chat.ui/show-more-chats]} {:events [:chat.ui/show-more-chats]}
[{:keys [db]}] [{:keys [db]}]
(when (< (:home-items-show-number db) (count (:chats db))) (when (< (:home-items-show-number db) (count (:chats db)))
{:db (update db :home-items-show-number + 40)})) {:db (update db :home-items-show-number + 40)}))
(fx/defn preload-chat-data (rf/defn preload-chat-data
"Takes chat-id and coeffects map, returns effects necessary when navigating to chat" "Takes chat-id and coeffects map, returns effects necessary when navigating to chat"
{:events [:chat.ui/preload-chat-data]} {:events [:chat.ui/preload-chat-data]}
[cofx chat-id] [cofx chat-id]
(loading/load-messages cofx chat-id)) (loading/load-messages cofx chat-id))
(fx/defn navigate-to-chat (rf/defn navigate-to-chat
"Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data" "Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data"
{:events [:chat.ui/navigate-to-chat]} {:events [:chat.ui/navigate-to-chat]}
[{db :db :as cofx} chat-id] [{db :db :as cofx} chat-id]
(fx/merge cofx (rf/merge cofx
{:dispatch [:navigate-to :chat]} {:dispatch [:navigate-to :chat]}
(navigation/change-tab :chat) (navigation/change-tab :chat)
(when-not (= (:view-id db) :community) (when-not (= (:view-id db) :community)
@@ -266,11 +266,11 @@
#(when (group-chat? cofx chat-id) #(when (group-chat? cofx chat-id)
(loading/load-chat % chat-id)))) (loading/load-chat % chat-id))))
(fx/defn navigate-to-chat-nav2 (rf/defn navigate-to-chat-nav2
"Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data" "Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data"
{:events [:chat.ui/navigate-to-chat-nav2]} {:events [:chat.ui/navigate-to-chat-nav2]}
[{db :db :as cofx} chat-id from-shell?] [{db :db :as cofx} chat-id from-shell?]
(fx/merge cofx (rf/merge cofx
{:dispatch [:navigate-to-nav2 :chat chat-id from-shell?]} {:dispatch [:navigate-to-nav2 :chat chat-id from-shell?]}
(when-not (= (:view-id db) :community) (when-not (= (:view-id db) :community)
(navigation/pop-to-root-tab :shell-stack)) (navigation/pop-to-root-tab :shell-stack))
@@ -282,13 +282,13 @@
#(when (group-chat? cofx chat-id) #(when (group-chat? cofx chat-id)
(loading/load-chat % chat-id)))) (loading/load-chat % chat-id))))
(fx/defn handle-clear-history-response (rf/defn handle-clear-history-response
{:events [::history-cleared]} {:events [::history-cleared]}
[{:keys [db]} chat-id response] [{:keys [db]} chat-id response]
(let [chat (chats-store/<-rpc (first (:chats response)))] (let [chat (chats-store/<-rpc (first (:chats response)))]
{:db (assoc-in db [:chats chat-id] chat)})) {:db (assoc-in db [:chats chat-id] chat)}))
(fx/defn handle-one-to-one-chat-created (rf/defn handle-one-to-one-chat-created
{:events [::one-to-one-chat-created]} {:events [::one-to-one-chat-created]}
[{:keys [db]} chat-id response] [{:keys [db]} chat-id response]
(let [chat (chats-store/<-rpc (first (:chats response))) (let [chat (chats-store/<-rpc (first (:chats response)))
@@ -303,13 +303,13 @@
(update :chats-home-list conj chat-id)) (update :chats-home-list conj chat-id))
:dispatch [:chat.ui/navigate-to-chat chat-id]})) :dispatch [:chat.ui/navigate-to-chat chat-id]}))
(fx/defn navigate-to-user-pinned-messages (rf/defn navigate-to-user-pinned-messages
"Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data" "Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data"
{:events [:chat.ui/navigate-to-pinned-messages]} {:events [:chat.ui/navigate-to-pinned-messages]}
[cofx chat-id] [cofx chat-id]
(navigation/navigate-to cofx :chat-pinned-messages {:chat-id chat-id})) (navigation/navigate-to cofx :chat-pinned-messages {:chat-id chat-id}))
(fx/defn start-chat (rf/defn start-chat
"Start a chat, making sure it exists" "Start a chat, making sure it exists"
{:events [:chat.ui/start-chat]} {:events [:chat.ui/start-chat]}
[{:keys [db] :as cofx} chat-id ens-name] [{:keys [db] :as cofx} chat-id ens-name]
@@ -326,7 +326,7 @@
(defn my-profile-chat-topic [db] (defn my-profile-chat-topic [db]
(profile-chat-topic (get-in db [:multiaccount :public-key]))) (profile-chat-topic (get-in db [:multiaccount :public-key])))
(fx/defn handle-public-chat-created (rf/defn handle-public-chat-created
{:events [::public-chat-created]} {:events [::public-chat-created]}
[{:keys [db]} chat-id response] [{:keys [db]} chat-id response]
{:db (-> db {:db (-> db
@@ -334,13 +334,13 @@
(update :chats-home-list conj chat-id)) (update :chats-home-list conj chat-id))
:dispatch [:chat.ui/navigate-to-chat chat-id]}) :dispatch [:chat.ui/navigate-to-chat chat-id]})
(fx/defn create-public-chat-go [_ chat-id] (rf/defn create-public-chat-go [_ chat-id]
{::json-rpc/call [{:method "wakuext_createPublicChat" {::json-rpc/call [{:method "wakuext_createPublicChat"
:params [{:id chat-id}] :params [{:id chat-id}]
:on-success #(re-frame/dispatch [::public-chat-created chat-id %]) :on-success #(re-frame/dispatch [::public-chat-created chat-id %])
:on-error #(log/error "failed to create public chat" chat-id %)}]}) :on-error #(log/error "failed to create public chat" chat-id %)}]})
(fx/defn start-public-chat (rf/defn start-public-chat
"Starts a new public chat" "Starts a new public chat"
{:events [:chat.ui/start-public-chat]} {:events [:chat.ui/start-public-chat]}
[cofx topic] [cofx topic]
@@ -353,10 +353,10 @@
{:utils/show-popup {:title (i18n/label :t/cant-open-public-chat) {:utils/show-popup {:title (i18n/label :t/cant-open-public-chat)
:content (i18n/label :t/invalid-public-chat-topic)}})) :content (i18n/label :t/invalid-public-chat-topic)}}))
(fx/defn profile-chat-created (rf/defn profile-chat-created
{:events [::profile-chat-created]} {:events [::profile-chat-created]}
[{:keys [db] :as cofx} chat-id response navigate-to?] [{:keys [db] :as cofx} chat-id response navigate-to?]
(fx/merge (rf/merge
cofx cofx
{:db db} {:db db}
#(when response #(when response
@@ -366,7 +366,7 @@
{:dispatch-n [[:chat.ui/preload-chat-data chat-id] {:dispatch-n [[:chat.ui/preload-chat-data chat-id]
[:open-modal :profile]]}))) [:open-modal :profile]]})))
(fx/defn start-profile-chat (rf/defn start-profile-chat
"Starts a new profile chat" "Starts a new profile chat"
{:events [:start-profile-chat]} {:events [:start-profile-chat]}
[cofx profile-public-key navigate-to?] [cofx profile-public-key navigate-to?]
@@ -378,7 +378,7 @@
:on-success #(re-frame/dispatch [::profile-chat-created chat-id % navigate-to?]) :on-success #(re-frame/dispatch [::profile-chat-created chat-id % navigate-to?])
:on-error #(log/error "failed to create profile chat" chat-id %)}]}))) :on-error #(log/error "failed to create profile chat" chat-id %)}]})))
(fx/defn disable-chat-cooldown (rf/defn disable-chat-cooldown
"Turns off chat cooldown (protection against message spamming)" "Turns off chat cooldown (protection against message spamming)"
{:events [:chat/disable-cooldown]} {:events [:chat/disable-cooldown]}
[{:keys [db]}] [{:keys [db]}]
@@ -392,18 +392,18 @@
(i18n/label :cooldown/warning-message) (i18n/label :cooldown/warning-message)
#()))) #())))
(fx/defn mute-chat-failed (rf/defn mute-chat-failed
{:events [::mute-chat-failed]} {:events [::mute-chat-failed]}
[{:keys [db] :as cofx} chat-id muted? error] [{:keys [db] :as cofx} chat-id muted? error]
(log/error "mute chat failed" chat-id error) (log/error "mute chat failed" chat-id error)
{:db (assoc-in db [:chats chat-id :muted] (not muted?))}) {:db (assoc-in db [:chats chat-id :muted] (not muted?))})
(fx/defn mute-chat-toggled-successfully (rf/defn mute-chat-toggled-successfully
{:events [::mute-chat-toggled-successfully]} {:events [::mute-chat-toggled-successfully]}
[_ chat-id] [_ chat-id]
(log/debug "muted chat successfully" chat-id)) (log/debug "muted chat successfully" chat-id))
(fx/defn mute-chat (rf/defn mute-chat
{:events [::mute-chat-toggled]} {:events [::mute-chat-toggled]}
[{:keys [db] :as cofx} chat-id muted?] [{:keys [db] :as cofx} chat-id muted?]
(let [method (if muted? "wakuext_muteChat" "wakuext_unmuteChat")] (let [method (if muted? "wakuext_muteChat" "wakuext_unmuteChat")]
@@ -413,19 +413,19 @@
:on-error #(re-frame/dispatch [::mute-chat-failed chat-id muted? %]) :on-error #(re-frame/dispatch [::mute-chat-failed chat-id muted? %])
:on-success #(re-frame/dispatch [::mute-chat-toggled-successfully chat-id])}]})) :on-success #(re-frame/dispatch [::mute-chat-toggled-successfully chat-id])}]}))
(fx/defn show-profile (rf/defn show-profile
{:events [:chat.ui/show-profile]} {:events [:chat.ui/show-profile]}
[{:keys [db] :as cofx} identity ens-name] [{:keys [db] :as cofx} identity ens-name]
(let [my-public-key (get-in db [:multiaccount :public-key])] (let [my-public-key (get-in db [:multiaccount :public-key])]
(when (not= my-public-key identity) (when (not= my-public-key identity)
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(assoc :contacts/identity identity) (assoc :contacts/identity identity)
(assoc :contacts/ens-name ens-name))} (assoc :contacts/ens-name ens-name))}
(start-profile-chat identity true))))) (start-profile-chat identity true)))))
(fx/defn clear-history-pressed (rf/defn clear-history-pressed
{:events [:chat.ui/clear-history-pressed]} {:events [:chat.ui/clear-history-pressed]}
[_ chat-id] [_ chat-id]
{:ui/show-confirmation {:ui/show-confirmation
@@ -436,19 +436,19 @@
(re-frame/dispatch [:bottom-sheet/hide]) (re-frame/dispatch [:bottom-sheet/hide])
(re-frame/dispatch [:chat.ui/clear-history chat-id false]))}}) (re-frame/dispatch [:chat.ui/clear-history chat-id false]))}})
(fx/defn gaps-failed (rf/defn gaps-failed
{:events [::gaps-failed]} {:events [::gaps-failed]}
[{:keys [db]} chat-id gap-ids error] [{:keys [db]} chat-id gap-ids error]
(log/error "failed to fetch gaps" chat-id gap-ids error) (log/error "failed to fetch gaps" chat-id gap-ids error)
{:db (dissoc db :mailserver/fetching-gaps-in-progress)}) {:db (dissoc db :mailserver/fetching-gaps-in-progress)})
(fx/defn sync-chat-from-sync-from-failed (rf/defn sync-chat-from-sync-from-failed
{:events [::sync-chat-from-sync-from-failed]} {:events [::sync-chat-from-sync-from-failed]}
[{:keys [db]} chat-id error] [{:keys [db]} chat-id error]
(log/error "failed to sync chat" chat-id error) (log/error "failed to sync chat" chat-id error)
{:db (dissoc db :mailserver/fetching-gaps-in-progress)}) {:db (dissoc db :mailserver/fetching-gaps-in-progress)})
(fx/defn sync-chat-from-sync-from-success (rf/defn sync-chat-from-sync-from-success
{:events [::sync-chat-from-sync-from-success]} {:events [::sync-chat-from-sync-from-success]}
[{:keys [db] :as cofx} chat-id synced-from] [{:keys [db] :as cofx} chat-id synced-from]
(log/debug "synced success" chat-id synced-from) (log/debug "synced success" chat-id synced-from)
@@ -457,24 +457,24 @@
(assoc-in [:chats chat-id :synced-from] synced-from) (assoc-in [:chats chat-id :synced-from] synced-from)
(dissoc :mailserver/fetching-gaps-in-progress))}) (dissoc :mailserver/fetching-gaps-in-progress))})
(fx/defn gaps-filled (rf/defn gaps-filled
{:events [::gaps-filled]} {:events [::gaps-filled]}
[{:keys [db] :as cofx} chat-id message-ids] [{:keys [db] :as cofx} chat-id message-ids]
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(update-in [:messages chat-id] (fn [messages] (apply dissoc messages message-ids))) (update-in [:messages chat-id] (fn [messages] (apply dissoc messages message-ids)))
(dissoc :mailserver/fetching-gaps-in-progress))} (dissoc :mailserver/fetching-gaps-in-progress))}
(message-list/rebuild-message-list chat-id))) (message-list/rebuild-message-list chat-id)))
(fx/defn fill-gaps (rf/defn fill-gaps
[cofx chat-id gap-ids] [cofx chat-id gap-ids]
{::json-rpc/call [{:method "wakuext_fillGaps" {::json-rpc/call [{:method "wakuext_fillGaps"
:params [chat-id gap-ids] :params [chat-id gap-ids]
:on-success #(re-frame/dispatch [::gaps-filled chat-id gap-ids %]) :on-success #(re-frame/dispatch [::gaps-filled chat-id gap-ids %])
:on-error #(re-frame/dispatch [::gaps-failed chat-id gap-ids %])}]}) :on-error #(re-frame/dispatch [::gaps-failed chat-id gap-ids %])}]})
(fx/defn sync-chat-from-sync-from (rf/defn sync-chat-from-sync-from
[cofx chat-id] [cofx chat-id]
(log/debug "syncing chat from sync from") (log/debug "syncing chat from sync from")
{::json-rpc/call [{:method "wakuext_syncChatFromSyncedFrom" {::json-rpc/call [{:method "wakuext_syncChatFromSyncedFrom"
@@ -482,19 +482,19 @@
:on-success #(re-frame/dispatch [::sync-chat-from-sync-from-success chat-id %]) :on-success #(re-frame/dispatch [::sync-chat-from-sync-from-success chat-id %])
:on-error #(re-frame/dispatch [::sync-chat-from-sync-from-failed chat-id %])}]}) :on-error #(re-frame/dispatch [::sync-chat-from-sync-from-failed chat-id %])}]})
(fx/defn chat-ui-fill-gaps (rf/defn chat-ui-fill-gaps
{:events [:chat.ui/fill-gaps]} {:events [:chat.ui/fill-gaps]}
[{:keys [db] :as cofx} chat-id gap-ids] [{:keys [db] :as cofx} chat-id gap-ids]
(let [use-status-nodes? (mailserver/fetch-use-mailservers? {:db db})] (let [use-status-nodes? (mailserver/fetch-use-mailservers? {:db db})]
(log/info "filling gaps if use-status-nodes = true" chat-id gap-ids) (log/info "filling gaps if use-status-nodes = true" chat-id gap-ids)
(when use-status-nodes? (when use-status-nodes?
(fx/merge cofx (rf/merge cofx
{:db (assoc db :mailserver/fetching-gaps-in-progress gap-ids)} {:db (assoc db :mailserver/fetching-gaps-in-progress gap-ids)}
(if (= gap-ids #{:first-gap}) (if (= gap-ids #{:first-gap})
(sync-chat-from-sync-from chat-id) (sync-chat-from-sync-from chat-id)
(fill-gaps chat-id gap-ids)))))) (fill-gaps chat-id gap-ids))))))
(fx/defn chat-ui-remove-chat-pressed (rf/defn chat-ui-remove-chat-pressed
{:events [:chat.ui/remove-chat-pressed]} {:events [:chat.ui/remove-chat-pressed]}
[_ chat-id] [_ chat-id]
{:ui/show-confirmation {:ui/show-confirmation
@@ -505,7 +505,7 @@
(re-frame/dispatch [:bottom-sheet/hide]) (re-frame/dispatch [:bottom-sheet/hide])
(re-frame/dispatch [:chat.ui/remove-chat chat-id]))}}) (re-frame/dispatch [:chat.ui/remove-chat chat-id]))}})
(fx/defn decrease-unviewed-count (rf/defn decrease-unviewed-count
{:events [:chat/decrease-unviewed-count]} {:events [:chat/decrease-unviewed-count]}
[{:keys [db]} chat-id {:keys [count countWithMentions]}] [{:keys [db]} chat-id {:keys [count countWithMentions]}]
{:db (-> db {:db (-> db
@@ -3,7 +3,7 @@
[status-im.chat.models.message-list :as message-list] [status-im.chat.models.message-list :as message-list]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.datetime :as datetime] [status-im.utils.datetime :as datetime]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.encore :as enc] [taoensso.encore :as enc]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
@@ -46,7 +46,7 @@
(when (get-in db [:messages chat-id message-id]) (when (get-in db [:messages chat-id message-id])
(update-in db [:messages chat-id message-id] assoc :deleted? true))) (update-in db [:messages chat-id message-id] assoc :deleted? true)))
(fx/defn delete (rf/defn delete
"Delete message now locally and broadcast after undo time limit timeout" "Delete message now locally and broadcast after undo time limit timeout"
{:events [:chat.ui/delete-message]} {:events [:chat.ui/delete-message]}
[{:keys [db]} {:keys [chat-id message-id]} undo-time-limit-ms] [{:keys [db]} {:keys [chat-id message-id]} undo-time-limit-ms]
@@ -60,7 +60,7 @@
:message-id message-id}] :message-id message-id}]
:ms undo-time-limit-ms}]))) :ms undo-time-limit-ms}])))
(fx/defn undo (rf/defn undo
{:events [:chat.ui/undo-delete-message]} {:events [:chat.ui/undo-delete-message]}
[{:keys [db]} {:keys [chat-id message-id]}] [{:keys [db]} {:keys [chat-id message-id]}]
(when (get-in db [:messages chat-id message-id]) (when (get-in db [:messages chat-id message-id])
@@ -68,7 +68,7 @@
{:db (update-db-undo-locally db chat-id message-id)} {:db (update-db-undo-locally db chat-id message-id)}
chat-id))) chat-id)))
(fx/defn delete-and-send (rf/defn delete-and-send
{:events [:chat.ui/delete-message-and-send]} {:events [:chat.ui/delete-message-and-send]}
[{:keys [db]} {:keys [message-id chat-id]}] [{:keys [db]} {:keys [message-id chat-id]}]
(when-let [message (get-in db [:messages chat-id message-id])] (when-let [message (get-in db [:messages chat-id message-id])]
@@ -90,14 +90,14 @@
(map (fn [message] {:chat-id chat-id :message-id (first message)})) (map (fn [message] {:chat-id chat-id :message-id (first message)}))
(concat acc))) (concat acc)))
(fx/defn send-all (rf/defn send-all
"Get all deleted messages that not yet synced with status-go and send them" "Get all deleted messages that not yet synced with status-go and send them"
{:events [:chat.ui/send-all-deleted-messages]} {:events [:chat.ui/send-all-deleted-messages]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [pending-send-messages (reduce-kv filter-pending-send-messages [] (:messages db))] (let [pending-send-messages (reduce-kv filter-pending-send-messages [] (:messages db))]
(apply fx/merge cofx (map delete-and-send pending-send-messages)))) (apply rf/merge cofx (map delete-and-send pending-send-messages))))
(fx/defn delete-messages-localy (rf/defn delete-messages-localy
"Mark messages :deleted? localy in client" "Mark messages :deleted? localy in client"
{:events [:chat.ui/delete-messages-localy]} {:events [:chat.ui/delete-messages-localy]}
[{:keys [db]} messages chat-id] [{:keys [db]} messages chat-id]
@@ -3,7 +3,7 @@
[status-im.chat.models.message-list :as message-list] [status-im.chat.models.message-list :as message-list]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.datetime :as datetime] [status-im.utils.datetime :as datetime]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(defn- update-db-clear-undo-timer (defn- update-db-clear-undo-timer
@@ -39,7 +39,7 @@
:deleted-for-me-undoable-till) :deleted-for-me-undoable-till)
(update-db-clear-undo-timer db chat-id message-id)))) (update-db-clear-undo-timer db chat-id message-id))))
(fx/defn delete (rf/defn delete
"Delete message for me now locally and broadcast after undo time limit timeout" "Delete message for me now locally and broadcast after undo time limit timeout"
{:events [:chat.ui/delete-message-for-me]} {:events [:chat.ui/delete-message-for-me]}
[{:keys [db]} {:keys [chat-id message-id]} undo-time-limit-ms] [{:keys [db]} {:keys [chat-id message-id]} undo-time-limit-ms]
@@ -53,7 +53,7 @@
:message-id message-id}] :message-id message-id}]
:ms undo-time-limit-ms}]))) :ms undo-time-limit-ms}])))
(fx/defn undo (rf/defn undo
{:events [:chat.ui/undo-delete-message-for-me]} {:events [:chat.ui/undo-delete-message-for-me]}
[{:keys [db]} {:keys [chat-id message-id]}] [{:keys [db]} {:keys [chat-id message-id]}]
(when (get-in db [:messages chat-id message-id]) (when (get-in db [:messages chat-id message-id])
@@ -61,7 +61,7 @@
{:db (update-db-undo-locally db chat-id message-id)} {:db (update-db-undo-locally db chat-id message-id)}
chat-id))) chat-id)))
(fx/defn delete-and-sync (rf/defn delete-and-sync
{:events [:chat.ui/delete-message-for-me-and-sync]} {:events [:chat.ui/delete-message-for-me-and-sync]}
[{:keys [db]} {:keys [message-id chat-id]}] [{:keys [db]} {:keys [message-id chat-id]}]
(when (get-in db [:messages chat-id message-id]) (when (get-in db [:messages chat-id message-id])
@@ -80,9 +80,9 @@
(map (fn [message] {:chat-id chat-id :message-id (first message)})) (map (fn [message] {:chat-id chat-id :message-id (first message)}))
(concat acc))) (concat acc)))
(fx/defn sync-all (rf/defn sync-all
"Get all deleted-for-me messages that not yet synced with status-go and sync them" "Get all deleted-for-me messages that not yet synced with status-go and sync them"
{:events [:chat.ui/sync-all-deleted-for-me-messages]} {:events [:chat.ui/sync-all-deleted-for-me-messages]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [pending-sync-messages (reduce-kv filter-pending-sync-messages [] (:messages db))] (let [pending-sync-messages (reduce-kv filter-pending-sync-messages [] (:messages db))]
(apply fx/merge cofx (map delete-and-sync pending-sync-messages)))) (apply rf/merge cofx (map delete-and-sync pending-sync-messages))))
+16 -16
View File
@@ -1,6 +1,6 @@
(ns status-im.chat.models.images (ns status-im.chat.models.images
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
["@react-native-community/cameraroll" :as CameraRoll] ["@react-native-community/cameraroll" :as CameraRoll]
["react-native-blob-util" :default ReactNativeBlobUtil] ["react-native-blob-util" :default ReactNativeBlobUtil]
[status-im.utils.types :as types] [status-im.utils.types :as types]
@@ -108,7 +108,7 @@
(.then #(re-frame/dispatch [:on-camera-roll-get-photos (:edges (types/js->clj %))])) (.then #(re-frame/dispatch [:on-camera-roll-get-photos (:edges (types/js->clj %))]))
(.catch #(log/warn "could not get cameraroll photos"))))}))) (.catch #(log/warn "could not get cameraroll photos"))))})))
(fx/defn image-captured (rf/defn image-captured
{:events [:chat.ui/image-captured]} {:events [:chat.ui/image-captured]}
[{:keys [db]} chat-id uri] [{:keys [db]} chat-id uri]
(let [current-chat-id (or chat-id (:current-chat-id db)) (let [current-chat-id (or chat-id (:current-chat-id db))
@@ -117,44 +117,44 @@
(not (get images uri))) (not (get images uri)))
{::image-selected [uri current-chat-id]}))) {::image-selected [uri current-chat-id]})))
(fx/defn camera-roll-get-photos (rf/defn camera-roll-get-photos
{:events [:chat.ui/camera-roll-get-photos]} {:events [:chat.ui/camera-roll-get-photos]}
[_ num] [_ num]
{::camera-roll-get-photos num}) {::camera-roll-get-photos num})
(fx/defn on-camera-roll-get-photos (rf/defn on-camera-roll-get-photos
{:events [:on-camera-roll-get-photos]} {:events [:on-camera-roll-get-photos]}
[{db :db} photos] [{db :db} photos]
{:db (assoc db :camera-roll-photos (mapv #(get-in % [:node :image :uri]) photos))}) {:db (assoc db :camera-roll-photos (mapv #(get-in % [:node :image :uri]) photos))})
(fx/defn clear-sending-images (rf/defn clear-sending-images
{:events [:chat.ui/clear-sending-images]} {:events [:chat.ui/clear-sending-images]}
[{:keys [db]} current-chat-id] [{:keys [db]} current-chat-id]
{:db (update-in db [:chat/inputs current-chat-id :metadata] assoc :sending-image {})}) {:db (update-in db [:chat/inputs current-chat-id :metadata] assoc :sending-image {})})
(fx/defn cancel-sending-image (rf/defn cancel-sending-image
{:events [:chat.ui/cancel-sending-image]} {:events [:chat.ui/cancel-sending-image]}
[{:keys [db] :as cofx} chat-id] [{:keys [db] :as cofx} chat-id]
(let [current-chat-id (or chat-id (:current-chat-id db))] (let [current-chat-id (or chat-id (:current-chat-id db))]
(clear-sending-images cofx current-chat-id))) (clear-sending-images cofx current-chat-id)))
(fx/defn cancel-sending-image-timeline (rf/defn cancel-sending-image-timeline
{:events [:chat.ui/cancel-sending-image-timeline]} {:events [:chat.ui/cancel-sending-image-timeline]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(cancel-sending-image cofx (chat/my-profile-chat-topic db))) (cancel-sending-image cofx (chat/my-profile-chat-topic db)))
(fx/defn image-selected (rf/defn image-selected
{:events [:chat.ui/image-selected]} {:events [:chat.ui/image-selected]}
[{:keys [db]} current-chat-id original uri] [{:keys [db]} current-chat-id original uri]
{:db (update-in db [:chat/inputs current-chat-id :metadata :sending-image original] merge {:uri uri})}) {:db (update-in db [:chat/inputs current-chat-id :metadata :sending-image original] merge {:uri uri})})
(fx/defn image-unselected (rf/defn image-unselected
{:events [:chat.ui/image-unselected]} {:events [:chat.ui/image-unselected]}
[{:keys [db]} original] [{:keys [db]} original]
(let [current-chat-id (:current-chat-id db)] (let [current-chat-id (:current-chat-id db)]
{:db (update-in db [:chat/inputs current-chat-id :metadata :sending-image] dissoc original)})) {:db (update-in db [:chat/inputs current-chat-id :metadata :sending-image] dissoc original)}))
(fx/defn chat-open-image-picker (rf/defn chat-open-image-picker
{:events [:chat.ui/open-image-picker]} {:events [:chat.ui/open-image-picker]}
[{:keys [db]} chat-id] [{:keys [db]} chat-id]
(let [current-chat-id (or chat-id (:current-chat-id db)) (let [current-chat-id (or chat-id (:current-chat-id db))
@@ -162,12 +162,12 @@
(when (< (count images) config/max-images-batch) (when (< (count images) config/max-images-batch)
{::chat-open-image-picker current-chat-id}))) {::chat-open-image-picker current-chat-id})))
(fx/defn chat-open-image-picker-timeline (rf/defn chat-open-image-picker-timeline
{:events [:chat.ui/open-image-picker-timeline]} {:events [:chat.ui/open-image-picker-timeline]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(chat-open-image-picker cofx (chat/my-profile-chat-topic db))) (chat-open-image-picker cofx (chat/my-profile-chat-topic db)))
(fx/defn chat-show-image-picker-camera (rf/defn chat-show-image-picker-camera
{:events [:chat.ui/show-image-picker-camera]} {:events [:chat.ui/show-image-picker-camera]}
[{:keys [db]} chat-id] [{:keys [db]} chat-id]
(let [current-chat-id (or chat-id (:current-chat-id db)) (let [current-chat-id (or chat-id (:current-chat-id db))
@@ -175,12 +175,12 @@
(when (< (count images) config/max-images-batch) (when (< (count images) config/max-images-batch)
{::chat-open-image-picker-camera current-chat-id}))) {::chat-open-image-picker-camera current-chat-id})))
(fx/defn chat-show-image-picker-camera-timeline (rf/defn chat-show-image-picker-camera-timeline
{:events [:chat.ui/show-image-picker-camera-timeline]} {:events [:chat.ui/show-image-picker-camera-timeline]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(chat-show-image-picker-camera cofx (chat/my-profile-chat-topic db))) (chat-show-image-picker-camera cofx (chat/my-profile-chat-topic db)))
(fx/defn camera-roll-pick (rf/defn camera-roll-pick
{:events [:chat.ui/camera-roll-pick]} {:events [:chat.ui/camera-roll-pick]}
[{:keys [db]} uri chat-id] [{:keys [db]} uri chat-id]
(let [current-chat-id (or chat-id (:current-chat-id db)) (let [current-chat-id (or chat-id (:current-chat-id db))
@@ -192,12 +192,12 @@
(not (get images uri))) (not (get images uri)))
{::image-selected [uri current-chat-id]})))) {::image-selected [uri current-chat-id]}))))
(fx/defn camera-roll-pick-timeline (rf/defn camera-roll-pick-timeline
{:events [:chat.ui/camera-roll-pick-timeline]} {:events [:chat.ui/camera-roll-pick-timeline]}
[{:keys [db] :as cofx} uri] [{:keys [db] :as cofx} uri]
(camera-roll-pick cofx uri (chat/my-profile-chat-topic db))) (camera-roll-pick cofx uri (chat/my-profile-chat-topic db)))
(fx/defn save-image-to-gallery (rf/defn save-image-to-gallery
{:events [:chat.ui/save-image-to-gallery]} {:events [:chat.ui/save-image-to-gallery]}
[_ base64-uri] [_ base64-uri]
{::save-image-to-gallery base64-uri}) {::save-image-to-gallery base64-uri})
+32 -32
View File
@@ -12,7 +12,7 @@
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.utils.datetime :as datetime] [status-im.utils.datetime :as datetime]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
@@ -26,7 +26,7 @@
(.-char ^js emoji-map) (.-char ^js emoji-map)
original)))) original))))
(fx/defn set-chat-input-text (rf/defn set-chat-input-text
"Set input text for current-chat. Takes db and input text and cofx "Set input text for current-chat. Takes db and input text and cofx
as arguments and returns new fx. Always clear all validation messages." as arguments and returns new fx. Always clear all validation messages."
{:events [:chat.ui/set-chat-input-text]} {:events [:chat.ui/set-chat-input-text]}
@@ -34,20 +34,20 @@
(let [current-chat-id (or chat-id (:current-chat-id db))] (let [current-chat-id (or chat-id (:current-chat-id db))]
{:db (assoc-in db [:chat/inputs current-chat-id :input-text] (text->emoji new-input))})) {:db (assoc-in db [:chat/inputs current-chat-id :input-text] (text->emoji new-input))}))
(fx/defn set-timeline-input-text (rf/defn set-timeline-input-text
{:events [:chat.ui/set-timeline-input-text]} {:events [:chat.ui/set-timeline-input-text]}
[{db :db} new-input] [{db :db} new-input]
{:db (assoc-in db [:chat/inputs (chat/my-profile-chat-topic db) :input-text] {:db (assoc-in db [:chat/inputs (chat/my-profile-chat-topic db) :input-text]
(text->emoji new-input))}) (text->emoji new-input))})
(fx/defn select-mention (rf/defn select-mention
{:events [:chat.ui/select-mention]} {:events [:chat.ui/select-mention]}
[{:keys [db] :as cofx} text-input-ref {:keys [alias name searched-text match] :as user}] [{:keys [db] :as cofx} text-input-ref {:keys [alias name searched-text match] :as user}]
(let [chat-id (:current-chat-id db) (let [chat-id (:current-chat-id db)
new-text (mentions/new-input-text-with-mention cofx user) new-text (mentions/new-input-text-with-mention cofx user)
at-sign-idx (get-in db [:chats/mentions chat-id :mentions :at-sign-idx]) at-sign-idx (get-in db [:chats/mentions chat-id :mentions :at-sign-idx])
cursor (+ at-sign-idx (count name) 2)] cursor (+ at-sign-idx (count name) 2)]
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(assoc-in [:chats/cursor chat-id] cursor) (assoc-in [:chats/cursor chat-id] cursor)
@@ -87,7 +87,7 @@
:chat/spam-messages-frequency 0 :chat/spam-messages-frequency 0
:chat/cooldown-enabled? true)}) :chat/cooldown-enabled? true)})
(fx/defn process-cooldown (rf/defn process-cooldown
"Process cooldown to protect against message spammers" "Process cooldown to protect against message spammers"
[{{:keys [chat/last-outgoing-message-sent-at [{{:keys [chat/last-outgoing-message-sent-at
chat/cooldowns chat/cooldowns
@@ -106,12 +106,12 @@
(and spamming-fast? spamming-frequently?) (and spamming-fast? spamming-frequently?)
(start-cooldown (inc cooldowns)))))) (start-cooldown (inc cooldowns))))))
(fx/defn reply-to-message (rf/defn reply-to-message
"Sets reference to previous chat message and focuses on input" "Sets reference to previous chat message and focuses on input"
{:events [:chat.ui/reply-to-message]} {:events [:chat.ui/reply-to-message]}
[{:keys [db] :as cofx} message] [{:keys [db] :as cofx} message]
(let [current-chat-id (:current-chat-id db)] (let [current-chat-id (:current-chat-id db)]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:chat/inputs current-chat-id :metadata :responding-to-message] (assoc-in [:chat/inputs current-chat-id :metadata :responding-to-message]
message) message)
@@ -119,7 +119,7 @@
(update-in [:chat/inputs current-chat-id :metadata] (update-in [:chat/inputs current-chat-id :metadata]
dissoc :sending-image))}))) dissoc :sending-image))})))
(fx/defn edit-message (rf/defn edit-message
"Sets reference to previous chat message and focuses on input" "Sets reference to previous chat message and focuses on input"
{:events [:chat.ui/edit-message]} {:events [:chat.ui/edit-message]}
[{:keys [db] :as cofx} message] [{:keys [db] :as cofx} message]
@@ -134,7 +134,7 @@
(update-in [:chat/inputs current-chat-id :metadata] (update-in [:chat/inputs current-chat-id :metadata]
dissoc :sending-image))})) dissoc :sending-image))}))
(fx/defn show-contact-request-input (rf/defn show-contact-request-input
"Sets reference to previous chat message and focuses on input" "Sets reference to previous chat message and focuses on input"
{:events [:chat.ui/send-contact-request]} {:events [:chat.ui/send-contact-request]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
@@ -148,7 +148,7 @@
(update-in [:chat/inputs current-chat-id :metadata] (update-in [:chat/inputs current-chat-id :metadata]
dissoc :sending-image))})) dissoc :sending-image))}))
(fx/defn cancel-message-reply (rf/defn cancel-message-reply
"Cancels stage message reply" "Cancels stage message reply"
{:events [:chat.ui/cancel-message-reply]} {:events [:chat.ui/cancel-message-reply]}
[{:keys [db]}] [{:keys [db]}]
@@ -181,8 +181,8 @@
:text (i18n/label :t/update-to-see-image {"locale" "en"})}) :text (i18n/label :t/update-to-see-image {"locale" "en"})})
images))) images)))
(fx/defn clean-input [{:keys [db] :as cofx} current-chat-id] (rf/defn clean-input [{:keys [db] :as cofx} current-chat-id]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:chat/inputs current-chat-id :metadata :sending-contact-request] nil) (assoc-in [:chat/inputs current-chat-id :metadata :sending-contact-request] nil)
(assoc-in [:chat/inputs current-chat-id :metadata :sending-image] nil) (assoc-in [:chat/inputs current-chat-id :metadata :sending-image] nil)
@@ -190,28 +190,28 @@
(assoc-in [:chat/inputs current-chat-id :metadata :responding-to-message] nil))} (assoc-in [:chat/inputs current-chat-id :metadata :responding-to-message] nil))}
(set-chat-input-text nil current-chat-id))) (set-chat-input-text nil current-chat-id)))
(fx/defn cancel-message-edit (rf/defn cancel-message-edit
"Cancels stage message edit" "Cancels stage message edit"
{:events [:chat.ui/cancel-message-edit]} {:events [:chat.ui/cancel-message-edit]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [current-chat-id (:current-chat-id db)] (let [current-chat-id (:current-chat-id db)]
(fx/merge cofx (rf/merge cofx
{:set-text-input-value [current-chat-id ""]} {:set-text-input-value [current-chat-id ""]}
(clean-input current-chat-id) (clean-input current-chat-id)
(mentions/clear-mentions) (mentions/clear-mentions)
(mentions/clear-cursor)))) (mentions/clear-cursor))))
(fx/defn send-messages [{:keys [db] :as cofx} input-text current-chat-id] (rf/defn send-messages [{:keys [db] :as cofx} input-text current-chat-id]
(let [image-messages (build-image-messages cofx current-chat-id) (let [image-messages (build-image-messages cofx current-chat-id)
text-message (build-text-message cofx input-text current-chat-id) text-message (build-text-message cofx input-text current-chat-id)
messages (keep identity (conj image-messages text-message))] messages (keep identity (conj image-messages text-message))]
(when (seq messages) (when (seq messages)
(fx/merge cofx (rf/merge cofx
(clean-input (:current-chat-id db)) (clean-input (:current-chat-id db))
(process-cooldown) (process-cooldown)
(chat.message/send-messages messages))))) (chat.message/send-messages messages)))))
(fx/defn send-my-status-message (rf/defn send-my-status-message
"when not empty, proceed by sending text message with public key topic" "when not empty, proceed by sending text message with public key topic"
{:events [:profile.ui/send-my-status-message]} {:events [:profile.ui/send-my-status-message]}
[{db :db :as cofx}] [{db :db :as cofx}]
@@ -221,11 +221,11 @@
text-message (build-text-message cofx input-text current-chat-id) text-message (build-text-message cofx input-text current-chat-id)
messages (keep identity (conj image-messages text-message))] messages (keep identity (conj image-messages text-message))]
(when (seq messages) (when (seq messages)
(fx/merge cofx (rf/merge cofx
(clean-input current-chat-id) (clean-input current-chat-id)
(chat.message/send-messages messages))))) (chat.message/send-messages messages)))))
(fx/defn send-audio-message (rf/defn send-audio-message
[cofx audio-path duration current-chat-id] [cofx audio-path duration current-chat-id]
(when-not (string/blank? audio-path) (when-not (string/blank? audio-path)
(chat.message/send-message cofx {:chat-id current-chat-id (chat.message/send-message cofx {:chat-id current-chat-id
@@ -234,7 +234,7 @@
:audio-duration-ms duration :audio-duration-ms duration
:text (i18n/label :t/update-to-listen-audio {"locale" "en"})}))) :text (i18n/label :t/update-to-listen-audio {"locale" "en"})})))
(fx/defn send-sticker-message (rf/defn send-sticker-message
[cofx {:keys [hash packID pack]} current-chat-id] [cofx {:keys [hash packID pack]} current-chat-id]
(when-not (or (string/blank? hash) (and (string/blank? packID) (string/blank? pack))) (when-not (or (string/blank? hash) (and (string/blank? packID) (string/blank? pack)))
(chat.message/send-message cofx {:chat-id current-chat-id (chat.message/send-message cofx {:chat-id current-chat-id
@@ -243,8 +243,8 @@
:pack (int (if (string/blank? packID) pack packID))} :pack (int (if (string/blank? packID) pack packID))}
:text (i18n/label :t/update-to-see-sticker {"locale" "en"})}))) :text (i18n/label :t/update-to-see-sticker {"locale" "en"})})))
(fx/defn send-edited-message [{:keys [db] :as cofx} text {:keys [message-id quoted-message]}] (rf/defn send-edited-message [{:keys [db] :as cofx} text {:keys [message-id quoted-message]}]
(fx/merge (rf/merge
cofx cofx
{::json-rpc/call [{:method "wakuext_editMessage" {::json-rpc/call [{:method "wakuext_editMessage"
:params [{:id message-id :params [{:id message-id
@@ -258,24 +258,24 @@
(cancel-message-edit) (cancel-message-edit)
(process-cooldown))) (process-cooldown)))
(fx/defn send-current-message (rf/defn send-current-message
"Sends message from current chat input" "Sends message from current chat input"
{:events [:chat.ui/send-current-message]} {:events [:chat.ui/send-current-message]}
[{{:keys [current-chat-id] :as db} :db :as cofx}] [{{:keys [current-chat-id] :as db} :db :as cofx}]
(let [{:keys [input-text metadata]} (get-in db [:chat/inputs current-chat-id]) (let [{:keys [input-text metadata]} (get-in db [:chat/inputs current-chat-id])
editing-message (:editing-message metadata) editing-message (:editing-message metadata)
input-text-with-mentions (mentions/check-mentions cofx input-text)] input-text-with-mentions (mentions/check-mentions cofx input-text)]
(fx/merge cofx (rf/merge cofx
(if editing-message (if editing-message
(send-edited-message input-text-with-mentions editing-message) (send-edited-message input-text-with-mentions editing-message)
(send-messages input-text-with-mentions current-chat-id)) (send-messages input-text-with-mentions current-chat-id))
(mentions/clear-mentions) (mentions/clear-mentions)
(mentions/clear-cursor)))) (mentions/clear-cursor))))
(fx/defn send-contact-request (rf/defn send-contact-request
{:events [:contacts/send-contact-request]} {:events [:contacts/send-contact-request]}
[{:keys [db] :as cofx} public-key message] [{:keys [db] :as cofx} public-key message]
(fx/merge cofx (rf/merge cofx
{:chat.ui/clear-inputs nil {:chat.ui/clear-inputs nil
:chat.ui/clear-inputs-old nil :chat.ui/clear-inputs-old nil
::json-rpc/call [{:method "wakuext_sendContactRequest" ::json-rpc/call [{:method "wakuext_sendContactRequest"
@@ -288,22 +288,22 @@
(clean-input (:current-chat-id db)) (clean-input (:current-chat-id db))
(process-cooldown))) (process-cooldown)))
(fx/defn cancel-contact-request (rf/defn cancel-contact-request
"Cancels contact request" "Cancels contact request"
{:events [:chat.ui/cancel-contact-request]} {:events [:chat.ui/cancel-contact-request]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [current-chat-id (:current-chat-id db)] (let [current-chat-id (:current-chat-id db)]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:chat/inputs current-chat-id :metadata :sending-contact-request] nil)} {:db (assoc-in db [:chat/inputs current-chat-id :metadata :sending-contact-request] nil)}
(mentions/clear-mentions) (mentions/clear-mentions)
(mentions/clear-cursor) (mentions/clear-cursor)
(clean-input (:current-chat-id db)) (clean-input (:current-chat-id db))
(process-cooldown)))) (process-cooldown))))
(fx/defn chat-send-sticker (rf/defn chat-send-sticker
{:events [:chat/send-sticker]} {:events [:chat/send-sticker]}
[{{:keys [current-chat-id] :as db} :db :as cofx} {:keys [hash packID pack] :as sticker}] [{{:keys [current-chat-id] :as db} :db :as cofx} {:keys [hash packID pack] :as sticker}]
(fx/merge (rf/merge
cofx cofx
{:db (update db {:db (update db
:stickers/recent-stickers :stickers/recent-stickers
@@ -314,7 +314,7 @@
:on-success #()}]} :on-success #()}]}
(send-sticker-message sticker current-chat-id))) (send-sticker-message sticker current-chat-id)))
(fx/defn chat-send-audio (rf/defn chat-send-audio
{:events [:chat/send-audio]} {:events [:chat/send-audio]}
[{{:keys [current-chat-id]} :db :as cofx} audio-path duration] [{{:keys [current-chat-id]} :db :as cofx} audio-path duration]
(send-audio-message cofx audio-path duration current-chat-id)) (send-audio-message cofx audio-path duration current-chat-id))
+14 -14
View File
@@ -1,15 +1,15 @@
(ns status-im.chat.models.link-preview (ns status-im.chat.models.link-preview
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.communities.core :as models.communities] [status-im.communities.core :as models.communities]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(fx/defn enable (rf/defn enable
{:events [::enable]} {:events [::enable]}
[{{:keys [multiaccount]} :db :as cofx} site enabled?] [{{:keys [multiaccount]} :db :as cofx} site enabled?]
(fx/merge cofx (rf/merge cofx
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:link-previews-enabled-sites :link-previews-enabled-sites
(if enabled? (if enabled?
@@ -17,10 +17,10 @@
(disj (get multiaccount :link-previews-enabled-sites #{}) site)) (disj (get multiaccount :link-previews-enabled-sites #{}) site))
{}))) {})))
(fx/defn enable-all (rf/defn enable-all
{:events [::enable-all]} {:events [::enable-all]}
[{{:keys [multiaccount]} :db :as cofx} link-previews-whitelist enabled?] [{{:keys [multiaccount]} :db :as cofx} link-previews-whitelist enabled?]
(fx/merge cofx (rf/merge cofx
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:link-previews-enabled-sites :link-previews-enabled-sites
(if enabled? (if enabled?
@@ -37,7 +37,7 @@
(defn community-resolving [db community-id] (defn community-resolving [db community-id]
(assoc-in db [:communities/resolve-community-info community-id] true)) (assoc-in db [:communities/resolve-community-info community-id] true))
(fx/defn handle-community-failed-to-resolve (rf/defn handle-community-failed-to-resolve
{:events [::community-failed-to-resolve]} {:events [::community-failed-to-resolve]}
[{:keys [db]} community-id] [{:keys [db]} community-id]
{:db (community-failed-to-resolve db community-id)}) {:db (community-failed-to-resolve db community-id)})
@@ -45,17 +45,17 @@
(defn community-link [id] (defn community-link [id]
(str "https://join.status.im/c/" id)) (str "https://join.status.im/c/" id))
(fx/defn handle-community-resolved (rf/defn handle-community-resolved
{:events [::community-resolved]} {:events [::community-resolved]}
[{:keys [db] :as cofx} community-id community] [{:keys [db] :as cofx} community-id community]
(fx/merge cofx (rf/merge cofx
(cond-> {:db (community-resolved db community-id)} (cond-> {:db (community-resolved db community-id)}
(some? community) (some? community)
(assoc :dispatch [::cache-link-preview-data (assoc :dispatch [::cache-link-preview-data
(community-link community-id) community])) (community-link community-id) community]))
(models.communities/handle-community community))) (models.communities/handle-community community)))
(fx/defn resolve-community-info (rf/defn resolve-community-info
{:events [::resolve-community-info]} {:events [::resolve-community-info]}
[{:keys [db]} community-id] [{:keys [db]} community-id]
{:db (community-resolving db community-id) {:db (community-resolving db community-id)
@@ -66,7 +66,7 @@
(re-frame/dispatch [::community-failed-to-resolve community-id]) (re-frame/dispatch [::community-failed-to-resolve community-id])
(log/error "Failed to request community info from mailserver"))}]}) (log/error "Failed to request community info from mailserver"))}]})
(fx/defn load-link-preview-data (rf/defn load-link-preview-data
{:events [::load-link-preview-data]} {:events [::load-link-preview-data]}
[cofx link] [cofx link]
{::json-rpc/call [{:method "wakuext_getLinkPreviewData" {::json-rpc/call [{:method "wakuext_getLinkPreviewData"
@@ -76,7 +76,7 @@
link link
{:error (str "Can't get preview data for " link)}])}]}) {:error (str "Can't get preview data for " link)}])}]})
(fx/defn cache-link-preview-data (rf/defn cache-link-preview-data
{:events [::cache-link-preview-data]} {:events [::cache-link-preview-data]}
[{{:keys [multiaccount]} :db :as cofx} site data] [{{:keys [multiaccount]} :db :as cofx} site data]
(multiaccounts.update/optimistic (multiaccounts.update/optimistic
@@ -90,7 +90,7 @@
(community-link id) (community-link id)
community])) community]))
(fx/defn should-suggest-link-preview (rf/defn should-suggest-link-preview
{:events [::should-suggest-link-preview]} {:events [::should-suggest-link-preview]}
[{:keys [db] :as cofx} enabled?] [{:keys [db] :as cofx} enabled?]
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
@@ -98,14 +98,14 @@
:link-preview-request-enabled (boolean enabled?) :link-preview-request-enabled (boolean enabled?)
{})) {}))
(fx/defn request-link-preview-whitelist (rf/defn request-link-preview-whitelist
[_] [_]
{::json-rpc/call [{:method "wakuext_getLinkPreviewWhitelist" {::json-rpc/call [{:method "wakuext_getLinkPreviewWhitelist"
:params [] :params []
:on-success #(re-frame/dispatch [::link-preview-whitelist-received %]) :on-success #(re-frame/dispatch [::link-preview-whitelist-received %])
:on-error #(log/error "Failed to get link preview whitelist")}]}) :on-error #(log/error "Failed to get link preview whitelist")}]})
(fx/defn save-link-preview-whitelist (rf/defn save-link-preview-whitelist
{:events [::link-preview-whitelist-received]} {:events [::link-preview-whitelist-received]}
[{:keys [db]} whitelist] [{:keys [db]} whitelist]
{:db (assoc db :link-previews-whitelist {:db (assoc db :link-previews-whitelist
+15 -15
View File
@@ -3,7 +3,7 @@
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.data-store.chats :as data-store.chats] [status-im.data-store.chats :as data-store.chats]
[status-im.data-store.messages :as data-store.messages] [status-im.data-store.messages :as data-store.messages]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.chat.models.message-list :as message-list] [status-im.chat.models.message-list :as message-list]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
@@ -18,7 +18,7 @@
clock-value clock-value
"0x0000000000000000000000000000000000000000000000000000000000000000")) "0x0000000000000000000000000000000000000000000000000000000000000000"))
(fx/defn update-chats-in-app-db (rf/defn update-chats-in-app-db
{:events [:chats-list/load-success]} {:events [:chats-list/load-success]}
[{:keys [db]} ^js new-chats-js] [{:keys [db]} ^js new-chats-js]
(let [{:keys [all-chats chats-home-list]} (let [{:keys [all-chats chats-home-list]}
@@ -37,20 +37,20 @@
:chats-home-list chats-home-list :chats-home-list chats-home-list
:chats/loading? false)})) :chats/loading? false)}))
(fx/defn load-chat-success (rf/defn load-chat-success
{:events [:chats-list/load-chat-success]} {:events [:chats-list/load-chat-success]}
[{:keys [db]} ^js chat] [{:keys [db]} ^js chat]
(let [{:keys [chat-id] :as chat} (data-store.chats/<-rpc chat)] (let [{:keys [chat-id] :as chat} (data-store.chats/<-rpc chat)]
{:db (update-in db [:chats chat-id] merge chat)})) {:db (update-in db [:chats chat-id] merge chat)}))
(fx/defn load-chat (rf/defn load-chat
[_ chat-id] [_ chat-id]
{::json-rpc/call [{:method "wakuext_chat" {::json-rpc/call [{:method "wakuext_chat"
:params [chat-id] :params [chat-id]
:on-success #(re-frame/dispatch [:chats-list/load-chat-success %]) :on-success #(re-frame/dispatch [:chats-list/load-chat-success %])
:on-error #(log/error "failed to fetch chats" 0 -1 %)}]}) :on-error #(log/error "failed to fetch chats" 0 -1 %)}]})
(fx/defn handle-failed-loading-messages (rf/defn handle-failed-loading-messages
{:events [::failed-loading-messages]} {:events [::failed-loading-messages]}
[{:keys [db]} current-chat-id _ err] [{:keys [db]} current-chat-id _ err]
(log/error "failed loading messages" current-chat-id err) (log/error "failed loading messages" current-chat-id err)
@@ -64,19 +64,19 @@
:unviewed-mentions-count 0 :unviewed-mentions-count 0
:highlight false)) :highlight false))
(fx/defn handle-mark-all-read-successful (rf/defn handle-mark-all-read-successful
{:events [::mark-all-read-successful]} {:events [::mark-all-read-successful]}
[cofx] [cofx]
(activity-center/notifications-fetch-unread-count cofx)) (activity-center/notifications-fetch-unread-count cofx))
(fx/defn handle-mark-all-read-in-community-successful (rf/defn handle-mark-all-read-in-community-successful
{:events [::mark-all-read-in-community-successful]} {:events [::mark-all-read-in-community-successful]}
[{:keys [db] :as cofx} chat-ids] [{:keys [db] :as cofx} chat-ids]
(fx/merge cofx (rf/merge cofx
{:db (reduce mark-chat-all-read db chat-ids)} {:db (reduce mark-chat-all-read db chat-ids)}
(activity-center/notifications-fetch-unread-count))) (activity-center/notifications-fetch-unread-count)))
(fx/defn handle-mark-all-read (rf/defn handle-mark-all-read
{:events [:chat.ui/mark-all-read-pressed :chat/mark-all-as-read]} {:events [:chat.ui/mark-all-read-pressed :chat/mark-all-as-read]}
[{db :db} chat-id] [{db :db} chat-id]
{:db (mark-chat-all-read db chat-id) {:db (mark-chat-all-read db chat-id)
@@ -86,7 +86,7 @@
:params [chat-id] :params [chat-id]
:on-success #(re-frame/dispatch [::mark-all-read-successful])}]}) :on-success #(re-frame/dispatch [::mark-all-read-successful])}]})
(fx/defn handle-mark-mark-all-read-in-community (rf/defn handle-mark-mark-all-read-in-community
{:events [:chat.ui/mark-all-read-in-community-pressed]} {:events [:chat.ui/mark-all-read-in-community-pressed]}
[{db :db} community-id] [{db :db} community-id]
(let [community-chat-ids (map #(str community-id %) (let [community-chat-ids (map #(str community-id %)
@@ -97,7 +97,7 @@
:params [community-id] :params [community-id]
:on-success #(re-frame/dispatch [::mark-all-read-in-community-successful %])}]})) :on-success #(re-frame/dispatch [::mark-all-read-in-community-successful %])}]}))
(fx/defn messages-loaded (rf/defn messages-loaded
"Loads more messages for current chat" "Loads more messages for current chat"
{:events [::messages-loaded]} {:events [::messages-loaded]}
[{db :db} chat-id session-id {:keys [cursor messages]}] [{db :db} chat-id session-id {:keys [cursor messages]}]
@@ -144,7 +144,7 @@
(empty? cursor)) (empty? cursor))
(update :contacts/contacts merge contacts))}))) (update :contacts/contacts merge contacts))})))
(fx/defn load-more-messages (rf/defn load-more-messages
{:events [:chat.ui/load-more-messages]} {:events [:chat.ui/load-more-messages]}
[{:keys [db]} chat-id first-request] [{:keys [db]} chat-id first-request]
(when-let [session-id (get-in db [:pagination-info chat-id :messages-initialized?])] (when-let [session-id (get-in db [:pagination-info chat-id :messages-initialized?])]
@@ -163,15 +163,15 @@
#(re-frame/dispatch [::messages-loaded chat-id session-id %]) #(re-frame/dispatch [::messages-loaded chat-id session-id %])
#(re-frame/dispatch [::failed-loading-messages chat-id session-id %])))))))) #(re-frame/dispatch [::failed-loading-messages chat-id session-id %]))))))))
(fx/defn load-more-messages-for-current-chat (rf/defn load-more-messages-for-current-chat
{:events [:chat.ui/load-more-messages-for-current-chat]} {:events [:chat.ui/load-more-messages-for-current-chat]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(load-more-messages cofx (:current-chat-id db) false)) (load-more-messages cofx (:current-chat-id db) false))
(fx/defn load-messages (rf/defn load-messages
[{:keys [db now] :as cofx} chat-id] [{:keys [db now] :as cofx} chat-id]
(when-not (get-in db [:pagination-info chat-id :messages-initialized?]) (when-not (get-in db [:pagination-info chat-id :messages-initialized?])
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:pagination-info chat-id :messages-initialized?] now) {:db (assoc-in db [:pagination-info chat-id :messages-initialized?] now)
:utils/dispatch-later [{:ms 50 :dispatch [:chat.ui/mark-all-read-pressed chat-id]} :utils/dispatch-later [{:ms 50 :dispatch [:chat.ui/mark-all-read-pressed chat-id]}
(when-not (get-in cofx [:db :chats chat-id :public?]) (when-not (get-in cofx [:db :chats chat-id :public?])
+11 -11
View File
@@ -2,7 +2,7 @@
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.contact.db :as contact.db] [status-im.contact.db :as contact.db]
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[taoensso.timbre :as log] [taoensso.timbre :as log]
@@ -489,7 +489,7 @@
(assoc-in [last-idx :to] (dec (count text))) (assoc-in [last-idx :to] (dec (count text)))
(assoc-in [last-idx :checked?] false))))))) (assoc-in [last-idx :checked?] false)))))))
(fx/defn on-text-input (rf/defn on-text-input
{:events [::on-text-input]} {:events [::on-text-input]}
[{:keys [db]} {:keys [previous-text start end] :as args}] [{:keys [db]} {:keys [previous-text start end] :as args}]
(log/debug "[mentions] on-text-input args" args) (log/debug "[mentions] on-text-input args" args)
@@ -533,7 +533,7 @@
[[:text (subs text 0 first-from)]])) [[:text (subs text 0 first-from)]]))
idxs)))) idxs))))
(fx/defn recheck-at-idxs (rf/defn recheck-at-idxs
[{:keys [db]} mentionable-users] [{:keys [db]} mentionable-users]
(let [chat-id (:current-chat-id db) (let [chat-id (:current-chat-id db)
text (get-in db [:chat/inputs chat-id :input-text]) text (get-in db [:chat/inputs chat-id :input-text])
@@ -551,7 +551,7 @@
:at-idxs new-at-idxs) :at-idxs new-at-idxs)
(assoc-in [:chat/inputs-with-mentions chat-id] calculated-input))})) (assoc-in [:chat/inputs-with-mentions chat-id] calculated-input))}))
(fx/defn calculate-suggestions (rf/defn calculate-suggestions
{:events [::calculate-suggestions]} {:events [::calculate-suggestions]}
[{:keys [db]} mentionable-users] [{:keys [db]} mentionable-users]
(let [chat-id (:current-chat-id db) (let [chat-id (:current-chat-id db)
@@ -616,31 +616,31 @@
" ")) " "))
(subs text mention-end)]))) (subs text mention-end)])))
(fx/defn clear-suggestions (rf/defn clear-suggestions
[{:keys [db]}] [{:keys [db]}]
(log/debug "[mentions] clear suggestions") (log/debug "[mentions] clear suggestions")
(let [chat-id (:current-chat-id db)] (let [chat-id (:current-chat-id db)]
{:db (update db :chats/mention-suggestions dissoc chat-id)})) {:db (update db :chats/mention-suggestions dissoc chat-id)}))
(fx/defn clear-mentions (rf/defn clear-mentions
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(log/debug "[mentions] clear mentions") (log/debug "[mentions] clear mentions")
(let [chat-id (:current-chat-id db)] (let [chat-id (:current-chat-id db)]
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(update-in [:chats/mentions chat-id] dissoc :mentions) (update-in [:chats/mentions chat-id] dissoc :mentions)
(update :chat/inputs-with-mentions dissoc chat-id))} (update :chat/inputs-with-mentions dissoc chat-id))}
(clear-suggestions)))) (clear-suggestions))))
(fx/defn clear-cursor (rf/defn clear-cursor
{:events [::clear-cursor]} {:events [::clear-cursor]}
[{:keys [db]}] [{:keys [db]}]
(log/debug "[mentions] clear cursor") (log/debug "[mentions] clear cursor")
{:db {:db
(update db :chats/cursor dissoc (:current-chat-id db))}) (update db :chats/cursor dissoc (:current-chat-id db))})
(fx/defn check-selection (rf/defn check-selection
{:events [::on-selection-change]} {:events [::on-selection-change]}
[{:keys [db] :as cofx} [{:keys [db] :as cofx}
{:keys [start end] :as selection} {:keys [start end] :as selection}
@@ -655,7 +655,7 @@
(<= (dec end) to)) (<= (dec end) to))
idx)) idx))
at-idxs) at-idxs)
(fx/merge (rf/merge
cofx cofx
{:db (update-in db [:chats/mentions chat-id :mentions] {:db (update-in db [:chats/mentions chat-id :mentions]
assoc assoc
@@ -673,7 +673,7 @@
(rn/find-node-handle (react/current-ref ref)) (rn/find-node-handle (react/current-ref ref))
cursor)))) cursor))))
(fx/defn reset-text-input-cursor (rf/defn reset-text-input-cursor
[_ ref cursor] [_ ref cursor]
{::reset-text-input-cursor [ref cursor]}) {::reset-text-input-cursor [ref cursor]})
+14 -14
View File
@@ -11,7 +11,7 @@
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.transport.message.protocol :as protocol] [status-im.transport.message.protocol :as protocol]
[status-im.ui.screens.chat.state :as view.state] [status-im.ui.screens.chat.state :as view.state]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.gfycat.core :as gfycat] [status-im.utils.gfycat.core :as gfycat]
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[status-im.utils.types :as types] [status-im.utils.types :as types]
@@ -36,7 +36,7 @@
;; TODO this is too expensive, probably we could mark message somehow and just hide it in the UI ;; TODO this is too expensive, probably we could mark message somehow and just hide it in the UI
(message-list/rebuild-message-list {:db (update-in db [:messages chat-id] dissoc message-id)} chat-id)) (message-list/rebuild-message-list {:db (update-in db [:messages chat-id] dissoc message-id)} chat-id))
(fx/defn add-senders-to-chat-users (rf/defn add-senders-to-chat-users
{:events [:chat/add-senders-to-chat-users]} {:events [:chat/add-senders-to-chat-users]}
[{:keys [db]} messages] [{:keys [db]} messages]
(reduce (fn [acc {:keys [chat-id alias name identicon from]}] (reduce (fn [acc {:keys [chat-id alias name identicon from]}]
@@ -155,42 +155,42 @@
(update-in [:message-lists constants/timeline-chat-id] message-list/add message))) (update-in [:message-lists constants/timeline-chat-id] message-list/add message)))
db))) db)))
(fx/defn process-statuses (rf/defn process-statuses
{:events [:process-statuses]} {:events [:process-statuses]}
[{:keys [db]} statuses] [{:keys [db]} statuses]
{:db (reduce reduce-js-statuses db statuses)}) {:db (reduce reduce-js-statuses db statuses)})
(fx/defn update-db-message-status (rf/defn update-db-message-status
[{:keys [db] :as cofx} chat-id message-id status] [{:keys [db] :as cofx} chat-id message-id status]
(when (get-in db [:messages chat-id message-id]) (when (get-in db [:messages chat-id message-id])
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db {:db (assoc-in db
[:messages chat-id message-id :outgoing-status] [:messages chat-id message-id :outgoing-status]
status)}))) status)})))
(fx/defn update-message-status (rf/defn update-message-status
[{:keys [db] :as cofx} chat-id message-id status] [{:keys [db] :as cofx} chat-id message-id status]
(fx/merge cofx (rf/merge cofx
(update-db-message-status chat-id message-id status))) (update-db-message-status chat-id message-id status)))
(fx/defn resend-message (rf/defn resend-message
[{:keys [db] :as cofx} chat-id message-id] [{:keys [db] :as cofx} chat-id message-id]
(fx/merge cofx (rf/merge cofx
{::json-rpc/call [{:method "wakuext_reSendChatMessage" {::json-rpc/call [{:method "wakuext_reSendChatMessage"
:params [message-id] :params [message-id]
:on-success #(log/debug "re-sent message successfully") :on-success #(log/debug "re-sent message successfully")
:on-error #(log/error "failed to re-send message" %)}]} :on-error #(log/error "failed to re-send message" %)}]}
(update-message-status chat-id message-id :sending))) (update-message-status chat-id message-id :sending)))
(fx/defn send-message (rf/defn send-message
[cofx message] [cofx message]
(protocol/send-chat-messages cofx [message])) (protocol/send-chat-messages cofx [message]))
(fx/defn send-messages (rf/defn send-messages
[cofx messages] [cofx messages]
(protocol/send-chat-messages cofx messages)) (protocol/send-chat-messages cofx messages))
(fx/defn handle-removed-messages (rf/defn handle-removed-messages
{:events [::handle-removed-messages]} {:events [::handle-removed-messages]}
[{:keys [db] :as cofx} removed-messages] [{:keys [db] :as cofx} removed-messages]
(let [mark-as-deleted-fx (->> removed-messages (let [mark-as-deleted-fx (->> removed-messages
@@ -206,7 +206,7 @@
removed-messages) removed-messages)
remove-messages-fx (fn [{:keys [db]}] remove-messages-fx (fn [{:keys [db]}]
{:dispatch [:activity-center.notifications/fetch-unread-count]})] {:dispatch [:activity-center.notifications/fetch-unread-count]})]
(apply fx/merge cofx (-> mark-as-deleted-fx (apply rf/merge cofx (-> mark-as-deleted-fx
(concat mark-as-seen-fx) (concat mark-as-seen-fx)
(conj remove-messages-fx))))) (conj remove-messages-fx)))))
@@ -223,7 +223,7 @@
(<= message-clock cleared-at)) (<= message-clock cleared-at))
messages))) messages)))
(fx/defn handle-cleared-histories-messages (rf/defn handle-cleared-histories-messages
{:events [::handle-cleared-hisotories-messages]} {:events [::handle-cleared-hisotories-messages]}
[{:keys [db]} cleared-histories] [{:keys [db]} cleared-histories]
{:db (reduce (fn [acc current] {:db (reduce (fn [acc current]
+2 -2
View File
@@ -2,7 +2,7 @@
(:require ["functional-red-black-tree" :as rb-tree] (:require ["functional-red-black-tree" :as rb-tree]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.utils.datetime :as time] [status-im.utils.datetime :as time]
[status-im.utils.fx :as fx])) [utils.re-frame :as rf]))
(defn- add-datemark [{:keys [whisper-timestamp] :as msg}] (defn- add-datemark [{:keys [whisper-timestamp] :as msg}]
;;TODO this is slow ;;TODO this is slow
@@ -187,7 +187,7 @@
[])) []))
;;TODO this is too expensive, probably we could mark message somehow and just hide it in the UI ;;TODO this is too expensive, probably we could mark message somehow and just hide it in the UI
(fx/defn rebuild-message-list (rf/defn rebuild-message-list
[{:keys [db]} chat-id] [{:keys [db]} chat-id]
{:db (assoc-in db [:message-lists chat-id] {:db (assoc-in db [:message-lists chat-id]
(add-many nil (vals (get-in db [:messages chat-id]))))}) (add-many nil (vals (get-in db [:messages chat-id]))))})
+7 -7
View File
@@ -1,7 +1,7 @@
(ns status-im.chat.models.reactions (ns status-im.chat.models.reactions
(:require [status-im.constants :as constants] (:require [status-im.constants :as constants]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.transport.message.protocol :as message.protocol] [status-im.transport.message.protocol :as message.protocol]
[status-im.data-store.reactions :as data-store.reactions])) [status-im.data-store.reactions :as data-store.reactions]))
@@ -32,12 +32,12 @@
(get-in db [:chats chat-id])] (get-in db [:chats chat-id])]
(>= deleted-at-clock-value clock-value))) (>= deleted-at-clock-value clock-value)))
(fx/defn receive-signal (rf/defn receive-signal
[{:keys [db] :as cofx} reactions] [{:keys [db] :as cofx} reactions]
(let [reactions (filter (partial earlier-than-deleted-at? cofx) reactions)] (let [reactions (filter (partial earlier-than-deleted-at? cofx) reactions)]
{:db (update db :reactions (process-reactions (:chats db)) reactions)})) {:db (update db :reactions (process-reactions (:chats db)) reactions)}))
(fx/defn load-more-reactions (rf/defn load-more-reactions
{:events [:load-more-reactions]} {:events [:load-more-reactions]}
[{:keys [db]} cursor chat-id] [{:keys [db]} cursor chat-id]
(when-let [session-id (get-in db [:pagination-info chat-id :messages-initialized?])] (when-let [session-id (get-in db [:pagination-info chat-id :messages-initialized?])]
@@ -48,7 +48,7 @@
#(re-frame/dispatch [::reactions-loaded chat-id session-id %]) #(re-frame/dispatch [::reactions-loaded chat-id session-id %])
#(log/error "failed loading reactions" chat-id %)))) #(log/error "failed loading reactions" chat-id %))))
(fx/defn reactions-loaded (rf/defn reactions-loaded
{:events [::reactions-loaded]} {:events [::reactions-loaded]}
[{db :db} [{db :db}
chat-id chat-id
@@ -64,19 +64,19 @@
;; Send reactions ;; Send reactions
(fx/defn send-emoji-reaction (rf/defn send-emoji-reaction
{:events [::send-emoji-reaction]} {:events [::send-emoji-reaction]}
[{{:keys [current-chat-id]} :db :as cofx} reaction] [{{:keys [current-chat-id]} :db :as cofx} reaction]
(message.protocol/send-reaction cofx (message.protocol/send-reaction cofx
(update reaction :chat-id #(or % current-chat-id)))) (update reaction :chat-id #(or % current-chat-id))))
(fx/defn send-retract-emoji-reaction (rf/defn send-retract-emoji-reaction
{:events [::send-emoji-reaction-retraction]} {:events [::send-emoji-reaction-retraction]}
[{{:keys [current-chat-id]} :db :as cofx} reaction] [{{:keys [current-chat-id]} :db :as cofx} reaction]
(message.protocol/send-retract-reaction cofx (message.protocol/send-retract-reaction cofx
(update reaction :chat-id #(or % current-chat-id)))) (update reaction :chat-id #(or % current-chat-id))))
(fx/defn receive-one (rf/defn receive-one
{:events [::receive-one]} {:events [::receive-one]}
[{:keys [db]} reaction] [{:keys [db]} reaction]
{:db (update db :reactions (process-reactions (:chats db)) [reaction])}) {:db (update db :reactions (process-reactions (:chats db)) [reaction])})
+4 -4
View File
@@ -1,14 +1,14 @@
;;this ns is needed because of cycled deps ;;this ns is needed because of cycled deps
(ns status-im.chat.models.transport (ns status-im.chat.models.transport
(:require [status-im.utils.fx :as fx] (:require [utils.re-frame :as rf]
[status-im.transport.message.core :as transport.message] [status-im.transport.message.core :as transport.message]
[status-im.chat.models.message :as chat.message])) [status-im.chat.models.message :as chat.message]))
(fx/defn chat-ui-resend-message (rf/defn chat-ui-resend-message
{:events [:chat.ui/resend-message]} {:events [:chat.ui/resend-message]}
[{:keys [db] :as cofx} chat-id message-id] [{:keys [db] :as cofx} chat-id message-id]
(let [message (get-in db [:messages chat-id message-id])] (let [message (get-in db [:messages chat-id message-id])]
(fx/merge (rf/merge
cofx cofx
(transport.message/set-message-envelope-hash chat-id message-id (:message-type message)) (transport.message/set-message-envelope-hash chat-id message-id (:message-type message))
(chat.message/resend-message chat-id message-id)))) (chat.message/resend-message chat-id message-id))))
+6 -6
View File
@@ -2,9 +2,9 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx])) [utils.re-frame :as rf]))
(fx/defn handle-prepare-accept-request-address-for-transaction (rf/defn handle-prepare-accept-request-address-for-transaction
{:events [::prepare-accept-request-address-for-transaction]} {:events [::prepare-accept-request-address-for-transaction]}
[{:keys [db]} message] [{:keys [db]} message]
{:db (assoc db {:db (assoc db
@@ -13,13 +13,13 @@
:from (ethereum/get-default-account (:multiaccount/accounts db))}) :from (ethereum/get-default-account (:multiaccount/accounts db))})
:show-select-acc-sheet nil}) :show-select-acc-sheet nil})
(fx/defn set-selected-account (rf/defn set-selected-account
{:events [::set-selected-account]} {:events [::set-selected-account]}
[{:keys [db]} _ account] [{:keys [db]} _ account]
{:db (-> (assoc-in db [:commands/select-account :from] account) {:db (-> (assoc-in db [:commands/select-account :from] account)
(assoc :bottom-sheet/show? false))}) (assoc :bottom-sheet/show? false))})
(fx/defn handle-accept-request-address-for-transaction (rf/defn handle-accept-request-address-for-transaction
{:events [::accept-request-address-for-transaction]} {:events [::accept-request-address-for-transaction]}
[{:keys [db]} message-id address] [{:keys [db]} message-id address]
{:db (dissoc db :commands/select-account) {:db (dissoc db :commands/select-account)
@@ -28,7 +28,7 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:transport/message-sent %])}]}) :on-success #(re-frame/dispatch [:transport/message-sent %])}]})
(fx/defn handle-decline-request-address-for-transaction (rf/defn handle-decline-request-address-for-transaction
{:events [::decline-request-address-for-transaction]} {:events [::decline-request-address-for-transaction]}
[_ message-id] [_ message-id]
{::json-rpc/call [{:method "wakuext_declineRequestAddressForTransaction" {::json-rpc/call [{:method "wakuext_declineRequestAddressForTransaction"
@@ -36,7 +36,7 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:transport/message-sent %])}]}) :on-success #(re-frame/dispatch [:transport/message-sent %])}]})
(fx/defn handle-decline-request-transaction (rf/defn handle-decline-request-transaction
{:events [::decline-request-transaction]} {:events [::decline-request-transaction]}
[cofx message-id] [cofx message-id]
{::json-rpc/call [{:method "wakuext_declineRequestTransaction" {::json-rpc/call [{:method "wakuext_declineRequestTransaction"
+86 -87
View File
@@ -6,14 +6,13 @@
[clojure.set :as clojure.set] [clojure.set :as clojure.set]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.async-storage.core :as async-storage] [status-im.async-storage.core :as async-storage]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.bottom-sheet.core :as bottom-sheet] [status-im.bottom-sheet.core :as bottom-sheet]
[status-im.utils.universal-links.core :as universal-links] [status-im.utils.universal-links.core :as universal-links]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[quo.design-system.colors :as colors] [quo.design-system.colors :as colors]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.handlers :refer [>evt]]
[status-im.ui.components.emoji-thumbnail.styles :as emoji-thumbnail-styles] [status-im.ui.components.emoji-thumbnail.styles :as emoji-thumbnail-styles]
[status-im2.contexts.activity-center.events :as activity-center])) [status-im2.contexts.activity-center.events :as activity-center]))
@@ -73,22 +72,22 @@
(defn fetch-community-id-input [{:keys [db]}] (defn fetch-community-id-input [{:keys [db]}]
(:communities/community-id-input db)) (:communities/community-id-input db))
(fx/defn handle-request-to-join [{:keys [db]} r] (rf/defn handle-request-to-join [{:keys [db]} r]
(let [{:keys [id community-id] :as request} (<-request-to-join-community-rpc r)] (let [{:keys [id community-id] :as request} (<-request-to-join-community-rpc r)]
{:db (assoc-in db [:communities/requests-to-join community-id id] request)})) {:db (assoc-in db [:communities/requests-to-join community-id id] request)}))
(fx/defn handle-removed-chats [{:keys [db]} chat-ids] (rf/defn handle-removed-chats [{:keys [db]} chat-ids]
{:db (reduce (fn [db chat-id] {:db (reduce (fn [db chat-id]
(update db :chats dissoc chat-id)) (update db :chats dissoc chat-id))
db db
chat-ids)}) chat-ids)})
(fx/defn handle-community (rf/defn handle-community
[{:keys [db]} {:keys [id] :as community}] [{:keys [db]} {:keys [id] :as community}]
(when id (when id
{:db (assoc-in db [:communities id] (<-rpc community))})) {:db (assoc-in db [:communities id] (<-rpc community))}))
(fx/defn handle-communities (rf/defn handle-communities
{:events [::fetched]} {:events [::fetched]}
[{:keys [db]} communities] [{:keys [db]} communities]
{:db (reduce (fn [db {:keys [id] :as community}] {:db (reduce (fn [db {:keys [id] :as community}]
@@ -96,23 +95,23 @@
db db
communities)}) communities)})
(fx/defn handle-response [_ response-js] (rf/defn handle-response [_ response-js]
{:dispatch [:sanitize-messages-and-process-response response-js]}) {:dispatch [:sanitize-messages-and-process-response response-js]})
(fx/defn left (rf/defn left
{:events [::left]} {:events [::left]}
[cofx response-js] [cofx response-js]
(fx/merge cofx (rf/merge cofx
(handle-response cofx response-js) (handle-response cofx response-js)
(navigation/pop-to-root-tab :chat-stack) (navigation/pop-to-root-tab :chat-stack)
(activity-center/notifications-fetch-unread-count))) (activity-center/notifications-fetch-unread-count)))
(fx/defn joined (rf/defn joined
{:events [::joined ::requested-to-join]} {:events [::joined ::requested-to-join]}
[cofx response-js] [cofx response-js]
(handle-response cofx response-js)) (handle-response cofx response-js))
(fx/defn export (rf/defn export
{:events [::export-pressed]} {:events [::export-pressed]}
[cofx community-id] [cofx community-id]
{::json-rpc/call [{:method "wakuext_exportCommunity" {::json-rpc/call [{:method "wakuext_exportCommunity"
@@ -123,7 +122,7 @@
(log/error "failed to export community" community-id %) (log/error "failed to export community" community-id %)
(re-frame/dispatch [::failed-to-export %]))}]}) (re-frame/dispatch [::failed-to-export %]))}]})
(fx/defn import-community (rf/defn import-community
{:events [::import]} {:events [::import]}
[cofx community-key] [cofx community-key]
{::json-rpc/call [{:method "wakuext_importCommunity" {::json-rpc/call [{:method "wakuext_importCommunity"
@@ -134,7 +133,7 @@
(log/error "failed to import community" %) (log/error "failed to import community" %)
(re-frame/dispatch [::failed-to-import %]))}]}) (re-frame/dispatch [::failed-to-import %]))}]})
(fx/defn join (rf/defn join
{:events [:communities/join]} {:events [:communities/join]}
[cofx community-id] [cofx community-id]
{::json-rpc/call [{:method "wakuext_joinCommunity" {::json-rpc/call [{:method "wakuext_joinCommunity"
@@ -145,7 +144,7 @@
(log/error "failed to join community" community-id %) (log/error "failed to join community" community-id %)
(re-frame/dispatch [::failed-to-join %]))}]}) (re-frame/dispatch [::failed-to-join %]))}]})
(fx/defn request-to-join (rf/defn request-to-join
{:events [::request-to-join]} {:events [::request-to-join]}
[cofx community-id] [cofx community-id]
{::json-rpc/call [{:method "wakuext_requestToJoinCommunity" {::json-rpc/call [{:method "wakuext_requestToJoinCommunity"
@@ -156,7 +155,7 @@
(log/error "failed to request to join community" community-id %) (log/error "failed to request to join community" community-id %)
(re-frame/dispatch [::failed-to-request-to-join %]))}]}) (re-frame/dispatch [::failed-to-request-to-join %]))}]})
(fx/defn leave (rf/defn leave
{:events [:communities/leave]} {:events [:communities/leave]}
[{:keys [db]} community-id] [{:keys [db]} community-id]
(let [community-chat-ids (map #(str community-id %) (let [community-chat-ids (map #(str community-id %)
@@ -171,7 +170,7 @@
(log/error "failed to leave community" community-id %) (log/error "failed to leave community" community-id %)
(re-frame/dispatch [::failed-to-leave %]))}]})) (re-frame/dispatch [::failed-to-leave %]))}]}))
(fx/defn fetch [_] (rf/defn fetch [_]
{::json-rpc/call [{:method "wakuext_communities" {::json-rpc/call [{:method "wakuext_communities"
:params [] :params []
:on-success #(re-frame/dispatch [::fetched %]) :on-success #(re-frame/dispatch [::fetched %])
@@ -179,7 +178,7 @@
(log/error "failed to fetch communities" %) (log/error "failed to fetch communities" %)
(re-frame/dispatch [::failed-to-fetch %]))}]}) (re-frame/dispatch [::failed-to-fetch %]))}]})
(fx/defn chat-created (rf/defn chat-created
{:events [::chat-created]} {:events [::chat-created]}
[_ community-id user-pk] [_ community-id user-pk]
{::json-rpc/call [{:method "wakuext_sendChatMessage" {::json-rpc/call [{:method "wakuext_sendChatMessage"
@@ -193,7 +192,7 @@
:on-error :on-error
#(log/error "failed to send a message" %)}]}) #(log/error "failed to send a message" %)}]})
(fx/defn invite-users (rf/defn invite-users
{:events [::invite-people-confirmation-pressed]} {:events [::invite-people-confirmation-pressed]}
[cofx user-pk contacts] [cofx user-pk contacts]
(let [community-id (fetch-community-id-input cofx) (let [community-id (fetch-community-id-input cofx)
@@ -209,7 +208,7 @@
:on-error #(do :on-error #(do
(log/error "failed to invite-user community" %) (log/error "failed to invite-user community" %)
(re-frame/dispatch [::failed-to-invite-people %]))}]}))) (re-frame/dispatch [::failed-to-invite-people %]))}]})))
(fx/defn share-community (rf/defn share-community
{:events [::share-community-confirmation-pressed]} {:events [::share-community-confirmation-pressed]}
[cofx user-pk contacts] [cofx user-pk contacts]
(let [community-id (fetch-community-id-input cofx) (let [community-id (fetch-community-id-input cofx)
@@ -226,7 +225,7 @@
(log/error "failed to invite-user community" %) (log/error "failed to invite-user community" %)
(re-frame/dispatch [::failed-to-share-community %]))}]}))) (re-frame/dispatch [::failed-to-share-community %]))}]})))
(fx/defn create (rf/defn create
{:events [::create-confirmation-pressed]} {:events [::create-confirmation-pressed]}
[{:keys [db]}] [{:keys [db]}]
(let [{:keys [name description membership image]} (get db :communities/create)] (let [{:keys [name description membership image]} (get db :communities/create)]
@@ -248,7 +247,7 @@
(log/error "failed to create community" %) (log/error "failed to create community" %)
(re-frame/dispatch [::failed-to-create-community %]))}]}))) (re-frame/dispatch [::failed-to-create-community %]))}]})))
(fx/defn edit (rf/defn edit
{:events [::edit-confirmation-pressed]} {:events [::edit-confirmation-pressed]}
[{:keys [db]}] [{:keys [db]}]
(let [{:keys [id name description membership new-image color]} (get db :communities/create)] (let [{:keys [id name description membership new-image color]} (get db :communities/create)]
@@ -268,7 +267,7 @@
(log/error "failed to edit community" %) (log/error "failed to edit community" %)
(re-frame/dispatch [::failed-to-edit-community %]))}]})) (re-frame/dispatch [::failed-to-edit-community %]))}]}))
(fx/defn create-channel (rf/defn create-channel
{:events [::create-channel-confirmation-pressed]} {:events [::create-channel-confirmation-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [community-id (fetch-community-id-input cofx) (let [community-id (fetch-community-id-input cofx)
@@ -291,7 +290,7 @@
(defn to-community-chat-id [chat-id] (defn to-community-chat-id [chat-id]
(subs chat-id community-chat-id-length)) (subs chat-id community-chat-id-length))
(fx/defn edit-channel (rf/defn edit-channel
{:events [::edit-channel-confirmation-pressed]} {:events [::edit-channel-confirmation-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [name description color community-id emoji edit-channel-id category-id position]} (let [{:keys [name description color community-id emoji edit-channel-id category-id position]}
@@ -319,44 +318,44 @@
(let [chat-id (to-community-chat-id local-chat-id)] (let [chat-id (to-community-chat-id local-chat-id)]
(get-in community [:chats chat-id :can-post?]))) (get-in community [:chats chat-id :can-post?])))
(fx/defn reset-community-id-input [{:keys [db]} id] (rf/defn reset-community-id-input [{:keys [db]} id]
{:db (assoc db :communities/community-id-input id)}) {:db (assoc db :communities/community-id-input id)})
(fx/defn reset-channel-info [{:keys [db]}] (rf/defn reset-channel-info [{:keys [db]}]
{:db (assoc db :communities/create-channel {})}) {:db (assoc db :communities/create-channel {})})
(fx/defn invite-people-pressed (rf/defn invite-people-pressed
{:events [:communities/invite-people-pressed]} {:events [:communities/invite-people-pressed]}
[cofx id] [cofx id]
(fx/merge cofx (rf/merge cofx
(reset-community-id-input id) (reset-community-id-input id)
(bottom-sheet/hide-bottom-sheet) (bottom-sheet/hide-bottom-sheet)
(navigation/open-modal :invite-people-community {:invite? true}))) (navigation/open-modal :invite-people-community {:invite? true})))
(fx/defn share-community-pressed (rf/defn share-community-pressed
{:events [:communities/share-community-pressed]} {:events [:communities/share-community-pressed]}
[cofx id] [cofx id]
(fx/merge cofx (rf/merge cofx
(reset-community-id-input id) (reset-community-id-input id)
(bottom-sheet/hide-bottom-sheet) (bottom-sheet/hide-bottom-sheet)
(navigation/open-modal :invite-people-community {}))) (navigation/open-modal :invite-people-community {})))
(fx/defn create-channel-pressed (rf/defn create-channel-pressed
{:events [::create-channel-pressed]} {:events [::create-channel-pressed]}
[{:keys [db] :as cofx} id] [{:keys [db] :as cofx} id]
(fx/merge cofx (rf/merge cofx
(reset-community-id-input id) (reset-community-id-input id)
(reset-channel-info) (reset-channel-info)
(>evt [::create-channel-fields (rand-nth emoji-thumbnail-styles/emoji-picker-default-thumbnails)]) (rf/dispatch [::create-channel-fields (rand-nth emoji-thumbnail-styles/emoji-picker-default-thumbnails)])
(navigation/open-modal :create-community-channel {:community-id id}))) (navigation/open-modal :create-community-channel {:community-id id})))
(fx/defn edit-channel-pressed (rf/defn edit-channel-pressed
{:events [::edit-channel-pressed]} {:events [::edit-channel-pressed]}
[{:keys [db] :as cofx} community-id chat-name description color emoji chat-id category-id position] [{:keys [db] :as cofx} community-id chat-name description color emoji chat-id category-id position]
(let [{:keys [color emoji]} (if (string/blank? emoji) (let [{:keys [color emoji]} (if (string/blank? emoji)
(rand-nth emoji-thumbnail-styles/emoji-picker-default-thumbnails) (rand-nth emoji-thumbnail-styles/emoji-picker-default-thumbnails)
{:color color :emoji emoji})] {:color color :emoji emoji})]
(fx/merge cofx (rf/merge cofx
{:db (assoc db :communities/create-channel {:name chat-name {:db (assoc db :communities/create-channel {:name chat-name
:description description :description description
:color color :color color
@@ -367,33 +366,33 @@
:position position})} :position position})}
(navigation/open-modal :edit-community-channel nil)))) (navigation/open-modal :edit-community-channel nil))))
(fx/defn community-created (rf/defn community-created
{:events [::community-created]} {:events [::community-created]}
[cofx response-js] [cofx response-js]
(fx/merge cofx (rf/merge cofx
(navigation/navigate-back) (navigation/navigate-back)
(handle-response response-js))) (handle-response response-js)))
(fx/defn community-edited (rf/defn community-edited
{:events [::community-edited]} {:events [::community-edited]}
[cofx response-js] [cofx response-js]
(fx/merge cofx (rf/merge cofx
(navigation/navigate-back) (navigation/navigate-back)
(handle-response response-js))) (handle-response response-js)))
(fx/defn open-create-community (rf/defn open-create-community
{:events [::open-create-community]} {:events [::open-create-community]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc db :communities/create {:membership constants/community-no-membership-access})} {:db (assoc db :communities/create {:membership constants/community-no-membership-access})}
(navigation/navigate-to :community-create nil))) (navigation/navigate-to :community-create nil)))
(fx/defn open-edit-community (rf/defn open-edit-community
{:events [::open-edit-community]} {:events [::open-edit-community]}
[{:keys [db] :as cofx} id] [{:keys [db] :as cofx} id]
(let [{:keys [name description images permissions color]} (get-in db [:communities id]) (let [{:keys [name description images permissions color]} (get-in db [:communities id])
{:keys [access]} permissions] {:keys [access]} permissions]
(fx/merge cofx (rf/merge cofx
{:db (assoc db :communities/create {:id id {:db (assoc db :communities/create {:id id
:name name :name name
:description description :description description
@@ -403,63 +402,63 @@
:editing? true})} :editing? true})}
(navigation/navigate-to :community-edit nil)))) (navigation/navigate-to :community-edit nil))))
(fx/defn community-imported (rf/defn community-imported
{:events [::community-imported]} {:events [::community-imported]}
[cofx response-js] [cofx response-js]
(fx/merge cofx (rf/merge cofx
(navigation/navigate-back) (navigation/navigate-back)
(handle-response response-js))) (handle-response response-js)))
(fx/defn people-invited (rf/defn people-invited
{:events [::people-invited]} {:events [::people-invited]}
[cofx response-js] [cofx response-js]
(fx/merge cofx (rf/merge cofx
(navigation/navigate-back) (navigation/navigate-back)
(handle-response response-js))) (handle-response response-js)))
(fx/defn community-channel-created (rf/defn community-channel-created
{:events [::community-channel-created]} {:events [::community-channel-created]}
[cofx response-js] [cofx response-js]
(fx/merge cofx (rf/merge cofx
(navigation/navigate-back) (navigation/navigate-back)
(handle-response response-js))) (handle-response response-js)))
(fx/defn community-channel-edited (rf/defn community-channel-edited
{:events [::community-channel-edited]} {:events [::community-channel-edited]}
[cofx response-js] [cofx response-js]
(fx/merge cofx (rf/merge cofx
(navigation/navigate-back) (navigation/navigate-back)
(handle-response response-js))) (handle-response response-js)))
(fx/defn create-field (rf/defn create-field
{:events [::create-field]} {:events [::create-field]}
[{:keys [db]} field value] [{:keys [db]} field value]
{:db (assoc-in db [:communities/create field] value)}) {:db (assoc-in db [:communities/create field] value)})
(fx/defn remove-field (rf/defn remove-field
{:events [::remove-field]} {:events [::remove-field]}
[{:keys [db]} field] [{:keys [db]} field]
{:db (update-in db [:communities/create] dissoc field)}) {:db (update-in db [:communities/create] dissoc field)})
(fx/defn create-channel-field (rf/defn create-channel-field
{:events [::create-channel-field]} {:events [::create-channel-field]}
[{:keys [db]} field value] [{:keys [db]} field value]
{:db (assoc-in db [:communities/create-channel field] value)}) {:db (assoc-in db [:communities/create-channel field] value)})
(fx/defn create-channel-fields (rf/defn create-channel-fields
{:events [::create-channel-fields]} {:events [::create-channel-fields]}
[{:keys [db]} field-values] [{:keys [db]} field-values]
{:db (update-in db [:communities/create-channel] merge field-values)}) {:db (update-in db [:communities/create-channel] merge field-values)})
(fx/defn member-banned (rf/defn member-banned
{:events [::member-banned]} {:events [::member-banned]}
[cofx response-js] [cofx response-js]
(fx/merge cofx (rf/merge cofx
(bottom-sheet/hide-bottom-sheet) (bottom-sheet/hide-bottom-sheet)
(handle-response response-js) (handle-response response-js)
(activity-center/notifications-fetch-unread-count))) (activity-center/notifications-fetch-unread-count)))
(fx/defn member-ban (rf/defn member-ban
{:events [::member-ban]} {:events [::member-ban]}
[cofx community-id public-key] [cofx community-id public-key]
{::json-rpc/call [{:method "wakuext_banUserFromCommunity" {::json-rpc/call [{:method "wakuext_banUserFromCommunity"
@@ -469,14 +468,14 @@
:on-success #(re-frame/dispatch [::member-banned %]) :on-success #(re-frame/dispatch [::member-banned %])
:on-error #(log/error "failed to ban user from community" community-id public-key %)}]}) :on-error #(log/error "failed to ban user from community" community-id public-key %)}]})
(fx/defn member-kicked (rf/defn member-kicked
{:events [::member-kicked]} {:events [::member-kicked]}
[cofx response-js] [cofx response-js]
(fx/merge cofx (rf/merge cofx
(bottom-sheet/hide-bottom-sheet) (bottom-sheet/hide-bottom-sheet)
(handle-response response-js))) (handle-response response-js)))
(fx/defn member-kick (rf/defn member-kick
{:events [::member-kick]} {:events [::member-kick]}
[cofx community-id public-key] [cofx community-id public-key]
{::json-rpc/call [{:method "wakuext_removeUserFromCommunity" {::json-rpc/call [{:method "wakuext_removeUserFromCommunity"
@@ -485,17 +484,17 @@
:on-success #(re-frame/dispatch [::member-kicked %]) :on-success #(re-frame/dispatch [::member-kicked %])
:on-error #(log/error "failed to remove user from community" community-id public-key %)}]}) :on-error #(log/error "failed to remove user from community" community-id public-key %)}]})
(fx/defn delete-community (rf/defn delete-community
{:events [::delete-community]} {:events [::delete-community]}
[cofx community-id] [cofx community-id]
(log/error "Community delete is not yet implemented")) (log/error "Community delete is not yet implemented"))
(fx/defn requests-to-join-fetched (rf/defn requests-to-join-fetched
{:events [::requests-to-join-fetched]} {:events [::requests-to-join-fetched]}
[{:keys [db]} community-id requests] [{:keys [db]} community-id requests]
{:db (assoc-in db [:communities/requests-to-join community-id] (<-requests-to-join-community-rpc requests))}) {:db (assoc-in db [:communities/requests-to-join community-id] (<-requests-to-join-community-rpc requests))})
(fx/defn fetch-requests-to-join (rf/defn fetch-requests-to-join
{:events [::fetch-requests-to-join]} {:events [::fetch-requests-to-join]}
[cofx community-id] [cofx community-id]
{::json-rpc/call [{:method "wakuext_pendingRequestsToJoinForCommunity" {::json-rpc/call [{:method "wakuext_pendingRequestsToJoinForCommunity"
@@ -506,21 +505,21 @@
(defn fetch-requests-to-join! [community-id] (defn fetch-requests-to-join! [community-id]
(re-frame/dispatch [::fetch-requests-to-join community-id])) (re-frame/dispatch [::fetch-requests-to-join community-id]))
(fx/defn request-to-join-accepted (rf/defn request-to-join-accepted
{:events [::request-to-join-accepted]} {:events [::request-to-join-accepted]}
[{:keys [db] :as cofx} community-id request-id response-js] [{:keys [db] :as cofx} community-id request-id response-js]
(fx/merge cofx (rf/merge cofx
{:db (update-in db [:communities/requests-to-join community-id] dissoc request-id)} {:db (update-in db [:communities/requests-to-join community-id] dissoc request-id)}
(handle-response response-js))) (handle-response response-js)))
(fx/defn request-to-join-declined (rf/defn request-to-join-declined
{:events [::request-to-join-declined]} {:events [::request-to-join-declined]}
[{:keys [db] :as cofx} community-id request-id response-js] [{:keys [db] :as cofx} community-id request-id response-js]
(fx/merge cofx (rf/merge cofx
{:db (update-in db [:communities/requests-to-join community-id] dissoc request-id)} {:db (update-in db [:communities/requests-to-join community-id] dissoc request-id)}
(handle-response response-js))) (handle-response response-js)))
(fx/defn accept-request-to-join-pressed (rf/defn accept-request-to-join-pressed
{:events [:communities.ui/accept-request-to-join-pressed]} {:events [:communities.ui/accept-request-to-join-pressed]}
[cofx community-id request-id] [cofx community-id request-id]
{::json-rpc/call [{:method "wakuext_acceptRequestToJoinCommunity" {::json-rpc/call [{:method "wakuext_acceptRequestToJoinCommunity"
@@ -529,7 +528,7 @@
:on-success #(re-frame/dispatch [::request-to-join-accepted community-id request-id %]) :on-success #(re-frame/dispatch [::request-to-join-accepted community-id request-id %])
:on-error #(log/error "failed to accept requests-to-join" community-id request-id %)}]}) :on-error #(log/error "failed to accept requests-to-join" community-id request-id %)}]})
(fx/defn decline-request-to-join-pressed (rf/defn decline-request-to-join-pressed
{:events [:communities.ui/decline-request-to-join-pressed]} {:events [:communities.ui/decline-request-to-join-pressed]}
[cofx community-id request-id] [cofx community-id request-id]
{::json-rpc/call [{:method "wakuext_declineRequestToJoinCommunity" {::json-rpc/call [{:method "wakuext_declineRequestToJoinCommunity"
@@ -538,13 +537,13 @@
:on-success #(re-frame/dispatch [::request-to-join-declined community-id request-id %]) :on-success #(re-frame/dispatch [::request-to-join-declined community-id request-id %])
:on-error #(log/error "failed to decline requests-to-join" community-id request-id)}]}) :on-error #(log/error "failed to decline requests-to-join" community-id request-id)}]})
(fx/defn switch-communities-enabled (rf/defn switch-communities-enabled
{:events [:multiaccounts.ui/switch-communities-enabled]} {:events [:multiaccounts.ui/switch-communities-enabled]}
[{:keys [db]} enabled?] [{:keys [db]} enabled?]
{::async-storage/set! {:communities-enabled? enabled?} {::async-storage/set! {:communities-enabled? enabled?}
:db (assoc db :communities/enabled? enabled?)}) :db (assoc db :communities/enabled? enabled?)})
(fx/defn create-category (rf/defn create-category
{:events [::create-category-confirmation-pressed]} {:events [::create-category-confirmation-pressed]}
[_ community-id category-title chat-ids] [_ community-id category-title chat-ids]
{::json-rpc/call [{:method "wakuext_createCommunityCategory" {::json-rpc/call [{:method "wakuext_createCommunityCategory"
@@ -557,7 +556,7 @@
(re-frame/dispatch [:sanitize-messages-and-process-response %])) (re-frame/dispatch [:sanitize-messages-and-process-response %]))
:on-error #(log/error "failed to create community category" %)}]}) :on-error #(log/error "failed to create community category" %)}]})
(fx/defn remove-chat-from-category (rf/defn remove-chat-from-category
{:events [:remove-chat-from-community-category]} {:events [:remove-chat-from-community-category]}
[{:keys [db]} community-id id categoryID] [{:keys [db]} community-id id categoryID]
(let [category (get-in db [:communities community-id :categories categoryID]) (let [category (get-in db [:communities community-id :categories categoryID])
@@ -572,7 +571,7 @@
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %]) :on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
:on-error #(log/error "failed to remove chat from community" %)}]})) :on-error #(log/error "failed to remove chat from community" %)}]}))
(fx/defn delete-community-chat (rf/defn delete-community-chat
{:events [:delete-community-chat]} {:events [:delete-community-chat]}
[_ community-id chat-id] [_ community-id chat-id]
{::json-rpc/call [{:method "wakuext_deleteCommunityChat" {::json-rpc/call [{:method "wakuext_deleteCommunityChat"
@@ -581,7 +580,7 @@
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %]) :on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
:on-error #(log/error "failed to delete community chat" %)}]}) :on-error #(log/error "failed to delete community chat" %)}]})
(fx/defn delete-category (rf/defn delete-category
{:events [:delete-community-category]} {:events [:delete-community-category]}
[_ community-id category-id] [_ community-id category-id]
{::json-rpc/call [{:method "wakuext_deleteCommunityCategory" {::json-rpc/call [{:method "wakuext_deleteCommunityCategory"
@@ -591,7 +590,7 @@
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %]) :on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
:on-error #(log/error "failed to delete community category" %)}]}) :on-error #(log/error "failed to delete community category" %)}]})
(fx/defn change-category (rf/defn change-category
{:events [::change-category-confirmation-pressed]} {:events [::change-category-confirmation-pressed]}
[cofx community-id category-id {:keys [id position categoryID]}] [cofx community-id category-id {:keys [id position categoryID]}]
(if (not (string/blank? category-id)) (if (not (string/blank? category-id))
@@ -605,11 +604,11 @@
(re-frame/dispatch [:navigate-back]) (re-frame/dispatch [:navigate-back])
(re-frame/dispatch [:sanitize-messages-and-process-response %])) (re-frame/dispatch [:sanitize-messages-and-process-response %]))
:on-error #(log/error "failed to change community category" %)}]} :on-error #(log/error "failed to change community category" %)}]}
(fx/merge cofx (rf/merge cofx
(navigation/navigate-back) (navigation/navigate-back)
(remove-chat-from-category community-id id categoryID)))) (remove-chat-from-category community-id id categoryID))))
(fx/defn reorder-category-chat (rf/defn reorder-category-chat
{:events [::reorder-community-category-chat]} {:events [::reorder-community-category-chat]}
[_ community-id category-id chat-id new-position] [_ community-id category-id chat-id new-position]
{::json-rpc/call [{:method "wakuext_reorderCommunityChat" {::json-rpc/call [{:method "wakuext_reorderCommunityChat"
@@ -621,7 +620,7 @@
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %]) :on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
:on-error #(log/error "failed to reorder community category chat" %)}]}) :on-error #(log/error "failed to reorder community category chat" %)}]})
(fx/defn reorder-category (rf/defn reorder-category
{:events [::reorder-community-category]} {:events [::reorder-community-category]}
[_ community-id category-id new-position] [_ community-id category-id new-position]
{::json-rpc/call [{:method "wakuext_reorderCommunityCategories" {::json-rpc/call [{:method "wakuext_reorderCommunityCategories"
@@ -635,14 +634,14 @@
(defn category-hash [public-key community-id category-id] (defn category-hash [public-key community-id category-id]
(hash (str public-key community-id category-id))) (hash (str public-key community-id category-id)))
(fx/defn store-category-state (rf/defn store-category-state
{:events [::store-category-state]} {:events [::store-category-state]}
[{:keys [db]} community-id category-id state-open?] [{:keys [db]} community-id category-id state-open?]
(let [public-key (get-in db [:multiaccount :public-key]) (let [public-key (get-in db [:multiaccount :public-key])
hash (category-hash public-key community-id category-id)] hash (category-hash public-key community-id category-id)]
{::async-storage/set! {hash state-open?}})) {::async-storage/set! {hash state-open?}}))
(fx/defn update-category-states-in-db (rf/defn update-category-states-in-db
{:events [::category-states-loaded]} {:events [::category-states-loaded]}
[{:keys [db]} community-id hashes states] [{:keys [db]} community-id hashes states]
(let [public-key (get-in db [:multiaccount :public-key]) (let [public-key (get-in db [:multiaccount :public-key])
@@ -655,7 +654,7 @@
{} categories-old)] {} categories-old)]
{:db (update-in db [:communities community-id :categories] merge categories)})) {:db (update-in db [:communities community-id :categories] merge categories)}))
(fx/defn load-category-states (rf/defn load-category-states
{:events [:communities/load-category-states]} {:events [:communities/load-category-states]}
[{:keys [db]} community-id] [{:keys [db]} community-id]
(let [public-key (get-in db [:multiaccount :public-key]) (let [public-key (get-in db [:multiaccount :public-key])
@@ -674,21 +673,21 @@
:cb #(re-frame/dispatch :cb #(re-frame/dispatch
[::category-states-loaded community-id hashes %])}})) [::category-states-loaded community-id hashes %])}}))
(fx/defn navigate-to-community (rf/defn navigate-to-community
{:events [:communities/navigate-to-community]} {:events [:communities/navigate-to-community]}
[cofx community-id] [cofx community-id]
(fx/merge cofx (rf/merge cofx
(navigation/pop-to-root-tab :shell-stack) (navigation/pop-to-root-tab :shell-stack)
(navigation/navigate-to-nav2 :community community-id true))) (navigation/navigate-to-nav2 :community community-id true)))
(fx/defn member-role-updated (rf/defn member-role-updated
{:events [:community.member/role-updated]} {:events [:community.member/role-updated]}
[cofx response-js] [cofx response-js]
(fx/merge cofx (rf/merge cofx
(bottom-sheet/hide-bottom-sheet) (bottom-sheet/hide-bottom-sheet)
(handle-response response-js))) (handle-response response-js)))
(fx/defn add-role-to-member (rf/defn add-role-to-member
{:events [:community.member/add-role]} {:events [:community.member/add-role]}
[cofx community-id public-key role-id] [cofx community-id public-key role-id]
{::json-rpc/call [{:method "wakuext_addRoleToMember" {::json-rpc/call [{:method "wakuext_addRoleToMember"
@@ -702,7 +701,7 @@
:public-key public-key :public-key public-key
:role-id role-id})}]}) :role-id role-id})}]})
(fx/defn remove-role-from-member (rf/defn remove-role-from-member
{:events [:community.member/remove-role]} {:events [:community.member/remove-role]}
[_ community-id public-key role-id] [_ community-id public-key role-id]
{::json-rpc/call [{:method "wakuext_removeRoleFromMember" {::json-rpc/call [{:method "wakuext_removeRoleFromMember"
+8 -8
View File
@@ -7,9 +7,9 @@
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[status-im2.contexts.activity-center.events :as activity-center] [status-im2.contexts.activity-center.events :as activity-center]
[status-im.utils.fx :as fx])) [utils.re-frame :as rf]))
(fx/defn clean-up-chat (rf/defn clean-up-chat
[{:keys [db] :as cofx} [{:keys [db] :as cofx}
public-key public-key
{:keys [chat-id {:keys [chat-id
@@ -33,13 +33,13 @@
{:db (assoc-in db [:message-lists chat-id] {:db (assoc-in db [:message-lists chat-id]
(message-list/add-many nil (vals (get-in db [:messages chat-id]))))})) (message-list/add-many nil (vals (get-in db [:messages chat-id]))))}))
(fx/defn contact-blocked (rf/defn contact-blocked
{:events [::contact-blocked]} {:events [::contact-blocked]}
[{:keys [db] :as cofx} {:keys [public-key]} chats] [{:keys [db] :as cofx} {:keys [public-key]} chats]
(let [fxs (when chats (let [fxs (when chats
(map #(->> (chats-store/<-rpc %) (map #(->> (chats-store/<-rpc %)
(clean-up-chat public-key)) (types/js->clj chats)))] (clean-up-chat public-key)) (types/js->clj chats)))]
(apply fx/merge (apply rf/merge
cofx cofx
{:db (-> db {:db (-> db
(update :chats dissoc public-key) (update :chats dissoc public-key)
@@ -50,7 +50,7 @@
(activity-center/notifications-fetch-unread-count) (activity-center/notifications-fetch-unread-count)
fxs))) fxs)))
(fx/defn block-contact (rf/defn block-contact
{:events [:contact.ui/block-contact-confirmed]} {:events [:contact.ui/block-contact-confirmed]}
[{:keys [db] :as cofx} public-key] [{:keys [db] :as cofx} public-key]
(let [contact (-> (contact.db/public-key->contact (let [contact (-> (contact.db/public-key->contact
@@ -59,7 +59,7 @@
(assoc :blocked true (assoc :blocked true
:added false)) :added false))
from-one-to-one-chat? (not (get-in db [:chats (:current-chat-id db) :group-chat]))] from-one-to-one-chat? (not (get-in db [:chats (:current-chat-id db) :group-chat]))]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
;; add the contact to blocked contacts ;; add the contact to blocked contacts
(update :contacts/blocked (fnil conj #{}) public-key) (update :contacts/blocked (fnil conj #{}) public-key)
@@ -74,7 +74,7 @@
(navigation/pop-to-root-tab :chat-stack) (navigation/pop-to-root-tab :chat-stack)
(navigation/navigate-back))))) (navigation/navigate-back)))))
(fx/defn contact-unblocked (rf/defn contact-unblocked
{:events [::contact-unblocked]} {:events [::contact-unblocked]}
[{:keys [db]} contact-id] [{:keys [db]} contact-id]
(let [contact (-> (get-in db [:contacts/contacts contact-id]) (let [contact (-> (get-in db [:contacts/contacts contact-id])
@@ -83,7 +83,7 @@
(update :contacts/blocked disj contact-id) (update :contacts/blocked disj contact-id)
(assoc-in [:contacts/contacts contact-id] contact))})) (assoc-in [:contacts/contacts contact-id] contact))}))
(fx/defn unblock-contact (rf/defn unblock-contact
{:events [:contact.ui/unblock-contact-pressed]} {:events [:contact.ui/unblock-contact-pressed]}
[cofx contact-id] [cofx contact-id]
(contacts-store/unblock (contacts-store/unblock
+5 -5
View File
@@ -1,29 +1,29 @@
(ns status-im.contact.chat (ns status-im.contact.chat
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.chat.models :as chat] [status-im.chat.models :as chat]
[status-im.contact.core :as contact])) [status-im.contact.core :as contact]))
(fx/defn send-message-pressed (rf/defn send-message-pressed
{:events [:contact.ui/send-message-pressed] {:events [:contact.ui/send-message-pressed]
:interceptors [(re-frame/inject-cofx :random-id-generator)]} :interceptors [(re-frame/inject-cofx :random-id-generator)]}
[cofx {:keys [public-key ens-name]}] [cofx {:keys [public-key ens-name]}]
(chat/start-chat cofx public-key ens-name)) (chat/start-chat cofx public-key ens-name))
(fx/defn contact-code-submitted (rf/defn contact-code-submitted
{:events [:contact.ui/contact-code-submitted] {:events [:contact.ui/contact-code-submitted]
:interceptors [(re-frame/inject-cofx :random-id-generator)]} :interceptors [(re-frame/inject-cofx :random-id-generator)]}
[{{:contacts/keys [new-identity]} :db :as cofx} new-contact? nickname] [{{:contacts/keys [new-identity]} :db :as cofx} new-contact? nickname]
(let [{:keys [public-key ens-name]} new-identity] (let [{:keys [public-key ens-name]} new-identity]
(fx/merge cofx (rf/merge cofx
#(if new-contact? #(if new-contact?
(contact/add-contact % public-key nickname ens-name) (contact/add-contact % public-key nickname ens-name)
(chat/start-chat % public-key ens-name)) (chat/start-chat % public-key ens-name))
#(when new-contact? #(when new-contact?
(navigation/navigate-back %))))) (navigation/navigate-back %)))))
(fx/defn pinned-messages-pressed (rf/defn pinned-messages-pressed
{:events [:contact.ui/pinned-messages-pressed]} {:events [:contact.ui/pinned-messages-pressed]}
[cofx public-key] [cofx public-key]
(chat/navigate-to-user-pinned-messages cofx public-key)) (chat/navigate-to-user-pinned-messages cofx public-key))
+15 -15
View File
@@ -5,12 +5,12 @@
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.contact.block :as contact.block])) [status-im.contact.block :as contact.block]))
(fx/defn load-contacts (rf/defn load-contacts
{:events [::contacts-loaded]} {:events [::contacts-loaded]}
[{:keys [db] :as cofx} all-contacts] [{:keys [db] :as cofx} all-contacts]
(let [contacts-list (map #(vector (:public-key %) (if (empty? (:address %)) (let [contacts-list (map #(vector (:public-key %) (if (empty? (:address %))
@@ -29,7 +29,7 @@
(= public-key (:public-key multiaccount)) (= public-key (:public-key multiaccount))
(assoc :name (:name multiaccount)))) (assoc :name (:name multiaccount))))
(fx/defn ensure-contacts (rf/defn ensure-contacts
[{:keys [db]} contacts chats] [{:keys [db]} contacts chats]
(let [events (let [events
(reduce (reduce
@@ -68,7 +68,7 @@
:profile-image identicon :profile-image identicon
:address address})) :address address}))
(fx/defn send-contact-request (rf/defn send-contact-request
{:events [::send-contact-request]} {:events [::send-contact-request]}
[{:keys [db] :as cofx} public-key] [{:keys [db] :as cofx} public-key]
(let [{:keys [name profile-image]} (own-info db)] (let [{:keys [name profile-image]} (own-info db)]
@@ -76,7 +76,7 @@
:params [public-key name profile-image] :params [public-key name profile-image]
:on-success #(log/debug "contact request sent" public-key)}]})) :on-success #(log/debug "contact request sent" public-key)}]}))
(fx/defn add-contact (rf/defn add-contact
"Add a contact and set pending to false" "Add a contact and set pending to false"
{:events [:contact.ui/add-to-contact-pressed]} {:events [:contact.ui/add-to-contact-pressed]}
[{:keys [db] :as cofx} public-key nickname ens-name] [{:keys [db] :as cofx} public-key nickname ens-name]
@@ -90,7 +90,7 @@
(re-frame/dispatch [:sanitize-messages-and-process-response %]) (re-frame/dispatch [:sanitize-messages-and-process-response %])
(re-frame/dispatch [:offload-messages constants/timeline-chat-id]))))) (re-frame/dispatch [:offload-messages constants/timeline-chat-id])))))
(fx/defn remove-contact (rf/defn remove-contact
"Remove a contact from current account's contact list" "Remove a contact from current account's contact list"
{:events [:contact.ui/remove-contact-pressed]} {:events [:contact.ui/remove-contact-pressed]}
[{:keys [db]} {:keys [public-key]}] [{:keys [db]} {:keys [public-key]}]
@@ -105,7 +105,7 @@
:on-success #(log/debug "contact removed successfully")}] :on-success #(log/debug "contact removed successfully")}]
:dispatch [:offload-messages constants/timeline-chat-id]}) :dispatch [:offload-messages constants/timeline-chat-id]})
(fx/defn accept-contact-request (rf/defn accept-contact-request
{:events [:contact-requests.ui/accept-request]} {:events [:contact-requests.ui/accept-request]}
[{:keys [db]} id] [{:keys [db]} id]
{::json-rpc/call [{:method "wakuext_acceptContactRequest" {::json-rpc/call [{:method "wakuext_acceptContactRequest"
@@ -113,7 +113,7 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]}) :on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]})
(fx/defn decline-contact-request (rf/defn decline-contact-request
{:events [:contact-requests.ui/decline-request]} {:events [:contact-requests.ui/decline-request]}
[{:keys [db]} id] [{:keys [db]} id]
{::json-rpc/call [{:method "wakuext_dismissContactRequest" {::json-rpc/call [{:method "wakuext_dismissContactRequest"
@@ -121,29 +121,29 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]}) :on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]})
(fx/defn initialize-contacts [cofx] (rf/defn initialize-contacts [cofx]
(contacts-store/fetch-contacts-rpc cofx #(re-frame/dispatch [::contacts-loaded %]))) (contacts-store/fetch-contacts-rpc cofx #(re-frame/dispatch [::contacts-loaded %])))
(fx/defn open-contact-toggle-list (rf/defn open-contact-toggle-list
{:events [:contact.ui/start-group-chat-pressed]} {:events [:contact.ui/start-group-chat-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc db {:db (assoc db
:group/selected-contacts #{} :group/selected-contacts #{}
:new-chat-name "")} :new-chat-name "")}
(navigation/navigate-to-cofx :contact-toggle-list nil))) (navigation/navigate-to-cofx :contact-toggle-list nil)))
(fx/defn update-nickname (rf/defn update-nickname
{:events [:contacts/update-nickname]} {:events [:contacts/update-nickname]}
[{:keys [db] :as cofx} public-key nickname] [{:keys [db] :as cofx} public-key nickname]
(fx/merge cofx (rf/merge cofx
(contacts-store/set-nickname (contacts-store/set-nickname
public-key public-key
nickname nickname
#(re-frame/dispatch [:sanitize-messages-and-process-response %])) #(re-frame/dispatch [:sanitize-messages-and-process-response %]))
(navigation/navigate-back))) (navigation/navigate-back)))
(fx/defn switch-mutual-contact-requests-enabled (rf/defn switch-mutual-contact-requests-enabled
{:events [:multiaccounts.ui/switch-mutual-contact-requests-enabled]} {:events [:multiaccounts.ui/switch-mutual-contact-requests-enabled]}
[cofx enabled?] [cofx enabled?]
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
@@ -152,7 +152,7 @@
enabled? enabled?
nil)) nil))
(fx/defn set-search-query (rf/defn set-search-query
{:events [:contacts/set-search-query]} {:events [:contacts/set-search-query]}
[{:keys [db] :as cofx} value] [{:keys [db] :as cofx} value]
{:db (assoc db :contacts/search-query value)}) {:db (assoc db :contacts/search-query value)})
+3 -3
View File
@@ -1,15 +1,15 @@
(ns status-im.currency.core (ns status-im.currency.core
(:require [status-im.multiaccounts.update.core :as multiaccounts.update] (:require [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.wallet.prices :as prices])) [status-im.wallet.prices :as prices]))
(defn get-currency [db] (defn get-currency [db]
(get-in db [:multiaccount :currency] :usd)) (get-in db [:multiaccount :currency] :usd))
(fx/defn set-currency (rf/defn set-currency
{:events [:wallet.settings.ui/currency-selected]} {:events [:wallet.settings.ui/currency-selected]}
[{:keys [db] :as cofx} currency] [{:keys [db] :as cofx} currency]
(fx/merge cofx (rf/merge cofx
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:currency currency :currency currency
{}) {})
+2 -2
View File
@@ -3,7 +3,7 @@
[status-im.data-store.messages :as messages] [status-im.data-store.messages :as messages]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.utils.types :as types])) [status-im.utils.types :as types]))
@@ -103,7 +103,7 @@
rpc->type rpc->type
unmarshal-members)) unmarshal-members))
(fx/defn fetch-chats-rpc [_ {:keys [on-success]}] (rf/defn fetch-chats-rpc [_ {:keys [on-success]}]
{::json-rpc/call [{:method "wakuext_chatsPreview" {::json-rpc/call [{:method "wakuext_chatsPreview"
:params [] :params []
:js-response true :js-response true
+6 -6
View File
@@ -1,7 +1,7 @@
(ns status-im.data-store.contacts (ns status-im.data-store.contacts
(:require [clojure.set :as clojure.set] (:require [clojure.set :as clojure.set]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(defn <-rpc [contact] (defn <-rpc [contact]
@@ -20,14 +20,14 @@
(assoc :mutual? (and (:added contact) (assoc :mutual? (and (:added contact)
(:hasAddedUs contact))))) (:hasAddedUs contact)))))
(fx/defn fetch-contacts-rpc (rf/defn fetch-contacts-rpc
[_ on-success] [_ on-success]
{::json-rpc/call [{:method "wakuext_contacts" {::json-rpc/call [{:method "wakuext_contacts"
:params [] :params []
:on-success #(on-success (map <-rpc %)) :on-success #(on-success (map <-rpc %))
:on-error #(log/error "failed to fetch contacts" %)}]}) :on-error #(log/error "failed to fetch contacts" %)}]})
(fx/defn add (rf/defn add
[_ public-key nickname ens-name on-success] [_ public-key nickname ens-name on-success]
{::json-rpc/call [{:method "wakuext_addContact" {::json-rpc/call [{:method "wakuext_addContact"
:params [{:id public-key :nickname nickname :ensName ens-name}] :params [{:id public-key :nickname nickname :ensName ens-name}]
@@ -38,7 +38,7 @@
(on-success %))) (on-success %)))
:on-error #(log/error "failed to add contact" public-key %)}]}) :on-error #(log/error "failed to add contact" public-key %)}]})
(fx/defn set-nickname (rf/defn set-nickname
[_ public-key nickname on-success] [_ public-key nickname on-success]
{::json-rpc/call [{:method "wakuext_setContactLocalNickname" {::json-rpc/call [{:method "wakuext_setContactLocalNickname"
:params [{:id public-key :nickname nickname}] :params [{:id public-key :nickname nickname}]
@@ -49,14 +49,14 @@
(on-success %))) (on-success %)))
:on-error #(log/error "failed to set contact nickname " public-key nickname %)}]}) :on-error #(log/error "failed to set contact nickname " public-key nickname %)}]})
(fx/defn block [_ contact-id on-success] (rf/defn block [_ contact-id on-success]
{::json-rpc/call [{:method "wakuext_blockContact" {::json-rpc/call [{:method "wakuext_blockContact"
:params [contact-id] :params [contact-id]
:js-response true :js-response true
:on-success on-success :on-success on-success
:on-error #(log/error "failed to block contact" % contact-id)}]}) :on-error #(log/error "failed to block contact" % contact-id)}]})
(fx/defn unblock [_ contact-id on-success] (rf/defn unblock [_ contact-id on-success]
{::json-rpc/call [{:method "wakuext_unblockContact" {::json-rpc/call [{:method "wakuext_unblockContact"
:params [contact-id] :params [contact-id]
:on-success on-success :on-success on-success
+5 -5
View File
@@ -1,7 +1,7 @@
(ns status-im.data-store.messages (ns status-im.data-store.messages
(:require [clojure.set :as clojure.set] (:require [clojure.set :as clojure.set]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(defn ->rpc [{:keys [content] :as message}] (defn ->rpc [{:keys [content] :as message}]
@@ -90,14 +90,14 @@
:on-success #(log/debug "successfully deleted messages by chat-id" chat-id) :on-success #(log/debug "successfully deleted messages by chat-id" chat-id)
:on-error #(log/error "failed to delete messages by chat-id" % chat-id)}]}) :on-error #(log/error "failed to delete messages by chat-id" % chat-id)}]})
(fx/defn delete-message [cofx id] (rf/defn delete-message [cofx id]
(delete-message-rpc id)) (delete-message-rpc id))
(fx/defn delete-messages-from [cofx author] (rf/defn delete-messages-from [cofx author]
(delete-messages-from-rpc author)) (delete-messages-from-rpc author))
(fx/defn mark-messages-seen [cofx chat-id ids on-success] (rf/defn mark-messages-seen [cofx chat-id ids on-success]
(mark-seen-rpc chat-id ids on-success)) (mark-seen-rpc chat-id ids on-success))
(fx/defn delete-messages-by-chat-id [cofx chat-id] (rf/defn delete-messages-by-chat-id [cofx chat-id]
(delete-messages-by-chat-id-rpc chat-id)) (delete-messages-by-chat-id-rpc chat-id))
+2 -2
View File
@@ -1,7 +1,7 @@
(ns status-im.data-store.pin-messages (ns status-im.data-store.pin-messages
(:require [clojure.set :as clojure.set] (:require [clojure.set :as clojure.set]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.data-store.messages :as messages])) [status-im.data-store.messages :as messages]))
@@ -24,7 +24,7 @@
(on-success (update result :pinned-messages #(map <-rpc %))))) (on-success (update result :pinned-messages #(map <-rpc %)))))
:on-error on-error}]}) :on-error on-error}]})
(fx/defn send-pin-message [cofx pin-message] (rf/defn send-pin-message [cofx pin-message]
{::json-rpc/call [{:method "wakuext_sendPinMessage" {::json-rpc/call [{:method "wakuext_sendPinMessage"
:params [(messages/->rpc pin-message)] :params [(messages/->rpc pin-message)]
:on-success #(log/debug "successfully pinned message" pin-message) :on-success #(log/debug "successfully pinned message" pin-message)
@@ -2,7 +2,7 @@
(:require [clojure.set :as clojure.set] (:require [clojure.set :as clojure.set]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(defn <-rpc [visibility-status-update] (defn <-rpc [visibility-status-update]
@@ -14,7 +14,7 @@
{:current-user-status :current-user-visibility-status}) {:current-user-status :current-user-visibility-status})
(update :current-user-visibility-status <-rpc))) (update :current-user-visibility-status <-rpc)))
(fx/defn fetch-visibility-status-updates-rpc [_] (rf/defn fetch-visibility-status-updates-rpc [_]
{::json-rpc/call [{:method "wakuext_statusUpdates" {::json-rpc/call [{:method "wakuext_statusUpdates"
:params [] :params []
:on-success #(re-frame/dispatch :on-success #(re-frame/dispatch
+30 -30
View File
@@ -9,7 +9,7 @@
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.datetime :as datetime] [status-im.utils.datetime :as datetime]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.random :as random] [status-im.utils.random :as random]
[status-im.bottom-sheet.core :as bottom-sheet])) [status-im.bottom-sheet.core :as bottom-sheet]))
@@ -38,14 +38,14 @@
(fn [[chain-id name cb]] (fn [[chain-id name cb]]
(ens/expire-at chain-id name cb))) (ens/expire-at chain-id name cb)))
(fx/defn update-ens-tx-state (rf/defn update-ens-tx-state
{:events [:update-ens-tx-state]} {:events [:update-ens-tx-state]}
[{:keys [db]} new-state username custom-domain? tx-hash] [{:keys [db]} new-state username custom-domain? tx-hash]
{:db (assoc-in db [:ens/registrations tx-hash] {:state new-state {:db (assoc-in db [:ens/registrations tx-hash] {:state new-state
:username username :username username
:custom-domain? custom-domain?})}) :custom-domain? custom-domain?})})
(fx/defn redirect-to-ens-summary (rf/defn redirect-to-ens-summary
{:events [::redirect-to-ens-summary]} {:events [::redirect-to-ens-summary]}
[cofx] [cofx]
;; we reset navigation so that navigate back doesn't return ;; we reset navigation so that navigate back doesn't return
@@ -55,19 +55,19 @@
[:my-profile [:my-profile
:ens-confirmation])) :ens-confirmation]))
(fx/defn update-ens-tx-state-and-redirect (rf/defn update-ens-tx-state-and-redirect
{:events [:update-ens-tx-state-and-redirect]} {:events [:update-ens-tx-state-and-redirect]}
[cofx new-state username custom-domain? tx-hash] [cofx new-state username custom-domain? tx-hash]
(fx/merge cofx (rf/merge cofx
(update-ens-tx-state new-state username custom-domain? tx-hash) (update-ens-tx-state new-state username custom-domain? tx-hash)
(redirect-to-ens-summary))) (redirect-to-ens-summary)))
(fx/defn clear-ens-registration (rf/defn clear-ens-registration
{:events [:clear-ens-registration]} {:events [:clear-ens-registration]}
[{:keys [db]} tx-hash] [{:keys [db]} tx-hash]
{:db (update db :ens/registrations dissoc tx-hash)}) {:db (update db :ens/registrations dissoc tx-hash)})
(fx/defn set-state (rf/defn set-state
{:events [::name-resolved]} {:events [::name-resolved]}
[{:keys [db]} username state address] [{:keys [db]} username state address]
(when (= username (when (= username
@@ -76,13 +76,13 @@
(assoc-in [:ens/registration :state] state) (assoc-in [:ens/registration :state] state)
(assoc-in [:ens/registration :address] address))})) (assoc-in [:ens/registration :address] address))}))
(fx/defn save-username (rf/defn save-username
{:events [::save-username]} {:events [::save-username]}
[{:keys [db] :as cofx} custom-domain? username redirectToSummary] [{:keys [db] :as cofx} custom-domain? username redirectToSummary]
(let [name (fullname custom-domain? username) (let [name (fullname custom-domain? username)
names (get-in db [:multiaccount :usernames] []) names (get-in db [:multiaccount :usernames] [])
new-names (conj names name)] new-names (conj names name)]
(fx/merge cofx (rf/merge cofx
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:usernames new-names :usernames new-names
(when redirectToSummary (when redirectToSummary
@@ -91,7 +91,7 @@
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:preferred-name name {}))))) :preferred-name name {})))))
(fx/defn set-pub-key (rf/defn set-pub-key
{:events [::set-pub-key]} {:events [::set-pub-key]}
[{:keys [db]}] [{:keys [db]}]
(let [{:keys [username address custom-domain?]} (:ens/registration db) (let [{:keys [username address custom-domain?]} (:ens/registration db)
@@ -106,7 +106,7 @@
:on-result [::save-username custom-domain? username true] :on-result [::save-username custom-domain? username true]
:on-error [::on-registration-failure]}])))) :on-error [::on-registration-failure]}]))))
(fx/defn on-input-submitted (rf/defn on-input-submitted
{:events [::input-submitted]} {:events [::input-submitted]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [state username custom-domain?]} (:ens/registration db)] (let [{:keys [state username custom-domain?]} (:ens/registration db)]
@@ -153,7 +153,7 @@
5 10 5 10
1 10)) 1 10))
(fx/defn register-name (rf/defn register-name
{:events [::register-name-pressed]} {:events [::register-name-pressed]}
[{:keys [db]} address] [{:keys [db]} address]
(let [{:keys [username]} (let [{:keys [username]}
@@ -189,7 +189,7 @@
;;NOTE we want to handle only last resolve ;;NOTE we want to handle only last resolve
(def resolve-last-id (atom nil)) (def resolve-last-id (atom nil))
(fx/defn set-username-candidate (rf/defn set-username-candidate
{:events [::set-username-candidate]} {:events [::set-username-candidate]}
[{:keys [db]} username] [{:keys [db]} username]
(let [{:keys [custom-domain?]} (:ens/registration db) (let [{:keys [custom-domain?]} (:ens/registration db)
@@ -211,10 +211,10 @@
chain-id custom-domain? username addresses public-key % chain-id custom-domain? username addresses public-key %
resolve-last-id @resolve-last-id)]}))))) resolve-last-id @resolve-last-id)]})))))
(fx/defn return-to-ens-main-screen (rf/defn return-to-ens-main-screen
{:events [::got-it-pressed ::cancel-pressed]} {:events [::got-it-pressed ::cancel-pressed]}
[{:keys [db] :as cofx} _] [{:keys [db] :as cofx} _]
(fx/merge cofx (rf/merge cofx
;; clear registration data ;; clear registration data
{:db (dissoc db :ens/registration)} {:db (dissoc db :ens/registration)}
;; we reset navigation so that navigate back doesn't return ;; we reset navigation so that navigate back doesn't return
@@ -222,46 +222,46 @@
(navigation/set-stack-root :profile-stack [:my-profile (navigation/set-stack-root :profile-stack [:my-profile
:ens-main]))) :ens-main])))
(fx/defn switch-domain-type (rf/defn switch-domain-type
{:events [::switch-domain-type]} {:events [::switch-domain-type]}
[{:keys [db] :as cofx} _] [{:keys [db] :as cofx} _]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(update :ens/registration dissoc :username :state) (update :ens/registration dissoc :username :state)
(update-in [:ens/registration :custom-domain?] not))})) (update-in [:ens/registration :custom-domain?] not))}))
(fx/defn change-address (rf/defn change-address
{:events [::change-address]} {:events [::change-address]}
[{:keys [db] :as cofx} _ {:keys [address]}] [{:keys [db] :as cofx} _ {:keys [address]}]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:ens/registration :address] address)} {:db (assoc-in db [:ens/registration :address] address)}
(bottom-sheet/hide-bottom-sheet))) (bottom-sheet/hide-bottom-sheet)))
(fx/defn save-preferred-name (rf/defn save-preferred-name
{:events [::save-preferred-name]} {:events [::save-preferred-name]}
[cofx name] [cofx name]
(multiaccounts.update/multiaccount-update cofx (multiaccounts.update/multiaccount-update cofx
:preferred-name name :preferred-name name
{})) {}))
(fx/defn on-registration-failure (rf/defn on-registration-failure
"TODO not sure there is actually anything to do here "TODO not sure there is actually anything to do here
it should only be called if the user cancels the signing it should only be called if the user cancels the signing
Actual registration failure has not been implemented properly" Actual registration failure has not been implemented properly"
{:events [::on-registration-failure]} {:events [::on-registration-failure]}
[_ _]) [_ _])
(fx/defn store-name-address (rf/defn store-name-address
{:events [::address-resolved]} {:events [::address-resolved]}
[{:keys [db]} username address] [{:keys [db]} username address]
{:db (assoc-in db [:ens/names username :address] address)}) {:db (assoc-in db [:ens/names username :address] address)})
(fx/defn store-name-public-key (rf/defn store-name-public-key
{:events [::public-key-resolved]} {:events [::public-key-resolved]}
[{:keys [db]} username public-key] [{:keys [db]} username public-key]
{:db (assoc-in db [:ens/names username :public-key] public-key)}) {:db (assoc-in db [:ens/names username :public-key] public-key)})
(fx/defn store-expiration-date (rf/defn store-expiration-date
{:events [::get-expiration-time-success]} {:events [::get-expiration-time-success]}
[{:keys [now db]} username timestamp] [{:keys [now db]} username timestamp]
{:db (-> db {:db (-> db
@@ -269,11 +269,11 @@
(datetime/timestamp->year-month-day-date timestamp)) (datetime/timestamp->year-month-day-date timestamp))
(assoc-in [:ens/names username :releasable?] (<= timestamp now)))}) (assoc-in [:ens/names username :releasable?] (<= timestamp now)))})
(fx/defn navigate-to-name (rf/defn navigate-to-name
{:events [::navigate-to-name]} {:events [::navigate-to-name]}
[{:keys [db] :as cofx} username] [{:keys [db] :as cofx} username]
(let [chain-id (ethereum/chain-id db)] (let [chain-id (ethereum/chain-id db)]
(fx/merge cofx (rf/merge cofx
{::get-expiration-time {::get-expiration-time
[chain-id [chain-id
(stateofus/username username) (stateofus/username username)
@@ -286,20 +286,20 @@
#(re-frame/dispatch [::public-key-resolved username %])]} #(re-frame/dispatch [::public-key-resolved username %])]}
(navigation/navigate-to-cofx :ens-name-details username)))) (navigation/navigate-to-cofx :ens-name-details username))))
(fx/defn start-registration (rf/defn start-registration
{:events [::add-username-pressed ::get-started-pressed]} {:events [::add-username-pressed ::get-started-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
(set-username-candidate (get-in db [:ens/registration :username] "")) (set-username-candidate (get-in db [:ens/registration :username] ""))
(navigation/navigate-to-cofx :ens-search {}))) (navigation/navigate-to-cofx :ens-search {})))
(fx/defn remove-username (rf/defn remove-username
{:events [::remove-username]} {:events [::remove-username]}
[{:keys [db] :as cofx} name] [{:keys [db] :as cofx} name]
(let [names (get-in db [:multiaccount :usernames] []) (let [names (get-in db [:multiaccount :usernames] [])
preferred-name (get-in db [:multiaccount :preferred-name]) preferred-name (get-in db [:multiaccount :preferred-name])
new-names (remove #(= name %) names)] new-names (remove #(= name %) names)]
(fx/merge cofx (rf/merge cofx
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:usernames new-names :usernames new-names
{}) {})
+8 -8
View File
@@ -3,17 +3,17 @@
[status-im.wallet.db :as wallet] [status-im.wallet.db :as wallet]
[status-im.wallet.core :as wallet.core] [status-im.wallet.core :as wallet.core]
[status-im.ethereum.transactions.core :as transactions] [status-im.ethereum.transactions.core :as transactions]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(fx/defn new-transfers (rf/defn new-transfers
[cofx block-number accounts] [cofx block-number accounts]
(log/debug "[wallet-subs] new-transfers" (log/debug "[wallet-subs] new-transfers"
"accounts" accounts "accounts" accounts
"block" block-number) "block" block-number)
(transactions/check-watched-transactions cofx)) (transactions/check-watched-transactions cofx))
(fx/defn recent-history-fetching-started (rf/defn recent-history-fetching-started
[{:keys [db]} accounts] [{:keys [db]} accounts]
(log/debug "[wallet-subs] recent-history-fetching-started" (log/debug "[wallet-subs] recent-history-fetching-started"
"accounts" accounts) "accounts" accounts)
@@ -25,7 +25,7 @@
event event
(assoc :dispatch event)))) (assoc :dispatch event))))
(fx/defn recent-history-fetching-ended (rf/defn recent-history-fetching-ended
[{:keys [db]} {:keys [accounts blockNumber]}] [{:keys [db]} {:keys [accounts blockNumber]}]
(log/debug "[wallet-subs] recent-history-fetching-ended" (log/debug "[wallet-subs] recent-history-fetching-ended"
"accounts" accounts "accounts" accounts
@@ -53,18 +53,18 @@
:before-block blockNumber :before-block blockNumber
:limit 20}}) :limit 20}})
(fx/defn fetching-error (rf/defn fetching-error
[{:keys [db] :as cofx} {:keys [message]}] [{:keys [db] :as cofx} {:keys [message]}]
(fx/merge (rf/merge
cofx cofx
{:db (assoc db :wallet/fetching-error message)} {:db (assoc db :wallet/fetching-error message)}
(wallet.core/after-checking-history))) (wallet.core/after-checking-history)))
(fx/defn non-archival-node-detected (rf/defn non-archival-node-detected
[{:keys [db]} _] [{:keys [db]} _]
{:db (assoc db :wallet/non-archival-node true)}) {:db (assoc db :wallet/non-archival-node true)})
(fx/defn new-wallet-event (rf/defn new-wallet-event
[cofx {:keys [type blockNumber accounts] :as event}] [cofx {:keys [type blockNumber accounts] :as event}]
(log/info "[wallet-subs] new-wallet-event" (log/info "[wallet-subs] new-wallet-event"
"event-type" type "event-type" type
+24 -24
View File
@@ -7,7 +7,7 @@
[status-im.ethereum.eip55 :as eip55] [status-im.ethereum.eip55 :as eip55]
[status-im.ethereum.encode :as encode] [status-im.ethereum.encode :as encode]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.mobile-sync :as utils.mobile-sync] [status-im.utils.mobile-sync :as utils.mobile-sync]
[status-im.wallet.core :as wallet] [status-im.wallet.core :as wallet]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
@@ -105,7 +105,7 @@
(def default-transfers-limit 20) (def default-transfers-limit 20)
(fx/defn watch-transaction (rf/defn watch-transaction
"Set a watch for the given transaction "Set a watch for the given transaction
`watch-params` needs to contain a `trigger-fn` and `on-trigger` functions `watch-params` needs to contain a `trigger-fn` and `on-trigger` functions
`trigger-fn` is a function that returns true if the watch has been triggered `trigger-fn` is a function that returns true if the watch has been triggered
@@ -117,7 +117,7 @@
{:db (assoc-in db [:ethereum/watched-transactions transaction-id] {:db (assoc-in db [:ethereum/watched-transactions transaction-id]
watch-params)})) watch-params)}))
(fx/defn check-transaction (rf/defn check-transaction
"Check if the transaction has been triggered and applies the effects returned "Check if the transaction has been triggered and applies the effects returned
by `on-trigger` if that is the case" by `on-trigger` if that is the case"
[{:keys [db] :as cofx} {:keys [hash] :as transaction}] [{:keys [db] :as cofx} {:keys [hash] :as transaction}]
@@ -125,12 +125,12 @@
(get-in db [:ethereum/watched-transactions hash])] (get-in db [:ethereum/watched-transactions hash])]
(let [{:keys [trigger-fn on-trigger]} watch-params] (let [{:keys [trigger-fn on-trigger]} watch-params]
(when (trigger-fn db transaction) (when (trigger-fn db transaction)
(fx/merge cofx (rf/merge cofx
{:db (update db :ethereum/watched-transactions {:db (update db :ethereum/watched-transactions
dissoc hash)} dissoc hash)}
(on-trigger transaction)))))) (on-trigger transaction))))))
(fx/defn check-watched-transactions (rf/defn check-watched-transactions
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [watched-transactions (let [watched-transactions
(reduce-kv (fn [acc _ {:keys [transactions]}] (reduce-kv (fn [acc _ {:keys [transactions]}]
@@ -139,13 +139,13 @@
(keys (get db :ethereum/watched-transactions))))) (keys (get db :ethereum/watched-transactions)))))
{} {}
(get-in db [:wallet :accounts]))] (get-in db [:wallet :accounts]))]
(apply fx/merge (apply rf/merge
cofx cofx
(map (fn [[_ transaction]] (map (fn [[_ transaction]]
(check-transaction transaction)) (check-transaction transaction))
watched-transactions)))) watched-transactions))))
(fx/defn add-transfer (rf/defn add-transfer
"We determine a unique id for the transfer before adding it because some "We determine a unique id for the transfer before adding it because some
transaction can contain multiple transfers and they would overwrite each other transaction can contain multiple transfers and they would overwrite each other
in the transfer map if identified by hash" in the transfer map if identified by hash"
@@ -157,7 +157,7 @@
(:type transfer-by-hash)))) (:type transfer-by-hash))))
id id
hash))] hash))]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:wallet :accounts address :transactions unique-id] {:db (assoc-in db [:wallet :accounts address :transactions unique-id]
(assoc transfer :hash unique-id))} (assoc transfer :hash unique-id))}
(check-transaction transfer))))) (check-transaction transfer)))))
@@ -173,7 +173,7 @@
(eip55/address->checksum address) (eip55/address->checksum address)
:min-block-transfers-count])) :min-block-transfers-count]))
(fx/defn set-lowest-fetched-block (rf/defn set-lowest-fetched-block
[{:keys [db]} address transfers] [{:keys [db]} address transfers]
(let [checksum (eip55/address->checksum address) (let [checksum (eip55/address->checksum address)
{:keys [min-block min-block-transfers-count]} {:keys [min-block min-block-transfers-count]}
@@ -218,15 +218,15 @@
accounts accounts
addresses)))) addresses))))
(fx/defn tx-fetching-in-progress (rf/defn tx-fetching-in-progress
[{:keys [db]} addresses] [{:keys [db]} addresses]
{:db (update-fetching-status db addresses :history? true)}) {:db (update-fetching-status db addresses :history? true)})
(fx/defn tx-fetching-ended (rf/defn tx-fetching-ended
[{:keys [db]} addresses] [{:keys [db]} addresses]
{:db (update-fetching-status db addresses :history? false)}) {:db (update-fetching-status db addresses :history? false)})
(fx/defn tx-history-end-reached (rf/defn tx-history-end-reached
[{:keys [db] :as cofx} address] [{:keys [db] :as cofx} address]
(let [syncing-allowed? (utils.mobile-sync/syncing-allowed? cofx)] (let [syncing-allowed? (utils.mobile-sync/syncing-allowed? cofx)]
{:db (assoc-in db [:wallet :fetching address :all-fetched?] {:db (assoc-in db [:wallet :fetching address :all-fetched?]
@@ -234,7 +234,7 @@
:all :all
:all-preloaded))})) :all-preloaded))}))
(fx/defn delete-pending-transactions (rf/defn delete-pending-transactions
[{:keys [db]} address transactions] [{:keys [db]} address transactions]
(let [all-transactions (let [all-transactions
(get-in db [:wallet :accounts (eip55/address->checksum address) :transactions]) (get-in db [:wallet :accounts (eip55/address->checksum address) :transactions])
@@ -247,7 +247,7 @@
transactions)] transactions)]
{:wallet/delete-pending-transactions pending-tx-hashes})) {:wallet/delete-pending-transactions pending-tx-hashes}))
(fx/defn handle-new-transfer (rf/defn handle-new-transfer
[{:keys [db] :as cofx} transfers {:keys [address limit]}] [{:keys [db] :as cofx} transfers {:keys [address limit]}]
(log/debug "[transfers] new-transfers" (log/debug "[transfers] new-transfers"
"address" address "address" address
@@ -276,9 +276,9 @@
(< (count transfers) limit) (< (count transfers) limit)
(conj (tx-history-end-reached checksum)))] (conj (tx-history-end-reached checksum)))]
(apply fx/merge cofx (tx-fetching-ended [checksum]) effects))) (apply rf/merge cofx (tx-fetching-ended [checksum]) effects)))
(fx/defn check-ens-transactions (rf/defn check-ens-transactions
[{:keys [db] :as cofx} transfers] [{:keys [db] :as cofx} transfers]
(let [set-of-transactions-hash (reduce (fn [acc {:keys [hash]}] (conj acc hash)) #{} transfers) (let [set-of-transactions-hash (reduce (fn [acc {:keys [hash]}] (conj acc hash)) #{} transfers)
registrations (filter registrations (filter
@@ -293,7 +293,7 @@
transaction-success (get transfer :transfer)] transaction-success (get transfer :transfer)]
(cond (cond
(= transaction-success true) (= transaction-success true)
(fx/merge cofx (rf/merge cofx
(ens/clear-ens-registration hash) (ens/clear-ens-registration hash)
(ens/save-username custom-domain? username false)) (ens/save-username custom-domain? username false))
(= type :failed) (= type :failed)
@@ -301,17 +301,17 @@
:else :else
nil))) nil)))
registrations)] registrations)]
(apply fx/merge cofx fxs))) (apply rf/merge cofx fxs)))
(fx/defn new-transfers (rf/defn new-transfers
{:events [::new-transfers]} {:events [::new-transfers]}
[cofx transfers params] [cofx transfers params]
(fx/merge cofx (rf/merge cofx
(handle-new-transfer transfers params) (handle-new-transfer transfers params)
(wallet/stop-fetching-on-empty-tx-history transfers) (wallet/stop-fetching-on-empty-tx-history transfers)
(check-ens-transactions transfers))) (check-ens-transactions transfers)))
(fx/defn tx-fetching-failed (rf/defn tx-fetching-failed
{:events [::tx-fetching-failed]} {:events [::tx-fetching-failed]}
[cofx error address] [cofx error address]
(log/debug "[transactions] tx-fetching-failed" (log/debug "[transactions] tx-fetching-failed"
@@ -351,13 +351,13 @@
(defn some-transactions-loaded? [db address] (defn some-transactions-loaded? [db address]
(not-empty (get-in db [:wallet :accounts address :transactions]))) (not-empty (get-in db [:wallet :accounts address :transactions])))
(fx/defn fetch-more-tx (rf/defn fetch-more-tx
{:events [:transactions/fetch-more]} {:events [:transactions/fetch-more]}
[{:keys [db] :as cofx} address] [{:keys [db] :as cofx} address]
(let [min-known-block (or (get-min-known-block db address) (let [min-known-block (or (get-min-known-block db address)
(:ethereum/current-block db)) (:ethereum/current-block db))
min-block-transfers-count (or (min-block-transfers-count db address) 0)] min-block-transfers-count (or (min-block-transfers-count db address) 0)]
(fx/merge (rf/merge
cofx cofx
{:transactions/get-transfers {:transactions/get-transfers
{:chain-tokens (:wallet/all-tokens db) {:chain-tokens (:wallet/all-tokens db)
@@ -373,7 +373,7 @@
min-block-transfers-count)}}} min-block-transfers-count)}}}
(tx-fetching-in-progress [address])))) (tx-fetching-in-progress [address]))))
(fx/defn get-fetched-transfers (rf/defn get-fetched-transfers
{:events [:transaction/get-fetched-transfers]} {:events [:transaction/get-fetched-transfers]}
[{:keys [db]}] [{:keys [db]}]
{:transactions/get-transfers {:transactions/get-transfers
+26 -26
View File
@@ -43,7 +43,7 @@
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
status-im.ui.screens.privacy-and-security-settings.events status-im.ui.screens.privacy-and-security-settings.events
[status-im.utils.dimensions :as dimensions] [status-im.utils.dimensions :as dimensions]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
status-im.utils.logging.core status-im.utils.logging.core
[status-im.utils.universal-links.core :as universal-links] [status-im.utils.universal-links.core :as universal-links]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
@@ -95,22 +95,22 @@
(fn [] (fn []
(dimensions/add-event-listener))) (dimensions/add-event-listener)))
(fx/defn dismiss-keyboard (rf/defn dismiss-keyboard
{:events [:dismiss-keyboard]} {:events [:dismiss-keyboard]}
[_] [_]
{:dismiss-keyboard nil}) {:dismiss-keyboard nil})
(fx/defn identicon-generated (rf/defn identicon-generated
{:events [:identicon-generated]} {:events [:identicon-generated]}
[{:keys [db]} path identicon] [{:keys [db]} path identicon]
{:db (assoc-in db path identicon)}) {:db (assoc-in db path identicon)})
(fx/defn gfycat-generated (rf/defn gfycat-generated
{:events [:gfycat-generated]} {:events [:gfycat-generated]}
[{:keys [db]} path gfycat] [{:keys [db]} path gfycat]
{:db (assoc-in db path gfycat)}) {:db (assoc-in db path gfycat)})
(fx/defn system-theme-mode-changed (rf/defn system-theme-mode-changed
{:events [:system-theme-mode-changed]} {:events [:system-theme-mode-changed]}
[cofx _] [cofx _]
(when (multiaccounts.model/logged-in? cofx) (when (multiaccounts.model/logged-in? cofx)
@@ -131,7 +131,7 @@
:on-accept #(biometric/authenticate nil on-biometric-auth-result authentication-options) :on-accept #(biometric/authenticate nil on-biometric-auth-result authentication-options)
:on-cancel #(re-frame/dispatch [:multiaccounts.logout.ui/logout-confirmed])})))) :on-cancel #(re-frame/dispatch [:multiaccounts.logout.ui/logout-confirmed])}))))
(fx/defn on-return-from-background [{:keys [db now] :as cofx}] (rf/defn on-return-from-background [{:keys [db now] :as cofx}]
(let [app-in-background-since (get db :app-in-background-since) (let [app-in-background-since (get db :app-in-background-since)
signed-up? (get-in db [:multiaccount :signed-up?]) signed-up? (get-in db [:multiaccount :signed-up?])
biometric-auth? (= (:auth-method db) "biometric") biometric-auth? (= (:auth-method db) "biometric")
@@ -141,7 +141,7 @@
(some? app-in-background-since) (some? app-in-background-since)
(>= (- now app-in-background-since) (>= (- now app-in-background-since)
constants/ms-in-bg-for-require-bioauth))] constants/ms-in-bg-for-require-bioauth))]
(fx/merge cofx (rf/merge cofx
{:db (dissoc db :app-in-background-since)} {:db (dissoc db :app-in-background-since)}
(mailserver/process-next-messages-request) (mailserver/process-next-messages-request)
(wallet/restart-wallet-service-after-background app-in-background-since) (wallet/restart-wallet-service-after-background app-in-background-since)
@@ -151,17 +151,17 @@
#(when requires-bio-auth #(when requires-bio-auth
(biometric/authenticate % on-biometric-auth-result authentication-options))))) (biometric/authenticate % on-biometric-auth-result authentication-options)))))
(fx/defn on-going-in-background (rf/defn on-going-in-background
[{:keys [db now]}] [{:keys [db now]}]
{:db (assoc db :app-in-background-since now) {:db (assoc db :app-in-background-since now)
:dispatch-n [[:audio-recorder/on-background] [:audio-message/on-background]]}) :dispatch-n [[:audio-recorder/on-background] [:audio-message/on-background]]})
(fx/defn app-state-change (rf/defn app-state-change
{:events [:app-state-change]} {:events [:app-state-change]}
[{:keys [db] :as cofx} state] [{:keys [db] :as cofx} state]
(let [app-coming-from-background? (= state "active") (let [app-coming-from-background? (= state "active")
app-going-in-background? (= state "background")] app-going-in-background? (= state "background")]
(fx/merge cofx (rf/merge cofx
{::app-state-change-fx state {::app-state-change-fx state
:db (assoc db :app-state state)} :db (assoc db :app-state state)}
#(when app-coming-from-background? #(when app-coming-from-background?
@@ -169,26 +169,26 @@
#(when app-going-in-background? #(when app-going-in-background?
(on-going-in-background %))))) (on-going-in-background %)))))
(fx/defn request-permissions (rf/defn request-permissions
{:events [:request-permissions]} {:events [:request-permissions]}
[_ options] [_ options]
{:request-permissions-fx options}) {:request-permissions-fx options})
(fx/defn update-window-dimensions (rf/defn update-window-dimensions
{:events [:update-window-dimensions]} {:events [:update-window-dimensions]}
[{:keys [db]} dimensions] [{:keys [db]} dimensions]
{:db (assoc db :dimensions/window (dimensions/window dimensions))}) {:db (assoc db :dimensions/window (dimensions/window dimensions))})
(fx/defn init-timeline-chat (rf/defn init-timeline-chat
{:events [:init-timeline-chat]} {:events [:init-timeline-chat]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(when-not (get-in db [:pagination-info constants/timeline-chat-id :messages-initialized?]) (when-not (get-in db [:pagination-info constants/timeline-chat-id :messages-initialized?])
(chat/preload-chat-data cofx constants/timeline-chat-id))) (chat/preload-chat-data cofx constants/timeline-chat-id)))
(fx/defn on-will-focus (rf/defn on-will-focus
{:events [:screens/on-will-focus]} {:events [:screens/on-will-focus]}
[{:keys [db] :as cofx} view-id] [{:keys [db] :as cofx} view-id]
(fx/merge cofx (rf/merge cofx
(cond (cond
(= :chat view-id) (= :chat view-id)
{::async-storage/set! {:chat-id (get-in cofx [:db :current-chat-id]) {::async-storage/set! {:chat-id (get-in cofx [:db :current-chat-id])
@@ -217,25 +217,25 @@
nil))) nil)))
;;TODO :replace by named events ;;TODO :replace by named events
(fx/defn set-event (rf/defn set-event
{:events [:set]} {:events [:set]}
[{:keys [db]} k v] [{:keys [db]} k v]
{:db (assoc db k v)}) {:db (assoc db k v)})
(fx/defn set-view-id (rf/defn set-view-id
{:events [:set-view-id]} {:events [:set-view-id]}
[{:keys [db]} view-id] [{:keys [db]} view-id]
{:db (assoc db :view-id view-id)}) {:db (assoc db :view-id view-id)})
;;TODO :replace by named events ;;TODO :replace by named events
(fx/defn set-once-event (rf/defn set-once-event
{:events [:set-once]} {:events [:set-once]}
[{:keys [db]} k v] [{:keys [db]} k v]
(when-not (get db k) (when-not (get db k)
{:db (assoc db k v)})) {:db (assoc db k v)}))
;;TODO :replace by named events ;;TODO :replace by named events
(fx/defn set-in-event (rf/defn set-in-event
{:events [:set-in]} {:events [:set-in]}
[{:keys [db]} path v] [{:keys [db]} path v]
{:db (assoc-in db path v)}) {:db (assoc-in db path v)})
@@ -244,7 +244,7 @@
(clojure.set/rename-keys on-ramp {:logoUrl :logo-url (clojure.set/rename-keys on-ramp {:logoUrl :logo-url
:siteUrl :site-url})) :siteUrl :site-url}))
(fx/defn crypto-loaded-event (rf/defn crypto-loaded-event
{:events [::crypto-loaded]} {:events [::crypto-loaded]}
[{:keys [db]} on-ramps] [{:keys [db]} on-ramps]
{:db (assoc {:db (assoc
@@ -252,7 +252,7 @@
:buy-crypto/on-ramps :buy-crypto/on-ramps
(map on-ramp<-rpc on-ramps))}) (map on-ramp<-rpc on-ramps))})
(fx/defn buy-crypto-ui-loaded (rf/defn buy-crypto-ui-loaded
{:events [:buy-crypto.ui/loaded]} {:events [:buy-crypto.ui/loaded]}
[_] [_]
{::json-rpc/call [{:method "wallet_getCryptoOnRamps" {::json-rpc/call [{:method "wallet_getCryptoOnRamps"
@@ -260,10 +260,10 @@
:on-success (fn [on-ramps] :on-success (fn [on-ramps]
(re-frame/dispatch [::crypto-loaded on-ramps]))}]}) (re-frame/dispatch [::crypto-loaded on-ramps]))}]})
(fx/defn open-buy-crypto-screen (rf/defn open-buy-crypto-screen
{:events [:buy-crypto.ui/open-screen]} {:events [:buy-crypto.ui/open-screen]}
[cofx] [cofx]
(fx/merge (rf/merge
cofx cofx
(navigation/open-modal :buy-crypto nil) (navigation/open-modal :buy-crypto nil)
(wallet/keep-watching-history))) (wallet/keep-watching-history)))
@@ -280,7 +280,7 @@
(hash id) (hash id)
(hash (str public-key id)))) (hash (str public-key id))))
(fx/defn close-information-box (rf/defn close-information-box
{:events [:close-information-box]} {:events [:close-information-box]}
[{:keys [db]} id global?] [{:keys [db]} id global?]
(let [public-key (get-in db [:multiaccount :public-key]) (let [public-key (get-in db [:multiaccount :public-key])
@@ -288,7 +288,7 @@
{::async-storage/set! {hash true} {::async-storage/set! {hash true}
:db (assoc-in db [:information-box-states id] true)})) :db (assoc-in db [:information-box-states id] true)}))
(fx/defn information-box-states-loaded (rf/defn information-box-states-loaded
{:events [:information-box-states-loaded]} {:events [:information-box-states-loaded]}
[{:keys [db]} hashes states] [{:keys [db]} hashes states]
{:db (assoc db :information-box-states (reduce {:db (assoc db :information-box-states (reduce
@@ -296,7 +296,7 @@
(assoc acc id (get states hash))) (assoc acc id (get states hash)))
{} hashes))}) {} hashes))})
(fx/defn load-information-box-states (rf/defn load-information-box-states
{:events [:load-information-box-states]} {:events [:load-information-box-states]}
[{:keys [db]}] [{:keys [db]}]
(let [public-key (get-in db [:multiaccount :public-key]) (let [public-key (get-in db [:multiaccount :public-key])
+5 -5
View File
@@ -5,7 +5,7 @@
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.node.core :as node] [status-im.node.core :as node]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.utils.fx :as fx])) [utils.re-frame :as rf]))
(defn current-fleet-sub (defn current-fleet-sub
[multiaccount] [multiaccount]
@@ -32,7 +32,7 @@
{} {}
(node/fleets db))) (node/fleets db)))
(fx/defn show-save-confirmation (rf/defn show-save-confirmation
{:events [:fleet.ui/fleet-selected]} {:events [:fleet.ui/fleet-selected]}
[_ fleet] [_ fleet]
{:ui/show-confirmation {:ui/show-confirmation
@@ -56,7 +56,7 @@
:mail (format-nodes nodes) :mail (format-nodes nodes)
:whisper (format-nodes nodes)})) :whisper (format-nodes nodes)}))
(fx/defn set-nodes [{:keys [db]} fleet nodes] (rf/defn set-nodes [{:keys [db]} fleet nodes]
{:db (-> db {:db (-> db
(assoc-in [:custom-fleets fleet] (nodes->fleet nodes)) (assoc-in [:custom-fleets fleet] (nodes->fleet nodes))
(assoc-in [:mailserver/mailservers fleet] (format-mailservers (assoc-in [:mailserver/mailservers fleet] (format-mailservers
@@ -68,12 +68,12 @@
{} {}
nodes))))}) nodes))))})
(fx/defn save (rf/defn save
{:events [:fleet.ui/save-fleet-confirmed]} {:events [:fleet.ui/save-fleet-confirmed]}
[{:keys [db now] :as cofx} fleet] [{:keys [db now] :as cofx} fleet]
(let [old-fleet (get-in db [:multiaccount :fleet])] (let [old-fleet (get-in db [:multiaccount :fleet])]
(when (not= fleet old-fleet) (when (not= fleet old-fleet)
(fx/merge (rf/merge
cofx cofx
(multiaccounts.update/multiaccount-update :fleet fleet {}) (multiaccounts.update/multiaccount-update :fleet fleet {})
(node/prepare-new-config (node/prepare-new-config
+29 -29
View File
@@ -6,33 +6,33 @@
[status-im.chat.models :as models.chat] [status-im.chat.models :as models.chat]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im2.contexts.activity-center.events :as activity-center])) [status-im2.contexts.activity-center.events :as activity-center]))
(fx/defn navigate-chat-updated (rf/defn navigate-chat-updated
{:events [:navigate-chat-updated]} {:events [:navigate-chat-updated]}
[cofx chat-id] [cofx chat-id]
(when (get-in cofx [:db :chats chat-id]) (when (get-in cofx [:db :chats chat-id])
(models.chat/navigate-to-chat cofx chat-id))) (models.chat/navigate-to-chat cofx chat-id)))
(fx/defn handle-chat-removed (rf/defn handle-chat-removed
{:events [:chat-removed]} {:events [:chat-removed]}
[cofx response] [cofx response]
(fx/merge cofx (rf/merge cofx
{:db (dissoc (:db cofx) :current-chat-id) {:db (dissoc (:db cofx) :current-chat-id)
:dispatch-n [[:sanitize-messages-and-process-response response] :dispatch-n [[:sanitize-messages-and-process-response response]
[:pop-to-root-tab :chat-stack]]} [:pop-to-root-tab :chat-stack]]}
(activity-center/notifications-fetch-unread-count))) (activity-center/notifications-fetch-unread-count)))
(fx/defn handle-chat-update (rf/defn handle-chat-update
{:events [:chat-updated]} {:events [:chat-updated]}
[_ response do-not-navigate?] [_ response do-not-navigate?]
{:dispatch-n [[:sanitize-messages-and-process-response response] {:dispatch-n [[:sanitize-messages-and-process-response response]
(when-not do-not-navigate? [:navigate-chat-updated (.-id (aget (.-chats response) 0))])]}) (when-not do-not-navigate? [:navigate-chat-updated (.-id (aget (.-chats response) 0))])]})
(fx/defn remove-member (rf/defn remove-member
"Format group update message and sign membership" "Format group update message and sign membership"
{:events [:group-chats.ui/remove-member-pressed]} {:events [:group-chats.ui/remove-member-pressed]}
[_ chat-id member do-not-navigate?] [_ chat-id member do-not-navigate?]
@@ -41,7 +41,7 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:chat-updated % do-not-navigate?])}]}) :on-success #(re-frame/dispatch [:chat-updated % do-not-navigate?])}]})
(fx/defn join-chat (rf/defn join-chat
{:events [:group-chats.ui/join-pressed]} {:events [:group-chats.ui/join-pressed]}
[_ chat-id] [_ chat-id]
{::json-rpc/call [{:method "wakuext_confirmJoiningGroup" {::json-rpc/call [{:method "wakuext_confirmJoiningGroup"
@@ -49,7 +49,7 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:chat-updated %])}]}) :on-success #(re-frame/dispatch [:chat-updated %])}]})
(fx/defn create (rf/defn create
{:events [:group-chats.ui/create-pressed] {:events [:group-chats.ui/create-pressed]
:interceptors [(re-frame/inject-cofx :random-guid-generator)]} :interceptors [(re-frame/inject-cofx :random-guid-generator)]}
[{:keys [db] :as cofx} group-name] [{:keys [db] :as cofx} group-name]
@@ -59,7 +59,7 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:chat-updated %])}]})) :on-success #(re-frame/dispatch [:chat-updated %])}]}))
(fx/defn create-from-link (rf/defn create-from-link
[cofx {:keys [chat-id invitation-admin chat-name]}] [cofx {:keys [chat-id invitation-admin chat-name]}]
(if (get-in cofx [:db :chats chat-id]) (if (get-in cofx [:db :chats chat-id])
{:dispatch [:chat.ui/navigate-to-chat chat-id]} {:dispatch [:chat.ui/navigate-to-chat chat-id]}
@@ -68,7 +68,7 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:chat-updated %])}]})) :on-success #(re-frame/dispatch [:chat-updated %])}]}))
(fx/defn make-admin (rf/defn make-admin
{:events [:group-chats.ui/make-admin-pressed]} {:events [:group-chats.ui/make-admin-pressed]}
[_ chat-id member] [_ chat-id member]
{::json-rpc/call [{:method "wakuext_addAdminsToGroupChat" {::json-rpc/call [{:method "wakuext_addAdminsToGroupChat"
@@ -76,7 +76,7 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:chat-updated %])}]}) :on-success #(re-frame/dispatch [:chat-updated %])}]})
(fx/defn add-members (rf/defn add-members
"Add members to a group chat" "Add members to a group chat"
{:events [:group-chats.ui/add-members-pressed]} {:events [:group-chats.ui/add-members-pressed]}
[{{:keys [current-chat-id selected-participants]} :db :as cofx}] [{{:keys [current-chat-id selected-participants]} :db :as cofx}]
@@ -85,7 +85,7 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:chat-updated %])}]}) :on-success #(re-frame/dispatch [:chat-updated %])}]})
(fx/defn add-members-from-invitation (rf/defn add-members-from-invitation
"Add members to a group chat" "Add members to a group chat"
{:events [:group-chats.ui/add-members-from-invitation]} {:events [:group-chats.ui/add-members-from-invitation]}
[{{:keys [current-chat-id] :as db} :db :as cofx} id participant] [{{:keys [current-chat-id] :as db} :db :as cofx} id participant]
@@ -95,7 +95,7 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:chat-updated %])}]}) :on-success #(re-frame/dispatch [:chat-updated %])}]})
(fx/defn leave (rf/defn leave
"Leave chat" "Leave chat"
{:events [:group-chats.ui/leave-chat-confirmed]} {:events [:group-chats.ui/leave-chat-confirmed]}
[{:keys [db] :as cofx} chat-id] [{:keys [db] :as cofx} chat-id]
@@ -104,11 +104,11 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:chat-removed %])}]}) :on-success #(re-frame/dispatch [:chat-removed %])}]})
(fx/defn remove (rf/defn remove
"Remove chat" "Remove chat"
{:events [:group-chats.ui/remove-chat-confirmed]} {:events [:group-chats.ui/remove-chat-confirmed]}
[cofx chat-id] [cofx chat-id]
(fx/merge cofx (rf/merge cofx
(models.chat/deactivate-chat chat-id) (models.chat/deactivate-chat chat-id)
(navigation/pop-to-root-tab :chat-stack))) (navigation/pop-to-root-tab :chat-stack)))
@@ -118,7 +118,7 @@
(defn- valid-name? [name] (defn- valid-name? [name]
(spec/valid? not-blank? name)) (spec/valid? not-blank? name))
(fx/defn name-changed (rf/defn name-changed
"Save chat from edited profile" "Save chat from edited profile"
{:events [:group-chats.ui/name-changed]} {:events [:group-chats.ui/name-changed]}
[{:keys [db] :as cofx} chat-id new-name] [{:keys [db] :as cofx} chat-id new-name]
@@ -129,17 +129,17 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:chat-updated %])}]})) :on-success #(re-frame/dispatch [:chat-updated %])}]}))
(fx/defn membership-retry (rf/defn membership-retry
{:events [:group-chats.ui/membership-retry]} {:events [:group-chats.ui/membership-retry]}
[{{:keys [current-chat-id] :as db} :db}] [{{:keys [current-chat-id] :as db} :db}]
{:db (assoc-in db [:chat/memberships current-chat-id :retry?] true)}) {:db (assoc-in db [:chat/memberships current-chat-id :retry?] true)})
(fx/defn membership-message (rf/defn membership-message
{:events [:group-chats.ui/update-membership-message]} {:events [:group-chats.ui/update-membership-message]}
[{{:keys [current-chat-id] :as db} :db} message] [{{:keys [current-chat-id] :as db} :db} message]
{:db (assoc-in db [:chat/memberships current-chat-id :message] message)}) {:db (assoc-in db [:chat/memberships current-chat-id :message] message)})
(fx/defn send-group-chat-membership-request (rf/defn send-group-chat-membership-request
"Send group chat membership request" "Send group chat membership request"
{:events [:send-group-chat-membership-request]} {:events [:send-group-chat-membership-request]}
[{{:keys [current-chat-id chats] :as db} :db :as cofx}] [{{:keys [current-chat-id chats] :as db} :db :as cofx}]
@@ -151,7 +151,7 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]})) :on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]}))
(fx/defn send-group-chat-membership-rejection (rf/defn send-group-chat-membership-rejection
"Send group chat membership rejection" "Send group chat membership rejection"
{:events [:send-group-chat-membership-rejection]} {:events [:send-group-chat-membership-rejection]}
[cofx invitation-id] [cofx invitation-id]
@@ -160,7 +160,7 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]}) :on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]})
(fx/defn handle-invitations (rf/defn handle-invitations
[{db :db} invitations] [{db :db} invitations]
{:db (update db :group-chat/invitations #(reduce (fn [acc {:keys [id] :as inv}] {:db (update db :group-chat/invitations #(reduce (fn [acc {:keys [id] :as inv}]
(assoc acc id inv)) (assoc acc id inv))
@@ -175,41 +175,41 @@
:type :type
(= constants/invitation-state-removed))) (= constants/invitation-state-removed)))
(fx/defn deselect-contact (rf/defn deselect-contact
{:events [:deselect-contact]} {:events [:deselect-contact]}
[{:keys [db]} id] [{:keys [db]} id]
{:db (update db :group/selected-contacts disj id)}) {:db (update db :group/selected-contacts disj id)})
(fx/defn select-contact (rf/defn select-contact
{:events [:select-contact]} {:events [:select-contact]}
[{:keys [db]} id] [{:keys [db]} id]
{:db (update db :group/selected-contacts conj id)}) {:db (update db :group/selected-contacts conj id)})
(fx/defn deselect-participant (rf/defn deselect-participant
{:events [:deselect-participant]} {:events [:deselect-participant]}
[{:keys [db]} id] [{:keys [db]} id]
{:db (update db :selected-participants disj id)}) {:db (update db :selected-participants disj id)})
(fx/defn select-participant (rf/defn select-participant
{:events [:select-participant]} {:events [:select-participant]}
[{:keys [db]} id] [{:keys [db]} id]
{:db (update db :selected-participants conj id)}) {:db (update db :selected-participants conj id)})
(fx/defn add-participants-toggle-list (rf/defn add-participants-toggle-list
{:events [:group/add-participants-toggle-list]} {:events [:group/add-participants-toggle-list]}
[{db :db}] [{db :db}]
{:db (assoc db :selected-participants #{})}) {:db (assoc db :selected-participants #{})})
(fx/defn show-group-chat-profile (rf/defn show-group-chat-profile
{:events [:show-group-chat-profile]} {:events [:show-group-chat-profile]}
[{:keys [db] :as cofx} chat-id] [{:keys [db] :as cofx} chat-id]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc :new-chat-name (get-in db [:chats chat-id :name])) (assoc :new-chat-name (get-in db [:chats chat-id :name]))
(assoc :current-chat-id chat-id))} (assoc :current-chat-id chat-id))}
(navigation/navigate-to-cofx :group-chat-profile nil))) (navigation/navigate-to-cofx :group-chat-profile nil)))
(fx/defn ui-leave-chat-pressed (rf/defn ui-leave-chat-pressed
{:events [:group-chats.ui/leave-chat-pressed]} {:events [:group-chats.ui/leave-chat-pressed]}
[{:keys [db]} chat-id] [{:keys [db]} chat-id]
(let [chat-name (get-in db [:chats chat-id :name])] (let [chat-name (get-in db [:chats chat-id :name])]
+8 -8
View File
@@ -1,5 +1,5 @@
(ns status-im.keycard.backup-key (ns status-im.keycard.backup-key
(:require [status-im.utils.fx :as fx] (:require [utils.re-frame :as rf]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
@@ -10,21 +10,21 @@
[status-im.signing.core :as signing.core] [status-im.signing.core :as signing.core]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(fx/defn backup-card-pressed (rf/defn backup-card-pressed
{:events [:keycard-settings.ui/backup-card-pressed]} {:events [:keycard-settings.ui/backup-card-pressed]}
[{:keys [db] :as cofx} backup-type] [{:keys [db] :as cofx} backup-type]
(log/debug "[keycard] start backup") (log/debug "[keycard] start backup")
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :creating-backup?] backup-type))} (assoc-in [:keycard :creating-backup?] backup-type))}
(when (:multiaccount db) (when (:multiaccount db)
(navigation/change-tab :profile)) (navigation/change-tab :profile))
(navigation/navigate-to-cofx :seed-phrase nil))) (navigation/navigate-to-cofx :seed-phrase nil)))
(fx/defn recovery-card-pressed (rf/defn recovery-card-pressed
{:events [:keycard-settings.ui/recovery-card-pressed]} {:events [:keycard-settings.ui/recovery-card-pressed]}
[{:keys [db] :as cofx} show-warning] [{:keys [db] :as cofx} show-warning]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
;setting pin-retry-counter is a workaround for the way the PIN view decides if it should accept PUK or PIN ;setting pin-retry-counter is a workaround for the way the PIN view decides if it should accept PUK or PIN
(assoc-in [:keycard :application-info :pin-retry-counter] 3) (assoc-in [:keycard :application-info :pin-retry-counter] 3)
@@ -41,7 +41,7 @@
:on-cancel #()}) :on-cancel #()})
(backup-card-pressed :recovery-card)))) (backup-card-pressed :recovery-card))))
(fx/defn start-keycard-backup (rf/defn start-keycard-backup
{:events [::start-keycard-backup]} {:events [::start-keycard-backup]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
{::multiaccounts.recover/import-multiaccount {:passphrase (-> db {::multiaccounts.recover/import-multiaccount {:passphrase (-> db
@@ -51,10 +51,10 @@
:password nil :password nil
:success-event ::create-backup-card}}) :success-event ::create-backup-card}})
(fx/defn create-backup-card (rf/defn create-backup-card
{:events [::create-backup-card]} {:events [::create-backup-card]}
[{:keys [db] :as cofx} root-data derived-data] [{:keys [db] :as cofx} root-data derived-data]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(update :intro-wizard (update :intro-wizard
assoc assoc
+28 -28
View File
@@ -2,15 +2,15 @@
(:require [status-im.i18n.i18n :as i18n] (:require [status-im.i18n.i18n :as i18n]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.keycard.onboarding :as onboarding] [status-im.keycard.onboarding :as onboarding]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.keycard.common :as common] [status-im.keycard.common :as common]
[status-im.utils.security :as security])) [status-im.utils.security :as security]))
(fx/defn change-credentials-pressed (rf/defn change-credentials-pressed
{:events [:keycard-settings.ui/change-credentials-pressed]} {:events [:keycard-settings.ui/change-credentials-pressed]}
[{:keys [db] :as cofx} changing] [{:keys [db] :as cofx} changing]
(fx/merge cofx (rf/merge cofx
{:db {:db
(assoc-in db [:keycard :pin] {:enter-step :current (assoc-in db [:keycard :pin] {:enter-step :current
:current [] :current []
@@ -27,40 +27,40 @@
:pairing :keycard/proceed-to-change-pairing)})} :pairing :keycard/proceed-to-change-pairing)})}
(common/navigate-to-enter-pin-screen))) (common/navigate-to-enter-pin-screen)))
(fx/defn proceed-to-change-pin (rf/defn proceed-to-change-pin
{:events [:keycard/proceed-to-change-pin]} {:events [:keycard/proceed-to-change-pin]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :pin :enter-step] :original) (assoc-in [:keycard :pin :enter-step] :original)
(assoc-in [:keycard :pin :status] nil))} (assoc-in [:keycard :pin :status] nil))}
(navigation/navigate-replace :enter-pin-settings nil))) (navigation/navigate-replace :enter-pin-settings nil)))
(fx/defn proceed-to-change-puk (rf/defn proceed-to-change-puk
{:events [:keycard/proceed-to-change-puk]} {:events [:keycard/proceed-to-change-puk]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :pin :enter-step] :puk-original) (assoc-in [:keycard :pin :enter-step] :puk-original)
(assoc-in [:keycard :pin :status] nil))} (assoc-in [:keycard :pin :status] nil))}
(navigation/navigate-replace :enter-pin-settings nil))) (navigation/navigate-replace :enter-pin-settings nil)))
(fx/defn proceed-to-change-pairing (rf/defn proceed-to-change-pairing
{:events [:keycard/proceed-to-change-pairing]} {:events [:keycard/proceed-to-change-pairing]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(navigation/navigate-replace cofx :change-pairing-code nil)) (navigation/navigate-replace cofx :change-pairing-code nil))
(fx/defn discard-pin-change (rf/defn discard-pin-change
{:events [::on-cancel]} {:events [::on-cancel]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
(common/clear-pin) (common/clear-pin)
(common/hide-connection-sheet) (common/hide-connection-sheet)
(if (get-in db [:keycard :pin :puk-restore?]) (if (get-in db [:keycard :pin :puk-restore?])
(navigation/navigate-to-cofx :multiaccounts nil) (navigation/navigate-to-cofx :multiaccounts nil)
(navigation/set-stack-root :profile-stack [:my-profile :keycard-settings])))) (navigation/set-stack-root :profile-stack [:my-profile :keycard-settings]))))
(fx/defn change-pin (rf/defn change-pin
{:events [:keycard/change-pin]} {:events [:keycard/change-pin]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [setup-step (get-in db [:keycard :setup-step])] (let [setup-step (get-in db [:keycard :setup-step])]
@@ -78,7 +78,7 @@
(get-in db [:keycard :pin :original])) (get-in db [:keycard :pin :original]))
current-pin (common/vector->string current-pin (common/vector->string
(get-in db [:keycard :pin :current]))] (get-in db [:keycard :pin :current]))]
(fx/merge (rf/merge
cofx cofx
{:db (assoc-in db [:keycard :pin :status] :verifying) {:db (assoc-in db [:keycard :pin :status] :verifying)
@@ -86,7 +86,7 @@
{:new-pin new-pin {:new-pin new-pin
:current-pin current-pin}})))})))) :current-pin current-pin}})))}))))
(fx/defn change-puk (rf/defn change-puk
{:events [:keycard/change-puk]} {:events [:keycard/change-puk]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(common/show-connection-sheet (common/show-connection-sheet
@@ -99,13 +99,13 @@
(get-in db [:keycard :pin :puk-original])) (get-in db [:keycard :pin :puk-original]))
pin (common/vector->string pin (common/vector->string
(get-in db [:keycard :pin :current]))] (get-in db [:keycard :pin :current]))]
(fx/merge (rf/merge
cofx cofx
{:db (assoc-in db [:keycard :pin :status] :verifying) {:db (assoc-in db [:keycard :pin :status] :verifying)
:keycard/change-puk {:puk puk :keycard/change-puk {:puk puk
:pin pin}})))})) :pin pin}})))}))
(fx/defn change-pairing (rf/defn change-pairing
{:events [:keycard/change-pairing]} {:events [:keycard/change-pairing]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(common/show-connection-sheet (common/show-connection-sheet
@@ -117,26 +117,26 @@
(let [pairing (get-in db [:keycard :pin :pairing-code]) (let [pairing (get-in db [:keycard :pin :pairing-code])
pin (common/vector->string pin (common/vector->string
(get-in db [:keycard :pin :current]))] (get-in db [:keycard :pin :current]))]
(fx/merge (rf/merge
cofx cofx
{:db (assoc-in db [:keycard :pin :status] :verifying) {:db (assoc-in db [:keycard :pin :status] :verifying)
:keycard/change-pairing {:pairing pairing :keycard/change-pairing {:pairing pairing
:pin pin}})))})) :pin pin}})))}))
(fx/defn change-pairing-code (rf/defn change-pairing-code
{:events [:keycard/change-pairing-code]} {:events [:keycard/change-pairing-code]}
[{:keys [db] :as cofx} pairing] [{:keys [db] :as cofx} pairing]
(fx/merge (rf/merge
cofx cofx
{:db (assoc-in db [:keycard :pin :pairing-code] (security/unmask pairing))} {:db (assoc-in db [:keycard :pin :pairing-code] (security/unmask pairing))}
(change-pairing))) (change-pairing)))
(fx/defn on-change-pin-success (rf/defn on-change-pin-success
{:events [:keycard.callback/on-change-pin-success]} {:events [:keycard.callback/on-change-pin-success]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [pin (get-in db [:keycard :pin :original]) (let [pin (get-in db [:keycard :pin :original])
puk-restore? (get-in db [:keycard :pin :puk-restore?])] puk-restore? (get-in db [:keycard :pin :puk-restore?])]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :pin] {:status nil {:db (assoc-in db [:keycard :pin] {:status nil
:login pin :login pin
:confirmation [] :confirmation []
@@ -150,10 +150,10 @@
(when (:multiaccounts/login db) (when (:multiaccounts/login db)
(common/get-keys-from-keycard))))) (common/get-keys-from-keycard)))))
(fx/defn on-change-puk-success (rf/defn on-change-puk-success
{:events [:keycard.callback/on-change-puk-success]} {:events [:keycard.callback/on-change-puk-success]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :pin] {:status nil {:db (assoc-in db [:keycard :pin] {:status nil
:puk-original [] :puk-original []
:puk-confirmation [] :puk-confirmation []
@@ -163,10 +163,10 @@
(common/hide-connection-sheet) (common/hide-connection-sheet)
(navigation/set-stack-root :profile-stack [:my-profile :keycard-settings]))) (navigation/set-stack-root :profile-stack [:my-profile :keycard-settings])))
(fx/defn on-change-pairing-success (rf/defn on-change-pairing-success
{:events [:keycard.callback/on-change-pairing-success]} {:events [:keycard.callback/on-change-pairing-success]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :pin] {:status nil {:db (assoc-in db [:keycard :pin] {:status nil
:pairing-code nil :pairing-code nil
:error-label nil}) :error-label nil})
@@ -175,19 +175,19 @@
(common/hide-connection-sheet) (common/hide-connection-sheet)
(navigation/set-stack-root :profile-stack [:my-profile :keycard-settings]))) (navigation/set-stack-root :profile-stack [:my-profile :keycard-settings])))
(fx/defn on-change-pin-error (rf/defn on-change-pin-error
{:events [:keycard.callback/on-change-pin-error]} {:events [:keycard.callback/on-change-pin-error]}
[{:keys [db] :as cofx} error] [{:keys [db] :as cofx} error]
(log/debug "[keycard] change pin error" error) (log/debug "[keycard] change pin error" error)
(let [tag-was-lost? (common/tag-lost? (:error error)) (let [tag-was-lost? (common/tag-lost? (:error error))
pin-retries (common/pin-retries (:error error))] pin-retries (common/pin-retries (:error error))]
(fx/merge cofx (rf/merge cofx
(if tag-was-lost? (if tag-was-lost?
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :pin :status] nil)} {:db (assoc-in db [:keycard :pin :status] nil)}
(common/set-on-card-connected :keycard/change-pin)) (common/set-on-card-connected :keycard/change-pin))
(if-not (nil? pin-retries) (if-not (nil? pin-retries)
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :application-info :pin-retry-counter] pin-retries) (assoc-in [:keycard :application-info :pin-retry-counter] pin-retries)
(update-in [:keycard :pin] assoc (update-in [:keycard :pin] assoc
+57 -57
View File
@@ -6,7 +6,7 @@
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.ui.screens.keycard.keycard-interaction :as keycard-sheet] [status-im.ui.screens.keycard.keycard-interaction :as keycard-sheet]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.keychain.core :as keychain] [status-im.utils.keychain.core :as keychain]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[taoensso.timbre :as log] [taoensso.timbre :as log]
@@ -22,7 +22,7 @@
(defn pin-retries [error] (defn pin-retries [error]
(when-let [matched-error (re-matches pin-mismatch-error error)] (js/parseInt (second (filter some? matched-error))))) (when-let [matched-error (re-matches pin-mismatch-error error)] (js/parseInt (second (filter some? matched-error)))))
(fx/defn dispatch-event (rf/defn dispatch-event
[_ event] [_ event]
{:dispatch [event]}) {:dispatch [event]})
@@ -94,24 +94,24 @@
(fn [supported?] (fn [supported?]
(nfc/set-nfc-supported? supported?))) (nfc/set-nfc-supported? supported?)))
(fx/defn listen-to-hardware-back-button (rf/defn listen-to-hardware-back-button
[{:keys [db]}] [{:keys [db]}]
(when-not (get-in db [:keycard :back-button-listener]) (when-not (get-in db [:keycard :back-button-listener])
{:keycard/listen-to-hardware-back-button nil})) {:keycard/listen-to-hardware-back-button nil}))
(fx/defn remove-listener-to-hardware-back-button (rf/defn remove-listener-to-hardware-back-button
[{:keys [db]}] [{:keys [db]}]
(when-let [listener (get-in db [:keycard :back-button-listener])] (when-let [listener (get-in db [:keycard :back-button-listener])]
{:keycard/remove-listener-to-hardware-back-button listener})) {:keycard/remove-listener-to-hardware-back-button listener}))
(fx/defn set-on-card-connected (rf/defn set-on-card-connected
[{:keys [db]} on-connect] [{:keys [db]} on-connect]
(log/debug "[keycard] set-on-card-connected" on-connect) (log/debug "[keycard] set-on-card-connected" on-connect)
{:db (-> db {:db (-> db
(assoc-in [:keycard :on-card-connected] on-connect) (assoc-in [:keycard :on-card-connected] on-connect)
(assoc-in [:keycard :last-on-card-connected] nil))}) (assoc-in [:keycard :last-on-card-connected] nil))})
(fx/defn stash-on-card-connected (rf/defn stash-on-card-connected
[{:keys [db]}] [{:keys [db]}]
(let [on-connect (get-in db [:keycard :on-card-connected])] (let [on-connect (get-in db [:keycard :on-card-connected])]
(log/debug "[keycard] stash-on-card-connected" on-connect) (log/debug "[keycard] stash-on-card-connected" on-connect)
@@ -119,7 +119,7 @@
(assoc-in [:keycard :last-on-card-connected] on-connect) (assoc-in [:keycard :last-on-card-connected] on-connect)
(assoc-in [:keycard :on-card-connected] nil))})) (assoc-in [:keycard :on-card-connected] nil))}))
(fx/defn restore-on-card-connected (rf/defn restore-on-card-connected
[{:keys [db]}] [{:keys [db]}]
(let [on-connect (or (let [on-connect (or
(get-in db [:keycard :on-card-connected]) (get-in db [:keycard :on-card-connected])
@@ -129,21 +129,21 @@
(assoc-in [:keycard :on-card-connected] on-connect) (assoc-in [:keycard :on-card-connected] on-connect)
(assoc-in [:keycard :last-on-card-connect] nil))})) (assoc-in [:keycard :last-on-card-connect] nil))}))
(fx/defn clear-on-card-connected (rf/defn clear-on-card-connected
[{:keys [db]}] [{:keys [db]}]
(log/debug "[keycard] clear-on-card-connected") (log/debug "[keycard] clear-on-card-connected")
{:db (-> db {:db (-> db
(assoc-in [:keycard :on-card-connected] nil) (assoc-in [:keycard :on-card-connected] nil)
(assoc-in [:keycard :last-on-card-connected] nil))}) (assoc-in [:keycard :last-on-card-connected] nil))})
(fx/defn set-on-card-read (rf/defn set-on-card-read
[{:keys [db]} on-connect] [{:keys [db]} on-connect]
(log/debug "[keycard] set-on-card-read" on-connect) (log/debug "[keycard] set-on-card-read" on-connect)
{:db (-> db {:db (-> db
(assoc-in [:keycard :on-card-read] on-connect) (assoc-in [:keycard :on-card-read] on-connect)
(assoc-in [:keycard :last-on-card-read] nil))}) (assoc-in [:keycard :last-on-card-read] nil))})
(fx/defn stash-on-card-read (rf/defn stash-on-card-read
[{:keys [db]}] [{:keys [db]}]
(let [on-connect (get-in db [:keycard :on-card-read])] (let [on-connect (get-in db [:keycard :on-card-read])]
(log/debug "[keycard] stash-on-card-read" on-connect) (log/debug "[keycard] stash-on-card-read" on-connect)
@@ -151,7 +151,7 @@
(assoc-in [:keycard :last-on-card-read] on-connect) (assoc-in [:keycard :last-on-card-read] on-connect)
(assoc-in [:keycard :on-card-read] nil))})) (assoc-in [:keycard :on-card-read] nil))}))
(fx/defn restore-on-card-read (rf/defn restore-on-card-read
[{:keys [db]}] [{:keys [db]}]
(let [on-connect (or (let [on-connect (or
(get-in db [:keycard :on-card-read]) (get-in db [:keycard :on-card-read])
@@ -161,7 +161,7 @@
(assoc-in [:keycard :on-card-read] on-connect) (assoc-in [:keycard :on-card-read] on-connect)
(assoc-in [:keycard :last-on-card-connect] nil))})) (assoc-in [:keycard :last-on-card-connect] nil))}))
(fx/defn clear-on-card-read (rf/defn clear-on-card-read
[{:keys [db]}] [{:keys [db]}]
(log/debug "[keycard] clear-on-card-read") (log/debug "[keycard] clear-on-card-read")
{:db (-> db {:db (-> db
@@ -177,7 +177,7 @@
:on-connect ::on-card-connected :on-connect ::on-card-connected
:on-disconnect ::on-card-disconnected}])) :on-disconnect ::on-card-disconnected}]))
(fx/defn show-connection-sheet-component (rf/defn show-connection-sheet-component
[{:keys [db] :as cofx} {:keys [on-card-connected on-card-read handler] [{:keys [db] :as cofx} {:keys [on-card-connected on-card-read handler]
{:keys [on-cancel] {:keys [on-cancel]
:or {on-cancel [::cancel-sheet-confirm]}} :or {on-cancel [::cancel-sheet-confirm]}}
@@ -187,7 +187,7 @@
(let [connected? (get-in db [:keycard :card-connected?])] (let [connected? (get-in db [:keycard :card-connected?])]
(log/debug "[keycard] show-sheet-with-connection-check" (log/debug "[keycard] show-sheet-with-connection-check"
"card-connected?" connected?) "card-connected?" connected?)
(fx/merge (rf/merge
cofx cofx
{:dismiss-keyboard true} {:dismiss-keyboard true}
(bottom-sheet/show-bottom-sheet (bottom-sheet/show-bottom-sheet
@@ -205,7 +205,7 @@
(when connected? (when connected?
handler)))) handler))))
(fx/defn show-connection-sheet (rf/defn show-connection-sheet
[{:keys [db] :as cofx} args] [{:keys [db] :as cofx} args]
(let [nfc-running? (get-in db [:keycard :nfc-running?])] (let [nfc-running? (get-in db [:keycard :nfc-running?])]
(log/debug "show connection; already running?" nfc-running?) (log/debug "show connection; already running?" nfc-running?)
@@ -213,34 +213,34 @@
(show-connection-sheet-component cofx args) (show-connection-sheet-component cofx args)
{:keycard/start-nfc-and-show-connection-sheet args}))) {:keycard/start-nfc-and-show-connection-sheet args})))
(fx/defn on-nfc-ready-for-sheet (rf/defn on-nfc-ready-for-sheet
{:events [:keycard.callback/show-connection-sheet]} {:events [:keycard.callback/show-connection-sheet]}
[cofx args] [cofx args]
(log/debug "on-nfc-ready-for-sheet") (log/debug "on-nfc-ready-for-sheet")
(show-connection-sheet-component cofx args)) (show-connection-sheet-component cofx args))
(fx/defn hide-connection-sheet-component (rf/defn hide-connection-sheet-component
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :card-read-in-progress?] false)} {:db (assoc-in db [:keycard :card-read-in-progress?] false)}
(restore-on-card-connected) (restore-on-card-connected)
(restore-on-card-read) (restore-on-card-read)
(bottom-sheet/hide-bottom-sheet))) (bottom-sheet/hide-bottom-sheet)))
(fx/defn hide-connection-sheet (rf/defn hide-connection-sheet
[cofx] [cofx]
(log/debug "hide-connection-sheet") (log/debug "hide-connection-sheet")
{:keycard/stop-nfc-and-hide-connection-sheet nil}) {:keycard/stop-nfc-and-hide-connection-sheet nil})
(fx/defn on-nfc-ready-to-close-sheet (rf/defn on-nfc-ready-to-close-sheet
{:events [:keycard.callback/hide-connection-sheet]} {:events [:keycard.callback/hide-connection-sheet]}
[cofx] [cofx]
(log/debug "on-nfc-ready-to-close-sheet") (log/debug "on-nfc-ready-to-close-sheet")
(hide-connection-sheet-component cofx)) (hide-connection-sheet-component cofx))
(fx/defn clear-pin (rf/defn clear-pin
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge (rf/merge
cofx cofx
{:db (assoc-in db {:db (assoc-in db
[:keycard :pin] [:keycard :pin]
@@ -256,16 +256,16 @@
:on-verified (get-in db [:keycard :pin :on-verified]) :on-verified (get-in db [:keycard :pin :on-verified])
:on-verified-failure (get-in db [:keycard :pin :on-verified])})})) :on-verified-failure (get-in db [:keycard :pin :on-verified])})}))
(fx/defn cancel-sheet-confirm (rf/defn cancel-sheet-confirm
{:events [::cancel-sheet-confirm {:events [::cancel-sheet-confirm
:keycard/back-button-pressed]} :keycard/back-button-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(when-not (get-in db [:keycard :card-connected?]) (when-not (get-in db [:keycard :card-connected?])
(fx/merge cofx (rf/merge cofx
(hide-connection-sheet) (hide-connection-sheet)
(clear-pin)))) (clear-pin))))
(fx/defn cancel-sheet (rf/defn cancel-sheet
{:events [::cancel-sheet]} {:events [::cancel-sheet]}
[_] [_]
{:ui/show-confirmation {:title (i18n/label :t/keycard-cancel-setup-title) {:ui/show-confirmation {:title (i18n/label :t/keycard-cancel-setup-title)
@@ -275,7 +275,7 @@
:on-accept #(re-frame/dispatch [::cancel-sheet-confirm]) :on-accept #(re-frame/dispatch [::cancel-sheet-confirm])
:on-cancel #()}}) :on-cancel #()}})
(fx/defn on-add-listener-to-hardware-back-button (rf/defn on-add-listener-to-hardware-back-button
"Adds listener to hardware back button on Android. "Adds listener to hardware back button on Android.
During keycard setup we show user a warning that setup will be cancelled During keycard setup we show user a warning that setup will be cancelled
when back button pressed. This prevents user from going back during setup when back button pressed. This prevents user from going back during setup
@@ -284,24 +284,24 @@
[{:keys [db]} listener] [{:keys [db]} listener]
{:db (assoc-in db [:keycard :back-button-listener] listener)}) {:db (assoc-in db [:keycard :back-button-listener] listener)})
(fx/defn show-wrong-keycard-alert (rf/defn show-wrong-keycard-alert
[_] [_]
(log/debug "show-wrong-keycard-alert") (log/debug "show-wrong-keycard-alert")
{:utils/show-popup {:title (i18n/label :t/wrong-card) {:utils/show-popup {:title (i18n/label :t/wrong-card)
:content (i18n/label :t/wrong-card-text)}}) :content (i18n/label :t/wrong-card-text)}})
(fx/defn unauthorized-operation (rf/defn unauthorized-operation
[cofx] [cofx]
(fx/merge cofx (rf/merge cofx
{:utils/show-popup {:title "" {:utils/show-popup {:title ""
:content (i18n/label :t/keycard-unauthorized-operation)}} :content (i18n/label :t/keycard-unauthorized-operation)}}
(clear-on-card-connected) (clear-on-card-connected)
(navigation/set-stack-root :profile-stack [:my-profile :keycard-settings]))) (navigation/set-stack-root :profile-stack [:my-profile :keycard-settings])))
(fx/defn navigate-to-enter-pin-screen (rf/defn navigate-to-enter-pin-screen
{:events [:keycard/navigate-to-enter-pin-screen]} {:events [:keycard/navigate-to-enter-pin-screen]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :pin :current] [])} {:db (assoc-in db [:keycard :pin :current] [])}
(navigation/navigate-to-cofx :enter-pin-settings nil))) (navigation/navigate-to-cofx :enter-pin-settings nil)))
@@ -311,11 +311,11 @@
(= error "Tag was lost.") (= error "Tag was lost.")
(= error "NFCError:100"))) (= error "NFCError:100")))
(fx/defn process-error [{:keys [db]} code error] (rf/defn process-error [{:keys [db]} code error]
(when-not (tag-lost-exception? code error) (when-not (tag-lost-exception? code error)
{:db (assoc-in db [:keycard :setup-step] :error)})) {:db (assoc-in db [:keycard :setup-step] :error)}))
(fx/defn get-keys-from-keycard (rf/defn get-keys-from-keycard
[{:keys [db]}] [{:keys [db]}]
(let [key-uid (get-in db [:multiaccounts/login :key-uid]) (let [key-uid (get-in db [:multiaccounts/login :key-uid])
pin (string/join (get-in db [:keycard :pin :login]))] pin (string/join (get-in db [:keycard :pin :login]))]
@@ -325,7 +325,7 @@
{:db (assoc-in db [:keycard :pin :status] :verifying) {:db (assoc-in db [:keycard :pin :status] :verifying)
:keycard/get-keys {:pin pin}}))) :keycard/get-keys {:pin pin}})))
(fx/defn on-get-keys-success (rf/defn on-get-keys-success
{:events [:keycard.callback/on-get-keys-success]} {:events [:keycard.callback/on-get-keys-success]}
[{:keys [db] :as cofx} data] [{:keys [db] :as cofx} data]
(let [{:keys [key-uid encryption-public-key whisper-private-key] (let [{:keys [key-uid encryption-public-key whisper-private-key]
@@ -336,7 +336,7 @@
:key-uid key-uid :key-uid key-uid
:identicon identicon}) :identicon identicon})
save-keys? (get-in db [:multiaccounts/login :save-password?])] save-keys? (get-in db [:multiaccounts/login :save-password?])]
(fx/merge cofx (rf/merge cofx
{:db {:db
(-> db (-> db
(assoc-in [:keycard :pin :status] nil) (assoc-in [:keycard :pin :status] nil)
@@ -363,9 +363,9 @@
(clear-on-card-read) (clear-on-card-read)
(hide-connection-sheet)))) (hide-connection-sheet))))
(fx/defn blocked-or-frozen-keycard-popup (rf/defn blocked-or-frozen-keycard-popup
[{:keys [db] :as cofx} card-status] [{:keys [db] :as cofx} card-status]
(fx/merge (rf/merge
cofx cofx
{:db (assoc-in db [:keycard :pin :status] card-status)} {:db (assoc-in db [:keycard :pin :status] card-status)}
(hide-connection-sheet) (hide-connection-sheet)
@@ -374,15 +374,15 @@
(when-not (or (:multiaccounts/login db) (:popover/popover db)) (when-not (or (:multiaccounts/login db) (:popover/popover db))
(popover/show-popover {:view card-status})))) (popover/show-popover {:view card-status}))))
(fx/defn blocked-keycard-popup (rf/defn blocked-keycard-popup
[cofx] [cofx]
(blocked-or-frozen-keycard-popup cofx :blocked-card)) (blocked-or-frozen-keycard-popup cofx :blocked-card))
(fx/defn frozen-keycard-popup (rf/defn frozen-keycard-popup
[cofx] [cofx]
(blocked-or-frozen-keycard-popup cofx :frozen-card)) (blocked-or-frozen-keycard-popup cofx :frozen-card))
(fx/defn on-get-keys-error (rf/defn on-get-keys-error
{:events [:keycard.callback/on-get-keys-error]} {:events [:keycard.callback/on-get-keys-error]}
[{:keys [db] :as cofx} error] [{:keys [db] :as cofx} error]
(log/debug "[keycard] get keys error: " error) (log/debug "[keycard] get keys error: " error)
@@ -393,7 +393,7 @@
(if tag-was-lost? (if tag-was-lost?
{:db (assoc-in db [:keycard :pin :status] nil)} {:db (assoc-in db [:keycard :pin :status] nil)}
(if-not (nil? pin-retries-count) (if-not (nil? pin-retries-count)
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :application-info :pin-retry-counter] pin-retries-count) (assoc-in [:keycard :application-info :pin-retry-counter] pin-retries-count)
@@ -406,7 +406,7 @@
(when (zero? pin-retries-count) (frozen-keycard-popup))) (when (zero? pin-retries-count) (frozen-keycard-popup)))
(show-wrong-keycard-alert))))) (show-wrong-keycard-alert)))))
(fx/defn factory-reset (rf/defn factory-reset
{:events [:keycard/factory-reset]} {:events [:keycard/factory-reset]}
[{:keys [db]} on-card-read] [{:keys [db]} on-card-read]
(log/debug "[keycard] factory-reset") (log/debug "[keycard] factory-reset")
@@ -415,7 +415,7 @@
;; Get application info ;; Get application info
(fx/defn update-pairings (rf/defn update-pairings
[{:keys [db]} instance-uid pairing] [{:keys [db]} instance-uid pairing]
(let [paired-on (utils.datetime/timestamp) (let [paired-on (utils.datetime/timestamp)
pairings (-> (get-in db [:keycard :pairings]) pairings (-> (get-in db [:keycard :pairings])
@@ -423,13 +423,13 @@
{:keycard/persist-pairings pairings {:keycard/persist-pairings pairings
:db (assoc-in db [:keycard :pairings] pairings)})) :db (assoc-in db [:keycard :pairings] pairings)}))
(fx/defn get-application-info (rf/defn get-application-info
{:events [:keycard/get-application-info]} {:events [:keycard/get-application-info]}
[{:keys [db]} on-card-read] [{:keys [db]} on-card-read]
(log/debug "[keycard] get-application-info") (log/debug "[keycard] get-application-info")
{:keycard/get-application-info {:on-success on-card-read}}) {:keycard/get-application-info {:on-success on-card-read}})
(fx/defn on-get-application-info-success (rf/defn on-get-application-info-success
{:events [:keycard.callback/on-get-application-info-success]} {:events [:keycard.callback/on-get-application-info-success]}
[{:keys [db] :as cofx} info on-success] [{:keys [db] :as cofx} info on-success]
(let [{:keys [pin-retry-counter puk-retry-counter instance-uid new-pairing]} info (let [{:keys [pin-retry-counter puk-retry-counter instance-uid new-pairing]} info
@@ -441,7 +441,7 @@
"on-success" on-success' "on-success" on-success'
"pin-retry-counter" pin-retry-counter "pin-retry-counter" pin-retry-counter
"puk-retry-counter" puk-retry-counter) "puk-retry-counter" puk-retry-counter)
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :pin :enter-step] enter-step) (assoc-in [:keycard :pin :enter-step] enter-step)
@@ -461,7 +461,7 @@
(when on-success' (when on-success'
(dispatch-event cofx on-success'))))))) (dispatch-event cofx on-success')))))))
(fx/defn on-get-application-info-error (rf/defn on-get-application-info-error
{:events [:keycard.callback/on-get-application-info-error]} {:events [:keycard.callback/on-get-application-info-error]}
[{:keys [db] :as cofx} error] [{:keys [db] :as cofx} error]
(let [on-card-read (get-in db [:keycard :on-card-read]) (let [on-card-read (get-in db [:keycard :on-card-read])
@@ -475,10 +475,10 @@
last-on-card-connected) last-on-card-connected)
(when-not tag-was-lost? (when-not tag-was-lost?
(if login? (if login?
(fx/merge cofx (rf/merge cofx
(clear-on-card-read) (clear-on-card-read)
(navigation/navigate-to-cofx :not-keycard nil)) (navigation/navigate-to-cofx :not-keycard nil))
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :application-info-error] error)} {:db (assoc-in db [:keycard :application-info-error] error)}
(when (contains? (when (contains?
@@ -489,7 +489,7 @@
(when on-card-read (when on-card-read
(dispatch-event on-card-read))))))) (dispatch-event on-card-read)))))))
(fx/defn on-card-connected (rf/defn on-card-connected
{:events [::on-card-connected]} {:events [::on-card-connected]}
[{:keys [db] :as cofx} _] [{:keys [db] :as cofx} _]
(let [instance-uid (get-in db [:keycard :application-info :instance-uid]) (let [instance-uid (get-in db [:keycard :application-info :instance-uid])
@@ -502,7 +502,7 @@
(log/debug "[keycard] on-card-connected" on-card-connected (log/debug "[keycard] on-card-connected" on-card-connected
"on-card-read" on-card-read) "on-card-read" on-card-read)
(when on-card-connected (when on-card-connected
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :card-read-in-progress?] (boolean on-card-read)))} (assoc-in [:keycard :card-read-in-progress?] (boolean on-card-read)))}
(when on-card-connected (when on-card-connected
@@ -512,11 +512,11 @@
(nil? on-card-connected)) (nil? on-card-connected))
(get-application-info on-card-read)))))) (get-application-info on-card-read))))))
(fx/defn on-card-disconnected (rf/defn on-card-disconnected
{:events [::on-card-disconnected]} {:events [::on-card-disconnected]}
[{:keys [db] :as cofx} _] [{:keys [db] :as cofx} _]
(log/debug "[keycard] card disconnected") (log/debug "[keycard] card disconnected")
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :card-read-in-progress?] false))} (assoc-in [:keycard :card-read-in-progress?] false))}
(restore-on-card-connected) (restore-on-card-connected)
@@ -525,7 +525,7 @@
(defn keycard-multiaccount? [db] (defn keycard-multiaccount? [db]
(boolean (get-in db [:multiaccount :keycard-pairing]))) (boolean (get-in db [:multiaccount :keycard-pairing])))
(fx/defn verify-pin (rf/defn verify-pin
{:events [:keycard/verify-pin]} {:events [:keycard/verify-pin]}
[{:keys [db] :as cofx} {:keys [pin-step on-card-connected on-failure on-success]}] [{:keys [db] :as cofx} {:keys [pin-step on-card-connected on-failure on-success]}]
(let [on-success (or on-success (let [on-success (or on-success
@@ -534,7 +534,7 @@
(get-in db [:keycard :pin :on-verified-failure])) (get-in db [:keycard :pin :on-verified-failure]))
pin-step (or pin-step pin-step (or pin-step
(get-in db [:keycard :pin :step]))] (get-in db [:keycard :pin :step]))]
(fx/merge (rf/merge
cofx cofx
{:db (update-in db [:keycard :pin] assoc {:db (update-in db [:keycard :pin] assoc
:step pin-step :step pin-step
@@ -545,12 +545,12 @@
:handler :handler
(fn [{:keys [db] :as cofx}] (fn [{:keys [db] :as cofx}]
(let [pin (vector->string (get-in db [:keycard :pin pin-step]))] (let [pin (vector->string (get-in db [:keycard :pin pin-step]))]
(fx/merge (rf/merge
cofx cofx
{:db (assoc-in db [:keycard :pin :status] :verifying) {:db (assoc-in db [:keycard :pin :status] :verifying)
:keycard/verify-pin {:pin pin}})))})))) :keycard/verify-pin {:pin pin}})))}))))
(fx/defn navigete-to-keycard-settings (rf/defn navigete-to-keycard-settings
{:events [::navigate-to-keycard-settings]} {:events [::navigate-to-keycard-settings]}
[cofx] [cofx]
(navigation/set-stack-root :profile-stack [:my-profile :keycard-settings])) (navigation/set-stack-root :profile-stack [:my-profile :keycard-settings]))
+57 -57
View File
@@ -18,21 +18,21 @@
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.datetime :as utils.datetime] [status-im.utils.datetime :as utils.datetime]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(fx/defn show-keycard-has-multiaccount-alert (rf/defn show-keycard-has-multiaccount-alert
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :setup-step] nil) {:db (assoc-in db [:keycard :setup-step] nil)
:utils/show-confirmation {:title nil :utils/show-confirmation {:title nil
:content (i18n/label :t/keycard-has-multiaccount-on-it) :content (i18n/label :t/keycard-has-multiaccount-on-it)
:cancel-button-text "" :cancel-button-text ""
:confirm-button-text :t/okay}})) :confirm-button-text :t/okay}}))
(fx/defn load-pin-screen (rf/defn load-pin-screen
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :setup-step] :pin) (assoc-in [:keycard :setup-step] :pin)
(assoc-in [:keycard :pin] {:enter-step :original (assoc-in [:keycard :pin] {:enter-step :original
@@ -40,9 +40,9 @@
:confirmation []}))} :confirmation []}))}
(navigation/navigate-to-cofx :keycard-onboarding-pin nil))) (navigation/navigate-to-cofx :keycard-onboarding-pin nil)))
(fx/defn load-recovery-pin-screen (rf/defn load-recovery-pin-screen
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :pin] {:enter-step :import-multiaccount (assoc-in [:keycard :pin] {:enter-step :import-multiaccount
:import-multiaccount [] :import-multiaccount []
@@ -50,21 +50,21 @@
(common/listen-to-hardware-back-button) (common/listen-to-hardware-back-button)
(navigation/navigate-replace :keycard-recovery-pin nil))) (navigation/navigate-replace :keycard-recovery-pin nil)))
(fx/defn load-pairing (rf/defn load-pairing
[{:keys [db]}] [{:keys [db]}]
(let [instance-uid (get-in db [:keycard :application-info :instance-uid]) (let [instance-uid (get-in db [:keycard :application-info :instance-uid])
pairing-data (or (get-in db [:keycard :pairings (keyword instance-uid)]) pairing-data (or (get-in db [:keycard :pairings (keyword instance-uid)])
(get-in db [:keycard :pairings instance-uid]))] (get-in db [:keycard :pairings instance-uid]))]
{:db (update-in db [:keycard :secrets] merge pairing-data)})) {:db (update-in db [:keycard :secrets] merge pairing-data)}))
(fx/defn proceed-setup-with-initialized-card (rf/defn proceed-setup-with-initialized-card
[{:keys [db] :as cofx} flow instance-uid paired?] [{:keys [db] :as cofx} flow instance-uid paired?]
(log/debug "[keycard] proceed-setup-with-initialized-card" (log/debug "[keycard] proceed-setup-with-initialized-card"
"instance-uid" instance-uid) "instance-uid" instance-uid)
(if (= flow :import) (if (= flow :import)
(navigation/navigate-to-cofx cofx :keycard-recovery-no-key nil) (navigation/navigate-to-cofx cofx :keycard-recovery-no-key nil)
(if paired? (if paired?
(fx/merge cofx (rf/merge cofx
(common/listen-to-hardware-back-button) (common/listen-to-hardware-back-button)
(when (= flow :create) (when (= flow :create)
(mnemonic/set-mnemonic)) (mnemonic/set-mnemonic))
@@ -74,25 +74,25 @@
(onboarding/load-pairing-screen cofx) (onboarding/load-pairing-screen cofx)
(recovery/load-pair-screen cofx))))) (recovery/load-pair-screen cofx)))))
(fx/defn navigate-to-keycard-settings (rf/defn navigate-to-keycard-settings
{:events [:profile.ui/keycard-settings-button-pressed]} {:events [:profile.ui/keycard-settings-button-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :pin :on-verified] nil) (assoc-in [:keycard :pin :on-verified] nil)
(assoc-in [:keycard :setup-step] nil))} (assoc-in [:keycard :setup-step] nil))}
(common/clear-on-card-connected) (common/clear-on-card-connected)
(navigation/navigate-to-cofx :keycard-settings nil))) (navigation/navigate-to-cofx :keycard-settings nil)))
(fx/defn password-option-pressed (rf/defn password-option-pressed
{:eevents [:keycard.ui/password-option-pressed]} {:eevents [:keycard.ui/password-option-pressed]}
[{:keys [db]}] [{:keys [db]}]
(when (= (get-in db [:keycard :flow]) :create) (when (= (get-in db [:keycard :flow]) :create)
#())) ;;TODO with v1 flow #())) ;;TODO with v1 flow
(fx/defn settings-screen-did-load (rf/defn settings-screen-did-load
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :pin :on-verified] nil) (assoc-in [:keycard :pin :on-verified] nil)
(assoc-in [:keycard :setup-step] nil))} (assoc-in [:keycard :setup-step] nil))}
@@ -122,13 +122,13 @@
[{:keys [db]}] [{:keys [db]}]
{:db (assoc-in db [:keycard :setup-step] nil)}) {:db (assoc-in db [:keycard :setup-step] nil)})
(fx/defn set-nfc-supported (rf/defn set-nfc-supported
{:events [:keycard.callback/check-nfc-support-success]} {:events [:keycard.callback/check-nfc-support-success]}
[_ supported?] [_ supported?]
{:keycard/set-nfc-supported supported?}) {:keycard/set-nfc-supported supported?})
;; TODO: Should be listener and replace the view in bottom sheet to avoid this ;; TODO: Should be listener and replace the view in bottom sheet to avoid this
(fx/defn on-check-nfc-enabled-success (rf/defn on-check-nfc-enabled-success
{:events [:keycard.callback/check-nfc-enabled-success]} {:events [:keycard.callback/check-nfc-enabled-success]}
[{:keys [db]} nfc-enabled?] [{:keys [db]} nfc-enabled?]
(log/debug "[keycard] check-nfc-enabled-success" (log/debug "[keycard] check-nfc-enabled-success"
@@ -149,11 +149,11 @@
(defn- proceed-to-puk-confirmation [fx] (defn- proceed-to-puk-confirmation [fx]
(assoc-in fx [:db :keycard :pin :enter-step] :puk)) (assoc-in fx [:db :keycard :pin :enter-step] :puk))
(fx/defn on-unblock-pin-success (rf/defn on-unblock-pin-success
{:events [:keycard.callback/on-unblock-pin-success]} {:events [:keycard.callback/on-unblock-pin-success]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [reset-pin (get-in db [:keycard :pin :reset])] (let [reset-pin (get-in db [:keycard :pin :reset])]
(fx/merge cofx (rf/merge cofx
{:db {:db
(-> db (-> db
(update-in [:keycard :application-info] assoc (update-in [:keycard :application-info] assoc
@@ -171,14 +171,14 @@
(common/clear-on-card-connected) (common/clear-on-card-connected)
(common/clear-on-card-read)))) (common/clear-on-card-read))))
(fx/defn on-unblock-pin-error (rf/defn on-unblock-pin-error
{:events [:keycard.callback/on-unblock-pin-error]} {:events [:keycard.callback/on-unblock-pin-error]}
[{:keys [db] :as cofx} error] [{:keys [db] :as cofx} error]
(let [tag-was-lost? (common/tag-lost? (:error error)) (let [tag-was-lost? (common/tag-lost? (:error error))
puk-retries (common/pin-retries (:error error))] puk-retries (common/pin-retries (:error error))]
(log/debug "[keycard] unblock pin error" error) (log/debug "[keycard] unblock pin error" error)
(when-not tag-was-lost? (when-not tag-was-lost?
(fx/merge cofx (rf/merge cofx
{:db {:db
(-> db (-> db
(assoc-in [:keycard :application-info :puk-retry-counter] puk-retries) (assoc-in [:keycard :application-info :puk-retry-counter] puk-retries)
@@ -190,17 +190,17 @@
(common/hide-connection-sheet))))) (common/hide-connection-sheet)))))
(fx/defn clear-on-verify-handlers (rf/defn clear-on-verify-handlers
[{:keys [db]}] [{:keys [db]}]
{:db (update-in db [:keycard :pin] {:db (update-in db [:keycard :pin]
dissoc :on-verified-failure :on-verified)}) dissoc :on-verified-failure :on-verified)})
(fx/defn on-verify-pin-success (rf/defn on-verify-pin-success
{:events [:keycard.callback/on-verify-pin-success]} {:events [:keycard.callback/on-verify-pin-success]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [on-verified (get-in db [:keycard :pin :on-verified])] (let [on-verified (get-in db [:keycard :pin :on-verified])]
(log/debug "[hardwaller] success pin verification. on-verified" on-verified) (log/debug "[hardwaller] success pin verification. on-verified" on-verified)
(fx/merge cofx (rf/merge cofx
{:db (update-in db [:keycard :pin] merge {:status nil {:db (update-in db [:keycard :pin] merge {:status nil
:error-label nil})} :error-label nil})}
(common/clear-on-card-connected) (common/clear-on-card-connected)
@@ -223,7 +223,7 @@
(common/dispatch-event on-verified)) (common/dispatch-event on-verified))
(clear-on-verify-handlers)))) (clear-on-verify-handlers))))
(fx/defn on-verify-pin-error (rf/defn on-verify-pin-error
{:events [:keycard.callback/on-verify-pin-error]} {:events [:keycard.callback/on-verify-pin-error]}
[{:keys [db] :as cofx} error] [{:keys [db] :as cofx} error]
(let [tag-was-lost? (common/tag-lost? (:error error)) (let [tag-was-lost? (common/tag-lost? (:error error))
@@ -234,7 +234,7 @@
(log/debug "[keycard] verify pin error" error) (log/debug "[keycard] verify pin error" error)
(when-not tag-was-lost? (when-not tag-was-lost?
(if-not (nil? pin-retries) (if-not (nil? pin-retries)
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :application-info :pin-retry-counter] pin-retries) (assoc-in [:keycard :application-info :pin-retry-counter] pin-retries)
(update-in [:keycard :pin] assoc (update-in [:keycard :pin] assoc
@@ -259,12 +259,12 @@
:ms 200}]})) :ms 200}]}))
#_(clear-on-verify-handlers)) #_(clear-on-verify-handlers))
(fx/merge cofx (rf/merge cofx
(common/hide-connection-sheet) (common/hide-connection-sheet)
(common/show-wrong-keycard-alert) (common/show-wrong-keycard-alert)
(clear-on-verify-handlers)))))) (clear-on-verify-handlers))))))
(fx/defn unblock-pin (rf/defn unblock-pin
{:events [:keycard/unblock-pin]} {:events [:keycard/unblock-pin]}
[cofx] [cofx]
(common/show-connection-sheet (common/show-connection-sheet
@@ -283,14 +283,14 @@
(def pin-code-length 6) (def pin-code-length 6)
(def puk-code-length 12) (def puk-code-length 12)
(fx/defn handle-pin-input (rf/defn handle-pin-input
[{:keys [db]} enter-step] [{:keys [db]} enter-step]
(let [numbers-entered (count (get-in db [:keycard :pin enter-step]))] (let [numbers-entered (count (get-in db [:keycard :pin enter-step]))]
(when (or (= numbers-entered pin-code-length) (when (or (= numbers-entered pin-code-length)
(= numbers-entered puk-code-length)) (= numbers-entered puk-code-length))
{:dispatch [:keycard/process-pin-input]}))) {:dispatch [:keycard/process-pin-input]})))
(fx/defn update-pin (rf/defn update-pin
{:events [:keycard.ui/pin-numpad-button-pressed]} {:events [:keycard.ui/pin-numpad-button-pressed]}
[{:keys [db] :as cofx} number enter-step] [{:keys [db] :as cofx} number enter-step]
(log/debug "update-pin" enter-step) (log/debug "update-pin" enter-step)
@@ -298,7 +298,7 @@
need-update? (if (or (= enter-step :puk) (= enter-step :puk-original) (= enter-step :puk-confirmation)) need-update? (if (or (= enter-step :puk) (= enter-step :puk-original) (= enter-step :puk-confirmation))
(< numbers-entered puk-code-length) (< numbers-entered puk-code-length)
(< numbers-entered pin-code-length))] (< numbers-entered pin-code-length))]
(fx/merge cofx (rf/merge cofx
{:db (cond-> (-> db {:db (cond-> (-> db
(assoc-in [:keycard :pin :enter-step] enter-step) (assoc-in [:keycard :pin :enter-step] enter-step)
(assoc-in [:keycard :pin :status] nil)) (assoc-in [:keycard :pin :status] nil))
@@ -333,7 +333,7 @@
; current - current PIN to perform actions which require PIN auth ; current - current PIN to perform actions which require PIN auth
; original - new PIN when user changes it or creates new one ; original - new PIN when user changes it or creates new one
; confirmation - confirmation for new PIN ; confirmation - confirmation for new PIN
(fx/defn process-pin-input (rf/defn process-pin-input
{:events [:keycard/process-pin-input]} {:events [:keycard/process-pin-input]}
[{:keys [db]}] [{:keys [db]}]
(let [enter-step (get-in db [:keycard :pin :enter-step]) (let [enter-step (get-in db [:keycard :pin :enter-step])
@@ -417,15 +417,15 @@
(get-in db [:keycard :pin :reset-confirmation]))) (get-in db [:keycard :pin :reset-confirmation])))
(pin-reset-error :t/pin-mismatch)))) (pin-reset-error :t/pin-mismatch))))
(fx/defn set-multiaccount-pairing (rf/defn set-multiaccount-pairing
[cofx _ pairing paired-on] [cofx _ pairing paired-on]
(fx/merge cofx (rf/merge cofx
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:keycard-pairing pairing {}) :keycard-pairing pairing {})
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:keycard-paired-on paired-on {}))) :keycard-paired-on paired-on {})))
(fx/defn on-retrieve-pairings-success (rf/defn on-retrieve-pairings-success
{:events [:keycard.callback/on-retrieve-pairings-success]} {:events [:keycard.callback/on-retrieve-pairings-success]}
[{:keys [db]} pairings] [{:keys [db]} pairings]
(card/set-pairings pairings) (card/set-pairings pairings)
@@ -438,7 +438,7 @@
;; with setup and skip the pairing step if the pairing was already done during a previous ;; with setup and skip the pairing step if the pairing was already done during a previous
;; unfinished setup. ;; unfinished setup.
(fx/defn on-pair-success (rf/defn on-pair-success
{:events [:keycard.callback/on-pair-success]} {:events [:keycard.callback/on-pair-success]}
[{:keys [db] :as cofx} pairing] [{:keys [db] :as cofx} pairing]
(let [setup-step (get-in db [:keycard :setup-step]) (let [setup-step (get-in db [:keycard :setup-step])
@@ -452,7 +452,7 @@
next-step (if (= setup-step :pair) next-step (if (= setup-step :pair)
:begin :begin
:card-ready)] :card-ready)]
(fx/merge cofx (rf/merge cofx
{:keycard/persist-pairings pairings {:keycard/persist-pairings pairings
:db (-> db :db (-> db
(assoc-in [:keycard :pairings] pairings) (assoc-in [:keycard :pairings] pairings)
@@ -474,7 +474,7 @@
(when (= flow :create) (when (= flow :create)
(mnemonic/set-mnemonic))))) (mnemonic/set-mnemonic)))))
(fx/defn on-pair-error (rf/defn on-pair-error
{:events [:keycard.callback/on-pair-error]} {:events [:keycard.callback/on-pair-error]}
[{:keys [db] :as cofx} {:keys [error code]}] [{:keys [db] :as cofx} {:keys [error code]}]
(log/debug "[keycard] pair error: " error) (log/debug "[keycard] pair error: " error)
@@ -483,7 +483,7 @@
flow (get-in db [:keycard :flow])] flow (get-in db [:keycard :flow])]
(log/debug "[keycard] on-pair-error" setup-step "flow:" flow) (log/debug "[keycard] on-pair-error" setup-step "flow:" flow)
(when-not tag-was-lost? (when-not tag-was-lost?
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :setup-error] (i18n/label :t/invalid-pairing-password))} {:db (assoc-in db [:keycard :setup-error] (i18n/label :t/invalid-pairing-password))}
(common/set-on-card-connected (if (= setup-step :pairing) (common/set-on-card-connected (if (= setup-step :pairing)
:keycard/load-pairing-screen :keycard/load-pairing-screen
@@ -494,7 +494,7 @@
(when (not= setup-step :enter-pair-code) (when (not= setup-step :enter-pair-code)
(common/process-error code error)))))) (common/process-error code error))))))
(fx/defn set-setup-step (rf/defn set-setup-step
[{:keys [db]} card-state] [{:keys [db]} card-state]
{:db (assoc-in db [:keycard :setup-step] {:db (assoc-in db [:keycard :setup-step]
(case card-state (case card-state
@@ -504,7 +504,7 @@
:multiaccount :import-multiaccount :multiaccount :import-multiaccount
:begin))}) :begin))})
(fx/defn show-no-keycard-applet-alert [_] (rf/defn show-no-keycard-applet-alert [_]
{:utils/show-confirmation {:title (i18n/label :t/no-keycard-applet-on-card) {:utils/show-confirmation {:title (i18n/label :t/no-keycard-applet-on-card)
:content (i18n/label :t/keycard-applet-install-instructions) :content (i18n/label :t/keycard-applet-install-instructions)
:cancel-button-text "" :cancel-button-text ""
@@ -512,7 +512,7 @@
;; NOTE: Maybe replaced by multiple events based on on flow to make it easier to maintain. ;; NOTE: Maybe replaced by multiple events based on on flow to make it easier to maintain.
;; Because there are many execution paths it is harder to follow all possible states. ;; Because there are many execution paths it is harder to follow all possible states.
(fx/defn check-card-state (rf/defn check-card-state
{:events [:keycard/check-card-state]} {:events [:keycard/check-card-state]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [app-info (get-in db [:keycard :application-info]) (let [app-info (get-in db [:keycard :application-info])
@@ -522,7 +522,7 @@
(log/debug "[keycard] check-card-state" (log/debug "[keycard] check-card-state"
"card-state" card-state "card-state" card-state
"flow" flow) "flow" flow)
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :card-state] card-state)} {:db (assoc-in db [:keycard :card-state] card-state)}
(set-setup-step card-state) (set-setup-step card-state)
@@ -538,7 +538,7 @@
(if (= flow :import) (if (= flow :import)
(navigation/navigate-to-cofx :keycard-recovery-no-key nil) (navigation/navigate-to-cofx :keycard-recovery-no-key nil)
(fn [cofx] (fn [cofx]
(fx/merge (rf/merge
cofx cofx
(common/clear-on-card-read) (common/clear-on-card-read)
(load-pin-screen))))) (load-pin-screen)))))
@@ -560,25 +560,25 @@
(#{:create :recovery} flow)) (#{:create :recovery} flow))
(show-keycard-has-multiaccount-alert))))) (show-keycard-has-multiaccount-alert)))))
(fx/defn on-card-connected (rf/defn on-card-connected
{:events [:keycard.callback/on-card-connected]} {:events [:keycard.callback/on-card-connected]}
[{:keys [db]} _] [{:keys [db]} _]
(log/debug "[keycard] card globally connected") (log/debug "[keycard] card globally connected")
{:db (assoc-in db [:keycard :card-connected?] true)}) {:db (assoc-in db [:keycard :card-connected?] true)})
(fx/defn on-card-disconnected (rf/defn on-card-disconnected
{:events [:keycard.callback/on-card-disconnected]} {:events [:keycard.callback/on-card-disconnected]}
[{:keys [db]} _] [{:keys [db]} _]
(log/debug "[keycard] card disconnected") (log/debug "[keycard] card disconnected")
{:db (assoc-in db [:keycard :card-connected?] false)}) {:db (assoc-in db [:keycard :card-connected?] false)})
(fx/defn on-nfc-user-cancelled (rf/defn on-nfc-user-cancelled
{:events [:keycard.callback/on-nfc-user-cancelled]} {:events [:keycard.callback/on-nfc-user-cancelled]}
[{:keys [db]} _] [{:keys [db]} _]
(log/debug "[keycard] nfc user cancelled") (log/debug "[keycard] nfc user cancelled")
{:dispatch [:signing.ui/cancel-is-pressed]}) {:dispatch [:signing.ui/cancel-is-pressed]})
(fx/defn on-nfc-timeout (rf/defn on-nfc-timeout
{:events [:keycard.callback/on-nfc-timeout]} {:events [:keycard.callback/on-nfc-timeout]}
[{:keys [db]} _] [{:keys [db]} _]
(log/debug "[keycard] nfc timeout") (log/debug "[keycard] nfc timeout")
@@ -587,45 +587,45 @@
(assoc-in [:keycard :card-connected?] false)) (assoc-in [:keycard :card-connected?] false))
:dispatch-later [{:ms 500 :dispatch [:keycard.ui/start-nfc]}]}) :dispatch-later [{:ms 500 :dispatch [:keycard.ui/start-nfc]}]})
(fx/defn on-register-card-events (rf/defn on-register-card-events
{:events [:keycard.callback/on-register-card-events]} {:events [:keycard.callback/on-register-card-events]}
[{:keys [db]} listeners] [{:keys [db]} listeners]
{:db (update-in db [:keycard :listeners] merge listeners)}) {:db (update-in db [:keycard :listeners] merge listeners)})
(fx/defn ui-recovery-phrase-cancel-pressed (rf/defn ui-recovery-phrase-cancel-pressed
{:events [:keycard.ui/recovery-phrase-cancel-pressed]} {:events [:keycard.ui/recovery-phrase-cancel-pressed]}
[{:keys [db]}] [{:keys [db]}]
{:db (assoc-in db [:keycard :setup-step] :recovery-phrase)}) {:db (assoc-in db [:keycard :setup-step] :recovery-phrase)})
(fx/defn ui-pin-numpad-delete-button-pressed (rf/defn ui-pin-numpad-delete-button-pressed
{:events [:keycard.ui/pin-numpad-delete-button-pressed]} {:events [:keycard.ui/pin-numpad-delete-button-pressed]}
[{:keys [db]} step] [{:keys [db]} step]
(when-not (empty? (get-in db [:keycard :pin step])) (when-not (empty? (get-in db [:keycard :pin step]))
{:db (update-in db [:keycard :pin step] pop)})) {:db (update-in db [:keycard :pin step] pop)}))
(fx/defn start-nfc (rf/defn start-nfc
{:events [:keycard.ui/start-nfc]} {:events [:keycard.ui/start-nfc]}
[cofx] [cofx]
{:keycard/start-nfc nil}) {:keycard/start-nfc nil})
(fx/defn stop-nfc (rf/defn stop-nfc
{:events [:keycard.ui/stop-nfc]} {:events [:keycard.ui/stop-nfc]}
[cofx] [cofx]
{:keycard/stop-nfc nil {:keycard/stop-nfc nil
:keycard.callback/on-card-disconnected nil}) :keycard.callback/on-card-disconnected nil})
(fx/defn start-nfc-success (rf/defn start-nfc-success
{:events [:keycard.callback/start-nfc-success]} {:events [:keycard.callback/start-nfc-success]}
[{:keys [db]} _] [{:keys [db]} _]
(log/debug "[keycard] nfc started success") (log/debug "[keycard] nfc started success")
{:db (assoc-in db [:keycard :nfc-running?] true)}) {:db (assoc-in db [:keycard :nfc-running?] true)})
(fx/defn start-nfc-failure (rf/defn start-nfc-failure
{:events [:keycard.callback/start-nfc-failure]} {:events [:keycard.callback/start-nfc-failure]}
[{:keys [db]} _] [{:keys [db]} _]
(log/debug "[keycard] nfc failed starting")) ;; leave current value on :nfc-running (log/debug "[keycard] nfc failed starting")) ;; leave current value on :nfc-running
(fx/defn stop-nfc-success (rf/defn stop-nfc-success
{:events [:keycard.callback/stop-nfc-success]} {:events [:keycard.callback/stop-nfc-success]}
[{:keys [db]} _] [{:keys [db]} _]
(log/debug "[keycard] nfc stopped success") (log/debug "[keycard] nfc stopped success")
@@ -634,7 +634,7 @@
(assoc-in [:keycard :nfc-running?] false) (assoc-in [:keycard :nfc-running?] false)
(assoc-in [:keycard :card-connected?] false))}) (assoc-in [:keycard :card-connected?] false))})
(fx/defn stop-nfc-failure (rf/defn stop-nfc-failure
{:events [:keycard.callback/stop-nfc-failure]} {:events [:keycard.callback/stop-nfc-failure]}
[{:keys [db]} _] [{:keys [db]} _]
(log/debug "[keycard] nfc failed stopping")) ;; leave current value on :nfc-running (log/debug "[keycard] nfc failed stopping")) ;; leave current value on :nfc-running
+7 -7
View File
@@ -1,14 +1,14 @@
(ns status-im.keycard.delete-key (ns status-im.keycard.delete-key
(:require [status-im2.navigation.events :as navigation] (:require [status-im2.navigation.events :as navigation]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.keycard.common :as common])) [status-im.keycard.common :as common]))
(fx/defn reset-card-pressed (rf/defn reset-card-pressed
{:events [:keycard-settings.ui/reset-card-pressed]} {:events [:keycard-settings.ui/reset-card-pressed]}
[cofx] [cofx]
(navigation/navigate-to-cofx cofx :reset-card nil)) (navigation/navigate-to-cofx cofx :reset-card nil))
(fx/defn delete-card (rf/defn delete-card
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [key-uid (get-in db [:keycard :application-info :key-uid]) (let [key-uid (get-in db [:keycard :application-info :key-uid])
multiaccount-key-uid (get-in db [:multiaccount :key-uid])] multiaccount-key-uid (get-in db [:multiaccount :key-uid])]
@@ -17,21 +17,21 @@
{:keycard/delete nil} {:keycard/delete nil}
(common/unauthorized-operation cofx)))) (common/unauthorized-operation cofx))))
(fx/defn navigate-to-reset-card-screen (rf/defn navigate-to-reset-card-screen
{:events [:keycard/navigate-to-reset-card-screen]} {:events [:keycard/navigate-to-reset-card-screen]}
[cofx] [cofx]
(navigation/navigate-to-cofx cofx :reset-card nil)) (navigation/navigate-to-cofx cofx :reset-card nil))
(fx/defn reset-card-next-button-pressed (rf/defn reset-card-next-button-pressed
{:events [:keycard-settings.ui/reset-card-next-button-pressed]} {:events [:keycard-settings.ui/reset-card-next-button-pressed]}
[{:keys [db]}] [{:keys [db]}]
{:db (assoc-in db [:keycard :reset-card :disabled?] true) {:db (assoc-in db [:keycard :reset-card :disabled?] true)
:dispatch [:keycard/proceed-to-reset-card false]}) :dispatch [:keycard/proceed-to-reset-card false]})
(fx/defn proceed-to-reset-card (rf/defn proceed-to-reset-card
{:events [:keycard/proceed-to-reset-card]} {:events [:keycard/proceed-to-reset-card]}
[{:keys [db] :as cofx} keep-keys-on-keycard?] [{:keys [db] :as cofx} keep-keys-on-keycard?]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :pin] {:enter-step :current {:db (assoc-in db [:keycard :pin] {:enter-step :current
:current [] :current []
:puk [] :puk []
+7 -7
View File
@@ -1,22 +1,22 @@
(ns status-im.keycard.export-key (ns status-im.keycard.export-key
(:require [status-im.utils.fx :as fx] (:require [utils.re-frame :as rf]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.keycard.wallet :as wallet] [status-im.keycard.wallet :as wallet]
[status-im.keycard.common :as common])) [status-im.keycard.common :as common]))
(fx/defn on-export-key-error (rf/defn on-export-key-error
{:events [:keycard.callback/on-export-key-error]} {:events [:keycard.callback/on-export-key-error]}
[{:keys [db] :as cofx} error] [{:keys [db] :as cofx} error]
(log/debug "[keycard] export key error" error) (log/debug "[keycard] export key error" error)
(let [tag-was-lost? (common/tag-lost? (:error error)) (let [tag-was-lost? (common/tag-lost? (:error error))
pin-retries (common/pin-retries (:error error))] pin-retries (common/pin-retries (:error error))]
(cond tag-was-lost? (cond tag-was-lost?
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :pin :status] nil)} {:db (assoc-in db [:keycard :pin :status] nil)}
(common/set-on-card-connected :wallet.accounts/generate-new-keycard-account)) (common/set-on-card-connected :wallet.accounts/generate-new-keycard-account))
(not (nil? pin-retries)) (not (nil? pin-retries))
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :application-info :pin-retry-counter] pin-retries) (assoc-in [:keycard :application-info :pin-retry-counter] pin-retries)
(update-in [:keycard :pin] assoc (update-in [:keycard :pin] assoc
@@ -32,16 +32,16 @@
(common/hide-connection-sheet) (common/hide-connection-sheet)
(when (zero? pin-retries) (common/frozen-keycard-popup))) (when (zero? pin-retries) (common/frozen-keycard-popup)))
:else :else
(fx/merge cofx (rf/merge cofx
(common/show-wrong-keycard-alert) (common/show-wrong-keycard-alert)
(common/clear-pin) (common/clear-pin)
(common/hide-connection-sheet))))) (common/hide-connection-sheet)))))
(fx/defn on-export-key-success (rf/defn on-export-key-success
{:events [:keycard.callback/on-export-key-success]} {:events [:keycard.callback/on-export-key-success]}
[{:keys [db] :as cofx} pubkey] [{:keys [db] :as cofx} pubkey]
(let [callback-fn (get-in db [:keycard :on-export-success])] (let [callback-fn (get-in db [:keycard :on-export-success])]
(fx/merge cofx (rf/merge cofx
{:dispatch (callback-fn pubkey)} {:dispatch (callback-fn pubkey)}
(wallet/hide-pin-sheet) (wallet/hide-pin-sheet)
(common/clear-pin) (common/clear-pin)
+22 -22
View File
@@ -1,7 +1,7 @@
(ns status-im.keycard.login (ns status-im.keycard.login
(:require [status-im.ethereum.core :as ethereum] (:require [status-im.ethereum.core :as ethereum]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.keycard.common :as common] [status-im.keycard.common :as common]
@@ -11,49 +11,49 @@
[status-im.bottom-sheet.core :as bottom-sheet] [status-im.bottom-sheet.core :as bottom-sheet]
[status-im.signing.core :as signing.core])) [status-im.signing.core :as signing.core]))
(fx/defn login-got-it-pressed (rf/defn login-got-it-pressed
{:events [:keycard.login.pin.ui/got-it-pressed {:events [:keycard.login.pin.ui/got-it-pressed
:keycard.login.pin.ui/cancel-pressed]} :keycard.login.pin.ui/cancel-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db db} {:db db}
(navigation/pop-to-root-tab :multiaccounts-stack))) (navigation/pop-to-root-tab :multiaccounts-stack)))
(fx/defn login-pin-more-icon-pressed (rf/defn login-pin-more-icon-pressed
{:events [:keycard.login.pin.ui/more-icon-pressed]} {:events [:keycard.login.pin.ui/more-icon-pressed]}
[cofx] [cofx]
(bottom-sheet/show-bottom-sheet cofx {:view :keycard.login/more})) (bottom-sheet/show-bottom-sheet cofx {:view :keycard.login/more}))
(fx/defn login-create-key-pressed (rf/defn login-create-key-pressed
{:events [:keycard.login.ui/create-new-key-pressed]} {:events [:keycard.login.ui/create-new-key-pressed]}
[cofx] [cofx]
(fx/merge cofx (rf/merge cofx
(bottom-sheet/hide-bottom-sheet) (bottom-sheet/hide-bottom-sheet)
(onboarding/start-onboarding-flow))) (onboarding/start-onboarding-flow)))
(fx/defn login-add-key-pressed (rf/defn login-add-key-pressed
{:events [:keycard.login.ui/add-key-pressed]} {:events [:keycard.login.ui/add-key-pressed]}
[cofx] [cofx]
(recovery/start-import-flow cofx)) (recovery/start-import-flow cofx))
(fx/defn login-remember-me-changed (rf/defn login-remember-me-changed
{:events [:keycard.login.ui/remember-me-changed]} {:events [:keycard.login.ui/remember-me-changed]}
[{:keys [db] :as cofx} value] [{:keys [db] :as cofx} value]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :remember-me?] value)})) {:db (assoc-in db [:keycard :remember-me?] value)}))
(fx/defn login-pair-card-pressed (rf/defn login-pair-card-pressed
{:events [:keycard.login.ui/pair-card-pressed]} {:events [:keycard.login.ui/pair-card-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(log/debug "[keycard] load-pair-card-pressed") (log/debug "[keycard] load-pair-card-pressed")
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :flow] :login)} {:db (assoc-in db [:keycard :flow] :login)}
(navigation/navigate-to-cofx :keycard-recovery-pair nil))) (navigation/navigate-to-cofx :keycard-recovery-pair nil)))
(fx/defn reset-pin (rf/defn reset-pin
{:events [::reset-pin]} {:events [::reset-pin]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge (rf/merge
cofx cofx
(signing.core/discard) (signing.core/discard)
(fn [{:keys [db]}] (fn [{:keys [db]}]
@@ -73,7 +73,7 @@
(navigation/navigate-replace :keycard-pin nil) (navigation/navigate-replace :keycard-pin nil)
(navigation/navigate-to-cofx :keycard-pin nil))))) (navigation/navigate-to-cofx :keycard-pin nil)))))
(fx/defn dismiss-frozen-keycard-popover (rf/defn dismiss-frozen-keycard-popover
{:events [::frozen-keycard-popover-dismissed]} {:events [::frozen-keycard-popover-dismissed]}
[{:keys [db]}] [{:keys [db]}]
{:db (-> db {:db (-> db
@@ -81,7 +81,7 @@
(update :keycard dissoc :setup-step)) (update :keycard dissoc :setup-step))
:hide-popover nil}) :hide-popover nil})
(fx/defn login-with-keycard (rf/defn login-with-keycard
{:events [:keycard/login-with-keycard]} {:events [:keycard/login-with-keycard]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [:pin-retry-counter :puk-retry-counter] (let [{:keys [:pin-retry-counter :puk-retry-counter]
@@ -101,22 +101,22 @@
"no pairing" paired?) "no pairing" paired?)
(cond (cond
(empty? application-info) (empty? application-info)
(fx/merge cofx (rf/merge cofx
(common/hide-connection-sheet) (common/hide-connection-sheet)
(navigation/navigate-to-cofx :not-keycard nil)) (navigation/navigate-to-cofx :not-keycard nil))
(empty? key-uid) (empty? key-uid)
(fx/merge cofx (rf/merge cofx
(common/hide-connection-sheet) (common/hide-connection-sheet)
(navigation/navigate-to-cofx :keycard-blank nil)) (navigation/navigate-to-cofx :keycard-blank nil))
multiaccount-mismatch? multiaccount-mismatch?
(fx/merge cofx (rf/merge cofx
(common/hide-connection-sheet) (common/hide-connection-sheet)
(navigation/navigate-to-cofx :keycard-wrong nil)) (navigation/navigate-to-cofx :keycard-wrong nil))
(not paired?) (not paired?)
(fx/merge cofx (rf/merge cofx
(common/hide-connection-sheet) (common/hide-connection-sheet)
(navigation/navigate-to-cofx :keycard-unpaired nil)) (navigation/navigate-to-cofx :keycard-unpaired nil))
@@ -128,7 +128,7 @@
:else :else
(common/get-keys-from-keycard cofx)))) (common/get-keys-from-keycard cofx))))
(fx/defn proceed-to-login (rf/defn proceed-to-login
{:events [::login-after-reset]} {:events [::login-after-reset]}
[cofx] [cofx]
(log/debug "[keycard] proceed-to-login") (log/debug "[keycard] proceed-to-login")
@@ -139,7 +139,7 @@
:on-card-read :keycard/login-with-keycard :on-card-read :keycard/login-with-keycard
:handler (common/get-application-info :keycard/login-with-keycard)})) :handler (common/get-application-info :keycard/login-with-keycard)}))
(fx/defn on-keycard-keychain-keys (rf/defn on-keycard-keychain-keys
{:events [:multiaccounts.login.callback/get-keycard-keys-success]} {:events [:multiaccounts.login.callback/get-keycard-keys-success]}
[{:keys [db] :as cofx} key-uid [encryption-public-key whisper-private-key :as creds]] [{:keys [db] :as cofx} key-uid [encryption-public-key whisper-private-key :as creds]]
(if (nil? creds) (if (nil? creds)
@@ -171,7 +171,7 @@
:password encryption-public-key :password encryption-public-key
:chat-key whisper-private-key}}))) :chat-key whisper-private-key}})))
(fx/defn on-login-success (rf/defn on-login-success
{:events [:keycard.login.callback/login-success]} {:events [:keycard.login.callback/login-success]}
[_ result] [_ result]
(log/debug "loginWithKeycard success: " result)) (log/debug "loginWithKeycard success: " result))
+5 -5
View File
@@ -1,11 +1,11 @@
(ns status-im.keycard.mnemonic (ns status-im.keycard.mnemonic
(:require [status-im2.navigation.events :as navigation] (:require [status-im2.navigation.events :as navigation]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.keycard.common :as common] [status-im.keycard.common :as common]
status-im.keycard.fx)) status-im.keycard.fx))
(fx/defn set-mnemonic (rf/defn set-mnemonic
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(log/debug "[keycard] set-mnemonic") (log/debug "[keycard] set-mnemonic")
(let [selected-id (get-in db [:intro-wizard :selected-id]) (let [selected-id (get-in db [:intro-wizard :selected-id])
@@ -15,7 +15,7 @@
(reduced mnemonic))) (reduced mnemonic)))
nil nil
(get-in db [:intro-wizard :multiaccounts]))] (get-in db [:intro-wizard :multiaccounts]))]
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :setup-step] :recovery-phrase) (assoc-in [:keycard :setup-step] :recovery-phrase)
@@ -24,11 +24,11 @@
(common/hide-connection-sheet) (common/hide-connection-sheet)
(navigation/navigate-replace :keycard-onboarding-recovery-phrase nil)))) (navigation/navigate-replace :keycard-onboarding-recovery-phrase nil))))
(fx/defn load-loading-keys-screen (rf/defn load-loading-keys-screen
{:events [:keycard.ui/recovery-phrase-confirm-pressed {:events [:keycard.ui/recovery-phrase-confirm-pressed
:keycard/load-loading-keys-screen]} :keycard/load-loading-keys-screen]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge (rf/merge
cofx cofx
{:db (assoc-in db [:keycard :setup-step] :loading-keys)} {:db (assoc-in db [:keycard :setup-step] :loading-keys)}
(common/show-connection-sheet (common/show-connection-sheet
+44 -44
View File
@@ -3,7 +3,7 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im.keycard.common :as common] [status-im.keycard.common :as common]
[status-im.keycard.mnemonic :as mnemonic] [status-im.keycard.mnemonic :as mnemonic]
@@ -12,7 +12,7 @@
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[status-im.constants :as constants])) [status-im.constants :as constants]))
(fx/defn begin-setup-button-pressed (rf/defn begin-setup-button-pressed
{:keys [:keycard.ui/begin-setup-button-pressed]} {:keys [:keycard.ui/begin-setup-button-pressed]}
[{:keys [db]}] [{:keys [db]}]
{:db (-> db {:db (-> db
@@ -21,7 +21,7 @@
(assoc-in [:keycard :pin :original] []) (assoc-in [:keycard :pin :original] [])
(assoc-in [:keycard :pin :confirmation] []))}) (assoc-in [:keycard :pin :confirmation] []))})
(fx/defn start-installation (rf/defn start-installation
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [card-state (get-in db [:keycard :card-state]) (let [card-state (get-in db [:keycard :card-state])
pin (common/vector->string (get-in db [:keycard :pin :original]))] pin (common/vector->string (get-in db [:keycard :pin :original]))]
@@ -33,12 +33,12 @@
(do (do
(log/debug (str "Cannot start keycard installation from state: " card-state)) (log/debug (str "Cannot start keycard installation from state: " card-state))
(fx/merge cofx (rf/merge cofx
{:utils/show-popup {:title (i18n/label :t/error) {:utils/show-popup {:title (i18n/label :t/error)
:content (i18n/label :t/something-went-wrong)}} :content (i18n/label :t/something-went-wrong)}}
(navigation/navigate-to-cofx :keycard-authentication-method nil)))))) (navigation/navigate-to-cofx :keycard-authentication-method nil))))))
(fx/defn load-preparing-screen (rf/defn load-preparing-screen
{:events [:keycard/load-preparing-screen]} {:events [:keycard/load-preparing-screen]}
[cofx] [cofx]
(common/show-connection-sheet (common/show-connection-sheet
@@ -47,11 +47,11 @@
:on-card-connected :keycard/load-preparing-screen :on-card-connected :keycard/load-preparing-screen
:handler start-installation})) :handler start-installation}))
(fx/defn load-pairing-screen (rf/defn load-pairing-screen
{:events [:keycard/load-pairing-screen {:events [:keycard/load-pairing-screen
:keycard.onboarding.puk-code.ui/confirm-pressed]} :keycard.onboarding.puk-code.ui/confirm-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge (rf/merge
cofx cofx
{:db (assoc-in db [:keycard :setup-step] :pairing)} {:db (assoc-in db [:keycard :setup-step] :pairing)}
(common/show-connection-sheet (common/show-connection-sheet
@@ -59,7 +59,7 @@
:on-card-connected :keycard/load-pairing-screen :on-card-connected :keycard/load-pairing-screen
:handler (common/dispatch-event :keycard/pair)}))) :handler (common/dispatch-event :keycard/pair)})))
(fx/defn puk-code-next-pressed (rf/defn puk-code-next-pressed
{:events [:keycard.onboarding.puk-code.ui/next-pressed]} {:events [:keycard.onboarding.puk-code.ui/next-pressed]}
[_] [_]
{:ui/show-confirmation {:title (i18n/label :t/secret-keys-confirmation-title) {:ui/show-confirmation {:title (i18n/label :t/secret-keys-confirmation-title)
@@ -69,11 +69,11 @@
:on-accept #(re-frame/dispatch [:keycard.onboarding.puk-code.ui/confirm-pressed]) :on-accept #(re-frame/dispatch [:keycard.onboarding.puk-code.ui/confirm-pressed])
:on-cancel #()}}) :on-cancel #()}})
(fx/defn load-finishing-screen (rf/defn load-finishing-screen
{:events [:keycard.onboarding.recovery-phrase-confirm-word2.ui/next-pressed {:events [:keycard.onboarding.recovery-phrase-confirm-word2.ui/next-pressed
:keycard/load-finishing-screen]} :keycard/load-finishing-screen]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge (rf/merge
cofx cofx
{:db (assoc-in db [:keycard :setup-step] :loading-keys)} {:db (assoc-in db [:keycard :setup-step] :loading-keys)}
(common/show-connection-sheet (common/show-connection-sheet
@@ -81,12 +81,12 @@
:on-card-connected :keycard/load-finishing-screen :on-card-connected :keycard/load-finishing-screen
:handler (common/dispatch-event :keycard/generate-and-load-key)}))) :handler (common/dispatch-event :keycard/generate-and-load-key)})))
(fx/defn recovery-phrase-learn-more-pressed (rf/defn recovery-phrase-learn-more-pressed
{:events [:keycard.onboarding.recovery-phrase.ui/learn-more-pressed]} {:events [:keycard.onboarding.recovery-phrase.ui/learn-more-pressed]}
[_] [_]
(.openURL ^js react/linking constants/keycard-integration-link)) (.openURL ^js react/linking constants/keycard-integration-link))
(fx/defn recovery-phrase-next-pressed (rf/defn recovery-phrase-next-pressed
{:events [:keycard.onboarding.recovery-phrase.ui/next-pressed {:events [:keycard.onboarding.recovery-phrase.ui/next-pressed
:keycard.ui/recovery-phrase-next-button-pressed]} :keycard.ui/recovery-phrase-next-button-pressed]}
[_] [_]
@@ -97,13 +97,13 @@
:on-accept #(re-frame/dispatch [:keycard.onboarding.recovery-phrase.ui/confirm-pressed]) :on-accept #(re-frame/dispatch [:keycard.onboarding.recovery-phrase.ui/confirm-pressed])
:on-cancel #()}}) :on-cancel #()}})
(fx/defn recovery-phrase-start-confirmation (rf/defn recovery-phrase-start-confirmation
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [mnemonic (get-in db [:keycard :secrets :mnemonic]) (let [mnemonic (get-in db [:keycard :secrets :mnemonic])
[word1 word2] (shuffle (map-indexed vector (clojure.string/split mnemonic #" "))) [word1 word2] (shuffle (map-indexed vector (clojure.string/split mnemonic #" ")))
word1 (zipmap [:idx :word] word1) word1 (zipmap [:idx :word] word1)
word2 (zipmap [:idx :word] word2)] word2 (zipmap [:idx :word] word2)]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :setup-step] :recovery-phrase-confirm-word1) (assoc-in [:keycard :setup-step] :recovery-phrase-confirm-word1)
(assoc-in [:keycard :recovery-phrase :step] :word1) (assoc-in [:keycard :recovery-phrase :step] :word1)
@@ -113,14 +113,14 @@
(assoc-in [:keycard :recovery-phrase :word2] word2))} (assoc-in [:keycard :recovery-phrase :word2] word2))}
(common/remove-listener-to-hardware-back-button)))) (common/remove-listener-to-hardware-back-button))))
(fx/defn recovery-phrase-confirm-pressed (rf/defn recovery-phrase-confirm-pressed
{:events [:keycard.onboarding.recovery-phrase.ui/confirm-pressed]} {:events [:keycard.onboarding.recovery-phrase.ui/confirm-pressed]}
[cofx] [cofx]
(fx/merge cofx (rf/merge cofx
(recovery-phrase-start-confirmation) (recovery-phrase-start-confirmation)
(navigation/navigate-to-cofx :keycard-onboarding-recovery-phrase-confirm-word1 nil))) (navigation/navigate-to-cofx :keycard-onboarding-recovery-phrase-confirm-word1 nil)))
(fx/defn recovery-phrase-next-word (rf/defn recovery-phrase-next-word
[{:keys [db]}] [{:keys [db]}]
{:db (-> db {:db (-> db
(assoc-in [:keycard :recovery-phrase :step] :word2) (assoc-in [:keycard :recovery-phrase :step] :word2)
@@ -128,12 +128,12 @@
(assoc-in [:keycard :recovery-phrase :input-word] nil) (assoc-in [:keycard :recovery-phrase :input-word] nil)
(assoc-in [:keycard :setup-step] :recovery-phrase-confirm-word2))}) (assoc-in [:keycard :setup-step] :recovery-phrase-confirm-word2))})
(fx/defn proceed-with-generating-key (rf/defn proceed-with-generating-key
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [pin (get-in db [:keycard :secrets :pin] (let [pin (get-in db [:keycard :secrets :pin]
(common/vector->string (get-in db [:keycard :pin :current])))] (common/vector->string (get-in db [:keycard :pin :current])))]
(if (empty? pin) (if (empty? pin)
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :pin] {:enter-step :current (assoc-in [:keycard :pin] {:enter-step :current
:on-verified :keycard/generate-and-load-key :on-verified :keycard/generate-and-load-key
@@ -142,7 +142,7 @@
(navigation/navigate-to-cofx :keycard-onboarding-pin nil)) (navigation/navigate-to-cofx :keycard-onboarding-pin nil))
(load-finishing-screen cofx)))) (load-finishing-screen cofx))))
(fx/defn recovery-phrase-confirm-word-next-pressed (rf/defn recovery-phrase-confirm-word-next-pressed
{:events [:keycard.onboarding.recovery-phrase-confirm-word.ui/next-pressed {:events [:keycard.onboarding.recovery-phrase-confirm-word.ui/next-pressed
:keycard.onboarding.recovery-phrase-confirm-word.ui/input-submitted]} :keycard.onboarding.recovery-phrase-confirm-word.ui/input-submitted]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
@@ -151,27 +151,27 @@
{:keys [word]} (get-in db [:keycard :recovery-phrase step])] {:keys [word]} (get-in db [:keycard :recovery-phrase step])]
(if (= word input-word) (if (= word input-word)
(if (= (:view-id db) :keycard-onboarding-recovery-phrase-confirm-word1) (if (= (:view-id db) :keycard-onboarding-recovery-phrase-confirm-word1)
(fx/merge cofx (rf/merge cofx
(recovery-phrase-next-word) (recovery-phrase-next-word)
(navigation/navigate-replace :keycard-onboarding-recovery-phrase-confirm-word2 nil)) (navigation/navigate-replace :keycard-onboarding-recovery-phrase-confirm-word2 nil))
(proceed-with-generating-key cofx)) (proceed-with-generating-key cofx))
{:db (assoc-in db [:keycard :recovery-phrase :confirm-error] (i18n/label :t/wrong-word))}))) {:db (assoc-in db [:keycard :recovery-phrase :confirm-error] (i18n/label :t/wrong-word))})))
(fx/defn recovery-phrase-confirm-word-input-changed (rf/defn recovery-phrase-confirm-word-input-changed
{:events [:keycard.onboarding.recovery-phrase-confirm-word.ui/input-changed]} {:events [:keycard.onboarding.recovery-phrase-confirm-word.ui/input-changed]}
[{:keys [db]} input] [{:keys [db]} input]
{:db (assoc-in db [:keycard :recovery-phrase :input-word] input)}) {:db (assoc-in db [:keycard :recovery-phrase :input-word] input)})
(fx/defn pair-code-input-changed (rf/defn pair-code-input-changed
{:events [:keycard.onboarding.pair.ui/input-changed]} {:events [:keycard.onboarding.pair.ui/input-changed]}
[{:keys [db]} input] [{:keys [db]} input]
{:db (assoc-in db [:keycard :secrets :password] input)}) {:db (assoc-in db [:keycard :secrets :password] input)})
(fx/defn keycard-option-pressed (rf/defn keycard-option-pressed
{:events [:onboarding.ui/keycard-option-pressed]} {:events [:onboarding.ui/keycard-option-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [flow (get-in db [:keycard :flow])] (let [flow (get-in db [:keycard :flow])]
(fx/merge cofx (rf/merge cofx
{:keycard/check-nfc-enabled nil} {:keycard/check-nfc-enabled nil}
(if (= flow :import) (if (= flow :import)
(navigation/navigate-to-cofx :keycard-recovery-intro nil) (navigation/navigate-to-cofx :keycard-recovery-intro nil)
@@ -179,16 +179,16 @@
(common/listen-to-hardware-back-button) (common/listen-to-hardware-back-button)
(navigation/navigate-to-cofx :keycard-onboarding-intro nil)))))) (navigation/navigate-to-cofx :keycard-onboarding-intro nil))))))
(fx/defn start-onboarding-flow (rf/defn start-onboarding-flow
{:events [:keycard/start-onboarding-flow]} {:events [:keycard/start-onboarding-flow]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :flow] :create) {:db (assoc-in db [:keycard :flow] :create)
:keycard/check-nfc-enabled nil} :keycard/check-nfc-enabled nil}
(common/listen-to-hardware-back-button) (common/listen-to-hardware-back-button)
(navigation/navigate-to-cofx :keycard-onboarding-intro nil))) (navigation/navigate-to-cofx :keycard-onboarding-intro nil)))
(fx/defn open-nfc-settings-pressed (rf/defn open-nfc-settings-pressed
{:events [:keycard.onboarding.nfc-on/open-nfc-settings-pressed]} {:events [:keycard.onboarding.nfc-on/open-nfc-settings-pressed]}
[_] [_]
{:keycard/open-nfc-settings nil}) {:keycard/open-nfc-settings nil})
@@ -201,7 +201,7 @@
:on-accept #(re-frame/dispatch [:keycard.ui/recovery-phrase-confirm-pressed]) :on-accept #(re-frame/dispatch [:keycard.ui/recovery-phrase-confirm-pressed])
:on-cancel #(re-frame/dispatch [:keycard.ui/recovery-phrase-cancel-pressed])}}) :on-cancel #(re-frame/dispatch [:keycard.ui/recovery-phrase-cancel-pressed])}})
(fx/defn recovery-phrase-confirm-word (rf/defn recovery-phrase-confirm-word
{:events [:keycard.ui/recovery-phrase-confirm-word-next-button-pressed]} {:events [:keycard.ui/recovery-phrase-confirm-word-next-button-pressed]}
[{:keys [db]}] [{:keys [db]}]
(let [step (get-in db [:keycard :recovery-phrase :step]) (let [step (get-in db [:keycard :recovery-phrase :step])
@@ -213,21 +213,21 @@
(show-recover-confirmation)) (show-recover-confirmation))
{:db (assoc-in db [:keycard :recovery-phrase :confirm-error] (i18n/label :t/wrong-word))}))) {:db (assoc-in db [:keycard :recovery-phrase :confirm-error] (i18n/label :t/wrong-word))})))
(fx/defn recovery-phrase-next-button-pressed (rf/defn recovery-phrase-next-button-pressed
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(if (= (get-in db [:keycard :flow]) :create) (if (= (get-in db [:keycard :flow]) :create)
(recovery-phrase-start-confirmation cofx) (recovery-phrase-start-confirmation cofx)
(let [mnemonic (get-in db [:multiaccounts/recover :passphrase])] (let [mnemonic (get-in db [:multiaccounts/recover :passphrase])]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :secrets :mnemonic] mnemonic)} {:db (assoc-in db [:keycard :secrets :mnemonic] mnemonic)}
(mnemonic/load-loading-keys-screen))))) (mnemonic/load-loading-keys-screen)))))
(fx/defn on-install-applet-and-init-card-success (rf/defn on-install-applet-and-init-card-success
{:events [:keycard.callback/on-install-applet-and-init-card-success {:events [:keycard.callback/on-install-applet-and-init-card-success
:keycard.callback/on-init-card-success]} :keycard.callback/on-init-card-success]}
[{:keys [db] :as cofx} secrets] [{:keys [db] :as cofx} secrets]
(let [secrets' (js->clj secrets :keywordize-keys true)] (let [secrets' (js->clj secrets :keywordize-keys true)]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :card-state] :init) (assoc-in [:keycard :card-state] :init)
(assoc-in [:keycard :setup-step] :secret-keys) (assoc-in [:keycard :setup-step] :secret-keys)
@@ -237,17 +237,17 @@
:on-card-read :keycard/check-card-state :on-card-read :keycard/check-card-state
:handler (common/get-application-info :keycard/check-card-state)})))) :handler (common/get-application-info :keycard/check-card-state)}))))
(fx/defn on-install-applet-and-init-card-error (rf/defn on-install-applet-and-init-card-error
{:events [:keycard.callback/on-install-applet-and-init-card-error {:events [:keycard.callback/on-install-applet-and-init-card-error
:keycard.callback/on-init-card-error]} :keycard.callback/on-init-card-error]}
[{:keys [db] :as cofx} {:keys [code error]}] [{:keys [db] :as cofx} {:keys [code error]}]
(log/debug "[keycard] install applet and init card error: " error) (log/debug "[keycard] install applet and init card error: " error)
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :setup-error] error)} {:db (assoc-in db [:keycard :setup-error] error)}
(common/set-on-card-connected :keycard/load-preparing-screen) (common/set-on-card-connected :keycard/load-preparing-screen)
(common/process-error code error))) (common/process-error code error)))
(fx/defn generate-and-load-key (rf/defn generate-and-load-key
{:events [:keycard/generate-and-load-key]} {:events [:keycard/generate-and-load-key]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [pin]} (let [{:keys [pin]}
@@ -266,22 +266,22 @@
mnemonic (or (:mnemonic multiaccount) mnemonic (or (:mnemonic multiaccount)
recovery-mnemonic) recovery-mnemonic)
pin' (or pin (common/vector->string (get-in db [:keycard :pin :current])))] pin' (or pin (common/vector->string (get-in db [:keycard :pin :current])))]
(fx/merge cofx (rf/merge cofx
{:keycard/generate-and-load-key {:keycard/generate-and-load-key
{:mnemonic mnemonic {:mnemonic mnemonic
:pin pin' :pin pin'
:key-uid (:key-uid multiaccount) :key-uid (:key-uid multiaccount)
:delete-multiaccount? (get-in db [:keycard :delete-account?])}}))) :delete-multiaccount? (get-in db [:keycard :delete-account?])}})))
(fx/defn factory-reset-card-toggle (rf/defn factory-reset-card-toggle
{:events [:keycard.onboarding.intro.ui/factory-reset-card-toggle]} {:events [:keycard.onboarding.intro.ui/factory-reset-card-toggle]}
[{:keys [db] :as cofx} checked?] [{:keys [db] :as cofx} checked?]
{:db (assoc-in db [:keycard :factory-reset-card?] checked?)}) {:db (assoc-in db [:keycard :factory-reset-card?] checked?)})
(fx/defn begin-setup-pressed (rf/defn begin-setup-pressed
{:events [:keycard.onboarding.intro.ui/begin-setup-pressed]} {:events [:keycard.onboarding.intro.ui/begin-setup-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(update :keycard (update :keycard
@@ -301,7 +301,7 @@
:on-card-read :keycard/check-card-state :on-card-read :keycard/check-card-state
:handler (common/get-application-info :keycard/check-card-state)})))) :handler (common/get-application-info :keycard/check-card-state)}))))
(fx/defn factory-reset (rf/defn factory-reset
{:events [::factory-reset]} {:events [::factory-reset]}
[cofx] [cofx]
(common/show-connection-sheet (common/show-connection-sheet
@@ -310,14 +310,14 @@
:on-card-read :keycard/check-card-state :on-card-read :keycard/check-card-state
:handler (common/factory-reset :keycard/check-card-state)})) :handler (common/factory-reset :keycard/check-card-state)}))
(fx/defn factory-reset-cancel (rf/defn factory-reset-cancel
{:events [::factory-reset-cancel]} {:events [::factory-reset-cancel]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
{:db (update db :keycard dissoc :factory-reset-card?)}) {:db (update db :keycard dissoc :factory-reset-card?)})
(fx/defn cancel-pressed (rf/defn cancel-pressed
{:events [::cancel-pressed]} {:events [::cancel-pressed]}
[cofx] [cofx]
(fx/merge cofx (rf/merge cofx
(navigation/navigate-back) (navigation/navigate-back)
(common/cancel-sheet-confirm))) (common/cancel-sheet-confirm)))
+42 -42
View File
@@ -3,7 +3,7 @@
[status-im.utils.datetime :as utils.datetime] [status-im.utils.datetime :as utils.datetime]
[status-im.multiaccounts.create.core :as multiaccounts.create] [status-im.multiaccounts.create.core :as multiaccounts.create]
[status-im.multiaccounts.model :as multiaccounts.model] [status-im.multiaccounts.model :as multiaccounts.model]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[clojure.string :as string] [clojure.string :as string]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
@@ -21,10 +21,10 @@
[status-im.utils.keychain.core :as keychain] [status-im.utils.keychain.core :as keychain]
[status-im.utils.platform :as platform])) [status-im.utils.platform :as platform]))
(fx/defn pair* [_ password] (rf/defn pair* [_ password]
{:keycard/pair {:password password}}) {:keycard/pair {:password password}})
(fx/defn pair (rf/defn pair
{:events [:keycard/pair]} {:events [:keycard/pair]}
[cofx] [cofx]
(let [{:keys [password]} (get-in cofx [:db :keycard :secrets])] (let [{:keys [password]} (get-in cofx [:db :keycard :secrets])]
@@ -33,41 +33,41 @@
{:on-card-connected :keycard/pair {:on-card-connected :keycard/pair
:handler (pair* password)}))) :handler (pair* password)})))
(fx/defn pair-code-next-button-pressed (rf/defn pair-code-next-button-pressed
{:events [:keycard.onboarding.pair.ui/input-submitted {:events [:keycard.onboarding.pair.ui/input-submitted
:keycard.ui/pair-code-next-button-pressed :keycard.ui/pair-code-next-button-pressed
:keycard.onboarding.pair.ui/next-pressed]} :keycard.onboarding.pair.ui/next-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [pairing (get-in db [:keycard :secrets :pairing]) (let [pairing (get-in db [:keycard :secrets :pairing])
paired-on (get-in db [:keycard :secrets :paired-on] (utils.datetime/timestamp))] paired-on (get-in db [:keycard :secrets :paired-on] (utils.datetime/timestamp))]
(fx/merge cofx (rf/merge cofx
(if pairing (if pairing
{:db (-> db {:db (-> db
(assoc-in [:keycard :setup-step] :import-multiaccount) (assoc-in [:keycard :setup-step] :import-multiaccount)
(assoc-in [:keycard :secrets :paired-on] paired-on))} (assoc-in [:keycard :secrets :paired-on] paired-on))}
(pair))))) (pair)))))
(fx/defn load-pair-screen (rf/defn load-pair-screen
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(log/debug "[keycard] load-pair-screen") (log/debug "[keycard] load-pair-screen")
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :setup-step] :pair)) (assoc-in [:keycard :setup-step] :pair))
:dispatch [:bottom-sheet/hide]} :dispatch [:bottom-sheet/hide]}
(common/listen-to-hardware-back-button) (common/listen-to-hardware-back-button)
(navigation/navigate-to-cofx :keycard-recovery-pair nil))) (navigation/navigate-to-cofx :keycard-recovery-pair nil)))
(fx/defn keycard-storage-selected-for-recovery (rf/defn keycard-storage-selected-for-recovery
{:events [:recovery.ui/keycard-storage-selected]} {:events [:recovery.ui/keycard-storage-selected]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :flow] :recovery)} {:db (assoc-in db [:keycard :flow] :recovery)}
(navigation/navigate-to-cofx :keycard-recovery-enter-mnemonic nil))) (navigation/navigate-to-cofx :keycard-recovery-enter-mnemonic nil)))
(fx/defn start-import-flow (rf/defn start-import-flow
{:events [::recover-with-keycard-pressed]} {:events [::recover-with-keycard-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db {:db
(-> db (-> db
(assoc-in [:keycard :flow] :import) (assoc-in [:keycard :flow] :import)
@@ -76,31 +76,31 @@
(bottom-sheet/hide-bottom-sheet) (bottom-sheet/hide-bottom-sheet)
(navigation/navigate-to-cofx :keycard-recovery-intro nil))) (navigation/navigate-to-cofx :keycard-recovery-intro nil)))
(fx/defn access-key-pressed (rf/defn access-key-pressed
{:events [:multiaccounts.recover.ui/recover-multiaccount-button-pressed]} {:events [:multiaccounts.recover.ui/recover-multiaccount-button-pressed]}
[_] [_]
{:dispatch [:bottom-sheet/show-sheet :recover-sheet]}) {:dispatch [:bottom-sheet/show-sheet :recover-sheet]})
(fx/defn recovery-keycard-selected (rf/defn recovery-keycard-selected
{:events [:recovery.ui/keycard-option-pressed]} {:events [:recovery.ui/keycard-option-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :flow] :recovery) {:db (assoc-in db [:keycard :flow] :recovery)
:keycard/check-nfc-enabled nil} :keycard/check-nfc-enabled nil}
(common/listen-to-hardware-back-button) (common/listen-to-hardware-back-button)
(navigation/navigate-to-cofx :keycard-onboarding-intro nil))) (navigation/navigate-to-cofx :keycard-onboarding-intro nil)))
(fx/defn cancel-pressed (rf/defn cancel-pressed
{:events [::cancel-pressed]} {:events [::cancel-pressed]}
[cofx] [cofx]
(fx/merge cofx (rf/merge cofx
(common/cancel-sheet-confirm) (common/cancel-sheet-confirm)
(navigation/navigate-back))) (navigation/navigate-back)))
(fx/defn begin-setup-pressed (rf/defn begin-setup-pressed
{:events [:keycard.recovery.intro.ui/begin-recovery-pressed]} {:events [:keycard.recovery.intro.ui/begin-recovery-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(update :keycard (update :keycard
@@ -115,21 +115,21 @@
:sheet-options {:on-cancel [::cancel-pressed]} :sheet-options {:on-cancel [::cancel-pressed]}
:handler (common/get-application-info :keycard/check-card-state)}))) :handler (common/get-application-info :keycard/check-card-state)})))
(fx/defn recovery-success-finish-pressed (rf/defn recovery-success-finish-pressed
{:events [:keycard.recovery.success/finish-pressed]} {:events [:keycard.recovery.success/finish-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (update db :keycard dissoc {:db (update db :keycard dissoc
:multiaccount-wallet-address :multiaccount-wallet-address
:multiaccount-whisper-public-key)} :multiaccount-whisper-public-key)}
(navigation/navigate-to-cofx (if platform/android? (navigation/navigate-to-cofx (if platform/android?
:notifications-settings :welcome) nil))) :notifications-settings :welcome) nil)))
(fx/defn intro-wizard (rf/defn intro-wizard
{:events [:multiaccounts.create.ui/intro-wizard]} {:events [:multiaccounts.create.ui/intro-wizard]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [accs (get db :multiaccounts/multiaccounts)] (let [accs (get db :multiaccounts/multiaccounts)]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(update :keycard dissoc :flow) (update :keycard dissoc :flow)
(dissoc :restored-account?))} (dissoc :restored-account?))}
@@ -138,15 +138,15 @@
(navigation/navigate-to-cofx :get-your-keys nil) (navigation/navigate-to-cofx :get-your-keys nil)
(navigation/set-stack-root :onboarding [:get-your-keys]))))) (navigation/set-stack-root :onboarding [:get-your-keys])))))
(fx/defn recovery-no-key (rf/defn recovery-no-key
{:events [:keycard.recovery.no-key.ui/generate-key-pressed]} {:events [:keycard.recovery.no-key.ui/generate-key-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :flow] :create) {:db (assoc-in db [:keycard :flow] :create)
:keycard/check-nfc-enabled nil} :keycard/check-nfc-enabled nil}
(intro-wizard))) (intro-wizard)))
(fx/defn create-keycard-multiaccount (rf/defn create-keycard-multiaccount
{:events [::create-keycard-multiaccount] {:events [::create-keycard-multiaccount]
:interceptors [(re-frame/inject-cofx :random-guid-generator) :interceptors [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]} (re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]}
@@ -180,7 +180,7 @@
{:keycard/generate-name-and-photo {:keycard/generate-name-and-photo
{:public-key whisper-public-key {:public-key whisper-public-key
:on-success ::on-name-and-photo-generated}} :on-success ::on-name-and-photo-generated}}
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :setup-step] nil) (assoc-in [:keycard :setup-step] nil)
(dissoc :intro-wizard))} (dissoc :intro-wizard))}
@@ -207,9 +207,9 @@
encryption-public-key encryption-public-key
{}))))) {})))))
(fx/defn return-to-keycard-login (rf/defn return-to-keycard-login
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(update-in [:keycard :pin] assoc :enter-step :login (update-in [:keycard :pin] assoc :enter-step :login
:status nil :status nil
@@ -218,9 +218,9 @@
(navigation/set-stack-root :multiaccounts-stack [:multiaccounts (navigation/set-stack-root :multiaccounts-stack [:multiaccounts
:keycard-login-pin]))) :keycard-login-pin])))
(fx/defn on-backup-success (rf/defn on-backup-success
[{:keys [db] :as cofx} backup-type] [{:keys [db] :as cofx} backup-type]
(fx/merge cofx (rf/merge cofx
{:utils/show-popup {:title (i18n/label (if (= backup-type :recovery-card) {:utils/show-popup {:title (i18n/label (if (= backup-type :recovery-card)
:t/keycard-access-reset :t/keycard-backup-success-title)) :t/keycard-access-reset :t/keycard-backup-success-title))
:content (i18n/label (if (= backup-type :recovery-card) :content (i18n/label (if (= backup-type :recovery-card)
@@ -248,7 +248,7 @@
(status/login-with-keycard login-params) (status/login-with-keycard login-params)
(throw (js/Error. "Please shake the phone to report this error and restart the app. Migration failed unexpectedly."))))))) (throw (js/Error. "Please shake the phone to report this error and restart the app. Migration failed unexpectedly.")))))))
(fx/defn migrate-account (rf/defn migrate-account
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [pairing (get-in db [:keycard :secrets :pairing]) (let [pairing (get-in db [:keycard :secrets :pairing])
paired-on (get-in db [:keycard :secrets :paired-on]) paired-on (get-in db [:keycard :secrets :paired-on])
@@ -275,7 +275,7 @@
(dissoc :recovered-account?)) (dissoc :recovered-account?))
::finish-migration [account settings password encryption-pass login-params]})) ::finish-migration [account settings password encryption-pass login-params]}))
(fx/defn delete-multiaccount (rf/defn delete-multiaccount
[{:keys [db]}] [{:keys [db]}]
(let [key-uid (get-in db [:multiaccounts/login :key-uid])] (let [key-uid (get-in db [:multiaccounts/login :key-uid])]
{:keycard/delete-multiaccount-before-migration {:keycard/delete-multiaccount-before-migration
@@ -283,12 +283,12 @@
:on-error #(re-frame/dispatch [::delete-multiaccount-error %]) :on-error #(re-frame/dispatch [::delete-multiaccount-error %])
:on-success #(re-frame/dispatch [::create-keycard-multiaccount])}})) :on-success #(re-frame/dispatch [::create-keycard-multiaccount])}}))
(fx/defn handle-delete-multiaccount-error (rf/defn handle-delete-multiaccount-error
{:events [::delete-multiaccount-error]} {:events [::delete-multiaccount-error]}
[cofx _] [cofx _]
(popover/show-popover cofx {:view :transfer-multiaccount-unknown-error})) (popover/show-popover cofx {:view :transfer-multiaccount-unknown-error}))
(fx/defn on-generate-and-load-key-success (rf/defn on-generate-and-load-key-success
{:events [:keycard.callback/on-generate-and-load-key-success] {:events [:keycard.callback/on-generate-and-load-key-success]
:interceptors [(re-frame/inject-cofx :random-guid-generator) :interceptors [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]} (re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]}
@@ -296,7 +296,7 @@
(let [account-data (js->clj data :keywordize-keys true) (let [account-data (js->clj data :keywordize-keys true)
backup? (get-in db [:keycard :creating-backup?]) backup? (get-in db [:keycard :creating-backup?])
migration? (get-in db [:keycard :converting-account?])] migration? (get-in db [:keycard :converting-account?])]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :multiaccount] (assoc-in [:keycard :multiaccount]
(-> account-data (-> account-data
@@ -327,17 +327,17 @@
:else (create-keycard-multiaccount))))) :else (create-keycard-multiaccount)))))
(fx/defn on-generate-and-load-key-error (rf/defn on-generate-and-load-key-error
{:events [:keycard.callback/on-generate-and-load-key-error]} {:events [:keycard.callback/on-generate-and-load-key-error]}
[{:keys [db] :as cofx} {:keys [error code]}] [{:keys [db] :as cofx} {:keys [error code]}]
(log/debug "[keycard] generate and load key error: " error) (log/debug "[keycard] generate and load key error: " error)
(when-not (common/tag-lost? error) (when-not (common/tag-lost? error)
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :setup-error] error)} {:db (assoc-in db [:keycard :setup-error] error)}
(common/set-on-card-connected :keycard/load-loading-keys-screen) (common/set-on-card-connected :keycard/load-loading-keys-screen)
(common/process-error code error)))) (common/process-error code error))))
(fx/defn import-multiaccount (rf/defn import-multiaccount
{:events [:keycard/import-multiaccount]} {:events [:keycard/import-multiaccount]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [pairing]} (get-in db [:keycard :secrets]) (let [{:keys [pairing]} (get-in db [:keycard :secrets])
@@ -345,7 +345,7 @@
key-uid (get-in db [:keycard :application-info :key-uid]) key-uid (get-in db [:keycard :application-info :key-uid])
pairing' (or pairing (common/get-pairing db key-uid)) pairing' (or pairing (common/get-pairing db key-uid))
pin (common/vector->string (get-in db [:keycard :pin :import-multiaccount]))] pin (common/vector->string (get-in db [:keycard :pin :import-multiaccount]))]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :multiaccount :instance-uid] instance-uid) (assoc-in [:keycard :multiaccount :instance-uid] instance-uid)
(assoc-in [:keycard :pin :status] :verifying) (assoc-in [:keycard :pin :status] :verifying)
@@ -355,7 +355,7 @@
{:pin pin {:pin pin
:on-success :keycard.callback/on-generate-and-load-key-success}}))) :on-success :keycard.callback/on-generate-and-load-key-success}})))
(fx/defn load-recovering-key-screen (rf/defn load-recovering-key-screen
{:events [:keycard/load-recovering-key-screen]} {:events [:keycard/load-recovering-key-screen]}
[cofx] [cofx]
(common/show-connection-sheet (common/show-connection-sheet
@@ -363,12 +363,12 @@
{:on-card-connected :keycard/load-recovering-key-screen {:on-card-connected :keycard/load-recovering-key-screen
:handler (common/dispatch-event :keycard/import-multiaccount)})) :handler (common/dispatch-event :keycard/import-multiaccount)}))
(fx/defn on-name-and-photo-generated (rf/defn on-name-and-photo-generated
{:events [::on-name-and-photo-generated] {:events [::on-name-and-photo-generated]
:interceptors [(re-frame/inject-cofx :random-guid-generator) :interceptors [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]} (re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]}
[{:keys [db] :as cofx} whisper-name identicon] [{:keys [db] :as cofx} whisper-name identicon]
(fx/merge (rf/merge
cofx cofx
{:db (update-in db [:keycard :multiaccount] {:db (update-in db [:keycard :multiaccount]
(fn [multiacc] (fn [multiacc]
+20 -20
View File
@@ -2,14 +2,14 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.money :as money] [status-im.utils.money :as money]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.keycard.common :as common] [status-im.keycard.common :as common]
[clojure.string :as string])) [clojure.string :as string]))
(fx/defn sign (rf/defn sign
{:events [:keycard/sign]} {:events [:keycard/sign]}
[{:keys [db] :as cofx} hash on-success] [{:keys [db] :as cofx} hash on-success]
(let [card-connected? (get-in db [:keycard :card-connected?]) (let [card-connected? (get-in db [:keycard :card-connected?])
@@ -33,7 +33,7 @@
(common/show-wrong-keycard-alert cofx) (common/show-wrong-keycard-alert cofx)
(not card-connected?) (not card-connected?)
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:signing/sign :keycard-step] :signing)} {:db (assoc-in db [:signing/sign :keycard-step] :signing)}
(common/set-on-card-connected :keycard/sign)) (common/set-on-card-connected :keycard/sign))
@@ -54,7 +54,7 @@
(string/replace-first #"01$", "1c") (string/replace-first #"01$", "1c")
ethereum/normalized-hex)) ethereum/normalized-hex))
(fx/defn sign-message (rf/defn sign-message
{:events [:keycard/sign-message]} {:events [:keycard/sign-message]}
[cofx params result] [cofx params result]
(let [{:keys [result error]} (types/json->clj result) (let [{:keys [result error]} (types/json->clj result)
@@ -63,10 +63,10 @@
hash (ethereum/naked-address result)] hash (ethereum/naked-address result)]
(sign cofx hash on-success))) (sign cofx hash on-success)))
(fx/defn on-sign-message-success (rf/defn on-sign-message-success
{:events [:keycard/on-sign-message-success]} {:events [:keycard/on-sign-message-success]}
[{:keys [db] :as cofx} {:keys [tx-hash message-id chat-id value contract]} signature] [{:keys [db] :as cofx} {:keys [tx-hash message-id chat-id value contract]} signature]
(fx/merge (rf/merge
cofx cofx
{:dispatch {:dispatch
(if message-id (if message-id
@@ -80,7 +80,7 @@
(common/get-application-info nil) (common/get-application-info nil)
(common/hide-connection-sheet))) (common/hide-connection-sheet)))
(fx/defn sign-typed-data (rf/defn sign-typed-data
{:events [:keycard/sign-typed-data]} {:events [:keycard/sign-typed-data]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [card-connected? (get-in db [:keycard :card-connected?]) (let [card-connected? (get-in db [:keycard :card-connected?])
@@ -90,11 +90,11 @@
(assoc-in [:keycard :card-read-in-progress?] true) (assoc-in [:keycard :card-read-in-progress?] true)
(assoc-in [:signing/sign :keycard-step] :signing)) (assoc-in [:signing/sign :keycard-step] :signing))
:keycard/sign-typed-data {:hash (ethereum/naked-address hash)}} :keycard/sign-typed-data {:hash (ethereum/naked-address hash)}}
(fx/merge cofx (rf/merge cofx
(common/set-on-card-connected :keycard/sign-typed-data) (common/set-on-card-connected :keycard/sign-typed-data)
{:db (assoc-in db [:signing/sign :keycard-step] :signing)})))) {:db (assoc-in db [:signing/sign :keycard-step] :signing)}))))
(fx/defn fetch-currency-token-on-success (rf/defn fetch-currency-token-on-success
{:events [:keycard/fetch-currency-token-on-success]} {:events [:keycard/fetch-currency-token-on-success]}
[{:keys [db]} {:keys [decimals symbol]}] [{:keys [db]} {:keys [decimals symbol]}]
{:db (-> db {:db (-> db
@@ -103,7 +103,7 @@
#(assoc % :formatted-amount (.dividedBy ^js (money/bignumber (:amount %)) #(assoc % :formatted-amount (.dividedBy ^js (money/bignumber (:amount %))
(money/bignumber (money/from-decimal decimals))))))}) (money/bignumber (money/from-decimal decimals))))))})
(fx/defn store-hash-and-sign-typed (rf/defn store-hash-and-sign-typed
{:events [:keycard/store-hash-and-sign-typed]} {:events [:keycard/store-hash-and-sign-typed]}
[{:keys [db] :as cofx} result] [{:keys [db] :as cofx} result]
(let [{:keys [result]} (types/json->clj result) (let [{:keys [result]} (types/json->clj result)
@@ -113,11 +113,11 @@
{::json-rpc/call [{:method "wallet_discoverToken" {::json-rpc/call [{:method "wallet_discoverToken"
:params [(ethereum/chain-id db) currency-contract] :params [(ethereum/chain-id db) currency-contract]
:on-success #(re-frame/dispatch [:keycard/fetch-currency-token-on-success %])}]}) :on-success #(re-frame/dispatch [:keycard/fetch-currency-token-on-success %])}]})
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :hash] result)} {:db (assoc-in db [:keycard :hash] result)}
sign-typed-data))) sign-typed-data)))
(fx/defn prepare-to-sign (rf/defn prepare-to-sign
{:events [:keycard/prepare-to-sign]} {:events [:keycard/prepare-to-sign]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(common/show-connection-sheet (common/show-connection-sheet
@@ -125,16 +125,16 @@
{:on-card-connected :keycard/prepare-to-sign {:on-card-connected :keycard/prepare-to-sign
:handler (common/get-application-info :keycard/sign)})) :handler (common/get-application-info :keycard/sign)}))
(fx/defn sign-message-completed (rf/defn sign-message-completed
[_ signature] [_ signature]
{:dispatch {:dispatch
[:signing/sign-message-completed signature]}) [:signing/sign-message-completed signature]})
(fx/defn send-transaction-with-signature (rf/defn send-transaction-with-signature
[_ data] [_ data]
{:send-transaction-with-signature data}) {:send-transaction-with-signature data})
(fx/defn on-sign-success (rf/defn on-sign-success
{:events [:keycard.callback/on-sign-success]} {:events [:keycard.callback/on-sign-success]}
[{:keys [db] :as cofx} signature] [{:keys [db] :as cofx} signature]
(log/debug "[keycard] sign success: " signature) (log/debug "[keycard] sign success: " signature)
@@ -142,13 +142,13 @@
transaction (get-in db [:keycard :transaction]) transaction (get-in db [:keycard :transaction])
tx-obj (select-keys transaction [:from :to :value :gas :gasPrice :command? :chat-id :message-id]) tx-obj (select-keys transaction [:from :to :value :gas :gasPrice :command? :chat-id :message-id])
command? (:command? transaction)] command? (:command? transaction)]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :hash] nil) (assoc-in [:keycard :hash] nil)
(assoc-in [:keycard :transaction] nil))} (assoc-in [:keycard :transaction] nil))}
(when-not command? (when-not command?
(fn [{:keys [db] :as cofx}] (fn [{:keys [db] :as cofx}]
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :pin :sign] []) (assoc-in [:keycard :pin :sign] [])
@@ -163,7 +163,7 @@
:on-completed #(re-frame/dispatch [:signing/transaction-completed % tx-obj])}) :on-completed #(re-frame/dispatch [:signing/transaction-completed % tx-obj])})
(sign-message-completed signature-json))))) (sign-message-completed signature-json)))))
(fx/defn on-sign-error (rf/defn on-sign-error
{:events [:keycard.callback/on-sign-error]} {:events [:keycard.callback/on-sign-error]}
[{:keys [db] :as cofx} error] [{:keys [db] :as cofx} error]
(log/debug "[keycard] sign error: " error) (log/debug "[keycard] sign error: " error)
@@ -171,7 +171,7 @@
pin-retries (common/pin-retries (:error error))] pin-retries (common/pin-retries (:error error))]
(when-not tag-was-lost? (when-not tag-was-lost?
(if (not (nil? pin-retries)) (if (not (nil? pin-retries))
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :application-info :pin-retry-counter] pin-retries) (assoc-in [:keycard :application-info :pin-retry-counter] pin-retries)
(update-in [:keycard :pin] assoc (update-in [:keycard :pin] assoc
@@ -182,6 +182,6 @@
(common/hide-connection-sheet) (common/hide-connection-sheet)
(when (zero? pin-retries) (common/frozen-keycard-popup))) (when (zero? pin-retries) (common/frozen-keycard-popup)))
(fx/merge cofx (rf/merge cofx
(common/hide-connection-sheet) (common/hide-connection-sheet)
(common/show-wrong-keycard-alert)))))) (common/show-wrong-keycard-alert))))))
+22 -22
View File
@@ -3,12 +3,12 @@
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.keycard.common :as common] [status-im.keycard.common :as common]
[status-im.multiaccounts.key-storage.core :as key-storage])) [status-im.multiaccounts.key-storage.core :as key-storage]))
(fx/defn unpair-card-pressed (rf/defn unpair-card-pressed
{:events [:keycard-settings.ui/unpair-card-pressed]} {:events [:keycard-settings.ui/unpair-card-pressed]}
[_] [_]
{:ui/show-confirmation {:title (i18n/label :t/unpair-card) {:ui/show-confirmation {:title (i18n/label :t/unpair-card)
@@ -18,10 +18,10 @@
:on-accept #(re-frame/dispatch [:keycard-settings.ui/unpair-card-confirmed]) :on-accept #(re-frame/dispatch [:keycard-settings.ui/unpair-card-confirmed])
:on-cancel #()}}) :on-cancel #()}})
(fx/defn unpair-card-confirmed (rf/defn unpair-card-confirmed
{:events [:keycard-settings.ui/unpair-card-confirmed]} {:events [:keycard-settings.ui/unpair-card-confirmed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :pin] {:enter-step :current {:db (assoc-in db [:keycard :pin] {:enter-step :current
:current [] :current []
:puk [] :puk []
@@ -30,13 +30,13 @@
:on-verified :keycard/unpair})} :on-verified :keycard/unpair})}
(common/navigate-to-enter-pin-screen))) (common/navigate-to-enter-pin-screen)))
(fx/defn unpair (rf/defn unpair
{:events [:keycard/unpair]} {:events [:keycard/unpair]}
[{:keys [db]}] [{:keys [db]}]
(let [pin (common/vector->string (get-in db [:keycard :pin :current]))] (let [pin (common/vector->string (get-in db [:keycard :pin :current]))]
{:keycard/unpair {:pin pin}})) {:keycard/unpair {:pin pin}}))
(fx/defn unpair-and-delete (rf/defn unpair-and-delete
{:events [:keycard/unpair-and-delete]} {:events [:keycard/unpair-and-delete]}
[cofx] [cofx]
(common/show-connection-sheet (common/show-connection-sheet
@@ -48,9 +48,9 @@
{:keycard/unpair-and-delete {:keycard/unpair-and-delete
{:pin pin}}))})) {:pin pin}}))}))
(fx/defn remove-pairing-from-multiaccount (rf/defn remove-pairing-from-multiaccount
[cofx {:keys [remove-instance-uid?]}] [cofx {:keys [remove-instance-uid?]}]
(fx/merge cofx (rf/merge cofx
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:keycard-pairing nil {}) :keycard-pairing nil {})
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
@@ -59,12 +59,12 @@
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:keycard-instance-uid nil {})))) :keycard-instance-uid nil {}))))
(fx/defn on-unpair-success (rf/defn on-unpair-success
{:events [:keycard.callback/on-unpair-success]} {:events [:keycard.callback/on-unpair-success]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [instance-uid (get-in db [:keycard :application-info :instance-uid]) (let [instance-uid (get-in db [:keycard :application-info :instance-uid])
pairings (get-in db [:keycard :pairings])] pairings (get-in db [:keycard :pairings])]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :secrets] nil) (assoc-in [:keycard :secrets] nil)
(update-in [:keycard :pairings] dissoc (keyword instance-uid)) (update-in [:keycard :pairings] dissoc (keyword instance-uid))
@@ -78,11 +78,11 @@
(remove-pairing-from-multiaccount nil) (remove-pairing-from-multiaccount nil)
(navigation/navigate-to-cofx :keycard-settings nil)))) (navigation/navigate-to-cofx :keycard-settings nil))))
(fx/defn on-unpair-error (rf/defn on-unpair-error
{:events [:keycard.callback/on-unpair-error]} {:events [:keycard.callback/on-unpair-error]}
[{:keys [db] :as cofx} error] [{:keys [db] :as cofx} error]
(log/debug "[keycard] unpair error" error) (log/debug "[keycard] unpair error" error)
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :pin] {:status nil {:db (assoc-in db [:keycard :pin] {:status nil
:error-label nil :error-label nil
:on-verified nil}) :on-verified nil})
@@ -92,7 +92,7 @@
(common/clear-on-card-connected) (common/clear-on-card-connected)
(navigation/navigate-to-cofx :keycard-settings nil))) (navigation/navigate-to-cofx :keycard-settings nil)))
(fx/defn remove-key-with-unpair (rf/defn remove-key-with-unpair
{:events [:keycard/remove-key-with-unpair]} {:events [:keycard/remove-key-with-unpair]}
[cofx] [cofx]
(common/show-connection-sheet (common/show-connection-sheet
@@ -108,7 +108,7 @@
(let [key-uid (get-in db [:multiaccount :key-uid]) (let [key-uid (get-in db [:multiaccount :key-uid])
instance-uid (get-in db [:keycard :application-info :instance-uid]) instance-uid (get-in db [:keycard :application-info :instance-uid])
pairings (get-in db [:keycard :pairings])] pairings (get-in db [:keycard :pairings])]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(update :multiaccounts/multiaccounts dissoc key-uid) (update :multiaccounts/multiaccounts dissoc key-uid)
(assoc-in [:keycard :secrets] nil) (assoc-in [:keycard :secrets] nil)
@@ -130,36 +130,36 @@
(common/clear-on-card-connected) (common/clear-on-card-connected)
(common/hide-connection-sheet)))) (common/hide-connection-sheet))))
(fx/defn on-remove-key-success (rf/defn on-remove-key-success
{:events [:keycard.callback/on-remove-key-success]} {:events [:keycard.callback/on-remove-key-success]}
[cofx] [cofx]
(handle-account-removal cofx true)) (handle-account-removal cofx true))
(fx/defn on-remove-key-error (rf/defn on-remove-key-error
{:events [:keycard.callback/on-remove-key-error]} {:events [:keycard.callback/on-remove-key-error]}
[{:keys [db] :as cofx} error] [{:keys [db] :as cofx} error]
(log/debug "[keycard] remove key error" error) (log/debug "[keycard] remove key error" error)
(let [tag-was-lost? (common/tag-lost? (:error error))] (let [tag-was-lost? (common/tag-lost? (:error error))]
(fx/merge cofx (rf/merge cofx
(if tag-was-lost? (if tag-was-lost?
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :pin :status] nil)} {:db (assoc-in db [:keycard :pin :status] nil)}
(common/set-on-card-connected :keycard/remove-key-with-unpair)) (common/set-on-card-connected :keycard/remove-key-with-unpair))
(common/show-wrong-keycard-alert))))) (common/show-wrong-keycard-alert)))))
(fx/defn on-unpair-and-delete-success (rf/defn on-unpair-and-delete-success
{:events [:keycard.callback/on-unpair-and-delete-success]} {:events [:keycard.callback/on-unpair-and-delete-success]}
[cofx] [cofx]
(handle-account-removal cofx false)) (handle-account-removal cofx false))
(fx/defn on-unpair-and-delete-error (rf/defn on-unpair-and-delete-error
{:events [:keycard.callback/on-unpair-and-delete-error]} {:events [:keycard.callback/on-unpair-and-delete-error]}
[{:keys [db] :as cofx} error] [{:keys [db] :as cofx} error]
(log/debug "[keycard] unpair and delete error" error) (log/debug "[keycard] unpair and delete error" error)
(let [tag-was-lost? (common/tag-lost? (:error error))] (let [tag-was-lost? (common/tag-lost? (:error error))]
(fx/merge cofx (rf/merge cofx
(if tag-was-lost? (if tag-was-lost?
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:keycard :pin :status] nil)} {:db (assoc-in db [:keycard :pin :status] nil)}
(common/set-on-card-connected :keycard/unpair-and-delete)) (common/set-on-card-connected :keycard/unpair-and-delete))
(common/show-wrong-keycard-alert))))) (common/show-wrong-keycard-alert)))))
+7 -7
View File
@@ -1,6 +1,6 @@
(ns status-im.keycard.wallet (ns status-im.keycard.wallet
(:require [status-im.ethereum.core :as ethereum] (:require [status-im.ethereum.core :as ethereum]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.keycard.common :as common] [status-im.keycard.common :as common]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.ethereum.eip55 :as eip55] [status-im.ethereum.eip55 :as eip55]
@@ -8,10 +8,10 @@
[status-im.ui.screens.wallet.add-new.views :as add-new.views] [status-im.ui.screens.wallet.add-new.views :as add-new.views]
[status-im.bottom-sheet.core :as bottom-sheet])) [status-im.bottom-sheet.core :as bottom-sheet]))
(fx/defn show-pin-sheet (rf/defn show-pin-sheet
{:events [:keycard/new-account-pin-sheet]} {:events [:keycard/new-account-pin-sheet]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :pin :enter-step] :export-key) (assoc-in [:keycard :pin :enter-step] :export-key)
@@ -19,19 +19,19 @@
:dismiss-keyboard nil} :dismiss-keyboard nil}
(bottom-sheet/show-bottom-sheet {:view {:content add-new.views/pin}}))) (bottom-sheet/show-bottom-sheet {:view {:content add-new.views/pin}})))
(fx/defn verify-pin-with-delay (rf/defn verify-pin-with-delay
[cofx] [cofx]
{:utils/dispatch-later {:utils/dispatch-later
;; We need to give previous sheet some time to be fully hidden ;; We need to give previous sheet some time to be fully hidden
[{:ms 200 [{:ms 200
:dispatch [:wallet.accounts/verify-pin]}]}) :dispatch [:wallet.accounts/verify-pin]}]})
(fx/defn hide-pin-sheet (rf/defn hide-pin-sheet
{:events [:keycard/new-account-pin-sheet-hide]} {:events [:keycard/new-account-pin-sheet-hide]}
[cofx] [cofx]
(bottom-sheet/hide-bottom-sheet cofx)) (bottom-sheet/hide-bottom-sheet cofx))
(fx/defn generate-new-keycard-account (rf/defn generate-new-keycard-account
{:events [:wallet.accounts/generate-new-keycard-account]} {:events [:wallet.accounts/generate-new-keycard-account]}
[{:keys [db]}] [{:keys [db]}]
(let [path-num (inc (get-in db [:multiaccount :latest-derived-path])) (let [path-num (inc (get-in db [:multiaccount :latest-derived-path]))
@@ -52,7 +52,7 @@
:keycard/export-key {:pin pin :path path}})) :keycard/export-key {:pin pin :path path}}))
(fx/defn verify-pin (rf/defn verify-pin
{:events [:wallet.accounts/verify-pin]} {:events [:wallet.accounts/verify-pin]}
[cofx] [cofx]
(common/verify-pin (common/verify-pin
+4 -4
View File
@@ -3,21 +3,21 @@
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.node.core :as node] [status-im.node.core :as node]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.utils.fx :as fx])) [utils.re-frame :as rf]))
(fx/defn save-log-level (rf/defn save-log-level
{:events [:log-level.ui/change-log-level-confirmed]} {:events [:log-level.ui/change-log-level-confirmed]}
[{:keys [db now] :as cofx} log-level] [{:keys [db now] :as cofx} log-level]
(let [old-log-level (get-in db [:multiaccount :log-level])] (let [old-log-level (get-in db [:multiaccount :log-level])]
(when (not= old-log-level log-level) (when (not= old-log-level log-level)
(fx/merge cofx (rf/merge cofx
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:log-level log-level :log-level log-level
{}) {})
(node/prepare-new-config (node/prepare-new-config
{:on-success #(re-frame/dispatch [:logout])}))))) {:on-success #(re-frame/dispatch [:logout])})))))
(fx/defn show-change-log-level-confirmation (rf/defn show-change-log-level-confirmation
{:events [:log-level.ui/log-level-selected]} {:events [:log-level.ui/log-level-selected]}
[_ {:keys [name value]}] [_ {:keys [name value]}]
{:ui/show-confirmation {:ui/show-confirmation
+35 -35
View File
@@ -8,7 +8,7 @@
[status-im.node.core :as node] [status-im.node.core :as node]
[status-im.utils.mobile-sync :as mobile-network-utils] [status-im.utils.mobile-sync :as mobile-network-utils]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
;; How do mailserver work ? ;; How do mailserver work ?
@@ -48,7 +48,7 @@
current-fleet current-fleet
vals))))) vals)))))
(fx/defn disconnect-from-mailserver (rf/defn disconnect-from-mailserver
{:events [::disconnect-from-mailserver]} {:events [::disconnect-from-mailserver]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
{:db (-> db {:db (-> db
@@ -68,7 +68,7 @@
::cancel-connection-popup ::cancel-connection-popup
cancel-connection-popup!) cancel-connection-popup!)
(fx/defn show-connection-error! [cofx current-fleet preferred-mailserver] (rf/defn show-connection-error! [cofx current-fleet preferred-mailserver]
(reset! showing-connection-error-popup? true) (reset! showing-connection-error-popup? true)
{:ui/show-confirmation {:ui/show-confirmation
{:title (i18n/label :t/mailserver-error-title) {:title (i18n/label :t/mailserver-error-title)
@@ -88,13 +88,13 @@
preferred-mailserver])) preferred-mailserver]))
:style "default"}]}}) :style "default"}]}})
(fx/defn handle-successful-request (rf/defn handle-successful-request
{:events [::request-success]} {:events [::request-success]}
[{:keys [db] :as cofx} response-js] [{:keys [db] :as cofx} response-js]
{:db (dissoc db :mailserver/current-request) {:db (dissoc db :mailserver/current-request)
:dispatch [:sanitize-messages-and-process-response response-js]}) :dispatch [:sanitize-messages-and-process-response response-js]})
(fx/defn handle-mailserver-not-working [{:keys [db] :as cofx}] (rf/defn handle-mailserver-not-working [{:keys [db] :as cofx}]
(let [current-fleet (node/current-fleet-key db) (let [current-fleet (node/current-fleet-key db)
error-dismissed? (connection-error-dismissed db) error-dismissed? (connection-error-dismissed db)
pinned-mailserver (get-in db [:multiaccount :pinned-mailservers current-fleet])] pinned-mailserver (get-in db [:multiaccount :pinned-mailservers current-fleet])]
@@ -103,12 +103,12 @@
(not @showing-connection-error-popup?)) (not @showing-connection-error-popup?))
(show-connection-error! cofx current-fleet pinned-mailserver)))) (show-connection-error! cofx current-fleet pinned-mailserver))))
(fx/defn handle-request-error (rf/defn handle-request-error
{:events [::request-error]} {:events [::request-error]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
{:db (dissoc db :mailserver/current-request)}) {:db (dissoc db :mailserver/current-request)})
(fx/defn process-next-messages-request (rf/defn process-next-messages-request
{:events [::request-messages]} {:events [::request-messages]}
[{:keys [db now] :as cofx}] [{:keys [db now] :as cofx}]
(when (and (when (and
@@ -127,34 +127,34 @@
(log/error "failed retrieve historical messages" %) (log/error "failed retrieve historical messages" %)
(re-frame/dispatch [::request-error]))}]})) (re-frame/dispatch [::request-error]))}]}))
(fx/defn handle-mailserver-changed (rf/defn handle-mailserver-changed
[{:keys [db] :as cofx} ms] [{:keys [db] :as cofx} ms]
(if (seq ms) (if (seq ms)
{:db (assoc db :mailserver/state :connecting {:db (assoc db :mailserver/state :connecting
:mailserver/current-id (keyword ms))} :mailserver/current-id (keyword ms))}
{:db (assoc db :mailserver/state nil)})) {:db (assoc db :mailserver/state nil)}))
(fx/defn handle-mailserver-available (rf/defn handle-mailserver-available
[{:keys [db] :as cofx} ms] [{:keys [db] :as cofx} ms]
{::cancel-connection-popup [] {::cancel-connection-popup []
:db (assoc db :mailserver/state :connected :db (assoc db :mailserver/state :connected
:mailserver/current-id (keyword ms))}) :mailserver/current-id (keyword ms))})
(fx/defn connected-to-mailserver (rf/defn connected-to-mailserver
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [address]} (fetch-current db)] (let [{:keys [address]} (fetch-current db)]
(fx/merge (rf/merge
cofx cofx
{:mailserver/update-mailservers [[address] #(re-frame/dispatch [::request-messages])]}))) {:mailserver/update-mailservers [[address] #(re-frame/dispatch [::request-messages])]})))
(fx/defn handle-request-success (rf/defn handle-request-success
{:events [:mailserver.callback/request-success]} {:events [:mailserver.callback/request-success]}
[{{:keys [chats] :as db} :db} {:keys [request-id topics]}] [{{:keys [chats] :as db} :db} {:keys [request-id topics]}]
(when (:mailserver/current-request db) (when (:mailserver/current-request db)
{:db (assoc-in db [:mailserver/current-request :request-id] {:db (assoc-in db [:mailserver/current-request :request-id]
request-id)})) request-id)}))
(fx/defn toggle-use-mailservers (rf/defn toggle-use-mailservers
[cofx value] [cofx value]
{::json-rpc/call {::json-rpc/call
[{:method "wakuext_toggleUseMailservers" [{:method "wakuext_toggleUseMailservers"
@@ -162,23 +162,23 @@
:on-success #(log/info "successfully toggled use-mailservers" value) :on-success #(log/info "successfully toggled use-mailservers" value)
:on-failure #(log/error "failed to toggle use-mailserver" value %)}]}) :on-failure #(log/error "failed to toggle use-mailserver" value %)}]})
(fx/defn update-use-mailservers (rf/defn update-use-mailservers
{:events [:mailserver.ui/use-history-switch-pressed]} {:events [:mailserver.ui/use-history-switch-pressed]}
[cofx use-mailservers?] [cofx use-mailservers?]
(fx/merge cofx (rf/merge cofx
(multiaccounts.update/optimistic :use-mailservers? use-mailservers?) (multiaccounts.update/optimistic :use-mailservers? use-mailservers?)
(toggle-use-mailservers use-mailservers?) (toggle-use-mailservers use-mailservers?)
(when use-mailservers? (when use-mailservers?
(disconnect-from-mailserver)))) (disconnect-from-mailserver))))
(fx/defn retry-next-messages-request (rf/defn retry-next-messages-request
{:events [:mailserver.ui/retry-request-pressed]} {:events [:mailserver.ui/retry-request-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (dissoc db :mailserver/request-error)} {:db (dissoc db :mailserver/request-error)}
(process-next-messages-request))) (process-next-messages-request)))
(fx/defn show-request-error-popup (rf/defn show-request-error-popup
{:events [:mailserver.ui/request-error-pressed]} {:events [:mailserver.ui/request-error-pressed]}
[{:keys [db]}] [{:keys [db]}]
(let [mailserver-error (:mailserver/request-error db)] (let [mailserver-error (:mailserver/request-error db)]
@@ -202,7 +202,7 @@
(let [[initial host] (extract-url-components address)] (let [[initial host] (extract-url-components address)]
(str "enode://" initial "@" host))) (str "enode://" initial "@" host)))
(fx/defn set-input (rf/defn set-input
{:events [:mailserver.ui/input-changed]} {:events [:mailserver.ui/input-changed]}
[{:keys [db]} input-key value] [{:keys [db]} input-key value]
{:db (update {:db (update
@@ -230,12 +230,12 @@
(def default? (comp not :custom fetch)) (def default? (comp not :custom fetch))
(fx/defn edit (rf/defn edit
{:events [:mailserver.ui/custom-mailserver-selected]} {:events [:mailserver.ui/custom-mailserver-selected]}
[{:keys [db] :as cofx} id] [{:keys [db] :as cofx} id]
(let [{:keys [id address name]} (fetch db id) (let [{:keys [id address name]} (fetch db id)
url (when address (build-url address))] url (when address (build-url address))]
(fx/merge cofx (rf/merge cofx
(set-input :id id) (set-input :id id)
(set-input :url (str url)) (set-input :url (str url))
(set-input :name (str name)) (set-input :name (str name))
@@ -247,7 +247,7 @@
(assoc :fleet (name current-fleet)) (assoc :fleet (name current-fleet))
(update :id name))) (update :id name)))
(fx/defn upsert (rf/defn upsert
{:events [:mailserver.ui/save-pressed] {:events [:mailserver.ui/save-pressed]
:interceptors [(re-frame/inject-cofx :random-id-generator)]} :interceptors [(re-frame/inject-cofx :random-id-generator)]}
[{{:mailserver.edit/keys [mailserver] :keys [multiaccount] :as db} :db [{{:mailserver.edit/keys [mailserver] :keys [multiaccount] :as db} :db
@@ -286,7 +286,7 @@
(not (or (default? db id) (not (or (default? db id)
(connected? db id)))) (connected? db id))))
(fx/defn delete (rf/defn delete
{:events [:mailserver.ui/delete-confirmed]} {:events [:mailserver.ui/delete-confirmed]}
[{:keys [db] :as cofx} id] [{:keys [db] :as cofx} id]
(if (can-delete? db id) (if (can-delete? db id)
@@ -303,7 +303,7 @@
:dispatch [:navigate-back]} :dispatch [:navigate-back]}
{:dispatch [:navigate-back]})) {:dispatch [:navigate-back]}))
(fx/defn show-connection-confirmation (rf/defn show-connection-confirmation
{:events [:mailserver.ui/default-mailserver-selected :mailserver.ui/connect-pressed]} {:events [:mailserver.ui/default-mailserver-selected :mailserver.ui/connect-pressed]}
[{:keys [db]} mailserver-id] [{:keys [db]} mailserver-id]
(let [current-fleet (node/current-fleet-key db)] (let [current-fleet (node/current-fleet-key db)]
@@ -319,7 +319,7 @@
[:mailserver.ui/connect-confirmed current-fleet mailserver-id]) [:mailserver.ui/connect-confirmed current-fleet mailserver-id])
:on-cancel nil}})) :on-cancel nil}}))
(fx/defn show-delete-confirmation (rf/defn show-delete-confirmation
{:events [:mailserver.ui/delete-pressed]} {:events [:mailserver.ui/delete-pressed]}
[{:keys [db]} mailserver-id] [{:keys [db]} mailserver-id]
{:ui/show-confirmation {:ui/show-confirmation
@@ -329,24 +329,24 @@
:on-accept #(re-frame/dispatch :on-accept #(re-frame/dispatch
[:mailserver.ui/delete-confirmed mailserver-id])}}) [:mailserver.ui/delete-confirmed mailserver-id])}})
(fx/defn set-url-from-qr (rf/defn set-url-from-qr
{:events [:mailserver.callback/qr-code-scanned]} {:events [:mailserver.callback/qr-code-scanned]}
[cofx url] [cofx url]
(assoc (set-input cofx :url url) (assoc (set-input cofx :url url)
:dispatch [:navigate-back])) :dispatch [:navigate-back]))
(fx/defn dismiss-connection-error (rf/defn dismiss-connection-error
{:events [:mailserver.ui/dismiss-connection-error]} {:events [:mailserver.ui/dismiss-connection-error]}
[{:keys [db]} new-state] [{:keys [db]} new-state]
{:db (assoc db :mailserver/connection-error-dismissed new-state)}) {:db (assoc db :mailserver/connection-error-dismissed new-state)})
(fx/defn pin-mailserver (rf/defn pin-mailserver
{:events [:mailserver.ui/connect-confirmed]} {:events [:mailserver.ui/connect-confirmed]}
[{:keys [db] :as cofx} current-fleet mailserver-id] [{:keys [db] :as cofx} current-fleet mailserver-id]
(let [pinned-mailservers (-> db (let [pinned-mailservers (-> db
(get-in [:multiaccount :pinned-mailservers]) (get-in [:multiaccount :pinned-mailservers])
(assoc current-fleet mailserver-id))] (assoc current-fleet mailserver-id))]
(fx/merge cofx (rf/merge cofx
{:db (assoc db :mailserver/current-id mailserver-id) {:db (assoc db :mailserver/current-id mailserver-id)
::json-rpc/call [{:method "wakuext_setPinnedMailservers" ::json-rpc/call [{:method "wakuext_setPinnedMailservers"
:params [pinned-mailservers] :params [pinned-mailservers]
@@ -354,14 +354,14 @@
:on-error #(log/error "failed to pin mailserver" %)}]} :on-error #(log/error "failed to pin mailserver" %)}]}
(multiaccounts.update/optimistic :pinned-mailservers pinned-mailservers)))) (multiaccounts.update/optimistic :pinned-mailservers pinned-mailservers))))
(fx/defn unpin (rf/defn unpin
{:events [:mailserver.ui/unpin-pressed]} {:events [:mailserver.ui/unpin-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [current-fleet (node/current-fleet-key db) (let [current-fleet (node/current-fleet-key db)
pinned-mailservers (-> db pinned-mailservers (-> db
(get-in [:multiaccount :pinned-mailservers]) (get-in [:multiaccount :pinned-mailservers])
(dissoc current-fleet))] (dissoc current-fleet))]
(fx/merge cofx (rf/merge cofx
{::json-rpc/call [{:method "wakuext_setPinnedMailservers" {::json-rpc/call [{:method "wakuext_setPinnedMailservers"
:params [pinned-mailservers] :params [pinned-mailservers]
:on-success #(log/info "successfully unpinned mailserver") :on-success #(log/info "successfully unpinned mailserver")
@@ -370,13 +370,13 @@
:pinned-mailservers pinned-mailservers) :pinned-mailservers pinned-mailservers)
(dismiss-connection-error false)))) (dismiss-connection-error false))))
(fx/defn pin (rf/defn pin
{:events [:mailserver.ui/pin-pressed]} {:events [:mailserver.ui/pin-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [current-fleet (node/current-fleet-key db) (let [current-fleet (node/current-fleet-key db)
mailserver-id (:mailserver/current-id db) mailserver-id (:mailserver/current-id db)
pinned-mailservers (get-in db [:multiaccount :pinned-mailservers])] pinned-mailservers (get-in db [:multiaccount :pinned-mailservers])]
(fx/merge cofx (rf/merge cofx
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:pinned-mailservers (assoc pinned-mailservers :pinned-mailservers (assoc pinned-mailservers
current-fleet current-fleet
@@ -384,9 +384,9 @@
{}) {})
(dismiss-connection-error false)))) (dismiss-connection-error false))))
(fx/defn mailserver-ui-add-pressed (rf/defn mailserver-ui-add-pressed
{:events [:mailserver.ui/add-pressed]} {:events [:mailserver.ui/add-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (dissoc db :mailserver.edit/mailserver)} {:db (dissoc db :mailserver.edit/mailserver)}
(navigation/navigate-to-cofx :edit-mailserver nil))) (navigation/navigate-to-cofx :edit-mailserver nil)))
+14 -14
View File
@@ -1,7 +1,7 @@
(ns status-im.mobile-sync-settings.core (ns status-im.mobile-sync-settings.core
(:require (:require
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.wallet.core :as wallet] [status-im.wallet.core :as wallet]
[status-im.bottom-sheet.core :as bottom-sheet] [status-im.bottom-sheet.core :as bottom-sheet]
[status-im.multiaccounts.model :as multiaccounts.model] [status-im.multiaccounts.model :as multiaccounts.model]
@@ -10,19 +10,19 @@
[status-im.utils.mobile-sync :as utils] [status-im.utils.mobile-sync :as utils]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(fx/defn sheet-defaults (rf/defn sheet-defaults
[{:keys [db]}] [{:keys [db]}]
(let [remember-choice? (get-in db [:multiaccount :remember-syncing-choice?])] (let [remember-choice? (get-in db [:multiaccount :remember-syncing-choice?])]
{:db (assoc db :mobile-network/remember-choice? (or (nil? remember-choice?) {:db (assoc db :mobile-network/remember-choice? (or (nil? remember-choice?)
remember-choice?))})) remember-choice?))}))
(fx/defn on-network-status-change (rf/defn on-network-status-change
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [initialized? (get db :network-status/initialized?) (let [initialized? (get db :network-status/initialized?)
logged-in? (multiaccounts.model/logged-in? cofx) logged-in? (multiaccounts.model/logged-in? cofx)
{:keys [remember-syncing-choice?]} (:multiaccount db)] {:keys [remember-syncing-choice?]} (:multiaccount db)]
(apply (apply
fx/merge rf/merge
cofx cofx
{:db (assoc db :network-status/initialized? true)} {:db (assoc db :network-status/initialized? true)}
(cond (cond
@@ -61,7 +61,7 @@
"sunc?" sync? "sunc?" sync?
"remember?" remember? "remember?" remember?
"cellular?" cellular?) "cellular?" cellular?)
(fx/merge (rf/merge
cofx cofx
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:syncing-on-mobile-network? (boolean sync?) {}) :syncing-on-mobile-network? (boolean sync?) {})
@@ -71,47 +71,47 @@
(mailserver/process-next-messages-request)) (mailserver/process-next-messages-request))
(wallet/restart-wallet-service nil)))))) (wallet/restart-wallet-service nil))))))
(fx/defn mobile-network-continue-syncing (rf/defn mobile-network-continue-syncing
{:events [:mobile-network/continue-syncing]} {:events [:mobile-network/continue-syncing]}
[cofx] [cofx]
((apply-settings true) cofx)) ((apply-settings true) cofx))
(fx/defn mobile-network-stop-syncing (rf/defn mobile-network-stop-syncing
{:events [:mobile-network/stop-syncing]} {:events [:mobile-network/stop-syncing]}
[cofx] [cofx]
((apply-settings false) cofx)) ((apply-settings false) cofx))
(fx/defn mobile-network-set-syncing (rf/defn mobile-network-set-syncing
{:events [:mobile-network/set-syncing]} {:events [:mobile-network/set-syncing]}
[{:keys [db] :as cofx} syncing?] [{:keys [db] :as cofx} syncing?]
(let [{:keys [remember-syncing-choice?]} (:multiaccount db)] (let [{:keys [remember-syncing-choice?]} (:multiaccount db)]
((apply-settings syncing? remember-syncing-choice?) cofx))) ((apply-settings syncing? remember-syncing-choice?) cofx)))
(fx/defn mobile-network-ask-on-mobile-network? (rf/defn mobile-network-ask-on-mobile-network?
{:events [:mobile-network/ask-on-mobile-network?]} {:events [:mobile-network/ask-on-mobile-network?]}
[{:keys [db] :as cofx} ask?] [{:keys [db] :as cofx} ask?]
(let [{:keys [syncing-on-mobile-network?]} (:multiaccount db)] (let [{:keys [syncing-on-mobile-network?]} (:multiaccount db)]
((apply-settings syncing-on-mobile-network? (not ask?)) cofx))) ((apply-settings syncing-on-mobile-network? (not ask?)) cofx)))
(fx/defn mobile-network-restore-defaults (rf/defn mobile-network-restore-defaults
{:events [:mobile-network/restore-defaults]} {:events [:mobile-network/restore-defaults]}
[cofx] [cofx]
((apply-settings false false) cofx)) ((apply-settings false false) cofx))
(fx/defn mobile-network-remember-choice? (rf/defn mobile-network-remember-choice?
{:events [:mobile-network/remember-choice?]} {:events [:mobile-network/remember-choice?]}
[{:keys [db]} remember-choice?] [{:keys [db]} remember-choice?]
{:db (assoc db :mobile-network/remember-choice? remember-choice?)}) {:db (assoc db :mobile-network/remember-choice? remember-choice?)})
(fx/defn mobile-network-navigate-to-settings (rf/defn mobile-network-navigate-to-settings
{:events [:mobile-network/navigate-to-settings]} {:events [:mobile-network/navigate-to-settings]}
[cofx] [cofx]
(fx/merge (rf/merge
cofx cofx
(bottom-sheet/hide-bottom-sheet) (bottom-sheet/hide-bottom-sheet)
(navigation/navigate-to-cofx :mobile-network-settings nil))) (navigation/navigate-to-cofx :mobile-network-settings nil)))
(fx/defn mobile-network-show-offline-sheet (rf/defn mobile-network-show-offline-sheet
{:events [:mobile-network/show-offline-sheet]} {:events [:mobile-network/show-offline-sheet]}
[cofx] [cofx]
(bottom-sheet/show-bottom-sheet (bottom-sheet/show-bottom-sheet
+14 -14
View File
@@ -4,7 +4,7 @@
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.popover.core :as popover] [status-im.popover.core :as popover]
[quo.design-system.colors :as colors] [quo.design-system.colors :as colors]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.keychain.core :as keychain] [status-im.utils.keychain.core :as keychain]
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[taoensso.timbre :as log] [taoensso.timbre :as log]
@@ -105,12 +105,12 @@
(get-supported callback) (get-supported callback)
(callback nil))))))) (callback nil)))))))
(fx/defn set-supported-biometric-auth (rf/defn set-supported-biometric-auth
{:events [:init.callback/get-supported-biometric-auth-success]} {:events [:init.callback/get-supported-biometric-auth-success]}
[{:keys [db]} supported-biometric-auth] [{:keys [db]} supported-biometric-auth]
{:db (assoc db :supported-biometric-auth supported-biometric-auth)}) {:db (assoc db :supported-biometric-auth supported-biometric-auth)})
(fx/defn authenticate (rf/defn authenticate
[_ cb options] [_ cb options]
{:biometric-auth/authenticate [cb options]}) {:biometric-auth/authenticate [cb options]})
@@ -119,10 +119,10 @@
(fn [[cb options]] (fn [[cb options]]
(authenticate-fx #(cb %) options))) (authenticate-fx #(cb %) options)))
(fx/defn update-biometric [{db :db :as cofx} biometric-auth?] (rf/defn update-biometric [{db :db :as cofx} biometric-auth?]
(let [key-uid (or (get-in db [:multiaccount :key-uid]) (let [key-uid (or (get-in db [:multiaccount :key-uid])
(get-in db [:multiaccounts/login :key-uid]))] (get-in db [:multiaccounts/login :key-uid]))]
(fx/merge cofx (rf/merge cofx
(keychain/save-auth-method (keychain/save-auth-method
key-uid key-uid
(if biometric-auth? (if biometric-auth?
@@ -131,7 +131,7 @@
#(when-not biometric-auth? #(when-not biometric-auth?
{:keychain/clear-user-password key-uid})))) {:keychain/clear-user-password key-uid}))))
(fx/defn biometric-auth-switched (rf/defn biometric-auth-switched
{:events [:multiaccounts.ui/biometric-auth-switched]} {:events [:multiaccounts.ui/biometric-auth-switched]}
[cofx biometric-auth?] [cofx biometric-auth?]
(if biometric-auth? (if biometric-auth?
@@ -141,7 +141,7 @@
{}) {})
(update-biometric cofx false))) (update-biometric cofx false)))
(fx/defn show-message (rf/defn show-message
[cofx bioauth-message bioauth-code] [cofx bioauth-message bioauth-code]
(let [content (or (when (get #{"NOT_AVAILABLE" "NOT_ENROLLED"} bioauth-code) (let [content (or (when (get #{"NOT_AVAILABLE" "NOT_ENROLLED"} bioauth-code)
(i18n/label :t/grant-face-id-permissions)) (i18n/label :t/grant-face-id-permissions))
@@ -151,7 +151,7 @@
{:title (i18n/label :t/biometric-auth-login-error-title) {:title (i18n/label :t/biometric-auth-login-error-title)
:content content}}))) :content content}})))
(fx/defn biometric-init-done (rf/defn biometric-init-done
{:events [:biometric-init-done]} {:events [:biometric-init-done]}
[cofx {:keys [bioauth-success bioauth-message bioauth-code]}] [cofx {:keys [bioauth-success bioauth-message bioauth-code]}]
(if bioauth-success (if bioauth-success
@@ -161,7 +161,7 @@
(popover/show-popover cofx {:view :enable-biometric})) (popover/show-popover cofx {:view :enable-biometric}))
(show-message cofx bioauth-message bioauth-code))) (show-message cofx bioauth-message bioauth-code)))
(fx/defn biometric-auth (rf/defn biometric-auth
{:events [:biometric-authenticate]} {:events [:biometric-authenticate]}
[cofx] [cofx]
(authenticate (authenticate
@@ -170,25 +170,25 @@
{:reason (i18n/label :t/biometric-auth-reason-login) {:reason (i18n/label :t/biometric-auth-reason-login)
:ios-fallback-label (i18n/label :t/biometric-auth-login-ios-fallback-label)})) :ios-fallback-label (i18n/label :t/biometric-auth-login-ios-fallback-label)}))
(fx/defn enable (rf/defn enable
{:events [:biometric/enable]} {:events [:biometric/enable]}
[cofx] [cofx]
(fx/merge (rf/merge
cofx cofx
(popover/hide-popover) (popover/hide-popover)
(authenticate #(re-frame/dispatch [:biometric/setup-done %]) {}))) (authenticate #(re-frame/dispatch [:biometric/setup-done %]) {})))
(fx/defn disable (rf/defn disable
{:events [:biometric/disable]} {:events [:biometric/disable]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(assoc :auth-method keychain/auth-method-none) (assoc :auth-method keychain/auth-method-none)
(assoc-in [:multiaccounts/login :save-password?] false))} (assoc-in [:multiaccounts/login :save-password?] false))}
(popover/hide-popover))) (popover/hide-popover)))
(fx/defn setup-done (rf/defn setup-done
{:events [:biometric/setup-done]} {:events [:biometric/setup-done]}
[{:keys [db] :as cofx} {:keys [bioauth-success bioauth-message bioauth-code]}] [{:keys [db] :as cofx} {:keys [bioauth-success bioauth-message bioauth-code]}]
(log/debug "[biometric] setup-done" (log/debug "[biometric] setup-done"
+23 -23
View File
@@ -5,7 +5,7 @@
[status-im.bottom-sheet.core :as bottom-sheet] [status-im.bottom-sheet.core :as bottom-sheet]
[status-im.native-module.core :as native-module] [status-im.native-module.core :as native-module]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.gfycat.core :as gfycat] [status-im.utils.gfycat.core :as gfycat]
[status-im.utils.identicon :as identicon] [status-im.utils.identicon :as identicon]
[status-im.theme.core :as theme] [status-im.theme.core :as theme]
@@ -110,37 +110,37 @@
(fn [flag] (fn [flag]
(native-module/set-blank-preview-flag flag))) (native-module/set-blank-preview-flag flag)))
(fx/defn confirm-wallet-set-up (rf/defn confirm-wallet-set-up
{:events [:multiaccounts.ui/wallet-set-up-confirmed]} {:events [:multiaccounts.ui/wallet-set-up-confirmed]}
[cofx] [cofx]
(multiaccounts.update/multiaccount-update cofx (multiaccounts.update/multiaccount-update cofx
:wallet-set-up-passed? true {})) :wallet-set-up-passed? true {}))
(fx/defn confirm-home-tooltip (rf/defn confirm-home-tooltip
{:events [:multiaccounts.ui/hide-home-tooltip]} {:events [:multiaccounts.ui/hide-home-tooltip]}
[cofx] [cofx]
(multiaccounts.update/multiaccount-update cofx (multiaccounts.update/multiaccount-update cofx
:hide-home-tooltip? true {})) :hide-home-tooltip? true {}))
(fx/defn switch-webview-debug (rf/defn switch-webview-debug
{:events [:multiaccounts.ui/switch-webview-debug]} {:events [:multiaccounts.ui/switch-webview-debug]}
[{:keys [db] :as cofx} value] [{:keys [db] :as cofx} value]
(fx/merge cofx (rf/merge cofx
{::webview-debug-changed value} {::webview-debug-changed value}
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:webview-debug (boolean value) :webview-debug (boolean value)
{}))) {})))
(fx/defn switch-preview-privacy-mode (rf/defn switch-preview-privacy-mode
{:events [:multiaccounts.ui/preview-privacy-mode-switched]} {:events [:multiaccounts.ui/preview-privacy-mode-switched]}
[{:keys [db] :as cofx} private?] [{:keys [db] :as cofx} private?]
(fx/merge cofx (rf/merge cofx
{::blank-preview-flag-changed private?} {::blank-preview-flag-changed private?}
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:preview-privacy? (boolean private?) :preview-privacy? (boolean private?)
{}))) {})))
(fx/defn switch-webview-permission-requests? (rf/defn switch-webview-permission-requests?
{:events [:multiaccounts.ui/webview-permission-requests-switched]} {:events [:multiaccounts.ui/webview-permission-requests-switched]}
[cofx enabled?] [cofx enabled?]
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
@@ -148,7 +148,7 @@
:webview-allow-permission-requests? (boolean enabled?) :webview-allow-permission-requests? (boolean enabled?)
{})) {}))
(fx/defn switch-default-sync-period (rf/defn switch-default-sync-period
{:events [:multiaccounts.ui/default-sync-period-switched]} {:events [:multiaccounts.ui/default-sync-period-switched]}
[cofx value] [cofx value]
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
@@ -156,7 +156,7 @@
:default-sync-period value :default-sync-period value
{})) {}))
(fx/defn switch-preview-privacy-mode-flag (rf/defn switch-preview-privacy-mode-flag
[{:keys [db]}] [{:keys [db]}]
(let [private? (get-in db [:multiaccount :preview-privacy?])] (let [private? (get-in db [:multiaccount :preview-privacy?])]
{::blank-preview-flag-changed private?})) {::blank-preview-flag-changed private?}))
@@ -169,23 +169,23 @@
:light)] :light)]
(theme/change-theme theme)))) (theme/change-theme theme))))
(fx/defn switch-appearance (rf/defn switch-appearance
{:events [:multiaccounts.ui/appearance-switched]} {:events [:multiaccounts.ui/appearance-switched]}
[cofx theme] [cofx theme]
(fx/merge cofx (rf/merge cofx
{:multiaccounts.ui/switch-theme theme} {:multiaccounts.ui/switch-theme theme}
(multiaccounts.update/multiaccount-update :appearance theme {}))) (multiaccounts.update/multiaccount-update :appearance theme {})))
(fx/defn switch-profile-picture-show-to (rf/defn switch-profile-picture-show-to
{:events [:multiaccounts.ui/profile-picture-show-to-switched]} {:events [:multiaccounts.ui/profile-picture-show-to-switched]}
[cofx id] [cofx id]
(fx/merge cofx (rf/merge cofx
{::json-rpc/call [{:method "wakuext_changeIdentityImageShowTo" {::json-rpc/call [{:method "wakuext_changeIdentityImageShowTo"
:params [id] :params [id]
:on-success #(log/debug "picture settings changed successfully")}]} :on-success #(log/debug "picture settings changed successfully")}]}
(multiaccounts.update/optimistic :profile-pictures-show-to id))) (multiaccounts.update/optimistic :profile-pictures-show-to id)))
(fx/defn switch-appearance-profile (rf/defn switch-appearance-profile
{:events [:multiaccounts.ui/appearance-profile-switched]} {:events [:multiaccounts.ui/appearance-profile-switched]}
[cofx id] [cofx id]
(multiaccounts.update/multiaccount-update cofx :profile-pictures-visibility id {})) (multiaccounts.update/multiaccount-update cofx :profile-pictures-visibility id {}))
@@ -195,22 +195,22 @@
(string/replace-first path #"file://" "") (string/replace-first path #"file://" "")
(log/warn "[native-module] Empty path was provided"))) (log/warn "[native-module] Empty path was provided")))
(fx/defn save-profile-picture (rf/defn save-profile-picture
{:events [::save-profile-picture]} {:events [::save-profile-picture]}
[cofx path ax ay bx by] [cofx path ax ay bx by]
(let [key-uid (get-in cofx [:db :multiaccount :key-uid])] (let [key-uid (get-in cofx [:db :multiaccount :key-uid])]
(fx/merge cofx (rf/merge cofx
{::json-rpc/call [{:method "multiaccounts_storeIdentityImage" {::json-rpc/call [{:method "multiaccounts_storeIdentityImage"
:params [key-uid (clean-path path) ax ay bx by] :params [key-uid (clean-path path) ax ay bx by]
;; NOTE: In case of an error we can show a toast error ;; NOTE: In case of an error we can show a toast error
:on-success #(re-frame/dispatch [::update-local-picture %])}]} :on-success #(re-frame/dispatch [::update-local-picture %])}]}
(bottom-sheet/hide-bottom-sheet)))) (bottom-sheet/hide-bottom-sheet))))
(fx/defn save-profile-picture-from-url (rf/defn save-profile-picture-from-url
{:events [::save-profile-picture-from-url]} {:events [::save-profile-picture-from-url]}
[cofx url] [cofx url]
(let [key-uid (get-in cofx [:db :multiaccount :key-uid])] (let [key-uid (get-in cofx [:db :multiaccount :key-uid])]
(fx/merge cofx (rf/merge cofx
{::json-rpc/call [{:method "multiaccounts_storeIdentityImageFromURL" {::json-rpc/call [{:method "multiaccounts_storeIdentityImageFromURL"
:params [key-uid url] :params [key-uid url]
:on-error #(log/error "::save-profile-picture-from-url error" %) :on-error #(log/error "::save-profile-picture-from-url error" %)
@@ -220,11 +220,11 @@
(comment (comment
(re-frame/dispatch [::save-profile-picture-from-url "https://lh3.googleusercontent.com/XuKjNm3HydsaxbPkbpGs9YyCKhn5QQk5oDC8XF2jzmPyYXeZofxFtfUDZuQ3EVmacS_BlBKzbX2ypm37YNX3n1fDJA3WndeFcPsp7Z0=w600"])) (re-frame/dispatch [::save-profile-picture-from-url "https://lh3.googleusercontent.com/XuKjNm3HydsaxbPkbpGs9YyCKhn5QQk5oDC8XF2jzmPyYXeZofxFtfUDZuQ3EVmacS_BlBKzbX2ypm37YNX3n1fDJA3WndeFcPsp7Z0=w600"]))
(fx/defn delete-profile-picture (rf/defn delete-profile-picture
{:events [::delete-profile-picture]} {:events [::delete-profile-picture]}
[cofx name] [cofx name]
(let [key-uid (get-in cofx [:db :multiaccount :key-uid])] (let [key-uid (get-in cofx [:db :multiaccount :key-uid])]
(fx/merge cofx (rf/merge cofx
{::json-rpc/call [{:method "multiaccounts_deleteIdentityImage" {::json-rpc/call [{:method "multiaccounts_deleteIdentityImage"
:params [key-uid] :params [key-uid]
;; NOTE: In case of an error we could fallback to previous image in UI with a toast error ;; NOTE: In case of an error we could fallback to previous image in UI with a toast error
@@ -232,14 +232,14 @@
(multiaccounts.update/optimistic :images nil) (multiaccounts.update/optimistic :images nil)
(bottom-sheet/hide-bottom-sheet)))) (bottom-sheet/hide-bottom-sheet))))
(fx/defn get-profile-picture (rf/defn get-profile-picture
[cofx] [cofx]
(let [key-uid (get-in cofx [:db :multiaccount :key-uid])] (let [key-uid (get-in cofx [:db :multiaccount :key-uid])]
{::json-rpc/call [{:method "multiaccounts_getIdentityImages" {::json-rpc/call [{:method "multiaccounts_getIdentityImages"
:params [key-uid] :params [key-uid]
:on-success #(re-frame/dispatch [::update-local-picture %])}]})) :on-success #(re-frame/dispatch [::update-local-picture %])}]}))
(fx/defn store-profile-picture (rf/defn store-profile-picture
{:events [::update-local-picture]} {:events [::update-local-picture]}
[cofx pics] [cofx pics]
(multiaccounts.update/optimistic cofx :images pics)) (multiaccounts.update/optimistic cofx :images pics))
+13 -13
View File
@@ -9,7 +9,7 @@
[status-im.node.core :as node] [status-im.node.core :as node]
[quo.design-system.colors :as colors] [quo.design-system.colors :as colors]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.security :as security] [status-im.utils.security :as security]
[status-im.utils.signing-phrase.core :as signing-phrase] [status-im.utils.signing-phrase.core :as signing-phrase]
[status-im.utils.types :as types])) [status-im.utils.types :as types]))
@@ -49,7 +49,7 @@
hashed-password hashed-password
callback))) callback)))
(fx/defn create-multiaccount (rf/defn create-multiaccount
{:events [:create-multiaccount]} {:events [:create-multiaccount]}
[{:keys [db]} key-code] [{:keys [db]} key-code]
(let [{:keys [selected-id]} (:intro-wizard db)] (let [{:keys [selected-id]} (:intro-wizard db)]
@@ -86,7 +86,7 @@
(mapv normalize-multiaccount-data-keys (mapv normalize-multiaccount-data-keys
(types/json->clj %))])))) (types/json->clj %))]))))
(fx/defn multiaccount-generate-and-derive-addresses-success (rf/defn multiaccount-generate-and-derive-addresses-success
{:events [:multiaccount-generate-and-derive-addresses-success]} {:events [:multiaccount-generate-and-derive-addresses-success]}
[{:keys [db]} result] [{:keys [db]} result]
{:db (update db :intro-wizard {:db (update db :intro-wizard
@@ -99,7 +99,7 @@
:step :choose-key)))) :step :choose-key))))
:navigate-to-fx :choose-name}) :navigate-to-fx :choose-name})
(fx/defn generate-and-derive-addresses (rf/defn generate-and-derive-addresses
{:events [:generate-and-derive-addresses]} {:events [:generate-and-derive-addresses]}
[{:keys [db]}] [{:keys [db]}]
{:db (-> db {:db (-> db
@@ -107,11 +107,11 @@
(dissoc :recovered-account?)) (dissoc :recovered-account?))
:multiaccount-generate-and-derive-addresses nil}) :multiaccount-generate-and-derive-addresses nil})
(fx/defn prepare-intro-wizard (rf/defn prepare-intro-wizard
[{:keys [db]}] [{:keys [db]}]
{:db (assoc db :intro-wizard {})}) {:db (assoc db :intro-wizard {})})
(fx/defn save-multiaccount-and-login-with-keycard (rf/defn save-multiaccount-and-login-with-keycard
[_ args] [_ args]
{:keycard/save-multiaccount-and-login args}) {:keycard/save-multiaccount-and-login args})
@@ -126,7 +126,7 @@
config config
accounts-data))) accounts-data)))
(fx/defn save-account-and-login (rf/defn save-account-and-login
[_ key-uid multiaccount-data password settings node-config accounts-data] [_ key-uid multiaccount-data password settings node-config accounts-data]
{::save-account-and-login [key-uid {::save-account-and-login [key-uid
(types/clj->json multiaccount-data) (types/clj->json multiaccount-data)
@@ -154,7 +154,7 @@
:path constants/path-whisper :path constants/path-whisper
:chat true})]) :chat true})])
(fx/defn on-multiaccount-created (rf/defn on-multiaccount-created
[{:keys [signing-phrase random-guid-generator db] :as cofx} [{:keys [signing-phrase random-guid-generator db] :as cofx}
{:keys [address chat-key keycard-instance-uid key-uid {:keys [address chat-key keycard-instance-uid key-uid
keycard-pairing keycard-paired-on mnemonic recovered] keycard-pairing keycard-paired-on mnemonic recovered]
@@ -221,7 +221,7 @@
settings (assoc new-multiaccount settings (assoc new-multiaccount
:networks/current-network config/default-network :networks/current-network config/default-network
:networks/networks config/default-networks)] :networks/networks config/default-networks)]
(fx/merge cofx (rf/merge cofx
{:db db} {:db db}
(if keycard-multiaccount? (if keycard-multiaccount?
(save-multiaccount-and-login-with-keycard (save-multiaccount-and-login-with-keycard
@@ -240,12 +240,12 @@
(node/get-new-config db) (node/get-new-config db)
accounts-data))))) accounts-data)))))
(fx/defn store-multiaccount-success (rf/defn store-multiaccount-success
{:events [::store-multiaccount-success] {:events [::store-multiaccount-success]
:interceptors [(re-frame/inject-cofx :random-guid-generator) :interceptors [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx ::get-signing-phrase)]} (re-frame/inject-cofx ::get-signing-phrase)]}
[{:keys [db] :as cofx} password derived] [{:keys [db] :as cofx} password derived]
(fx/merge cofx (rf/merge cofx
{:db (dissoc db :intro-wizard)} {:db (dissoc db :intro-wizard)}
(on-multiaccount-created (assoc (let [{:keys [selected-id multiaccounts]} (:intro-wizard db)] (on-multiaccount-created (assoc (let [{:keys [selected-id multiaccounts]} (:intro-wizard db)]
(some #(when (= selected-id (:id %)) %) multiaccounts)) (some #(when (= selected-id (:id %)) %) multiaccounts))
@@ -254,12 +254,12 @@
password password
{:save-mnemonic? true}))) {:save-mnemonic? true})))
(fx/defn on-key-selected (rf/defn on-key-selected
{:events [:intro-wizard/on-key-selected]} {:events [:intro-wizard/on-key-selected]}
[{:keys [db]} id] [{:keys [db]} id]
{:db (assoc-in db [:intro-wizard :selected-id] id)}) {:db (assoc-in db [:intro-wizard :selected-id] id)})
(fx/defn on-key-storage-selected (rf/defn on-key-storage-selected
{:events [:intro-wizard/on-key-storage-selected]} {:events [:intro-wizard/on-key-storage-selected]}
[{:keys [db]} storage-type] [{:keys [db]} storage-type]
{:db (assoc-in db [:intro-wizard :selected-storage-type] storage-type)}) {:db (assoc-in db [:intro-wizard :selected-storage-type] storage-type)})
@@ -10,7 +10,7 @@
[status-im.native-module.core :as native-module] [status-im.native-module.core :as native-module]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.popover.core :as popover] [status-im.popover.core :as popover]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.security :as security] [status-im.utils.security :as security]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
@@ -18,7 +18,7 @@
[status-im.keycard.backup-key :as keycard.backup] [status-im.keycard.backup-key :as keycard.backup]
[status-im.bottom-sheet.core :as bottom-sheet])) [status-im.bottom-sheet.core :as bottom-sheet]))
(fx/defn key-and-storage-management-pressed (rf/defn key-and-storage-management-pressed
"This event can be dispatched before login and from profile and needs to redirect accordingly" "This event can be dispatched before login and from profile and needs to redirect accordingly"
{:events [::key-and-storage-management-pressed]} {:events [::key-and-storage-management-pressed]}
[cofx] [cofx]
@@ -29,36 +29,36 @@
:actions-not-logged-in) :actions-not-logged-in)
nil)) nil))
(fx/defn move-keystore-checked (rf/defn move-keystore-checked
{:events [::move-keystore-checked]} {:events [::move-keystore-checked]}
[{:keys [db] :as cofx} checked?] [{:keys [db] :as cofx} checked?]
{:db (assoc-in db [:multiaccounts/key-storage :move-keystore-checked?] checked?)}) {:db (assoc-in db [:multiaccounts/key-storage :move-keystore-checked?] checked?)})
(fx/defn reset-db-checked (rf/defn reset-db-checked
{:events [::reset-db-checked]} {:events [::reset-db-checked]}
[{:keys [db] :as cofx} checked?] [{:keys [db] :as cofx} checked?]
{:db (assoc-in db [:multiaccounts/key-storage :reset-db-checked?] checked?)}) {:db (assoc-in db [:multiaccounts/key-storage :reset-db-checked?] checked?)})
(fx/defn navigate-back (rf/defn navigate-back
{:events [::navigate-back]} {:events [::navigate-back]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(dissoc :recovered-account?) (dissoc :recovered-account?)
(update :keycard dissoc :from-key-storage-and-migration? :creating-backup? :factory-reset-card?))} (update :keycard dissoc :from-key-storage-and-migration? :creating-backup? :factory-reset-card?))}
(navigation/navigate-back))) (navigation/navigate-back)))
(fx/defn enter-seed-pressed (rf/defn enter-seed-pressed
"User is logged out and probably wants to move multiaccount to Keycard. Navigate to enter seed phrase screen" "User is logged out and probably wants to move multiaccount to Keycard. Navigate to enter seed phrase screen"
{:events [::enter-seed-pressed]} {:events [::enter-seed-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge (rf/merge
cofx cofx
{:db (assoc db :recovered-account? true)} {:db (assoc db :recovered-account? true)}
(navigation/navigate-to-cofx :seed-phrase nil))) (navigation/navigate-to-cofx :seed-phrase nil)))
(fx/defn seed-phrase-input-changed (rf/defn seed-phrase-input-changed
{:events [::seed-phrase-input-changed]} {:events [::seed-phrase-input-changed]}
[{:keys [db] :as cofx} masked-seed-phrase] [{:keys [db] :as cofx} masked-seed-phrase]
(let [seed-phrase (security/safe-unmask-data masked-seed-phrase)] (let [seed-phrase (security/safe-unmask-data masked-seed-phrase)]
@@ -69,12 +69,12 @@
(not (mnemonic/valid-length? seed-phrase))) (not (mnemonic/valid-length? seed-phrase)))
:seed-word-count (mnemonic/words-count seed-phrase))})) :seed-word-count (mnemonic/words-count seed-phrase))}))
(fx/defn key-uid-seed-mismatch (rf/defn key-uid-seed-mismatch
{:events [::show-seed-key-uid-mismatch-error-popup]} {:events [::show-seed-key-uid-mismatch-error-popup]}
[cofx _] [cofx _]
(popover/show-popover cofx {:view :seed-key-uid-mismatch})) (popover/show-popover cofx {:view :seed-key-uid-mismatch}))
(fx/defn key-uid-matches (rf/defn key-uid-matches
{:events [::key-uid-matches]} {:events [::key-uid-matches]}
[{:keys [db] :as cofx} _] [{:keys [db] :as cofx} _]
(let [backup? (get-in db [:keycard :creating-backup?])] (let [backup? (get-in db [:keycard :creating-backup?])]
@@ -103,7 +103,7 @@
:on-success #(re-frame/dispatch [::key-uid-matches]) :on-success #(re-frame/dispatch [::key-uid-matches])
:on-error #(re-frame/dispatch [::show-seed-key-uid-mismatch-error-popup])})) :on-error #(re-frame/dispatch [::show-seed-key-uid-mismatch-error-popup])}))
(fx/defn seed-phrase-validated (rf/defn seed-phrase-validated
{:events [::seed-phrase-validated]} {:events [::seed-phrase-validated]}
[{:keys [db] :as cofx} validation-error] [{:keys [db] :as cofx} validation-error]
(let [error? (-> validation-error (let [error? (-> validation-error
@@ -120,7 +120,7 @@
(-> db :multiaccount :key-uid) (-> db :multiaccount :key-uid)
(and onboarding? (-> db :keycard :application-info :key-uid)))}}))) (and onboarding? (-> db :keycard :application-info :key-uid)))}})))
(fx/defn choose-storage-pressed (rf/defn choose-storage-pressed
{:events [::choose-storage-pressed]} {:events [::choose-storage-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [seed-phrase]} (:multiaccounts/key-storage db)] (let [{:keys [seed-phrase]} (:multiaccounts/key-storage db)]
@@ -128,7 +128,7 @@
[(mnemonic/sanitize-passphrase seed-phrase) [(mnemonic/sanitize-passphrase seed-phrase)
#(re-frame/dispatch [::seed-phrase-validated %])]})) #(re-frame/dispatch [::seed-phrase-validated %])]}))
(fx/defn keycard-storage-pressed (rf/defn keycard-storage-pressed
{:events [::keycard-storage-pressed]} {:events [::keycard-storage-pressed]}
[{:keys [db]} selected?] [{:keys [db]} selected?]
{:db (assoc-in db [:multiaccounts/key-storage :keycard-storage-selected?] selected?)}) {:db (assoc-in db [:multiaccounts/key-storage :keycard-storage-selected?] selected?)})
@@ -161,7 +161,7 @@ The exact events dispatched for this flow if consumed from the UI are:
We don't need to take the exact steps, just set the required state and redirect to correct screen We don't need to take the exact steps, just set the required state and redirect to correct screen
" "
(fx/defn import-multiaccount (rf/defn import-multiaccount
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
{:dispatch [:bottom-sheet/hide] {:dispatch [:bottom-sheet/hide]
::multiaccounts.recover/import-multiaccount ::multiaccounts.recover/import-multiaccount
@@ -169,27 +169,27 @@ We don't need to take the exact steps, just set the required state and redirect
:password nil :password nil
:success-event ::import-multiaccount-success}}) :success-event ::import-multiaccount-success}})
(fx/defn delete-multiaccount-and-init-keycard-onboarding (rf/defn delete-multiaccount-and-init-keycard-onboarding
{:events [::delete-multiaccount-and-init-keycard-onboarding]} {:events [::delete-multiaccount-and-init-keycard-onboarding]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge (rf/merge
{:dispatch [:bottom-sheet/hide] {:dispatch [:bottom-sheet/hide]
:db (assoc-in db [:multiaccounts/key-storage :reset-db-checked?] true)} :db (assoc-in db [:multiaccounts/key-storage :reset-db-checked?] true)}
(import-multiaccount))) (import-multiaccount)))
(fx/defn storage-selected (rf/defn storage-selected
{:events [::storage-selected]} {:events [::storage-selected]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(if (get-in db [:multiaccounts/key-storage :reset-db-checked?]) (if (get-in db [:multiaccounts/key-storage :reset-db-checked?])
(popover/show-popover cofx {:view :transfer-multiaccount-to-keycard-warning}) (popover/show-popover cofx {:view :transfer-multiaccount-to-keycard-warning})
(bottom-sheet/show-bottom-sheet cofx {:view :migrate-account-password}))) (bottom-sheet/show-bottom-sheet cofx {:view :migrate-account-password})))
(fx/defn skip-password-pressed (rf/defn skip-password-pressed
{:events [::skip-password-pressed]} {:events [::skip-password-pressed]}
[cofx] [cofx]
(popover/show-popover cofx {:view :transfer-multiaccount-to-keycard-warning})) (popover/show-popover cofx {:view :transfer-multiaccount-to-keycard-warning}))
(fx/defn password-changed (rf/defn password-changed
{:events [::password-changed]} {:events [::password-changed]}
[{db :db} password] [{db :db} password]
(let [unmasked-pass (security/safe-unmask-data password)] (let [unmasked-pass (security/safe-unmask-data password)]
@@ -198,18 +198,18 @@ We don't need to take the exact steps, just set the required state and redirect
:migration-password-error nil :migration-password-error nil
:migration-password-valid? (and unmasked-pass (> (count unmasked-pass) 5)))})) :migration-password-valid? (and unmasked-pass (> (count unmasked-pass) 5)))}))
(fx/defn verify-password-result (rf/defn verify-password-result
{:events [::verify-password-result]} {:events [::verify-password-result]}
[{:keys [db] :as cofx} result] [{:keys [db] :as cofx} result]
(let [{:keys [error]} (types/json->clj result)] (let [{:keys [error]} (types/json->clj result)]
(if (string/blank? error) (if (string/blank? error)
(fx/merge (rf/merge
cofx cofx
{:db (update db :keycard dissoc :migration-password-error :migration-password-valid?)} {:db (update db :keycard dissoc :migration-password-error :migration-password-valid?)}
(import-multiaccount)) (import-multiaccount))
{:db (assoc-in db [:keycard :migration-password-error] (i18n/label :t/wrong-password))}))) {:db (assoc-in db [:keycard :migration-password-error] (i18n/label :t/wrong-password))})))
(fx/defn verify-password (rf/defn verify-password
{:events [::verify-password]} {:events [::verify-password]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(native-module/verify-database-password (native-module/verify-database-password
@@ -217,10 +217,10 @@ We don't need to take the exact steps, just set the required state and redirect
(ethereum/sha3 (security/safe-unmask-data (get-in db [:keycard :migration-password]))) (ethereum/sha3 (security/safe-unmask-data (get-in db [:keycard :migration-password])))
#(re-frame/dispatch [::verify-password-result %]))) #(re-frame/dispatch [::verify-password-result %])))
(fx/defn handle-multiaccount-import (rf/defn handle-multiaccount-import
{:events [::import-multiaccount-success]} {:events [::import-multiaccount-success]}
[{:keys [db] :as cofx} root-data derived-data] [{:keys [db] :as cofx} root-data derived-data]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(update :intro-wizard (update :intro-wizard
assoc assoc
@@ -238,21 +238,21 @@ We don't need to take the exact steps, just set the required state and redirect
(common/listen-to-hardware-back-button) (common/listen-to-hardware-back-button)
(navigation/navigate-to-cofx :keycard-onboarding-intro nil))) (navigation/navigate-to-cofx :keycard-onboarding-intro nil)))
(fx/defn goto-multiaccounts-screen (rf/defn goto-multiaccounts-screen
{:events [::hide-popover-and-goto-multiaccounts-screen]} {:events [::hide-popover-and-goto-multiaccounts-screen]}
[cofx _] [cofx _]
(fx/merge cofx (rf/merge cofx
(popover/hide-popover) (popover/hide-popover)
(navigation/navigate-to-cofx :multiaccounts nil))) (navigation/navigate-to-cofx :multiaccounts nil)))
(fx/defn confirm-logout-and-goto-key-storage (rf/defn confirm-logout-and-goto-key-storage
{:events [::confirm-logout-and-goto-key-storage]} {:events [::confirm-logout-and-goto-key-storage]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc db :goto-key-storage? true)} {:db (assoc db :goto-key-storage? true)}
(multiaccounts.logout/logout))) (multiaccounts.logout/logout)))
(fx/defn logout-and-goto-key-storage (rf/defn logout-and-goto-key-storage
{:events [::logout-and-goto-key-storage]} {:events [::logout-and-goto-key-storage]}
[_] [_]
{:ui/show-confirmation {:ui/show-confirmation
+55 -55
View File
@@ -18,7 +18,7 @@
[status-im.communities.core :as communities] [status-im.communities.core :as communities]
[status-im.transport.core :as transport] [status-im.transport.core :as transport]
[status-im.mobile-sync-settings.core :as mobile-network] [status-im.mobile-sync-settings.core :as mobile-network]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.keychain.core :as keychain] [status-im.utils.keychain.core :as keychain]
[status-im2.setup.log :as logging] [status-im2.setup.log :as logging]
[status-im.utils.security :as security] [status-im.utils.security :as security]
@@ -119,7 +119,7 @@
"0x86a12d91c813f69a53349ff640e32af97d5f5c1f8d42d54cf4c8aa8dea231955" "0x86a12d91c813f69a53349ff640e32af97d5f5c1f8d42d54cf4c8aa8dea231955"
"0x0011a30f5b2023bc228f6dd5608b3e7149646fa83f33350926ceb1925af78f08"}) "0x0011a30f5b2023bc228f6dd5608b3e7149646fa83f33350926ceb1925af78f08"})
(fx/defn check-invalid-ens [{:keys [db]}] (rf/defn check-invalid-ens [{:keys [db]}]
(async-storage/get-item (async-storage/get-item
:invalid-ens-name-seen :invalid-ens-name-seen
(fn [already-seen] (fn [already-seen]
@@ -131,11 +131,11 @@
#(async-storage/set-item! :invalid-ens-name-seen true))))) #(async-storage/set-item! :invalid-ens-name-seen true)))))
nil) nil)
(fx/defn initialize-wallet (rf/defn initialize-wallet
{:events [::initialize-wallet]} {:events [::initialize-wallet]}
[{:keys [db] :as cofx} accounts tokens custom-tokens [{:keys [db] :as cofx} accounts tokens custom-tokens
favourites scan-all-tokens? new-account?] favourites scan-all-tokens? new-account?]
(fx/merge (rf/merge
cofx cofx
{:db (assoc db :multiaccount/accounts {:db (assoc db :multiaccount/accounts
(rpc->accounts accounts)) (rpc->accounts accounts))
@@ -166,7 +166,7 @@
(prices/update-prices) (prices/update-prices)
(wallet-connect-legacy/get-connector-session-from-db))) (wallet-connect-legacy/get-connector-session-from-db)))
(fx/defn login (rf/defn login
{:events [:multiaccounts.login.ui/password-input-submitted]} {:events [:multiaccounts.login.ui/password-input-submitted]}
[{:keys [db]}] [{:keys [db]}]
(let [{:keys [key-uid password name identicon]} (:multiaccounts/login db)] (let [{:keys [key-uid password name identicon]} (:multiaccounts/login db)]
@@ -180,7 +180,7 @@
:identicon identicon}) :identicon identicon})
(ethereum/sha3 (security/safe-unmask-data password))]})) (ethereum/sha3 (security/safe-unmask-data password))]}))
(fx/defn export-db-submitted (rf/defn export-db-submitted
{:events [:multiaccounts.login.ui/export-db-submitted]} {:events [:multiaccounts.login.ui/export-db-submitted]}
[{:keys [db]}] [{:keys [db]}]
(let [{:keys [key-uid password name identicon]} (:multiaccounts/login db)] (let [{:keys [key-uid password name identicon]} (:multiaccounts/login db)]
@@ -195,7 +195,7 @@
(.share ^js react/sharing (clj->js {:title "Unencrypted database" (.share ^js react/sharing (clj->js {:title "Unencrypted database"
:url uri})))))]})) :url uri})))))]}))
(fx/defn import-db-submitted (rf/defn import-db-submitted
{:events [:multiaccounts.login.ui/import-db-submitted]} {:events [:multiaccounts.login.ui/import-db-submitted]}
[{:keys [db]}] [{:keys [db]}]
(let [{:keys [key-uid password name identicon]} (:multiaccounts/login db)] (let [{:keys [key-uid password name identicon]} (:multiaccounts/login db)]
@@ -205,11 +205,11 @@
:identicon identicon}) :identicon identicon})
(ethereum/sha3 (security/safe-unmask-data password))]})) (ethereum/sha3 (security/safe-unmask-data password))]}))
(fx/defn finish-keycard-setup (rf/defn finish-keycard-setup
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
{:db (update db :keycard dissoc :flow)}) {:db (update db :keycard dissoc :flow)})
(fx/defn initialize-dapp-permissions (rf/defn initialize-dapp-permissions
{:events [::initialize-dapp-permissions]} {:events [::initialize-dapp-permissions]}
[{:keys [db]} all-dapp-permissions] [{:keys [db]} all-dapp-permissions]
(let [dapp-permissions (reduce (fn [acc {:keys [dapp] :as dapp-permissions}] (let [dapp-permissions (reduce (fn [acc {:keys [dapp] :as dapp-permissions}]
@@ -218,7 +218,7 @@
all-dapp-permissions)] all-dapp-permissions)]
{:db (assoc db :dapps/permissions dapp-permissions)})) {:db (assoc db :dapps/permissions dapp-permissions)}))
(fx/defn initialize-browsers (rf/defn initialize-browsers
{:events [::initialize-browsers]} {:events [::initialize-browsers]}
[{:keys [db]} all-stored-browsers] [{:keys [db]} all-stored-browsers]
(let [browsers (reduce (fn [acc {:keys [browser-id] :as browser}] (let [browsers (reduce (fn [acc {:keys [browser-id] :as browser}]
@@ -227,7 +227,7 @@
all-stored-browsers)] all-stored-browsers)]
{:db (assoc db :browser/browsers browsers)})) {:db (assoc db :browser/browsers browsers)}))
(fx/defn initialize-bookmarks (rf/defn initialize-bookmarks
{:events [::initialize-bookmarks]} {:events [::initialize-bookmarks]}
[{:keys [db]} stored-bookmarks] [{:keys [db]} stored-bookmarks]
(let [bookmarks (reduce (fn [acc {:keys [url] :as bookmark}] (let [bookmarks (reduce (fn [acc {:keys [url] :as bookmark}]
@@ -236,7 +236,7 @@
stored-bookmarks)] stored-bookmarks)]
{:db (assoc db :bookmarks/bookmarks bookmarks)})) {:db (assoc db :bookmarks/bookmarks bookmarks)}))
(fx/defn initialize-invitations (rf/defn initialize-invitations
{:events [::initialize-invitations]} {:events [::initialize-invitations]}
[{:keys [db]} invitations] [{:keys [db]} invitations]
{:db (assoc db :group-chat/invitations (reduce (fn [acc {:keys [id] :as inv}] {:db (assoc db :group-chat/invitations (reduce (fn [acc {:keys [id] :as inv}]
@@ -244,17 +244,17 @@
{} {}
invitations))}) invitations))})
(fx/defn initialize-web3-client-version (rf/defn initialize-web3-client-version
{:events [::initialize-web3-client-version]} {:events [::initialize-web3-client-version]}
[{:keys [db]} node-version] [{:keys [db]} node-version]
{:db (assoc db :web3-node-version node-version)}) {:db (assoc db :web3-node-version node-version)})
(fx/defn handle-close-app-confirmed (rf/defn handle-close-app-confirmed
{:events [::close-app-confirmed]} {:events [::close-app-confirmed]}
[_] [_]
{:ui/close-application nil}) {:ui/close-application nil})
(fx/defn check-network-version (rf/defn check-network-version
[_ network-id] [_ network-id]
{::json-rpc/call {::json-rpc/call
[{:method "net_version" [{:method "net_version"
@@ -326,7 +326,7 @@
(.catch (fn [_] (.catch (fn [_]
(log/error "Failed to initialize wallet")))))) (log/error "Failed to initialize wallet"))))))
(fx/defn initialize-browser [_] (rf/defn initialize-browser [_]
{::json-rpc/call {::json-rpc/call
[{:method "wakuext_getBrowsers" [{:method "wakuext_getBrowsers"
:on-success #(re-frame/dispatch [::initialize-browsers %])} :on-success #(re-frame/dispatch [::initialize-browsers %])}
@@ -335,38 +335,38 @@
{:method "permissions_getDappPermissions" {:method "permissions_getDappPermissions"
:on-success #(re-frame/dispatch [::initialize-dapp-permissions %])}]}) :on-success #(re-frame/dispatch [::initialize-dapp-permissions %])}]})
(fx/defn initialize-appearance [cofx] (rf/defn initialize-appearance [cofx]
{:multiaccounts.ui/switch-theme (get-in cofx [:db :multiaccount :appearance])}) {:multiaccounts.ui/switch-theme (get-in cofx [:db :multiaccount :appearance])})
(fx/defn get-group-chat-invitations [_] (rf/defn get-group-chat-invitations [_]
{::json-rpc/call {::json-rpc/call
[{:method "wakuext_getGroupChatInvitations" [{:method "wakuext_getGroupChatInvitations"
:on-success #(re-frame/dispatch [::initialize-invitations %])}]}) :on-success #(re-frame/dispatch [::initialize-invitations %])}]})
(fx/defn initialize-communities-enabled (rf/defn initialize-communities-enabled
[cofx] [cofx]
{::initialize-communities-enabled nil}) {::initialize-communities-enabled nil})
(fx/defn initialize-transactions-management-enabled (rf/defn initialize-transactions-management-enabled
[cofx] [cofx]
{::initialize-transactions-management-enabled nil}) {::initialize-transactions-management-enabled nil})
(fx/defn initialize-wallet-connect (rf/defn initialize-wallet-connect
[cofx] [cofx]
{::initialize-wallet-connect nil}) {::initialize-wallet-connect nil})
(fx/defn get-node-config-callback (rf/defn get-node-config-callback
{:events [::get-node-config-callback]} {:events [::get-node-config-callback]}
[{:keys [db] :as cofx} node-config-json] [{:keys [db] :as cofx} node-config-json]
(let [node-config (types/json->clj node-config-json)] (let [node-config (types/json->clj node-config-json)]
{:db (assoc-in db [:multiaccount :wakuv2-config] {:db (assoc-in db [:multiaccount :wakuv2-config]
(get node-config :WakuV2Config))})) (get node-config :WakuV2Config))}))
(fx/defn get-node-config (rf/defn get-node-config
[_] [_]
(status/get-node-config #(re-frame/dispatch [::get-node-config-callback %]))) (status/get-node-config #(re-frame/dispatch [::get-node-config-callback %])))
(fx/defn get-settings-callback (rf/defn get-settings-callback
{:events [::get-settings-callback]} {:events [::get-settings-callback]}
[{:keys [db] :as cofx} settings] [{:keys [db] :as cofx} settings]
(let [{:networks/keys [current-network networks] (let [{:networks/keys [current-network networks]
@@ -376,7 +376,7 @@
;;for some reason we save default networks in db, in case when we want to modify default-networks for ;;for some reason we save default networks in db, in case when we want to modify default-networks for
;; existing accounts we have to merge them again into networks ;; existing accounts we have to merge them again into networks
merged-networks (merge networks config/default-networks-by-id)] merged-networks (merge networks config/default-networks-by-id)]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(dissoc :multiaccounts/login) (dissoc :multiaccounts/login)
(assoc :networks/current-network current-network (assoc :networks/current-network current-network
@@ -408,12 +408,12 @@
(when (= stored-key-uid key-uid) (when (= stored-key-uid key-uid)
(re-frame/dispatch [:chat.ui/navigate-to-chat chat-id]))))))))) (re-frame/dispatch [:chat.ui/navigate-to-chat chat-id])))))))))
(fx/defn check-last-chat (rf/defn check-last-chat
{:events [::check-last-chat]} {:events [::check-last-chat]}
[{:keys [db]}] [{:keys [db]}]
{::open-last-chat (get-in db [:multiaccount :key-uid])}) {::open-last-chat (get-in db [:multiaccount :key-uid])})
(fx/defn update-wallet-accounts (rf/defn update-wallet-accounts
[{:keys [db]} accounts] [{:keys [db]} accounts]
(let [existing-accounts (into {} (map #(vector (:address %1) %1) (:multiaccount/accounts db))) (let [existing-accounts (into {} (map #(vector (:address %1) %1) (:multiaccount/accounts db)))
reduce-fn (fn [existing-accs new-acc] reduce-fn (fn [existing-accs new-acc]
@@ -424,7 +424,7 @@
new-accounts (reduce reduce-fn existing-accounts (rpc->accounts accounts))] new-accounts (reduce reduce-fn existing-accounts (rpc->accounts accounts))]
{:db (assoc db :multiaccount/accounts (vals new-accounts))})) {:db (assoc db :multiaccount/accounts (vals new-accounts))}))
(fx/defn get-chats-callback (rf/defn get-chats-callback
{:events [::get-chats-callback]} {:events [::get-chats-callback]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:networks/keys [current-network networks]} db (let [{:networks/keys [current-network networks]} db
@@ -432,7 +432,7 @@
network-id (str (get-in networks [current-network :config :NetworkId])) network-id (str (get-in networks [current-network :config :NetworkId]))
remote-push-notifications-enabled? remote-push-notifications-enabled?
(get-in db [:multiaccount :remote-push-notifications-enabled?])] (get-in db [:multiaccount :remote-push-notifications-enabled?])]
(fx/merge cofx (rf/merge cofx
(cond-> {::eip1559/check-eip1559-activation (cond-> {::eip1559/check-eip1559-activation
{:network-id network-id {:network-id network-id
:on-enabled #(log/info "eip1550 is activated") :on-enabled #(log/info "eip1550 is activated")
@@ -472,14 +472,14 @@
(re-frame/dispatch [:init-root (if config/new-ui-enabled? :shell-stack :chat-stack)]) (re-frame/dispatch [:init-root (if config/new-ui-enabled? :shell-stack :chat-stack)])
(re-frame/dispatch [:init-root :tos]))) (re-frame/dispatch [:init-root :tos])))
(fx/defn login-only-events (rf/defn login-only-events
[{:keys [db] :as cofx} key-uid password save-password?] [{:keys [db] :as cofx} key-uid password save-password?]
(let [auth-method (:auth-method db) (let [auth-method (:auth-method db)
new-auth-method (get-new-auth-method auth-method save-password?)] new-auth-method (get-new-auth-method auth-method save-password?)]
(log/debug "[login] login-only-events" (log/debug "[login] login-only-events"
"auth-method" auth-method "auth-method" auth-method
"new-auth-method" new-auth-method) "new-auth-method" new-auth-method)
(fx/merge cofx (rf/merge cofx
{:db (assoc db :chats/loading? true) {:db (assoc db :chats/loading? true)
::json-rpc/call ::json-rpc/call
[{:method "settings_getSettings" [{:method "settings_getSettings"
@@ -490,7 +490,7 @@
(keychain/save-user-password key-uid password)) (keychain/save-user-password key-uid password))
(keychain/save-auth-method key-uid (or new-auth-method auth-method keychain/auth-method-none))))) (keychain/save-auth-method key-uid (or new-auth-method auth-method keychain/auth-method-none)))))
(fx/defn create-only-events (rf/defn create-only-events
[{:keys [db] :as cofx} recovered-account?] [{:keys [db] :as cofx} recovered-account?]
(let [{:keys [multiaccount (let [{:keys [multiaccount
:multiaccounts/multiaccounts :multiaccounts/multiaccounts
@@ -501,7 +501,7 @@
tos-accepted? (get db :tos/accepted?) tos-accepted? (get db :tos/accepted?)
{:networks/keys [current-network networks]} db {:networks/keys [current-network networks]} db
network-id (str (get-in networks [current-network :config :NetworkId]))] network-id (str (get-in networks [current-network :config :NetworkId]))]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(dissoc :multiaccounts/login) (dissoc :multiaccounts/login)
(assoc :tos/next-root :onboarding-notification :chats/loading? false) (assoc :tos/next-root :onboarding-notification :chats/loading? false)
@@ -544,7 +544,7 @@
(assoc :logged-in-since now) (assoc :logged-in-since now)
(assoc :view-id :home))) (assoc :view-id :home)))
(fx/defn multiaccount-login-success (rf/defn multiaccount-login-success
[{:keys [db now] :as cofx}] [{:keys [db now] :as cofx}]
(let [{:keys [key-uid password save-password? creating?]} (let [{:keys [key-uid password save-password? creating?]}
(:multiaccounts/login db) (:multiaccounts/login db)
@@ -559,7 +559,7 @@
(log/debug "[multiaccount] multiaccount-login-success" (log/debug "[multiaccount] multiaccount-login-success"
"login-only?" login-only? "login-only?" login-only?
"recovered-account?" recovered-account?) "recovered-account?" recovered-account?)
(fx/merge cofx (rf/merge cofx
{:db (on-login-update-db db login-only? now) {:db (on-login-update-db db login-only? now)
::json-rpc/call ::json-rpc/call
[{:method "web3_clientVersion" [{:method "web3_clientVersion"
@@ -582,7 +582,7 @@
;; are alreayd in `multiaccounts/login` and should not be overriden, as they come from ;; are alreayd in `multiaccounts/login` and should not be overriden, as they come from
;; the keychain (save-password), this is not very explicit and we should probably ;; the keychain (save-password), this is not very explicit and we should probably
;; make it clearer ;; make it clearer
(fx/defn open-login (rf/defn open-login
[{:keys [db]} override-multiaccount] [{:keys [db]} override-multiaccount]
{:db (-> db {:db (-> db
(update :multiaccounts/login (update :multiaccounts/login
@@ -593,7 +593,7 @@
:error :error
:password))}) :password))})
(fx/defn open-login-callback (rf/defn open-login-callback
{:events [:multiaccounts.login.callback/get-user-password-success]} {:events [:multiaccounts.login.callback/get-user-password-success]}
[{:keys [db] :as cofx} password] [{:keys [db] :as cofx} password]
(let [key-uid (get-in db [:multiaccounts/login :key-uid]) (let [key-uid (get-in db [:multiaccounts/login :key-uid])
@@ -602,14 +602,14 @@
:keycard-pairing])) :keycard-pairing]))
goto-key-storage? (:goto-key-storage? db)] goto-key-storage? (:goto-key-storage? db)]
(if password (if password
(fx/merge (rf/merge
cofx cofx
{:db (update-in db [:multiaccounts/login] assoc {:db (update-in db [:multiaccounts/login] assoc
:password password :password password
:save-password? true) :save-password? true)
:init-root-fx :progress} :init-root-fx :progress}
login) login)
(fx/merge (rf/merge
cofx cofx
{:db (dissoc db :goto-key-storage?)} {:db (dissoc db :goto-key-storage?)}
(when keycard-account? (when keycard-account?
@@ -622,7 +622,7 @@
#(when goto-key-storage? #(when goto-key-storage?
(navigation/navigate-to-cofx % :actions-not-logged-in nil)))))) (navigation/navigate-to-cofx % :actions-not-logged-in nil))))))
(fx/defn get-credentials (rf/defn get-credentials
[{:keys [db] :as cofx} key-uid] [{:keys [db] :as cofx} key-uid]
(let [keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts key-uid :keycard-pairing]))] (let [keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts key-uid :keycard-pairing]))]
(log/debug "[login] get-credentials" (log/debug "[login] get-credentials"
@@ -631,7 +631,7 @@
(keychain/get-keycard-keys cofx key-uid) (keychain/get-keycard-keys cofx key-uid)
(keychain/get-user-password cofx key-uid)))) (keychain/get-user-password cofx key-uid))))
(fx/defn get-auth-method-success (rf/defn get-auth-method-success
"Auth method: nil - not supported, \"none\" - not selected, \"password\", \"biometric\", \"biometric-prepare\"" "Auth method: nil - not supported, \"none\" - not selected, \"password\", \"biometric\", \"biometric-prepare\""
{:events [:multiaccounts.login/get-auth-method-success]} {:events [:multiaccounts.login/get-auth-method-success]}
[{:keys [db] :as cofx} auth-method] [{:keys [db] :as cofx} auth-method]
@@ -640,7 +640,7 @@
(log/debug "[login] get-auth-method-success" (log/debug "[login] get-auth-method-success"
"auth-method" auth-method "auth-method" auth-method
"keycard-multiacc?" keycard-multiaccount?) "keycard-multiacc?" keycard-multiaccount?)
(fx/merge (rf/merge
cofx cofx
{:db (assoc db :auth-method auth-method)} {:db (assoc db :auth-method auth-method)}
#(cond #(cond
@@ -653,7 +653,7 @@
(keycard.common/get-application-info % nil)) (keycard.common/get-application-info % nil))
(open-login-callback nil)))) (open-login-callback nil))))
(fx/defn biometric-auth-done (rf/defn biometric-auth-done
{:events [:biometric-auth-done]} {:events [:biometric-auth-done]}
[{:keys [db] :as cofx} {:keys [bioauth-success bioauth-message bioauth-code]}] [{:keys [db] :as cofx} {:keys [bioauth-success bioauth-message bioauth-code]}]
(let [key-uid (get-in db [:multiaccounts/login :key-uid]) (let [key-uid (get-in db [:multiaccounts/login :key-uid])
@@ -664,7 +664,7 @@
"bioauth-code" bioauth-code) "bioauth-code" bioauth-code)
(if bioauth-success (if bioauth-success
(get-credentials cofx key-uid) (get-credentials cofx key-uid)
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db {:db (assoc-in db
[:multiaccounts/login :save-password?] [:multiaccounts/login :save-password?]
(= auth-method keychain/auth-method-biometric))} (= auth-method keychain/auth-method-biometric))}
@@ -673,7 +673,7 @@
(biometric/show-message bioauth-message bioauth-code) (biometric/show-message bioauth-message bioauth-code)
(open-login-callback nil))))) (open-login-callback nil)))))
(fx/defn save-password (rf/defn save-password
{:events [:multiaccounts/save-password]} {:events [:multiaccounts/save-password]}
[{:keys [db] :as cofx} save-password?] [{:keys [db] :as cofx} save-password?]
(let [bioauth-supported? (boolean (get db :supported-biometric-auth)) (let [bioauth-supported? (boolean (get db :supported-biometric-auth))
@@ -682,7 +682,7 @@
"save-password?" save-password? "save-password?" save-password?
"bioauth-supported?" bioauth-supported? "bioauth-supported?" bioauth-supported?
"previous-auth-method" previous-auth-method) "previous-auth-method" previous-auth-method)
(fx/merge (rf/merge
cofx cofx
{:db (cond-> db {:db (cond-> db
(not= previous-auth-method (not= previous-auth-method
@@ -700,54 +700,54 @@
(when-not (= previous-auth-method keychain/auth-method-none) (when-not (= previous-auth-method keychain/auth-method-none)
(popover/show-popover {:view :disable-password-saving}))))))) (popover/show-popover {:view :disable-password-saving})))))))
(fx/defn welcome-lets-go (rf/defn welcome-lets-go
{:events [:welcome-lets-go]} {:events [:welcome-lets-go]}
[_] [_]
{:init-root-fx :chat-stack}) {:init-root-fx :chat-stack})
(fx/defn multiaccount-selected (rf/defn multiaccount-selected
{:events [:multiaccounts.login.ui/multiaccount-selected]} {:events [:multiaccounts.login.ui/multiaccount-selected]}
[{:keys [db] :as cofx} key-uid] [{:keys [db] :as cofx} key-uid]
;; We specifically pass a bunch of fields instead of the whole multiaccount ;; We specifically pass a bunch of fields instead of the whole multiaccount
;; as we want store some fields in multiaccount that are not here ;; as we want store some fields in multiaccount that are not here
(let [multiaccount (get-in db [:multiaccounts/multiaccounts key-uid]) (let [multiaccount (get-in db [:multiaccounts/multiaccounts key-uid])
keycard-multiaccount? (boolean (:keycard-pairing multiaccount))] keycard-multiaccount? (boolean (:keycard-pairing multiaccount))]
(fx/merge (rf/merge
cofx cofx
{:db (update db :keycard dissoc :application-info) {:db (update db :keycard dissoc :application-info)
:navigate-to-fx (if keycard-multiaccount? :keycard-login-pin :login)} :navigate-to-fx (if keycard-multiaccount? :keycard-login-pin :login)}
(open-login (select-keys multiaccount [:key-uid :name :public-key :identicon :images]))))) (open-login (select-keys multiaccount [:key-uid :name :public-key :identicon :images])))))
(fx/defn hide-keycard-banner (rf/defn hide-keycard-banner
{:events [:hide-keycard-banner]} {:events [:hide-keycard-banner]}
[{:keys [db]}] [{:keys [db]}]
{:db (assoc db :keycard/banner-hidden true) {:db (assoc db :keycard/banner-hidden true)
::async-storage/set! {:keycard-banner-hidden true}}) ::async-storage/set! {:keycard-banner-hidden true}})
(fx/defn get-keycard-banner-preference-cb (rf/defn get-keycard-banner-preference-cb
{:events [:get-keycard-banner-preference-cb]} {:events [:get-keycard-banner-preference-cb]}
[{:keys [db]} {:keys [keycard-banner-hidden]}] [{:keys [db]} {:keys [keycard-banner-hidden]}]
{:db (assoc db :keycard/banner-hidden keycard-banner-hidden)}) {:db (assoc db :keycard/banner-hidden keycard-banner-hidden)})
(fx/defn get-keycard-banner-preference (rf/defn get-keycard-banner-preference
{:events [:get-keycard-banner-preference]} {:events [:get-keycard-banner-preference]}
[_] [_]
{::async-storage/get {:keys [:keycard-banner-hidden] {::async-storage/get {:keys [:keycard-banner-hidden]
:cb #(re-frame/dispatch [:get-keycard-banner-preference-cb %])}}) :cb #(re-frame/dispatch [:get-keycard-banner-preference-cb %])}})
(fx/defn get-opted-in-to-new-terms-of-service-cb (rf/defn get-opted-in-to-new-terms-of-service-cb
{:events [:get-opted-in-to-new-terms-of-service-cb]} {:events [:get-opted-in-to-new-terms-of-service-cb]}
[{:keys [db]} {:keys [new-terms-of-service-accepted]}] [{:keys [db]} {:keys [new-terms-of-service-accepted]}]
{:db (assoc db :tos/accepted? new-terms-of-service-accepted)}) {:db (assoc db :tos/accepted? new-terms-of-service-accepted)})
(fx/defn get-opted-in-to-new-terms-of-service (rf/defn get-opted-in-to-new-terms-of-service
"New TOS sprint https://github.com/status-im/status-mobile/pull/12240" "New TOS sprint https://github.com/status-im/status-mobile/pull/12240"
{:events [:get-opted-in-to-new-terms-of-service]} {:events [:get-opted-in-to-new-terms-of-service]}
[{:keys [db]}] [{:keys [db]}]
{::async-storage/get {:keys [:new-terms-of-service-accepted] {::async-storage/get {:keys [:new-terms-of-service-accepted]
:cb #(re-frame/dispatch [:get-opted-in-to-new-terms-of-service-cb %])}}) :cb #(re-frame/dispatch [:get-opted-in-to-new-terms-of-service-cb %])}})
(fx/defn hide-terms-of-services-opt-in-screen (rf/defn hide-terms-of-services-opt-in-screen
{:events [:hide-terms-of-services-opt-in-screen]} {:events [:hide-terms-of-services-opt-in-screen]}
[{:keys [db]}] [{:keys [db]}]
{::async-storage/set! {:new-terms-of-service-accepted true} {::async-storage/set! {:new-terms-of-service-accepted true}
@@ -2,7 +2,7 @@
(:require [cljs.test :as test] (:require [cljs.test :as test]
[status-im.multiaccounts.biometric.core :as biometric] [status-im.multiaccounts.biometric.core :as biometric]
[status-im.multiaccounts.login.core :as login] [status-im.multiaccounts.login.core :as login]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.keychain.core :as keychain])) [status-im.utils.keychain.core :as keychain]))
(test/deftest save-password-test (test/deftest save-password-test
@@ -44,7 +44,7 @@
"uncheck save password") "uncheck save password")
(let [initial-cofx {:db {:auth-method keychain/auth-method-none (let [initial-cofx {:db {:auth-method keychain/auth-method-none
:supported-biometric-auth true}} :supported-biometric-auth true}}
{:keys [db]} (login/save-password (fx/merge {:keys [db]} (login/save-password (rf/merge
initial-cofx initial-cofx
(login/save-password true) (login/save-password true)
(biometric/enable) (biometric/enable)
+8 -8
View File
@@ -2,18 +2,18 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.multiaccounts.core :as multiaccounts] [status-im.multiaccounts.core :as multiaccounts]
[status-im.utils.keychain.core :as keychain] [status-im.utils.keychain.core :as keychain]
[status-im.notifications.core :as notifications] [status-im.notifications.core :as notifications]
[status-im.wallet.core :as wallet] [status-im.wallet.core :as wallet]
[status-im2.setup.events :as init])) [status-im2.setup.events :as init]))
(fx/defn logout-method (rf/defn logout-method
{:events [::logout-method]} {:events [::logout-method]}
[{:keys [db] :as cofx} {:keys [auth-method logout?]}] [{:keys [db] :as cofx} {:keys [auth-method logout?]}]
(let [key-uid (get-in db [:multiaccount :key-uid])] (let [key-uid (get-in db [:multiaccount :key-uid])]
(fx/merge cofx (rf/merge cofx
{:init-root-fx :progress {:init-root-fx :progress
:chat.ui/clear-inputs nil :chat.ui/clear-inputs nil
:chat.ui/clear-inputs-old nil :chat.ui/clear-inputs-old nil
@@ -27,11 +27,11 @@
(wallet/clear-timeouts) (wallet/clear-timeouts)
(init/initialize-app-db)))) (init/initialize-app-db))))
(fx/defn logout (rf/defn logout
{:events [:logout :multiaccounts.logout.ui/logout-confirmed :multiaccounts.update.callback/save-settings-success]} {:events [:logout :multiaccounts.logout.ui/logout-confirmed :multiaccounts.update.callback/save-settings-success]}
[cofx] [cofx]
;; we need to disable notifications before starting the logout process ;; we need to disable notifications before starting the logout process
(fx/merge cofx (rf/merge cofx
{:dispatch [:wallet-connect-legacy/clean-up-sessions] {:dispatch [:wallet-connect-legacy/clean-up-sessions]
:dispatch-later [{:ms 100 :dispatch-later [{:ms 100
:dispatch [::logout-method :dispatch [::logout-method
@@ -39,7 +39,7 @@
:logout? true}]}]} :logout? true}]}]}
(notifications/logout-disable))) (notifications/logout-disable)))
(fx/defn show-logout-confirmation (rf/defn show-logout-confirmation
{:events [:multiaccounts.logout.ui/logout-pressed]} {:events [:multiaccounts.logout.ui/logout-pressed]}
[_] [_]
{:ui/show-confirmation {:ui/show-confirmation
@@ -49,10 +49,10 @@
:on-accept #(re-frame/dispatch [:multiaccounts.logout.ui/logout-confirmed]) :on-accept #(re-frame/dispatch [:multiaccounts.logout.ui/logout-confirmed])
:on-cancel nil}}) :on-cancel nil}})
(fx/defn biometric-logout (rf/defn biometric-logout
{:events [:biometric-logout]} {:events [:biometric-logout]}
[cofx] [cofx]
(fx/merge cofx (rf/merge cofx
(logout-method {:auth-method keychain/auth-method-biometric-prepare (logout-method {:auth-method keychain/auth-method-biometric-prepare
:logout? false}) :logout? false})
(fn [{:keys [db]}] (fn [{:keys [db]}]
+29 -29
View File
@@ -11,7 +11,7 @@
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.popover.core :as popover] [status-im.popover.core :as popover]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.security :as security] [status-im.utils.security :as security]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
@@ -26,24 +26,24 @@
(defn check-phrase-warnings [recovery-phrase] (defn check-phrase-warnings [recovery-phrase]
(cond (string/blank? recovery-phrase) :t/required-field)) (cond (string/blank? recovery-phrase) :t/required-field))
(fx/defn set-phrase (rf/defn set-phrase
{:events [:multiaccounts.recover/passphrase-input-changed]} {:events [:multiaccounts.recover/passphrase-input-changed]}
[{:keys [db]} masked-recovery-phrase] [{:keys [db]} masked-recovery-phrase]
(let [recovery-phrase (security/safe-unmask-data masked-recovery-phrase)] (let [recovery-phrase (security/safe-unmask-data masked-recovery-phrase)]
(fx/merge (rf/merge
{:db (update db :intro-wizard assoc {:db (update db :intro-wizard assoc
:passphrase (string/lower-case recovery-phrase) :passphrase (string/lower-case recovery-phrase)
:passphrase-error nil :passphrase-error nil
:next-button-disabled? (or (empty? recovery-phrase) :next-button-disabled? (or (empty? recovery-phrase)
(not (mnemonic/valid-length? recovery-phrase))))}))) (not (mnemonic/valid-length? recovery-phrase))))})))
(fx/defn validate-phrase-for-warnings (rf/defn validate-phrase-for-warnings
[{:keys [db]}] [{:keys [db]}]
(let [recovery-phrase (get-in db [:intro-wizard :passphrase])] (let [recovery-phrase (get-in db [:intro-wizard :passphrase])]
{:db (update db :intro-wizard assoc {:db (update db :intro-wizard assoc
:passphrase-error (check-phrase-warnings recovery-phrase))})) :passphrase-error (check-phrase-warnings recovery-phrase))}))
(fx/defn on-store-multiaccount-success (rf/defn on-store-multiaccount-success
{:events [::store-multiaccount-success] {:events [::store-multiaccount-success]
:interceptors [(re-frame/inject-cofx :random-guid-generator) :interceptors [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]} (re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]}
@@ -69,7 +69,7 @@
password password
{}))))))) {})))))))
(fx/defn store-multiaccount (rf/defn store-multiaccount
{:events [::recover-multiaccount-confirmed]} {:events [::recover-multiaccount-confirmed]}
[{:keys [db]} password] [{:keys [db]} password]
(let [{:keys [root-key]} (:intro-wizard db) (let [{:keys [root-key]} (:intro-wizard db)
@@ -109,7 +109,7 @@
merge {:name name :identicon identicon})] merge {:name name :identicon identicon})]
(re-frame/dispatch [success-event root-data derived-data-extended])))))))))))) (re-frame/dispatch [success-event root-data derived-data-extended]))))))))))))
(fx/defn show-existing-multiaccount-alert (rf/defn show-existing-multiaccount-alert
[_ key-uid] [_ key-uid]
{:utils/show-confirmation {:utils/show-confirmation
{:title (i18n/label :t/multiaccount-exists-title) {:title (i18n/label :t/multiaccount-exists-title)
@@ -121,11 +121,11 @@
[:multiaccounts.login.ui/multiaccount-selected key-uid])) [:multiaccounts.login.ui/multiaccount-selected key-uid]))
:on-cancel #(re-frame/dispatch [:pop-to-root-tab :multiaccounts])}}) :on-cancel #(re-frame/dispatch [:pop-to-root-tab :multiaccounts])}})
(fx/defn on-import-multiaccount-success (rf/defn on-import-multiaccount-success
{:events [::import-multiaccount-success]} {:events [::import-multiaccount-success]}
[{:keys [db] :as cofx} {:keys [key-uid] :as root-data} derived-data] [{:keys [db] :as cofx} {:keys [key-uid] :as root-data} derived-data]
(let [multiaccounts (:multiaccounts/multiaccounts db)] (let [multiaccounts (:multiaccounts/multiaccounts db)]
(fx/merge (rf/merge
cofx cofx
{:db (update db :intro-wizard {:db (update db :intro-wizard
assoc :root-key root-data assoc :root-key root-data
@@ -135,10 +135,10 @@
(show-existing-multiaccount-alert key-uid)) (show-existing-multiaccount-alert key-uid))
(navigation/navigate-to-cofx :recover-multiaccount-success nil)))) (navigation/navigate-to-cofx :recover-multiaccount-success nil))))
(fx/defn enter-phrase-pressed (rf/defn enter-phrase-pressed
{:events [::enter-phrase-pressed]} {:events [::enter-phrase-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(assoc :intro-wizard (assoc :intro-wizard
@@ -153,7 +153,7 @@
(bottom-sheet/hide-bottom-sheet) (bottom-sheet/hide-bottom-sheet)
(navigation/navigate-to-cofx :recover-multiaccount-enter-phrase nil))) (navigation/navigate-to-cofx :recover-multiaccount-enter-phrase nil)))
(fx/defn proceed-to-import-mnemonic (rf/defn proceed-to-import-mnemonic
{:events [:multiaccounts.recover/phrase-validated]} {:events [:multiaccounts.recover/phrase-validated]}
[{:keys [db] :as cofx} phrase-warnings] [{:keys [db] :as cofx} phrase-warnings]
(let [{:keys [password passphrase]} (:intro-wizard db)] (let [{:keys [password passphrase]} (:intro-wizard db)]
@@ -165,23 +165,23 @@
(security/safe-unmask-data password)) (security/safe-unmask-data password))
:success-event ::import-multiaccount-success}})))) :success-event ::import-multiaccount-success}}))))
(fx/defn seed-phrase-next-pressed (rf/defn seed-phrase-next-pressed
{:events [:multiaccounts.recover/enter-phrase-next-pressed]} {:events [:multiaccounts.recover/enter-phrase-next-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [passphrase]} (:intro-wizard db)] (let [{:keys [passphrase]} (:intro-wizard db)]
{::multiaccounts/validate-mnemonic [passphrase #(re-frame/dispatch [:multiaccounts.recover/phrase-validated %])]})) {::multiaccounts/validate-mnemonic [passphrase #(re-frame/dispatch [:multiaccounts.recover/phrase-validated %])]}))
(fx/defn continue-to-import-mnemonic (rf/defn continue-to-import-mnemonic
{:events [::continue-pressed]} {:events [::continue-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [password passphrase]} (:multiaccounts/recover db)] (let [{:keys [password passphrase]} (:multiaccounts/recover db)]
(fx/merge cofx (rf/merge cofx
{::import-multiaccount {:passphrase passphrase {::import-multiaccount {:passphrase passphrase
:password password :password password
:success-event ::import-multiaccount-success}} :success-event ::import-multiaccount-success}}
(popover/hide-popover)))) (popover/hide-popover))))
(fx/defn dec-step (rf/defn dec-step
{:events [:multiaccounts.recover/dec-step]} {:events [:multiaccounts.recover/dec-step]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [step (get-in db [:intro-wizard :step])] (let [step (get-in db [:intro-wizard :step])]
@@ -195,7 +195,7 @@
:confirm-failure? false :confirm-failure? false
:key-code nil)}))) :key-code nil)})))
(fx/defn cancel-pressed (rf/defn cancel-pressed
{:events [:multiaccounts.recover/cancel-pressed]} {:events [:multiaccounts.recover/cancel-pressed]}
[{:keys [db] :as cofx} skip-alert?] [{:keys [db] :as cofx} skip-alert?]
;; Workaround for multiple Cancel button clicks ;; Workaround for multiple Cancel button clicks
@@ -207,11 +207,11 @@
(i18n/label :t/are-you-sure-to-cancel) (i18n/label :t/are-you-sure-to-cancel)
(i18n/label :t/you-will-start-from-scratch) (i18n/label :t/you-will-start-from-scratch)
#(re-frame/dispatch [:multiaccounts.recover/cancel-pressed true])) #(re-frame/dispatch [:multiaccounts.recover/cancel-pressed true]))
(fx/merge cofx (rf/merge cofx
dec-step dec-step
navigation/navigate-back))))) navigation/navigate-back)))))
(fx/defn select-storage-next-pressed (rf/defn select-storage-next-pressed
{:events [:multiaccounts.recover/select-storage-next-pressed] {:events [:multiaccounts.recover/select-storage-next-pressed]
:interceptors [(re-frame/inject-cofx :random-guid-generator)]} :interceptors [(re-frame/inject-cofx :random-guid-generator)]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
@@ -219,14 +219,14 @@
(if (= storage-type :advanced) (if (= storage-type :advanced)
;;TODO: fix circular dependency to remove dispatch here ;;TODO: fix circular dependency to remove dispatch here
{:dispatch [:recovery.ui/keycard-option-pressed]} {:dispatch [:recovery.ui/keycard-option-pressed]}
(fx/merge cofx (rf/merge cofx
{:db (update db :intro-wizard assoc :step :create-code)} {:db (update db :intro-wizard assoc :step :create-code)}
(navigation/navigate-to-cofx :create-password nil))))) (navigation/navigate-to-cofx :create-password nil)))))
(fx/defn re-encrypt-pressed (rf/defn re-encrypt-pressed
{:events [:multiaccounts.recover/re-encrypt-pressed]} {:events [:multiaccounts.recover/re-encrypt-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (update db :intro-wizard {:db (update db :intro-wizard
assoc :step :select-key-storage assoc :step :select-key-storage
:selected-storage-type :default)} :selected-storage-type :default)}
@@ -234,34 +234,34 @@
(navigation/navigate-to-cofx :select-key-storage nil) (navigation/navigate-to-cofx :select-key-storage nil)
(select-storage-next-pressed)))) (select-storage-next-pressed))))
(fx/defn confirm-password-next-button-pressed (rf/defn confirm-password-next-button-pressed
{:events [:multiaccounts.recover/enter-password-next-pressed] {:events [:multiaccounts.recover/enter-password-next-pressed]
:interceptors [(re-frame/inject-cofx :random-guid-generator)]} :interceptors [(re-frame/inject-cofx :random-guid-generator)]}
[cofx key-code] [cofx key-code]
(store-multiaccount cofx key-code)) (store-multiaccount cofx key-code))
(fx/defn count-words (rf/defn count-words
[{:keys [db]}] [{:keys [db]}]
(let [passphrase (get-in db [:intro-wizard :passphrase])] (let [passphrase (get-in db [:intro-wizard :passphrase])]
{:db (assoc-in db [:intro-wizard :passphrase-word-count] {:db (assoc-in db [:intro-wizard :passphrase-word-count]
(mnemonic/words-count passphrase))})) (mnemonic/words-count passphrase))}))
(fx/defn run-validation (rf/defn run-validation
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [passphrase (get-in db [:intro-wizard :passphrase])] (let [passphrase (get-in db [:intro-wizard :passphrase])]
(when (= (last passphrase) " ") (when (= (last passphrase) " ")
(fx/merge cofx (rf/merge cofx
(validate-phrase-for-warnings))))) (validate-phrase-for-warnings)))))
(fx/defn enter-phrase-input-changed (rf/defn enter-phrase-input-changed
{:events [:multiaccounts.recover/enter-phrase-input-changed]} {:events [:multiaccounts.recover/enter-phrase-input-changed]}
[cofx input] [cofx input]
(fx/merge cofx (rf/merge cofx
(set-phrase input) (set-phrase input)
(count-words) (count-words)
(run-validation))) (run-validation)))
(fx/defn enter-passphrase-input-changed (rf/defn enter-passphrase-input-changed
{:events [:multiaccounts.recover/enter-passphrase-input-changed]} {:events [:multiaccounts.recover/enter-passphrase-input-changed]}
[{:keys [db]} masked-passphrase] [{:keys [db]} masked-passphrase]
{:db (update db :intro-wizard assoc {:db (update db :intro-wizard assoc
@@ -1,6 +1,6 @@
(ns status-im.multiaccounts.reset-password.core (ns status-im.multiaccounts.reset-password.core
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[clojure.string :as string] [clojure.string :as string]
[status-im.utils.security :as security] [status-im.utils.security :as security]
@@ -9,7 +9,7 @@
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.ethereum.core :as ethereum])) [status-im.ethereum.core :as ethereum]))
(fx/defn on-input-change (rf/defn on-input-change
{:events [::handle-input-change]} {:events [::handle-input-change]}
[{:keys [db]} input-id value] [{:keys [db]} input-id value]
(let [new-password (get-in db [:multiaccount/reset-password-form-vals :new-password]) (let [new-password (get-in db [:multiaccount/reset-password-form-vals :new-password])
@@ -22,23 +22,23 @@
(assoc-in [:multiaccount/reset-password-form-vals input-id] value) (assoc-in [:multiaccount/reset-password-form-vals input-id] value)
(assoc-in [:multiaccount/reset-password-errors input-id] error))})) (assoc-in [:multiaccount/reset-password-errors input-id] error))}))
(fx/defn clear-form-vals (rf/defn clear-form-vals
{:events [::clear-form-vals]} {:events [::clear-form-vals]}
[{:keys [db]}] [{:keys [db]}]
{:db (dissoc db :multiaccount/reset-password-form-vals :multiaccount/reset-password-errors)}) {:db (dissoc db :multiaccount/reset-password-form-vals :multiaccount/reset-password-errors)})
(fx/defn set-current-password-error (rf/defn set-current-password-error
{:events [::handle-verification-error ::password-reset-error]} {:events [::handle-verification-error ::password-reset-error]}
[{:keys [db]} error] [{:keys [db]} error]
{:db (assoc-in db [:multiaccount/reset-password-errors :current-password] error)}) {:db (assoc-in db [:multiaccount/reset-password-errors :current-password] error)})
(fx/defn password-reset-success (rf/defn password-reset-success
{:events [::password-reset-success]} {:events [::password-reset-success]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [key-uid]} (:multiaccount db) (let [{:keys [key-uid]} (:multiaccount db)
auth-method (get db :auth-method keychain/auth-method-none) auth-method (get db :auth-method keychain/auth-method-none)
new-password (get-in db [:multiaccount/reset-password-form-vals :new-password])] new-password (get-in db [:multiaccount/reset-password-form-vals :new-password])]
(fx/merge cofx (rf/merge cofx
{:db (dissoc {:db (dissoc
db db
:multiaccount/reset-password-form-vals :multiaccount/reset-password-form-vals
@@ -64,11 +64,11 @@
(ethereum/sha3 (security/safe-unmask-data new-password)) (ethereum/sha3 (security/safe-unmask-data new-password))
change-db-password-cb))) change-db-password-cb)))
(fx/defn handle-verification-success (rf/defn handle-verification-success
{:events [::handle-verification-success]} {:events [::handle-verification-success]}
[{:keys [db] :as cofx} form-vals] [{:keys [db] :as cofx} form-vals]
(let [{:keys [key-uid name]} (:multiaccount db)] (let [{:keys [key-uid name]} (:multiaccount db)]
(fx/merge cofx (rf/merge cofx
{::change-db-password [key-uid form-vals] {::change-db-password [key-uid form-vals]
:db (assoc db :db (assoc db
:multiaccount/resetting-password? true)} :multiaccount/resetting-password? true)}
@@ -88,7 +88,7 @@
(status/verify address hashed-pass (status/verify address hashed-pass
(partial handle-verification form-vals))))) (partial handle-verification form-vals)))))
(fx/defn reset (rf/defn reset
{:events [::reset]} {:events [::reset]}
[{:keys [db]} form-vals] [{:keys [db]} form-vals]
{::validate-current-password-and-reset {::validate-current-password-and-reset
+11 -11
View File
@@ -1,18 +1,18 @@
(ns status-im.multiaccounts.update.core (ns status-im.multiaccounts.update.core
(:require [status-im.constants :as constants] (:require [status-im.constants :as constants]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(fx/defn send-multiaccount-update [{:keys [db] :as cofx}] (rf/defn send-multiaccount-update [{:keys [db] :as cofx}]
(let [multiaccount (:multiaccount db) (let [multiaccount (:multiaccount db)
{:keys [name preferred-name address]} multiaccount] {:keys [name preferred-name address]} multiaccount]
{::json-rpc/call [{:method "wakuext_sendContactUpdates" {::json-rpc/call [{:method "wakuext_sendContactUpdates"
:params [(or preferred-name name) ""] :params [(or preferred-name name) ""]
:on-success #(log/debug "sent contact update")}]})) :on-success #(log/debug "sent contact update")}]}))
(fx/defn multiaccount-update (rf/defn multiaccount-update
"Takes effects (containing :db) + new multiaccount fields, adds all effects necessary for multiaccount update. "Takes effects (containing :db) + new multiaccount fields, adds all effects necessary for multiaccount update.
Optionally, one can specify a success-event to be dispatched after fields are persisted." Optionally, one can specify a success-event to be dispatched after fields are persisted."
[{:keys [db] :as cofx} [{:keys [db] :as cofx}
@@ -23,7 +23,7 @@
;; NOTE: this should never happen, but if it does this is a critical error ;; NOTE: this should never happen, but if it does this is a critical error
;; and it is better to crash than risk having an unstable state ;; and it is better to crash than risk having an unstable state
(throw (js/Error. "Please shake the phone to report this error and restart the app. multiaccount is currently empty, which means something went wrong when trying to update it with")) (throw (js/Error. "Please shake the phone to report this error and restart the app. multiaccount is currently empty, which means something went wrong when trying to update it with"))
(fx/merge cofx (rf/merge cofx
{:db (if setting-value {:db (if setting-value
(assoc-in db [:multiaccount setting] setting-value) (assoc-in db [:multiaccount setting] setting-value)
(update db :multiaccount dissoc setting)) (update db :multiaccount dissoc setting))
@@ -35,7 +35,7 @@
(#{:name :prefered-name} setting)) (#{:name :prefered-name} setting))
(send-multiaccount-update)))))) (send-multiaccount-update))))))
(fx/defn clean-seed-phrase (rf/defn clean-seed-phrase
"A helper function that removes seed phrase from storage." "A helper function that removes seed phrase from storage."
[cofx on-success] [cofx on-success]
(multiaccount-update cofx :mnemonic nil on-success)) (multiaccount-update cofx :mnemonic nil on-success))
@@ -51,7 +51,7 @@
(:url))) (:url)))
synced-stickers)) synced-stickers))
(fx/defn optimistic (rf/defn optimistic
[{:keys [db] :as cofx} setting setting-value] [{:keys [db] :as cofx} setting setting-value]
(let [current-multiaccount (:multiaccount db) (let [current-multiaccount (:multiaccount db)
setting-value (if (= :currency setting) setting-value (if (= :currency setting)
@@ -73,9 +73,9 @@
(assoc-in db [:multiaccount setting] setting-value) (assoc-in db [:multiaccount setting] setting-value)
(update db :multiaccount dissoc setting))})) (update db :multiaccount dissoc setting))}))
(fx/defn set-many-js (rf/defn set-many-js
[cofx settings-js] [cofx settings-js]
(apply fx/merge (apply rf/merge
cofx cofx
(map (map
#(optimistic #(optimistic
@@ -83,15 +83,15 @@
(.-value %)) (.-value %))
settings-js))) settings-js)))
(fx/defn toggle-backup-enabled (rf/defn toggle-backup-enabled
{:events [:multiaccounts.ui/switch-backup-enabled]} {:events [:multiaccounts.ui/switch-backup-enabled]}
[cofx enabled?] [cofx enabled?]
(multiaccount-update cofx :backup-enabled? enabled? {})) (multiaccount-update cofx :backup-enabled? enabled? {}))
(fx/defn toggle-opensea-nfts-visibility (rf/defn toggle-opensea-nfts-visibility
{:events [::toggle-opensea-nfts-visiblity]} {:events [::toggle-opensea-nfts-visiblity]}
[cofx visible?] [cofx visible?]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in (:db cofx) [:multiaccount :opensea-enabled?] visible?) {:db (assoc-in (:db cofx) [:multiaccount :opensea-enabled?] visible?)
;; need to add fully qualified namespace to counter circular deps ;; need to add fully qualified namespace to counter circular deps
:dispatch [:status-im.wallet.core/fetch-collectibles-collection]} :dispatch [:status-im.wallet.core/fetch-collectibles-collection]}
+3 -3
View File
@@ -13,7 +13,7 @@
[status-im.ui.components.icons.icons :as icons] [status-im.ui.components.icons.icons :as icons]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[status-im.ui.screens.views :as views] [status-im.ui.screens.views :as views]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
@@ -182,7 +182,7 @@
(reset! state/root-id @state/root-comp-id) (reset! state/root-id @state/root-comp-id)
(.setRoot Navigation (clj->js (get (roots/roots) new-root-id))))) (.setRoot Navigation (clj->js (get (roots/roots) new-root-id)))))
(fx/defn set-multiaccount-root (rf/defn set-multiaccount-root
{:events [::set-multiaccount-root]} {:events [::set-multiaccount-root]}
[{:keys [db]}] [{:keys [db]}]
(log/debug :set-multiaccounts-root) (log/debug :set-multiaccounts-root)
@@ -426,7 +426,7 @@
;; change view-id if it is still same after component is disappeared ;; change view-id if it is still same after component is disappeared
;; https://github.com/wix/react-native-navigation/issues/5744#issuecomment-563226820 ;; https://github.com/wix/react-native-navigation/issues/5744#issuecomment-563226820
(fx/defn view-disappeared (rf/defn view-disappeared
{:events [::view-disappeared]} {:events [::view-disappeared]}
[{:keys [db]} view-id] [{:keys [db]} view-id]
(when (= view-id (:view-id db)) (when (= view-id (:view-id db))
+12 -12
View File
@@ -6,7 +6,7 @@
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.node.core :as node] [status-im.node.core :as node]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.http :as http] [status-im.utils.http :as http]
[status-im.utils.types :as types])) [status-im.utils.types :as types]))
@@ -56,7 +56,7 @@
(defn get-network [{:keys [db]} network-id] (defn get-network [{:keys [db]} network-id]
(get-in db [:networks/networks network-id])) (get-in db [:networks/networks network-id]))
(fx/defn set-input (rf/defn set-input
{:events [::input-changed]} {:events [::input-changed]}
[{:keys [db]} input-key value] [{:keys [db]} input-key value]
{:db (-> db {:db (-> db
@@ -64,13 +64,13 @@
(update-in [:networks/manage] validate-manage))}) (update-in [:networks/manage] validate-manage))})
;; No edit functionality actually implemented ;; No edit functionality actually implemented
(fx/defn edit (rf/defn edit
{:events [::add-network-pressed]} {:events [::add-network-pressed]}
[{db :db}] [{db :db}]
{:db (assoc db :networks/manage (validate-manage default-manage)) {:db (assoc db :networks/manage (validate-manage default-manage))
:dispatch [:navigate-to :edit-network]}) :dispatch [:navigate-to :edit-network]})
(fx/defn connect-success (rf/defn connect-success
{:events [::connect-success]} {:events [::connect-success]}
[_ network-id] [_ network-id]
{:ui/show-confirmation {:ui/show-confirmation
@@ -80,14 +80,14 @@
:on-accept #(re-frame/dispatch [::save-network-settings-pressed network-id]) :on-accept #(re-frame/dispatch [::save-network-settings-pressed network-id])
:on-cancel nil}}) :on-cancel nil}})
(fx/defn connect-failure (rf/defn connect-failure
{:events [::connect-failure]} {:events [::connect-failure]}
[_ reason] [_ reason]
{:utils/show-popup {:utils/show-popup
{:title (i18n/label :t/error) {:title (i18n/label :t/error)
:content (str reason)}}) :content (str reason)}})
(fx/defn connect (rf/defn connect
{:events [::connect-network-pressed]} {:events [::connect-network-pressed]}
[{:keys [db] :as cofx} network-id] [{:keys [db] :as cofx} network-id]
(if-let [config (get-in db [:networks/networks network-id :config])] (if-let [config (get-in db [:networks/networks network-id :config])]
@@ -115,7 +115,7 @@
(connect-success cofx network-id)) (connect-success cofx network-id))
(connect-failure cofx "A network with the specified id doesn't exist"))) (connect-failure cofx "A network with the specified id doesn't exist")))
(fx/defn delete (rf/defn delete
{:events [::delete-network-pressed]} {:events [::delete-network-pressed]}
[{:keys [db]} network] [{:keys [db]} network]
(let [current-network? (= (:networks/current-network db) network)] (let [current-network? (= (:networks/current-network db) network)]
@@ -128,17 +128,17 @@
:on-accept #(re-frame/dispatch [::remove-network-confirmed network]) :on-accept #(re-frame/dispatch [::remove-network-confirmed network])
:on-cancel nil}}))) :on-cancel nil}})))
(fx/defn save-network-settings (rf/defn save-network-settings
{:events [::save-network-settings-pressed]} {:events [::save-network-settings-pressed]}
[{:keys [db] :as cofx} network] [{:keys [db] :as cofx} network]
(fx/merge cofx (rf/merge cofx
{:db (assoc db :networks/current-network network) {:db (assoc db :networks/current-network network)
::json-rpc/call [{:method "settings_saveSetting" ::json-rpc/call [{:method "settings_saveSetting"
:params [:networks/current-network network] :params [:networks/current-network network]
:on-success #()}]} :on-success #()}]}
(node/prepare-new-config {:on-success #(re-frame/dispatch [:logout])}))) (node/prepare-new-config {:on-success #(re-frame/dispatch [:logout])})))
(fx/defn remove-network (rf/defn remove-network
{:events [::remove-network-confirmed]} {:events [::remove-network-confirmed]}
[{:keys [db] :as cofx} network] [{:keys [db] :as cofx} network]
(let [networks (dissoc (:networks/networks db) network)] (let [networks (dissoc (:networks/networks db) network)]
@@ -160,7 +160,7 @@
:symbol symbol :symbol symbol
:config config})) :config config}))
(fx/defn save (rf/defn save
{:events [::save-network-pressed] {:events [::save-network-pressed]
:interceptors [(re-frame/inject-cofx :random-id-generator)]} :interceptors [(re-frame/inject-cofx :random-id-generator)]}
[{{:networks/keys [manage networks] :as db} :db [{{:networks/keys [manage networks] :as db} :db
@@ -188,7 +188,7 @@
{:ui/show-error "chain-id already defined"})) {:ui/show-error "chain-id already defined"}))
{:ui/show-error "invalid network parameters"})) {:ui/show-error "invalid network parameters"}))
(fx/defn open-network-details (rf/defn open-network-details
{:events [::network-entry-pressed]} {:events [::network-entry-pressed]}
[cofx network] [cofx network]
(navigation/navigate-to-cofx cofx :network-details {:networks/selected-network network})) (navigation/navigate-to-cofx cofx :network-details {:networks/selected-network network}))
+7 -7
View File
@@ -2,14 +2,14 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.mobile-sync-settings.core :as mobile-network] [status-im.mobile-sync-settings.core :as mobile-network]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.wallet.core :as wallet] [status-im.wallet.core :as wallet]
["@react-native-community/netinfo" :default net-info] ["@react-native-community/netinfo" :default net-info]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(fx/defn change-network-status (rf/defn change-network-status
[{:keys [db] :as cofx} is-connected?] [{:keys [db] :as cofx} is-connected?]
(fx/merge cofx (rf/merge cofx
{:db (assoc db :network-status (if is-connected? :online :offline))} {:db (assoc db :network-status (if is-connected? :online :offline))}
(when (and is-connected? (when (and is-connected?
(or (not= (count (get-in db [:wallet :accounts])) (or (not= (count (get-in db [:wallet :accounts]))
@@ -17,14 +17,14 @@
(wallet/has-empty-balances? db))) (wallet/has-empty-balances? db)))
(wallet/update-balances nil nil)))) (wallet/update-balances nil nil))))
(fx/defn change-network-type (rf/defn change-network-type
[{:keys [db] :as cofx} old-network-type network-type expensive?] [{:keys [db] :as cofx} old-network-type network-type expensive?]
(fx/merge cofx (rf/merge cofx
{:db (assoc db :network/type network-type) {:db (assoc db :network/type network-type)
:network/notify-status-go [network-type expensive?]} :network/notify-status-go [network-type expensive?]}
(mobile-network/on-network-status-change))) (mobile-network/on-network-status-change)))
(fx/defn handle-network-info-change (rf/defn handle-network-info-change
{:events [::network-info-changed]} {:events [::network-info-changed]}
[{:keys [db] :as cofx} {:keys [isConnected type details] :as state}] [{:keys [db] :as cofx} {:keys [isConnected type details] :as state}]
(let [old-network-status (:network-status db) (let [old-network-status (:network-status db)
@@ -38,7 +38,7 @@
"connectivity-status" connectivity-status "connectivity-status" connectivity-status
"type" type "type" type
"details" details) "details" details)
(fx/merge cofx (rf/merge cofx
(when-not status-changed? (when-not status-changed?
(change-network-status isConnected)) (change-network-status isConnected))
(when-not type-changed? (when-not type-changed?
+3 -3
View File
@@ -3,7 +3,7 @@
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.platform :as utils.platform] [status-im.utils.platform :as utils.platform]
[status-im.utils.types :as types])) [status-im.utils.types :as types]))
@@ -173,7 +173,7 @@
[db] [db]
(types/clj->json (get-multiaccount-node-config db))) (types/clj->json (get-multiaccount-node-config db)))
(fx/defn save-new-config (rf/defn save-new-config
"Saves a new status-go config for the current account "Saves a new status-go config for the current account
This RPC method is the only way to change the node config of an account. This RPC method is the only way to change the node config of an account.
NOTE: it is better used indirectly through `prepare-new-config`, NOTE: it is better used indirectly through `prepare-new-config`,
@@ -185,7 +185,7 @@ app-db"
:params [:node-config config] :params [:node-config config]
:on-success on-success}]}) :on-success on-success}]})
(fx/defn prepare-new-config (rf/defn prepare-new-config
"Use this function to apply settings to the current account node config" "Use this function to apply settings to the current account node config"
[{:keys [db]} {:keys [on-success]}] [{:keys [db]} {:keys [on-success]}]
(let [key-uid (get-in db [:multiaccount :key-uid])] (let [key-uid (get-in db [:multiaccount :key-uid])]
+26 -26
View File
@@ -1,7 +1,7 @@
(ns status-im.notifications.core (ns status-im.notifications.core
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
["@react-native-community/push-notification-ios" :default pn-ios] ["@react-native-community/push-notification-ios" :default pn-ios]
[status-im.notifications.android :as pn-android] [status-im.notifications.android :as pn-android]
@@ -59,7 +59,7 @@
::request-permission ::request-permission
identity) identity)
(fx/defn request-permission (rf/defn request-permission
{:events [::request-permission]} {:events [::request-permission]}
[_] [_]
{::request-permission true}) {::request-permission true})
@@ -103,7 +103,7 @@
(doseq [chat-id chat-ids] (doseq [chat-id chat-ids]
(pn-android/clear-message-notifications chat-id)))))) (pn-android/clear-message-notifications chat-id))))))
(fx/defn handle-enable-notifications-event (rf/defn handle-enable-notifications-event
{:events [:notifications/registered-for-push-notifications]} {:events [:notifications/registered-for-push-notifications]}
[cofx token] [cofx token]
{::json-rpc/call [{:method "wakuext_registerForPushNotifications" {::json-rpc/call [{:method "wakuext_registerForPushNotifications"
@@ -111,7 +111,7 @@
:on-success #(log/info "[push-notifications] register-success" %) :on-success #(log/info "[push-notifications] register-success" %)
:on-error #(re-frame/dispatch [:notifications/switch-error true %])}]}) :on-error #(re-frame/dispatch [:notifications/switch-error true %])}]})
(fx/defn handle-disable-notifications-event (rf/defn handle-disable-notifications-event
{:events [:notifications/unregistered-from-push-notifications]} {:events [:notifications/unregistered-from-push-notifications]}
[cofx] [cofx]
{::json-rpc/call [{:method "wakuext_unregisterFromPushNotifications" {::json-rpc/call [{:method "wakuext_unregisterFromPushNotifications"
@@ -119,7 +119,7 @@
:on-success #(log/info "[push-notifications] unregister-success" %) :on-success #(log/info "[push-notifications] unregister-success" %)
:on-error #(re-frame/dispatch [:notifications/switch-error false %])}]}) :on-error #(re-frame/dispatch [:notifications/switch-error false %])}]})
(fx/defn logout-disable (rf/defn logout-disable
[cofx] [cofx]
(merge {::logout-disable nil} (merge {::logout-disable nil}
{::json-rpc/call [{:method "wakuext_unregisterFromPushNotifications" {::json-rpc/call [{:method "wakuext_unregisterFromPushNotifications"
@@ -127,16 +127,16 @@
:on-success #(log/info "[push-notifications] unregister-success" %) :on-success #(log/info "[push-notifications] unregister-success" %)
:on-error #(log/info "[push-notifications] unregister-error" %)}]})) :on-error #(log/info "[push-notifications] unregister-error" %)}]}))
(fx/defn notification-switch-error (rf/defn notification-switch-error
{:events [:notifications/switch-error]} {:events [:notifications/switch-error]}
[cofx enabled?] [cofx enabled?]
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
cofx :remote-push-notifications-enabled? (not enabled?) {})) cofx :remote-push-notifications-enabled? (not enabled?) {}))
(fx/defn notification-switch (rf/defn notification-switch
{:events [::switch]} {:events [::switch]}
[{:keys [db] :as cofx} enabled? remote-push-notifications?] [{:keys [db] :as cofx} enabled? remote-push-notifications?]
(fx/merge cofx (rf/merge cofx
(if enabled? (if enabled?
{::enable remote-push-notifications?} {::enable remote-push-notifications?}
{::disable nil}) {::disable nil})
@@ -145,23 +145,23 @@
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
:notifications-enabled? (and (not remote-push-notifications?) enabled?) {}))) :notifications-enabled? (and (not remote-push-notifications?) enabled?) {})))
(fx/defn notification-non-contacts-error (rf/defn notification-non-contacts-error
{:events [::non-contacts-update-error]} {:events [::non-contacts-update-error]}
[cofx enabled?] [cofx enabled?]
(multiaccounts.update/optimistic cofx :push-notifications-from-contacts-only? (not (boolean enabled?)))) (multiaccounts.update/optimistic cofx :push-notifications-from-contacts-only? (not (boolean enabled?))))
(fx/defn notification-block-mentions-error (rf/defn notification-block-mentions-error
{:events [::block-mentions-update-error]} {:events [::block-mentions-update-error]}
[cofx enabled?] [cofx enabled?]
(multiaccounts.update/optimistic cofx :push-notifications-block-mentions? (not (boolean enabled?)))) (multiaccounts.update/optimistic cofx :push-notifications-block-mentions? (not (boolean enabled?))))
(fx/defn notification-non-contacts (rf/defn notification-non-contacts
{:events [::switch-non-contacts]} {:events [::switch-non-contacts]}
[{:keys [db] :as cofx} enabled?] [{:keys [db] :as cofx} enabled?]
(let [method (if enabled? (let [method (if enabled?
"wakuext_enablePushNotificationsFromContactsOnly" "wakuext_enablePushNotificationsFromContactsOnly"
"wakuext_disablePushNotificationsFromContactsOnly")] "wakuext_disablePushNotificationsFromContactsOnly")]
(fx/merge cofx (rf/merge cofx
{::json-rpc/call [{:method method {::json-rpc/call [{:method method
:params [] :params []
:on-success #(log/info "[push-notifications] contacts-notification-success" %) :on-success #(log/info "[push-notifications] contacts-notification-success" %)
@@ -169,14 +169,14 @@
(multiaccounts.update/optimistic :push-notifications-from-contacts-only? (boolean enabled?))))) (multiaccounts.update/optimistic :push-notifications-from-contacts-only? (boolean enabled?)))))
(fx/defn notification-block-mentions (rf/defn notification-block-mentions
{:events [::switch-block-mentions]} {:events [::switch-block-mentions]}
[{:keys [db] :as cofx} enabled?] [{:keys [db] :as cofx} enabled?]
(let [method (if enabled? (let [method (if enabled?
"wakuext_enablePushNotificationsBlockMentions" "wakuext_enablePushNotificationsBlockMentions"
"wakuext_disablePushNotificationsBlockMentions")] "wakuext_disablePushNotificationsBlockMentions")]
(log/info "USING METHOD" method enabled?) (log/info "USING METHOD" method enabled?)
(fx/merge cofx (rf/merge cofx
{::json-rpc/call [{:method method {::json-rpc/call [{:method method
:params [] :params []
:on-success #(log/info "[push-notifications] block-mentions-success" %) :on-success #(log/info "[push-notifications] block-mentions-success" %)
@@ -184,13 +184,13 @@
(multiaccounts.update/optimistic :push-notifications-block-mentions? (boolean enabled?))))) (multiaccounts.update/optimistic :push-notifications-block-mentions? (boolean enabled?)))))
(fx/defn switch-push-notifications-server-enabled (rf/defn switch-push-notifications-server-enabled
{:events [::switch-push-notifications-server-enabled]} {:events [::switch-push-notifications-server-enabled]}
[{:keys [db] :as cofx} enabled?] [{:keys [db] :as cofx} enabled?]
(let [method (if enabled? (let [method (if enabled?
"wakuext_startPushNotificationsServer" "wakuext_startPushNotificationsServer"
"wakuext_stopPushNotificationsServer")] "wakuext_stopPushNotificationsServer")]
(fx/merge cofx (rf/merge cofx
{::json-rpc/call [{:method method {::json-rpc/call [{:method method
:params [] :params []
:on-success #(log/info "[push-notifications] switch-server-enabled successful" %) :on-success #(log/info "[push-notifications] switch-server-enabled successful" %)
@@ -198,13 +198,13 @@
(multiaccounts.update/optimistic :push-notifications-server-enabled? (boolean enabled?))))) (multiaccounts.update/optimistic :push-notifications-server-enabled? (boolean enabled?)))))
(fx/defn switch-send-notifications (rf/defn switch-send-notifications
{:events [::switch-send-push-notifications]} {:events [::switch-send-push-notifications]}
[{:keys [db] :as cofx} enabled?] [{:keys [db] :as cofx} enabled?]
(let [method (if enabled? (let [method (if enabled?
"wakuext_enableSendingNotifications" "wakuext_enableSendingNotifications"
"wakuext_disableSendingNotifications")] "wakuext_disableSendingNotifications")]
(fx/merge cofx (rf/merge cofx
{::json-rpc/call [{:method method {::json-rpc/call [{:method method
:params [] :params []
:on-success #(log/info "[push-notifications] switch-send-notifications successful" %) :on-success #(log/info "[push-notifications] switch-send-notifications successful" %)
@@ -212,15 +212,15 @@
(multiaccounts.update/optimistic :send-push-notifications? (boolean enabled?))))) (multiaccounts.update/optimistic :send-push-notifications? (boolean enabled?)))))
(fx/defn handle-add-server-error (rf/defn handle-add-server-error
{:events [::push-notifications-add-server-error]} {:events [::push-notifications-add-server-error]}
[_ public-key error] [_ public-key error]
(log/error "failed to add server", public-key, error)) (log/error "failed to add server", public-key, error))
(fx/defn add-server (rf/defn add-server
{:events [::add-server]} {:events [::add-server]}
[{:keys [db] :as cofx} public-key] [{:keys [db] :as cofx} public-key]
(fx/merge cofx (rf/merge cofx
{::json-rpc/call [{:method "wakuext_addPushNotificationsServer" {::json-rpc/call [{:method "wakuext_addPushNotificationsServer"
:params [public-key] :params [public-key]
:on-success #(do :on-success #(do
@@ -228,12 +228,12 @@
(re-frame/dispatch [::fetch-servers])) (re-frame/dispatch [::fetch-servers]))
:on-error #(re-frame/dispatch [::push-notifications-add-server-error public-key %])}]})) :on-error #(re-frame/dispatch [::push-notifications-add-server-error public-key %])}]}))
(fx/defn handle-servers-fetched (rf/defn handle-servers-fetched
{:events [::servers-fetched]} {:events [::servers-fetched]}
[{:keys [db]} servers] [{:keys [db]} servers]
{:db (assoc db :push-notifications/servers (map server<-rpc servers))}) {:db (assoc db :push-notifications/servers (map server<-rpc servers))})
(fx/defn fetch-push-notifications-servers (rf/defn fetch-push-notifications-servers
{:events [::fetch-servers]} {:events [::fetch-servers]}
[cofx] [cofx]
{::json-rpc/call [{:method "wakuext_getPushNotificationsServers" {::json-rpc/call [{:method "wakuext_getPushNotificationsServers"
@@ -244,12 +244,12 @@
;; Wallet transactions ;; Wallet transactions
(fx/defn handle-preferences-load (rf/defn handle-preferences-load
{:events [::preferences-loaded]} {:events [::preferences-loaded]}
[{:keys [db]} preferences] [{:keys [db]} preferences]
{:db (assoc db :push-notifications/preferences preferences)}) {:db (assoc db :push-notifications/preferences preferences)})
(fx/defn load-notification-preferences (rf/defn load-notification-preferences
{:events [::load-notification-preferences]} {:events [::load-notification-preferences]}
[cofx] [cofx]
{::json-rpc/call [{:method "localnotifications_notificationPreferences" {::json-rpc/call [{:method "localnotifications_notificationPreferences"
@@ -264,7 +264,7 @@
(defn- update-preference [all new] (defn- update-preference [all new]
(conj (filter (comp not (partial preference= new)) all) new)) (conj (filter (comp not (partial preference= new)) all) new))
(fx/defn switch-transaction-notifications (rf/defn switch-transaction-notifications
{:events [::switch-transaction-notifications]} {:events [::switch-transaction-notifications]}
[{:keys [db] :as cofx} enabled?] [{:keys [db] :as cofx} enabled?]
{:db (update db :push-notifications/preferences update-preference {:enabled (not enabled?) {:db (update db :push-notifications/preferences update-preference {:enabled (not enabled?)
+3 -3
View File
@@ -1,6 +1,6 @@
(ns status-im.notifications.local (ns status-im.notifications.local
(:require [status-im.async-storage.core :as async-storage] (:require [status-im.async-storage.core :as async-storage]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.ethereum.decode :as decode] [status-im.ethereum.decode :as decode]
["@react-native-community/push-notification-ios" :default pn-ios] ["@react-native-community/push-notification-ios" :default pn-ios]
[status-im.notifications.android :as pn-android] [status-im.notifications.android :as pn-android]
@@ -120,14 +120,14 @@
(fn [evt] (fn [evt]
(-> evt create-notification local-push-ios))) (-> evt create-notification local-push-ios)))
(fx/defn local-notification-android (rf/defn local-notification-android
{:events [::local-notification-android]} {:events [::local-notification-android]}
[cofx event] [cofx event]
(some->> event (some->> event
(create-notification cofx) (create-notification cofx)
local-push-android)) local-push-android))
(fx/defn process (rf/defn process
[cofx evt] [cofx evt]
(if platform/ios? (if platform/ios?
{::local-push-ios evt} {::local-push-ios evt}
+20 -20
View File
@@ -4,7 +4,7 @@
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.platform :as utils.platform] [status-im.utils.platform :as utils.platform]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.multiaccounts.update.core :as multiaccounts.update])) [status-im.multiaccounts.update.core :as multiaccounts.update]))
@@ -52,26 +52,26 @@
[our-installation-id installations] [our-installation-id installations]
(sort (partial compare-installation our-installation-id) installations)) (sort (partial compare-installation our-installation-id) installations))
(fx/defn send-pair-installation (rf/defn send-pair-installation
{:events [:pairing.ui/pair-devices-pressed]} {:events [:pairing.ui/pair-devices-pressed]}
[_] [_]
{::json-rpc/call [{:method "wakuext_sendPairInstallation" {::json-rpc/call [{:method "wakuext_sendPairInstallation"
:params [] :params []
:on-success #(log/info "sent pair installation message")}]}) :on-success #(log/info "sent pair installation message")}]})
(fx/defn prompt-dismissed (rf/defn prompt-dismissed
{:events [:pairing.ui/prompt-dismissed]} {:events [:pairing.ui/prompt-dismissed]}
[{:keys [db]}] [{:keys [db]}]
{:db (assoc-in db [:pairing/prompt-user-pop-up] false)}) {:db (assoc-in db [:pairing/prompt-user-pop-up] false)})
(fx/defn prompt-accepted (rf/defn prompt-accepted
{:events [:pairing.ui/prompt-accepted]} {:events [:pairing.ui/prompt-accepted]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:pairing/prompt-user-pop-up] false)} {:db (assoc-in db [:pairing/prompt-user-pop-up] false)}
(navigation/navigate-to-cofx :installations nil))) (navigation/navigate-to-cofx :installations nil)))
(fx/defn prompt-user-on-new-installation [{:keys [db]}] (rf/defn prompt-user-on-new-installation [{:keys [db]}]
(when-not config/pairing-popup-disabled? (when-not config/pairing-popup-disabled?
{:db (assoc-in db [:pairing/prompt-user-pop-up] true) {:db (assoc-in db [:pairing/prompt-user-pop-up] true)
:ui/show-confirmation {:title (i18n/label :t/pairing-new-installation-detected-title) :ui/show-confirmation {:title (i18n/label :t/pairing-new-installation-detected-title)
@@ -81,7 +81,7 @@
:on-cancel #(re-frame/dispatch [:pairing.ui/prompt-dismissed]) :on-cancel #(re-frame/dispatch [:pairing.ui/prompt-dismissed])
:on-accept #(re-frame/dispatch [:pairing.ui/prompt-accepted])}})) :on-accept #(re-frame/dispatch [:pairing.ui/prompt-accepted])}}))
(fx/defn set-name (rf/defn set-name
"Set the name of the device" "Set the name of the device"
{:events [:pairing.ui/set-name-pressed]} {:events [:pairing.ui/set-name-pressed]}
[{:keys [db]} installation-name] [{:keys [db]} installation-name]
@@ -90,15 +90,15 @@
{:name installation-name {:name installation-name
:deviceType utils.platform/os}]})) :deviceType utils.platform/os}]}))
(fx/defn init [cofx] (rf/defn init [cofx]
{:pairing/get-our-installations nil}) {:pairing/get-our-installations nil})
(fx/defn enable [{:keys [db]} installation-id] (rf/defn enable [{:keys [db]} installation-id]
{:db (assoc-in db {:db (assoc-in db
[:pairing/installations installation-id :enabled?] [:pairing/installations installation-id :enabled?]
true)}) true)})
(fx/defn disable [{:keys [db]} installation-id] (rf/defn disable [{:keys [db]} installation-id]
{:db (assoc-in db {:db (assoc-in db
[:pairing/installations installation-id :enabled?] [:pairing/installations installation-id :enabled?]
false)}) false)})
@@ -145,7 +145,7 @@
(defn get-our-installations [] (defn get-our-installations []
(get-our-installations-rpc handle-get-our-installations-response-success nil)) (get-our-installations-rpc handle-get-our-installations-response-success nil))
(fx/defn enable-fx (rf/defn enable-fx
{:events [:pairing.ui/enable-installation-pressed]} {:events [:pairing.ui/enable-installation-pressed]}
[cofx installation-id] [cofx installation-id]
(if (< (count (filter :enabled? (vals (get-in cofx [:db :pairing/installations])))) (inc config/max-installations)) (if (< (count (filter :enabled? (vals (get-in cofx [:db :pairing/installations])))) (inc config/max-installations))
@@ -154,7 +154,7 @@
:content (i18n/label :t/pairing-maximum-number-reached-content)}})) :content (i18n/label :t/pairing-maximum-number-reached-content)}}))
(fx/defn disable-fx (rf/defn disable-fx
{:events [:pairing.ui/disable-installation-pressed]} {:events [:pairing.ui/disable-installation-pressed]}
[_ installation-id] [_ installation-id]
{:pairing/disable-installation [installation-id]}) {:pairing/disable-installation [installation-id]})
@@ -178,7 +178,7 @@
:pairing/get-our-installations :pairing/get-our-installations
get-our-installations) get-our-installations)
(fx/defn send-installation-messages (rf/defn send-installation-messages
{:events [:pairing.ui/synchronize-installation-pressed]} {:events [:pairing.ui/synchronize-installation-pressed]}
[{:keys [db]}] [{:keys [db]}]
(let [multiaccount (:multiaccount db) (let [multiaccount (:multiaccount db)
@@ -194,7 +194,7 @@
:device-type (:deviceType metadata) :device-type (:deviceType metadata)
:enabled? enabled}) :enabled? enabled})
(fx/defn update-installation (rf/defn update-installation
{:events [:pairing.callback/set-installation-metadata-success]} {:events [:pairing.callback/set-installation-metadata-success]}
[{:keys [db]} installation-id metadata] [{:keys [db]} installation-id metadata]
{:db (update-in db [:pairing/installations installation-id] {:db (update-in db [:pairing/installations installation-id]
@@ -203,14 +203,14 @@
:name (:name metadata) :name (:name metadata)
:device-type (:deviceType metadata))}) :device-type (:deviceType metadata))})
(fx/defn handle-installations [{:keys [db]} installations] (rf/defn handle-installations [{:keys [db]} installations]
{:db (update db :pairing/installations #(reduce {:db (update db :pairing/installations #(reduce
(fn [acc {:keys [id] :as i}] (fn [acc {:keys [id] :as i}]
(update acc id merge (installation<-rpc i))) (update acc id merge (installation<-rpc i)))
% %
installations))}) installations))})
(fx/defn load-installations (rf/defn load-installations
{:events [:pairing.callback/get-our-installations-success]} {:events [:pairing.callback/get-our-installations-success]}
[{:keys [db]} installations] [{:keys [db]} installations]
{:db (assoc db :pairing/installations (reduce {:db (assoc db :pairing/installations (reduce
@@ -220,16 +220,16 @@
{} {}
installations))}) installations))})
(fx/defn enable-installation-success (rf/defn enable-installation-success
{:events [:pairing.callback/enable-installation-success]} {:events [:pairing.callback/enable-installation-success]}
[cofx installation-id] [cofx installation-id]
(fx/merge cofx (rf/merge cofx
(enable installation-id) (enable installation-id)
(multiaccounts.update/send-multiaccount-update))) (multiaccounts.update/send-multiaccount-update)))
(fx/defn disable-installation-success (rf/defn disable-installation-success
{:events [:pairing.callback/disable-installation-success]} {:events [:pairing.callback/disable-installation-success]}
[cofx installation-id] [cofx installation-id]
(fx/merge cofx (rf/merge cofx
(disable installation-id) (disable installation-id)
(multiaccounts.update/send-multiaccount-update))) (multiaccounts.update/send-multiaccount-update)))
+4 -4
View File
@@ -1,7 +1,7 @@
(ns status-im.popover.core (ns status-im.popover.core
(:require [status-im.utils.fx :as fx])) (:require [utils.re-frame :as rf]))
(fx/defn show-popover (rf/defn show-popover
{:events [:show-popover]} {:events [:show-popover]}
[_ value] [_ value]
{:show-popover nil {:show-popover nil
@@ -9,12 +9,12 @@
:dispatch-later [{:ms 250 :dispatch [:show-popover-db value]}] :dispatch-later [{:ms 250 :dispatch [:show-popover-db value]}]
:dismiss-keyboard nil}) :dismiss-keyboard nil})
(fx/defn show-popover-db (rf/defn show-popover-db
{:events [:show-popover-db]} {:events [:show-popover-db]}
[{:keys [db]} value] [{:keys [db]} value]
{:db (assoc db :popover/popover value)}) {:db (assoc db :popover/popover value)})
(fx/defn hide-popover (rf/defn hide-popover
{:events [:hide-popover]} {:events [:hide-popover]}
[{:keys [db]}] [{:keys [db]}]
{:db (dissoc db :popover/popover) {:db (dissoc db :popover/popover)
+8 -8
View File
@@ -1,6 +1,6 @@
(ns status-im.profile.core (ns status-im.profile.core
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.ui.components.list-selection :as list-selection] [status-im.ui.components.list-selection :as list-selection]
[status-im.utils.universal-links.utils :as universal-links] [status-im.utils.universal-links.utils :as universal-links]
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
@@ -40,19 +40,19 @@
(let [link (universal-links/generate-link :user :external contact-code)] (let [link (universal-links/generate-link :user :external contact-code)]
(list-selection/open-share {:message link})))) (list-selection/open-share {:message link}))))
(fx/defn finish-success (rf/defn finish-success
{:events [:my-profile/finish-success]} {:events [:my-profile/finish-success]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
{:db (update db :my-profile/seed assoc :step :finish :error nil :word nil)}) {:db (update db :my-profile/seed assoc :step :finish :error nil :word nil)})
(fx/defn finish (rf/defn finish
{:events [:my-profile/finish]} {:events [:my-profile/finish]}
[cofx] [cofx]
(multiaccounts.update/clean-seed-phrase (multiaccounts.update/clean-seed-phrase
cofx cofx
{:on-success #(re-frame/dispatch [:my-profile/finish-success])})) {:on-success #(re-frame/dispatch [:my-profile/finish-success])}))
(fx/defn enter-two-random-words (rf/defn enter-two-random-words
{:events [:my-profile/enter-two-random-words]} {:events [:my-profile/enter-two-random-words]}
[{:keys [db]}] [{:keys [db]}]
(let [{:keys [mnemonic]} (:multiaccount db) (let [{:keys [mnemonic]} (:multiaccount db)
@@ -61,22 +61,22 @@
:first-word (first shuffled-mnemonic) :first-word (first shuffled-mnemonic)
:second-word (second shuffled-mnemonic)})})) :second-word (second shuffled-mnemonic)})}))
(fx/defn set-step (rf/defn set-step
{:events [:my-profile/set-step]} {:events [:my-profile/set-step]}
[{:keys [db]} step] [{:keys [db]} step]
{:db (update db :my-profile/seed assoc :step step :error nil :word nil)}) {:db (update db :my-profile/seed assoc :step step :error nil :word nil)})
(fx/defn copy-to-clipboard (rf/defn copy-to-clipboard
{:events [:copy-to-clipboard]} {:events [:copy-to-clipboard]}
[_ value] [_ value]
{:copy-to-clipboard value}) {:copy-to-clipboard value})
(fx/defn show-tooltip (rf/defn show-tooltip
{:events [:show-tooltip]} {:events [:show-tooltip]}
[_ tooltip-id] [_ tooltip-id]
{:show-tooltip tooltip-id}) {:show-tooltip tooltip-id})
(fx/defn share-profile-link (rf/defn share-profile-link
{:events [:profile/share-profile-link]} {:events [:profile/share-profile-link]}
[_ value] [_ value]
{:profile/share-profile-link value}) {:profile/share-profile-link value})
+18 -18
View File
@@ -7,12 +7,12 @@
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.add-new.db :as new-chat.db] [status-im.add-new.db :as new-chat.db]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.group-chats.core :as group-chats] [status-im.group-chats.core :as group-chats]
[clojure.string :as string] [clojure.string :as string]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(fx/defn scan-qr-code (rf/defn scan-qr-code
{:events [::scan-code]} {:events [::scan-code]}
[_ opts] [_ opts]
{:request-permissions-fx {:request-permissions-fx
@@ -24,39 +24,39 @@
(i18n/label :t/camera-access-error)) (i18n/label :t/camera-access-error))
50))}}) 50))}})
(fx/defn set-qr-code (rf/defn set-qr-code
{:events [:qr-scanner.callback/scan-qr-code-success]} {:events [:qr-scanner.callback/scan-qr-code-success]}
[{:keys [db]} opts data] [{:keys [db]} opts data]
(when-let [handler (:handler opts)] (when-let [handler (:handler opts)]
{:dispatch [handler data opts]})) {:dispatch [handler data opts]}))
(fx/defn set-qr-code-cancel (rf/defn set-qr-code-cancel
{:events [:qr-scanner.callback/scan-qr-code-cancel]} {:events [:qr-scanner.callback/scan-qr-code-cancel]}
[cofx opts] [cofx opts]
(fx/merge cofx (rf/merge cofx
(navigation/navigate-back) (navigation/navigate-back)
(when-let [handler (:cancel-handler opts)] (when-let [handler (:cancel-handler opts)]
(fn [] {:dispatch [handler opts]})))) (fn [] {:dispatch [handler opts]}))))
(fx/defn handle-browse [cofx {:keys [url]}] (rf/defn handle-browse [cofx {:keys [url]}]
(fx/merge cofx (rf/merge cofx
{:browser/show-browser-selection url} {:browser/show-browser-selection url}
(navigation/navigate-back))) (navigation/navigate-back)))
(fx/defn handle-private-chat [{:keys [db] :as cofx} {:keys [chat-id]}] (rf/defn handle-private-chat [{:keys [db] :as cofx} {:keys [chat-id]}]
(if-not (new-chat.db/own-public-key? db chat-id) (if-not (new-chat.db/own-public-key? db chat-id)
(chat/start-chat cofx chat-id nil) (chat/start-chat cofx chat-id nil)
{:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code) {:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)
:content (i18n/label :t/can-not-add-yourself)}})) :content (i18n/label :t/can-not-add-yourself)}}))
(fx/defn handle-public-chat [cofx {:keys [topic]}] (rf/defn handle-public-chat [cofx {:keys [topic]}]
(when (seq topic) (when (seq topic)
(chat/start-public-chat cofx topic))) (chat/start-public-chat cofx topic)))
(fx/defn handle-group-chat [cofx params] (rf/defn handle-group-chat [cofx params]
(group-chats/create-from-link cofx params)) (group-chats/create-from-link cofx params))
(fx/defn handle-view-profile (rf/defn handle-view-profile
[{:keys [db] :as cofx} {:keys [public-key ens-name]}] [{:keys [db] :as cofx} {:keys [public-key ens-name]}]
(let [own (new-chat.db/own-public-key? db public-key)] (let [own (new-chat.db/own-public-key? db public-key)]
(cond (cond
@@ -65,7 +65,7 @@
:pop-to-root-tab-fx :profile-stack} :pop-to-root-tab-fx :profile-stack}
(and public-key (not own)) (and public-key (not own))
(fx/merge cofx (rf/merge cofx
{:dispatch [:chat.ui/show-profile public-key ens-name]} {:dispatch [:chat.ui/show-profile public-key ens-name]}
(navigation/navigate-back)) (navigation/navigate-back))
@@ -74,13 +74,13 @@
:content (i18n/label :t/ens-name-not-found) :content (i18n/label :t/ens-name-not-found)
:on-dismiss #(re-frame/dispatch [:pop-to-root-tab :chat-stack])}}))) :on-dismiss #(re-frame/dispatch [:pop-to-root-tab :chat-stack])}})))
(fx/defn handle-eip681 [cofx data] (rf/defn handle-eip681 [cofx data]
(fx/merge cofx (rf/merge cofx
{:dispatch [:wallet/parse-eip681-uri-and-resolve-ens data]} {:dispatch [:wallet/parse-eip681-uri-and-resolve-ens data]}
(navigation/change-tab :wallet) (navigation/change-tab :wallet)
(navigation/pop-to-root-tab :wallet-stack))) (navigation/pop-to-root-tab :wallet-stack)))
(fx/defn handle-wallet-connect (rf/defn handle-wallet-connect
{:events [::handle-wallet-connect-uri]} {:events [::handle-wallet-connect-uri]}
[cofx data] [cofx data]
(let [wc-version (last (string/split (first (string/split data "?")) "@"))] (let [wc-version (last (string/split (first (string/split data "?")) "@"))]
@@ -88,12 +88,12 @@
{:dispatch [:wallet-connect-legacy/pair data]} {:dispatch [:wallet-connect-legacy/pair data]}
{:dispatch [:wallet-connect/pair data]}))) {:dispatch [:wallet-connect/pair data]})))
(fx/defn handle-local-pairing (rf/defn handle-local-pairing
{:events [::handle-local-pairing-uri]} {:events [::handle-local-pairing-uri]}
[_ data] [_ data]
{:dispatch [:syncing/input-connection-string-for-bootstrapping data]}) {:dispatch [:syncing/input-connection-string-for-bootstrapping data]})
(fx/defn match-scan (rf/defn match-scan
{:events [::match-scanned-value]} {:events [::match-scanned-value]}
[cofx {:keys [type] :as data}] [cofx {:keys [type] :as data}]
(case type (case type
@@ -113,7 +113,7 @@
:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code) :utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)
:on-dismiss #(re-frame/dispatch [:pop-to-root-tab :chat-stack])}}))) :on-dismiss #(re-frame/dispatch [:pop-to-root-tab :chat-stack])}})))
(fx/defn on-scan (rf/defn on-scan
{:events [::on-scan-success]} {:events [::on-scan-success]}
[{:keys [db]} uri] [{:keys [db]} uri]
{::router/handle-uri {:chain (ethereum/chain-keyword db) {::router/handle-uri {:chain (ethereum/chain-keyword db)
+6 -6
View File
@@ -1,22 +1,22 @@
(ns status-im.search.core (ns status-im.search.core
(:require [status-im.utils.fx :as fx])) (:require [utils.re-frame :as rf]))
(fx/defn home-filter-changed (rf/defn home-filter-changed
{:events [:search/home-filter-changed]} {:events [:search/home-filter-changed]}
[cofx search-filter] [cofx search-filter]
{:db (assoc-in (:db cofx) [:ui/search :home-filter] search-filter)}) {:db (assoc-in (:db cofx) [:ui/search :home-filter] search-filter)})
(fx/defn currency-filter-changed (rf/defn currency-filter-changed
{:events [:search/currency-filter-changed]} {:events [:search/currency-filter-changed]}
[cofx search-filter] [cofx search-filter]
{:db (assoc-in (:db cofx) [:ui/search :currency-filter] search-filter)}) {:db (assoc-in (:db cofx) [:ui/search :currency-filter] search-filter)})
(fx/defn token-filter-changed (rf/defn token-filter-changed
{:events [:search/token-filter-changed]} {:events [:search/token-filter-changed]}
[cofx search-filter] [cofx search-filter]
{:db (assoc-in (:db cofx) [:ui/search :token-filter] search-filter)}) {:db (assoc-in (:db cofx) [:ui/search :token-filter] search-filter)})
(fx/defn recipient-filter-changed (rf/defn recipient-filter-changed
{:events [:search/recipient-filter-changed]} {:events [:search/recipient-filter-changed]}
[cofx search-filter] [cofx search-filter]
{:db (assoc-in (:db cofx) [:ui/search :recipient-filter] search-filter)}) {:db (assoc-in (:db cofx) [:ui/search :recipient-filter] search-filter)})
+6 -6
View File
@@ -8,10 +8,10 @@
[status-im.chat.models.message :as models.message] [status-im.chat.models.message :as models.message]
[status-im.chat.models.link-preview :as link.preview] [status-im.chat.models.link-preview :as link.preview]
[status-im.visibility-status-updates.core :as visibility-status-updates] [status-im.visibility-status-updates.core :as visibility-status-updates]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(fx/defn status-node-started (rf/defn status-node-started
[{db :db :as cofx} {:keys [error]}] [{db :db :as cofx} {:keys [error]}]
(log/debug "[signals] status-node-started" (log/debug "[signals] status-node-started"
"error" error) "error" error)
@@ -34,17 +34,17 @@
(assoc :dispatch [:navigate-to :login])) (assoc :dispatch [:navigate-to :login]))
(login/multiaccount-login-success cofx))) (login/multiaccount-login-success cofx)))
(fx/defn summary (rf/defn summary
[{:keys [db] :as cofx} peers-summary] [{:keys [db] :as cofx} peers-summary]
(let [previous-summary (:peers-summary db) (let [previous-summary (:peers-summary db)
peers-count (count peers-summary)] peers-count (count peers-summary)]
(fx/merge cofx (rf/merge cofx
{:db (assoc db {:db (assoc db
:peers-summary peers-summary :peers-summary peers-summary
:peers-count peers-count)} :peers-count peers-count)}
(visibility-status-updates/peers-summary-change peers-count)))) (visibility-status-updates/peers-summary-change peers-count))))
(fx/defn wakuv2-peer-stats (rf/defn wakuv2-peer-stats
[{:keys [db]} peer-stats] [{:keys [db]} peer-stats]
(let [previous-stats (:peer-stats db)] (let [previous-stats (:peer-stats db)]
{:db (assoc db :peer-stats peer-stats {:db (assoc db :peer-stats peer-stats
@@ -54,7 +54,7 @@
(log/info "local pairing signal received" (log/info "local pairing signal received"
{:signal-type signal-type})) {:signal-type signal-type}))
(fx/defn process (rf/defn process
{:events [:signals/signal-received]} {:events [:signals/signal-received]}
[{:keys [db] :as cofx} event-str] [{:keys [db] :as cofx} event-str]
;; We only convert to clojure when strictly necessary or we know it ;; We only convert to clojure when strictly necessary or we know it
+35 -35
View File
@@ -11,7 +11,7 @@
[status-im.keycard.card :as keycard.card] [status-im.keycard.card :as keycard.card]
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.signing.keycard :as signing.keycard] [status-im.signing.keycard :as signing.keycard]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.hex :as utils.hex] [status-im.utils.hex :as utils.hex]
[status-im.utils.money :as money] [status-im.utils.money :as money]
[status-im.utils.security :as security] [status-im.utils.security :as security]
@@ -65,7 +65,7 @@
(get-in db [:contacts/contacts to]) (get-in db [:contacts/contacts to])
{:address (ethereum/normalized-hex to)}))) {:address (ethereum/normalized-hex to)})))
(fx/defn change-password (rf/defn change-password
{:events [:signing.ui/password-is-changed]} {:events [:signing.ui/password-is-changed]}
[{db :db} password] [{db :db} password]
(let [unmasked-pass (security/safe-unmask-data password)] (let [unmasked-pass (security/safe-unmask-data password)]
@@ -74,7 +74,7 @@
:error nil :error nil
:enabled? (and unmasked-pass (> (count unmasked-pass) 5)))})) :enabled? (and unmasked-pass (> (count unmasked-pass) 5)))}))
(fx/defn sign-message (rf/defn sign-message
[{{:signing/keys [sign tx] :as db} :db}] [{{:signing/keys [sign tx] :as db} :db}]
(let [{{:keys [data typed? from v4]} :message} tx (let [{{:keys [data typed? from v4]} :message} tx
{:keys [in-progress? password]} sign {:keys [in-progress? password]} sign
@@ -94,7 +94,7 @@
:account from} :account from}
:on-completed #(re-frame/dispatch [:signing/sign-message-completed %])}}))))) :on-completed #(re-frame/dispatch [:signing/sign-message-completed %])}})))))
(fx/defn send-transaction (rf/defn send-transaction
{:events [:signing.ui/sign-is-pressed]} {:events [:signing.ui/sign-is-pressed]}
[{{:signing/keys [sign tx] :as db} :db :as cofx}] [{{:signing/keys [sign tx] :as db} :db :as cofx}]
(let [{:keys [in-progress? password]} sign (let [{:keys [in-progress? password]} sign
@@ -121,7 +121,7 @@
:hashed-password hashed-password :hashed-password hashed-password
:cb #(re-frame/dispatch [:signing/transaction-completed % tx-obj-to-send hashed-password])}}))))) :cb #(re-frame/dispatch [:signing/transaction-completed % tx-obj-to-send hashed-password])}})))))
(fx/defn prepare-unconfirmed-transaction (rf/defn prepare-unconfirmed-transaction
[{:keys [db now]} new-tx-hash [{:keys [db now]} new-tx-hash
{:keys [value gasPrice maxFeePerGas maxPriorityFeePerGas gas data to from hash]} symbol amount] {:keys [value gasPrice maxFeePerGas maxPriorityFeePerGas gas data to from hash]} symbol amount]
(let [token (tokens/symbol->token (:wallet/all-tokens db) symbol) (let [token (tokens/symbol->token (:wallet/all-tokens db) symbol)
@@ -221,13 +221,13 @@
:maxPriorityFeePerGas (when maxPriorityFeePerGas :maxPriorityFeePerGas (when maxPriorityFeePerGas
(money/bignumber maxPriorityFeePerGas))})) (money/bignumber maxPriorityFeePerGas))}))
(fx/defn show-sign [{:keys [db] :as cofx}] (rf/defn show-sign [{:keys [db] :as cofx}]
(let [{:signing/keys [queue]} db (let [{:signing/keys [queue]} db
{{:keys [gas gasPrice maxFeePerGas] :as tx-obj} :tx-obj {:keys [data typed? pinless?] :as message} :message :as tx} (last queue) {{:keys [gas gasPrice maxFeePerGas] :as tx-obj} :tx-obj {:keys [data typed? pinless?] :as message} :message :as tx} (last queue)
keycard-multiaccount? (boolean (get-in db [:multiaccount :keycard-pairing])) keycard-multiaccount? (boolean (get-in db [:multiaccount :keycard-pairing]))
wallet-set-up-passed? (get-in db [:multiaccount :wallet-set-up-passed?])] wallet-set-up-passed? (get-in db [:multiaccount :wallet-set-up-passed?])]
(if message (if message
(fx/merge (rf/merge
cofx cofx
{:db (assoc db {:db (assoc db
:signing/queue (drop-last queue) :signing/queue (drop-last queue)
@@ -248,7 +248,7 @@
(signing.keycard/hash-message {:data data (signing.keycard/hash-message {:data data
:typed? true :typed? true
:on-completed #(re-frame/dispatch [:keycard/store-hash-and-sign-typed %])}))) :on-completed #(re-frame/dispatch [:keycard/store-hash-and-sign-typed %])})))
(fx/merge (rf/merge
cofx cofx
{:db (assoc db {:db (assoc db
:signing/queue (drop-last queue) :signing/queue (drop-last queue)
@@ -279,12 +279,12 @@
:network-id (get-in (ethereum/current-network db) :network-id (get-in (ethereum/current-network db)
[:config :NetworkId])}}))))) [:config :NetworkId])}})))))
(fx/defn check-queue [{:keys [db] :as cofx}] (rf/defn check-queue [{:keys [db] :as cofx}]
(let [{:signing/keys [tx queue]} db] (let [{:signing/keys [tx queue]} db]
(when (and (not tx) (seq queue)) (when (and (not tx) (seq queue))
(show-sign cofx)))) (show-sign cofx))))
(fx/defn send-transaction-message (rf/defn send-transaction-message
{:events [:sign/send-transaction-message]} {:events [:sign/send-transaction-message]}
[cofx chat-id value contract transaction-hash signature] [cofx chat-id value contract transaction-hash signature]
{::json-rpc/call [{:method "wakuext_sendTransaction" {::json-rpc/call [{:method "wakuext_sendTransaction"
@@ -297,7 +297,7 @@
:on-success :on-success
#(re-frame/dispatch [:transport/message-sent %])}]}) #(re-frame/dispatch [:transport/message-sent %])}]})
(fx/defn send-accept-request-transaction-message (rf/defn send-accept-request-transaction-message
{:events [:sign/send-accept-transaction-message]} {:events [:sign/send-accept-transaction-message]}
[cofx message-id transaction-hash signature] [cofx message-id transaction-hash signature]
{::json-rpc/call [{:method "wakuext_acceptRequestTransaction" {::json-rpc/call [{:method "wakuext_acceptRequestTransaction"
@@ -308,10 +308,10 @@
:on-success :on-success
#(re-frame/dispatch [:transport/message-sent %])}]}) #(re-frame/dispatch [:transport/message-sent %])}]})
(fx/defn transaction-result (rf/defn transaction-result
[{:keys [db] :as cofx} result tx-obj] [{:keys [db] :as cofx} result tx-obj]
(let [{:keys [on-result symbol amount from]} (get db :signing/tx)] (let [{:keys [on-result symbol amount from]} (get db :signing/tx)]
(fx/merge cofx (rf/merge cofx
{:db (dissoc db :signing/tx :signing/sign) {:db (dissoc db :signing/tx :signing/sign)
:signing/show-transaction-result nil} :signing/show-transaction-result nil}
(prepare-unconfirmed-transaction result tx-obj symbol amount) (prepare-unconfirmed-transaction result tx-obj symbol amount)
@@ -320,13 +320,13 @@
#(when on-result #(when on-result
{:dispatch (conj on-result result)})))) {:dispatch (conj on-result result)}))))
(fx/defn command-transaction-result (rf/defn command-transaction-result
[{:keys [db] :as cofx} transaction-hash hashed-password [{:keys [db] :as cofx} transaction-hash hashed-password
{:keys [message-id chat-id from] :as tx-obj}] {:keys [message-id chat-id from] :as tx-obj}]
(let [{:keys [on-result symbol amount contract value]} (get db :signing/tx) (let [{:keys [on-result symbol amount contract value]} (get db :signing/tx)
data (str (get-in db [:multiaccount :public-key]) data (str (get-in db [:multiaccount :public-key])
(subs transaction-hash 2))] (subs transaction-hash 2))]
(fx/merge (rf/merge
cofx cofx
{:db (dissoc db :signing/tx :signing/sign)} {:db (dissoc db :signing/tx :signing/sign)}
(wallet/watch-tx (get from :address) transaction-hash) (wallet/watch-tx (get from :address) transaction-hash)
@@ -362,7 +362,7 @@
#(when on-result #(when on-result
{:dispatch (conj on-result transaction-hash)})))) {:dispatch (conj on-result transaction-hash)}))))
(fx/defn transaction-error (rf/defn transaction-error
[{:keys [db]} {:keys [code message]}] [{:keys [db]} {:keys [code message]}]
(let [on-error (get-in db [:signing/tx :on-error])] (let [on-error (get-in db [:signing/tx :on-error])]
(if (= code constants/send-transaction-err-decrypt) (if (= code constants/send-transaction-err-decrypt)
@@ -373,14 +373,14 @@
(when on-error (when on-error
{:dispatch (conj on-error message)}))))) {:dispatch (conj on-error message)})))))
(fx/defn dissoc-signing-db-entries-and-check-queue (rf/defn dissoc-signing-db-entries-and-check-queue
{:events [:signing/dissoc-entries-and-check-queue]} {:events [:signing/dissoc-entries-and-check-queue]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (rf/merge cofx
{:db (dissoc db :signing/tx :signing/sign)} {:db (dissoc db :signing/tx :signing/sign)}
check-queue)) check-queue))
(fx/defn sign-message-completed (rf/defn sign-message-completed
{:events [:signing/sign-message-completed]} {:events [:signing/sign-message-completed]}
[{:keys [db] :as cofx} result] [{:keys [db] :as cofx} result]
(let [{:keys [result error]} (types/json->clj result) (let [{:keys [result error]} (types/json->clj result)
@@ -391,7 +391,7 @@
(i18n/label :t/wrong-password) (i18n/label :t/wrong-password)
(:message error)) (:message error))
:in-progress? false)} :in-progress? false)}
(fx/merge cofx (rf/merge cofx
(when-not (= (-> db :signing/sign :type) :pinless) (when-not (= (-> db :signing/sign :type) :pinless)
(dissoc-signing-db-entries-and-check-queue)) (dissoc-signing-db-entries-and-check-queue))
#(when (= (-> db :signing/sign :type) :pinless) #(when (= (-> db :signing/sign :type) :pinless)
@@ -400,7 +400,7 @@
#(when on-result #(when on-result
{:dispatch (conj on-result result)}))))) {:dispatch (conj on-result result)})))))
(fx/defn transaction-completed (rf/defn transaction-completed
{:events [:signing/transaction-completed] {:events [:signing/transaction-completed]
:interceptors [(re-frame/inject-cofx :random-id-generator)]} :interceptors [(re-frame/inject-cofx :random-id-generator)]}
[cofx response tx-obj hashed-password] [cofx response tx-obj hashed-password]
@@ -412,12 +412,12 @@
(command-transaction-result cofx-in-progress-false result hashed-password tx-obj) (command-transaction-result cofx-in-progress-false result hashed-password tx-obj)
(transaction-result cofx-in-progress-false result tx-obj))))) (transaction-result cofx-in-progress-false result tx-obj)))))
(fx/defn discard (rf/defn discard
"Discrad transaction signing" "Discrad transaction signing"
{:events [:signing.ui/cancel-is-pressed]} {:events [:signing.ui/cancel-is-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [on-error]} (get-in db [:signing/tx])] (let [{:keys [on-error]} (get-in db [:signing/tx])]
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :pin :status] nil) (assoc-in [:keycard :pin :status] nil)
(dissoc :signing/tx :signing/sign)) (dissoc :signing/tx :signing/sign))
@@ -431,7 +431,7 @@
(defn normalize-tx-obj [db tx] (defn normalize-tx-obj [db tx]
(update-in tx [:tx-obj :from] #(eip55/address->checksum (or % (ethereum/default-address db))))) (update-in tx [:tx-obj :from] #(eip55/address->checksum (or % (ethereum/default-address db)))))
(fx/defn sign (rf/defn sign
"Signing transaction or message, shows signing sheet "Signing transaction or message, shows signing sheet
tx tx
{:tx-obj - transaction object to send https://github.com/ethereum/wiki/wiki/JavaScript-API#parameters-25 {:tx-obj - transaction object to send https://github.com/ethereum/wiki/wiki/JavaScript-API#parameters-25
@@ -440,11 +440,11 @@
:on-error - re-frame event vector}" :on-error - re-frame event vector}"
{:events [:signing.ui/sign]} {:events [:signing.ui/sign]}
[{:keys [db] :as cofx} tx] [{:keys [db] :as cofx} tx]
(fx/merge cofx (rf/merge cofx
{:db (update db :signing/queue conj (normalize-tx-obj db tx))} {:db (update db :signing/queue conj (normalize-tx-obj db tx))}
(check-queue))) (check-queue)))
(fx/defn sign-transaction-button-clicked-from-chat (rf/defn sign-transaction-button-clicked-from-chat
{:events [:wallet.ui/sign-transaction-button-clicked-from-chat]} {:events [:wallet.ui/sign-transaction-button-clicked-from-chat]}
[{:keys [db] :as cofx} {:keys [to amount from token]}] [{:keys [db] :as cofx} {:keys [to amount from token]}]
(let [{:keys [symbol address]} token (let [{:keys [symbol address]} token
@@ -454,7 +454,7 @@
identity (:current-chat-id db) identity (:current-chat-id db)
db (dissoc db :wallet/prepare-transaction :signing/edit-fee)] db (dissoc db :wallet/prepare-transaction :signing/edit-fee)]
(if to-norm (if to-norm
(fx/merge (rf/merge
cofx cofx
{:db db} {:db db}
(sign {:tx-obj (if (= symbol :ETH) (sign {:tx-obj (if (= symbol :ETH)
@@ -479,7 +479,7 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [:transport/message-sent %])}]}))) :on-success #(re-frame/dispatch [:transport/message-sent %])}]})))
(fx/defn sign-transaction-button-clicked-from-request (rf/defn sign-transaction-button-clicked-from-request
{:events [:wallet.ui/sign-transaction-button-clicked-from-request]} {:events [:wallet.ui/sign-transaction-button-clicked-from-request]}
[{:keys [db] :as cofx} {:keys [amount from token]}] [{:keys [db] :as cofx} {:keys [amount from token]}]
(let [{:keys [request-parameters chat-id]} (:wallet/prepare-transaction db) (let [{:keys [request-parameters chat-id]} (:wallet/prepare-transaction db)
@@ -487,7 +487,7 @@
amount-hex (str "0x" (status/number-to-hex amount)) amount-hex (str "0x" (status/number-to-hex amount))
to-norm (:address request-parameters) to-norm (:address request-parameters)
from-address (:address from)] from-address (:address from)]
(fx/merge cofx (rf/merge cofx
{:db (dissoc db :wallet/prepare-transaction :signing/edit-fee)} {:db (dissoc db :wallet/prepare-transaction :signing/edit-fee)}
(fn [cofx] (fn [cofx]
(sign (sign
@@ -506,14 +506,14 @@
:chat-id chat-id :chat-id chat-id
:data (status/encode-transfer to-norm amount-hex)})}))))) :data (status/encode-transfer to-norm amount-hex)})})))))
(fx/defn sign-transaction-button-clicked (rf/defn sign-transaction-button-clicked
{:events [:wallet.ui/sign-transaction-button-clicked]} {:events [:wallet.ui/sign-transaction-button-clicked]}
[{:keys [db] :as cofx} {:keys [to amount from token gas gasPrice maxFeePerGas maxPriorityFeePerGas]}] [{:keys [db] :as cofx} {:keys [to amount from token gas gasPrice maxFeePerGas maxPriorityFeePerGas]}]
(let [{:keys [symbol address]} token (let [{:keys [symbol address]} token
amount-hex (str "0x" (status/number-to-hex amount)) amount-hex (str "0x" (status/number-to-hex amount))
to-norm (ethereum/normalized-hex (if (string? to) to (:address to))) to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))
from-address (:address from)] from-address (:address from)]
(fx/merge cofx (rf/merge cofx
{:db (dissoc db :wallet/prepare-transaction :signing/edit-fee)} {:db (dissoc db :wallet/prepare-transaction :signing/edit-fee)}
(sign (sign
{:tx-obj (merge (if (eip1559/sync-enabled?) {:tx-obj (merge (if (eip1559/sync-enabled?)
@@ -540,17 +540,17 @@
:params [hash] :params [hash]
:on-success handler}))) :on-success handler})))
(fx/defn cancel-transaction-pressed (rf/defn cancel-transaction-pressed
{:events [:signing.ui/cancel-transaction-pressed]} {:events [:signing.ui/cancel-transaction-pressed]}
[_ hash] [_ hash]
{:signing/get-transaction-by-hash-fx [hash #(re-frame/dispatch [:signing/cancel-transaction %])]}) {:signing/get-transaction-by-hash-fx [hash #(re-frame/dispatch [:signing/cancel-transaction %])]})
(fx/defn increase-gas-pressed (rf/defn increase-gas-pressed
{:events [:signing.ui/increase-gas-pressed]} {:events [:signing.ui/increase-gas-pressed]}
[_ hash] [_ hash]
{:signing/get-transaction-by-hash-fx [hash #(re-frame/dispatch [:signing/increase-gas %])]}) {:signing/get-transaction-by-hash-fx [hash #(re-frame/dispatch [:signing/increase-gas %])]})
(fx/defn cancel-transaction (rf/defn cancel-transaction
{:events [:signing/cancel-transaction]} {:events [:signing/cancel-transaction]}
[cofx {:keys [from nonce hash]}] [cofx {:keys [from nonce hash]}]
(when (and from nonce hash) (when (and from nonce hash)
@@ -561,7 +561,7 @@
:cancel? true :cancel? true
:hash hash}}))) :hash hash}})))
(fx/defn increase-gas (rf/defn increase-gas
{:events [:signing/increase-gas]} {:events [:signing/increase-gas]}
[cofx {:keys [from nonce] :as tx}] [cofx {:keys [from nonce] :as tx}]
(when (and from nonce) (when (and from nonce)
+15 -15
View File
@@ -3,7 +3,7 @@
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.bottom-sheet.core :as bottom-sheet] [status-im.bottom-sheet.core :as bottom-sheet]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.money :as money] [status-im.utils.money :as money]
[status-im.signing.eip1559 :as eip1559] [status-im.signing.eip1559 :as eip1559]
[taoensso.timbre :as log] [taoensso.timbre :as log]
@@ -139,7 +139,7 @@
validate-max-priority-fee]) validate-max-priority-fee])
db)) db))
(fx/defn edit-value (rf/defn edit-value
{:events [:signing.edit-fee.ui/edit-value]} {:events [:signing.edit-fee.ui/edit-value]}
[{:keys [db]} key value] [{:keys [db]} key value]
{:db (-> db {:db (-> db
@@ -165,7 +165,7 @@
:tip tip-bn :tip tip-bn
:fee (money/add fast-bn tip-bn)}})) :fee (money/add fast-bn tip-bn)}}))
(fx/defn set-fee-option (rf/defn set-fee-option
{:events [:signing.edit-fee.ui/set-option]} {:events [:signing.edit-fee.ui/set-option]}
[{:keys [db] :as cofx} option] [{:keys [db] :as cofx} option]
(let [tip (get db :wallet/current-priority-fee) (let [tip (get db :wallet/current-priority-fee)
@@ -180,7 +180,7 @@
(update :signing/edit-fee (update :signing/edit-fee
build-edit :maxPriorityFeePerGas (money/wei->gwei tip)))})) build-edit :maxPriorityFeePerGas (money/wei->gwei tip)))}))
(fx/defn set-priority-fee (rf/defn set-priority-fee
{:events [:signing.edit-fee.ui/set-priority-fee]} {:events [:signing.edit-fee.ui/set-priority-fee]}
[{:keys [db]} value] [{:keys [db]} value]
(let [{:keys [maxFeePerGas maxPriorityFeePerGas]} (let [{:keys [maxFeePerGas maxPriorityFeePerGas]}
@@ -201,14 +201,14 @@
(update :signing/edit-fee build-edit :maxFeePerGas new-max-fee-value) (update :signing/edit-fee build-edit :maxFeePerGas new-max-fee-value)
validate-eip1559-fees)})) validate-eip1559-fees)}))
(fx/defn update-estimated-gas-success (rf/defn update-estimated-gas-success
{:events [:signing/update-estimated-gas-success]} {:events [:signing/update-estimated-gas-success]}
[{db :db} gas] [{db :db} gas]
{:db (-> db {:db (-> db
(assoc-in [:signing/tx :gas] gas) (assoc-in [:signing/tx :gas] gas)
(assoc-in [:signing/edit-fee :gas-loading?] false))}) (assoc-in [:signing/edit-fee :gas-loading?] false))})
(fx/defn update-gas-price-success (rf/defn update-gas-price-success
{:events [:signing/update-gas-price-success]} {:events [:signing/update-gas-price-success]}
[{db :db} price] [{db :db} price]
(if (eip1559/sync-enabled?) (if (eip1559/sync-enabled?)
@@ -225,7 +225,7 @@
(assoc-in [:signing/tx :gasPrice] price) (assoc-in [:signing/tx :gasPrice] price)
(assoc-in [:signing/edit-fee :gas-price-loading?] false))})) (assoc-in [:signing/edit-fee :gas-price-loading?] false))}))
(fx/defn update-estimated-gas-error (rf/defn update-estimated-gas-error
{:events [:signing/update-estimated-gas-error]} {:events [:signing/update-estimated-gas-error]}
[{db :db} {:keys [message]}] [{db :db} {:keys [message]}]
(log/warn "signing/update-estimated-gas-error" message) (log/warn "signing/update-estimated-gas-error" message)
@@ -233,12 +233,12 @@
(assoc-in [:signing/edit-fee :gas-loading?] false) (assoc-in [:signing/edit-fee :gas-loading?] false)
(assoc-in [:signing/tx :gas-error-message] message))}) (assoc-in [:signing/tx :gas-error-message] message))})
(fx/defn update-gas-price-error (rf/defn update-gas-price-error
{:events [:signing/update-gas-price-error]} {:events [:signing/update-gas-price-error]}
[{db :db}] [{db :db}]
{:db (assoc-in db [:signing/edit-fee :gas-price-loading?] false)}) {:db (assoc-in db [:signing/edit-fee :gas-price-loading?] false)})
(fx/defn open-fee-sheet (rf/defn open-fee-sheet
{:events [:signing.ui/open-fee-sheet]} {:events [:signing.ui/open-fee-sheet]}
[{{:signing/keys [tx] :as db} :db :as cofx} sheet-opts] [{{:signing/keys [tx] :as db} :db :as cofx} sheet-opts]
(let [{:keys [gas gasPrice maxFeePerGas maxPriorityFeePerGas]} tx (let [{:keys [gas gasPrice maxFeePerGas maxPriorityFeePerGas]} tx
@@ -250,11 +250,11 @@
:gasPrice (money/to-fixed (money/wei->gwei gasPrice)) :gasPrice (money/to-fixed (money/wei->gwei gasPrice))
:maxFeePerGas max-fee :maxFeePerGas max-fee
:maxPriorityFeePerGas max-priority-fee})] :maxPriorityFeePerGas max-priority-fee})]
(fx/merge cofx (rf/merge cofx
{:db (assoc db :signing/edit-fee edit-fee)} {:db (assoc db :signing/edit-fee edit-fee)}
(bottom-sheet/show-bottom-sheet {:view sheet-opts})))) (bottom-sheet/show-bottom-sheet {:view sheet-opts}))))
(fx/defn submit-fee (rf/defn submit-fee
{:events [:signing.edit-fee.ui/submit]} {:events [:signing.edit-fee.ui/submit]}
[{{:signing/keys [edit-fee] :as db} :db :as cofx} force?] [{{:signing/keys [edit-fee] :as db} :db :as cofx} force?]
(let [{:keys [gas gasPrice maxFeePerGas maxPriorityFeePerGas]} edit-fee (let [{:keys [gas gasPrice maxFeePerGas maxPriorityFeePerGas]} edit-fee
@@ -267,7 +267,7 @@
(if (and (seq errors?) (if (and (seq errors?)
(not force?)) (not force?))
(popover/show-popover cofx {:view :fees-warning}) (popover/show-popover cofx {:view :fees-warning})
(fx/merge cofx (rf/merge cofx
{:db (update db :signing/tx assoc {:db (update db :signing/tx assoc
:gas (:value-number gas) :gas (:value-number gas)
:gasPrice (:value-number gasPrice) :gasPrice (:value-number gasPrice)
@@ -275,10 +275,10 @@
:maxPriorityFeePerGas (money/->wei :gwei (:value-number maxPriorityFeePerGas)))} :maxPriorityFeePerGas (money/->wei :gwei (:value-number maxPriorityFeePerGas)))}
(bottom-sheet/hide-bottom-sheet))))) (bottom-sheet/hide-bottom-sheet)))))
(fx/defn submit-nonce (rf/defn submit-nonce
{:events [:signing.nonce/submit]} {:events [:signing.nonce/submit]}
[{db :db :as cofx} nonce] [{db :db :as cofx} nonce]
(fx/merge cofx (rf/merge cofx
{:db (assoc-in db [:signing/tx :nonce] (if (string/blank? nonce) nil nonce))} {:db (assoc-in db [:signing/tx :nonce] (if (string/blank? nonce) nil nonce))}
(bottom-sheet/hide-bottom-sheet))) (bottom-sheet/hide-bottom-sheet)))
@@ -362,7 +362,7 @@
(money/sub (money/bignumber gas-price) (money/sub (money/bignumber gas-price)
(money/bignumber base-fee)))) (money/bignumber base-fee))))
(fx/defn header-fetched (rf/defn header-fetched
{:events [::header-fetched]} {:events [::header-fetched]}
[{{:networks/keys [current-network networks]} :db} [{{:networks/keys [current-network networks]} :db}
{:keys [error-callback success-callback fee-history] :as params}] {:keys [error-callback success-callback fee-history] :as params}]
+7 -7
View File
@@ -1,7 +1,7 @@
(ns status-im.signing.keycard (ns status-im.signing.keycard
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
@@ -49,7 +49,7 @@
nonce nonce
(assoc :nonce nonce)))) (assoc :nonce nonce))))
(fx/defn hash-message (rf/defn hash-message
[_ {:keys [v4 data typed? on-completed]}] [_ {:keys [v4 data typed? on-completed]}]
(if typed? (if typed?
{::hash-typed-data {::hash-typed-data
@@ -68,7 +68,7 @@
[:signing.keycard.callback/hash-message-completed [:signing.keycard.callback/hash-message-completed
data typed? %]))}})) data typed? %]))}}))
(fx/defn hash-message-completed (rf/defn hash-message-completed
{:events [:signing.keycard.callback/hash-message-completed]} {:events [:signing.keycard.callback/hash-message-completed]}
[{:keys [db]} data typed? result] [{:keys [db]} data typed? result]
(let [{:keys [result error]} (types/json->clj result)] (let [{:keys [result error]} (types/json->clj result)]
@@ -81,7 +81,7 @@
:typed? typed? :typed? typed?
:data data)}))) :data data)})))
(fx/defn hash-transaction (rf/defn hash-transaction
[{:keys [db]}] [{:keys [db]}]
(let [tx (prepare-transaction (:signing/tx db))] (let [tx (prepare-transaction (:signing/tx db))]
(log/debug "hash-transaction" tx) (log/debug "hash-transaction" tx)
@@ -90,7 +90,7 @@
:on-completed #(re-frame/dispatch :on-completed #(re-frame/dispatch
[:signing.keycard.callback/hash-transaction-completed tx %])}})) [:signing.keycard.callback/hash-transaction-completed tx %])}}))
(fx/defn hash-transaction-completed (rf/defn hash-transaction-completed
{:events [:signing.keycard.callback/hash-transaction-completed]} {:events [:signing.keycard.callback/hash-transaction-completed]}
[{:keys [db]} original-tx result] [{:keys [db]} original-tx result]
(let [{:keys [transaction hash]} (:result (types/json->clj result))] (let [{:keys [transaction hash]} (:result (types/json->clj result))]
@@ -99,11 +99,11 @@
(merge original-tx transaction)) (merge original-tx transaction))
(assoc-in [:keycard :hash] hash))})) (assoc-in [:keycard :hash] hash))}))
(fx/defn sign-with-keycard (rf/defn sign-with-keycard
{:events [:signing.ui/sign-with-keycard-pressed]} {:events [:signing.ui/sign-with-keycard-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [message maxPriorityFeePerGas maxFeePerGas]} (get db :signing/tx)] (let [{:keys [message maxPriorityFeePerGas maxFeePerGas]} (get db :signing/tx)]
(fx/merge (rf/merge
cofx cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :pin :enter-step] :sign) (assoc-in [:keycard :pin :enter-step] :sign)
+14 -14
View File
@@ -4,7 +4,7 @@
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.constants :as constants])) [status-im.constants :as constants]))
@@ -15,17 +15,17 @@
(utils/set-timeout #(re-frame/dispatch [:stickers/pending-timeout]) (utils/set-timeout #(re-frame/dispatch [:stickers/pending-timeout])
10000))) 10000)))
(fx/defn install-stickers-pack (rf/defn install-stickers-pack
{:events [:stickers/install-pack]} {:events [:stickers/install-pack]}
[{db :db :as cofx} id] [{db :db :as cofx} id]
(fx/merge (rf/merge
cofx cofx
{:db (assoc-in db [:stickers/packs id :status] constants/sticker-pack-status-installed) {:db (assoc-in db [:stickers/packs id :status] constants/sticker-pack-status-installed)
::json-rpc/call [{:method "stickers_install" ::json-rpc/call [{:method "stickers_install"
:params [(ethereum/chain-id db) id] :params [(ethereum/chain-id db) id]
:on-success #()}]})) :on-success #()}]}))
(fx/defn load-packs (rf/defn load-packs
{:events [:stickers/load-packs]} {:events [:stickers/load-packs]}
[{:keys [db]}] [{:keys [db]}]
{::json-rpc/call [{:method "stickers_market" {::json-rpc/call [{:method "stickers_market"
@@ -41,7 +41,7 @@
:params [] :params []
:on-success #(re-frame/dispatch [:stickers/stickers-recent-success %])}]}) :on-success #(re-frame/dispatch [:stickers/stickers-recent-success %])}]})
(fx/defn buy-pack (rf/defn buy-pack
{:events [:stickers/buy-pack]} {:events [:stickers/buy-pack]}
[{db :db} pack-id] [{db :db} pack-id]
{::json-rpc/call [{:method "stickers_buyPrepareTx" {::json-rpc/call [{:method "stickers_buyPrepareTx"
@@ -50,7 +50,7 @@
{:tx-obj % {:tx-obj %
:on-result [:stickers/pending-pack pack-id]}])}]}) :on-result [:stickers/pending-pack pack-id]}])}]})
(fx/defn pending-pack (rf/defn pending-pack
{:events [:stickers/pending-pack]} {:events [:stickers/pending-pack]}
[{db :db} id] [{db :db} id]
{:db (-> db {:db (-> db
@@ -61,7 +61,7 @@
:params [(ethereum/chain-id db) (int id)] :params [(ethereum/chain-id db) (int id)]
:on-success #()}]}) :on-success #()}]})
(fx/defn pending-timeout (rf/defn pending-timeout
{:events [:stickers/pending-timeout]} {:events [:stickers/pending-timeout]}
[{{:stickers/keys [packs-pending] :as db} :db}] [{{:stickers/keys [packs-pending] :as db} :db}]
(when (seq packs-pending) (when (seq packs-pending)
@@ -69,7 +69,7 @@
:params [(ethereum/chain-id db)] :params [(ethereum/chain-id db)]
:on-success #(re-frame/dispatch [:stickers/stickers-process-pending-success %])}]})) :on-success #(re-frame/dispatch [:stickers/stickers-process-pending-success %])}]}))
(fx/defn stickers-process-pending-success (rf/defn stickers-process-pending-success
{:events [:stickers/stickers-process-pending-success]} {:events [:stickers/stickers-process-pending-success]}
[{{:stickers/keys [packs-pending packs] :as db} :db} purchased] [{{:stickers/keys [packs-pending packs] :as db} :db} purchased]
(let [purchased-ids (map :id (vals purchased)) (let [purchased-ids (map :id (vals purchased))
@@ -85,19 +85,19 @@
(when (seq packs-pending) (when (seq packs-pending)
{:stickers/set-pending-timeout-fx nil})))) {:stickers/set-pending-timeout-fx nil}))))
(fx/defn stickers-market-success (rf/defn stickers-market-success
{:events [:stickers/stickers-market-success]} {:events [:stickers/stickers-market-success]}
[{:keys [db]} packs] [{:keys [db]} packs]
(let [packs (reduce (fn [acc pack] (assoc acc (:id pack) pack)) {} packs)] (let [packs (reduce (fn [acc pack] (assoc acc (:id pack) pack)) {} packs)]
{:db (update db :stickers/packs merge packs)})) {:db (update db :stickers/packs merge packs)}))
(fx/defn stickers-installed-success (rf/defn stickers-installed-success
{:events [:stickers/stickers-installed-success]} {:events [:stickers/stickers-installed-success]}
[{:keys [db]} packs] [{:keys [db]} packs]
(let [packs (reduce (fn [acc [_ pack]] (assoc acc (:id pack) pack)) {} packs)] (let [packs (reduce (fn [acc [_ pack]] (assoc acc (:id pack) pack)) {} packs)]
{:db (update db :stickers/packs merge packs)})) {:db (update db :stickers/packs merge packs)}))
(fx/defn stickers-pending-success (rf/defn stickers-pending-success
{:events [:stickers/stickers-pending-success]} {:events [:stickers/stickers-pending-success]}
[{:keys [db]} packs] [{:keys [db]} packs]
(let [packs (reduce (fn [acc [_ pack]] (assoc acc (:id pack) pack)) {} packs)] (let [packs (reduce (fn [acc [_ pack]] (assoc acc (:id pack) pack)) {} packs)]
@@ -108,18 +108,18 @@
(when (seq packs) (when (seq packs)
{:stickers/set-pending-timeout-fx nil})))) {:stickers/set-pending-timeout-fx nil}))))
(fx/defn stickers-recent-success (rf/defn stickers-recent-success
{:events [:stickers/stickers-recent-success]} {:events [:stickers/stickers-recent-success]}
[{:keys [db]} packs] [{:keys [db]} packs]
{:db (assoc db :stickers/recent-stickers packs)}) {:db (assoc db :stickers/recent-stickers packs)})
(fx/defn open-sticker-pack (rf/defn open-sticker-pack
{:events [:stickers/open-sticker-pack]} {:events [:stickers/open-sticker-pack]}
[{{:networks/keys [current-network]} :db :as cofx} id] [{{:networks/keys [current-network]} :db :as cofx} id]
(when (and id (or config/stickers-test-enabled? (string/starts-with? current-network "mainnet"))) (when (and id (or config/stickers-test-enabled? (string/starts-with? current-network "mainnet")))
(navigation/open-modal cofx :stickers-pack {:id id}))) (navigation/open-modal cofx :stickers-pack {:id id})))
(fx/defn select-pack (rf/defn select-pack
{:events [:stickers/select-pack]} {:events [:stickers/select-pack]}
[{:keys [db]} id] [{:keys [db]} id]
{:db (assoc db :stickers/selected-pack id)}) {:db (assoc db :stickers/selected-pack id)})
+6 -6
View File
@@ -3,18 +3,18 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.pairing.core :as pairing] [status-im.pairing.core :as pairing]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
status-im.transport.shh status-im.transport.shh
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.utils.universal-links.core :as universal-links] [status-im.utils.universal-links.core :as universal-links]
[status-im.stickers.core :as stickers])) [status-im.stickers.core :as stickers]))
(fx/defn set-node-info (rf/defn set-node-info
{:events [:transport.callback/node-info-fetched]} {:events [:transport.callback/node-info-fetched]}
[{:keys [db]} node-info] [{:keys [db]} node-info]
{:db (assoc db :node-info node-info)}) {:db (assoc db :node-info node-info)})
(fx/defn fetch-node-info-fx [_] (rf/defn fetch-node-info-fx [_]
{::json-rpc/call [{:method "admin_nodeInfo" {::json-rpc/call [{:method "admin_nodeInfo"
:on-success #(re-frame/dispatch [:transport.callback/node-info-fetched %]) :on-success #(re-frame/dispatch [:transport.callback/node-info-fetched %])
:on-error #(log/error "node-info: failed error" %)}]}) :on-error #(log/error "node-info: failed error" %)}]})
@@ -33,7 +33,7 @@
db db
mailservers)) mailservers))
(fx/defn start-messenger (rf/defn start-messenger
"We should only start receiving messages/processing topics once all the "We should only start receiving messages/processing topics once all the
initializiation is completed, otherwise we might receive messages/topics initializiation is completed, otherwise we might receive messages/topics
when the state has not been properly initialized." when the state has not been properly initialized."
@@ -42,11 +42,11 @@
:on-success #(re-frame/dispatch [::messenger-started %]) :on-success #(re-frame/dispatch [::messenger-started %])
:on-error #(log/error "failed to start messenger")}]}) :on-error #(log/error "failed to start messenger")}]})
(fx/defn messenger-started (rf/defn messenger-started
{:events [::messenger-started]} {:events [::messenger-started]}
[{:keys [db] :as cofx} {:keys [mailservers] :as response}] [{:keys [db] :as cofx} {:keys [mailservers] :as response}]
(log/info "Messenger started") (log/info "Messenger started")
(fx/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
(assoc :messenger/started? true) (assoc :messenger/started? true)
(add-mailservers mailservers))} (add-mailservers mailservers))}
+33 -33
View File
@@ -16,7 +16,7 @@
[status-im.data-store.messages :as data-store.messages] [status-im.data-store.messages :as data-store.messages]
[status-im.group-chats.core :as models.group] [status-im.group-chats.core :as models.group]
[status-im.multiaccounts.update.core :as update.core] [status-im.multiaccounts.update.core :as update.core]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.multiaccounts.model :as multiaccounts.model] [status-im.multiaccounts.model :as multiaccounts.model]
@@ -25,13 +25,13 @@
[status-im.browser.core :as browser] [status-im.browser.core :as browser]
[clojure.string :as string])) [clojure.string :as string]))
(fx/defn process-next (rf/defn process-next
[cofx ^js response-js sync-handler] [cofx ^js response-js sync-handler]
(if sync-handler (if sync-handler
(sync-handler cofx response-js true) (sync-handler cofx response-js true)
{:utils/dispatch-later [{:ms 20 :dispatch [:process-response response-js]}]})) {:utils/dispatch-later [{:ms 20 :dispatch [:process-response response-js]}]}))
(fx/defn process-response (rf/defn process-response
{:events [:process-response]} {:events [:process-response]}
[{:keys [db] :as cofx} ^js response-js process-async] [{:keys [db] :as cofx} ^js response-js process-async]
(let [^js communities (.-communities response-js) (let [^js communities (.-communities response-js)
@@ -59,7 +59,7 @@
(seq chats) (seq chats)
(do (do
(js-delete response-js "chats") (js-delete response-js "chats")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(models.chat/ensure-chats (map data-store.chats/<-rpc (types/js->clj chats))))) (models.chat/ensure-chats (map data-store.chats/<-rpc (types/js->clj chats)))))
@@ -69,7 +69,7 @@
(seq activity-notifications) (seq activity-notifications)
(do (do
(js-delete response-js "activityCenterNotifications") (js-delete response-js "activityCenterNotifications")
(fx/merge cofx (rf/merge cofx
(->> activity-notifications (->> activity-notifications
types/js->clj types/js->clj
(map data-store.activities/<-rpc) (map data-store.activities/<-rpc)
@@ -79,7 +79,7 @@
(seq installations) (seq installations)
(let [installations-clj (types/js->clj installations)] (let [installations-clj (types/js->clj installations)]
(js-delete response-js "installations") (js-delete response-js "installations")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(models.pairing/handle-installations installations-clj))) (models.pairing/handle-installations installations-clj)))
@@ -88,7 +88,7 @@
^js chats (.-chatsForContacts response-js)] ^js chats (.-chatsForContacts response-js)]
(js-delete response-js "contacts") (js-delete response-js "contacts")
(js-delete response-js "chatsForContacts") (js-delete response-js "chatsForContacts")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(models.contact/ensure-contacts (models.contact/ensure-contacts
(map data-store.contacts/<-rpc contacts-clj) chats))) (map data-store.contacts/<-rpc contacts-clj) chats)))
@@ -96,69 +96,69 @@
(seq communities) (seq communities)
(let [communities-clj (types/js->clj communities)] (let [communities-clj (types/js->clj communities)]
(js-delete response-js "communities") (js-delete response-js "communities")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(models.communities/handle-communities communities-clj))) (models.communities/handle-communities communities-clj)))
(seq bookmarks) (seq bookmarks)
(let [bookmarks-clj (types/js->clj bookmarks)] (let [bookmarks-clj (types/js->clj bookmarks)]
(js-delete response-js "bookmarks") (js-delete response-js "bookmarks")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(browser/handle-bookmarks bookmarks-clj))) (browser/handle-bookmarks bookmarks-clj)))
(seq pin-messages) (seq pin-messages)
(let [pin-messages (types/js->clj pin-messages)] (let [pin-messages (types/js->clj pin-messages)]
(js-delete response-js "pinMessages") (js-delete response-js "pinMessages")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(messages.pin/receive-signal (map data-store.messages/<-rpc pin-messages)))) (messages.pin/receive-signal (map data-store.messages/<-rpc pin-messages))))
(seq removed-chats) (seq removed-chats)
(let [removed-chats-clj (types/js->clj removed-chats)] (let [removed-chats-clj (types/js->clj removed-chats)]
(js-delete response-js "removedChats") (js-delete response-js "removedChats")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(models.communities/handle-removed-chats removed-chats-clj))) (models.communities/handle-removed-chats removed-chats-clj)))
(seq requests-to-join-community) (seq requests-to-join-community)
(let [request-js (types/js->clj (.pop requests-to-join-community))] (let [request-js (types/js->clj (.pop requests-to-join-community))]
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(models.communities/handle-request-to-join request-js))) (models.communities/handle-request-to-join request-js)))
(seq emoji-reactions) (seq emoji-reactions)
(let [reactions (types/js->clj emoji-reactions)] (let [reactions (types/js->clj emoji-reactions)]
(js-delete response-js "emojiReactions") (js-delete response-js "emojiReactions")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(models.reactions/receive-signal (map data-store.reactions/<-rpc reactions)))) (models.reactions/receive-signal (map data-store.reactions/<-rpc reactions))))
(seq invitations) (seq invitations)
(let [invitations (types/js->clj invitations)] (let [invitations (types/js->clj invitations)]
(js-delete response-js "invitations") (js-delete response-js "invitations")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(models.group/handle-invitations (map data-store.invitations/<-rpc invitations)))) (models.group/handle-invitations (map data-store.invitations/<-rpc invitations))))
(seq removed-messages) (seq removed-messages)
(let [removed-messages-clj (types/js->clj removed-messages)] (let [removed-messages-clj (types/js->clj removed-messages)]
(js-delete response-js "removedMessages") (js-delete response-js "removedMessages")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(models.message/handle-removed-messages removed-messages-clj))) (models.message/handle-removed-messages removed-messages-clj)))
(seq cleared-histories) (seq cleared-histories)
(let [cleared-histories-clj (types/js->clj cleared-histories)] (let [cleared-histories-clj (types/js->clj cleared-histories)]
(js-delete response-js "clearedHistories") (js-delete response-js "clearedHistories")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(models.message/handle-cleared-histories-messages cleared-histories-clj))) (models.message/handle-cleared-histories-messages cleared-histories-clj)))
(seq visibility-status-updates) (seq visibility-status-updates)
(let [visibility-status-updates-clj (types/js->clj visibility-status-updates)] (let [visibility-status-updates-clj (types/js->clj visibility-status-updates)]
(js-delete response-js "statusUpdates") (js-delete response-js "statusUpdates")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(models.visibility-status-updates/handle-visibility-status-updates (models.visibility-status-updates/handle-visibility-status-updates
visibility-status-updates-clj))) visibility-status-updates-clj)))
@@ -166,28 +166,28 @@
(seq accounts) (seq accounts)
(do (do
(js-delete response-js "accounts") (js-delete response-js "accounts")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(multiaccounts.login/update-wallet-accounts (types/js->clj accounts)))) (multiaccounts.login/update-wallet-accounts (types/js->clj accounts))))
(seq settings) (seq settings)
(do (do
(js-delete response-js "settings") (js-delete response-js "settings")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(update.core/set-many-js settings))) (update.core/set-many-js settings)))
(seq identity-images) (seq identity-images)
(let [images-clj (map types/js->clj identity-images)] (let [images-clj (map types/js->clj identity-images)]
(js-delete response-js "identityImages") (js-delete response-js "identityImages")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(update.core/optimistic :images images-clj))) (update.core/optimistic :images images-clj)))
(some? current-visibility-status) (some? current-visibility-status)
(let [current-visibility-status-clj (types/js->clj current-visibility-status)] (let [current-visibility-status-clj (types/js->clj current-visibility-status)]
(js-delete response-js "currentStatus") (js-delete response-js "currentStatus")
(fx/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(models.visibility-status-updates/sync-visibility-status-update (models.visibility-status-updates/sync-visibility-status-update
current-visibility-status-clj)))))) current-visibility-status-clj))))))
@@ -240,7 +240,7 @@
(- (.-clock b) (.-clock a))))) (- (.-clock b) (.-clock a)))))
(js-delete response-js "messages"))) (js-delete response-js "messages")))
(fx/defn sanitize-messages-and-process-response (rf/defn sanitize-messages-and-process-response
"before processing we want to filter and sort messages, so we can process first only messages which will be showed" "before processing we want to filter and sort messages, so we can process first only messages which will be showed"
{:events [:sanitize-messages-and-process-response]} {:events [:sanitize-messages-and-process-response]}
[{:keys [db] :as cofx} ^js response-js process-async] [{:keys [db] :as cofx} ^js response-js process-async]
@@ -252,7 +252,7 @@
:current-chat-id current-chat-id} :current-chat-id current-chat-id}
(.-messages response-js))] (.-messages response-js))]
(sort-js-messages! response-js messages) (sort-js-messages! response-js messages)
(fx/merge cofx (rf/merge cofx
{:db db {:db db
:utils/dispatch-later (concat [] :utils/dispatch-later (concat []
(when (seq statuses) (when (seq statuses)
@@ -262,16 +262,16 @@
{:ms 100 :dispatch [:watch-tx nil transaction-hash]})))} {:ms 100 :dispatch [:watch-tx nil transaction-hash]})))}
(process-response response-js process-async))))) (process-response response-js process-async)))))
(fx/defn remove-hash (rf/defn remove-hash
[{:keys [db]} envelope-hash] [{:keys [db]} envelope-hash]
{:db (update db :transport/message-envelopes dissoc envelope-hash)}) {:db (update db :transport/message-envelopes dissoc envelope-hash)})
(fx/defn check-confirmations (rf/defn check-confirmations
[{:keys [db] :as cofx} status chat-id message-id] [{:keys [db] :as cofx} status chat-id message-id]
(when-let [{:keys [pending-confirmations not-sent]} (when-let [{:keys [pending-confirmations not-sent]}
(get-in db [:transport/message-ids->confirmations message-id])] (get-in db [:transport/message-ids->confirmations message-id])]
(if (zero? (dec pending-confirmations)) (if (zero? (dec pending-confirmations))
(fx/merge cofx (rf/merge cofx
{:db (update db {:db (update db
:transport/message-ids->confirmations :transport/message-ids->confirmations
dissoc message-id)} dissoc message-id)}
@@ -288,7 +288,7 @@
[:transport/message-ids->confirmations message-id] [:transport/message-ids->confirmations message-id]
confirmations)})))) confirmations)}))))
(fx/defn update-envelope-status (rf/defn update-envelope-status
[{:keys [db] :as cofx} message-id status] [{:keys [db] :as cofx} message-id status]
(if-let [{:keys [chat-id]} (if-let [{:keys [chat-id]}
(get-in db [:transport/message-envelopes message-id])] (get-in db [:transport/message-envelopes message-id])]
@@ -298,13 +298,13 @@
;; came too early ;; came too early
{:db (update-in db [:transport/message-confirmations message-id] conj status)})) {:db (update-in db [:transport/message-confirmations message-id] conj status)}))
(fx/defn update-envelopes-status (rf/defn update-envelopes-status
[{:keys [db] :as cofx} message-id status] [{:keys [db] :as cofx} message-id status]
(when (or (not= status :not-sent) (when (or (not= status :not-sent)
(= :online (:network db))) (= :online (:network db)))
(apply fx/merge cofx (map #(update-envelope-status % status) message-id)))) (apply rf/merge cofx (map #(update-envelope-status % status) message-id))))
(fx/defn set-message-envelope-hash (rf/defn set-message-envelope-hash
"message-type is used for tracking" "message-type is used for tracking"
[{:keys [db] :as cofx} chat-id message-id message-type] [{:keys [db] :as cofx} chat-id message-id message-type]
;; Check first if the confirmation has already arrived ;; Check first if the confirmation has already arrived
@@ -321,14 +321,14 @@
:message-type message-type}) :message-type message-type})
(update-in [:transport/message-ids->confirmations message-id] (update-in [:transport/message-ids->confirmations message-id]
#(or % {:pending-confirmations 1})))})] #(or % {:pending-confirmations 1})))})]
(apply fx/merge cofx (conj check-confirmations-fx add-envelope-data)))) (apply rf/merge cofx (conj check-confirmations-fx add-envelope-data))))
(fx/defn transport-message-sent (rf/defn transport-message-sent
{:events [:transport/message-sent]} {:events [:transport/message-sent]}
[cofx response-js] [cofx response-js]
(let [set-hash-fxs (map (fn [{:keys [localChatId id messageType]}] (let [set-hash-fxs (map (fn [{:keys [localChatId id messageType]}]
(set-message-envelope-hash localChatId id messageType)) (set-message-envelope-hash localChatId id messageType))
(types/js->clj (.-messages response-js)))] (types/js->clj (.-messages response-js)))]
(apply fx/merge cofx (apply rf/merge cofx
(conj set-hash-fxs (conj set-hash-fxs
#(sanitize-messages-and-process-response % response-js false))))) #(sanitize-messages-and-process-response % response-js false)))))
@@ -2,7 +2,7 @@
status-im.transport.message.protocol status-im.transport.message.protocol
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(defn build-message [{:keys [chat-id (defn build-message [{:keys [chat-id
@@ -26,7 +26,7 @@
:sticker sticker :sticker sticker
:contentType content-type}) :contentType content-type})
(fx/defn send-chat-messages [_ messages] (rf/defn send-chat-messages [_ messages]
{::json-rpc/call [{:method "wakuext_sendChatMessages" {::json-rpc/call [{:method "wakuext_sendChatMessages"
:params [(mapv build-message messages)] :params [(mapv build-message messages)]
:js-response true :js-response true
@@ -35,14 +35,14 @@
(log/warn "failed to send a message" %) (log/warn "failed to send a message" %)
(js/alert (str "failed to send a message: " %)))}]}) (js/alert (str "failed to send a message: " %)))}]})
(fx/defn send-reaction [_ {:keys [message-id chat-id emoji-id]}] (rf/defn send-reaction [_ {:keys [message-id chat-id emoji-id]}]
{::json-rpc/call [{:method "wakuext_sendEmojiReaction" {::json-rpc/call [{:method "wakuext_sendEmojiReaction"
:params [chat-id message-id emoji-id] :params [chat-id message-id emoji-id]
:js-response true :js-response true
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %]) :on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
:on-error #(log/error "failed to send a reaction" %)}]}) :on-error #(log/error "failed to send a reaction" %)}]})
(fx/defn send-retract-reaction [_ {:keys [emoji-reaction-id]}] (rf/defn send-retract-reaction [_ {:keys [emoji-reaction-id]}]
{::json-rpc/call [{:method "wakuext_sendEmojiReactionRetraction" {::json-rpc/call [{:method "wakuext_sendEmojiReactionRetraction"
:params [emoji-reaction-id] :params [emoji-reaction-id]
:js-response true :js-response true
@@ -1,6 +1,6 @@
(ns status-im.ui.components.invite.events (ns status-im.ui.components.invite.events
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[status-im.utils.universal-links.utils :as universal-links])) [status-im.utils.universal-links.utils :as universal-links]))
@@ -10,7 +10,7 @@
(fn [content] (fn [content]
(.share ^js react/sharing (clj->js content)))) (.share ^js react/sharing (clj->js content))))
(fx/defn share-link (rf/defn share-link
{:events [::share-link]} {:events [::share-link]}
[{:keys [db]}] [{:keys [db]}]
(let [{:keys [public-key preferred-name]} (get db :multiaccount) (let [{:keys [public-key preferred-name]} (get db :multiaccount)
@@ -17,7 +17,7 @@
[status-im.ui.components.icons.icons :as icons] [status-im.ui.components.icons.icons :as icons]
[status-im.utils.utils :as utils.utils] [status-im.utils.utils :as utils.utils]
[status-im.utils.fs :as fs] [status-im.utils.fs :as fs]
[status-im.utils.fx :as fx])) [utils.re-frame :as rf]))
;; reference db levels ;; reference db levels
(def total-silence-db -160) (def total-silence-db -160)
@@ -70,7 +70,7 @@
;; to be called when app goes in background ;; to be called when app goes in background
(defonce on-background-cb (atom #())) (defonce on-background-cb (atom #()))
(fx/defn on-background (rf/defn on-background
{:events [:audio-recorder/on-background]} {:events [:audio-recorder/on-background]}
[_] [_]
(when @on-background-cb (when @on-background-cb
@@ -6,7 +6,7 @@
[quo.components.text :as text] [quo.components.text :as text]
[quo.design-system.colors :as colors] [quo.design-system.colors :as colors]
[status-im.ui.screens.chat.components.style :as styles] [status-im.ui.screens.chat.components.style :as styles]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.ui.screens.chat.components.reply :as reply] [status-im.ui.screens.chat.components.reply :as reply]
[status-im.multiaccounts.core :as multiaccounts] [status-im.multiaccounts.core :as multiaccounts]
[status-im.chat.constants :as chat.constants] [status-im.chat.constants :as chat.constants]
@@ -187,7 +187,7 @@
(when platform/ios? (when platform/ios?
(re-frame/dispatch [::mentions/calculate-suggestions mentionable-users])))) (re-frame/dispatch [::mentions/calculate-suggestions mentionable-users]))))
(fx/defn set-input-text (rf/defn set-input-text
"Set input text for current-chat. Takes db and input text and cofx "Set input text for current-chat. Takes db and input text and cofx
as arguments and returns new fx. Always clear all validation messages." as arguments and returns new fx. Always clear all validation messages."
{:events [:chat.ui.input/set-chat-input-text]} {:events [:chat.ui.input/set-chat-input-text]}
@@ -4,7 +4,7 @@
[reagent.core :as reagent] [reagent.core :as reagent]
[goog.string :as gstring] [goog.string :as gstring]
[status-im.audio.core :as audio] [status-im.audio.core :as audio]
[status-im.utils.fx :as fx] [utils.re-frame :as rf]
[status-im.ui.screens.chat.styles.message.audio-old :as style] [status-im.ui.screens.chat.styles.message.audio-old :as style]
[status-im.ui.components.animation :as anim] [status-im.ui.components.animation :as anim]
[quo.design-system.colors :as colors] [quo.design-system.colors :as colors]
@@ -184,7 +184,7 @@
:accessibility-label :play-pause-audio-message-button :accessibility-label :play-pause-audio-message-button
:color color}]]))) :color color}]])))
(fx/defn on-background (rf/defn on-background
{:events [:audio-message/on-background]} {:events [:audio-message/on-background]}
[_] [_]
(when (and @current-active-state-ref-ref (when (and @current-active-state-ref-ref
@@ -6,7 +6,7 @@
[quo.core :as quo] [quo.core :as quo]
[reagent.core :as reagent] [reagent.core :as reagent]
[status-im.ui.components.list.views :as list] [status-im.ui.components.list.views :as list]
[status-im.utils.handlers :refer [<sub]] [utils.re-frame :as rf]
[status-im.ui.screens.chat.message.message :as message])) [status-im.ui.screens.chat.message.message :as message]))
(def selected-unpin (reagent/atom nil)) (def selected-unpin (reagent/atom nil))
@@ -58,7 +58,7 @@
:padding-top 10}}])) :padding-top 10}}]))
(defn pin-limit-popover [] (defn pin-limit-popover []
(let [{:keys [message]} (<sub [:popover/popover])] (let [{:keys [message]} (rf/sub [:popover/popover])]
[react/view {:style {:flex-shrink 1}} [react/view {:style {:flex-shrink 1}}
[react/view {:style {:height 60 [react/view {:style {:height 60
:justify-content :center}} :justify-content :center}}
@@ -1,6 +1,6 @@
(ns status-im.ui.screens.communities.channel-details (ns status-im.ui.screens.communities.channel-details
(:require [quo.core :as quo] (:require [quo.core :as quo]
[status-im.utils.handlers :refer [>evt <sub]] [utils.re-frame :as rf]
[status-im.ui.components.profile-header.view :as profile-header] [status-im.ui.components.profile-header.view :as profile-header]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[clojure.string :as string] [clojure.string :as string]
@@ -8,28 +8,28 @@
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
(defn view [] (defn view []
(let [{:keys [chat-id]} (<sub [:get-screen-params])] (let [{:keys [chat-id]} (rf/sub [:get-screen-params])]
(fn [] (fn []
(let [current-chat (<sub [:chat-by-id chat-id]) (let [current-chat (rf/sub [:chat-by-id chat-id])
{:keys [chat-name color description community-id emoji]} current-chat {:keys [chat-name color description community-id emoji]} current-chat
{:keys [position]} (<sub [:chats/community-chat-by-id community-id chat-id]) {:keys [position]} (rf/sub [:chats/community-chat-by-id community-id chat-id])
category (<sub [:chats/category-by-chat-id community-id chat-id]) category (rf/sub [:chats/category-by-chat-id community-id chat-id])
{:keys [admin]} (<sub [:communities/community community-id]) {:keys [admin]} (rf/sub [:communities/community community-id])
pinned-messages (<sub [:chats/pinned chat-id])] pinned-messages (rf/sub [:chats/pinned chat-id])]
[quo/animated-header {:left-accessories [{:icon :main-icons/arrow-left [quo/animated-header {:left-accessories [{:icon :main-icons/arrow-left
:accessibility-label :back-button :accessibility-label :back-button
:on-press #(>evt [:navigate-back])}] :on-press #(rf/dispatch [:navigate-back])}]
:right-accessories (when admin [{:icon :edit :right-accessories (when admin [{:icon :edit
:accessibility-label :invite-button :accessibility-label :invite-button
:on-press #(>evt [::communities/edit-channel-pressed :on-press #(rf/dispatch [::communities/edit-channel-pressed
community-id community-id
chat-name chat-name
description description
color color
emoji emoji
chat-id chat-id
(:id category) (:id category)
position])}]) position])}])
:extended-header (profile-header/extended-header :extended-header (profile-header/extended-header
{:title chat-name {:title chat-name
:color color :color color
@@ -43,9 +43,9 @@
[quo/separator {:style {:margin-vertical 8}}] [quo/separator {:style {:margin-vertical 8}}]
(when admin (when admin
[quo/list-item {:title (i18n/label :t/category) [quo/list-item {:title (i18n/label :t/category)
:on-press #(>evt [:open-modal :select-category {:chat current-chat :on-press #(rf/dispatch [:open-modal :select-category {:chat current-chat
:category category :category category
:community-id community-id}]) :community-id community-id}])
:chevron true :chevron true
:accessory :text :accessory :text
:accessory-text (if category :accessory-text (if category
@@ -3,7 +3,7 @@
[quo.core :as quo] [quo.core :as quo]
[clojure.string :as string] [clojure.string :as string]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[status-im.utils.handlers :refer [>evt <sub]] [utils.re-frame :as rf]
[status-im.communities.core :as communities] [status-im.communities.core :as communities]
[status-im.ui.components.keyboard-avoid-presentation :as kb-presentation] [status-im.ui.components.keyboard-avoid-presentation :as kb-presentation]
[status-im.ui.components.emoji-thumbnail.styles :as styles] [status-im.ui.components.emoji-thumbnail.styles :as styles]
@@ -11,29 +11,29 @@
[status-im.ui.components.emoji-thumbnail.color-picker :as color-picker])) [status-im.ui.components.emoji-thumbnail.color-picker :as color-picker]))
(defn thumbnail-preview-section [] (defn thumbnail-preview-section []
(let [{:keys [color emoji]} (<sub [:communities/create-channel]) (let [{:keys [color emoji]} (rf/sub [:communities/create-channel])
size styles/emoji-thumbnail-preview-size] size styles/emoji-thumbnail-preview-size]
[rn/view styles/emoji-thumbnail-preview [rn/view styles/emoji-thumbnail-preview
[emoji-thumbnail-preview/emoji-thumbnail [emoji-thumbnail-preview/emoji-thumbnail
emoji color size]])) emoji color size]]))
(defn color-circle [item] (defn color-circle [item]
(let [{:keys [color]} (<sub [:communities/create-channel]) (let [{:keys [color]} (rf/sub [:communities/create-channel])
item-color (:color item) item-color (:color item)
key (:key key) key (:key key)
color-selected? (= (string/lower-case item-color) (string/lower-case color))] color-selected? (= (string/lower-case item-color) (string/lower-case color))]
[react/touchable-opacity {:key key [react/touchable-opacity {:key key
:accessibility-label :color-circle :accessibility-label :color-circle
:on-press #(>evt [::communities/create-channel-field :color item-color])} :on-press #(rf/dispatch [::communities/create-channel-field :color item-color])}
[rn/view {:style (styles/emoji-picker-color-border item-color color-selected?)} [rn/view {:style (styles/emoji-picker-color-border item-color color-selected?)}
[rn/view {:style (styles/emoji-picker-color item-color)}]]])) [rn/view {:style (styles/emoji-picker-color item-color)}]]]))
(defn update-emoji [emoji] (defn update-emoji [emoji]
(when-not (string/blank? emoji) (when-not (string/blank? emoji)
(>evt [::communities/create-channel-field :emoji emoji]))) (rf/dispatch [::communities/create-channel-field :emoji emoji])))
(defn emoji-keyboard-section [] (defn emoji-keyboard-section []
(let [{:keys [width height]} (<sub [:dimensions/window]) (let [{:keys [width height]} (rf/sub [:dimensions/window])
keyboard_height (if (> width height) 400 (- height styles/emoji-picker-upper-components-size))] keyboard_height (if (> width height) 400 (- height styles/emoji-picker-upper-components-size))]
[rn/view {:style {:height keyboard_height} :accessibility-label :emoji-keyboard-container} [rn/view {:style {:height keyboard_height} :accessibility-label :emoji-keyboard-container}
[rn/emoji-keyboard (styles/emoji-keyboard #(update-emoji (.-emoji ^js %)))]])) [rn/emoji-keyboard (styles/emoji-keyboard #(update-emoji (.-emoji ^js %)))]]))
@@ -3,7 +3,7 @@
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[quo.core :as quo] [quo.core :as quo]
[clojure.string :as string] [clojure.string :as string]
[status-im.utils.handlers :refer [>evt <sub]] [utils.re-frame :as rf]
[status-im.communities.core :as communities] [status-im.communities.core :as communities]
[status-im.ui.components.toolbar :as toolbar] [status-im.ui.components.toolbar :as toolbar]
[status-im.utils.image :as utils.image] [status-im.utils.image :as utils.image]
@@ -33,8 +33,8 @@
(js/setTimeout (js/setTimeout
(fn [] (fn []
(react/show-image-picker (react/show-image-picker
#(do (>evt [::communities/create-field :image (.-path ^js %)]) #(do (rf/dispatch [::communities/create-field :image (.-path ^js %)])
(>evt [::communities/create-field :new-image (.-path ^js %)])) (rf/dispatch [::communities/create-field :new-image (.-path ^js %)]))
crop-opts)) crop-opts))
300)) 300))
@@ -44,8 +44,8 @@
(js/setTimeout (js/setTimeout
(fn [] (fn []
(react/show-image-picker-camera (react/show-image-picker-camera
#(do (>evt [::communities/create-field :image (.-path ^js %)]) #(do (rf/dispatch [::communities/create-field :image (.-path ^js %)])
(>evt [::communities/create-field :new-image (.-path ^js %)])) (rf/dispatch [::communities/create-field :new-image (.-path ^js %)]))
crop-opts)) crop-opts))
300)) 300))
@@ -57,14 +57,14 @@
:icon :main-icons/camera :icon :main-icons/camera
:title (i18n/label :t/community-image-take) :title (i18n/label :t/community-image-take)
:on-press #(do :on-press #(do
(>evt [:bottom-sheet/hide]) (rf/dispatch [:bottom-sheet/hide])
(take-pic))}] (take-pic))}]
[quo/list-item {:accessibility-label :pick-photo [quo/list-item {:accessibility-label :pick-photo
:icon :main-icons/gallery :icon :main-icons/gallery
:theme :accent :theme :accent
:title (i18n/label :t/community-image-pick) :title (i18n/label :t/community-image-pick)
:on-press #(do :on-press #(do
(>evt [:bottom-sheet/hide]) (rf/dispatch [:bottom-sheet/hide])
(pick-pic))}] (pick-pic))}]
(when (and has-picture (not editing?)) (when (and has-picture (not editing?))
[quo/list-item {:accessibility-label :remove-photo [quo/list-item {:accessibility-label :remove-photo
@@ -72,15 +72,15 @@
:theme :accent :theme :accent
:title (i18n/label :t/community-image-remove) :title (i18n/label :t/community-image-remove)
:on-press #(do :on-press #(do
(>evt [:bottom-sheet/hide]) (rf/dispatch [:bottom-sheet/hide])
(>evt [::communities/remove-field :image]))}])])) (rf/dispatch [::communities/remove-field :image]))}])]))
(defn photo-picker [] (defn photo-picker []
(let [{:keys [image editing?]} (<sub [:communities/create])] (let [{:keys [image editing?]} (rf/sub [:communities/create])]
[rn/view {:style {:padding-top 16 [rn/view {:style {:padding-top 16
:align-items :center}} :align-items :center}}
[rn/touchable-opacity {:on-press #(>evt [:bottom-sheet/show-sheet [rn/touchable-opacity {:on-press #(rf/dispatch [:bottom-sheet/show-sheet
{:content (bottom-sheet (boolean image) editing?)}])} {:content (bottom-sheet (boolean image) editing?)}])}
[rn/view {:style {:width 128 [rn/view {:style {:width 128
:height 128}} :height 128}}
[rn/view {:style {:flex 1 [rn/view {:style {:flex 1
@@ -129,7 +129,7 @@
(str (count text) "/" max-length)]]) (str (count text) "/" max-length)]])
(defn form [] (defn form []
(let [{:keys [name description membership editing?]} (<sub [:communities/create])] (let [{:keys [name description membership editing?]} (rf/sub [:communities/create])]
[rn/scroll-view {:keyboard-should-persist-taps :handled [rn/scroll-view {:keyboard-should-persist-taps :handled
:style {:flex 1} :style {:flex 1}
:content-container-style {:padding-vertical 16}} :content-container-style {:padding-vertical 16}}
@@ -142,7 +142,7 @@
[quo/text-input [quo/text-input
{:placeholder (i18n/label :t/name-your-community-placeholder) {:placeholder (i18n/label :t/name-your-community-placeholder)
:default-value name :default-value name
:on-change-text #(>evt [::communities/create-field :name %]) :on-change-text #(rf/dispatch [::communities/create-field :name %])
:auto-focus true}]] :auto-focus true}]]
[rn/view {:style {:padding-bottom 16 [rn/view {:style {:padding-bottom 16
:padding-top 10 :padding-top 10
@@ -154,7 +154,7 @@
{:placeholder (i18n/label :t/give-a-short-description-community) {:placeholder (i18n/label :t/give-a-short-description-community)
:multiline true :multiline true
:default-value description :default-value description
:on-change-text #(>evt [::communities/create-field :description %])}]] :on-change-text #(rf/dispatch [::communities/create-field :description %])}]]
[quo/list-header {:color :main} [quo/list-header {:color :main}
(i18n/label :t/community-thumbnail-image)] (i18n/label :t/community-thumbnail-image)]
[photo-picker] [photo-picker]
@@ -163,14 +163,14 @@
[quo/list-item {:title (i18n/label :t/membership-button) [quo/list-item {:title (i18n/label :t/membership-button)
:accessory-text (i18n/label (get-in memberships/options [membership :title] :t/membership-none)) :accessory-text (i18n/label (get-in memberships/options [membership :title] :t/membership-none))
:accessory :text :accessory :text
:on-press #(>evt [:navigate-to :community-membership]) :on-press #(rf/dispatch [:navigate-to :community-membership])
:chevron true :chevron true
:size :small}] :size :small}]
[quo/list-footer [quo/list-footer
(i18n/label (get-in memberships/options [membership :description] :t/membership-none-placeholder))]])])) (i18n/label (get-in memberships/options [membership :description] :t/membership-none-placeholder))]])]))
(defn view [] (defn view []
(let [{:keys [name description]} (<sub [:communities/create])] (let [{:keys [name description]} (rf/sub [:communities/create])]
[rn/keyboard-avoiding-view {:style {:flex 1}} [rn/keyboard-avoiding-view {:style {:flex 1}}
[form] [form]
[toolbar/toolbar [toolbar/toolbar
@@ -1,6 +1,6 @@
(ns status-im.ui.screens.communities.create-category (ns status-im.ui.screens.communities.create-category
(:require [status-im.ui.components.keyboard-avoid-presentation :as kb-presentation] (:require [status-im.ui.components.keyboard-avoid-presentation :as kb-presentation]
[status-im.utils.handlers :refer [<sub]] [utils.re-frame :as rf]
[status-im.ui.components.toolbar :as toolbar] [status-im.ui.components.toolbar :as toolbar]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[quo.core :as quo] [quo.core :as quo]
@@ -32,11 +32,11 @@
{:on-press on-change}]]])) {:on-press on-change}]]]))
(defn view [] (defn view []
(let [{:keys [community-id]} (<sub [:get-screen-params]) (let [{:keys [community-id]} (rf/sub [:get-screen-params])
category-name (reagent/atom "") category-name (reagent/atom "")
_ (reset! selected-items #{})] _ (reset! selected-items #{})]
(fn [] (fn []
(let [chats (<sub [:chats/with-empty-category-by-community-id community-id])] (let [chats (rf/sub [:chats/with-empty-category-by-community-id community-id])]
[kb-presentation/keyboard-avoiding-view {:style {:flex 1}} [kb-presentation/keyboard-avoiding-view {:style {:flex 1}}
[react/view {:flex 1} [react/view {:flex 1}
[react/view {:padding-horizontal 16} [react/view {:padding-horizontal 16}
@@ -6,7 +6,7 @@
[status-im.ui.components.toolbar :as toolbar] [status-im.ui.components.toolbar :as toolbar]
[status-im.communities.core :as communities] [status-im.communities.core :as communities]
[utils.debounce :as debounce] [utils.debounce :as debounce]
[status-im.utils.handlers :refer [>evt <sub]] [utils.re-frame :as rf]
[status-im.ui.screens.communities.create :as create] [status-im.ui.screens.communities.create :as create]
[status-im.ui.components.keyboard-avoid-presentation :as kb-presentation] [status-im.ui.components.keyboard-avoid-presentation :as kb-presentation]
[status-im.ui.components.emoji-thumbnail.styles :as styles] [status-im.ui.components.emoji-thumbnail.styles :as styles]
@@ -19,15 +19,15 @@
(<= (count channel-description) create/max-description-length))) (<= (count channel-description) create/max-description-length)))
(defn thumbnail [] (defn thumbnail []
(let [{:keys [color emoji]} (<sub [:communities/create-channel]) (let [{:keys [color emoji]} (rf/sub [:communities/create-channel])
size styles/emoji-thumbnail-preview-size] size styles/emoji-thumbnail-preview-size]
[rn/view styles/emoji-thumbnail-preview [rn/view styles/emoji-thumbnail-preview
[emoji-thumbnail-preview/emoji-thumbnail-touchable [emoji-thumbnail-preview/emoji-thumbnail-touchable
emoji color size emoji color size
#(>evt [:open-modal :community-emoji-thumbnail-picker nil])]])) #(rf/dispatch [:open-modal :community-emoji-thumbnail-picker nil])]]))
(defn form [] (defn form []
(let [{:keys [name description]} (<sub [:communities/create-channel])] (let [{:keys [name description]} (rf/sub [:communities/create-channel])]
[rn/scroll-view {:style {:flex 1} [rn/scroll-view {:style {:flex 1}
:content-container-style {:padding-bottom 16}} :content-container-style {:padding-bottom 16}}
[:<> [:<>
@@ -35,7 +35,7 @@
[rn/view {:padding-horizontal 16} [rn/view {:padding-horizontal 16}
[quo/text-input [quo/text-input
{:placeholder (i18n/label :t/name-your-channel-placeholder) {:placeholder (i18n/label :t/name-your-channel-placeholder)
:on-change-text #(>evt [::communities/create-channel-field :name %]) :on-change-text #(rf/dispatch [::communities/create-channel-field :name %])
:default-value name :default-value name
:auto-focus false}]] :auto-focus false}]]
[quo/separator {:style {:margin-vertical 16}}] [quo/separator {:style {:margin-vertical 16}}]
@@ -47,10 +47,10 @@
{:placeholder (i18n/label :t/give-a-short-description-community) {:placeholder (i18n/label :t/give-a-short-description-community)
:multiline true :multiline true
:default-value description :default-value description
:on-change-text #(>evt [::communities/create-channel-field :description %])}]]]])) :on-change-text #(rf/dispatch [::communities/create-channel-field :description %])}]]]]))
(defn view [] (defn view []
(let [{:keys [name description]} (<sub [:communities/create-channel])] (let [{:keys [name description]} (rf/sub [:communities/create-channel])]
[kb-presentation/keyboard-avoiding-view {:style {:flex 1}} [kb-presentation/keyboard-avoiding-view {:style {:flex 1}}
[quo/separator] [quo/separator]
[form] [form]
@@ -2,12 +2,12 @@
(:require [quo.core :as quo] (:require [quo.core :as quo]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.ui.screens.communities.create :as community.create] [status-im.ui.screens.communities.create :as community.create]
[status-im.utils.handlers :refer [>evt <sub]] [utils.re-frame :as rf]
[status-im.communities.core :as communities] [status-im.communities.core :as communities]
[status-im.ui.components.toolbar :as toolbar])) [status-im.ui.components.toolbar :as toolbar]))
(defn edit [] (defn edit []
(let [{:keys [name description]} (<sub [:communities/create])] (let [{:keys [name description]} (rf/sub [:communities/create])]
[:<> [:<>
[community.create/form] [community.create/form]
[toolbar/toolbar [toolbar/toolbar
@@ -15,5 +15,5 @@
:center :center
[quo/button {:disabled (not (community.create/valid? name description)) [quo/button {:disabled (not (community.create/valid? name description))
:type :secondary :type :secondary
:on-press #(>evt [::communities/edit-confirmation-pressed])} :on-press #(rf/dispatch [::communities/edit-confirmation-pressed])}
(i18n/label :t/save)]}]])) (i18n/label :t/save)]}]]))
@@ -5,14 +5,14 @@
[status-im.ui.components.toolbar :as toolbar] [status-im.ui.components.toolbar :as toolbar]
[status-im.communities.core :as communities] [status-im.communities.core :as communities]
[utils.debounce :as debounce] [utils.debounce :as debounce]
[status-im.utils.handlers :refer [<sub]] [utils.re-frame :as rf]
[status-im.ui.screens.communities.create-channel :as create-channel])) [status-im.ui.screens.communities.create-channel :as create-channel]))
(defn valid? [community-name] (defn valid? [community-name]
(not (string/blank? community-name))) (not (string/blank? community-name)))
(defn view [] (defn view []
(let [{:keys [name]} (<sub [:communities/create-channel])] (let [{:keys [name]} (rf/sub [:communities/create-channel])]
(fn [] (fn []
[:<> [:<>
[create-channel/form] [create-channel/form]
@@ -3,7 +3,7 @@
[reagent.core :as reagent] [reagent.core :as reagent]
[quo.core :as quo] [quo.core :as quo]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.utils.handlers :refer [>evt]] [utils.re-frame :as rf]
[status-im.communities.core :as communities] [status-im.communities.core :as communities]
[status-im.ui.components.toolbar :as toolbar])) [status-im.ui.components.toolbar :as toolbar]))
@@ -26,5 +26,5 @@
{:show-border? true {:show-border? true
:center [quo/button {:disabled (= @community-key "") :center [quo/button {:disabled (= @community-key "")
:type :secondary :type :secondary
:on-press #(>evt [::communities/import @community-key])} :on-press #(rf/dispatch [::communities/import @community-key])}
(i18n/label :t/import)]}]]))) (i18n/label :t/import)]}]])))
@@ -5,11 +5,12 @@
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.ui.components.toolbar :as toolbar] [status-im.ui.components.toolbar :as toolbar]
[status-im.utils.handlers :refer [<sub >evt-once]] [utils.re-frame :as rf]
[status-im.communities.core :as communities] [status-im.communities.core :as communities]
[status-im.ui.components.topbar :as topbar] [status-im.ui.components.topbar :as topbar]
[status-im.ui.components.chat-icon.screen :as chat-icon.screen] [status-im.ui.components.chat-icon.screen :as chat-icon.screen]
[status-im.multiaccounts.core :as multiaccounts] [status-im.multiaccounts.core :as multiaccounts]
[utils.debounce :as debounce]
[clojure.string :as string])) [clojure.string :as string]))
(defn header [user-pk] (defn header [user-pk]
@@ -42,11 +43,11 @@
(defn invite [] (defn invite []
(let [user-pk (reagent/atom "") (let [user-pk (reagent/atom "")
contacts-selected (reagent/atom #{}) contacts-selected (reagent/atom #{})
{:keys [invite?]} (<sub [:get-screen-params])] {:keys [invite?]} (rf/sub [:get-screen-params])]
(fn [] (fn []
(let [contacts-data (<sub [:contacts/active]) (let [contacts-data (rf/sub [:contacts/active])
{:keys [permissions {:keys [permissions
can-manage-users?]} (<sub [:communities/edited-community]) can-manage-users?]} (rf/sub [:communities/edited-community])
selected @contacts-selected selected @contacts-selected
contacts (map (fn [{:keys [public-key] :as contact}] contacts (map (fn [{:keys [public-key] :as contact}]
(assoc contact :active (contains? selected public-key))) (assoc contact :active (contains? selected public-key)))
@@ -75,8 +76,9 @@
(zero? (count selected))) (zero? (count selected)))
:accessibility-label :share-community-link :accessibility-label :share-community-link
:type :secondary :type :secondary
:on-press #(>evt-once :on-press #(debounce/dispatch-and-chill
[(if can-invite? [(if can-invite?
::communities/invite-people-confirmation-pressed ::communities/invite-people-confirmation-pressed
::communities/share-community-confirmation-pressed) @user-pk selected])} ::communities/share-community-confirmation-pressed) @user-pk selected]
3000)}
(i18n/label (if can-invite? :t/invite :t/share))]}]])))) (i18n/label (if can-invite? :t/invite :t/share))]}]]))))
@@ -4,7 +4,7 @@
[reagent.core :as reagent] [reagent.core :as reagent]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[status-im.utils.handlers :refer [<sub >evt]] [utils.re-frame :as rf]
[status-im.ui.components.chat-icon.screen :as chat-icon] [status-im.ui.components.chat-icon.screen :as chat-icon]
[status-im.ui.components.unviewed-indicator :as unviewed-indicator] [status-im.ui.components.unviewed-indicator :as unviewed-indicator]
[status-im.multiaccounts.core :as multiaccounts] [status-im.multiaccounts.core :as multiaccounts]
@@ -13,8 +13,8 @@
[status-im.communities.core :as communities])) [status-im.communities.core :as communities]))
(defn hide-sheet-and-dispatch [event] (defn hide-sheet-and-dispatch [event]
(>evt [:bottom-sheet/hide]) (rf/dispatch [:bottom-sheet/hide])
(>evt event)) (rf/dispatch event))
(defn member-sheet [first-name {:keys [public-key] :as member} community-id can-kick-users? can-manage-users? admin?] (defn member-sheet [first-name {:keys [public-key] :as member} community-id can-kick-users? can-manage-users? admin?]
[:<> [:<>
@@ -33,27 +33,27 @@
[quo/list-item {:theme :negative [quo/list-item {:theme :negative
:icon :main-icons/arrow-left :icon :main-icons/arrow-left
:title (i18n/label :t/member-kick) :title (i18n/label :t/member-kick)
:on-press #(>evt [::communities/member-kick community-id public-key])}]]) :on-press #(rf/dispatch [::communities/member-kick community-id public-key])}]])
(when can-manage-users? (when can-manage-users?
[:<> [:<>
[quo/list-item {:theme :negative [quo/list-item {:theme :negative
:icon :main-icons/cancel :icon :main-icons/cancel
:title (i18n/label :t/member-ban) :title (i18n/label :t/member-ban)
:on-press #(>evt [::communities/member-ban community-id public-key])}]]) :on-press #(rf/dispatch [::communities/member-ban community-id public-key])}]])
(when admin? (when admin?
[:<> [:<>
[quo/list-item {:theme :accent [quo/list-item {:theme :accent
:icon :main-icons/make-admin :icon :main-icons/make-admin
:title (i18n/label :t/make-moderator) :title (i18n/label :t/make-moderator)
:on-press #(>evt [:community.member/add-role community-id public-key constants/community-member-role-moderator])}]])]) :on-press #(rf/dispatch [:community.member/add-role community-id public-key constants/community-member-role-moderator])}]])])
(defn render-member [public-key _ _ {:keys [community-id (defn render-member [public-key _ _ {:keys [community-id
my-public-key my-public-key
can-manage-users? can-manage-users?
can-kick-users? can-kick-users?
admin?]}] admin?]}]
(let [member (<sub [:contacts/contact-by-identity public-key]) (let [member (rf/sub [:contacts/contact-by-identity public-key])
[first-name second-name] (<sub [:contacts/contact-two-names-by-identity public-key])] [first-name second-name] (rf/sub [:contacts/contact-two-names-by-identity public-key])]
[quo/list-item [quo/list-item
{:title first-name {:title first-name
:subtitle second-name :subtitle second-name
@@ -63,9 +63,9 @@
:photo-path (multiaccounts/displayed-photo member)}] :photo-path (multiaccounts/displayed-photo member)}]
:accessory (when (not= public-key my-public-key) :accessory (when (not= public-key my-public-key)
[quo/button {:on-press [quo/button {:on-press
#(>evt [:bottom-sheet/show-sheet #(rf/dispatch [:bottom-sheet/show-sheet
{:content (fn [] {:content (fn []
[member-sheet first-name member community-id can-kick-users? can-manage-users? admin?])}]) [member-sheet first-name member community-id can-kick-users? can-manage-users? admin?])}])
:type :icon :type :icon
:theme :icon :theme :icon
:accessibility-label :menu-option} :accessibility-label :menu-option}
@@ -77,11 +77,11 @@
:title (i18n/label :t/invite-people) :title (i18n/label :t/invite-people)
:accessibility-label :community-invite-people :accessibility-label :community-invite-people
:theme :accent :theme :accent
:on-press #(>evt [:communities/invite-people-pressed community-id])}] :on-press #(rf/dispatch [:communities/invite-people-pressed community-id])}]
[quo/separator {:style {:margin-vertical 8}}]]) [quo/separator {:style {:margin-vertical 8}}]])
(defn requests-to-join [community-id] (defn requests-to-join [community-id]
(let [requests (<sub [:communities/requests-to-join-for-community community-id]) (let [requests (rf/sub [:communities/requests-to-join-for-community community-id])
requests-count (count requests)] requests-count (count requests)]
[:<> [:<>
[quo/list-item {:chevron true [quo/list-item {:chevron true
@@ -89,19 +89,19 @@
[react/view {:flex-direction :row} [react/view {:flex-direction :row}
(when (pos? requests-count) (when (pos? requests-count)
[unviewed-indicator/unviewed-indicator requests-count])] [unviewed-indicator/unviewed-indicator requests-count])]
:on-press #(>evt [:navigate-to :community-requests-to-join {:community-id community-id}]) :on-press #(rf/dispatch [:navigate-to :community-requests-to-join {:community-id community-id}])
:title (i18n/label :t/membership-requests)}] :title (i18n/label :t/membership-requests)}]
[quo/separator {:style {:margin-vertical 8}}]])) [quo/separator {:style {:margin-vertical 8}}]]))
(defn members [] (defn members []
(let [{:keys [community-id]} (<sub [:get-screen-params])] (let [{:keys [community-id]} (rf/sub [:get-screen-params])]
(fn [] (fn []
(let [my-public-key (<sub [:multiaccount/public-key]) (let [my-public-key (rf/sub [:multiaccount/public-key])
{:keys [permissions {:keys [permissions
can-manage-users? can-manage-users?
admin]} (<sub [:communities/community community-id]) admin]} (rf/sub [:communities/community community-id])
sorted-members (<sub [:communities/sorted-community-members sorted-members (rf/sub [:communities/sorted-community-members
community-id])] community-id])]
[:<> [:<>
[topbar/topbar {:title (i18n/label :t/community-members-title) [topbar/topbar {:title (i18n/label :t/community-members-title)
:subtitle (str (count sorted-members))}] :subtitle (str (count sorted-members))}]
@@ -123,5 +123,5 @@
(reagent/create-class (reagent/create-class
{:display-name "community-members-view" {:display-name "community-members-view"
:component-did-mount (fn [] :component-did-mount (fn []
(communities/fetch-requests-to-join! (get (<sub [:get-screen-params]) :community-id))) (communities/fetch-requests-to-join! (get (rf/sub [:get-screen-params]) :community-id)))
:reagent-render members})) :reagent-render members}))
@@ -3,7 +3,7 @@
[status-im.ui.components.toolbar :as toolbar] [status-im.ui.components.toolbar :as toolbar]
[quo.core :as quo] [quo.core :as quo]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.utils.handlers :refer [>evt <sub]] [utils.re-frame :as rf]
[status-im.communities.core :as communities] [status-im.communities.core :as communities]
[status-im.constants :as constants])) [status-im.constants :as constants]))
@@ -26,16 +26,16 @@
[quo/separator {:style {:margin-vertical 8}}]]) [quo/separator {:style {:margin-vertical 8}}]])
(defn membership [] (defn membership []
(let [{:keys [membership]} (<sub [:communities/create])] (let [{:keys [membership]} (rf/sub [:communities/create])]
[:<> [:<>
[rn/scroll-view {} [rn/scroll-view {}
(doall (doall
(for [[id o] options] (for [[id o] options]
^{:key (str "option-" id)} ^{:key (str "option-" id)}
[option o {:selected (= id membership) [option o {:selected (= id membership)
:on-select #(>evt [::communities/create-field :membership id])}]))] :on-select #(rf/dispatch [::communities/create-field :membership id])}]))]
[toolbar/toolbar [toolbar/toolbar
{:show-border? true {:show-border? true
:center [quo/button {:type :secondary :center [quo/button {:type :secondary
:on-press #(>evt [:navigate-back])} :on-press #(rf/dispatch [:navigate-back])}
(i18n/label :t/done)]}]])) (i18n/label :t/done)]}]]))
@@ -1,6 +1,6 @@
(ns status-im.ui.screens.communities.profile (ns status-im.ui.screens.communities.profile
(:require [quo.core :as quo] (:require [quo.core :as quo]
[status-im.utils.handlers :refer [>evt <sub]] [utils.re-frame :as rf]
[status-im.ui.components.profile-header.view :as profile-header] [status-im.ui.components.profile-header.view :as profile-header]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[reagent.core :as reagent] [reagent.core :as reagent]
@@ -15,10 +15,10 @@
[clojure.string :as string])) [clojure.string :as string]))
(defn management [] (defn management []
(let [{:keys [community-id]} (<sub [:get-screen-params])] (let [{:keys [community-id]} (rf/sub [:get-screen-params])]
(fn [] (fn []
(let [requests-to-join (<sub [:communities/requests-to-join-for-community community-id]) (let [requests-to-join (rf/sub [:communities/requests-to-join-for-community community-id])
community (<sub [:communities/community community-id]) community (rf/sub [:communities/community community-id])
{:keys [color members permissions description name admin]} community {:keys [color members permissions description name admin]} community
roles false roles false
notifications false notifications false
@@ -28,10 +28,10 @@
[:<> [:<>
[quo/animated-header {:left-accessories [{:icon :main-icons/arrow-left [quo/animated-header {:left-accessories [{:icon :main-icons/arrow-left
:accessibility-label :back-button :accessibility-label :back-button
:on-press #(>evt [:navigate-back])}] :on-press #(rf/dispatch [:navigate-back])}]
:right-accessories [{:icon :main-icons/share :right-accessories [{:icon :main-icons/share
:accessibility-label :invite-button :accessibility-label :invite-button
:on-press #(>evt [:communities/share-community-pressed community-id])}] :on-press #(rf/dispatch [:communities/share-community-pressed community-id])}]
:extended-header (profile-header/extended-header :extended-header (profile-header/extended-header
{:title name {:title name
:color (or color (rand-nth colors/chat-colors)) :color (or color (rand-nth colors/chat-colors))
@@ -74,7 +74,7 @@
(when (pos? members-count) (when (pos? members-count)
[quo/text {:color :secondary} (str members-count)]) [quo/text {:color :secondary} (str members-count)])
[unviewed-indicator/unviewed-indicator (count requests-to-join)]] [unviewed-indicator/unviewed-indicator (count requests-to-join)]]
:on-press #(>evt [:navigate-to :community-members {:community-id community-id}]) :on-press #(rf/dispatch [:navigate-to :community-members {:community-id community-id}])
:title (i18n/label :t/members-label) :title (i18n/label :t/members-label)
:icon :main-icons/group-chat}]) :icon :main-icons/group-chat}])
(when (and admin roles) (when (and admin roles)
@@ -91,21 +91,21 @@
[quo/list-item {:theme :accent [quo/list-item {:theme :accent
:icon :main-icons/edit :icon :main-icons/edit
:title (i18n/label :t/edit-community) :title (i18n/label :t/edit-community)
:on-press #(>evt [::communities/open-edit-community community-id])}]) :on-press #(rf/dispatch [::communities/open-edit-community community-id])}])
[quo/list-item {:theme :accent [quo/list-item {:theme :accent
:icon :main-icons/arrow-left :icon :main-icons/arrow-left
:title (i18n/label :t/leave-community) :title (i18n/label :t/leave-community)
:on-press #(>evt [:communities/leave community-id])}] :on-press #(rf/dispatch [:communities/leave community-id])}]
;; Disable as not implemented yet ;; Disable as not implemented yet
(when false (when false
[quo/list-item {:theme :negative [quo/list-item {:theme :negative
:icon :main-icons/delete :icon :main-icons/delete
:title (i18n/label :t/delete) :title (i18n/label :t/delete)
:on-press #(>evt [::communities/delete-community community-id])}])]]])))) :on-press #(rf/dispatch [::communities/delete-community community-id])}])]]]))))
(defn management-container [] (defn management-container []
(reagent/create-class (reagent/create-class
{:display-name "community-profile-view" {:display-name "community-profile-view"
:component-did-mount (fn [] :component-did-mount (fn []
(communities/fetch-requests-to-join! (get (<sub [:get-screen-params]) :community-id))) (communities/fetch-requests-to-join! (get (rf/sub [:get-screen-params]) :community-id)))
:reagent-render management})) :reagent-render management}))
@@ -11,7 +11,7 @@
[quo.design-system.colors :as colors] [quo.design-system.colors :as colors]
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[status-im.communities.core :as communities] [status-im.communities.core :as communities]
[status-im.utils.handlers :refer [>evt <sub]] [utils.re-frame :as rf]
[status-im.ui.components.icons.icons :as icons] [status-im.ui.components.icons.icons :as icons]
[quo2.components.community.style :as styles] [quo2.components.community.style :as styles]
[status-im.ui.components.topbar :as topbar] [status-im.ui.components.topbar :as topbar]
@@ -28,14 +28,14 @@
{:title (i18n/label :t/delete-confirmation) {:title (i18n/label :t/delete-confirmation)
:content (i18n/label :t/delete-chat-confirmation) :content (i18n/label :t/delete-chat-confirmation)
:confirm-button-text (i18n/label :t/delete) :confirm-button-text (i18n/label :t/delete)
:on-accept #(>evt [:delete-community-chat community-id chat-id])})) :on-accept #(rf/dispatch [:delete-community-chat community-id chat-id])}))
(defn show-delete-category-confirmation [community-id category-id] (defn show-delete-category-confirmation [community-id category-id]
(utils/show-confirmation (utils/show-confirmation
{:title (i18n/label :t/delete-confirmation) {:title (i18n/label :t/delete-confirmation)
:content (i18n/label :t/delete-category-confirmation) :content (i18n/label :t/delete-category-confirmation)
:confirm-button-text (i18n/label :t/delete) :confirm-button-text (i18n/label :t/delete)
:on-accept #(>evt [:delete-community-category community-id category-id])})) :on-accept #(rf/dispatch [:delete-community-category community-id category-id])}))
(defn categories-tab? [] (defn categories-tab? []
(let [{:keys [tab]} @state] (let [{:keys [tab]} @state]
@@ -117,14 +117,14 @@
chat-id (string/replace id community-id "")] chat-id (string/replace id community-id "")]
(when-not (and (= new-position position) (= new-category categoryID)) (when-not (and (= new-position position) (= new-category categoryID))
(update-local-atom data-js) (update-local-atom data-js)
(>evt [::communities/reorder-community-category-chat (rf/dispatch [::communities/reorder-community-category-chat
community-id new-category chat-id new-position])))) community-id new-category chat-id new-position]))))
(defn on-drag-end-category [from to data-js] (defn on-drag-end-category [from to data-js]
(let [{:keys [id community-id position]} (get @data from)] (let [{:keys [id community-id position]} (get @data from)]
(when (and (< to (count @data)) (not= position to) (not= id "")) (when (and (< to (count @data)) (not= position to) (not= id ""))
(update-local-atom data-js) (update-local-atom data-js)
(>evt [::communities/reorder-community-category community-id id to])))) (rf/dispatch [::communities/reorder-community-category community-id id to]))))
(defn on-drag-end-fn [from to data-js] (defn on-drag-end-fn [from to data-js]
(if (categories-tab?) (if (categories-tab?)
@@ -160,10 +160,10 @@
[tabs/tab-button state :categories (i18n/label :t/edit-categories) (= tab :categories)]]])) [tabs/tab-button state :categories (i18n/label :t/edit-categories) (= tab :categories)]]]))
(defn view [] (defn view []
(let [{:keys [community-id]} (<sub [:get-screen-params]) (let [{:keys [community-id]} (rf/sub [:get-screen-params])
{:keys [id name images members permissions color]} {:keys [id name images members permissions color]}
(<sub [:communities/community community-id]) (rf/sub [:communities/community community-id])
sorted-categories (<sub [:communities/sorted-categories community-id]) sorted-categories (rf/sub [:communities/sorted-categories community-id])
categories (if (categories-tab?) categories (if (categories-tab?)
sorted-categories sorted-categories
(conj sorted-categories (conj sorted-categories
@@ -171,7 +171,7 @@
:position (count sorted-categories) :position (count sorted-categories)
:name (i18n/label :t/none) :name (i18n/label :t/none)
:community-id community-id})) :community-id community-id}))
chats (<sub [:chats/sorted-categories-by-community-id community-id])] chats (rf/sub [:chats/sorted-categories-by-community-id community-id])]
(reset-data categories chats) (reset-data categories chats)
[:<> [:<>
[topbar/topbar [topbar/topbar
@@ -182,4 +182,4 @@
[community/blank-page (i18n/label :t/welcome-community-blank-message-edit-chats)] [community/blank-page (i18n/label :t/welcome-community-blank-message-edit-chats)]
[:<> [:<>
[chats_and_categories] [chats_and_categories]
[draggable-list]])])) [draggable-list]])]))

Some files were not shown because too many files have changed in this diff Show More