2018-09-06 10:04:12 +00:00
|
|
|
(ns status-im.events
|
2020-06-01 13:24:30 +00:00
|
|
|
(:require [re-frame.core :as re-frame]
|
2021-01-29 14:08:48 +00:00
|
|
|
[clojure.set :as clojure.set]
|
2018-09-06 10:04:12 +00:00
|
|
|
[status-im.bootnodes.core :as bootnodes]
|
2018-09-21 13:41:40 +00:00
|
|
|
[status-im.browser.core :as browser]
|
|
|
|
[status-im.browser.permissions :as browser.permissions]
|
2018-09-24 16:27:04 +00:00
|
|
|
[status-im.chat.models :as chat]
|
|
|
|
[status-im.chat.models.input :as chat.input]
|
2018-10-09 08:10:47 +00:00
|
|
|
[status-im.chat.models.loading :as chat.loading]
|
|
|
|
[status-im.chat.models.message :as chat.message]
|
2020-07-03 15:04:45 +00:00
|
|
|
[status-im.chat.models.reactions :as chat.reactions]
|
2020-05-05 14:18:23 +00:00
|
|
|
[status-im.chat.models.message-seen :as message-seen]
|
2019-02-22 12:26:40 +00:00
|
|
|
[status-im.contact.block :as contact.block]
|
2019-02-22 12:26:40 +00:00
|
|
|
[status-im.contact.core :as contact]
|
2020-05-05 14:18:23 +00:00
|
|
|
[status-im.data-store.chats :as data-store.chats]
|
|
|
|
[status-im.data-store.messages :as data-store.messages]
|
2020-07-03 15:04:45 +00:00
|
|
|
[status-im.data-store.reactions :as data-store.reactions]
|
2019-05-08 23:33:19 +00:00
|
|
|
[status-im.ethereum.subscriptions :as ethereum.subscriptions]
|
2018-09-06 10:04:12 +00:00
|
|
|
[status-im.fleet.core :as fleet]
|
2018-07-19 15:51:06 +00:00
|
|
|
[status-im.group-chats.core :as group-chats]
|
2018-09-06 10:04:12 +00:00
|
|
|
[status-im.i18n :as i18n]
|
|
|
|
[status-im.init.core :as init]
|
|
|
|
[status-im.log-level.core :as log-level]
|
Adds topic negotiation and partitioned topic
All the code has been implemented in statusgo: status-im/status-go#1466
Basically all the whisper filter management is done at that level.
Technical description
On startup we load all chats and send a list of them to status go:
For a public chat: {:chatId "status"}, we create a single filter, based on the name of the chat.
For each contact added by us, each user in a group chat and each one to one chat open, we send:
{:chatId "0x", :oneToOne true}. This will create a chats, to listen to their contact code.
Any previously negotiated topic is also returned.
Once loaded, we create our filters, and upsert the mailserver topics, both of which are solely based on the filters loaded.
In order to remove a chat, we delete/stopwatching first the the filter in status-react and then ask status-go to remove the filter. For a public chat we always remove, for a one-to-one we remove only if the user is not in our contacts, or in a group chat or we have a chat open. Negotiated topics are never removed, as otherwise the other user won't be able to contact us anymore.
On stopping whisper we don't have to ask status-go to remove filters as they are removed automatically.
Some more logic can be pushed in status-go, but that will be in subsequent PRs.
Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-06-05 11:34:04 +00:00
|
|
|
[status-im.mailserver.constants :as mailserver.constants]
|
2020-05-05 14:18:23 +00:00
|
|
|
[status-im.mailserver.core :as mailserver]
|
Adds topic negotiation and partitioned topic
All the code has been implemented in statusgo: status-im/status-go#1466
Basically all the whisper filter management is done at that level.
Technical description
On startup we load all chats and send a list of them to status go:
For a public chat: {:chatId "status"}, we create a single filter, based on the name of the chat.
For each contact added by us, each user in a group chat and each one to one chat open, we send:
{:chatId "0x", :oneToOne true}. This will create a chats, to listen to their contact code.
Any previously negotiated topic is also returned.
Once loaded, we create our filters, and upsert the mailserver topics, both of which are solely based on the filters loaded.
In order to remove a chat, we delete/stopwatching first the the filter in status-react and then ask status-go to remove the filter. For a public chat we always remove, for a one-to-one we remove only if the user is not in our contacts, or in a group chat or we have a chat open. Negotiated topics are never removed, as otherwise the other user won't be able to contact us anymore.
On stopping whisper we don't have to ask status-go to remove filters as they are removed automatically.
Some more logic can be pushed in status-go, but that will be in subsequent PRs.
Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-06-05 11:34:04 +00:00
|
|
|
[status-im.mailserver.topics :as mailserver.topics]
|
2020-05-05 14:18:23 +00:00
|
|
|
[status-im.multiaccounts.core :as multiaccounts]
|
|
|
|
[status-im.multiaccounts.login.core :as multiaccounts.login]
|
|
|
|
[status-im.multiaccounts.logout.core :as multiaccounts.logout]
|
|
|
|
[status-im.multiaccounts.update.core :as multiaccounts.update]
|
2018-10-09 10:43:07 +00:00
|
|
|
[status-im.pairing.core :as pairing]
|
2018-09-06 10:04:12 +00:00
|
|
|
[status-im.privacy-policy.core :as privacy-policy]
|
|
|
|
[status-im.signals.core :as signals]
|
2019-02-22 12:26:40 +00:00
|
|
|
[status-im.stickers.core :as stickers]
|
2021-01-29 14:08:48 +00:00
|
|
|
[status-im.ethereum.json-rpc :as json-rpc]
|
|
|
|
|
2019-02-22 13:12:29 +00:00
|
|
|
[status-im.transport.core :as transport]
|
2019-02-22 12:26:40 +00:00
|
|
|
[status-im.transport.message.core :as transport.message]
|
|
|
|
[status-im.ui.components.react :as react]
|
|
|
|
[status-im.ui.screens.currency-settings.models
|
|
|
|
:as
|
|
|
|
currency-settings.models]
|
2020-04-29 13:11:24 +00:00
|
|
|
[status-im.navigation :as navigation]
|
2018-09-24 15:59:02 +00:00
|
|
|
[status-im.utils.fx :as fx]
|
2018-09-06 10:04:12 +00:00
|
|
|
[status-im.utils.handlers :as handlers]
|
2019-02-22 12:26:40 +00:00
|
|
|
[status-im.utils.logging.core :as logging]
|
2020-05-05 14:18:23 +00:00
|
|
|
[status-im.utils.universal-links.core :as universal-links]
|
2019-05-18 11:06:42 +00:00
|
|
|
[status-im.wallet.core :as wallet]
|
2019-02-22 12:26:40 +00:00
|
|
|
[status-im.wallet.custom-tokens.core :as custom-tokens]
|
2019-05-17 10:02:16 +00:00
|
|
|
[status-im.wallet.db :as wallet.db]
|
2019-06-17 09:41:37 +00:00
|
|
|
[taoensso.timbre :as log]
|
2020-05-05 14:18:23 +00:00
|
|
|
status-im.waku.core
|
|
|
|
status-im.wallet.choose-recipient.core
|
|
|
|
status-im.wallet.accounts.core
|
2020-04-29 13:11:24 +00:00
|
|
|
status-im.popover.core
|
2020-07-10 10:05:36 +00:00
|
|
|
[status-im.keycard.core :as keycard]
|
2020-04-29 13:11:24 +00:00
|
|
|
[status-im.utils.dimensions :as dimensions]
|
|
|
|
[status-im.multiaccounts.biometric.core :as biometric]
|
|
|
|
[status-im.constants :as constants]
|
|
|
|
[status-im.native-module.core :as status]
|
|
|
|
[status-im.ui.components.permissions :as permissions]
|
2020-05-05 14:18:23 +00:00
|
|
|
[status-im.utils.utils :as utils]
|
2020-05-19 10:40:39 +00:00
|
|
|
status-im.ui.components.bottom-sheet.core
|
2020-04-29 13:11:24 +00:00
|
|
|
status-im.ui.screens.add-new.new-chat.events
|
|
|
|
status-im.ui.screens.group.chat-settings.events
|
|
|
|
status-im.ui.screens.group.events
|
|
|
|
status-im.utils.universal-links.events
|
2020-05-07 10:48:08 +00:00
|
|
|
status-im.search.core
|
2020-08-04 06:44:10 +00:00
|
|
|
status-im.http.core
|
2020-05-14 13:00:06 +00:00
|
|
|
status-im.ui.screens.profile.events
|
2020-07-14 13:33:59 +00:00
|
|
|
status-im.chat.models.images
|
2020-07-07 10:20:48 +00:00
|
|
|
status-im.ui.screens.privacy-and-security-settings.events
|
2020-10-05 10:11:57 +00:00
|
|
|
[status-im.data-store.invitations :as data-store.invitations]
|
2020-10-29 13:59:58 +00:00
|
|
|
[status-im.ui.screens.wallet.events :as wallet.events]
|
|
|
|
[status-im.contact.db :as contact.db]))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
;; init module
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:init/app-started
|
|
|
|
(fn [cofx _]
|
2018-09-28 14:48:59 +00:00
|
|
|
(init/start-app cofx)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
2019-07-03 14:29:01 +00:00
|
|
|
;; multiaccounts module
|
2019-01-25 13:07:33 +00:00
|
|
|
(handlers/register-handler-fx
|
2019-07-03 14:29:01 +00:00
|
|
|
:multiaccounts.update.callback/published
|
2019-01-25 13:07:33 +00:00
|
|
|
(fn [{:keys [now] :as cofx} _]
|
2019-12-10 11:31:22 +00:00
|
|
|
(multiaccounts.update/multiaccount-update cofx :last-updated now {})))
|
2019-01-25 13:07:33 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
2019-07-03 14:29:01 +00:00
|
|
|
:multiaccounts.update.callback/failed-to-publish
|
2019-01-25 13:07:33 +00:00
|
|
|
(fn [{:keys [now] :as cofx} [_ message]]
|
2019-07-03 14:29:01 +00:00
|
|
|
(log/warn "failed to publish multiaccount update" message)
|
2019-12-10 11:31:22 +00:00
|
|
|
(multiaccounts.update/multiaccount-update cofx :last-updated now {})))
|
2019-01-25 13:07:33 +00:00
|
|
|
|
2018-09-06 10:04:12 +00:00
|
|
|
(handlers/register-handler-fx
|
2019-07-03 14:29:01 +00:00
|
|
|
:multiaccounts.ui/dev-mode-switched
|
2018-09-06 10:04:12 +00:00
|
|
|
(fn [cofx [_ dev-mode?]]
|
2019-07-03 14:29:01 +00:00
|
|
|
(multiaccounts/switch-dev-mode cofx dev-mode?)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
2019-03-19 12:24:57 +00:00
|
|
|
(def CUD-url "https://chaos-unicorn-day.org")
|
|
|
|
|
|
|
|
(defn open-chaos-unicorn-day-link []
|
2019-09-07 12:57:22 +00:00
|
|
|
(.openURL ^js react/linking CUD-url))
|
2019-03-19 12:24:57 +00:00
|
|
|
|
2019-03-18 14:41:25 +00:00
|
|
|
(handlers/register-handler-fx
|
2019-07-03 14:29:01 +00:00
|
|
|
:multiaccounts.ui/chaos-mode-switched
|
2019-03-19 12:24:57 +00:00
|
|
|
(fn [{:keys [db] :as cofx} [_ chaos-mode?]]
|
2019-08-01 20:11:59 +00:00
|
|
|
(let [old-chaos-mode? (get-in db [:multiaccount :chaos-mode?])]
|
2019-03-26 13:17:16 +00:00
|
|
|
(fx/merge
|
|
|
|
cofx
|
|
|
|
(when (and chaos-mode?
|
|
|
|
(not= old-chaos-mode? chaos-mode?))
|
|
|
|
{:ui/show-confirmation
|
|
|
|
{:title (i18n/label :t/chaos-unicorn-day)
|
|
|
|
:content (i18n/label :t/chaos-unicorn-day-details)
|
|
|
|
:confirm-button-text (i18n/label :t/see-details)
|
|
|
|
:cancel-button-text (i18n/label :t/cancel)
|
|
|
|
:on-accept open-chaos-unicorn-day-link}})
|
2019-07-03 14:29:01 +00:00
|
|
|
(multiaccounts/switch-chaos-mode chaos-mode?)))))
|
2019-03-18 14:41:25 +00:00
|
|
|
|
2019-05-08 12:26:39 +00:00
|
|
|
(handlers/register-handler-fx
|
2019-07-03 14:29:01 +00:00
|
|
|
:multiaccounts.ui/preview-privacy-mode-switched
|
2019-05-08 12:26:39 +00:00
|
|
|
(fn [cofx [_ private?]]
|
2019-07-03 14:29:01 +00:00
|
|
|
(multiaccounts/switch-preview-privacy-mode cofx private?)))
|
2019-05-08 12:26:39 +00:00
|
|
|
|
2020-09-16 08:51:36 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:multiaccounts.ui/webview-permission-requests-switched
|
|
|
|
(fn [cofx [_ enabled?]]
|
|
|
|
(multiaccounts/switch-webview-permission-requests? cofx enabled?)))
|
|
|
|
|
2018-09-06 10:04:12 +00:00
|
|
|
(handlers/register-handler-fx
|
2019-07-03 14:29:01 +00:00
|
|
|
:multiaccounts.ui/wallet-set-up-confirmed
|
2019-07-08 11:38:47 +00:00
|
|
|
(fn [cofx _]
|
2019-07-03 14:29:01 +00:00
|
|
|
(multiaccounts/confirm-wallet-set-up cofx)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
2019-11-10 09:50:03 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:multiaccounts.ui/hide-home-tooltip
|
|
|
|
(fn [cofx _]
|
|
|
|
(multiaccounts/confirm-home-tooltip cofx)))
|
|
|
|
|
2019-07-03 14:29:01 +00:00
|
|
|
;; multiaccounts login module
|
2018-09-06 10:04:12 +00:00
|
|
|
(handlers/register-handler-fx
|
2019-07-03 14:29:01 +00:00
|
|
|
:multiaccounts.login.ui/multiaccount-selected
|
2019-12-05 06:02:31 +00:00
|
|
|
(fn [{:keys [db] :as cofx} [_ key-uid]]
|
2020-12-28 11:30:50 +00:00
|
|
|
;; We specifically pass a bunch of fields instead of the whole multiaccount
|
|
|
|
;; as we want store some fields in multiaccount that are not here
|
|
|
|
(let [multiaccount
|
|
|
|
(get-in db [:multiaccounts/multiaccounts key-uid])]
|
2019-11-20 14:41:21 +00:00
|
|
|
(fx/merge
|
|
|
|
cofx
|
2020-03-06 09:16:26 +00:00
|
|
|
{:db (-> db
|
|
|
|
(dissoc :intro-wizard)
|
2020-07-10 10:05:36 +00:00
|
|
|
(update :keycard dissoc :application-info))}
|
2020-12-28 11:30:50 +00:00
|
|
|
(multiaccounts.login/open-login
|
|
|
|
(select-keys multiaccount [:key-uid :name :public-key :identicon :images]))))))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
2020-03-26 11:36:41 +00:00
|
|
|
(handlers/register-handler-fx
|
2021-01-18 13:01:57 +00:00
|
|
|
::transport/messenger-started
|
|
|
|
(fn [cofx [_ response]]
|
|
|
|
(fx/merge
|
|
|
|
cofx
|
|
|
|
(transport/messenger-started response)
|
|
|
|
(universal-links/process-stored-event))))
|
2020-03-26 11:36:41 +00:00
|
|
|
|
2019-07-03 14:29:01 +00:00
|
|
|
;; multiaccounts update module
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
2019-07-03 14:29:01 +00:00
|
|
|
:multiaccounts.update.callback/save-settings-success
|
2018-09-06 10:04:12 +00:00
|
|
|
(fn [cofx _]
|
2019-07-03 14:29:01 +00:00
|
|
|
(multiaccounts.logout/logout cofx)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
;; mailserver module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/user-defined-mailserver-selected
|
|
|
|
(fn [cofx [_ mailserver-id]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(mailserver/edit cofx mailserver-id)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/default-mailserver-selected
|
|
|
|
(fn [cofx [_ mailserver-id]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(mailserver/show-connection-confirmation cofx mailserver-id)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/add-pressed
|
2020-12-01 08:54:38 +00:00
|
|
|
(fn [{:keys [db] :as cofx} _]
|
|
|
|
(fx/merge cofx
|
|
|
|
{:db (dissoc db :mailserver.edit/mailserver)}
|
|
|
|
(navigation/navigate-to-cofx :edit-mailserver nil))))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/save-pressed
|
2018-09-24 16:27:04 +00:00
|
|
|
[(re-frame/inject-cofx :random-id-generator)]
|
2018-09-06 10:04:12 +00:00
|
|
|
(fn [cofx _]
|
|
|
|
(mailserver/upsert cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/input-changed
|
|
|
|
(fn [cofx [_ input-key value]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(mailserver/set-input cofx input-key value)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/delete-confirmed
|
|
|
|
(fn [cofx [_ mailserver-id]]
|
2018-10-18 00:05:02 +00:00
|
|
|
(mailserver/delete cofx mailserver-id)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/delete-pressed
|
|
|
|
(fn [cofx [_ mailserver-id]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(mailserver/show-delete-confirmation cofx mailserver-id)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.callback/qr-code-scanned
|
2019-11-16 09:56:09 +00:00
|
|
|
(fn [cofx [_ url _]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(mailserver/set-url-from-qr cofx url)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
2019-02-21 11:24:38 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.callback/resend-request
|
|
|
|
(fn [cofx [_ request]]
|
|
|
|
(mailserver/resend-request cofx request)))
|
|
|
|
|
2018-09-18 08:13:35 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/connect-pressed
|
2019-03-19 12:24:57 +00:00
|
|
|
(fn [cofx [_ mailserver-id]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(mailserver/show-connection-confirmation cofx mailserver-id)))
|
2018-09-18 08:13:35 +00:00
|
|
|
|
2018-09-06 10:04:12 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/connect-confirmed
|
|
|
|
(fn [cofx [_ current-fleet mailserver-id]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(mailserver/save-settings cofx current-fleet mailserver-id)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
2020-04-15 18:59:19 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/dismiss-connection-error
|
|
|
|
(fn [cofx [_ new-state]]
|
|
|
|
(mailserver/dismiss-connection-error cofx new-state)))
|
|
|
|
|
2019-03-01 09:36:49 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/unpin-pressed
|
|
|
|
(fn [cofx _]
|
|
|
|
(mailserver/unpin cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/pin-pressed
|
|
|
|
(fn [cofx _]
|
|
|
|
(mailserver/pin cofx)))
|
|
|
|
|
2018-11-22 09:22:02 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/request-error-pressed
|
|
|
|
(fn [cofx _]
|
|
|
|
(mailserver/show-request-error-popup cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/retry-request-pressed
|
2020-05-05 14:18:23 +00:00
|
|
|
(fn [cofx [_ _]]
|
2018-11-22 09:22:02 +00:00
|
|
|
(mailserver/retry-next-messages-request cofx)))
|
|
|
|
|
2020-09-19 04:02:28 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.ui/use-history-switch-pressed
|
|
|
|
(fn [cofx [_ use-mailservers?]]
|
|
|
|
(mailserver/update-use-mailservers cofx use-mailservers?)))
|
|
|
|
|
2018-10-18 00:05:02 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver/check-connection-timeout
|
|
|
|
(fn [cofx _]
|
|
|
|
(mailserver/check-connection cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.callback/generate-mailserver-symkey-success
|
|
|
|
(fn [cofx [_ mailserver sym-key-id]]
|
|
|
|
(mailserver/add-mailserver-sym-key cofx mailserver sym-key-id)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.callback/mark-trusted-peer-success
|
|
|
|
(fn [cofx _]
|
|
|
|
(mailserver/add-mailserver-trusted cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.callback/mark-trusted-peer-error
|
|
|
|
(fn [cofx [_ error]]
|
|
|
|
(log/error "Error on mark-trusted-peer: " error)
|
|
|
|
(mailserver/check-connection cofx)))
|
|
|
|
|
2019-02-19 08:24:53 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.callback/request-error
|
|
|
|
(fn [cofx [_ error]]
|
|
|
|
(mailserver/handle-request-error cofx error)))
|
|
|
|
|
2019-02-27 11:50:41 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:mailserver.callback/request-success
|
|
|
|
(fn [cofx [_ request-id]]
|
|
|
|
(mailserver/handle-request-success cofx request-id)))
|
|
|
|
|
2018-09-06 10:04:12 +00:00
|
|
|
;; fleet module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:fleet.ui/save-fleet-confirmed
|
|
|
|
(fn [cofx [_ fleet]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(fleet/save cofx fleet)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:fleet.ui/fleet-selected
|
|
|
|
(fn [cofx [_ fleet]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(fleet/show-save-confirmation cofx fleet)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
;; bootnodes module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:bootnodes.ui/add-bootnode-pressed
|
|
|
|
(fn [cofx [_ bootnode-id]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(bootnodes/edit cofx bootnode-id)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
2018-09-18 08:19:13 +00:00
|
|
|
:bootnodes.callback/qr-code-scanned
|
2019-11-16 09:56:09 +00:00
|
|
|
(fn [cofx [_ url _]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(bootnodes/set-bootnodes-from-qr cofx url)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:bootnodes.ui/input-changed
|
|
|
|
(fn [cofx [_ input-key value]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(bootnodes/set-input cofx input-key value)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
2018-09-18 08:19:13 +00:00
|
|
|
:bootnodes.ui/save-pressed
|
2018-09-24 16:27:04 +00:00
|
|
|
[(re-frame/inject-cofx :random-id-generator)]
|
2018-09-06 10:04:12 +00:00
|
|
|
(fn [cofx _]
|
|
|
|
(bootnodes/upsert cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:bootnodes.ui/delete-pressed
|
2019-03-14 07:31:15 +00:00
|
|
|
(fn [cofx [_ id]]
|
|
|
|
(bootnodes/show-delete-bootnode-confirmation cofx id)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:bootnodes.ui/delete-confirmed
|
|
|
|
(fn [cofx [_ bootnode-id]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(bootnodes/delete-bootnode cofx bootnode-id)))
|
2018-10-11 15:22:43 +00:00
|
|
|
|
2018-12-15 18:57:00 +00:00
|
|
|
;; logging module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:logging.ui/send-logs-pressed
|
|
|
|
(fn [cofx _]
|
|
|
|
(logging/send-logs cofx)))
|
|
|
|
|
2018-09-06 10:04:12 +00:00
|
|
|
;; log-level module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:log-level.ui/change-log-level-confirmed
|
|
|
|
(fn [cofx [_ log-level]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(log-level/save-log-level cofx log-level)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:log-level.ui/log-level-selected
|
|
|
|
(fn [cofx [_ log-level]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(log-level/show-change-log-level-confirmation cofx log-level)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
2018-09-13 14:07:42 +00:00
|
|
|
;; Browser bridge module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.bridge.callback/qr-code-scanned
|
2019-11-16 09:56:09 +00:00
|
|
|
(fn [cofx [_ data qr-code-data]]
|
2018-10-02 14:14:35 +00:00
|
|
|
(browser/handle-scanned-qr-code cofx data (:data qr-code-data))))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.bridge.callback/qr-code-canceled
|
2019-11-16 09:56:09 +00:00
|
|
|
(fn [cofx [_ qr-code-data _]]
|
2018-10-02 14:14:35 +00:00
|
|
|
(browser/handle-canceled-qr-code cofx (:data qr-code-data))))
|
2018-09-13 14:07:42 +00:00
|
|
|
|
2018-09-06 10:04:12 +00:00
|
|
|
;; privacy-policy module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:privacy-policy/privacy-policy-button-pressed
|
2018-09-24 15:59:02 +00:00
|
|
|
(fn [cofx _]
|
|
|
|
(privacy-policy/open-privacy-policy-link cofx)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
;; wallet modules
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.settings.ui/currency-selected
|
|
|
|
(fn [cofx [_ currency]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(currency-settings.models/set-currency cofx currency)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
;; chat module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/clear-history-pressed
|
2020-01-21 08:41:44 +00:00
|
|
|
(fn [_ [_ chat-id]]
|
2018-09-24 16:27:04 +00:00
|
|
|
{:ui/show-confirmation {:title (i18n/label :t/clear-history-title)
|
|
|
|
:content (i18n/label :t/clear-history-confirmation-content)
|
2018-09-06 10:04:12 +00:00
|
|
|
:confirm-button-text (i18n/label :t/clear-history-action)
|
2020-05-19 10:40:39 +00:00
|
|
|
:on-accept #(do
|
|
|
|
(re-frame/dispatch [:bottom-sheet/hide])
|
|
|
|
(re-frame/dispatch [:chat.ui/clear-history chat-id]))}}))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
2019-04-04 13:55:35 +00:00
|
|
|
(handlers/register-handler-fx
|
2019-04-16 19:09:18 +00:00
|
|
|
:chat.ui/fill-gaps
|
|
|
|
(fn [{:keys [db] :as cofx} [_ gap-ids]]
|
2020-04-29 13:11:24 +00:00
|
|
|
(let [chat-id (:current-chat-id db)
|
|
|
|
topics (mailserver.topics/topics-for-current-chat db)
|
|
|
|
gaps (keep
|
|
|
|
(fn [id]
|
|
|
|
(get-in db [:mailserver/gaps chat-id id]))
|
|
|
|
gap-ids)]
|
2019-04-04 13:55:35 +00:00
|
|
|
(mailserver/fill-the-gap
|
|
|
|
cofx
|
2019-04-16 19:09:18 +00:00
|
|
|
{:gaps gaps
|
Adds topic negotiation and partitioned topic
All the code has been implemented in statusgo: status-im/status-go#1466
Basically all the whisper filter management is done at that level.
Technical description
On startup we load all chats and send a list of them to status go:
For a public chat: {:chatId "status"}, we create a single filter, based on the name of the chat.
For each contact added by us, each user in a group chat and each one to one chat open, we send:
{:chatId "0x", :oneToOne true}. This will create a chats, to listen to their contact code.
Any previously negotiated topic is also returned.
Once loaded, we create our filters, and upsert the mailserver topics, both of which are solely based on the filters loaded.
In order to remove a chat, we delete/stopwatching first the the filter in status-react and then ask status-go to remove the filter. For a public chat we always remove, for a one-to-one we remove only if the user is not in our contacts, or in a group chat or we have a chat open. Negotiated topics are never removed, as otherwise the other user won't be able to contact us anymore.
On stopping whisper we don't have to ask status-go to remove filters as they are removed automatically.
Some more logic can be pushed in status-go, but that will be in subsequent PRs.
Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-06-05 11:34:04 +00:00
|
|
|
:topics topics
|
2019-04-16 19:09:18 +00:00
|
|
|
:chat-id chat-id}))))
|
2018-12-12 08:55:59 +00:00
|
|
|
|
2019-04-24 19:32:06 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/fetch-more
|
|
|
|
(fn [{:keys [db] :as cofx}]
|
2020-04-29 13:11:24 +00:00
|
|
|
(let [chat-id (:current-chat-id db)
|
2019-04-24 19:32:06 +00:00
|
|
|
|
|
|
|
{:keys [lowest-request-from]}
|
|
|
|
(get-in db [:mailserver/ranges chat-id])
|
|
|
|
|
2020-04-29 13:11:24 +00:00
|
|
|
topics (mailserver.topics/topics-for-current-chat db)
|
|
|
|
gaps [{:id :first-gap
|
|
|
|
:to lowest-request-from
|
|
|
|
:from (- lowest-request-from mailserver.constants/one-day)}]]
|
2019-04-24 19:32:06 +00:00
|
|
|
(mailserver/fill-the-gap
|
|
|
|
cofx
|
|
|
|
{:gaps gaps
|
2020-04-29 13:11:24 +00:00
|
|
|
:topics topics
|
2019-04-24 19:32:06 +00:00
|
|
|
:chat-id chat-id}))))
|
|
|
|
|
2018-09-06 10:04:12 +00:00
|
|
|
(handlers/register-handler-fx
|
2018-09-24 16:27:04 +00:00
|
|
|
:chat.ui/remove-chat-pressed
|
2018-10-01 08:47:20 +00:00
|
|
|
(fn [_ [_ chat-id]]
|
2018-09-24 16:27:04 +00:00
|
|
|
{:ui/show-confirmation {:title (i18n/label :t/delete-confirmation)
|
|
|
|
:content (i18n/label :t/delete-chat-confirmation)
|
|
|
|
:confirm-button-text (i18n/label :t/delete)
|
2020-05-19 10:40:39 +00:00
|
|
|
:on-accept #(do
|
|
|
|
(re-frame/dispatch [:bottom-sheet/hide])
|
|
|
|
(re-frame/dispatch [:chat.ui/remove-chat chat-id]))}}))
|
2018-09-24 16:27:04 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/set-chat-ui-props
|
|
|
|
(fn [{:keys [db]} [_ kvs]]
|
|
|
|
{:db (chat/set-chat-ui-props db kvs)}))
|
|
|
|
|
2019-02-27 12:58:56 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/join-time-messages-checked
|
2019-04-08 14:30:59 +00:00
|
|
|
(fn [cofx [_ chat-id]]
|
|
|
|
(chat/join-time-messages-checked cofx chat-id)))
|
2019-02-27 12:58:56 +00:00
|
|
|
|
2018-09-24 16:27:04 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/show-message-options
|
|
|
|
(fn [{:keys [db]} [_ options]]
|
|
|
|
{:db (chat/set-chat-ui-props db {:show-message-options? true
|
|
|
|
:message-options options})}))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/navigate-to-chat
|
2020-03-10 15:43:27 +00:00
|
|
|
(fn [cofx [_ chat-id _]]
|
|
|
|
(chat/navigate-to-chat cofx chat-id)))
|
2018-09-24 16:27:04 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/load-more-messages
|
|
|
|
(fn [cofx _]
|
2020-02-06 15:17:30 +00:00
|
|
|
(chat.loading/load-more-messages cofx)))
|
2018-09-24 16:27:04 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/start-chat
|
2020-05-08 15:08:53 +00:00
|
|
|
(fn [cofx [_ contact-id]]
|
|
|
|
(chat/start-chat cofx contact-id)))
|
2018-09-24 16:27:04 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/start-public-chat
|
2018-10-17 11:02:34 +00:00
|
|
|
(fn [cofx [_ topic opts]]
|
2020-01-10 06:28:39 +00:00
|
|
|
(chat/start-public-chat cofx topic opts)))
|
2018-09-24 16:27:04 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/remove-chat
|
|
|
|
(fn [cofx [_ chat-id]]
|
2020-10-29 13:59:58 +00:00
|
|
|
(chat/remove-chat cofx chat-id true)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat/remove-update-chat
|
|
|
|
(fn [cofx [_ update-public-key]]
|
|
|
|
(chat/remove-chat cofx (chat/profile-chat-topic update-public-key) false)))
|
2018-09-24 16:27:04 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/clear-history
|
2020-04-29 13:11:24 +00:00
|
|
|
(fn [cofx [_ chat-id]]
|
2020-11-06 14:21:33 +00:00
|
|
|
(chat/clear-history cofx chat-id false)))
|
2018-09-24 16:27:04 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/resend-message
|
2019-11-26 13:15:19 +00:00
|
|
|
(fn [{:keys [db] :as cofx} [_ chat-id message-id]]
|
Improve chat loading performance
This commit does a few things:
Move collections top level
Move `messages`,`message-lists`,`pagination-info` from nested in
`chats` to top level at the db.
The reason for this change is that if any of the `messages` fields
change, any `sub` that relies on `chat` will be recomputed, which is
unnecessary.
Move chat-name to events
`chat-name` was computed dynamically, while it is now only calculated
when loading chat the first time around.
Remove `enrich-chats`
Enrich chats was doing a lot of work, and many subscriptions were
relying on it.
Not all the computations were necessary, for example it would always
calculate the name of who invited the user to a group chat, regardless
of whether it was actually used in the view.
This commit changes that behavior so that we use smaller subscriptions
to calculate such fields.
In general we should move computations to events, if that's not
desirable (there are some cases where we might not want to do that), we
should have "bottom/leaf heavy" subscriptions as opposed to "top heavy",
especially if they are to be shared, so only when (and if) we load that
particular view, the subscription is triggered, while others can be
re-used.
I have compared performance with current release, and there's a
noticeable difference. Opening a chat is faster (messages are loaded
faster), and clicking on the home view on a chat is more responsing
(the animation on-press is much quicker).
2020-05-27 14:29:33 +00:00
|
|
|
(let [message (get-in db [:messages chat-id message-id])]
|
2019-11-26 13:15:19 +00:00
|
|
|
(fx/merge
|
|
|
|
cofx
|
|
|
|
(transport.message/set-message-envelope-hash chat-id message-id (:message-type message) 1)
|
|
|
|
(chat.message/resend-message chat-id message-id)))))
|
2018-09-24 16:27:04 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/delete-message
|
|
|
|
(fn [cofx [_ chat-id message-id]]
|
|
|
|
(chat.message/delete-message cofx chat-id message-id)))
|
|
|
|
|
2018-10-18 00:05:39 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/message-expand-toggled
|
|
|
|
(fn [cofx [_ chat-id message-id]]
|
|
|
|
(chat.message/toggle-expand-message cofx chat-id message-id)))
|
|
|
|
|
2020-08-31 09:52:17 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/select-mention
|
2020-09-28 10:37:03 +00:00
|
|
|
(fn [cofx [_ text-input-ref mention]]
|
|
|
|
(chat.input/select-mention cofx text-input-ref mention)))
|
2020-08-31 09:52:17 +00:00
|
|
|
|
2018-09-24 16:27:04 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/set-chat-input-text
|
|
|
|
(fn [cofx [_ text]]
|
|
|
|
(chat.input/set-chat-input-text cofx text)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/cancel-message-reply
|
|
|
|
(fn [cofx _]
|
|
|
|
(chat.input/cancel-message-reply cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/reply-to-message
|
2020-05-18 13:52:12 +00:00
|
|
|
(fn [cofx [_ message]]
|
|
|
|
(chat.input/reply-to-message cofx message)))
|
2018-09-24 16:27:04 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/send-current-message
|
|
|
|
(fn [cofx _]
|
|
|
|
(chat.input/send-current-message cofx)))
|
|
|
|
|
2019-07-05 09:05:36 +00:00
|
|
|
(defn- mark-messages-seen
|
|
|
|
[{:keys [db] :as cofx}]
|
|
|
|
(let [{:keys [current-chat-id]} db]
|
2020-04-22 10:18:52 +00:00
|
|
|
(message-seen/mark-messages-seen cofx current-chat-id)))
|
2019-07-05 09:05:36 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat.ui/mark-messages-seen
|
|
|
|
(fn [{:keys [db] :as cofx} [_ view-id]]
|
|
|
|
(fx/merge cofx
|
|
|
|
{:db (assoc db :view-id view-id)}
|
|
|
|
#(mark-messages-seen %))))
|
|
|
|
|
2019-01-07 12:50:06 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat/send-sticker
|
2019-07-03 14:29:01 +00:00
|
|
|
(fn [{{:keys [current-chat-id multiaccount]} :db :as cofx} [_ {:keys [hash] :as sticker}]]
|
2019-01-07 12:50:06 +00:00
|
|
|
(fx/merge
|
|
|
|
cofx
|
2019-08-01 20:11:59 +00:00
|
|
|
(multiaccounts.update/multiaccount-update
|
2019-12-10 11:31:22 +00:00
|
|
|
:stickers/recent-stickers
|
|
|
|
(conj (remove #(= hash %) (:stickers/recent-stickers multiaccount)) hash)
|
2019-08-01 20:11:59 +00:00
|
|
|
{})
|
2020-05-14 13:00:06 +00:00
|
|
|
(chat.input/send-sticker-message sticker current-chat-id))))
|
2019-01-07 12:50:06 +00:00
|
|
|
|
2020-07-28 11:06:58 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat/send-audio
|
|
|
|
(fn [{{:keys [current-chat-id]} :db :as cofx} [_ audio-path duration]]
|
|
|
|
(chat.input/send-audio-message cofx audio-path duration current-chat-id)))
|
|
|
|
|
2018-09-24 16:27:04 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:chat/disable-cooldown
|
|
|
|
(fn [cofx _]
|
|
|
|
(chat/disable-chat-cooldown cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:message/update-message-status
|
|
|
|
(fn [cofx [_ chat-id message-id status]]
|
|
|
|
(chat.message/update-message-status cofx chat-id message-id status)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
|
|
|
;; signal module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:signals/signal-received
|
|
|
|
(fn [cofx [_ event-str]]
|
|
|
|
(log/debug :event-str event-str)
|
2018-09-24 15:59:02 +00:00
|
|
|
(signals/process cofx event-str)))
|
2018-09-06 10:04:12 +00:00
|
|
|
|
2020-07-10 10:05:36 +00:00
|
|
|
;; keycard module
|
2018-09-18 16:27:58 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
2020-07-10 10:05:36 +00:00
|
|
|
:keycard.ui/go-to-settings-button-pressed
|
2018-09-18 16:27:58 +00:00
|
|
|
(fn [_ _]
|
2020-07-10 10:05:36 +00:00
|
|
|
{:keycard/open-nfc-settings nil}))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
2018-10-01 16:35:06 +00:00
|
|
|
(handlers/register-handler-fx
|
2020-07-10 10:05:36 +00:00
|
|
|
:keycard.ui/pair-card-button-pressed
|
2018-10-01 16:35:06 +00:00
|
|
|
(fn [{:keys [db]} _]
|
2020-07-10 10:05:36 +00:00
|
|
|
{:db (assoc-in db [:keycard :setup-step] :enter-pair-code)}))
|
2018-10-01 16:35:06 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
2020-07-10 10:05:36 +00:00
|
|
|
:keycard.ui/pair-code-input-changed
|
2018-10-01 16:35:06 +00:00
|
|
|
(fn [{:keys [db]} [_ pair-code]]
|
2020-07-10 10:05:36 +00:00
|
|
|
{:db (assoc-in db [:keycard :secrets :password] pair-code)}))
|
2018-10-01 16:35:06 +00:00
|
|
|
|
2018-12-04 13:41:34 +00:00
|
|
|
(handlers/register-handler-fx
|
2020-07-10 10:05:36 +00:00
|
|
|
:keycard.ui/recovery-phrase-confirm-word-back-button-pressed
|
2018-12-04 13:41:34 +00:00
|
|
|
(fn [{:keys [db]} _]
|
2020-07-10 10:05:36 +00:00
|
|
|
{:db (assoc-in db [:keycard :setup-step] :recovery-phrase)}))
|
2018-12-04 13:41:34 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
2020-07-10 10:05:36 +00:00
|
|
|
:keycard.ui/recovery-phrase-confirm-word-input-changed
|
2018-12-04 13:41:34 +00:00
|
|
|
(fn [{:keys [db]} [_ input]]
|
2020-07-10 10:05:36 +00:00
|
|
|
{:db (assoc-in db [:keycard :recovery-phrase :input-word] input)}))
|
2018-10-01 16:35:06 +00:00
|
|
|
|
2018-12-04 13:41:34 +00:00
|
|
|
(handlers/register-handler-fx
|
2020-07-10 10:05:36 +00:00
|
|
|
:keycard.ui/recovery-phrase-cancel-pressed
|
2018-12-04 13:41:34 +00:00
|
|
|
(fn [{:keys [db]} _]
|
2020-07-10 10:05:36 +00:00
|
|
|
{:db (assoc-in db [:keycard :setup-step] :recovery-phrase)}))
|
2018-09-20 11:24:14 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
2020-07-10 10:05:36 +00:00
|
|
|
:keycard.ui/pin-numpad-delete-button-pressed
|
2018-09-20 11:24:14 +00:00
|
|
|
(fn [{:keys [db]} [_ step]]
|
2020-07-10 10:05:36 +00:00
|
|
|
(when-not (empty? (get-in db [:keycard :pin step]))
|
|
|
|
{:db (update-in db [:keycard :pin step] pop)})))
|
2018-09-20 11:24:14 +00:00
|
|
|
|
2018-10-03 13:16:28 +00:00
|
|
|
(handlers/register-handler-fx
|
2020-07-10 10:05:36 +00:00
|
|
|
:keycard.ui/create-pin-button-pressed
|
2018-10-03 13:16:28 +00:00
|
|
|
(fn [{:keys [db]} _]
|
2018-12-04 13:41:34 +00:00
|
|
|
{:db (-> db
|
2020-07-10 10:05:36 +00:00
|
|
|
(assoc-in [:keycard :setup-step] :pin)
|
|
|
|
(assoc-in [:keycard :pin :enter-step] :original))}))
|
2018-12-04 13:41:34 +00:00
|
|
|
|
2018-09-21 13:41:40 +00:00
|
|
|
;; browser module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.ui/browser-item-selected
|
|
|
|
(fn [cofx [_ browser-id]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(browser/open-existing-browser cofx browser-id)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.ui/url-input-pressed
|
|
|
|
(fn [cofx _]
|
2018-09-24 15:59:02 +00:00
|
|
|
(browser/update-browser-option cofx :url-editing? true)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.ui/url-input-blured
|
|
|
|
(fn [cofx _]
|
2018-09-24 15:59:02 +00:00
|
|
|
(browser/update-browser-option cofx :url-editing? false)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.ui/url-submitted
|
|
|
|
(fn [cofx [_ url]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(browser/open-url-in-current-browser cofx url)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.ui/message-link-pressed
|
|
|
|
(fn [cofx [_ link]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(browser/handle-message-link cofx link)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.ui/remove-browser-pressed
|
|
|
|
(fn [cofx [_ browser-id]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(browser/remove-browser cofx browser-id)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.ui/lock-pressed
|
|
|
|
(fn [cofx [_ secure?]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(browser/update-browser-option cofx :show-tooltip (if secure? :secure :not-secure))))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.ui/close-tooltip-pressed
|
|
|
|
(fn [cofx _]
|
2018-09-24 15:59:02 +00:00
|
|
|
(browser/update-browser-option cofx :show-tooltip nil)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.ui/previous-page-button-pressed
|
|
|
|
(fn [cofx _]
|
|
|
|
(browser/navigate-to-previous-page cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.ui/next-page-button-pressed
|
|
|
|
(fn [cofx _]
|
|
|
|
(browser/navigate-to-next-page cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser/navigation-state-changed
|
|
|
|
(fn [cofx [_ event error?]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(browser/navigation-state-changed cofx event error?)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser/bridge-message-received
|
|
|
|
(fn [cofx [_ message]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(browser/process-bridge-message cofx message)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser/error-occured
|
|
|
|
(fn [cofx _]
|
|
|
|
(browser/handle-browser-error cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser/loading-started
|
|
|
|
(fn [cofx _]
|
2019-03-14 13:39:46 +00:00
|
|
|
(browser/update-browser-options cofx {:error? false :loading? true})))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.callback/resolve-ens-multihash-success
|
2019-04-25 13:02:25 +00:00
|
|
|
(fn [cofx [_ m]]
|
|
|
|
(browser/resolve-ens-multihash-success cofx m)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.callback/resolve-ens-multihash-error
|
|
|
|
(fn [cofx _]
|
2018-11-06 15:09:58 +00:00
|
|
|
(browser/resolve-ens-multihash-error cofx)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
2018-12-12 14:48:17 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.callback/resolve-ens-contenthash
|
|
|
|
(fn [cofx _]
|
|
|
|
(browser/resolve-ens-contenthash cofx)))
|
|
|
|
|
2018-09-21 13:41:40 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.callback/call-rpc
|
|
|
|
(fn [cofx [_ message]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(browser/send-to-bridge cofx message)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.permissions.ui/dapp-permission-allowed
|
2018-09-28 13:40:19 +00:00
|
|
|
(fn [cofx _]
|
|
|
|
(browser.permissions/allow-permission cofx)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.permissions.ui/dapp-permission-denied
|
2018-09-28 13:40:19 +00:00
|
|
|
(fn [cofx _]
|
|
|
|
(browser.permissions/deny-permission cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:browser.permissions.ui/permission-animation-finished
|
2018-09-21 13:41:40 +00:00
|
|
|
(fn [cofx [_ dapp-name]]
|
2018-09-24 15:59:02 +00:00
|
|
|
(browser.permissions/process-next-permission cofx dapp-name)))
|
2018-09-21 13:41:40 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
2019-06-08 04:04:07 +00:00
|
|
|
:browser.ui/open-url
|
2019-08-08 16:19:49 +00:00
|
|
|
(fn [cofx [_ url]]
|
|
|
|
(browser/open-url cofx url)))
|
2018-09-06 14:08:20 +00:00
|
|
|
|
2019-02-04 09:07:41 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:dapps/revoke-access
|
|
|
|
(fn [cofx [_ dapp]]
|
|
|
|
(browser.permissions/revoke-dapp-permissions cofx dapp)))
|
|
|
|
|
2018-07-19 15:51:06 +00:00
|
|
|
;; group-chats module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:group-chats.ui/create-pressed
|
|
|
|
[(re-frame/inject-cofx :random-guid-generator)]
|
|
|
|
(fn [cofx [_ chat-name]]
|
|
|
|
(group-chats/create cofx chat-name)))
|
|
|
|
|
2018-10-01 08:47:20 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:group-chats.ui/add-members-pressed
|
|
|
|
(fn [cofx _]
|
|
|
|
(group-chats/add-members cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:group-chats.ui/remove-member-pressed
|
|
|
|
(fn [cofx [_ chat-id public-key]]
|
|
|
|
(group-chats/remove-member cofx chat-id public-key)))
|
|
|
|
|
2018-11-29 10:06:06 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:group-chats.ui/make-admin-pressed
|
|
|
|
(fn [cofx [_ chat-id public-key]]
|
|
|
|
(group-chats/make-admin cofx chat-id public-key)))
|
|
|
|
|
2018-10-01 08:47:20 +00:00
|
|
|
(handlers/register-handler-fx
|
2020-02-27 15:11:12 +00:00
|
|
|
:group-chats.ui/leave-chat-pressed
|
2020-05-05 14:18:23 +00:00
|
|
|
(fn [_ [_ chat-id _]]
|
2020-02-27 15:11:12 +00:00
|
|
|
{:ui/show-confirmation {:title (i18n/label :t/leave-confirmation)
|
|
|
|
:content (i18n/label :t/leave-chat-confirmation)
|
|
|
|
:confirm-button-text (i18n/label :t/leave)
|
2020-05-19 10:40:39 +00:00
|
|
|
:on-accept #(do
|
|
|
|
(re-frame/dispatch [:bottom-sheet/hide])
|
|
|
|
(re-frame/dispatch [:group-chats.ui/leave-chat-confirmed chat-id]))}}))
|
2018-12-17 14:59:04 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:group-chats.ui/join-pressed
|
|
|
|
(fn [cofx [_ chat-id]]
|
|
|
|
(group-chats/join-chat cofx chat-id)))
|
|
|
|
|
2018-10-09 08:10:47 +00:00
|
|
|
;; transport module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:transport/send-status-message-error
|
2020-05-05 14:18:23 +00:00
|
|
|
(fn [_ [_ err]]
|
2018-10-09 08:10:47 +00:00
|
|
|
(log/error :send-status-message-error err)))
|
|
|
|
|
2020-07-07 10:20:48 +00:00
|
|
|
(fx/defn handle-update [cofx {:keys [chats messages emojiReactions invitations]}]
|
2020-07-03 15:04:45 +00:00
|
|
|
(let [chats (map data-store.chats/<-rpc chats)
|
|
|
|
messages (map data-store.messages/<-rpc messages)
|
|
|
|
message-fxs (map chat.message/receive-one messages)
|
|
|
|
emoji-reactions (map data-store.reactions/<-rpc emojiReactions)
|
|
|
|
emoji-react-fxs (map chat.reactions/receive-one emoji-reactions)
|
2020-07-07 10:20:48 +00:00
|
|
|
invitations-fxs [(group-chats/handle-invitations
|
|
|
|
(map data-store.invitations/<-rpc invitations))]
|
2020-07-03 15:04:45 +00:00
|
|
|
chat-fxs (map #(chat/ensure-chat (dissoc % :unviewed-messages-count)) chats)]
|
2020-07-07 10:20:48 +00:00
|
|
|
(apply fx/merge cofx (concat chat-fxs message-fxs emoji-react-fxs invitations-fxs))))
|
2019-11-26 13:15:19 +00:00
|
|
|
|
2018-10-09 08:10:47 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:transport/message-sent
|
2019-11-26 13:15:19 +00:00
|
|
|
(fn [cofx [_ response messages-count]]
|
2020-04-22 12:27:47 +00:00
|
|
|
(let [set-hash-fxs (map (fn [{:keys [localChatId id messageType]}]
|
|
|
|
(transport.message/set-message-envelope-hash localChatId id messageType messages-count))
|
|
|
|
(:messages response))]
|
|
|
|
(apply fx/merge cofx
|
|
|
|
(conj set-hash-fxs
|
|
|
|
(handle-update response))))))
|
2018-10-11 08:38:23 +00:00
|
|
|
|
2020-07-03 15:04:45 +00:00
|
|
|
(fx/defn reaction-sent
|
|
|
|
{:events [:transport/reaction-sent]}
|
|
|
|
[cofx response]
|
|
|
|
(handle-update cofx response))
|
|
|
|
|
|
|
|
(fx/defn retraction-sent
|
|
|
|
{:events [:transport/retraction-sent]}
|
|
|
|
[cofx response]
|
|
|
|
(handle-update cofx response))
|
|
|
|
|
2020-07-07 10:20:48 +00:00
|
|
|
(fx/defn invitation-sent
|
|
|
|
{:events [:transport/invitation-sent]}
|
|
|
|
[cofx response]
|
|
|
|
(handle-update cofx response))
|
|
|
|
|
2019-02-22 12:26:40 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:transport.callback/node-info-fetched
|
|
|
|
(fn [cofx [_ node-info]]
|
|
|
|
(transport/set-node-info cofx node-info)))
|
|
|
|
|
2018-10-11 08:38:23 +00:00
|
|
|
;; contact module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:contact.ui/add-to-contact-pressed
|
|
|
|
[(re-frame/inject-cofx :random-id-generator)]
|
2018-10-26 18:06:23 +00:00
|
|
|
(fn [cofx [_ public-key]]
|
2020-08-20 14:26:40 +00:00
|
|
|
(contact/add-contact cofx public-key nil)))
|
2018-10-11 08:38:23 +00:00
|
|
|
|
2018-12-20 14:50:02 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:contact.ui/block-contact-confirmed
|
|
|
|
(fn [cofx [_ public-key]]
|
2019-02-22 12:26:40 +00:00
|
|
|
(contact.block/block-contact cofx public-key)))
|
2018-12-20 14:50:02 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:contact.ui/unblock-contact-pressed
|
|
|
|
(fn [cofx [_ public-key]]
|
2019-02-22 12:26:40 +00:00
|
|
|
(contact.block/unblock-contact cofx public-key)))
|
2018-12-20 14:50:02 +00:00
|
|
|
|
2018-10-11 08:38:23 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:contact.ui/start-group-chat-pressed
|
2020-05-05 14:18:23 +00:00
|
|
|
(fn [cofx _]
|
2018-10-11 08:38:23 +00:00
|
|
|
(contact/open-contact-toggle-list cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:contact.ui/send-message-pressed
|
|
|
|
[(re-frame/inject-cofx :random-id-generator)]
|
2018-10-26 18:06:23 +00:00
|
|
|
(fn [cofx [_ {:keys [public-key]}]]
|
2020-05-08 15:08:53 +00:00
|
|
|
(chat/start-chat cofx public-key)))
|
2018-10-11 08:38:23 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:contact.ui/contact-code-submitted
|
|
|
|
[(re-frame/inject-cofx :random-id-generator)]
|
2020-08-20 14:26:40 +00:00
|
|
|
(fn [{{:contacts/keys [new-identity]} :db :as cofx} [_ new-contact? nickname]]
|
2019-12-18 11:07:08 +00:00
|
|
|
(let [{:keys [public-key ens-name]} new-identity]
|
|
|
|
(fx/merge cofx
|
2020-06-30 13:05:30 +00:00
|
|
|
#(if new-contact?
|
2020-08-20 14:26:40 +00:00
|
|
|
(contact/add-contact % public-key nickname)
|
2020-05-08 15:08:53 +00:00
|
|
|
(chat/start-chat % public-key))
|
2020-06-30 13:05:30 +00:00
|
|
|
#(when new-contact?
|
|
|
|
(navigation/navigate-back %))
|
2019-12-18 11:07:08 +00:00
|
|
|
#(when ens-name
|
|
|
|
(contact/name-verified % public-key ens-name))))))
|
2018-10-13 16:47:34 +00:00
|
|
|
|
2018-10-09 10:43:07 +00:00
|
|
|
;; pairing module
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:pairing.ui/pair-devices-pressed
|
|
|
|
(fn [cofx _]
|
2020-01-10 06:28:39 +00:00
|
|
|
(log/info "Sending pair installation")
|
|
|
|
(pairing/send-pair-installation cofx)))
|
2018-10-09 10:43:07 +00:00
|
|
|
|
2019-01-14 14:43:34 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:pairing.ui/set-name-pressed
|
|
|
|
(fn [cofx [_ installation-name]]
|
|
|
|
(pairing/set-name cofx installation-name)))
|
|
|
|
|
2018-10-09 10:43:07 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:pairing.ui/synchronize-installation-pressed
|
|
|
|
(fn [cofx _]
|
2018-11-08 13:07:29 +00:00
|
|
|
(pairing/send-installation-messages cofx)))
|
2018-11-02 13:48:45 +00:00
|
|
|
|
2019-06-25 14:34:55 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:pairing.callback/get-our-installations-success
|
|
|
|
(fn [cofx [_ installations]]
|
|
|
|
(pairing/load-installations cofx installations)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:pairing.callback/set-installation-metadata-success
|
|
|
|
(fn [cofx [_ installation-id metadata]]
|
|
|
|
(pairing/update-installation cofx installation-id metadata)))
|
|
|
|
|
2018-11-02 13:48:45 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:pairing.ui/enable-installation-pressed
|
|
|
|
(fn [cofx [_ installation-id]]
|
|
|
|
(pairing/enable-fx cofx installation-id)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:pairing.ui/disable-installation-pressed
|
|
|
|
(fn [cofx [_ installation-id]]
|
|
|
|
(pairing/disable-fx cofx installation-id)))
|
|
|
|
|
2018-11-30 15:11:32 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:pairing.ui/prompt-dismissed
|
|
|
|
(fn [cofx _]
|
|
|
|
(pairing/prompt-dismissed cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:pairing.ui/prompt-accepted
|
|
|
|
(fn [cofx _]
|
|
|
|
(pairing/prompt-accepted cofx)))
|
|
|
|
|
2018-11-02 13:48:45 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:pairing.callback/enable-installation-success
|
|
|
|
(fn [cofx [_ installation-id]]
|
2019-02-05 15:49:10 +00:00
|
|
|
(fx/merge cofx
|
|
|
|
(pairing/enable installation-id)
|
2019-07-03 14:29:01 +00:00
|
|
|
(multiaccounts.update/send-multiaccount-update))))
|
2018-11-02 13:48:45 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:pairing.callback/disable-installation-success
|
|
|
|
(fn [cofx [_ installation-id]]
|
2019-02-05 15:49:10 +00:00
|
|
|
(fx/merge cofx
|
|
|
|
(pairing/disable installation-id)
|
2019-07-03 14:29:01 +00:00
|
|
|
(multiaccounts.update/send-multiaccount-update))))
|
2018-12-27 12:12:54 +00:00
|
|
|
|
2019-01-07 12:50:06 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:stickers/load-sticker-pack-success
|
2019-11-30 10:29:25 +00:00
|
|
|
(fn [cofx [_ edn-string id price]]
|
|
|
|
(stickers/load-sticker-pack-success cofx edn-string id price)))
|
2019-01-07 12:50:06 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:stickers/install-pack
|
|
|
|
(fn [cofx [_ id]]
|
|
|
|
(stickers/install-stickers-pack cofx id)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:stickers/load-packs
|
2019-02-15 09:08:42 +00:00
|
|
|
(fn [cofx _]
|
|
|
|
(stickers/load-packs cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:stickers/load-pack
|
2019-11-30 10:29:25 +00:00
|
|
|
(fn [cofx [_ url id price]]
|
|
|
|
(stickers/load-pack cofx url id price)))
|
2019-01-07 12:50:06 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:stickers/select-pack
|
|
|
|
(fn [{:keys [db]} [_ id]]
|
2019-01-29 09:42:53 +00:00
|
|
|
{:db (assoc db :stickers/selected-pack id)}))
|
2019-02-07 15:49:07 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:stickers/open-sticker-pack
|
2019-02-15 09:08:42 +00:00
|
|
|
(fn [cofx [_ id]]
|
|
|
|
(stickers/open-sticker-pack cofx id)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:stickers/buy-pack
|
|
|
|
(fn [cofx [_ id price]]
|
|
|
|
(stickers/approve-pack cofx id price)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:stickers/pack-owned
|
|
|
|
(fn [cofx [_ id]]
|
|
|
|
(stickers/pack-owned cofx id)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:stickers/pending-pack
|
|
|
|
(fn [cofx [_ id]]
|
|
|
|
(stickers/pending-pack cofx id)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
2020-02-13 12:33:52 +00:00
|
|
|
:stickers/pending-timeout
|
2019-02-15 09:08:42 +00:00
|
|
|
(fn [cofx _]
|
|
|
|
(stickers/pending-timeout cofx)))
|
2019-02-22 13:12:29 +00:00
|
|
|
|
2019-05-20 08:02:56 +00:00
|
|
|
;;custom tokens
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.custom-token/decimals-result
|
|
|
|
(fn [cofx [_ result]]
|
|
|
|
(custom-tokens/decimals-result cofx result)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.custom-token/symbol-result
|
|
|
|
(fn [cofx [_ contract result]]
|
|
|
|
(custom-tokens/symbol-result cofx contract result)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.custom-token/name-result
|
|
|
|
(fn [cofx [_ contract result]]
|
|
|
|
(custom-tokens/name-result cofx contract result)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.custom-token/balance-result
|
|
|
|
(fn [cofx [_ contract result]]
|
|
|
|
(custom-tokens/balance-result cofx contract result)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.custom-token/total-supply-result
|
|
|
|
(fn [cofx [_ contract result]]
|
|
|
|
(custom-tokens/total-supply-result cofx contract result)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.custom-token/contract-address-is-pasted
|
|
|
|
(fn [cofx [_ contract]]
|
|
|
|
(custom-tokens/contract-address-is-changed cofx contract)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.custom-token.ui/contract-address-paste
|
|
|
|
(fn [_ _]
|
|
|
|
{:wallet.custom-token/contract-address-paste nil}))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.custom-token.ui/field-is-edited
|
|
|
|
(fn [cofx [_ field-key value]]
|
|
|
|
(custom-tokens/field-is-edited cofx field-key value)))
|
|
|
|
|
2019-05-09 19:51:41 +00:00
|
|
|
;; ethereum subscriptions events
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:ethereum.callback/subscription-success
|
|
|
|
(fn [cofx [_ id handler]]
|
|
|
|
(ethereum.subscriptions/register-subscription cofx id handler)))
|
|
|
|
|
2019-05-17 10:02:16 +00:00
|
|
|
;; wallet events
|
2019-05-18 11:06:42 +00:00
|
|
|
|
2019-05-17 10:02:16 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.transactions/add-filter
|
|
|
|
(fn [{:keys [db]} [_ id]]
|
|
|
|
{:db (update-in db [:wallet :filters] conj id)}))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.transactions/remove-filter
|
|
|
|
(fn [{:keys [db]} [_ id]]
|
|
|
|
{:db (update-in db [:wallet :filters] disj id)}))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.transactions/add-all-filters
|
|
|
|
(fn [{:keys [db]} _]
|
|
|
|
{:db (assoc-in db [:wallet :filters]
|
|
|
|
wallet.db/default-wallet-filters)}))
|
2019-05-18 11:06:42 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.settings/toggle-visible-token
|
|
|
|
(fn [cofx [_ symbol checked?]]
|
|
|
|
(wallet/toggle-visible-token cofx symbol checked?)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.settings.ui/navigate-back-pressed
|
|
|
|
(fn [cofx [_ on-close]]
|
|
|
|
(fx/merge cofx
|
|
|
|
(when on-close
|
|
|
|
{:dispatch on-close})
|
2019-08-23 23:21:38 +00:00
|
|
|
(navigation/navigate-back))))
|
2019-05-18 11:06:42 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.ui/show-transaction-details
|
2019-08-12 08:53:31 +00:00
|
|
|
(fn [cofx [_ hash address]]
|
|
|
|
(wallet/open-transaction-details cofx hash address)))
|
2019-05-18 11:06:42 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet.setup.ui/navigate-back-pressed
|
|
|
|
(fn [{:keys [db] :as cofx}]
|
|
|
|
(fx/merge cofx
|
|
|
|
{:db (assoc-in db [:wallet :send-transaction] {})}
|
|
|
|
(navigation/navigate-back))))
|
2019-05-07 06:37:43 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:shake-event
|
|
|
|
(fn [cofx _]
|
|
|
|
(logging/show-logs-dialog cofx)))
|
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
|
|
|
|
2019-11-16 09:56:09 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:dismiss-keyboard
|
|
|
|
(fn [_]
|
|
|
|
{:dismiss-keyboard nil}))
|
|
|
|
|
2019-06-17 09:41:37 +00:00
|
|
|
(handlers/register-handler-fx
|
|
|
|
:wallet-send-request
|
2020-05-05 14:18:23 +00:00
|
|
|
(fn [cofx [_ public-key _ _ _]]
|
2019-06-17 09:41:37 +00:00
|
|
|
(assert public-key)
|
2020-05-05 14:18:23 +00:00
|
|
|
(fx/merge cofx
|
|
|
|
(navigation/navigate-back)
|
2020-05-08 15:08:53 +00:00
|
|
|
(chat/start-chat public-key)
|
2020-05-05 14:18:23 +00:00
|
|
|
;; TODO send
|
|
|
|
#_(commands.sending/send public-key
|
|
|
|
request-command
|
|
|
|
{:asset (name symbol)
|
|
|
|
:amount (str (money/internal->formatted amount symbol decimals))}))))
|
2019-11-28 10:00:29 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:identicon-generated
|
|
|
|
(fn [{:keys [db]} [_ path identicon]]
|
|
|
|
{:db (assoc-in db path identicon)}))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:gfycat-generated
|
|
|
|
(fn [{:keys [db]} [_ path gfycat]]
|
2019-12-10 11:31:22 +00:00
|
|
|
{:db (assoc-in db path gfycat)}))
|
2020-03-16 13:02:35 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:system-theme-mode-changed
|
|
|
|
(fn [{:keys [db]} [_ theme]]
|
|
|
|
(let [cur-theme (get-in db [:multiaccount :appearance])]
|
2020-04-29 13:11:24 +00:00
|
|
|
(when (or (nil? cur-theme) (zero? cur-theme))
|
2020-03-26 11:36:41 +00:00
|
|
|
{::multiaccounts/switch-theme (if (= :dark theme) 2 1)}))))
|
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/listen-to-window-dimensions-change
|
|
|
|
(fn []
|
|
|
|
(dimensions/add-event-listener)))
|
|
|
|
|
|
|
|
(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)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:set
|
|
|
|
(fn [{:keys [db]} [_ k v]]
|
|
|
|
{:db (assoc db k v)}))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:set-once
|
|
|
|
(fn [{:keys [db]} [_ k v]]
|
|
|
|
(when-not (get db k)
|
|
|
|
{:db (assoc db k v)})))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:set-in
|
|
|
|
(fn [{:keys [db]} [_ path v]]
|
|
|
|
{:db (assoc-in db path v)}))
|
|
|
|
|
|
|
|
(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)
|
|
|
|
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))]
|
|
|
|
(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)
|
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
|
|
|
|
|
|
|
(defn app-state-change [state {:keys [db] :as cofx}]
|
|
|
|
(let [app-coming-from-background? (= state "active")
|
|
|
|
app-going-in-background? (= state "background")]
|
|
|
|
(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 %)))))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:app-state-change
|
|
|
|
(fn [cofx [_ state]]
|
|
|
|
(app-state-change state cofx)))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:request-permissions
|
|
|
|
(fn [_ [_ options]]
|
|
|
|
{:request-permissions-fx options}))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:set-swipe-position
|
|
|
|
(fn [{:keys [db]} [_ type item-id value]]
|
|
|
|
{:db (assoc-in db [:animations type item-id :delete-swiped] value)}))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:update-window-dimensions
|
|
|
|
(fn [{:keys [db]} [_ dimensions]]
|
|
|
|
{:db (assoc db :dimensions/window (dimensions/window dimensions))}))
|
|
|
|
|
2020-10-02 09:53:02 +00:00
|
|
|
(fx/defn reset-current-profile-chat [{:keys [db] :as cofx} public-key]
|
|
|
|
(let [chat-id (chat/profile-chat-topic public-key)]
|
|
|
|
(when-not (= (:current-chat-id db) chat-id)
|
|
|
|
(fx/merge cofx
|
2020-10-29 13:59:58 +00:00
|
|
|
(chat/start-profile-chat public-key)
|
2020-10-02 09:53:02 +00:00
|
|
|
(chat/offload-all-messages)
|
|
|
|
(chat/preload-chat-data chat-id)))))
|
|
|
|
|
2020-10-29 13:59:58 +00:00
|
|
|
(fx/defn reset-current-timeline-chat [{:keys [db] :as cofx}]
|
|
|
|
(let [profile-chats (conj (map :public-key (contact.db/get-active-contacts (:contacts/contacts db)))
|
|
|
|
(get-in db [:multiaccount :public-key]))]
|
|
|
|
(when-not (= (:current-chat-id db) chat/timeline-chat-id)
|
|
|
|
(fx/merge cofx
|
|
|
|
(fn [cofx]
|
|
|
|
(apply fx/merge cofx (map chat/start-profile-chat profile-chats)))
|
|
|
|
(chat/start-timeline-chat)
|
|
|
|
(chat/offload-all-messages)
|
|
|
|
(chat/preload-chat-data chat/timeline-chat-id)))))
|
|
|
|
|
2020-10-02 09:53:02 +00:00
|
|
|
(fx/defn reset-current-chat [{:keys [db] :as cofx} chat-id]
|
|
|
|
(when-not (= (:current-chat-id db) chat-id)
|
|
|
|
(fx/merge cofx
|
|
|
|
(chat/offload-all-messages)
|
|
|
|
(chat/preload-chat-data chat-id))))
|
|
|
|
|
2020-04-29 13:11:24 +00:00
|
|
|
;; NOTE: Will be removed with the keycard PR
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:screens/on-will-focus
|
2020-10-02 09:53:02 +00:00
|
|
|
(fn [{:keys [db] :as cofx} [_ view-id]]
|
2020-04-29 13:11:24 +00:00
|
|
|
(fx/merge cofx
|
|
|
|
#(case view-id
|
2020-07-10 10:05:36 +00:00
|
|
|
:keycard-settings (keycard/settings-screen-did-load %)
|
|
|
|
:reset-card (keycard/reset-card-screen-did-load %)
|
|
|
|
:enter-pin-settings (keycard/enter-pin-screen-did-load %)
|
|
|
|
:keycard-login-pin (keycard/enter-pin-screen-did-load %)
|
|
|
|
:add-new-account-pin (keycard/enter-pin-screen-did-load %)
|
|
|
|
:keycard-authentication-method (keycard/authentication-method-screen-did-load %)
|
2020-10-02 09:53:02 +00:00
|
|
|
(:chat :group-chat-profile) (reset-current-chat % (get db :inactive-chat-id))
|
2020-07-10 10:05:36 +00:00
|
|
|
:multiaccounts (keycard/multiaccounts-screen-did-load %)
|
2020-10-05 10:11:57 +00:00
|
|
|
(:wallet-stack :wallet) (wallet.events/wallet-will-focus %)
|
2020-10-29 13:59:58 +00:00
|
|
|
(:status :status-stack)
|
|
|
|
(reset-current-timeline-chat %)
|
2020-10-02 09:53:02 +00:00
|
|
|
:profile
|
|
|
|
(reset-current-profile-chat % (get-in % [:db :contacts/identity]))
|
2020-04-29 13:11:24 +00:00
|
|
|
nil))))
|
2020-10-02 09:53:02 +00:00
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:screens/tab-will-change
|
|
|
|
(fn [{:keys [db] :as cofx} [_ view-id]]
|
|
|
|
(fx/merge cofx
|
|
|
|
#(case view-id
|
|
|
|
;;when we back to chat we want to show inactive chat
|
|
|
|
:chat
|
|
|
|
(reset-current-chat % (get db :inactive-chat-id))
|
|
|
|
|
2020-10-29 13:59:58 +00:00
|
|
|
(:status :status-stack)
|
|
|
|
(reset-current-timeline-chat %)
|
2020-10-02 09:53:02 +00:00
|
|
|
|
|
|
|
:profile
|
|
|
|
(reset-current-profile-chat % (get-in % [:db :contacts/identity]))
|
|
|
|
|
2020-11-06 14:21:33 +00:00
|
|
|
nil))))
|
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}))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
::crypto-loaded
|
|
|
|
(fn [{:keys [db]} [_ on-ramps]]
|
|
|
|
(log/info "on-ramps event received" on-ramps)
|
|
|
|
{:db (assoc
|
|
|
|
db
|
|
|
|
:buy-crypto/on-ramps
|
|
|
|
(map on-ramp<-rpc on-ramps))}))
|
|
|
|
|
|
|
|
(handlers/register-handler-fx
|
|
|
|
:buy-crypto.ui/loaded
|
|
|
|
(fn [_ _]
|
|
|
|
{::json-rpc/call [{:method "wallet_getCryptoOnRamps"
|
|
|
|
:params []
|
|
|
|
:on-success (fn [on-ramps]
|
|
|
|
(log/info "on-ramps received" on-ramps)
|
|
|
|
(re-frame/dispatch [::crypto-loaded on-ramps]))}]}))
|