2018-09-06 10:04:12 +00:00
|
|
|
(ns status-im.events
|
2021-12-02 10:45:00 +00:00
|
|
|
(:require clojure.set
|
|
|
|
[re-frame.core :as re-frame]
|
|
|
|
status-im.add-new.core
|
|
|
|
[status-im.async-storage.core :as async-storage]
|
2021-10-25 08:46:33 +00:00
|
|
|
status-im.backup.core
|
2021-12-02 10:45:00 +00:00
|
|
|
status-im.bootnodes.core
|
2021-12-27 09:54:45 +00:00
|
|
|
[status-im.bottom-sheet.core :as bottom-sheet]
|
2021-12-02 10:45:00 +00:00
|
|
|
status-im.browser.core
|
|
|
|
status-im.browser.permissions
|
|
|
|
[status-im.chat.models :as chat]
|
|
|
|
status-im.chat.models.images
|
|
|
|
status-im.chat.models.input
|
|
|
|
status-im.chat.models.loading
|
|
|
|
status-im.chat.models.transport
|
2020-04-29 13:11:24 +00:00
|
|
|
[status-im.constants :as constants]
|
2021-12-02 10:45:00 +00:00
|
|
|
status-im.contact.block
|
|
|
|
status-im.contact.chat
|
|
|
|
status-im.contact.core
|
2021-02-12 14:58:43 +00:00
|
|
|
status-im.currency.core
|
2021-12-02 10:45:00 +00:00
|
|
|
[status-im.ethereum.json-rpc :as json-rpc]
|
|
|
|
status-im.ethereum.subscriptions
|
|
|
|
status-im.fleet.core
|
2020-08-04 06:44:10 +00:00
|
|
|
status-im.http.core
|
2021-12-02 10:45:00 +00:00
|
|
|
[status-im.i18n.i18n :as i18n]
|
|
|
|
status-im.init.core
|
|
|
|
[status-im.keycard.core :as keycard]
|
|
|
|
status-im.log-level.core
|
|
|
|
status-im.mailserver.constants
|
|
|
|
[status-im.mailserver.core :as mailserver]
|
|
|
|
[status-im.multiaccounts.biometric.core :as biometric]
|
|
|
|
[status-im.multiaccounts.core :as multiaccounts]
|
2021-02-12 14:58:43 +00:00
|
|
|
status-im.multiaccounts.login.core
|
|
|
|
status-im.multiaccounts.logout.core
|
|
|
|
status-im.multiaccounts.update.core
|
2021-12-02 10:45:00 +00:00
|
|
|
[status-im.native-module.core :as status]
|
|
|
|
[status-im.navigation :as navigation]
|
|
|
|
status-im.notifications-center.core
|
2022-09-13 19:02:01 +00:00
|
|
|
status-im.activity-center.core
|
2021-02-12 14:58:43 +00:00
|
|
|
status-im.pairing.core
|
2022-03-10 13:50:50 +00:00
|
|
|
[status-im.popover.core :as popover]
|
2021-12-02 10:45:00 +00:00
|
|
|
status-im.profile.core
|
|
|
|
status-im.search.core
|
2021-02-12 14:58:43 +00:00
|
|
|
status-im.signals.core
|
|
|
|
status-im.stickers.core
|
|
|
|
status-im.transport.core
|
2021-12-02 10:45:00 +00:00
|
|
|
[status-im.ui.components.permissions :as permissions]
|
|
|
|
[status-im.ui.components.react :as react]
|
|
|
|
status-im.ui.screens.privacy-and-security-settings.events
|
|
|
|
[status-im.utils.dimensions :as dimensions]
|
|
|
|
[status-im.utils.fx :as fx]
|
|
|
|
status-im.utils.logging.core
|
|
|
|
[status-im.utils.universal-links.core :as universal-links]
|
|
|
|
[status-im.utils.utils :as utils]
|
2022-03-10 13:50:50 +00:00
|
|
|
[status-im.visibility-status-popover.core :as visibility-status-popover]
|
2021-12-02 10:45:00 +00:00
|
|
|
status-im.visibility-status-updates.core
|
|
|
|
status-im.waku.core
|
|
|
|
status-im.wallet.accounts.core
|
|
|
|
status-im.wallet.choose-recipient.core
|
|
|
|
[status-im.wallet.core :as wallet]
|
2021-12-27 09:54:45 +00:00
|
|
|
status-im.wallet.custom-tokens.core
|
|
|
|
[status-im.navigation.core :as navigation.core]
|
2022-05-30 11:37:13 +00:00
|
|
|
[status-im.navigation.state :as navigation.state]
|
2021-11-15 04:42:11 +00:00
|
|
|
[status-im.signing.core :as signing]
|
2022-01-15 02:35:52 +00:00
|
|
|
status-im.wallet-connect.core
|
2022-05-10 09:38:19 +00:00
|
|
|
status-im.wallet-connect-legacy.core
|
|
|
|
status-im.navigation2
|
|
|
|
status-im.navigation2.core))
|
2019-06-05 11:11:47 +00:00
|
|
|
|
|
|
|
(re-frame/reg-fx
|
|
|
|
:dismiss-keyboard
|
|
|
|
(fn []
|
2019-06-03 07:42:29 +00:00
|
|
|
(react/dismiss-keyboard!)))
|
2019-06-17 09:41:37 +00:00
|
|
|
|
2020-04-29 13:11:24 +00:00
|
|
|
(re-frame/reg-fx
|
|
|
|
:request-permissions-fx
|
|
|
|
(fn [options]
|
|
|
|
(permissions/request-permissions options)))
|
|
|
|
|
|
|
|
(re-frame/reg-fx
|
|
|
|
:ui/show-error
|
|
|
|
(fn [content]
|
|
|
|
(utils/show-popup "Error" content)))
|
|
|
|
|
|
|
|
(re-frame/reg-fx
|
|
|
|
:ui/show-confirmation
|
|
|
|
(fn [options]
|
|
|
|
(utils/show-confirmation options)))
|
|
|
|
|
|
|
|
(re-frame/reg-fx
|
|
|
|
:ui/close-application
|
|
|
|
(fn [_]
|
|
|
|
(status/close-application)))
|
|
|
|
|
|
|
|
(re-frame/reg-fx
|
|
|
|
::app-state-change-fx
|
|
|
|
(fn [state]
|
|
|
|
(status/app-state-change state)))
|
|
|
|
|
2021-02-12 14:58:43 +00:00
|
|
|
(re-frame/reg-fx
|
|
|
|
:ui/listen-to-window-dimensions-change
|
|
|
|
(fn []
|
|
|
|
(dimensions/add-event-listener)))
|
2020-04-29 13:11:24 +00:00
|
|
|
|
2021-02-12 14:58:43 +00:00
|
|
|
(fx/defn dismiss-keyboard
|
|
|
|
{:events [:dismiss-keyboard]}
|
|
|
|
[_]
|
|
|
|
{:dismiss-keyboard nil})
|
|
|
|
|
|
|
|
(fx/defn identicon-generated
|
|
|
|
{:events [:identicon-generated]}
|
|
|
|
[{:keys [db]} path identicon]
|
|
|
|
{:db (assoc-in db path identicon)})
|
|
|
|
|
|
|
|
(fx/defn gfycat-generated
|
|
|
|
{:events [:gfycat-generated]}
|
|
|
|
[{:keys [db]} path gfycat]
|
|
|
|
{:db (assoc-in db path gfycat)})
|
|
|
|
|
|
|
|
(fx/defn system-theme-mode-changed
|
|
|
|
{:events [:system-theme-mode-changed]}
|
2021-12-27 09:54:45 +00:00
|
|
|
[{:keys [db] :as cofx} theme]
|
2022-09-05 15:47:39 +00:00
|
|
|
(let [cur-theme (get-in db [:multiaccount :appearance])
|
|
|
|
current-tab (get db :current-tab :chat)
|
|
|
|
view-id (:view-id db)
|
|
|
|
screen-params (get-in db [:navigation/screen-params view-id])
|
|
|
|
root-id @navigation.state/root-id
|
|
|
|
key-uid (get-in db [:multiaccounts/login :key-uid])
|
|
|
|
keycard-account? (boolean (get-in db [:multiaccounts/multiaccounts
|
|
|
|
key-uid
|
|
|
|
:keycard-pairing]))
|
|
|
|
dispatch-later (cond-> []
|
|
|
|
(= view-id :chat)
|
|
|
|
(conj {:ms 1000
|
|
|
|
:dispatch [:chat.ui/navigate-to-chat (:current-chat-id db)]})
|
|
|
|
|
|
|
|
(and
|
|
|
|
(= root-id :chat-stack)
|
|
|
|
(not-any? #(= view-id %) '(:home :empty-tab :wallet :status :my-profile :chat)))
|
|
|
|
(conj {:ms 1000
|
|
|
|
:dispatch [:navigate-to view-id screen-params]})
|
|
|
|
|
|
|
|
(some #(= view-id %) navigation.core/community-screens)
|
|
|
|
(conj {:ms 800 :dispatch
|
|
|
|
[:navigate-to :community
|
|
|
|
(get-in db [:navigation/screen-params :community])]})
|
|
|
|
|
|
|
|
(= view-id :community-emoji-thumbnail-picker)
|
|
|
|
(conj {:ms 900 :dispatch
|
|
|
|
[:navigate-to :create-community-channel
|
|
|
|
(get-in db [:navigation/screen-params :create-community-channel])]}))]
|
2022-08-04 17:35:20 +00:00
|
|
|
(when (and (some? root-id) (or (nil? cur-theme) (zero? cur-theme)))
|
|
|
|
(navigation.core/dismiss-all-modals)
|
2021-12-27 09:54:45 +00:00
|
|
|
(fx/merge cofx
|
2022-03-10 13:50:50 +00:00
|
|
|
(merge
|
|
|
|
{::multiaccounts/switch-theme (if (= :dark theme) 2 1)}
|
|
|
|
(when (seq dispatch-later)
|
|
|
|
{:utils/dispatch-later dispatch-later}))
|
|
|
|
(when (get-in db [:bottom-sheet/show?])
|
|
|
|
(bottom-sheet/hide-bottom-sheet))
|
|
|
|
(when (get-in db [:popover/popover])
|
|
|
|
(popover/hide-popover))
|
|
|
|
(when (get-in db [:visibility-status-popover/popover])
|
|
|
|
(visibility-status-popover/hide-visibility-status-popover))
|
|
|
|
(when (get-in db [:signing/tx])
|
|
|
|
(signing/discard))
|
2022-09-05 15:47:39 +00:00
|
|
|
(if (and (= root-id :multiaccounts) keycard-account?)
|
|
|
|
(navigation/init-root-with-component :multiaccounts-keycard :multiaccounts)
|
|
|
|
(navigation/init-root root-id))
|
2021-12-27 09:54:45 +00:00
|
|
|
(when (= root-id :chat-stack)
|
|
|
|
(navigation/change-tab current-tab))))))
|
2020-04-29 13:11:24 +00:00
|
|
|
|
|
|
|
(def authentication-options
|
|
|
|
{:reason (i18n/label :t/biometric-auth-reason-login)})
|
|
|
|
|
|
|
|
(defn- on-biometric-auth-result [{:keys [bioauth-success bioauth-code bioauth-message]}]
|
|
|
|
(when-not bioauth-success
|
|
|
|
(if (= bioauth-code "USER_FALLBACK")
|
|
|
|
(re-frame/dispatch [:multiaccounts.logout.ui/logout-confirmed])
|
|
|
|
(utils/show-confirmation {:title (i18n/label :t/biometric-auth-confirm-title)
|
|
|
|
:content (or bioauth-message (i18n/label :t/biometric-auth-confirm-message))
|
|
|
|
:confirm-button-text (i18n/label :t/biometric-auth-confirm-try-again)
|
|
|
|
:cancel-button-text (i18n/label :t/biometric-auth-confirm-logout)
|
|
|
|
:on-accept #(biometric/authenticate nil on-biometric-auth-result authentication-options)
|
|
|
|
:on-cancel #(re-frame/dispatch [:multiaccounts.logout.ui/logout-confirmed])}))))
|
|
|
|
|
|
|
|
(fx/defn on-return-from-background [{:keys [db now] :as cofx}]
|
|
|
|
(let [app-in-background-since (get db :app-in-background-since)
|
2021-02-12 14:58:43 +00:00
|
|
|
signed-up? (get-in db [:multiaccount :signed-up?])
|
|
|
|
biometric-auth? (= (:auth-method db) "biometric")
|
|
|
|
requires-bio-auth (and
|
|
|
|
signed-up?
|
|
|
|
biometric-auth?
|
|
|
|
(some? app-in-background-since)
|
|
|
|
(>= (- now app-in-background-since)
|
|
|
|
constants/ms-in-bg-for-require-bioauth))]
|
2020-04-29 13:11:24 +00:00
|
|
|
(fx/merge cofx
|
|
|
|
{:db (-> db
|
|
|
|
(dissoc :app-in-background-since)
|
|
|
|
(assoc :app-active-since now))}
|
|
|
|
(mailserver/process-next-messages-request)
|
2020-12-10 16:02:45 +00:00
|
|
|
(wallet/restart-wallet-service-after-background app-in-background-since)
|
2021-08-04 13:27:25 +00:00
|
|
|
(universal-links/process-stored-event)
|
2021-08-19 10:36:25 +00:00
|
|
|
#(when-let [chat-id (:current-chat-id db)]
|
|
|
|
{:dispatch [:chat/mark-all-as-read chat-id]})
|
2020-04-29 13:11:24 +00:00
|
|
|
#(when requires-bio-auth
|
|
|
|
(biometric/authenticate % on-biometric-auth-result authentication-options)))))
|
|
|
|
|
2020-11-16 13:26:40 +00:00
|
|
|
(fx/defn on-going-in-background
|
|
|
|
[{:keys [db now] :as cofx}]
|
2020-12-10 16:02:45 +00:00
|
|
|
{:db (-> db
|
|
|
|
(dissoc :app-active-since)
|
|
|
|
(assoc :app-in-background-since now))
|
|
|
|
:dispatch-n [[:audio-recorder/on-background] [:audio-message/on-background]]})
|
2020-04-29 13:11:24 +00:00
|
|
|
|
2021-02-12 14:58:43 +00:00
|
|
|
(fx/defn app-state-change
|
|
|
|
{:events [:app-state-change]}
|
|
|
|
[{:keys [db] :as cofx} state]
|
2020-04-29 13:11:24 +00:00
|
|
|
(let [app-coming-from-background? (= state "active")
|
2021-02-12 14:58:43 +00:00
|
|
|
app-going-in-background? (= state "background")]
|
2020-04-29 13:11:24 +00:00
|
|
|
(fx/merge cofx
|
|
|
|
{::app-state-change-fx state
|
|
|
|
:db (assoc db :app-state state)}
|
|
|
|
#(when app-coming-from-background?
|
|
|
|
(on-return-from-background %))
|
|
|
|
#(when app-going-in-background?
|
|
|
|
(on-going-in-background %)))))
|
|
|
|
|
2021-02-12 14:58:43 +00:00
|
|
|
(fx/defn request-permissions
|
|
|
|
{:events [:request-permissions]}
|
|
|
|
[_ options]
|
|
|
|
{:request-permissions-fx options})
|
2020-04-29 13:11:24 +00:00
|
|
|
|
2021-02-12 14:58:43 +00:00
|
|
|
(fx/defn update-window-dimensions
|
|
|
|
{:events [:update-window-dimensions]}
|
|
|
|
[{:keys [db]} dimensions]
|
|
|
|
{:db (assoc db :dimensions/window (dimensions/window dimensions))})
|
2020-04-29 13:11:24 +00:00
|
|
|
|
2021-02-16 14:16:32 +00:00
|
|
|
(fx/defn init-timeline-chat
|
|
|
|
{:events [:init-timeline-chat]}
|
|
|
|
[{:keys [db] :as cofx}]
|
|
|
|
(when-not (get-in db [:pagination-info constants/timeline-chat-id :messages-initialized?])
|
|
|
|
(chat/preload-chat-data cofx constants/timeline-chat-id)))
|
2020-10-29 13:59:58 +00:00
|
|
|
|
2021-02-12 14:58:43 +00:00
|
|
|
(fx/defn on-will-focus
|
2022-05-16 09:28:03 +00:00
|
|
|
{:events [:screens/on-will-focus]}
|
2021-12-02 10:45:00 +00:00
|
|
|
[{:keys [db] :as cofx} view-id]
|
2021-02-12 14:58:43 +00:00
|
|
|
(fx/merge cofx
|
2021-12-02 10:45:00 +00:00
|
|
|
(cond
|
|
|
|
(= :chat view-id)
|
|
|
|
{::async-storage/set! {:chat-id (get-in cofx [:db :current-chat-id])
|
|
|
|
:key-uid (get-in cofx [:db :multiaccount :key-uid])}
|
|
|
|
:db (assoc db :screens/was-focused-once? true)}
|
|
|
|
|
|
|
|
(= :login view-id)
|
|
|
|
{}
|
|
|
|
|
|
|
|
(not (get db :screens/was-focused-once?))
|
|
|
|
{:db (assoc db :screens/was-focused-once? true)}
|
|
|
|
|
|
|
|
:else
|
|
|
|
{::async-storage/set! {:chat-id nil
|
|
|
|
:key-uid nil}
|
|
|
|
:db (assoc db :screens/was-focused-once? true)})
|
2021-02-12 14:58:43 +00:00
|
|
|
#(case view-id
|
|
|
|
:keycard-settings (keycard/settings-screen-did-load %)
|
|
|
|
:reset-card (keycard/reset-card-screen-did-load %)
|
|
|
|
:enter-pin-settings (keycard/enter-pin-screen-did-load %)
|
2021-06-16 12:00:41 +00:00
|
|
|
:keycard-login-pin (keycard/login-pin-screen-did-load %)
|
2021-02-12 14:58:43 +00:00
|
|
|
:add-new-account-pin (keycard/enter-pin-screen-did-load %)
|
|
|
|
:keycard-authentication-method (keycard/authentication-method-screen-did-load %)
|
|
|
|
:multiaccounts (keycard/multiaccounts-screen-did-load %)
|
2021-06-16 12:00:41 +00:00
|
|
|
:wallet (wallet/wallet-will-focus %)
|
2021-02-12 14:58:43 +00:00
|
|
|
nil)))
|
|
|
|
|
|
|
|
;;TODO :replace by named events
|
|
|
|
(fx/defn set-event
|
|
|
|
{:events [:set]}
|
|
|
|
[{:keys [db]} k v]
|
|
|
|
{:db (assoc db k v)})
|
|
|
|
|
2022-09-20 16:52:41 +00:00
|
|
|
(fx/defn set-view-id
|
|
|
|
{:events [:set-view-id]}
|
|
|
|
[{:keys [db]} view-id]
|
|
|
|
{:db (assoc db :view-id view-id)})
|
|
|
|
|
2021-02-12 14:58:43 +00:00
|
|
|
;;TODO :replace by named events
|
|
|
|
(fx/defn set-once-event
|
|
|
|
{:events [:set-once]}
|
|
|
|
[{:keys [db]} k v]
|
|
|
|
(when-not (get db k)
|
|
|
|
{:db (assoc db k v)}))
|
|
|
|
|
|
|
|
;;TODO :replace by named events
|
|
|
|
(fx/defn set-in-event
|
|
|
|
{:events [:set-in]}
|
|
|
|
[{:keys [db]} path v]
|
|
|
|
{:db (assoc-in db path v)})
|
2021-01-29 14:08:48 +00:00
|
|
|
|
|
|
|
(defn on-ramp<-rpc [on-ramp]
|
|
|
|
(clojure.set/rename-keys on-ramp {:logoUrl :logo-url
|
|
|
|
:siteUrl :site-url}))
|
|
|
|
|
2021-02-12 14:58:43 +00:00
|
|
|
(fx/defn crypto-loaded-event
|
|
|
|
{:events [::crypto-loaded]}
|
|
|
|
[{:keys [db]} on-ramps]
|
|
|
|
{:db (assoc
|
|
|
|
db
|
|
|
|
:buy-crypto/on-ramps
|
|
|
|
(map on-ramp<-rpc on-ramps))})
|
|
|
|
|
|
|
|
(fx/defn buy-crypto-ui-loaded
|
|
|
|
{:events [:buy-crypto.ui/loaded]}
|
|
|
|
[_]
|
|
|
|
{::json-rpc/call [{:method "wallet_getCryptoOnRamps"
|
|
|
|
:params []
|
|
|
|
:on-success (fn [on-ramps]
|
|
|
|
(re-frame/dispatch [::crypto-loaded on-ramps]))}]})
|
2021-03-24 15:32:37 +00:00
|
|
|
|
|
|
|
(fx/defn open-buy-crypto-screen
|
|
|
|
{:events [:buy-crypto.ui/open-screen]}
|
|
|
|
[cofx]
|
|
|
|
(fx/merge
|
|
|
|
cofx
|
2021-05-24 14:25:05 +00:00
|
|
|
(navigation/open-modal :buy-crypto nil)
|
2021-03-24 15:32:37 +00:00
|
|
|
(wallet/keep-watching-history)))
|
2022-08-11 16:18:13 +00:00
|
|
|
|
|
|
|
;; Information Box
|
|
|
|
|
|
|
|
(def closable-information-boxes
|
2022-10-06 07:01:07 +00:00
|
|
|
"[{:id information box id
|
|
|
|
:global? true/false (close information box across all profiles)}]"
|
|
|
|
[])
|
2022-08-11 16:18:13 +00:00
|
|
|
|
|
|
|
(defn information-box-id-hash [id public-key global?]
|
|
|
|
(if global?
|
|
|
|
(hash id)
|
|
|
|
(hash (str public-key id))))
|
|
|
|
|
|
|
|
(fx/defn close-information-box
|
|
|
|
{:events [:close-information-box]}
|
|
|
|
[{:keys [db]} id global?]
|
|
|
|
(let [public-key (get-in db [:multiaccount :public-key])
|
|
|
|
hash (information-box-id-hash id public-key global?)]
|
|
|
|
{::async-storage/set! {hash true}
|
|
|
|
:db (assoc-in db [:information-box-states id] true)}))
|
|
|
|
|
|
|
|
(fx/defn information-box-states-loaded
|
|
|
|
{:events [:information-box-states-loaded]}
|
|
|
|
[{:keys [db]} hashes states]
|
|
|
|
{:db (assoc db :information-box-states (reduce
|
|
|
|
(fn [acc [id hash]]
|
|
|
|
(assoc acc id (get states hash)))
|
|
|
|
{} hashes))})
|
|
|
|
|
|
|
|
(fx/defn load-information-box-states
|
|
|
|
{:events [:load-information-box-states]}
|
|
|
|
[{:keys [db]}]
|
|
|
|
(let [public-key (get-in db [:multiaccount :public-key])
|
|
|
|
{:keys [keys hashes]} (reduce (fn [acc {:keys [id global?]}]
|
|
|
|
(let [hash (information-box-id-hash
|
|
|
|
id public-key global?)]
|
|
|
|
(-> acc
|
|
|
|
(assoc-in [:hashes id] hash)
|
|
|
|
(update :keys #(conj % hash)))))
|
|
|
|
{} closable-information-boxes)]
|
|
|
|
{::async-storage/get {:keys keys
|
|
|
|
:cb #(re-frame/dispatch
|
|
|
|
[:information-box-states-loaded hashes %])}}))
|