status-im/utils/fx replaced with utils/re-frame to avoid unambiguities (#14640)

This commit is contained in:
Volodymyr Kozieiev 2022-12-26 15:00:17 +00:00 committed by GitHub
parent a39e0f6fbd
commit 9c7b69a2cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
140 changed files with 2345 additions and 2529 deletions

View File

@ -10,7 +10,7 @@
[status-im.i18n.i18n :as i18n]
[status-im.router.core :as router]
[status-im.utils.db :as utils.db]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.random :as random]
[status-im.utils.utils :as utils]
[status-im2.navigation.events :as navigation]))
@ -24,7 +24,7 @@
;;NOTE we want to handle only last resolve
(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]}
[{db :db} new-identity-raw new-ens-name id]
(let [ens-error (and (= new-identity-raw "0x") (not (string/blank? new-ens-name)))]
@ -61,12 +61,12 @@
new-identity
@resolve-last-id])}})))))))
(fx/defn clear-new-identity
(rf/defn clear-new-identity
{:events [::clear-new-identity ::new-chat-focus]}
[{:keys [db]}]
{:db (dissoc db :contacts/new-identity)})
(fx/defn qr-code-handled
(rf/defn 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}]
@ -81,7 +81,7 @@
validation-result (db/validate-pub-key db chat-key)]
(if-not validation-result
(if new-contact?
(fx/merge cofx
(rf/merge cofx
(contact/add-contact chat-key nickname ens-name)
(navigation/navigate-to-cofx :contacts-list {}))
(chat/start-chat cofx chat-key ens-name))
@ -93,7 +93,7 @@
(i18n/label :t/can-not-add-yourself))
: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]}
[{:keys [db]} data opts]
{::router/handle-uri {:chain (ethereum/chain-keyword db)

View File

@ -1,19 +1,19 @@
(ns status-im.backup.core
(:require [re-frame.core :as re-frame]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[taoensso.timbre :as log]))
(fx/defn handle-backup-failed
(rf/defn handle-backup-failed
{:events [::backup-failed]}
[{:keys [db]}]
{:db (dissoc db :backup/performing-backup)})
(fx/defn handle-backup-perfomed
(rf/defn handle-backup-perfomed
{:events [::backup-performed]}
[{:keys [db]}]
{:db (dissoc db :backup/performing-backup)})
(fx/defn handle-perform-backup-pressed
(rf/defn handle-perform-backup-pressed
{:events [:multiaccounts.ui/perform-backup-pressed]}
[{:keys [db]}]
{:db (assoc db :backup/performing-backup true)

View File

@ -3,7 +3,7 @@
[re-frame.core :as re-frame]
[status-im.i18n.i18n :as i18n]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im2.navigation.events :as navigation]))
(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})")
@ -19,12 +19,12 @@
:id (string/replace id "-" "")
:name bootnode-name})
(fx/defn fetch
(rf/defn fetch
[cofx id]
(let [network (get-in cofx [:db :networks/current-network])]
(get-in cofx [:db :multiaccount :custom-bootnodes network id])))
(fx/defn set-input
(rf/defn set-input
{:events [:bootnodes.ui/input-changed]}
[{:keys [db]} input-key value]
{:db (update
@ -38,14 +38,14 @@
:name (string/blank? value)
:url (not (valid-address? value)))})})
(fx/defn edit
(rf/defn edit
{:events [:bootnodes.ui/add-bootnode-pressed]}
[{:keys [db] :as cofx} id]
(let [{:keys [id
address
name]}
(fetch cofx id)
fxs (fx/merge cofx
fxs (rf/merge cofx
(set-input :id id)
(set-input :url (str address))
(set-input :name (str name)))]
@ -56,11 +56,11 @@
(let [network (:networks/current-network db)]
(get-in db [:multiaccount :custom-bootnodes-enabled? network])))
(fx/defn delete
(rf/defn delete
[{{:keys [multiaccount] :as db} :db :as cofx} id]
(let [network (:networks/current-network db)
new-multiaccount (update-in multiaccount [:custom-bootnodes network] dissoc id)]
(fx/merge cofx
(rf/merge cofx
{:db (assoc db :multiaccount new-multiaccount)}
(multiaccounts.update/multiaccount-update
:custom-bootnodes
@ -68,7 +68,7 @@
{:success-event (when (custom-bootnodes-in-use? cofx)
[:multiaccounts.update.callback/save-settings-success])}))))
(fx/defn upsert
(rf/defn upsert
{:events [:bootnodes.ui/save-pressed]
:interceptors [(re-frame/inject-cofx :random-id-generator)]}
[{{:bootnodes/keys [manage] :keys [multiaccount] :as db} :db
@ -86,7 +86,7 @@
[network (:id bootnode)]
bootnode)]
(fx/merge cofx
(rf/merge cofx
{:db (dissoc db :bootnodes/manage)
:dispatch [:navigate-back]}
(multiaccounts.update/multiaccount-update
@ -95,7 +95,7 @@
{:success-event (when (custom-bootnodes-in-use? cofx)
[:multiaccounts.update.callback/save-settings-success])}))))
(fx/defn toggle-custom-bootnodes
(rf/defn toggle-custom-bootnodes
{:events [:bootnodes.ui/custom-bootnodes-switch-toggled]}
[{:keys [db] :as cofx} value]
(let [current-network (:networks/current-network db)
@ -106,14 +106,14 @@
(assoc bootnodes-settings current-network value)
{: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]}
[cofx url]
(assoc (set-input cofx :url (string/trim url))
:dispatch
[:navigate-back]))
(fx/defn show-delete-bootnode-confirmation
(rf/defn show-delete-bootnode-confirmation
{:events [:bootnodes.ui/delete-pressed]}
[_ bootnode-id]
{:ui/show-confirmation {:title (i18n/label :t/delete-bootnode-title)
@ -122,9 +122,9 @@
:on-accept #(re-frame/dispatch [:bootnodes.ui/delete-confirmed
bootnode-id])}})
(fx/defn delete-bootnode
(rf/defn delete-bootnode
{:events [:bootnodes.ui/delete-confirmed]}
[cofx bootnode-id]
(fx/merge cofx
(rf/merge cofx
(delete bootnode-id)
(navigation/navigate-back)))

View File

@ -1,7 +1,7 @@
(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]}]
{:show-bottom-sheet nil
:db (assoc db
@ -9,7 +9,7 @@
:bottom-sheet/view view
:bottom-sheet/options options)})
(fx/defn show-bottom-sheet-event
(rf/defn show-bottom-sheet-event
{:events [:bottom-sheet/show-sheet]}
[cofx view options]
(show-bottom-sheet
@ -17,7 +17,7 @@
{:view view
:options options}))
(fx/defn hide-bottom-sheet
(rf/defn hide-bottom-sheet
{:events [:bottom-sheet/hide]}
[{:keys [db]}]
{:hide-bottom-sheet nil

View File

@ -15,7 +15,7 @@
[status-im.native-module.core :as status]
[status-im.signing.core :as signing]
[status-im.ui.components.list-selection :as list-selection]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.http :as http]
[status-im.utils.platform :as platform]
[status-im.utils.random :as random]
@ -26,11 +26,11 @@
[utils.debounce :as debounce]
[utils.security.core :as security]))
(fx/defn update-browser-option
(rf/defn update-browser-option
[{:keys [db]} 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]
{:db (update db :browser/options merge options)})
@ -51,7 +51,7 @@
(when url
(string/starts-with? url "https://")))))
(fx/defn remove-browser
(rf/defn remove-browser
{:events [:browser.ui/remove-browser-pressed]}
[{:keys [db]} browser-id]
{:db (update-in db [:browser/browsers] dissoc browser-id)
@ -59,7 +59,7 @@
:params [browser-id]
:on-success #()}]})
(fx/defn clear-all-browsers
(rf/defn clear-all-browsers
{:events [:browser.ui/clear-all-browsers-pressed]}
[{:keys [db]}]
{:db (dissoc db :browser/browsers)
@ -83,7 +83,7 @@
(re-frame/dispatch [:browser.callback/resolve-ens-multihash-success url])
(re-frame/dispatch [:browser.callback/resolve-ens-multihash-error])))
(fx/defn resolve-url
(rf/defn resolve-url
[{:keys [db]} {:keys [error? resolved-url]}]
(when (not error?)
(let [current-url (get-current-url (get-current-browser db))
@ -95,7 +95,7 @@
:cb resolve-ens-contenthash-callback}}
{: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 [browser-id] :as browser}]
(let [updated-browser (-> browser
@ -111,7 +111,7 @@
:history-index])]
:on-success #()}]}))
(fx/defn store-bookmark
(rf/defn store-bookmark
{:events [:browser/store-bookmark]}
[{:keys [db]}
{:keys [url] :as bookmark}]
@ -120,25 +120,25 @@
:params [bookmark]
:on-success #()}]})
(fx/defn update-bookmark
(rf/defn update-bookmark
{:events [:browser/update-bookmark]}
[{:keys [db] :as cofx}
{:keys [url] :as bookmark}]
(let [old-bookmark (get-in db [:bookmarks/bookmarks url])
new-bookmark (merge old-bookmark bookmark)]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:bookmarks/bookmarks url] new-bookmark)
:json-rpc/call [{:method "wakuext_updateBookmark"
:params [url bookmark]
:on-success #()}]})))
(fx/defn delete-bookmark
(rf/defn delete-bookmark
{:events [:browser/delete-bookmark]}
[{:keys [db] :as cofx}
url]
(let [old-bookmark (get-in db [:bookmarks/bookmarks url])
removed-bookmark (merge old-bookmark {:removed true})]
(fx/merge cofx
(rf/merge cofx
{:db (update db :bookmarks/bookmarks dissoc url)
:json-rpc/call [{:method "wakuext_removeBookmark"
:params [url]
@ -148,16 +148,16 @@
[{:keys [history-index]}]
(pos? history-index))
(fx/defn navigate-to-previous-page
(rf/defn navigate-to-previous-page
{:events [:browser.ui/previous-page-button-pressed]}
[cofx]
(let [{:keys [history-index] :as browser} (get-current-browser (:db cofx))]
(when (can-go-back? browser)
(fx/merge cofx
(rf/merge cofx
(update-browser (assoc browser :history-index (dec history-index)))
(resolve-url nil)))))
(fx/defn ignore-unsafe
(rf/defn ignore-unsafe
{:events [:browser/ignore-unsafe]}
[cofx]
(let [browser (get-current-browser (:db cofx))
@ -168,16 +168,16 @@
[{:keys [history-index 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]}
[cofx]
(let [{:keys [history-index] :as browser} (get-current-browser (:db cofx))]
(when (can-go-forward? browser)
(fx/merge cofx
(rf/merge cofx
(update-browser (assoc browser :history-index (inc history-index)))
(resolve-url nil)))))
(fx/defn update-browser-history
(rf/defn update-browser-history
[cofx browser url]
(let [history-index (:history-index browser)
history (:history browser)]
@ -189,14 +189,14 @@
:history new-history
:history-index new-index))))))
(fx/defn resolve-ens-multihash-success
(rf/defn resolve-ens-multihash-success
{:events [:browser.callback/resolve-ens-multihash-success]}
[{:keys [db] :as cofx} url]
(let [current-url (get-current-url (get-current-browser db))
host (http/url-host current-url)
path (subs current-url (+ (.indexOf ^js current-url host) (count host)))
gateway url]
(fx/merge cofx
(rf/merge cofx
{:db (-> (update db
:browser/options
assoc
@ -204,7 +204,7 @@
:resolving? false)
(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]}
[{:keys [db] :as cofx}]
(update-browser-options cofx
@ -212,19 +212,19 @@
:resolving? false
:error? true}))
(fx/defn handle-browser-error
(rf/defn handle-browser-error
{:events [:browser/error-occured]}
[cofx]
(fx/merge cofx
(rf/merge cofx
(update-browser-option :error? true)
(update-browser-option :loading? false)))
(fx/defn handle-pdf
(rf/defn handle-pdf
[_ url]
(when (and platform/android? (string/ends-with? url ".pdf"))
{:browser/show-web-browser-selection url}))
(fx/defn handle-message-link
(rf/defn handle-message-link
{:events [:browser.ui/message-link-pressed]}
[_ link]
(when (security/safe-link? link)
@ -232,7 +232,7 @@
{:dispatch [:universal-links/handle-url link]}
{:browser/show-browser-selection link})))
(fx/defn update-browser-on-nav-change
(rf/defn update-browser-on-nav-change
[cofx url error?]
(let [browser (get-current-browser (:db cofx))
options (get-in cofx [:db :browser/options])
@ -250,18 +250,18 @@
(second resolved-ens)
(first resolved-ens)))
url)]
(fx/merge cofx
(rf/merge cofx
(update-browser-history browser resolved-url)
(handle-pdf url)
(resolve-url {:error? error? :resolved-url (when resolved-ens url)}))))))
(fx/defn update-browser-name
(rf/defn update-browser-name
[cofx title]
(let [browser (get-current-browser (:db cofx))]
(when (and browser (not (:dapp? browser)) title (not (string/blank? title)))
(update-browser cofx (assoc browser :name title)))))
(fx/defn navigation-state-changed
(rf/defn navigation-state-changed
{:events [:browser/navigation-state-changed]}
[cofx event error?]
(let [{:strs [url loading title]} (js->clj event)
@ -269,12 +269,12 @@
(if (links/universal-link? url)
(when-not (and deep-link? platform/ios?) ;; ios webview handles this
{:dispatch [:universal-links/handle-url url]})
(fx/merge cofx
(rf/merge cofx
(update-browser-option :loading? loading)
(update-browser-name title)
(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
and history of the current browser is updated so that the user can navigate back to the
origin url"
@ -284,12 +284,12 @@
normalized-url (http/normalize-and-decode-url url)]
(if (links/universal-link? normalized-url)
{:dispatch [:universal-links/handle-url normalized-url]}
(fx/merge cofx
(rf/merge cofx
(update-browser-option :url-editing? false)
(update-browser-history browser normalized-url)
(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
there is already a browser for this host, this browser is reused
If the browser is reused, the history is flushed"
@ -301,7 +301,7 @@
:history [normalized-url]}]
(if (links/universal-link? normalized-url)
{:dispatch [:universal-links/handle-url normalized-url]}
(fx/merge cofx
(rf/merge cofx
{:db (assoc db
:browser/options
{:browser-id (:browser-id browser)})}
@ -310,12 +310,12 @@
(update-browser browser)
(resolve-url nil)))))
(fx/defn open-existing-browser
(rf/defn open-existing-browser
"Opens an existing browser with it's history"
{:events [:browser.ui/browser-item-selected]}
[{:keys [db] :as cofx} browser-id]
(let [browser (get-in db [:browser/browsers browser-id])]
(fx/merge cofx
(rf/merge cofx
{:db (assoc db
:browser/options
{:browser-id browser-id})}
@ -323,7 +323,7 @@
(navigation/set-stack-root :browser-stack :browser)
(resolve-url nil))))
(fx/defn web3-error-callback
(rf/defn web3-error-callback
{:events [:browser.dapp/transaction-on-error]}
[_ message-id message]
{:browser/send-to-bridge
@ -331,7 +331,7 @@
:messageId message-id
:error message}})
(fx/defn dapp-complete-transaction
(rf/defn dapp-complete-transaction
{:events [:browser.dapp/transaction-on-result]}
[_ message-id id result]
;;TODO check and test id
@ -360,7 +360,7 @@
(ethereum/address? second-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]}
[_ message]
{:browser/send-to-bridge message})
@ -372,7 +372,7 @@
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]
(let [message? (web3-sign-message? method)
dapps-address (get-in cofx [:db :multiaccount :dapps-address])
@ -432,7 +432,7 @@
:error %1
:result %2}])]}))))
(fx/defn handle-no-permissions
(rf/defn handle-no-permissions
[cofx {:keys [method id]} message-id]
(if (= method "eth_accounts")
;; eth_accounts returns empty array for compatibility with meta-mask
@ -458,28 +458,28 @@
(and (permissioned-method method)
(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]
(if (has-permissions? db dapp-name method)
(handle-no-permissions cofx 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]}
[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/process-next-permission dapp-name)
(navigation/navigate-back)))
(fx/defn handle-canceled-qr-code
(rf/defn handle-canceled-qr-code
{:events [:browser.bridge.callback/qr-code-canceled]}
[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/process-next-permission dapp-name)))
(fx/defn process-bridge-message
(rf/defn process-bridge-message
{:events [:browser/bridge-message-received]}
[{:keys [db] :as cofx} message]
(let [browser (get-current-browser
@ -514,12 +514,12 @@
:browser/send-to-bridge
(fn [message]
(let
[^js webview @webview-ref/webview-ref
msg
(str
"(function() { var __send = function() { if (ReactNativeWebView.onMessage) { ReactNativeWebView.onMessage('"
(types/clj->json message)
"');} else {setTimeout(__send, 0)}}; __send();})();")]
[^js webview @webview-ref/webview-ref
msg
(str
"(function() { var __send = function() { if (ReactNativeWebView.onMessage) { ReactNativeWebView.onMessage('"
(types/clj->json message)
"');} else {setTimeout(__send, 0)}}; __send();})();")]
(when (and message webview)
(.injectJavaScript webview msg)))))
@ -556,10 +556,10 @@
message (i18n/label :t/share-dapp-text {:link link})]
(list-selection/open-share {:message message})))
(fx/defn dapps-account-selected
(rf/defn dapps-account-selected
{:events [:dapps-account-selected]}
[{:keys [db] :as cofx} address]
(fx/merge cofx
(rf/merge cofx
{:browser/clear-web-data nil}
(bottom-sheet/hide-bottom-sheet)
(browser.permissions/clear-dapps-permissions)
@ -569,38 +569,38 @@
{: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]}
[cofx]
(debounce/clear :browser/navigation-state-changed)
(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]}
[cofx _]
(update-browser-option cofx :url-editing? true))
(fx/defn url-input-blured
(rf/defn url-input-blured
{:events [:browser.ui/url-input-blured]}
[cofx]
(update-browser-option cofx :url-editing? false))
(fx/defn lock-pressed
(rf/defn lock-pressed
{:events [:browser.ui/lock-pressed]}
[cofx 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]}
[cofx]
(update-browser-option cofx :show-tooltip nil))
(fx/defn loading-started
(rf/defn loading-started
{:events [:browser/loading-started]}
[cofx]
(update-browser-options cofx {:error? false :loading? true}))
(fx/defn handle-bookmarks
(rf/defn handle-bookmarks
[{:keys [db]} bookmarks]
(let [changed-bookmarks (reduce (fn [acc {:keys [url] :as bookmark}]
(assoc acc url bookmark))

View File

@ -6,11 +6,11 @@
[status-im.constants :as constants]
[status-im.network.core :as network]
[status-im.ui.screens.browser.eip3085.sheet :as sheet]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.random :as random]
[taoensso.timbre :as log]))
(fx/defn send-success-call-to-bridge
(rf/defn send-success-call-to-bridge
{:events [:eip3085/send-success-call-to-bridge]}
[_ id messageId]
{:browser/send-to-bridge {:type constants/web3-send-async-callback
@ -19,7 +19,7 @@
:id (int id)
:result nil}}})
(fx/defn allow-permission
(rf/defn allow-permission
{:events [:eip3085.ui/dapp-permission-allowed]}
[{:keys [db] :as cofx} message-id {:keys [new-networks id]}]
{:db (assoc db :networks/networks new-networks)
@ -30,7 +30,7 @@
:on-error #(log/error "failed to perform settings_saveSetting" %)}]
:dispatch [:bottom-sheet/hide]})
(fx/defn deny-permission
(rf/defn deny-permission
{:events [:eip3085.ui/dapp-permission-denied]}
[_ message-id _]
{:browser/send-to-bridge {:type constants/web3-send-async-callback
@ -39,7 +39,7 @@
:message "User rejected the request."}}
:dispatch [:bottom-sheet/hide]})
(fx/defn handle-add-ethereum-chain
(rf/defn handle-add-ethereum-chain
{:events [:eip3085/handle-add-ethereum-chain]}
[{{:networks/keys [networks] :as db} :db :as cofx}
dapp-name id message-id

View File

@ -4,9 +4,9 @@
(:require [status-im.constants :as constants]
[status-im.ethereum.core :as ethereum]
[status-im.ui.screens.browser.eip3326.sheet :as sheet]
[status-im.utils.fx :as fx]))
[utils.re-frame :as rf]))
(fx/defn deny-permission
(rf/defn deny-permission
{:events [:eip3326.ui/dapp-permission-denied]}
[{:keys [db] :as cofx} message-id _]
{:browser/send-to-bridge {:type constants/web3-send-async-callback
@ -15,7 +15,7 @@
:message "User rejected the request."}}
:dispatch [:bottom-sheet/hide]})
(fx/defn handle-switch-ethereum-chain
(rf/defn handle-switch-ethereum-chain
{:events [:eip3326/handle-switch-ethereum-chain]}
[{:keys [db] :as cofx} dapp-name id message-id {:keys [chainId] :as params}]
(let [target-chain-id (js/parseInt chainId 16)

View File

@ -2,7 +2,7 @@
(:require [status-im.constants :as constants]
[status-im.i18n.i18n :as i18n]
[status-im.qr-scanner.core :as qr-scanner]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im2.navigation.events :as navigation]))
(declare process-next-permission)
@ -20,25 +20,25 @@
:description (i18n/label :t/allowing-authorizes-this-dapp)
:icon :main-icons/wallet}})
(fx/defn permission-yield-control
(rf/defn permission-yield-control
[{:keys [db] :as cofx} dapp-name permission message-id params]
(cond
(= 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
:cancel-handler :browser.bridge.callback/qr-code-canceled
:data {:dapp-name dapp-name
:permission permission
: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?]
{:db (assoc-in db
[:browser/options :show-permission]
{:requested-permission permission
:message-id message-id
:dapp-name dapp-name
:yield-control? yield-control?})})
[:browser/options :show-permission]
{:requested-permission permission
:message-id message-id
:dapp-name dapp-name
:yield-control? yield-control?})})
(defn get-permission-data
[cofx allowed-permission]
@ -47,7 +47,7 @@
constants/dapp-permission-web3 [(:dapps-address multiaccount)]}
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
with the permission"
[{:keys [db] :as cofx} permission message-id allowed? data]
@ -58,7 +58,7 @@
allowed?
(assoc :data data))})
(fx/defn update-dapp-permissions
(rf/defn update-dapp-permissions
[{:keys [db]} dapp-name permission allowed?]
(let [dapp-permissions-set (set (get-in db [:dapps/permissions dapp-name :permissions]))
allowed-permissions-set (if allowed?
@ -71,23 +71,23 @@
:params [allowed-permissions]
:on-success #()}]}))
(fx/defn revoke-permissions
(rf/defn revoke-permissions
{:events [:browser/revoke-dapp-permissions]}
[{:keys [db] :as cofx} dapp]
(fx/merge cofx
(rf/merge cofx
{:db (update-in db [:dapps/permissions] dissoc dapp)
:json-rpc/call [{:method "permissions_deleteDappPermissions"
:params [dapp]
:on-success #()}]}))
(fx/defn revoke-dapp-permissions
(rf/defn revoke-dapp-permissions
{:events [:dapps/revoke-access]}
[cofx dapp]
(fx/merge cofx
(rf/merge cofx
(revoke-permissions dapp)
(navigation/navigate-back)))
(fx/defn clear-dapps-permissions
(rf/defn clear-dapps-permissions
[{:keys [db]}]
(let [dapp-permissions (keys (:dapps/permissions db))]
{:db (dissoc db :dapps/permissions)
@ -96,7 +96,7 @@
:params [dapp]
:on-success #()})}))
(fx/defn process-next-permission
(rf/defn process-next-permission
"Process next permission by removing it from pending permissions and prompting user
if there is no pending permissions left, save all granted permissions
and return the result to the bridge"
@ -112,41 +112,41 @@
(permission-yield-control new-cofx dapp-name permission message-id params)
(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]
(fx/merge cofx
(rf/merge cofx
(send-response-to-bridge requested-permission
message-id
true
(get-permission-data cofx requested-permission))
(process-next-permission dapp-name)))
(fx/defn allow-permission
(rf/defn allow-permission
"Add permission to set of allowed permission and process next permission"
{:events [:browser.permissions.ui/dapp-permission-allowed]}
[{:keys [db] :as cofx}]
(let [{:keys [requested-permission message-id dapp-name yield-control? params]}
(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)
(if yield-control?
(permission-yield-control dapp-name requested-permission message-id params)
(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"
{:events [:browser.permissions.ui/dapp-permission-denied]}
[{:keys [db] :as cofx}]
(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
message-id
false
(get-permission-data cofx requested-permission))
(process-next-permission dapp-name))))
(fx/defn process-permission
(rf/defn process-permission
"Process the permission requested by a dapp
If supported permission is already granted, return the result immediatly to the bridge
Otherwise process the first permission which will prompt user"

View File

@ -13,7 +13,7 @@
[status-im.multiaccounts.model :as multiaccounts.model]
[status-im.ui.screens.chat.state :as chat.state]
[status-im.utils.clocks :as utils.clocks]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.types :as types]
[status-im.utils.utils :as utils]
[status-im2.contexts.chat.messages.delete-message-for-me.events :as delete-for-me]
@ -112,14 +112,14 @@
(fn [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
:as cofx}]
(when (and (= view-id :chat)
(not (contains? chats current-chat-id)))
(navigation/navigate-back cofx)))
(fx/defn ensure-chats
(rf/defn ensure-chats
"Add chats to db and update"
[{:keys [db] :as cofx} chats]
(let [{:keys [all-chats chats-home-list removed-chats]}
@ -136,7 +136,7 @@
:chats-home-list #{}
:removed-chats #{}}
(map (map-chats cofx) chats))]
(fx/merge
(rf/merge
cofx
(merge {:db (-> db
(update :chats merge all-chats)
@ -149,7 +149,7 @@
(get-in db [:multiaccount :remote-push-notifications-enabled?])]}))
leave-removed-chat)))
(fx/defn clear-history
(rf/defn clear-history
"Clears history of the particular chat"
[{:keys [db] :as cofx} chat-id remove-chat?]
(let [{:keys [last-message public?
@ -175,11 +175,11 @@
:deleted-at-clock-value last-message-clock-value})
chats))))}))
(fx/defn clear-history-handler
(rf/defn clear-history-handler
"Clears history of the particular chat"
{:events [:chat.ui/clear-history]}
[{:keys [db] :as cofx} chat-id remove-chat?]
(fx/merge cofx
(rf/merge cofx
{:db db
:json-rpc/call [{:method "wakuext_clearHistory"
:params [{:id chat-id}]
@ -187,19 +187,19 @@
:on-error #(log/error "failed to clear history " chat-id %)}]}
(clear-history chat-id remove-chat?)))
(fx/defn chat-deactivated
(rf/defn chat-deactivated
{:events [::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"
[{:keys [db now] :as cofx} chat-id]
(fx/merge
(rf/merge
cofx
{:db (-> (if (get-in db [:chats chat-id :muted])
(assoc-in db [:chats chat-id :active] false)
(update db :chats dissoc chat-id))
(assoc-in db [:chats chat-id :active] false)
(update db :chats dissoc chat-id))
(update :chats-home-list disj chat-id)
(assoc :current-chat-id nil))
:json-rpc/call [{:method "wakuext_deactivateChat"
@ -208,7 +208,7 @@
:on-error #(log/error "failed to create public chat" chat-id %)}]}
(clear-history chat-id true)))
(fx/defn offload-messages
(rf/defn offload-messages
{:events [:offload-messages]}
[{:keys [db]} chat-id]
(merge {:db (-> db
@ -218,52 +218,52 @@
(when (and (= chat-id constants/timeline-chat-id) (= (:view-id db) :status))
{:dispatch [:init-timeline-chat]})))
(fx/defn close-chat
(rf/defn close-chat
{:events [:close-chat]}
[{:keys [db] :as cofx}]
(when-let [chat-id (:current-chat-id db)]
(chat.state/reset-visible-item)
(fx/merge cofx
(rf/merge cofx
{:db (dissoc db :current-chat-id)}
(delete-for-me/sync-all)
(delete-message/send-all)
(offload-messages chat-id))))
(fx/defn force-close-chat
(rf/defn force-close-chat
[{:keys [db] :as cofx} chat-id]
(do
(chat.state/reset-visible-item)
(fx/merge cofx
(rf/merge cofx
{:db (dissoc db :current-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"
{:events [:chat.ui/remove-chat]}
[{:keys [db now] :as cofx} chat-id]
(fx/merge cofx
(rf/merge cofx
{:clear-message-notifications
[[chat-id] (get-in db [:multiaccount :remote-push-notifications-enabled?])]}
(deactivate-chat chat-id)
(offload-messages chat-id)))
(fx/defn show-more-chats
(rf/defn show-more-chats
{:events [:chat.ui/show-more-chats]}
[{:keys [db]}]
(when (< (:home-items-show-number db) (count (:chats db)))
{: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"
{:events [:chat.ui/preload-chat-data]}
[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"
{:events [:chat.ui/navigate-to-chat]}
[{db :db :as cofx} chat-id]
(fx/merge cofx
(rf/merge cofx
{:dispatch [:navigate-to :chat]}
(navigation/change-tab :chat)
(when-not (= (:view-id db) :community)
@ -276,11 +276,11 @@
#(when (group-chat? cofx 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"
{:events [:chat.ui/navigate-to-chat-nav2]}
[{db :db :as cofx} chat-id from-shell?]
(fx/merge cofx
(rf/merge cofx
{:dispatch [:navigate-to-nav2 :chat chat-id from-shell?]}
(when-not (= (:view-id db) :community)
(navigation/pop-to-root-tab :shell-stack))
@ -292,13 +292,13 @@
#(when (group-chat? cofx chat-id)
(loading/load-chat % chat-id))))
(fx/defn handle-clear-history-response
(rf/defn handle-clear-history-response
{:events [::history-cleared]}
[{:keys [db]} chat-id response]
(let [chat (chats-store/<-rpc (first (:chats response)))]
{: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]}
[{:keys [db]} chat-id response]
(let [chat (chats-store/<-rpc (first (:chats response)))
@ -313,13 +313,13 @@
(update :chats-home-list conj 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"
{:events [:chat.ui/navigate-to-pinned-messages]}
[cofx 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"
{:events [:chat.ui/start-chat]}
[{:keys [db] :as cofx} chat-id ens-name]
@ -338,7 +338,7 @@
[db]
(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]}
[{:keys [db]} chat-id response]
{:db (-> db
@ -346,14 +346,14 @@
(update :chats-home-list conj chat-id))
:dispatch [:chat.ui/navigate-to-chat chat-id]})
(fx/defn create-public-chat-go
(rf/defn create-public-chat-go
[_ chat-id]
{:json-rpc/call [{:method "wakuext_createPublicChat"
:params [{:id chat-id}]
:on-success #(re-frame/dispatch [::public-chat-created 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"
{:events [:chat.ui/start-public-chat]}
[cofx topic]
@ -366,10 +366,10 @@
{:utils/show-popup {:title (i18n/label :t/cant-open-public-chat)
:content (i18n/label :t/invalid-public-chat-topic)}}))
(fx/defn profile-chat-created
(rf/defn profile-chat-created
{:events [::profile-chat-created]}
[{:keys [db] :as cofx} chat-id response navigate-to?]
(fx/merge
(rf/merge
cofx
{:db db}
#(when response
@ -379,7 +379,7 @@
{:dispatch-n [[:chat.ui/preload-chat-data chat-id]
[:open-modal :profile]]})))
(fx/defn start-profile-chat
(rf/defn start-profile-chat
"Starts a new profile chat"
{:events [:start-profile-chat]}
[cofx profile-public-key navigate-to?]
@ -391,7 +391,7 @@
:on-success #(re-frame/dispatch [::profile-chat-created chat-id % navigate-to?])
: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)"
{:events [:chat/disable-cooldown]}
[{:keys [db]}]
@ -405,18 +405,18 @@
(i18n/label :cooldown/warning-message)
#())))
(fx/defn mute-chat-failed
(rf/defn mute-chat-failed
{:events [::mute-chat-failed]}
[{:keys [db] :as cofx} chat-id muted? error]
(log/error "mute chat failed" chat-id error)
{: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]}
[_ chat-id]
(log/debug "muted chat successfully" chat-id))
(fx/defn mute-chat
(rf/defn mute-chat
{:events [::mute-chat-toggled]}
[{:keys [db] :as cofx} chat-id muted?]
(let [method (if muted? "wakuext_muteChat" "wakuext_unmuteChat")]
@ -426,19 +426,19 @@
:on-error #(re-frame/dispatch [::mute-chat-failed chat-id muted? %])
:on-success #(re-frame/dispatch [::mute-chat-toggled-successfully chat-id])}]}))
(fx/defn show-profile
(rf/defn show-profile
{:events [:chat.ui/show-profile]}
[{:keys [db] :as cofx} identity ens-name]
(let [my-public-key (get-in db [:multiaccount :public-key])]
(when (not= my-public-key identity)
(fx/merge
(rf/merge
cofx
{:db (-> db
(assoc :contacts/identity identity)
(assoc :contacts/ens-name ens-name))}
(start-profile-chat identity true)))))
(fx/defn clear-history-pressed
(rf/defn clear-history-pressed
{:events [:chat.ui/clear-history-pressed]}
[_ chat-id]
{:ui/show-confirmation
@ -449,19 +449,19 @@
(re-frame/dispatch [:bottom-sheet/hide])
(re-frame/dispatch [:chat.ui/clear-history chat-id false]))}})
(fx/defn gaps-failed
(rf/defn gaps-failed
{:events [::gaps-failed]}
[{:keys [db]} chat-id gap-ids error]
(log/error "failed to fetch gaps" chat-id gap-ids error)
{: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]}
[{:keys [db]} chat-id error]
(log/error "failed to sync chat" chat-id error)
{: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]}
[{:keys [db] :as cofx} chat-id synced-from]
(log/debug "synced success" chat-id synced-from)
@ -470,24 +470,24 @@
(assoc-in [:chats chat-id :synced-from] synced-from)
(dissoc :mailserver/fetching-gaps-in-progress))})
(fx/defn gaps-filled
(rf/defn gaps-filled
{:events [::gaps-filled]}
[{:keys [db] :as cofx} chat-id message-ids]
(fx/merge
(rf/merge
cofx
{:db (-> db
(update-in [:messages chat-id] (fn [messages] (apply dissoc messages message-ids)))
(dissoc :mailserver/fetching-gaps-in-progress))}
(message-list/rebuild-message-list chat-id)))
(fx/defn fill-gaps
(rf/defn fill-gaps
[cofx chat-id gap-ids]
{:json-rpc/call [{:method "wakuext_fillGaps"
:params [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 %])}]})
(fx/defn sync-chat-from-sync-from
(rf/defn sync-chat-from-sync-from
[cofx chat-id]
(log/debug "syncing chat from sync from")
{:json-rpc/call [{:method "wakuext_syncChatFromSyncedFrom"
@ -495,19 +495,19 @@
: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 %])}]})
(fx/defn chat-ui-fill-gaps
(rf/defn chat-ui-fill-gaps
{:events [:chat.ui/fill-gaps]}
[{:keys [db] :as cofx} chat-id gap-ids]
(let [use-status-nodes? (mailserver/fetch-use-mailservers? {:db db})]
(log/info "filling gaps if use-status-nodes = true" chat-id gap-ids)
(when use-status-nodes?
(fx/merge cofx
(rf/merge cofx
{:db (assoc db :mailserver/fetching-gaps-in-progress gap-ids)}
(if (= gap-ids #{:first-gap})
(sync-chat-from-sync-from chat-id)
(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]}
[_ chat-id]
{:ui/show-confirmation
@ -518,7 +518,7 @@
(re-frame/dispatch [:bottom-sheet/hide])
(re-frame/dispatch [:chat.ui/remove-chat chat-id]))}})
(fx/defn decrease-unviewed-count
(rf/defn decrease-unviewed-count
{:events [:chat/decrease-unviewed-count]}
[{:keys [db]} chat-id {:keys [count countWithMentions]}]
{:db (-> db

View File

@ -9,7 +9,7 @@
[status-im.ui.components.react :as react]
[status-im.utils.config :as config]
[status-im.utils.fs :as fs]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.image-processing :as image-processing]
[status-im.utils.platform :as platform]
[status-im.utils.types :as types]
@ -110,17 +110,17 @@
{:permissions [:read-external-storage]
:on-allowed (fn []
(-> (if end-cursor
(.getPhotos
CameraRoll
#js {:first num :after end-cursor :assetType "Photos" :groupTypes "All"})
(.getPhotos CameraRoll
#js {:first num :assetType "Photos" :groupTypes "All"}))
(.getPhotos
CameraRoll
#js {:first num :after end-cursor :assetType "Photos" :groupTypes "All"})
(.getPhotos CameraRoll
#js {:first num :assetType "Photos" :groupTypes "All"}))
(.then #(let [response (types/js->clj %)]
(re-frame/dispatch [:on-camera-roll-get-photos (:edges response)
(:page_info response) end-cursor])))
(.catch #(log/warn "could not get camera roll photos"))))})))
(fx/defn image-captured
(rf/defn image-captured
{:events [:chat.ui/image-captured]}
[{:keys [db]} chat-id uri]
(let [current-chat-id (or chat-id (:current-chat-id db))
@ -129,24 +129,24 @@
(not (get images uri)))
{::image-selected [uri current-chat-id]})))
(fx/defn on-end-reached
(rf/defn on-end-reached
{:events [:camera-roll/on-end-reached]}
[_ end-cursor loading? has-next-page?]
(when (and (not loading?) has-next-page?)
(re-frame/dispatch [:chat.ui/camera-roll-loading-more true])
(re-frame/dispatch [:chat.ui/camera-roll-get-photos 20 end-cursor])))
(fx/defn camera-roll-get-photos
(rf/defn camera-roll-get-photos
{:events [:chat.ui/camera-roll-get-photos]}
[_ num end-cursor]
{::camera-roll-get-photos [num end-cursor]})
(fx/defn camera-roll-loading-more
(rf/defn camera-roll-loading-more
{:events [:chat.ui/camera-roll-loading-more]}
[{:keys [db]} is-loading]
{:db (assoc db :camera-roll/loading-more is-loading)})
(fx/defn on-camera-roll-get-photos
(rf/defn on-camera-roll-get-photos
{:events [:on-camera-roll-get-photos]}
[{:keys [db] :as cofx} photos page-info end-cursor]
(let [photos_x (when end-cursor (:camera-roll/photos db))]
@ -156,34 +156,34 @@
(assoc :camera-roll/has-next-page (:has_next_page page-info))
(assoc :camera-roll/loading-more false))}))
(fx/defn clear-sending-images
(rf/defn clear-sending-images
{:events [:chat.ui/clear-sending-images]}
[{:keys [db]} current-chat-id]
{: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]}
[{:keys [db] :as cofx} chat-id]
(let [current-chat-id (or chat-id (:current-chat-id db))]
(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]}
[{:keys [db] :as cofx}]
(cancel-sending-image cofx (chat/my-profile-chat-topic db)))
(fx/defn image-selected
(rf/defn image-selected
{:events [:chat.ui/image-selected]}
[{:keys [db]} current-chat-id original 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]}
[{:keys [db]} original]
(let [current-chat-id (:current-chat-id db)]
{: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]}
[{:keys [db]} chat-id]
(let [current-chat-id (or chat-id (:current-chat-id db))
@ -191,12 +191,12 @@
(when (< (count images) config/max-images-batch)
{::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]}
[{:keys [db] :as cofx}]
(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]}
[{:keys [db]} chat-id]
(let [current-chat-id (or chat-id (:current-chat-id db))
@ -204,12 +204,12 @@
(when (< (count images) config/max-images-batch)
{::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]}
[{:keys [db] :as cofx}]
(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]}
[{:keys [db]} uri chat-id]
(let [current-chat-id (or chat-id (:current-chat-id db))
@ -221,12 +221,12 @@
(not (get images uri)))
{::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]}
[{:keys [db] :as cofx} uri]
(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]}
[_ base64-uri]
{::save-image-to-gallery base64-uri})

View File

@ -11,7 +11,7 @@
[status-im.constants :as constants]
[status-im.i18n.i18n :as i18n]
[status-im.utils.datetime :as datetime]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.utils :as utils]
[taoensso.timbre :as log]))
@ -25,7 +25,7 @@
(.-char ^js emoji-map)
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
as arguments and returns new fx. Always clear all validation messages."
{:events [:chat.ui/set-chat-input-text]}
@ -33,21 +33,21 @@
(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))}))
(fx/defn set-timeline-input-text
(rf/defn set-timeline-input-text
{:events [:chat.ui/set-timeline-input-text]}
[{db :db} new-input]
{:db (assoc-in db
[:chat/inputs (chat/my-profile-chat-topic db) :input-text]
(text->emoji new-input))})
[:chat/inputs (chat/my-profile-chat-topic db) :input-text]
(text->emoji new-input))})
(fx/defn select-mention
(rf/defn select-mention
{:events [:chat.ui/select-mention]}
[{:keys [db] :as cofx} text-input-ref {:keys [alias name searched-text match] :as user}]
(let [chat-id (:current-chat-id db)
new-text (mentions/new-input-text-with-mention cofx user)
at-sign-idx (get-in db [:chats/mentions chat-id :mentions :at-sign-idx])
cursor (+ at-sign-idx (count name) 2)]
(fx/merge
(rf/merge
cofx
{:db (-> db
(assoc-in [:chats/cursor chat-id] cursor)
@ -83,15 +83,15 @@
:show-cooldown-warning nil
:db (assoc db
:chat/cooldowns (if
(=
chat.constants/cooldown-reset-threshold
cooldowns)
(=
chat.constants/cooldown-reset-threshold
cooldowns)
0
cooldowns)
:chat/spam-messages-frequency 0
:chat/cooldown-enabled? true)})
(fx/defn process-cooldown
(rf/defn process-cooldown
"Process cooldown to protect against message spammers"
[{{:keys [chat/last-outgoing-message-sent-at
chat/cooldowns
@ -114,12 +114,12 @@
(and spamming-fast? spamming-frequently?)
(start-cooldown (inc cooldowns))))))
(fx/defn reply-to-message
(rf/defn reply-to-message
"Sets reference to previous chat message and focuses on input"
{:events [:chat.ui/reply-to-message]}
[{:keys [db] :as cofx} message]
(let [current-chat-id (:current-chat-id db)]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:chat/inputs current-chat-id :metadata :responding-to-message]
message)
@ -128,7 +128,7 @@
dissoc
:sending-image))})))
(fx/defn edit-message
(rf/defn edit-message
"Sets reference to previous chat message and focuses on input"
{:events [:chat.ui/edit-message]}
[{:keys [db] :as cofx} message]
@ -144,7 +144,7 @@
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"
{:events [:chat.ui/send-contact-request]}
[{:keys [db] :as cofx}]
@ -159,7 +159,7 @@
dissoc
:sending-image))}))
(fx/defn cancel-message-reply
(rf/defn cancel-message-reply
"Cancels stage message reply"
{:events [:chat.ui/cancel-message-reply]}
[{:keys [db]}]
@ -192,9 +192,9 @@
:text (i18n/label :t/update-to-see-image {"locale" "en"})})
images)))
(fx/defn clean-input
(rf/defn clean-input
[{:keys [db] :as cofx} current-chat-id]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:chat/inputs current-chat-id :metadata :sending-contact-request] nil)
(assoc-in [:chat/inputs current-chat-id :metadata :sending-image] nil)
@ -202,29 +202,29 @@
(assoc-in [:chat/inputs current-chat-id :metadata :responding-to-message] nil))}
(set-chat-input-text nil current-chat-id)))
(fx/defn cancel-message-edit
(rf/defn cancel-message-edit
"Cancels stage message edit"
{:events [:chat.ui/cancel-message-edit]}
[{:keys [db] :as cofx}]
(let [current-chat-id (:current-chat-id db)]
(fx/merge cofx
(rf/merge cofx
{:set-text-input-value [current-chat-id ""]}
(clean-input current-chat-id)
(mentions/clear-mentions)
(mentions/clear-cursor))))
(fx/defn send-messages
(rf/defn send-messages
[{:keys [db] :as cofx} input-text current-chat-id]
(let [image-messages (build-image-messages cofx current-chat-id)
text-message (build-text-message cofx input-text current-chat-id)
messages (keep identity (conj image-messages text-message))]
(when (seq messages)
(fx/merge cofx
(rf/merge cofx
(clean-input (:current-chat-id db))
(process-cooldown)
(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"
{:events [:profile.ui/send-my-status-message]}
[{db :db :as cofx}]
@ -234,11 +234,11 @@
text-message (build-text-message cofx input-text current-chat-id)
messages (keep identity (conj image-messages text-message))]
(when (seq messages)
(fx/merge cofx
(rf/merge cofx
(clean-input current-chat-id)
(chat.message/send-messages messages)))))
(fx/defn send-audio-message
(rf/defn send-audio-message
[cofx audio-path duration current-chat-id]
(when-not (string/blank? audio-path)
(chat.message/send-message
@ -249,7 +249,7 @@
:audio-duration-ms duration
: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]
(when-not (or (string/blank? hash) (and (string/blank? packID) (string/blank? pack)))
(chat.message/send-message cofx
@ -259,9 +259,9 @@
:pack (int (if (string/blank? packID) pack packID))}
:text (i18n/label :t/update-to-see-sticker {"locale" "en"})})))
(fx/defn send-edited-message
(rf/defn send-edited-message
[{:keys [db] :as cofx} text {:keys [message-id quoted-message]}]
(fx/merge
(rf/merge
cofx
{:json-rpc/call [{:method "wakuext_editMessage"
:params [{:id message-id
@ -276,24 +276,24 @@
(cancel-message-edit)
(process-cooldown)))
(fx/defn send-current-message
(rf/defn send-current-message
"Sends message from current chat input"
{:events [:chat.ui/send-current-message]}
[{{:keys [current-chat-id] :as db} :db :as cofx}]
(let [{:keys [input-text metadata]} (get-in db [:chat/inputs current-chat-id])
editing-message (:editing-message metadata)
input-text-with-mentions (mentions/check-mentions cofx input-text)]
(fx/merge cofx
(rf/merge cofx
(if editing-message
(send-edited-message input-text-with-mentions editing-message)
(send-messages input-text-with-mentions current-chat-id))
(mentions/clear-mentions)
(mentions/clear-cursor))))
(fx/defn send-contact-request
(rf/defn send-contact-request
{:events [:contacts/send-contact-request]}
[{:keys [db] :as cofx} public-key message]
(fx/merge cofx
(rf/merge cofx
{:chat.ui/clear-inputs nil
:chat.ui/clear-inputs-old nil
:json-rpc/call [{:method "wakuext_sendContactRequest"
@ -306,22 +306,22 @@
(clean-input (:current-chat-id db))
(process-cooldown)))
(fx/defn cancel-contact-request
(rf/defn cancel-contact-request
"Cancels contact request"
{:events [:chat.ui/cancel-contact-request]}
[{:keys [db] :as cofx}]
(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)}
(mentions/clear-mentions)
(mentions/clear-cursor)
(clean-input (:current-chat-id db))
(process-cooldown))))
(fx/defn chat-send-sticker
(rf/defn chat-send-sticker
{:events [:chat/send-sticker]}
[{{:keys [current-chat-id] :as db} :db :as cofx} {:keys [hash packID pack] :as sticker}]
(fx/merge
(rf/merge
cofx
{:db (update db
:stickers/recent-stickers
@ -332,7 +332,7 @@
:on-success #()}]}
(send-sticker-message sticker current-chat-id)))
(fx/defn chat-send-audio
(rf/defn chat-send-audio
{:events [:chat/send-audio]}
[{{:keys [current-chat-id]} :db :as cofx} audio-path duration]
(send-audio-message cofx audio-path duration current-chat-id))

View File

@ -2,13 +2,13 @@
(:require [re-frame.core :as re-frame]
[status-im.communities.core :as models.communities]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[taoensso.timbre :as log]))
(fx/defn enable
(rf/defn enable
{:events [::enable]}
[{{:keys [multiaccount]} :db :as cofx} site enabled?]
(fx/merge cofx
(rf/merge cofx
(multiaccounts.update/multiaccount-update
:link-previews-enabled-sites
(if enabled?
@ -16,10 +16,10 @@
(disj (get multiaccount :link-previews-enabled-sites #{}) site))
{})))
(fx/defn enable-all
(rf/defn enable-all
{:events [::enable-all]}
[{{:keys [multiaccount]} :db :as cofx} link-previews-whitelist enabled?]
(fx/merge cofx
(rf/merge cofx
(multiaccounts.update/multiaccount-update
:link-previews-enabled-sites
(if enabled?
@ -39,7 +39,7 @@
[db community-id]
(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]}
[{:keys [db]} community-id]
{:db (community-failed-to-resolve db community-id)})
@ -48,10 +48,10 @@
[id]
(str "https://join.status.im/c/" id))
(fx/defn handle-community-resolved
(rf/defn handle-community-resolved
{:events [::community-resolved]}
[{:keys [db] :as cofx} community-id community]
(fx/merge cofx
(rf/merge cofx
(cond-> {:db (community-resolved db community-id)}
(some? community)
(assoc :dispatch
@ -59,7 +59,7 @@
(community-link community-id) community]))
(models.communities/handle-community community)))
(fx/defn resolve-community-info
(rf/defn resolve-community-info
{:events [::resolve-community-info]}
[{:keys [db]} community-id]
{:db (community-resolving db community-id)
@ -70,7 +70,7 @@
(re-frame/dispatch [::community-failed-to-resolve community-id])
(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]}
[cofx link]
{:json-rpc/call [{:method "wakuext_getLinkPreviewData"
@ -81,7 +81,7 @@
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]}
[{{:keys [multiaccount]} :db :as cofx} site data]
(multiaccounts.update/optimistic
@ -95,7 +95,7 @@
(community-link id)
community]))
(fx/defn should-suggest-link-preview
(rf/defn should-suggest-link-preview
{:events [::should-suggest-link-preview]}
[{:keys [db] :as cofx} enabled?]
(multiaccounts.update/multiaccount-update
@ -104,14 +104,14 @@
(boolean enabled?)
{}))
(fx/defn request-link-preview-whitelist
(rf/defn request-link-preview-whitelist
[_]
{:json-rpc/call [{:method "wakuext_getLinkPreviewWhitelist"
:params []
:on-success #(re-frame/dispatch [::link-preview-whitelist-received %])
: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]}
[{:keys [db]} whitelist]
{:db (assoc db

View File

@ -4,7 +4,7 @@
[status-im.constants :as constants]
[status-im.data-store.chats :as data-store.chats]
[status-im.data-store.messages :as data-store.messages]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im2.contexts.activity-center.events :as activity-center]
[taoensso.timbre :as log]))
@ -18,7 +18,7 @@
clock-value
"0x0000000000000000000000000000000000000000000000000000000000000000"))
(fx/defn update-chats-in-app-db
(rf/defn update-chats-in-app-db
{:events [:chats-list/load-success]}
[{:keys [db]} ^js new-chats-js]
(let [{:keys [all-chats chats-home-list]}
@ -38,20 +38,20 @@
:chats-home-list chats-home-list
:chats/loading? false)}))
(fx/defn load-chat-success
(rf/defn load-chat-success
{:events [:chats-list/load-chat-success]}
[{:keys [db]} ^js chat]
(let [{:keys [chat-id] :as chat} (data-store.chats/<-rpc chat)]
{:db (update-in db [:chats chat-id] merge chat)}))
(fx/defn load-chat
(rf/defn load-chat
[_ chat-id]
{:json-rpc/call [{:method "wakuext_chat"
:params [chat-id]
:on-success #(re-frame/dispatch [:chats-list/load-chat-success %])
: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]}
[{:keys [db]} current-chat-id _ err]
(log/error "failed loading messages" current-chat-id err)
@ -67,19 +67,19 @@
:unviewed-mentions-count 0
:highlight false))
(fx/defn handle-mark-all-read-successful
(rf/defn handle-mark-all-read-successful
{:events [::mark-all-read-successful]}
[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]}
[{:keys [db] :as cofx} chat-ids]
(fx/merge cofx
(rf/merge cofx
{:db (reduce mark-chat-all-read db chat-ids)}
(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]}
[{db :db} chat-id]
{:db (mark-chat-all-read db chat-id)
@ -89,7 +89,7 @@
:params [chat-id]
: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]}
[{db :db} community-id]
(let [community-chat-ids (map #(str community-id %)
@ -101,7 +101,7 @@
: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"
{:events [::messages-loaded]}
[{db :db} chat-id session-id {:keys [cursor messages]}]
@ -153,7 +153,7 @@
(empty? cursor))
(update :contacts/contacts merge contacts))})))
(fx/defn load-more-messages
(rf/defn load-more-messages
{:events [:chat.ui/load-more-messages]}
[{:keys [db]} chat-id first-request]
(when-let [session-id (get-in db [:pagination-info chat-id :messages-initialized?])]
@ -172,15 +172,15 @@
#(re-frame/dispatch [::messages-loaded 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]}
[{:keys [db] :as cofx}]
(load-more-messages cofx (:current-chat-id db) false))
(fx/defn load-messages
(rf/defn load-messages
[{:keys [db now] :as cofx} chat-id]
(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)
:utils/dispatch-later [{:ms 50 :dispatch [:chat.ui/mark-all-read-pressed chat-id]}
(when-not (get-in cofx [:db :chats chat-id :public?])

View File

@ -7,7 +7,7 @@
[status-im.contact.db :as contact.db]
[status-im.multiaccounts.core :as multiaccounts]
[status-im.native-module.core :as status]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.platform :as platform]
[status-im.utils.utils :as utils]
[taoensso.timbre :as log]))
@ -526,7 +526,7 @@
(assoc-in [last-idx :to] (dec (count text)))
(assoc-in [last-idx :checked?] false)))))))
(fx/defn on-text-input
(rf/defn on-text-input
{:events [::on-text-input]}
[{:keys [db]} {:keys [previous-text start end] :as args}]
(log/debug "[mentions] on-text-input args" args)
@ -573,7 +573,7 @@
[[:text (subs text 0 first-from)]]))
idxs))))
(fx/defn recheck-at-idxs
(rf/defn recheck-at-idxs
[{:keys [db]} mentionable-users]
(let [chat-id (:current-chat-id db)
text (get-in db [:chat/inputs chat-id :input-text])
@ -592,7 +592,7 @@
new-at-idxs)
(assoc-in [:chat/inputs-with-mentions chat-id] calculated-input))}))
(fx/defn calculate-suggestions
(rf/defn calculate-suggestions
{:events [::calculate-suggestions]}
[{:keys [db]} mentionable-users]
(let [chat-id (:current-chat-id db)
@ -601,8 +601,8 @@
(get-in db [:chats/mentions chat-id :mentions])
new-text (or new-text text)]
(log/debug "[mentions] calculate suggestions"
"state"
state)
"state"
state)
(if-not (seq at-idxs)
{:db (-> db
(assoc-in [:chats/mention-suggestions chat-id] nil)
@ -659,31 +659,31 @@
" "))
(subs text mention-end)])))
(fx/defn clear-suggestions
(rf/defn clear-suggestions
[{:keys [db]}]
(log/debug "[mentions] clear suggestions")
(let [chat-id (:current-chat-id db)]
{:db (update db :chats/mention-suggestions dissoc chat-id)}))
(fx/defn clear-mentions
(rf/defn clear-mentions
[{:keys [db] :as cofx}]
(log/debug "[mentions] clear mentions")
(let [chat-id (:current-chat-id db)]
(fx/merge
(rf/merge
cofx
{:db (-> db
(update-in [:chats/mentions chat-id] dissoc :mentions)
(update :chat/inputs-with-mentions dissoc chat-id))}
(clear-suggestions))))
(fx/defn clear-cursor
(rf/defn clear-cursor
{:events [::clear-cursor]}
[{:keys [db]}]
(log/debug "[mentions] clear cursor")
{:db
(update db :chats/cursor dissoc (:current-chat-id db))})
(fx/defn check-selection
(rf/defn check-selection
{:events [::on-selection-change]}
[{:keys [db] :as cofx}
{:keys [start end] :as selection}
@ -698,7 +698,7 @@
(<= (dec end) to))
idx))
at-idxs)
(fx/merge
(rf/merge
cofx
{:db (update-in db
[:chats/mentions chat-id :mentions]
@ -717,7 +717,7 @@
(rn/find-node-handle (react/current-ref ref))
cursor))))
(fx/defn reset-text-input-cursor
(rf/defn reset-text-input-cursor
[_ ref cursor]
{::reset-text-input-cursor [ref cursor]})

View File

@ -9,7 +9,7 @@
[status-im.data-store.messages :as data-store.messages]
[status-im.transport.message.protocol :as protocol]
[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.platform :as platform]
[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
(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]}
[{:keys [db]} messages]
(reduce (fn [acc {:keys [chat-id alias name identicon from]}]
@ -167,42 +167,42 @@
(update-in [:message-lists constants/timeline-chat-id] message-list/add message)))
db)))
(fx/defn process-statuses
(rf/defn process-statuses
{:events [:process-statuses]}
[{:keys [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]
(when (get-in db [:messages chat-id message-id])
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db
[:messages chat-id message-id :outgoing-status]
status)})))
[:messages chat-id message-id :outgoing-status]
status)})))
(fx/defn update-message-status
(rf/defn update-message-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)))
(fx/defn resend-message
(rf/defn resend-message
[{:keys [db] :as cofx} chat-id message-id]
(fx/merge cofx
(rf/merge cofx
{:json-rpc/call [{:method "wakuext_reSendChatMessage"
:params [message-id]
:on-success #(log/debug "re-sent message successfully")
:on-error #(log/error "failed to re-send message" %)}]}
(update-message-status chat-id message-id :sending)))
(fx/defn send-message
(rf/defn send-message
[cofx message]
(protocol/send-chat-messages cofx [message]))
(fx/defn send-messages
(rf/defn send-messages
[cofx messages]
(protocol/send-chat-messages cofx messages))
(fx/defn handle-removed-messages
(rf/defn handle-removed-messages
{:events [::handle-removed-messages]}
[{:keys [db] :as cofx} removed-messages]
(let [mark-as-deleted-fx (->> removed-messages
@ -222,7 +222,7 @@
removed-messages)
remove-messages-fx (fn [{:keys [db]}]
{:dispatch [:activity-center.notifications/fetch-unread-count]})]
(apply fx/merge
(apply rf/merge
cofx
(-> mark-as-deleted-fx
(concat mark-as-seen-fx)
@ -243,7 +243,7 @@
(<= message-clock cleared-at))
messages)))
(fx/defn handle-cleared-histories-messages
(rf/defn handle-cleared-histories-messages
{:events [::handle-cleared-hisotories-messages]}
[{:keys [db]} cleared-histories]
{:db (reduce (fn [acc current]

View File

@ -2,7 +2,7 @@
(:require ["functional-red-black-tree" :as rb-tree]
[status-im.constants :as constants]
[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}]
@ -197,8 +197,8 @@
;; NOTE(performance): 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]
{:db (assoc-in db
[:message-lists chat-id]
(add-many nil (vals (get-in db [:messages chat-id]))))})
[:message-lists chat-id]
(add-many nil (vals (get-in db [:messages chat-id]))))})

View File

@ -3,7 +3,7 @@
[status-im.constants :as constants]
[status-im.data-store.reactions :as data-store.reactions]
[status-im.transport.message.protocol :as message.protocol]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[taoensso.timbre :as log]))
(defn update-reaction
@ -40,12 +40,12 @@
(get-in db [:chats chat-id])]
(>= deleted-at-clock-value clock-value)))
(fx/defn receive-signal
(rf/defn receive-signal
[{:keys [db] :as cofx} reactions]
(let [reactions (filter (partial earlier-than-deleted-at? cofx) reactions)]
{:db (update db :reactions (process-reactions (:chats db)) reactions)}))
(fx/defn load-more-reactions
(rf/defn load-more-reactions
{:events [:load-more-reactions]}
[{:keys [db]} cursor chat-id]
(when-let [session-id (get-in db [:pagination-info chat-id :messages-initialized?])]
@ -56,7 +56,7 @@
#(re-frame/dispatch [::reactions-loaded chat-id session-id %])
#(log/error "failed loading reactions" chat-id %))))
(fx/defn reactions-loaded
(rf/defn reactions-loaded
{:events [::reactions-loaded]}
[{db :db}
chat-id
@ -72,19 +72,19 @@
;; Send reactions
(fx/defn send-emoji-reaction
(rf/defn send-emoji-reaction
{:events [:models.reactions/send-emoji-reaction]}
[{{:keys [current-chat-id]} :db :as cofx} reaction]
(message.protocol/send-reaction cofx
(update reaction :chat-id #(or % current-chat-id))))
(fx/defn send-retract-emoji-reaction
(rf/defn send-retract-emoji-reaction
{:events [:models.reactions/send-emoji-reaction-retraction]}
[{{:keys [current-chat-id]} :db :as cofx} reaction]
(message.protocol/send-retract-reaction cofx
(update reaction :chat-id #(or % current-chat-id))))
(fx/defn receive-one
(rf/defn receive-one
{:events [::receive-one]}
[{:keys [db]} reaction]
{:db (update db :reactions (process-reactions (:chats db)) [reaction])})

View File

@ -2,13 +2,13 @@
(ns status-im.chat.models.transport
(:require [status-im.chat.models.message :as chat.message]
[status-im.transport.message.core :as transport.message]
[status-im.utils.fx :as fx]))
[utils.re-frame :as rf]))
(fx/defn chat-ui-resend-message
(rf/defn chat-ui-resend-message
{:events [:chat.ui/resend-message]}
[{:keys [db] :as cofx} chat-id message-id]
(let [message (get-in db [:messages chat-id message-id])]
(fx/merge
(rf/merge
cofx
(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))))

View File

@ -1,9 +1,9 @@
(ns status-im.commands.core
(:require [re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[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]}
[{:keys [db]} message]
{:db (assoc db
@ -12,13 +12,13 @@
:from (ethereum/get-default-account (:multiaccount/accounts db))})
:show-select-acc-sheet nil})
(fx/defn set-selected-account
(rf/defn set-selected-account
{:events [::set-selected-account]}
[{:keys [db]} _ account]
{:db (-> (assoc-in db [:commands/select-account :from] account)
(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]}
[{:keys [db]} message-id address]
{:db (dissoc db :commands/select-account)
@ -27,7 +27,7 @@
:js-response true
: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]}
[_ message-id]
{:json-rpc/call [{:method "wakuext_declineRequestAddressForTransaction"
@ -35,7 +35,7 @@
:js-response true
:on-success #(re-frame/dispatch [:transport/message-sent %])}]})
(fx/defn handle-decline-request-transaction
(rf/defn handle-decline-request-transaction
{:events [::decline-request-transaction]}
[cofx message-id]
{:json-rpc/call [{:method "wakuext_declineRequestTransaction"

View File

@ -8,8 +8,7 @@
[status-im.bottom-sheet.core :as bottom-sheet]
[status-im.constants :as constants]
[status-im.ui.components.emoji-thumbnail.styles :as emoji-thumbnail-styles]
[status-im.utils.fx :as fx]
[status-im.utils.handlers :refer [>evt]]
[utils.re-frame :as rf]
[status-im.utils.universal-links.core :as universal-links]
[status-im2.contexts.activity-center.events :as activity-center]
[status-im2.navigation.events :as navigation]
@ -79,24 +78,24 @@
[{:keys [db]}]
(:communities/community-id-input db))
(fx/defn handle-request-to-join
(rf/defn handle-request-to-join
[{:keys [db]} 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)}))
(fx/defn handle-removed-chats
(rf/defn handle-removed-chats
[{:keys [db]} chat-ids]
{:db (reduce (fn [db chat-id]
(update db :chats dissoc chat-id))
db
chat-ids)})
(fx/defn handle-community
(rf/defn handle-community
[{:keys [db]} {:keys [id] :as community}]
(when id
{:db (assoc-in db [:communities id] (<-rpc community))}))
(fx/defn handle-communities
(rf/defn handle-communities
{:events [::fetched]}
[{:keys [db]} communities]
{:db (reduce (fn [db {:keys [id] :as community}]
@ -104,24 +103,24 @@
db
communities)})
(fx/defn handle-response
(rf/defn handle-response
[_ response-js]
{:dispatch [:sanitize-messages-and-process-response response-js]})
(fx/defn left
(rf/defn left
{:events [::left]}
[cofx response-js]
(fx/merge cofx
(rf/merge cofx
(handle-response cofx response-js)
(navigation/pop-to-root-tab :chat-stack)
(activity-center/notifications-fetch-unread-count)))
(fx/defn joined
(rf/defn joined
{:events [::joined ::requested-to-join]}
[cofx response-js]
(handle-response cofx response-js))
(fx/defn export
(rf/defn export
{:events [::export-pressed]}
[cofx community-id]
{:json-rpc/call [{:method "wakuext_exportCommunity"
@ -133,7 +132,7 @@
(log/error "failed to export community" community-id %)
(re-frame/dispatch [::failed-to-export %]))}]})
(fx/defn import-community
(rf/defn import-community
{:events [::import]}
[cofx community-key]
{:json-rpc/call [{:method "wakuext_importCommunity"
@ -144,7 +143,7 @@
(log/error "failed to import community" %)
(re-frame/dispatch [::failed-to-import %]))}]})
(fx/defn join
(rf/defn join
{:events [:communities/join]}
[cofx community-id]
{:json-rpc/call [{:method "wakuext_joinCommunity"
@ -155,7 +154,7 @@
(log/error "failed to join community" community-id %)
(re-frame/dispatch [::failed-to-join %]))}]})
(fx/defn request-to-join
(rf/defn request-to-join
{:events [::request-to-join]}
[cofx community-id]
{:json-rpc/call [{:method "wakuext_requestToJoinCommunity"
@ -166,7 +165,7 @@
(log/error "failed to request to join community" community-id %)
(re-frame/dispatch [::failed-to-request-to-join %]))}]})
(fx/defn leave
(rf/defn leave
{:events [:communities/leave]}
[{:keys [db]} community-id]
(let [community-chat-ids (map #(str community-id %)
@ -183,7 +182,7 @@
%)
(re-frame/dispatch [::failed-to-leave %]))}]}))
(fx/defn fetch
(rf/defn fetch
[_]
{:json-rpc/call [{:method "wakuext_communities"
:params []
@ -192,7 +191,7 @@
(log/error "failed to fetch communities" %)
(re-frame/dispatch [::failed-to-fetch %]))}]})
(fx/defn chat-created
(rf/defn chat-created
{:events [::chat-created]}
[_ community-id user-pk]
{:json-rpc/call [{:method "wakuext_sendChatMessage"
@ -206,7 +205,7 @@
:on-error
#(log/error "failed to send a message" %)}]})
(fx/defn invite-users
(rf/defn invite-users
{:events [::invite-people-confirmation-pressed]}
[cofx user-pk contacts]
(let [community-id (fetch-community-id-input cofx)
@ -222,7 +221,7 @@
:on-error #(do
(log/error "failed to invite-user community" %)
(re-frame/dispatch [::failed-to-invite-people %]))}]})))
(fx/defn share-community
(rf/defn share-community
{:events [::share-community-confirmation-pressed]}
[cofx user-pk contacts]
(let [community-id (fetch-community-id-input cofx)
@ -239,7 +238,7 @@
(log/error "failed to invite-user community" %)
(re-frame/dispatch [::failed-to-share-community %]))}]})))
(fx/defn create
(rf/defn create
{:events [::create-confirmation-pressed]}
[{:keys [db]}]
(let [{:keys [name description membership image]} (get db :communities/create)]
@ -261,7 +260,7 @@
(log/error "failed to create community" %)
(re-frame/dispatch [::failed-to-create-community %]))}]})))
(fx/defn edit
(rf/defn edit
{:events [::edit-confirmation-pressed]}
[{:keys [db]}]
(let [{:keys [id name description membership new-image color]} (get db :communities/create)]
@ -281,7 +280,7 @@
(log/error "failed to edit community" %)
(re-frame/dispatch [::failed-to-edit-community %]))}]}))
(fx/defn create-channel
(rf/defn create-channel
{:events [::create-channel-confirmation-pressed]}
[{:keys [db] :as cofx}]
(let [community-id (fetch-community-id-input cofx)
@ -306,7 +305,7 @@
[chat-id]
(subs chat-id community-chat-id-length))
(fx/defn edit-channel
(rf/defn edit-channel
{:events [::edit-channel-confirmation-pressed]}
[{:keys [db] :as cofx}]
(let [{:keys [name description color community-id emoji edit-channel-id category-id position]}
@ -337,47 +336,47 @@
(let [chat-id (to-community-chat-id local-chat-id)]
(get-in community [:chats chat-id :can-post?])))
(fx/defn reset-community-id-input
(rf/defn reset-community-id-input
[{:keys [db]} id]
{:db (assoc db :communities/community-id-input id)})
(fx/defn reset-channel-info
(rf/defn reset-channel-info
[{:keys [db]}]
{:db (assoc db :communities/create-channel {})})
(fx/defn invite-people-pressed
(rf/defn invite-people-pressed
{:events [:communities/invite-people-pressed]}
[cofx id]
(fx/merge cofx
(rf/merge cofx
(reset-community-id-input id)
(bottom-sheet/hide-bottom-sheet)
(navigation/open-modal :invite-people-community {:invite? true})))
(fx/defn share-community-pressed
(rf/defn share-community-pressed
{:events [:communities/share-community-pressed]}
[cofx id]
(fx/merge cofx
(rf/merge cofx
(reset-community-id-input id)
(bottom-sheet/hide-bottom-sheet)
(navigation/open-modal :invite-people-community {})))
(fx/defn create-channel-pressed
(rf/defn create-channel-pressed
{:events [::create-channel-pressed]}
[{:keys [db] :as cofx} id]
(fx/merge cofx
(rf/merge cofx
(reset-community-id-input id)
(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})))
(fx/defn edit-channel-pressed
(rf/defn edit-channel-pressed
{:events [::edit-channel-pressed]}
[{:keys [db] :as cofx} community-id chat-name description color emoji chat-id category-id position]
(let [{:keys [color emoji]} (if (string/blank? emoji)
(rand-nth emoji-thumbnail-styles/emoji-picker-default-thumbnails)
{:color color :emoji emoji})]
(fx/merge cofx
(rf/merge cofx
{:db (assoc db
:communities/create-channel
{:name chat-name
@ -390,33 +389,33 @@
:position position})}
(navigation/open-modal :edit-community-channel nil))))
(fx/defn community-created
(rf/defn community-created
{:events [::community-created]}
[cofx response-js]
(fx/merge cofx
(rf/merge cofx
(navigation/navigate-back)
(handle-response response-js)))
(fx/defn community-edited
(rf/defn community-edited
{:events [::community-edited]}
[cofx response-js]
(fx/merge cofx
(rf/merge cofx
(navigation/navigate-back)
(handle-response response-js)))
(fx/defn open-create-community
(rf/defn open-create-community
{:events [::open-create-community]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc db :communities/create {:membership constants/community-no-membership-access})}
(navigation/navigate-to :community-create nil)))
(fx/defn open-edit-community
(rf/defn open-edit-community
{:events [::open-edit-community]}
[{:keys [db] :as cofx} id]
(let [{:keys [name description images permissions color]} (get-in db [:communities id])
{:keys [access]} permissions]
(fx/merge cofx
(rf/merge cofx
{:db (assoc db
:communities/create
{:id id
@ -428,63 +427,63 @@
:editing? true})}
(navigation/navigate-to :community-edit nil))))
(fx/defn community-imported
(rf/defn community-imported
{:events [::community-imported]}
[cofx response-js]
(fx/merge cofx
(rf/merge cofx
(navigation/navigate-back)
(handle-response response-js)))
(fx/defn people-invited
(rf/defn people-invited
{:events [::people-invited]}
[cofx response-js]
(fx/merge cofx
(rf/merge cofx
(navigation/navigate-back)
(handle-response response-js)))
(fx/defn community-channel-created
(rf/defn community-channel-created
{:events [::community-channel-created]}
[cofx response-js]
(fx/merge cofx
(rf/merge cofx
(navigation/navigate-back)
(handle-response response-js)))
(fx/defn community-channel-edited
(rf/defn community-channel-edited
{:events [::community-channel-edited]}
[cofx response-js]
(fx/merge cofx
(rf/merge cofx
(navigation/navigate-back)
(handle-response response-js)))
(fx/defn create-field
(rf/defn create-field
{:events [::create-field]}
[{:keys [db]} field value]
{:db (assoc-in db [:communities/create field] value)})
(fx/defn remove-field
(rf/defn remove-field
{:events [::remove-field]}
[{:keys [db]} field]
{:db (update-in db [:communities/create] dissoc field)})
(fx/defn create-channel-field
(rf/defn create-channel-field
{:events [::create-channel-field]}
[{:keys [db]} 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]}
[{:keys [db]} field-values]
{:db (update-in db [:communities/create-channel] merge field-values)})
(fx/defn member-banned
(rf/defn member-banned
{:events [::member-banned]}
[cofx response-js]
(fx/merge cofx
(rf/merge cofx
(bottom-sheet/hide-bottom-sheet)
(handle-response response-js)
(activity-center/notifications-fetch-unread-count)))
(fx/defn member-ban
(rf/defn member-ban
{:events [::member-ban]}
[cofx community-id public-key]
{:json-rpc/call [{:method "wakuext_banUserFromCommunity"
@ -497,14 +496,14 @@
public-key
%)}]})
(fx/defn member-kicked
(rf/defn member-kicked
{:events [::member-kicked]}
[cofx response-js]
(fx/merge cofx
(rf/merge cofx
(bottom-sheet/hide-bottom-sheet)
(handle-response response-js)))
(fx/defn member-kick
(rf/defn member-kick
{:events [::member-kick]}
[cofx community-id public-key]
{:json-rpc/call [{:method "wakuext_removeUserFromCommunity"
@ -516,19 +515,19 @@
public-key
%)}]})
(fx/defn delete-community
(rf/defn delete-community
{:events [::delete-community]}
[cofx community-id]
(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]}
[{:keys [db]} community-id requests]
{:db (assoc-in db
[:communities/requests-to-join community-id]
(<-requests-to-join-community-rpc requests))})
[: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]}
[cofx community-id]
{:json-rpc/call [{:method "wakuext_pendingRequestsToJoinForCommunity"
@ -540,21 +539,21 @@
[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]}
[{: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)}
(handle-response response-js)))
(fx/defn request-to-join-declined
(rf/defn request-to-join-declined
{:events [::request-to-join-declined]}
[{: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)}
(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]}
[cofx community-id request-id]
{:json-rpc/call [{:method "wakuext_acceptRequestToJoinCommunity"
@ -567,7 +566,7 @@
request-id
%)}]})
(fx/defn decline-request-to-join-pressed
(rf/defn decline-request-to-join-pressed
{:events [:communities.ui/decline-request-to-join-pressed]}
[cofx community-id request-id]
{:json-rpc/call [{:method "wakuext_declineRequestToJoinCommunity"
@ -579,13 +578,13 @@
community-id
request-id)}]})
(fx/defn switch-communities-enabled
(rf/defn switch-communities-enabled
{:events [:multiaccounts.ui/switch-communities-enabled]}
[{:keys [db]} enabled?]
{::async-storage/set! {:communities-enabled? enabled?}
:db (assoc db :communities/enabled? enabled?)})
(fx/defn create-category
(rf/defn create-category
{:events [::create-category-confirmation-pressed]}
[_ community-id category-title chat-ids]
{:json-rpc/call [{:method "wakuext_createCommunityCategory"
@ -598,7 +597,7 @@
(re-frame/dispatch [:sanitize-messages-and-process-response %]))
: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]}
[{:keys [db]} community-id id categoryID]
(let [category (get-in db [:communities community-id :categories categoryID])
@ -614,7 +613,7 @@
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
:on-error #(log/error "failed to remove chat from community" %)}]}))
(fx/defn delete-community-chat
(rf/defn delete-community-chat
{:events [:delete-community-chat]}
[_ community-id chat-id]
{:json-rpc/call [{:method "wakuext_deleteCommunityChat"
@ -623,7 +622,7 @@
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
:on-error #(log/error "failed to delete community chat" %)}]})
(fx/defn delete-category
(rf/defn delete-category
{:events [:delete-community-category]}
[_ community-id category-id]
{:json-rpc/call [{:method "wakuext_deleteCommunityCategory"
@ -633,7 +632,7 @@
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
:on-error #(log/error "failed to delete community category" %)}]})
(fx/defn change-category
(rf/defn change-category
{:events [::change-category-confirmation-pressed]}
[cofx community-id category-id {:keys [id position categoryID]}]
(if (not (string/blank? category-id))
@ -647,11 +646,11 @@
(re-frame/dispatch [:navigate-back])
(re-frame/dispatch [:sanitize-messages-and-process-response %]))
:on-error #(log/error "failed to change community category" %)}]}
(fx/merge cofx
(rf/merge cofx
(navigation/navigate-back)
(remove-chat-from-category community-id id categoryID))))
(fx/defn reorder-category-chat
(rf/defn reorder-category-chat
{:events [::reorder-community-category-chat]}
[_ community-id category-id chat-id new-position]
{:json-rpc/call [{:method "wakuext_reorderCommunityChat"
@ -663,7 +662,7 @@
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
:on-error #(log/error "failed to reorder community category chat" %)}]})
(fx/defn reorder-category
(rf/defn reorder-category
{:events [::reorder-community-category]}
[_ community-id category-id new-position]
{:json-rpc/call [{:method "wakuext_reorderCommunityCategories"
@ -678,14 +677,14 @@
[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]}
[{:keys [db]} community-id category-id state-open?]
(let [public-key (get-in db [:multiaccount :public-key])
hash (category-hash public-key community-id category-id)]
{::async-storage/set! {hash state-open?}}))
(fx/defn update-category-states-in-db
(rf/defn update-category-states-in-db
{:events [::category-states-loaded]}
[{:keys [db]} community-id hashes states]
(let [public-key (get-in db [:multiaccount :public-key])
@ -699,7 +698,7 @@
categories-old)]
{: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]}
[{:keys [db]} community-id]
(let [public-key (get-in db [:multiaccount :public-key])
@ -719,21 +718,21 @@
:cb #(re-frame/dispatch
[::category-states-loaded community-id hashes %])}}))
(fx/defn navigate-to-community
(rf/defn navigate-to-community
{:events [:communities/navigate-to-community]}
[cofx community-id]
(fx/merge cofx
(rf/merge cofx
(navigation/pop-to-root-tab :shell-stack)
(navigation/navigate-to-nav2 :community community-id true)))
(fx/defn member-role-updated
(rf/defn member-role-updated
{:events [:community.member/role-updated]}
[cofx response-js]
(fx/merge cofx
(rf/merge cofx
(bottom-sheet/hide-bottom-sheet)
(handle-response response-js)))
(fx/defn add-role-to-member
(rf/defn add-role-to-member
{:events [:community.member/add-role]}
[cofx community-id public-key role-id]
{:json-rpc/call [{:method "wakuext_addRoleToMember"
@ -747,7 +746,7 @@
:public-key public-key
:role-id role-id})}]})
(fx/defn remove-role-from-member
(rf/defn remove-role-from-member
{:events [:community.member/remove-role]}
[_ community-id public-key role-id]
{:json-rpc/call [{:method "wakuext_removeRoleFromMember"

View File

@ -4,12 +4,12 @@
[status-im.contact.db :as contact.db]
[status-im.data-store.chats :as chats-store]
[status-im.data-store.contacts :as contacts-store]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.types :as types]
[status-im2.contexts.activity-center.events :as activity-center]
[status-im2.navigation.events :as navigation]))
(fx/defn clean-up-chat
(rf/defn clean-up-chat
[{:keys [db] :as cofx}
public-key
{:keys [chat-id
@ -31,17 +31,17 @@
:unviewed-mentions-count unviewed-mentions-count
:last-message last-message))]
{:db (assoc-in db
[:message-lists chat-id]
(message-list/add-many nil (vals (get-in db [:messages chat-id]))))}))
[:message-lists 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]}
[{:keys [db] :as cofx} {:keys [public-key]} chats]
(let [fxs (when chats
(map #(->> (chats-store/<-rpc %)
(clean-up-chat public-key))
(types/js->clj chats)))]
(apply fx/merge
(apply rf/merge
cofx
{:db (-> db
(update :chats dissoc public-key)
@ -52,7 +52,7 @@
(activity-center/notifications-fetch-unread-count)
fxs)))
(fx/defn block-contact
(rf/defn block-contact
{:events [:contact.ui/block-contact-confirmed]}
[{:keys [db] :as cofx} public-key]
(let [contact (-> (contact.db/public-key->contact
@ -61,7 +61,7 @@
(assoc :blocked true
:added false))
from-one-to-one-chat? (not (get-in db [:chats (:current-chat-id db) :group-chat]))]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
;; add the contact to blocked contacts
(update :contacts/blocked (fnil conj #{}) public-key)
@ -77,7 +77,7 @@
(navigation/pop-to-root-tab :chat-stack)
(navigation/navigate-back)))))
(fx/defn contact-unblocked
(rf/defn contact-unblocked
{:events [::contact-unblocked]}
[{:keys [db]} contact-id]
(let [contact (-> (get-in db [:contacts/contacts contact-id])
@ -86,7 +86,7 @@
(update :contacts/blocked disj contact-id)
(assoc-in [:contacts/contacts contact-id] contact))}))
(fx/defn unblock-contact
(rf/defn unblock-contact
{:events [:contact.ui/unblock-contact-pressed]}
[cofx contact-id]
(contacts-store/unblock

View File

@ -2,28 +2,28 @@
(:require [re-frame.core :as re-frame]
[status-im.chat.models :as chat]
[status-im.contact.core :as contact]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im2.navigation.events :as navigation]))
(fx/defn send-message-pressed
(rf/defn send-message-pressed
{:events [:contact.ui/send-message-pressed]
:interceptors [(re-frame/inject-cofx :random-id-generator)]}
[cofx {:keys [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]
:interceptors [(re-frame/inject-cofx :random-id-generator)]}
[{{:contacts/keys [new-identity]} :db :as cofx} new-contact? nickname]
(let [{:keys [public-key ens-name]} new-identity]
(fx/merge cofx
(rf/merge cofx
#(if new-contact?
(contact/add-contact % public-key nickname ens-name)
(chat/start-chat % public-key ens-name))
#(when new-contact?
(navigation/navigate-back %)))))
(fx/defn pinned-messages-pressed
(rf/defn pinned-messages-pressed
{:events [:contact.ui/pinned-messages-pressed]}
[cofx public-key]
(chat/navigate-to-user-pinned-messages cofx public-key))

View File

@ -5,11 +5,11 @@
[status-im.contact.db :as contact.db]
[status-im.data-store.contacts :as contacts-store]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im2.navigation.events :as navigation]
[taoensso.timbre :as log]))
(fx/defn load-contacts
(rf/defn load-contacts
{:events [::contacts-loaded]}
[{:keys [db] :as cofx} all-contacts]
(let [contacts-list (map #(vector (:public-key %)
@ -30,7 +30,7 @@
(= public-key (:public-key multiaccount))
(assoc :name (:name multiaccount))))
(fx/defn ensure-contacts
(rf/defn ensure-contacts
[{:keys [db]} contacts chats]
(let [events
(reduce
@ -74,7 +74,7 @@
:profile-image identicon
:address address}))
(fx/defn send-contact-request
(rf/defn send-contact-request
{:events [::send-contact-request]}
[{:keys [db] :as cofx} public-key]
(let [{:keys [name profile-image]} (own-info db)]
@ -82,7 +82,7 @@
:params [public-key name profile-image]
: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"
{:events [:contact.ui/add-to-contact-pressed]}
[{:keys [db] :as cofx} public-key nickname ens-name]
@ -96,7 +96,7 @@
(re-frame/dispatch [:sanitize-messages-and-process-response %])
(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"
{:events [:contact.ui/remove-contact-pressed]}
[{:keys [db]} {:keys [public-key]}]
@ -112,7 +112,7 @@
:on-success #(log/debug "contact removed successfully")}]
:dispatch [:offload-messages constants/timeline-chat-id]})
(fx/defn accept-contact-request
(rf/defn accept-contact-request
{:events [:contact-requests.ui/accept-request]}
[{:keys [db]} id]
{:json-rpc/call [{:method "wakuext_acceptContactRequest"
@ -120,7 +120,7 @@
:js-response true
: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]}
[{:keys [db]} id]
{:json-rpc/call [{:method "wakuext_dismissContactRequest"
@ -128,30 +128,30 @@
:js-response true
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]})
(fx/defn initialize-contacts
(rf/defn initialize-contacts
[cofx]
(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]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc db
:group/selected-contacts #{}
:new-chat-name "")}
(navigation/navigate-to-cofx :contact-toggle-list nil)))
(fx/defn update-nickname
(rf/defn update-nickname
{:events [:contacts/update-nickname]}
[{:keys [db] :as cofx} public-key nickname]
(fx/merge cofx
(rf/merge cofx
(contacts-store/set-nickname
public-key
nickname
#(re-frame/dispatch [:sanitize-messages-and-process-response %]))
(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]}
[cofx enabled?]
(multiaccounts.update/multiaccount-update
@ -160,7 +160,7 @@
enabled?
nil))
(fx/defn set-search-query
(rf/defn set-search-query
{:events [:contacts/set-search-query]}
[{:keys [db] :as cofx} value]
{:db (assoc db :contacts/search-query value)})

View File

@ -1,16 +1,16 @@
(ns status-im.currency.core
(: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]))
(defn get-currency
[db]
(get-in db [:multiaccount :currency] :usd))
(fx/defn set-currency
(rf/defn set-currency
{:events [:wallet.settings.ui/currency-selected]}
[{:keys [db] :as cofx} currency]
(fx/merge cofx
(rf/merge cofx
(multiaccounts.update/multiaccount-update
:currency
currency

View File

@ -2,7 +2,7 @@
(:require [clojure.set :as clojure.set]
[status-im.constants :as constants]
[status-im.data-store.messages :as messages]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.types :as types]
[taoensso.timbre :as log]))
@ -108,7 +108,7 @@
rpc->type
unmarshal-members))
(fx/defn fetch-chats-rpc
(rf/defn fetch-chats-rpc
[_ {:keys [on-success]}]
{:json-rpc/call [{:method "wakuext_chatsPreview"
:params []

View File

@ -1,6 +1,6 @@
(ns status-im.data-store.contacts
(:require [clojure.set :as clojure.set]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[taoensso.timbre :as log]))
(defn <-rpc
@ -21,14 +21,14 @@
(and (:added contact)
(:hasAddedUs contact)))))
(fx/defn fetch-contacts-rpc
(rf/defn fetch-contacts-rpc
[_ on-success]
{:json-rpc/call [{:method "wakuext_contacts"
:params []
:on-success #(on-success (map <-rpc %))
:on-error #(log/error "failed to fetch contacts" %)}]})
(fx/defn add
(rf/defn add
[_ public-key nickname ens-name on-success]
{:json-rpc/call [{:method "wakuext_addContact"
:params [{:id public-key :nickname nickname :ensName ens-name}]
@ -39,7 +39,7 @@
(on-success %)))
:on-error #(log/error "failed to add contact" public-key %)}]})
(fx/defn set-nickname
(rf/defn set-nickname
[_ public-key nickname on-success]
{:json-rpc/call [{:method "wakuext_setContactLocalNickname"
:params [{:id public-key :nickname nickname}]
@ -53,7 +53,7 @@
nickname
%)}]})
(fx/defn block
(rf/defn block
[_ contact-id on-success]
{:json-rpc/call [{:method "wakuext_blockContact"
:params [contact-id]
@ -61,7 +61,7 @@
:on-success on-success
:on-error #(log/error "failed to block contact" % contact-id)}]})
(fx/defn unblock
(rf/defn unblock
[_ contact-id on-success]
{:json-rpc/call [{:method "wakuext_unblockContact"
:params [contact-id]

View File

@ -1,6 +1,6 @@
(ns status-im.data-store.messages
(:require [clojure.set :as clojure.set]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[taoensso.timbre :as log]))
(defn ->rpc
@ -100,18 +100,18 @@
: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)}]})
(fx/defn delete-message
(rf/defn delete-message
[cofx id]
(delete-message-rpc id))
(fx/defn delete-messages-from
(rf/defn delete-messages-from
[cofx author]
(delete-messages-from-rpc author))
(fx/defn mark-messages-seen
(rf/defn mark-messages-seen
[cofx chat-id ids on-success]
(mark-seen-rpc chat-id ids on-success))
(fx/defn delete-messages-by-chat-id
(rf/defn delete-messages-by-chat-id
[cofx chat-id]
(delete-messages-by-chat-id-rpc chat-id))

View File

@ -1,7 +1,7 @@
(ns status-im.data-store.pin-messages
(:require [clojure.set :as clojure.set]
[status-im.data-store.messages :as messages]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[taoensso.timbre :as log]))
(defn <-rpc
@ -27,7 +27,7 @@
(on-success (update result :pinned-messages #(map <-rpc %)))))
:on-error on-error}]})
(fx/defn send-pin-message
(rf/defn send-pin-message
[cofx pin-message]
{:json-rpc/call [{:method "wakuext_sendPinMessage"
:params [(messages/->rpc pin-message)]

View File

@ -1,7 +1,7 @@
(ns status-im.data-store.visibility-status-updates
(:require [clojure.set :as clojure.set]
[re-frame.core :as re-frame]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[taoensso.timbre :as log]))
(defn <-rpc
@ -16,7 +16,7 @@
{:current-user-status :current-user-visibility-status})
(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"
:params []

View File

@ -9,7 +9,7 @@
[status-im.ethereum.stateofus :as stateofus]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.utils.datetime :as datetime]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.random :as random]
[status-im2.navigation.events :as navigation]))
@ -39,16 +39,16 @@
(fn [[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]}
[{:keys [db]} new-state username custom-domain? tx-hash]
{:db (assoc-in db
[:ens/registrations tx-hash]
{:state new-state
:username username
:custom-domain? custom-domain?})})
[:ens/registrations tx-hash]
{:state new-state
:username username
:custom-domain? custom-domain?})})
(fx/defn redirect-to-ens-summary
(rf/defn redirect-to-ens-summary
{:events [::redirect-to-ens-summary]}
[cofx]
;; we reset navigation so that navigate back doesn't return
@ -58,19 +58,19 @@
[:my-profile
: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]}
[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)
(redirect-to-ens-summary)))
(fx/defn clear-ens-registration
(rf/defn clear-ens-registration
{:events [:clear-ens-registration]}
[{:keys [db]} tx-hash]
{:db (update db :ens/registrations dissoc tx-hash)})
(fx/defn set-state
(rf/defn set-state
{:events [::name-resolved]}
[{:keys [db]} username state address]
(when (= username
@ -79,13 +79,13 @@
(assoc-in [:ens/registration :state] state)
(assoc-in [:ens/registration :address] address))}))
(fx/defn save-username
(rf/defn save-username
{:events [::save-username]}
[{:keys [db] :as cofx} custom-domain? username redirectToSummary]
(let [name (fullname custom-domain? username)
names (get-in db [:multiaccount :usernames] [])
new-names (conj names name)]
(fx/merge cofx
(rf/merge cofx
(multiaccounts.update/multiaccount-update
:usernames
new-names
@ -97,7 +97,7 @@
name
{})))))
(fx/defn set-pub-key
(rf/defn set-pub-key
{:events [::set-pub-key]}
[{:keys [db]}]
(let [{:keys [username address custom-domain?]} (:ens/registration db)
@ -115,7 +115,7 @@
:on-result [::save-username custom-domain? username true]
:on-error [::on-registration-failure]}]))))
(fx/defn on-input-submitted
(rf/defn on-input-submitted
{:events [::input-submitted]}
[{:keys [db] :as cofx}]
(let [{:keys [state username custom-domain?]} (:ens/registration db)]
@ -164,7 +164,7 @@
5 10
1 10))
(fx/defn register-name
(rf/defn register-name
{:events [::register-name-pressed]}
[{:keys [db]} address]
(let [{:keys [username]}
@ -207,7 +207,7 @@
;;NOTE we want to handle only last resolve
(def resolve-last-id (atom nil))
(fx/defn set-username-candidate
(rf/defn set-username-candidate
{:events [::set-username-candidate]}
[{:keys [db]} username]
(let [{:keys [custom-domain?]} (:ens/registration db)
@ -236,10 +236,10 @@
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]}
[{:keys [db] :as cofx} _]
(fx/merge cofx
(rf/merge cofx
;; clear registration data
{:db (dissoc db :ens/registration)}
;; we reset navigation so that navigate back doesn't return
@ -248,22 +248,22 @@
[:my-profile
:ens-main])))
(fx/defn switch-domain-type
(rf/defn switch-domain-type
{:events [::switch-domain-type]}
[{:keys [db] :as cofx} _]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(update :ens/registration dissoc :username :state)
(update-in [:ens/registration :custom-domain?] not))}))
(fx/defn change-address
(rf/defn change-address
{:events [::change-address]}
[{:keys [db] :as cofx} _ {:keys [address]}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:ens/registration :address] address)}
(bottom-sheet/hide-bottom-sheet)))
(fx/defn save-preferred-name
(rf/defn save-preferred-name
{:events [::save-preferred-name]}
[cofx name]
(multiaccounts.update/multiaccount-update cofx
@ -271,24 +271,24 @@
name
{}))
(fx/defn on-registration-failure
(rf/defn on-registration-failure
"TODO not sure there is actually anything to do here
it should only be called if the user cancels the signing
Actual registration failure has not been implemented properly"
{:events [::on-registration-failure]}
[_ _])
(fx/defn store-name-address
(rf/defn store-name-address
{:events [::address-resolved]}
[{:keys [db]} username 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]}
[{:keys [db]} username 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]}
[{:keys [now db]} username timestamp]
{:db (-> db
@ -296,11 +296,11 @@
(datetime/timestamp->year-month-day-date timestamp))
(assoc-in [:ens/names username :releasable?] (<= timestamp now)))})
(fx/defn navigate-to-name
(rf/defn navigate-to-name
{:events [::navigate-to-name]}
[{:keys [db] :as cofx} username]
(let [chain-id (ethereum/chain-id db)]
(fx/merge cofx
(rf/merge cofx
{::get-expiration-time
[chain-id
(stateofus/username username)
@ -313,20 +313,20 @@
#(re-frame/dispatch [::public-key-resolved username %])]}
(navigation/navigate-to-cofx :ens-name-details username))))
(fx/defn start-registration
(rf/defn start-registration
{:events [::add-username-pressed ::get-started-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
(set-username-candidate (get-in db [:ens/registration :username] ""))
(navigation/navigate-to-cofx :ens-search {})))
(fx/defn remove-username
(rf/defn remove-username
{:events [::remove-username]}
[{:keys [db] :as cofx} name]
(let [names (get-in db [:multiaccount :usernames] [])
preferred-name (get-in db [:multiaccount :preferred-name])
new-names (remove #(= name %) names)]
(fx/merge cofx
(rf/merge cofx
(multiaccounts.update/multiaccount-update
:usernames
new-names

View File

@ -1,19 +1,19 @@
(ns status-im.ethereum.subscriptions
(:require [status-im.ethereum.eip55 :as eip55]
[status-im.ethereum.transactions.core :as transactions]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.wallet.core :as wallet.core]
[status-im.wallet.db :as wallet]
[taoensso.timbre :as log]))
(fx/defn new-transfers
(rf/defn new-transfers
[cofx block-number accounts]
(log/debug "[wallet-subs] new-transfers"
"accounts" accounts
"block" block-number)
(transactions/check-watched-transactions cofx))
(fx/defn recent-history-fetching-started
(rf/defn recent-history-fetching-started
[{:keys [db]} accounts]
(log/debug "[wallet-subs] recent-history-fetching-started"
"accounts"
@ -26,7 +26,7 @@
event
(assoc :dispatch event))))
(fx/defn recent-history-fetching-ended
(rf/defn recent-history-fetching-ended
[{:keys [db]} {:keys [accounts blockNumber]}]
(log/debug "[wallet-subs] recent-history-fetching-ended"
"accounts" accounts
@ -55,18 +55,18 @@
:before-block blockNumber
:limit 20}})
(fx/defn fetching-error
(rf/defn fetching-error
[{:keys [db] :as cofx} {:keys [message]}]
(fx/merge
(rf/merge
cofx
{:db (assoc db :wallet/fetching-error message)}
(wallet.core/after-checking-history)))
(fx/defn non-archival-node-detected
(rf/defn non-archival-node-detected
[{:keys [db]} _]
{: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}]
(log/info "[wallet-subs] new-wallet-event"
"event-type" type

View File

@ -6,7 +6,7 @@
[status-im.ethereum.decode :as decode]
[status-im.ethereum.eip55 :as eip55]
[status-im.ethereum.encode :as encode]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.mobile-sync :as utils.mobile-sync]
[status-im.wallet.core :as wallet]
[status-im2.common.json-rpc.events :as json-rpc]
@ -107,7 +107,7 @@
(def default-transfers-limit 20)
(fx/defn watch-transaction
(rf/defn watch-transaction
"Set a watch for the given transaction
`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
@ -117,10 +117,10 @@
(when (and (fn? trigger-fn)
(fn? on-trigger))
{:db (assoc-in db
[:ethereum/watched-transactions transaction-id]
watch-params)}))
[:ethereum/watched-transactions transaction-id]
watch-params)}))
(fx/defn check-transaction
(rf/defn check-transaction
"Check if the transaction has been triggered and applies the effects returned
by `on-trigger` if that is the case"
[{:keys [db] :as cofx} {:keys [hash] :as transaction}]
@ -128,14 +128,14 @@
(get-in db [:ethereum/watched-transactions hash])]
(let [{:keys [trigger-fn on-trigger]} watch-params]
(when (trigger-fn db transaction)
(fx/merge cofx
(rf/merge cofx
{:db (update db
:ethereum/watched-transactions
dissoc
hash)}
(on-trigger transaction))))))
(fx/defn check-watched-transactions
(rf/defn check-watched-transactions
[{:keys [db] :as cofx}]
(let [watched-transactions
(reduce-kv (fn [acc _ {:keys [transactions]}]
@ -144,13 +144,13 @@
(keys (get db :ethereum/watched-transactions)))))
{}
(get-in db [:wallet :accounts]))]
(apply fx/merge
(apply rf/merge
cofx
(map (fn [[_ transaction]]
(check-transaction transaction))
watched-transactions))))
(fx/defn add-transfer
(rf/defn add-transfer
"We determine a unique id for the transfer before adding it because some
transaction can contain multiple transfers and they would overwrite each other
in the transfer map if identified by hash"
@ -162,10 +162,10 @@
(:type transfer-by-hash))))
id
hash))]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db
[:wallet :accounts address :transactions unique-id]
(assoc transfer :hash unique-id))}
[:wallet :accounts address :transactions unique-id]
(assoc transfer :hash unique-id))}
(check-transaction transfer)))))
(defn get-min-known-block
@ -183,7 +183,7 @@
(eip55/address->checksum address)
:min-block-transfers-count]))
(fx/defn set-lowest-fetched-block
(rf/defn set-lowest-fetched-block
[{:keys [db]} address transfers]
(let [checksum (eip55/address->checksum address)
{:keys [min-block min-block-transfers-count]}
@ -226,29 +226,29 @@
(reduce
(fn [accounts address]
(assoc-in accounts
[(eip55/address->checksum address) fetching-type]
state))
[(eip55/address->checksum address) fetching-type]
state))
accounts
addresses))))
(fx/defn tx-fetching-in-progress
(rf/defn tx-fetching-in-progress
[{:keys [db]} addresses]
{:db (update-fetching-status db addresses :history? true)})
(fx/defn tx-fetching-ended
(rf/defn tx-fetching-ended
[{:keys [db]} addresses]
{: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]
(let [syncing-allowed? (utils.mobile-sync/syncing-allowed? cofx)]
{:db (assoc-in db
[:wallet :fetching address :all-fetched?]
(if syncing-allowed?
:all
:all-preloaded))}))
[:wallet :fetching address :all-fetched?]
(if syncing-allowed?
:all
:all-preloaded))}))
(fx/defn delete-pending-transactions
(rf/defn delete-pending-transactions
[{:keys [db]} address transactions]
(let [all-transactions
(get-in db [:wallet :accounts (eip55/address->checksum address) :transactions])
@ -261,7 +261,7 @@
transactions)]
{: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]}]
(log/debug "[transfers] new-transfers"
"address" address
@ -290,9 +290,9 @@
(< (count transfers) limit)
(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]
(let [set-of-transactions-hash (reduce (fn [acc {:keys [hash]}] (conj acc hash)) #{} transfers)
registrations (filter
@ -310,7 +310,7 @@
transaction-success (get transfer :transfer)]
(cond
(= transaction-success true)
(fx/merge cofx
(rf/merge cofx
(ens/clear-ens-registration hash)
(ens/save-username custom-domain? username false))
(= type :failed)
@ -318,17 +318,17 @@
:else
nil)))
registrations)]
(apply fx/merge cofx fxs)))
(apply rf/merge cofx fxs)))
(fx/defn new-transfers
(rf/defn new-transfers
{:events [::new-transfers]}
[cofx transfers params]
(fx/merge cofx
(rf/merge cofx
(handle-new-transfer transfers params)
(wallet/stop-fetching-on-empty-tx-history transfers)
(check-ens-transactions transfers)))
(fx/defn tx-fetching-failed
(rf/defn tx-fetching-failed
{:events [::tx-fetching-failed]}
[cofx error address]
(log/debug "[transactions] tx-fetching-failed"
@ -371,13 +371,13 @@
[db address]
(not-empty (get-in db [:wallet :accounts address :transactions])))
(fx/defn fetch-more-tx
(rf/defn fetch-more-tx
{:events [:transactions/fetch-more]}
[{:keys [db] :as cofx} address]
(let [min-known-block (or (get-min-known-block db address)
(:ethereum/current-block db))
min-block-transfers-count (or (min-block-transfers-count db address) 0)]
(fx/merge
(rf/merge
cofx
{:transactions/get-transfers
{:chain-tokens (:wallet/all-tokens db)
@ -393,7 +393,7 @@
min-block-transfers-count)}}}
(tx-fetching-in-progress [address]))))
(fx/defn get-fetched-transfers
(rf/defn get-fetched-transfers
{:events [:transaction/get-fetched-transfers]}
[{:keys [db]}]
{:transactions/get-transfers

View File

@ -43,7 +43,7 @@
[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]
[utils.re-frame :as rf]
status-im.utils.logging.core
[status-im.utils.universal-links.core :as universal-links]
[status-im.utils.utils :as utils]
@ -95,22 +95,22 @@
(fn []
(dimensions/add-event-listener)))
(fx/defn dismiss-keyboard
(rf/defn dismiss-keyboard
{:events [:dismiss-keyboard]}
[_]
{:dismiss-keyboard nil})
(fx/defn identicon-generated
(rf/defn identicon-generated
{:events [:identicon-generated]}
[{:keys [db]} path identicon]
{:db (assoc-in db path identicon)})
(fx/defn gfycat-generated
(rf/defn gfycat-generated
{:events [:gfycat-generated]}
[{:keys [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]}
[cofx _]
(when (multiaccounts.model/logged-in? cofx)
@ -135,7 +135,7 @@
authentication-options)
:on-cancel #(re-frame/dispatch [:multiaccounts.logout.ui/logout-confirmed])}))))
(fx/defn on-return-from-background
(rf/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?])
@ -146,7 +146,7 @@
(some? app-in-background-since)
(>= (- now app-in-background-since)
constants/ms-in-bg-for-require-bioauth))]
(fx/merge cofx
(rf/merge cofx
{:db (dissoc db :app-in-background-since)}
(mailserver/process-next-messages-request)
(wallet/restart-wallet-service-after-background app-in-background-since)
@ -156,17 +156,17 @@
#(when requires-bio-auth
(biometric/authenticate % on-biometric-auth-result authentication-options)))))
(fx/defn on-going-in-background
(rf/defn on-going-in-background
[{:keys [db now]}]
{:db (assoc db :app-in-background-since now)
:dispatch-n [[:audio-recorder/on-background] [:audio-message/on-background]]})
(fx/defn app-state-change
(rf/defn app-state-change
{:events [:app-state-change]}
[{:keys [db] :as cofx} state]
(let [app-coming-from-background? (= state "active")
app-going-in-background? (= state "background")]
(fx/merge cofx
(rf/merge cofx
{::app-state-change-fx state
:db (assoc db :app-state state)}
#(when app-coming-from-background?
@ -174,26 +174,26 @@
#(when app-going-in-background?
(on-going-in-background %)))))
(fx/defn request-permissions
(rf/defn request-permissions
{:events [:request-permissions]}
[_ options]
{:request-permissions-fx options})
(fx/defn update-window-dimensions
(rf/defn update-window-dimensions
{:events [:update-window-dimensions]}
[{:keys [db]} dimensions]
{:db (assoc db :dimensions/window (dimensions/window dimensions))})
(fx/defn init-timeline-chat
(rf/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)))
(fx/defn on-will-focus
(rf/defn on-will-focus
{:events [:screens/on-will-focus]}
[{:keys [db] :as cofx} view-id]
(fx/merge cofx
(rf/merge cofx
(cond
(= :chat view-id)
{::async-storage/set! {:chat-id (get-in cofx [:db :current-chat-id])
@ -222,25 +222,25 @@
nil)))
;;TODO :replace by named events
(fx/defn set-event
(rf/defn set-event
{:events [:set]}
[{:keys [db]} k v]
{:db (assoc db k v)})
(fx/defn set-view-id
(rf/defn set-view-id
{:events [:set-view-id]}
[{:keys [db]} view-id]
{:db (assoc db :view-id view-id)})
;;TODO :replace by named events
(fx/defn set-once-event
(rf/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
(rf/defn set-in-event
{:events [:set-in]}
[{:keys [db]} path v]
{:db (assoc-in db path v)})
@ -251,7 +251,7 @@
{:logoUrl :logo-url
:siteUrl :site-url}))
(fx/defn crypto-loaded-event
(rf/defn crypto-loaded-event
{:events [::crypto-loaded]}
[{:keys [db]} on-ramps]
{:db (assoc
@ -259,7 +259,7 @@
:buy-crypto/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]}
[_]
{:json-rpc/call [{:method "wallet_getCryptoOnRamps"
@ -267,10 +267,10 @@
:on-success (fn [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]}
[cofx]
(fx/merge
(rf/merge
cofx
(navigation/open-modal :buy-crypto nil)
(wallet/keep-watching-history)))
@ -288,7 +288,7 @@
(hash id)
(hash (str public-key id))))
(fx/defn close-information-box
(rf/defn close-information-box
{:events [:close-information-box]}
[{:keys [db]} id global?]
(let [public-key (get-in db [:multiaccount :public-key])
@ -296,7 +296,7 @@
{::async-storage/set! {hash 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]}
[{:keys [db]} hashes states]
{:db (assoc db
@ -307,7 +307,7 @@
{}
hashes))})
(fx/defn load-information-box-states
(rf/defn load-information-box-states
{:events [:load-information-box-states]}
[{:keys [db]}]
(let [public-key (get-in db [:multiaccount :public-key])

View File

@ -5,7 +5,7 @@
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.node.core :as node]
[status-im.utils.config :as config]
[status-im.utils.fx :as fx]))
[utils.re-frame :as rf]))
(defn current-fleet-sub
[multiaccount]
@ -33,7 +33,7 @@
{}
(node/fleets db)))
(fx/defn show-save-confirmation
(rf/defn show-save-confirmation
{:events [:fleet.ui/fleet-selected]}
[_ fleet]
{:ui/show-confirmation
@ -58,7 +58,7 @@
:mail (format-nodes nodes)
:whisper (format-nodes nodes)}))
(fx/defn set-nodes
(rf/defn set-nodes
[{:keys [db]} fleet nodes]
{:db (-> db
(assoc-in [:custom-fleets fleet] (nodes->fleet nodes))
@ -72,12 +72,12 @@
{}
nodes))))})
(fx/defn save
(rf/defn save
{:events [:fleet.ui/save-fleet-confirmed]}
[{:keys [db now] :as cofx} fleet]
(let [old-fleet (get-in db [:multiaccount :fleet])]
(when (not= fleet old-fleet)
(fx/merge
(rf/merge
cofx
(multiaccounts.update/multiaccount-update :fleet fleet {})
(node/prepare-new-config

View File

@ -6,33 +6,33 @@
[status-im.chat.models :as models.chat]
[status-im.constants :as constants]
[status-im.i18n.i18n :as i18n]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im2.contexts.activity-center.events :as activity-center]
[status-im2.navigation.events :as navigation]))
(fx/defn navigate-chat-updated
(rf/defn navigate-chat-updated
{:events [:navigate-chat-updated]}
[cofx chat-id]
(when (get-in cofx [:db :chats chat-id])
(models.chat/navigate-to-chat cofx chat-id)))
(fx/defn handle-chat-removed
(rf/defn handle-chat-removed
{:events [:chat-removed]}
[cofx response]
(fx/merge cofx
(rf/merge cofx
{:db (dissoc (:db cofx) :current-chat-id)
:dispatch-n [[:sanitize-messages-and-process-response response]
[:pop-to-root-tab :chat-stack]]}
(activity-center/notifications-fetch-unread-count)))
(fx/defn handle-chat-update
(rf/defn handle-chat-update
{:events [:chat-updated]}
[_ response do-not-navigate?]
{:dispatch-n [[:sanitize-messages-and-process-response response]
(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"
{:events [:group-chats.ui/remove-member-pressed]}
[_ chat-id member do-not-navigate?]
@ -41,7 +41,7 @@
:js-response true
:on-success #(re-frame/dispatch [:chat-updated % do-not-navigate?])}]})
(fx/defn join-chat
(rf/defn join-chat
{:events [:group-chats.ui/join-pressed]}
[_ chat-id]
{:json-rpc/call [{:method "wakuext_confirmJoiningGroup"
@ -49,7 +49,7 @@
:js-response true
:on-success #(re-frame/dispatch [:chat-updated %])}]})
(fx/defn create
(rf/defn create
{:events [:group-chats.ui/create-pressed]
:interceptors [(re-frame/inject-cofx :random-guid-generator)]}
[{:keys [db] :as cofx} group-name]
@ -59,7 +59,7 @@
:js-response true
: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]}]
(if (get-in cofx [:db :chats chat-id])
{:dispatch [:chat.ui/navigate-to-chat chat-id]}
@ -68,7 +68,7 @@
:js-response true
:on-success #(re-frame/dispatch [:chat-updated %])}]}))
(fx/defn make-admin
(rf/defn make-admin
{:events [:group-chats.ui/make-admin-pressed]}
[_ chat-id member]
{:json-rpc/call [{:method "wakuext_addAdminsToGroupChat"
@ -76,7 +76,7 @@
:js-response true
:on-success #(re-frame/dispatch [:chat-updated %])}]})
(fx/defn add-members
(rf/defn add-members
"Add members to a group chat"
{:events [:group-chats.ui/add-members-pressed]}
[{{:keys [current-chat-id selected-participants]} :db :as cofx}]
@ -85,7 +85,7 @@
:js-response true
: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"
{:events [:group-chats.ui/add-members-from-invitation]}
[{{:keys [current-chat-id] :as db} :db :as cofx} id participant]
@ -95,7 +95,7 @@
:js-response true
:on-success #(re-frame/dispatch [:chat-updated %])}]})
(fx/defn leave
(rf/defn leave
"Leave chat"
{:events [:group-chats.ui/leave-chat-confirmed]}
[{:keys [db] :as cofx} chat-id]
@ -104,11 +104,11 @@
:js-response true
:on-success #(re-frame/dispatch [:chat-removed %])}]})
(fx/defn remove
(rf/defn remove
"Remove chat"
{:events [:group-chats.ui/remove-chat-confirmed]}
[cofx chat-id]
(fx/merge cofx
(rf/merge cofx
(models.chat/deactivate-chat chat-id)
(navigation/pop-to-root-tab :chat-stack)))
@ -119,7 +119,7 @@
[name]
(spec/valid? not-blank? name))
(fx/defn name-changed
(rf/defn name-changed
"Save chat from edited profile"
{:events [:group-chats.ui/name-changed]}
[{:keys [db] :as cofx} chat-id new-name]
@ -130,17 +130,17 @@
:js-response true
:on-success #(re-frame/dispatch [:chat-updated %])}]}))
(fx/defn membership-retry
(rf/defn membership-retry
{:events [:group-chats.ui/membership-retry]}
[{{:keys [current-chat-id] :as db} :db}]
{: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]}
[{{:keys [current-chat-id] :as db} :db} 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"
{:events [:send-group-chat-membership-request]}
[{{:keys [current-chat-id chats] :as db} :db :as cofx}]
@ -152,7 +152,7 @@
:js-response true
: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"
{:events [:send-group-chat-membership-rejection]}
[cofx invitation-id]
@ -161,7 +161,7 @@
:js-response true
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]})
(fx/defn handle-invitations
(rf/defn handle-invitations
[{db :db} invitations]
{:db (update db
:group-chat/invitations
@ -179,41 +179,41 @@
:type
(= constants/invitation-state-removed)))
(fx/defn deselect-contact
(rf/defn deselect-contact
{:events [:deselect-contact]}
[{:keys [db]} id]
{:db (update db :group/selected-contacts disj id)})
(fx/defn select-contact
(rf/defn select-contact
{:events [:select-contact]}
[{:keys [db]} id]
{:db (update db :group/selected-contacts conj id)})
(fx/defn deselect-participant
(rf/defn deselect-participant
{:events [:deselect-participant]}
[{:keys [db]} id]
{:db (update db :selected-participants disj id)})
(fx/defn select-participant
(rf/defn select-participant
{:events [:select-participant]}
[{:keys [db]} 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]}
[{db :db}]
{:db (assoc db :selected-participants #{})})
(fx/defn show-group-chat-profile
(rf/defn show-group-chat-profile
{:events [:show-group-chat-profile]}
[{:keys [db] :as cofx} chat-id]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc :new-chat-name (get-in db [:chats chat-id :name]))
(assoc :current-chat-id chat-id))}
(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]}
[{:keys [db]} chat-id]
(let [chat-name (get-in db [:chats chat-id :name])]

View File

@ -5,26 +5,26 @@
[status-im.keycard.common :as common]
[status-im.multiaccounts.recover.core :as multiaccounts.recover]
[status-im.signing.core :as signing.core]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.utils :as utils]
[status-im2.navigation.events :as navigation]
[taoensso.timbre :as log]))
(fx/defn backup-card-pressed
(rf/defn backup-card-pressed
{:events [:keycard-settings.ui/backup-card-pressed]}
[{:keys [db] :as cofx} backup-type]
(log/debug "[keycard] start backup")
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :creating-backup?] backup-type))}
(when (:multiaccount db)
(navigation/change-tab :profile))
(navigation/navigate-to-cofx :seed-phrase nil)))
(fx/defn recovery-card-pressed
(rf/defn recovery-card-pressed
{:events [:keycard-settings.ui/recovery-card-pressed]}
[{:keys [db] :as cofx} show-warning]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
;setting pin-retry-counter is a workaround for the way the PIN view
;decides if it should accept PUK or PIN
@ -44,7 +44,7 @@
:on-cancel #()})
(backup-card-pressed :recovery-card))))
(fx/defn start-keycard-backup
(rf/defn start-keycard-backup
{:events [::start-keycard-backup]}
[{:keys [db] :as cofx}]
{::multiaccounts.recover/import-multiaccount {:passphrase (-> db
@ -54,10 +54,10 @@
:password nil
:success-event ::create-backup-card}})
(fx/defn create-backup-card
(rf/defn create-backup-card
{:events [::create-backup-card]}
[{:keys [db] :as cofx} root-data derived-data]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(update :intro-wizard
assoc

View File

@ -2,67 +2,67 @@
(:require [status-im.i18n.i18n :as i18n]
[status-im.keycard.common :as common]
[status-im.keycard.onboarding :as onboarding]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im2.navigation.events :as navigation]
[taoensso.timbre :as log]
[utils.security.core :as security]))
(fx/defn change-credentials-pressed
(rf/defn change-credentials-pressed
{:events [:keycard-settings.ui/change-credentials-pressed]}
[{:keys [db] :as cofx} changing]
(fx/merge cofx
(rf/merge cofx
{:db
(assoc-in db
[:keycard :pin]
{:enter-step :current
:current []
:puk []
:original []
:confirmation []
:puk-original []
:puk-confirmation []
:status nil
:error-label nil
:on-verified (case changing
:pin :keycard/proceed-to-change-pin
:puk :keycard/proceed-to-change-puk
:pairing :keycard/proceed-to-change-pairing)})}
[:keycard :pin]
{:enter-step :current
:current []
:puk []
:original []
:confirmation []
:puk-original []
:puk-confirmation []
:status nil
:error-label nil
:on-verified (case changing
:pin :keycard/proceed-to-change-pin
:puk :keycard/proceed-to-change-puk
:pairing :keycard/proceed-to-change-pairing)})}
(common/navigate-to-enter-pin-screen)))
(fx/defn proceed-to-change-pin
(rf/defn proceed-to-change-pin
{:events [:keycard/proceed-to-change-pin]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :pin :enter-step] :original)
(assoc-in [:keycard :pin :status] 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]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :pin :enter-step] :puk-original)
(assoc-in [:keycard :pin :status] 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]}
[{:keys [db] :as cofx}]
(navigation/navigate-replace cofx :change-pairing-code nil))
(fx/defn discard-pin-change
(rf/defn discard-pin-change
{:events [::on-cancel]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
(common/clear-pin)
(common/hide-connection-sheet)
(if (get-in db [:keycard :pin :puk-restore?])
(navigation/navigate-to-cofx :multiaccounts nil)
(navigation/set-stack-root :profile-stack [:my-profile :keycard-settings]))))
(fx/defn change-pin
(rf/defn change-pin
{:events [:keycard/change-pin]}
[{:keys [db] :as cofx}]
(let [setup-step (get-in db [:keycard :setup-step])]
@ -81,7 +81,7 @@
(get-in db [:keycard :pin :original]))
current-pin (common/vector->string
(get-in db [:keycard :pin :current]))]
(fx/merge
(rf/merge
cofx
{:db (assoc-in db [:keycard :pin :status] :verifying)
@ -89,7 +89,7 @@
{:new-pin new-pin
:current-pin current-pin}})))}))))
(fx/defn change-puk
(rf/defn change-puk
{:events [:keycard/change-puk]}
[{:keys [db] :as cofx}]
(common/show-connection-sheet
@ -102,13 +102,13 @@
(get-in db [:keycard :pin :puk-original]))
pin (common/vector->string
(get-in db [:keycard :pin :current]))]
(fx/merge
(rf/merge
cofx
{:db (assoc-in db [:keycard :pin :status] :verifying)
:keycard/change-puk {:puk puk
:pin pin}})))}))
(fx/defn change-pairing
(rf/defn change-pairing
{:events [:keycard/change-pairing]}
[{:keys [db] :as cofx}]
(common/show-connection-sheet
@ -120,32 +120,32 @@
(let [pairing (get-in db [:keycard :pin :pairing-code])
pin (common/vector->string
(get-in db [:keycard :pin :current]))]
(fx/merge
(rf/merge
cofx
{:db (assoc-in db [:keycard :pin :status] :verifying)
:keycard/change-pairing {:pairing pairing
:pin pin}})))}))
(fx/defn change-pairing-code
(rf/defn change-pairing-code
{:events [:keycard/change-pairing-code]}
[{:keys [db] :as cofx} pairing]
(fx/merge
(rf/merge
cofx
{:db (assoc-in db [:keycard :pin :pairing-code] (security/unmask pairing))}
(change-pairing)))
(fx/defn on-change-pin-success
(rf/defn on-change-pin-success
{:events [:keycard.callback/on-change-pin-success]}
[{:keys [db] :as cofx}]
(let [pin (get-in db [:keycard :pin :original])
puk-restore? (get-in db [:keycard :pin :puk-restore?])]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db
[:keycard :pin]
{:status nil
:login pin
:confirmation []
:error-label nil})
[:keycard :pin]
{:status nil
:login pin
:confirmation []
:error-label nil})
:utils/show-popup {:title ""
:content (i18n/label :t/pin-changed)}}
(common/hide-connection-sheet)
@ -155,49 +155,49 @@
(when (:multiaccounts/login db)
(common/get-keys-from-keycard)))))
(fx/defn on-change-puk-success
(rf/defn on-change-puk-success
{:events [:keycard.callback/on-change-puk-success]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db
[:keycard :pin]
{:status nil
:puk-original []
:puk-confirmation []
:error-label nil})
[:keycard :pin]
{:status nil
:puk-original []
:puk-confirmation []
:error-label nil})
:utils/show-popup {:title ""
:content (i18n/label :t/puk-changed)}}
(common/hide-connection-sheet)
(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]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db
[:keycard :pin]
{:status nil
:pairing-code nil
:error-label nil})
[:keycard :pin]
{:status nil
:pairing-code nil
:error-label nil})
:utils/show-popup {:title ""
:content (i18n/label :t/pairing-changed)}}
(common/hide-connection-sheet)
(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]}
[{:keys [db] :as cofx} error]
(log/debug "[keycard] change pin error" error)
(let [tag-was-lost? (common/tag-lost? (:error error))
pin-retries (common/pin-retries (:error error))]
(fx/merge
(rf/merge
cofx
(if tag-was-lost?
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :pin :status] nil)}
(common/set-on-card-connected :keycard/change-pin))
(if-not (nil? pin-retries)
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :application-info :pin-retry-counter] pin-retries)
(update-in [:keycard :pin]

View File

@ -8,7 +8,7 @@
[status-im.popover.core :as popover]
[status-im.ui.screens.keycard.keycard-interaction :as keycard-sheet]
[status-im.utils.datetime :as utils.datetime]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.keychain.core :as keychain]
[status-im.utils.platform :as platform]
[status-im.utils.types :as types]
@ -24,7 +24,7 @@
(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]
{:dispatch [event]})
@ -97,24 +97,24 @@
(fn [supported?]
(nfc/set-nfc-supported? supported?)))
(fx/defn listen-to-hardware-back-button
(rf/defn listen-to-hardware-back-button
[{:keys [db]}]
(when-not (get-in db [:keycard :back-button-listener])
{: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]}]
(when-let [listener (get-in db [:keycard :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]
(log/debug "[keycard] set-on-card-connected" on-connect)
{:db (-> db
(assoc-in [:keycard :on-card-connected] on-connect)
(assoc-in [:keycard :last-on-card-connected] nil))})
(fx/defn stash-on-card-connected
(rf/defn stash-on-card-connected
[{:keys [db]}]
(let [on-connect (get-in db [:keycard :on-card-connected])]
(log/debug "[keycard] stash-on-card-connected" on-connect)
@ -122,7 +122,7 @@
(assoc-in [:keycard :last-on-card-connected] on-connect)
(assoc-in [:keycard :on-card-connected] nil))}))
(fx/defn restore-on-card-connected
(rf/defn restore-on-card-connected
[{:keys [db]}]
(let [on-connect (or
(get-in db [:keycard :on-card-connected])
@ -132,21 +132,21 @@
(assoc-in [:keycard :on-card-connected] on-connect)
(assoc-in [:keycard :last-on-card-connect] nil))}))
(fx/defn clear-on-card-connected
(rf/defn clear-on-card-connected
[{:keys [db]}]
(log/debug "[keycard] clear-on-card-connected")
{:db (-> db
(assoc-in [:keycard :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]
(log/debug "[keycard] set-on-card-read" on-connect)
{:db (-> db
(assoc-in [:keycard :on-card-read] on-connect)
(assoc-in [:keycard :last-on-card-read] nil))})
(fx/defn stash-on-card-read
(rf/defn stash-on-card-read
[{:keys [db]}]
(let [on-connect (get-in db [:keycard :on-card-read])]
(log/debug "[keycard] stash-on-card-read" on-connect)
@ -154,7 +154,7 @@
(assoc-in [:keycard :last-on-card-read] on-connect)
(assoc-in [:keycard :on-card-read] nil))}))
(fx/defn restore-on-card-read
(rf/defn restore-on-card-read
[{:keys [db]}]
(let [on-connect (or
(get-in db [:keycard :on-card-read])
@ -164,7 +164,7 @@
(assoc-in [:keycard :on-card-read] on-connect)
(assoc-in [:keycard :last-on-card-connect] nil))}))
(fx/defn clear-on-card-read
(rf/defn clear-on-card-read
[{:keys [db]}]
(log/debug "[keycard] clear-on-card-read")
{:db (-> db
@ -181,7 +181,7 @@
:on-connect ::on-card-connected
: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 [on-cancel]
@ -193,7 +193,7 @@
(log/debug "[keycard] show-sheet-with-connection-check"
"card-connected?"
connected?)
(fx/merge
(rf/merge
cofx
{:dismiss-keyboard true}
(bottom-sheet/show-bottom-sheet
@ -211,7 +211,7 @@
(when connected?
handler))))
(fx/defn show-connection-sheet
(rf/defn show-connection-sheet
[{:keys [db] :as cofx} args]
(let [nfc-running? (get-in db [:keycard :nfc-running?])]
(log/debug "show connection; already running?" nfc-running?)
@ -219,59 +219,59 @@
(show-connection-sheet-component cofx 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]}
[cofx args]
(log/debug "on-nfc-ready-for-sheet")
(show-connection-sheet-component cofx args))
(fx/defn hide-connection-sheet-component
(rf/defn hide-connection-sheet-component
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :card-read-in-progress?] false)}
(restore-on-card-connected)
(restore-on-card-read)
(bottom-sheet/hide-bottom-sheet)))
(fx/defn hide-connection-sheet
(rf/defn hide-connection-sheet
[cofx]
(log/debug "hide-connection-sheet")
{: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]}
[cofx]
(log/debug "on-nfc-ready-to-close-sheet")
(hide-connection-sheet-component cofx))
(fx/defn clear-pin
(rf/defn clear-pin
[{:keys [db] :as cofx}]
(fx/merge
(rf/merge
cofx
{:db (assoc-in db
[:keycard :pin]
{:status nil
:login (get-in db [:keycard :pin :original])
:export-key []
:sign []
:puk []
:current []
:original []
:confirmation []
:error-label nil
:on-verified (get-in db [:keycard :pin :on-verified])
:on-verified-failure (get-in db [:keycard :pin :on-verified])})}))
[:keycard :pin]
{:status nil
:login (get-in db [:keycard :pin :original])
:export-key []
:sign []
:puk []
:current []
:original []
:confirmation []
:error-label nil
:on-verified (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
:keycard/back-button-pressed]}
[{:keys [db] :as cofx}]
(when-not (get-in db [:keycard :card-connected?])
(fx/merge cofx
(rf/merge cofx
(hide-connection-sheet)
(clear-pin))))
(fx/defn cancel-sheet
(rf/defn cancel-sheet
{:events [::cancel-sheet]}
[_]
{:ui/show-confirmation {:title (i18n/label :t/keycard-cancel-setup-title)
@ -281,7 +281,7 @@
:on-accept #(re-frame/dispatch [::cancel-sheet-confirm])
: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.
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
@ -290,24 +290,24 @@
[{:keys [db]} 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")
{:utils/show-popup {:title (i18n/label :t/wrong-card)
:content (i18n/label :t/wrong-card-text)}})
(fx/defn unauthorized-operation
(rf/defn unauthorized-operation
[cofx]
(fx/merge cofx
(rf/merge cofx
{:utils/show-popup {:title ""
:content (i18n/label :t/keycard-unauthorized-operation)}}
(clear-on-card-connected)
(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]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :pin :current] [])}
(navigation/navigate-to-cofx :enter-pin-settings nil)))
@ -318,12 +318,12 @@
(= error "Tag was lost.")
(= error "NFCError:100")))
(fx/defn process-error
(rf/defn process-error
[{:keys [db]} code error]
(when-not (tag-lost-exception? code error)
{:db (assoc-in db [:keycard :setup-step] :error)}))
(fx/defn get-keys-from-keycard
(rf/defn get-keys-from-keycard
[{:keys [db]}]
(let [key-uid (get-in db [:multiaccounts/login :key-uid])
pin (string/join (get-in db [:keycard :pin :login]))]
@ -334,7 +334,7 @@
{:db (assoc-in db [:keycard :pin :status] :verifying)
:keycard/get-keys {:pin pin}})))
(fx/defn on-get-keys-success
(rf/defn on-get-keys-success
{:events [:keycard.callback/on-get-keys-success]}
[{:keys [db] :as cofx} data]
(let [{:keys [key-uid encryption-public-key whisper-private-key]
@ -346,7 +346,7 @@
:key-uid key-uid
:identicon identicon})
save-keys? (get-in db [:multiaccounts/login :save-password?])]
(fx/merge cofx
(rf/merge cofx
{:db
(-> db
(assoc-in [:keycard :pin :status] nil)
@ -374,9 +374,9 @@
(clear-on-card-read)
(hide-connection-sheet))))
(fx/defn blocked-or-frozen-keycard-popup
(rf/defn blocked-or-frozen-keycard-popup
[{:keys [db] :as cofx} card-status]
(fx/merge
(rf/merge
cofx
{:db (assoc-in db [:keycard :pin :status] card-status)}
(hide-connection-sheet)
@ -385,15 +385,15 @@
(when-not (or (:multiaccounts/login db) (:popover/popover db))
(popover/show-popover {:view card-status}))))
(fx/defn blocked-keycard-popup
(rf/defn blocked-keycard-popup
[cofx]
(blocked-or-frozen-keycard-popup cofx :blocked-card))
(fx/defn frozen-keycard-popup
(rf/defn frozen-keycard-popup
[cofx]
(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]}
[{:keys [db] :as cofx} error]
(log/debug "[keycard] get keys error: " error)
@ -404,7 +404,7 @@
(if tag-was-lost?
{:db (assoc-in db [:keycard :pin :status] nil)}
(if-not (nil? pin-retries-count)
(fx/merge
(rf/merge
cofx
{:db (-> db
(assoc-in [:keycard :application-info :pin-retry-counter] pin-retries-count)
@ -418,7 +418,7 @@
(when (zero? pin-retries-count) (frozen-keycard-popup)))
(show-wrong-keycard-alert)))))
(fx/defn factory-reset
(rf/defn factory-reset
{:events [:keycard/factory-reset]}
[{:keys [db]} on-card-read]
(log/debug "[keycard] factory-reset")
@ -427,7 +427,7 @@
;; Get application info
(fx/defn update-pairings
(rf/defn update-pairings
[{:keys [db]} instance-uid pairing]
(let [paired-on (utils.datetime/timestamp)
pairings (-> (get-in db [:keycard :pairings])
@ -435,13 +435,13 @@
{:keycard/persist-pairings pairings
:db (assoc-in db [:keycard :pairings] pairings)}))
(fx/defn get-application-info
(rf/defn get-application-info
{:events [:keycard/get-application-info]}
[{:keys [db]} on-card-read]
(log/debug "[keycard] get-application-info")
{: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]}
[{:keys [db] :as cofx} info on-success]
(let [{:keys [pin-retry-counter puk-retry-counter instance-uid new-pairing]} info
@ -456,7 +456,7 @@
"on-success" on-success'
"pin-retry-counter" pin-retry-counter
"puk-retry-counter" puk-retry-counter)
(fx/merge
(rf/merge
cofx
{:db (-> db
(assoc-in [:keycard :pin :enter-step] enter-step)
@ -476,7 +476,7 @@
(when 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]}
[{:keys [db] :as cofx} error]
(let [on-card-read (get-in db [:keycard :on-card-read])
@ -490,10 +490,10 @@
last-on-card-connected)
(when-not tag-was-lost?
(if login?
(fx/merge cofx
(rf/merge cofx
(clear-on-card-read)
(navigation/navigate-to-cofx :not-keycard nil))
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :application-info-error] error)}
(when (contains?
@ -504,7 +504,7 @@
(when on-card-read
(dispatch-event on-card-read)))))))
(fx/defn on-card-connected
(rf/defn on-card-connected
{:events [::on-card-connected]}
[{:keys [db] :as cofx} _]
(let [instance-uid (get-in db [:keycard :application-info :instance-uid])
@ -517,7 +517,7 @@
(log/debug "[keycard] on-card-connected" on-card-connected
"on-card-read" on-card-read)
(when on-card-connected
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :card-read-in-progress?] (boolean on-card-read)))}
(when on-card-connected
@ -527,11 +527,11 @@
(nil? on-card-connected))
(get-application-info on-card-read))))))
(fx/defn on-card-disconnected
(rf/defn on-card-disconnected
{:events [::on-card-disconnected]}
[{:keys [db] :as cofx} _]
(log/debug "[keycard] card disconnected")
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :card-read-in-progress?] false))}
(restore-on-card-connected)
@ -541,7 +541,7 @@
[db]
(boolean (get-in db [:multiaccount :keycard-pairing])))
(fx/defn verify-pin
(rf/defn verify-pin
{:events [:keycard/verify-pin]}
[{:keys [db] :as cofx} {:keys [pin-step on-card-connected on-failure on-success]}]
(let [on-success (or on-success
@ -550,7 +550,7 @@
(get-in db [:keycard :pin :on-verified-failure]))
pin-step (or pin-step
(get-in db [:keycard :pin :step]))]
(fx/merge
(rf/merge
cofx
{:db (update-in db
[:keycard :pin]
@ -563,12 +563,12 @@
:handler
(fn [{:keys [db] :as cofx}]
(let [pin (vector->string (get-in db [:keycard :pin pin-step]))]
(fx/merge
(rf/merge
cofx
{:db (assoc-in db [:keycard :pin :status] :verifying)
:keycard/verify-pin {:pin pin}})))}))))
(fx/defn navigete-to-keycard-settings
(rf/defn navigete-to-keycard-settings
{:events [::navigate-to-keycard-settings]}
[cofx]
(navigation/set-stack-root :profile-stack [:my-profile :keycard-settings]))

View File

@ -17,13 +17,13 @@
[status-im.multiaccounts.recover.core :as multiaccounts.recover]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.utils.datetime :as utils.datetime]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im2.navigation.events :as navigation]
[taoensso.timbre :as log]))
(fx/defn show-keycard-has-multiaccount-alert
(rf/defn show-keycard-has-multiaccount-alert
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :setup-step] nil)
:utils/show-confirmation {:title nil
:content (i18n/label
@ -31,9 +31,9 @@
:cancel-button-text ""
:confirm-button-text :t/okay}}))
(fx/defn load-pin-screen
(rf/defn load-pin-screen
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :setup-step] :pin)
(assoc-in [:keycard :pin]
@ -42,9 +42,9 @@
:confirmation []}))}
(navigation/navigate-to-cofx :keycard-onboarding-pin nil)))
(fx/defn load-recovery-pin-screen
(rf/defn load-recovery-pin-screen
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :pin]
{:enter-step :import-multiaccount
@ -53,14 +53,14 @@
(common/listen-to-hardware-back-button)
(navigation/navigate-replace :keycard-recovery-pin nil)))
(fx/defn load-pairing
(rf/defn load-pairing
[{:keys [db]}]
(let [instance-uid (get-in db [:keycard :application-info :instance-uid])
pairing-data (or (get-in db [:keycard :pairings (keyword instance-uid)])
(get-in db [:keycard :pairings instance-uid]))]
{: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?]
(log/debug "[keycard] proceed-setup-with-initialized-card"
"instance-uid"
@ -68,7 +68,7 @@
(if (= flow :import)
(navigation/navigate-to-cofx cofx :keycard-recovery-no-key nil)
(if paired?
(fx/merge cofx
(rf/merge cofx
(common/listen-to-hardware-back-button)
(when (= flow :create)
(mnemonic/set-mnemonic))
@ -78,25 +78,25 @@
(onboarding/load-pairing-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]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :pin :on-verified] nil)
(assoc-in [:keycard :setup-step] nil))}
(common/clear-on-card-connected)
(navigation/navigate-to-cofx :keycard-settings nil)))
(fx/defn password-option-pressed
(rf/defn password-option-pressed
{:eevents [:keycard.ui/password-option-pressed]}
[{:keys [db]}]
(when (= (get-in db [:keycard :flow]) :create)
#())) ;;TODO with v1 flow
(fx/defn settings-screen-did-load
(rf/defn settings-screen-did-load
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :pin :on-verified] nil)
(assoc-in [:keycard :setup-step] nil))}
@ -126,13 +126,13 @@
[{:keys [db]}]
{: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]}
[_ supported?]
{:keycard/set-nfc-supported supported?})
;; 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]}
[{:keys [db]} nfc-enabled?]
(log/debug "[keycard] check-nfc-enabled-success"
@ -158,11 +158,11 @@
[fx]
(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]}
[{:keys [db] :as cofx}]
(let [reset-pin (get-in db [:keycard :pin :reset])]
(fx/merge cofx
(rf/merge cofx
{:db
(-> db
(update-in [:keycard :application-info]
@ -182,14 +182,14 @@
(common/clear-on-card-connected)
(common/clear-on-card-read))))
(fx/defn on-unblock-pin-error
(rf/defn on-unblock-pin-error
{:events [:keycard.callback/on-unblock-pin-error]}
[{:keys [db] :as cofx} error]
(let [tag-was-lost? (common/tag-lost? (:error error))
puk-retries (common/pin-retries (:error error))]
(log/debug "[keycard] unblock pin error" error)
(when-not tag-was-lost?
(fx/merge cofx
(rf/merge cofx
{:db
(-> db
(assoc-in [:keycard :application-info :puk-retry-counter] puk-retries)
@ -202,7 +202,7 @@
(common/hide-connection-sheet)))))
(fx/defn clear-on-verify-handlers
(rf/defn clear-on-verify-handlers
[{:keys [db]}]
{:db (update-in db
[:keycard :pin]
@ -210,12 +210,12 @@
:on-verified-failure
:on-verified)})
(fx/defn on-verify-pin-success
(rf/defn on-verify-pin-success
{:events [:keycard.callback/on-verify-pin-success]}
[{:keys [db] :as cofx}]
(let [on-verified (get-in db [:keycard :pin :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
@ -243,7 +243,7 @@
(common/dispatch-event on-verified))
(clear-on-verify-handlers))))
(fx/defn on-verify-pin-error
(rf/defn on-verify-pin-error
{:events [:keycard.callback/on-verify-pin-error]}
[{:keys [db] :as cofx} error]
(let [tag-was-lost? (common/tag-lost? (:error error))
@ -254,7 +254,7 @@
(log/debug "[keycard] verify pin error" error)
(when-not tag-was-lost?
(if-not (nil? pin-retries)
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :application-info :pin-retry-counter] pin-retries)
(update-in [:keycard :pin]
@ -281,12 +281,12 @@
:ms 200}]}))
#_(clear-on-verify-handlers))
(fx/merge cofx
(rf/merge cofx
(common/hide-connection-sheet)
(common/show-wrong-keycard-alert)
(clear-on-verify-handlers))))))
(fx/defn unblock-pin
(rf/defn unblock-pin
{:events [:keycard/unblock-pin]}
[cofx]
(common/show-connection-sheet
@ -305,14 +305,14 @@
(def pin-code-length 6)
(def puk-code-length 12)
(fx/defn handle-pin-input
(rf/defn handle-pin-input
[{:keys [db]} enter-step]
(let [numbers-entered (count (get-in db [:keycard :pin enter-step]))]
(when (or (= numbers-entered pin-code-length)
(= numbers-entered puk-code-length))
{:dispatch [:keycard/process-pin-input]})))
(fx/defn update-pin
(rf/defn update-pin
{:events [:keycard.ui/pin-numpad-button-pressed]}
[{:keys [db] :as cofx} number enter-step]
(log/debug "update-pin" enter-step)
@ -322,7 +322,7 @@
(= enter-step :puk-confirmation))
(< numbers-entered puk-code-length)
(< numbers-entered pin-code-length))]
(fx/merge cofx
(rf/merge cofx
{:db (cond-> (-> db
(assoc-in [:keycard :pin :enter-step] enter-step)
(assoc-in [:keycard :pin :status] nil))
@ -369,7 +369,7 @@
; current - current PIN to perform actions which require PIN auth
; original - new PIN when user changes it or creates new one
; confirmation - confirmation for new PIN
(fx/defn process-pin-input
(rf/defn process-pin-input
{:events [:keycard/process-pin-input]}
[{:keys [db]}]
(let [enter-step (get-in db [:keycard :pin :enter-step])
@ -453,9 +453,9 @@
(get-in db [:keycard :pin :reset-confirmation])))
(pin-reset-error :t/pin-mismatch))))
(fx/defn set-multiaccount-pairing
(rf/defn set-multiaccount-pairing
[cofx _ pairing paired-on]
(fx/merge cofx
(rf/merge cofx
(multiaccounts.update/multiaccount-update
:keycard-pairing
pairing
@ -465,7 +465,7 @@
paired-on
{})))
(fx/defn on-retrieve-pairings-success
(rf/defn on-retrieve-pairings-success
{:events [:keycard.callback/on-retrieve-pairings-success]}
[{:keys [db]} pairings]
(card/set-pairings pairings)
@ -478,7 +478,7 @@
;; with setup and skip the pairing step if the pairing was already done during a previous
;; unfinished setup.
(fx/defn on-pair-success
(rf/defn on-pair-success
{:events [:keycard.callback/on-pair-success]}
[{:keys [db] :as cofx} pairing]
(let [setup-step (get-in db [:keycard :setup-step])
@ -492,7 +492,7 @@
next-step (if (= setup-step :pair)
:begin
:card-ready)]
(fx/merge cofx
(rf/merge cofx
{:keycard/persist-pairings pairings
:db (-> db
(assoc-in [:keycard :pairings] pairings)
@ -515,7 +515,7 @@
(when (= flow :create)
(mnemonic/set-mnemonic)))))
(fx/defn on-pair-error
(rf/defn on-pair-error
{:events [:keycard.callback/on-pair-error]}
[{:keys [db] :as cofx} {:keys [error code]}]
(log/debug "[keycard] pair error: " error)
@ -524,7 +524,7 @@
flow (get-in db [:keycard :flow])]
(log/debug "[keycard] on-pair-error" setup-step "flow:" flow)
(when-not tag-was-lost?
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :setup-error] (i18n/label :t/invalid-pairing-password))}
(common/set-on-card-connected (if (= setup-step :pairing)
:keycard/load-pairing-screen
@ -535,18 +535,18 @@
(when (not= setup-step :enter-pair-code)
(common/process-error code error))))))
(fx/defn set-setup-step
(rf/defn set-setup-step
[{:keys [db]} card-state]
{:db (assoc-in db
[:keycard :setup-step]
(case card-state
:not-paired :pair
:no-pairing-slots :no-slots
:init :card-ready
:multiaccount :import-multiaccount
:begin))})
[:keycard :setup-step]
(case card-state
:not-paired :pair
:no-pairing-slots :no-slots
:init :card-ready
:multiaccount :import-multiaccount
: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)
:content (i18n/label :t/keycard-applet-install-instructions)
@ -555,7 +555,7 @@
;; 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.
(fx/defn check-card-state
(rf/defn check-card-state
{:events [:keycard/check-card-state]}
[{:keys [db] :as cofx}]
(let [app-info (get-in db [:keycard :application-info])
@ -565,7 +565,7 @@
(log/debug "[keycard] check-card-state"
"card-state" card-state
"flow" flow)
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :card-state] card-state)}
(set-setup-step card-state)
@ -581,7 +581,7 @@
(if (= flow :import)
(navigation/navigate-to-cofx :keycard-recovery-no-key nil)
(fn [cofx]
(fx/merge
(rf/merge
cofx
(common/clear-on-card-read)
(load-pin-screen)))))
@ -603,25 +603,25 @@
(#{:create :recovery} flow))
(show-keycard-has-multiaccount-alert)))))
(fx/defn on-card-connected
(rf/defn on-card-connected
{:events [:keycard.callback/on-card-connected]}
[{:keys [db]} _]
(log/debug "[keycard] card globally connected")
{:db (assoc-in db [:keycard :card-connected?] true)})
(fx/defn on-card-disconnected
(rf/defn on-card-disconnected
{:events [:keycard.callback/on-card-disconnected]}
[{:keys [db]} _]
(log/debug "[keycard] card disconnected")
{: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]}
[{:keys [db]} _]
(log/debug "[keycard] nfc user cancelled")
{:dispatch [:signing.ui/cancel-is-pressed]})
(fx/defn on-nfc-timeout
(rf/defn on-nfc-timeout
{:events [:keycard.callback/on-nfc-timeout]}
[{:keys [db]} _]
(log/debug "[keycard] nfc timeout")
@ -630,45 +630,45 @@
(assoc-in [:keycard :card-connected?] false))
: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]}
[{:keys [db]} 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]}
[{:keys [db]}]
{: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]}
[{:keys [db]} step]
(when-not (empty? (get-in db [:keycard :pin step]))
{:db (update-in db [:keycard :pin step] pop)}))
(fx/defn start-nfc
(rf/defn start-nfc
{:events [:keycard.ui/start-nfc]}
[cofx]
{:keycard/start-nfc nil})
(fx/defn stop-nfc
(rf/defn stop-nfc
{:events [:keycard.ui/stop-nfc]}
[cofx]
{:keycard/stop-nfc nil
:keycard.callback/on-card-disconnected nil})
(fx/defn start-nfc-success
(rf/defn start-nfc-success
{:events [:keycard.callback/start-nfc-success]}
[{:keys [db]} _]
(log/debug "[keycard] nfc started success")
{:db (assoc-in db [:keycard :nfc-running?] true)})
(fx/defn start-nfc-failure
(rf/defn start-nfc-failure
{:events [:keycard.callback/start-nfc-failure]}
[{:keys [db]} _]
(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]}
[{:keys [db]} _]
(log/debug "[keycard] nfc stopped success")
@ -677,7 +677,7 @@
(assoc-in [:keycard :nfc-running?] false)
(assoc-in [:keycard :card-connected?] false))})
(fx/defn stop-nfc-failure
(rf/defn stop-nfc-failure
{:events [:keycard.callback/stop-nfc-failure]}
[{:keys [db]} _]
(log/debug "[keycard] nfc failed stopping")) ;; leave current value on :nfc-running

View File

@ -1,14 +1,14 @@
(ns status-im.keycard.delete-key
(:require [status-im.keycard.common :as common]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im2.navigation.events :as navigation]))
(fx/defn reset-card-pressed
(rf/defn reset-card-pressed
{:events [:keycard-settings.ui/reset-card-pressed]}
[cofx]
(navigation/navigate-to-cofx cofx :reset-card nil))
(fx/defn delete-card
(rf/defn delete-card
[{:keys [db] :as cofx}]
(let [key-uid (get-in db [:keycard :application-info :key-uid])
multiaccount-key-uid (get-in db [:multiaccount :key-uid])]
@ -17,30 +17,30 @@
{:keycard/delete nil}
(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]}
[cofx]
(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]}
[{:keys [db]}]
{:db (assoc-in db [:keycard :reset-card :disabled?] true)
: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]}
[{:keys [db] :as cofx} keep-keys-on-keycard?]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db
[:keycard :pin]
{:enter-step :current
:current []
:puk []
:status nil
:error-label nil
:on-verified (if keep-keys-on-keycard?
:keycard/unpair-and-delete
:keycard/remove-key-with-unpair)})}
[:keycard :pin]
{:enter-step :current
:current []
:puk []
:status nil
:error-label nil
:on-verified (if keep-keys-on-keycard?
:keycard/unpair-and-delete
:keycard/remove-key-with-unpair)})}
(common/set-on-card-connected :keycard/navigate-to-enter-pin-screen)
(common/navigate-to-enter-pin-screen)))

View File

@ -1,10 +1,10 @@
(ns status-im.keycard.export-key
(:require [status-im.keycard.common :as common]
[status-im.keycard.wallet :as wallet]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[taoensso.timbre :as log]))
(fx/defn on-export-key-error
(rf/defn on-export-key-error
{:events [:keycard.callback/on-export-key-error]}
[{:keys [db] :as cofx} error]
(log/debug "[keycard] export key error" error)
@ -12,12 +12,12 @@
pin-retries (common/pin-retries (:error error))]
(cond
tag-was-lost?
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :pin :status] nil)}
(common/set-on-card-connected :wallet.accounts/generate-new-keycard-account))
(not (nil? pin-retries))
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :application-info :pin-retry-counter] pin-retries)
(update-in [:keycard :pin]
@ -34,16 +34,16 @@
(common/hide-connection-sheet)
(when (zero? pin-retries) (common/frozen-keycard-popup)))
:else
(fx/merge cofx
(rf/merge cofx
(common/show-wrong-keycard-alert)
(common/clear-pin)
(common/hide-connection-sheet)))))
(fx/defn on-export-key-success
(rf/defn on-export-key-success
{:events [:keycard.callback/on-export-key-success]}
[{:keys [db] :as cofx} pubkey]
(let [callback-fn (get-in db [:keycard :on-export-success])]
(fx/merge cofx
(rf/merge cofx
{:dispatch (callback-fn pubkey)}
(wallet/hide-pin-sheet)
(common/clear-pin)

View File

@ -6,54 +6,54 @@
[status-im.keycard.onboarding :as onboarding]
[status-im.keycard.recovery :as recovery]
[status-im.signing.core :as signing.core]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.types :as types]
[status-im2.navigation.events :as navigation]
[taoensso.timbre :as log]))
(fx/defn login-got-it-pressed
(rf/defn login-got-it-pressed
{:events [:keycard.login.pin.ui/got-it-pressed
:keycard.login.pin.ui/cancel-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db db}
(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]}
[cofx]
(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]}
[cofx]
(fx/merge cofx
(rf/merge cofx
(bottom-sheet/hide-bottom-sheet)
(onboarding/start-onboarding-flow)))
(fx/defn login-add-key-pressed
(rf/defn login-add-key-pressed
{:events [:keycard.login.ui/add-key-pressed]}
[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]}
[{:keys [db] :as cofx} value]
(fx/merge cofx
(rf/merge cofx
{: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]}
[{:keys [db] :as cofx}]
(log/debug "[keycard] load-pair-card-pressed")
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :flow] :login)}
(navigation/navigate-to-cofx :keycard-recovery-pair nil)))
(fx/defn reset-pin
(rf/defn reset-pin
{:events [::reset-pin]}
[{:keys [db] :as cofx}]
(fx/merge
(rf/merge
cofx
(signing.core/discard)
(fn [{:keys [db]}]
@ -76,7 +76,7 @@
(navigation/navigate-replace :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]}
[{:keys [db]}]
{:db (-> db
@ -84,7 +84,7 @@
(update :keycard dissoc :setup-step))
:hide-popover nil})
(fx/defn login-with-keycard
(rf/defn login-with-keycard
{:events [:keycard/login-with-keycard]}
[{:keys [db] :as cofx}]
(let [{:keys [:pin-retry-counter :puk-retry-counter]
@ -105,22 +105,22 @@
"no pairing" paired?)
(cond
(empty? application-info)
(fx/merge cofx
(rf/merge cofx
(common/hide-connection-sheet)
(navigation/navigate-to-cofx :not-keycard nil))
(empty? key-uid)
(fx/merge cofx
(rf/merge cofx
(common/hide-connection-sheet)
(navigation/navigate-to-cofx :keycard-blank nil))
multiaccount-mismatch?
(fx/merge cofx
(rf/merge cofx
(common/hide-connection-sheet)
(navigation/navigate-to-cofx :keycard-wrong nil))
(not paired?)
(fx/merge cofx
(rf/merge cofx
(common/hide-connection-sheet)
(navigation/navigate-to-cofx :keycard-unpaired nil))
@ -132,7 +132,7 @@
:else
(common/get-keys-from-keycard cofx))))
(fx/defn proceed-to-login
(rf/defn proceed-to-login
{:events [::login-after-reset]}
[cofx]
(log/debug "[keycard] proceed-to-login")
@ -143,7 +143,7 @@
:on-card-read :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]}
[{:keys [db] :as cofx} key-uid [encryption-public-key whisper-private-key :as creds]]
(if (nil? creds)
@ -177,7 +177,7 @@
:password encryption-public-key
:chat-key whisper-private-key}})))
(fx/defn on-login-success
(rf/defn on-login-success
{:events [:keycard.login.callback/login-success]}
[_ result]
(log/debug "loginWithKeycard success: " result))

View File

@ -1,11 +1,11 @@
(ns status-im.keycard.mnemonic
(:require [status-im.keycard.common :as common]
status-im.keycard.fx
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im2.navigation.events :as navigation]
[taoensso.timbre :as log]))
(fx/defn set-mnemonic
(rf/defn set-mnemonic
[{:keys [db] :as cofx}]
(log/debug "[keycard] set-mnemonic")
(let [selected-id (get-in db [:intro-wizard :selected-id])
@ -15,7 +15,7 @@
(reduced mnemonic)))
nil
(get-in db [:intro-wizard :multiaccounts]))]
(fx/merge
(rf/merge
cofx
{:db (-> db
(assoc-in [:keycard :setup-step] :recovery-phrase)
@ -24,11 +24,11 @@
(common/hide-connection-sheet)
(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
:keycard/load-loading-keys-screen]}
[{:keys [db] :as cofx}]
(fx/merge
(rf/merge
cofx
{:db (assoc-in db [:keycard :setup-step] :loading-keys)}
(common/show-connection-sheet

View File

@ -7,12 +7,12 @@
status-im.keycard.fx
[status-im.keycard.mnemonic :as mnemonic]
[status-im.ui.components.react :as react]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.utils :as utils]
[status-im2.navigation.events :as navigation]
[taoensso.timbre :as log]))
(fx/defn begin-setup-button-pressed
(rf/defn begin-setup-button-pressed
{:keys [:keycard.ui/begin-setup-button-pressed]}
[{:keys [db]}]
{:db (-> db
@ -21,7 +21,7 @@
(assoc-in [:keycard :pin :original] [])
(assoc-in [:keycard :pin :confirmation] []))})
(fx/defn start-installation
(rf/defn start-installation
[{:keys [db] :as cofx}]
(let [card-state (get-in db [:keycard :card-state])
pin (common/vector->string (get-in db [:keycard :pin :original]))]
@ -33,12 +33,12 @@
(do
(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)
:content (i18n/label :t/something-went-wrong)}}
(navigation/navigate-to-cofx :keycard-authentication-method nil))))))
(fx/defn load-preparing-screen
(rf/defn load-preparing-screen
{:events [:keycard/load-preparing-screen]}
[cofx]
(common/show-connection-sheet
@ -47,11 +47,11 @@
:on-card-connected :keycard/load-preparing-screen
:handler start-installation}))
(fx/defn load-pairing-screen
(rf/defn load-pairing-screen
{:events [:keycard/load-pairing-screen
:keycard.onboarding.puk-code.ui/confirm-pressed]}
[{:keys [db] :as cofx}]
(fx/merge
(rf/merge
cofx
{:db (assoc-in db [:keycard :setup-step] :pairing)}
(common/show-connection-sheet
@ -59,7 +59,7 @@
:on-card-connected :keycard/load-pairing-screen
: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]}
[_]
{:ui/show-confirmation {:title (i18n/label :t/secret-keys-confirmation-title)
@ -70,11 +70,11 @@
[:keycard.onboarding.puk-code.ui/confirm-pressed])
:on-cancel #()}})
(fx/defn load-finishing-screen
(rf/defn load-finishing-screen
{:events [:keycard.onboarding.recovery-phrase-confirm-word2.ui/next-pressed
:keycard/load-finishing-screen]}
[{:keys [db] :as cofx}]
(fx/merge
(rf/merge
cofx
{:db (assoc-in db [:keycard :setup-step] :loading-keys)}
(common/show-connection-sheet
@ -82,12 +82,12 @@
:on-card-connected :keycard/load-finishing-screen
: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]}
[_]
(.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
:keycard.ui/recovery-phrase-next-button-pressed]}
[_]
@ -99,13 +99,13 @@
[:keycard.onboarding.recovery-phrase.ui/confirm-pressed])
:on-cancel #()}})
(fx/defn recovery-phrase-start-confirmation
(rf/defn recovery-phrase-start-confirmation
[{:keys [db] :as cofx}]
(let [mnemonic (get-in db [:keycard :secrets :mnemonic])
[word1 word2] (shuffle (map-indexed vector (clojure.string/split mnemonic #" ")))
word1 (zipmap [:idx :word] word1)
word2 (zipmap [:idx :word] word2)]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :setup-step] :recovery-phrase-confirm-word1)
(assoc-in [:keycard :recovery-phrase :step] :word1)
@ -115,14 +115,14 @@
(assoc-in [:keycard :recovery-phrase :word2] word2))}
(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]}
[cofx]
(fx/merge cofx
(rf/merge cofx
(recovery-phrase-start-confirmation)
(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]}]
{:db (-> db
(assoc-in [:keycard :recovery-phrase :step] :word2)
@ -130,13 +130,13 @@
(assoc-in [:keycard :recovery-phrase :input-word] nil)
(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}]
(let [pin (get-in db
[:keycard :secrets :pin]
(common/vector->string (get-in db [:keycard :pin :current])))]
(if (empty? pin)
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :pin]
{:enter-step :current
@ -146,7 +146,7 @@
(navigation/navigate-to-cofx :keycard-onboarding-pin nil))
(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
:keycard.onboarding.recovery-phrase-confirm-word.ui/input-submitted]}
[{:keys [db] :as cofx}]
@ -155,27 +155,27 @@
{:keys [word]} (get-in db [:keycard :recovery-phrase step])]
(if (= word input-word)
(if (= (:view-id db) :keycard-onboarding-recovery-phrase-confirm-word1)
(fx/merge cofx
(rf/merge cofx
(recovery-phrase-next-word)
(navigation/navigate-replace :keycard-onboarding-recovery-phrase-confirm-word2 nil))
(proceed-with-generating-key cofx))
{: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]}
[{:keys [db]} 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]}
[{:keys [db]} 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]}
[{:keys [db] :as cofx}]
(let [flow (get-in db [:keycard :flow])]
(fx/merge cofx
(rf/merge cofx
{:keycard/check-nfc-enabled nil}
(if (= flow :import)
(navigation/navigate-to-cofx :keycard-recovery-intro nil)
@ -183,16 +183,16 @@
(common/listen-to-hardware-back-button)
(navigation/navigate-to-cofx :keycard-onboarding-intro nil))))))
(fx/defn start-onboarding-flow
(rf/defn start-onboarding-flow
{:events [:keycard/start-onboarding-flow]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :flow] :create)
:keycard/check-nfc-enabled nil}
(common/listen-to-hardware-back-button)
(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]}
[_]
{:keycard/open-nfc-settings nil})
@ -208,7 +208,7 @@
: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]}
[{:keys [db]}]
(let [step (get-in db [:keycard :recovery-phrase :step])
@ -220,21 +220,21 @@
(show-recover-confirmation))
{: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}]
(if (= (get-in db [:keycard :flow]) :create)
(recovery-phrase-start-confirmation cofx)
(let [mnemonic (get-in db [:multiaccounts/recover :passphrase])]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :secrets :mnemonic] mnemonic)}
(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
:keycard.callback/on-init-card-success]}
[{:keys [db] :as cofx} secrets]
(let [secrets' (js->clj secrets :keywordize-keys true)]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :card-state] :init)
(assoc-in [:keycard :setup-step] :secret-keys)
@ -244,17 +244,17 @@
:on-card-read :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
:keycard.callback/on-init-card-error]}
[{:keys [db] :as cofx} {:keys [code 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)}
(common/set-on-card-connected :keycard/load-preparing-screen)
(common/process-error code error)))
(fx/defn generate-and-load-key
(rf/defn generate-and-load-key
{:events [:keycard/generate-and-load-key]}
[{:keys [db] :as cofx}]
(let [{:keys [pin]}
@ -276,22 +276,22 @@
(common/vector->string (get-in db
[:keycard :pin
:current])))]
(fx/merge cofx
(rf/merge cofx
{:keycard/generate-and-load-key
{:mnemonic mnemonic
:pin pin'
:key-uid (:key-uid multiaccount)
: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]}
[{:keys [db] :as cofx} 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]}
[{:keys [db] :as cofx}]
(fx/merge
(rf/merge
cofx
{:db (-> db
(update :keycard
@ -313,7 +313,7 @@
:on-card-read :keycard/check-card-state
:handler (common/get-application-info :keycard/check-card-state)}))))
(fx/defn factory-reset
(rf/defn factory-reset
{:events [::factory-reset]}
[cofx]
(common/show-connection-sheet
@ -322,14 +322,14 @@
:on-card-read :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]}
[{:keys [db] :as cofx}]
{:db (update db :keycard dissoc :factory-reset-card?)})
(fx/defn cancel-pressed
(rf/defn cancel-pressed
{:events [::cancel-pressed]}
[cofx]
(fx/merge cofx
(rf/merge cofx
(navigation/navigate-back)
(common/cancel-sheet-confirm)))

View File

@ -13,7 +13,7 @@
[status-im.native-module.core :as status]
[status-im.popover.core :as popover]
[status-im.utils.datetime :as utils.datetime]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.keychain.core :as keychain]
[status-im.utils.platform :as platform]
[status-im.utils.types :as types]
@ -21,11 +21,11 @@
[taoensso.timbre :as log]
[utils.security.core :as security]))
(fx/defn pair*
(rf/defn pair*
[_ password]
{:keycard/pair {:password password}})
(fx/defn pair
(rf/defn pair
{:events [:keycard/pair]}
[cofx]
(let [{:keys [password]} (get-in cofx [:db :keycard :secrets])]
@ -34,41 +34,41 @@
{:on-card-connected :keycard/pair
:handler (pair* password)})))
(fx/defn pair-code-next-button-pressed
(rf/defn pair-code-next-button-pressed
{:events [:keycard.onboarding.pair.ui/input-submitted
:keycard.ui/pair-code-next-button-pressed
:keycard.onboarding.pair.ui/next-pressed]}
[{:keys [db] :as cofx}]
(let [pairing (get-in db [:keycard :secrets :pairing])
paired-on (get-in db [:keycard :secrets :paired-on] (utils.datetime/timestamp))]
(fx/merge cofx
(rf/merge cofx
(if pairing
{:db (-> db
(assoc-in [:keycard :setup-step] :import-multiaccount)
(assoc-in [:keycard :secrets :paired-on] paired-on))}
(pair)))))
(fx/defn load-pair-screen
(rf/defn load-pair-screen
[{:keys [db] :as cofx}]
(log/debug "[keycard] load-pair-screen")
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :setup-step] :pair))
:dispatch [:bottom-sheet/hide]}
(common/listen-to-hardware-back-button)
(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]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :flow] :recovery)}
(navigation/navigate-to-cofx :keycard-recovery-enter-mnemonic nil)))
(fx/defn start-import-flow
(rf/defn start-import-flow
{:events [::recover-with-keycard-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db
(-> db
(assoc-in [:keycard :flow] :import)
@ -77,31 +77,31 @@
(bottom-sheet/hide-bottom-sheet)
(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]}
[_]
{:dispatch [:bottom-sheet/show-sheet :recover-sheet]})
(fx/defn recovery-keycard-selected
(rf/defn recovery-keycard-selected
{:events [:recovery.ui/keycard-option-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :flow] :recovery)
:keycard/check-nfc-enabled nil}
(common/listen-to-hardware-back-button)
(navigation/navigate-to-cofx :keycard-onboarding-intro nil)))
(fx/defn cancel-pressed
(rf/defn cancel-pressed
{:events [::cancel-pressed]}
[cofx]
(fx/merge cofx
(rf/merge cofx
(common/cancel-sheet-confirm)
(navigation/navigate-back)))
(fx/defn begin-setup-pressed
(rf/defn begin-setup-pressed
{:events [:keycard.recovery.intro.ui/begin-recovery-pressed]}
[{:keys [db] :as cofx}]
(fx/merge
(rf/merge
cofx
{:db (-> db
(update :keycard
@ -118,10 +118,10 @@
:sheet-options {:on-cancel [::cancel-pressed]}
: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]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (update db
:keycard dissoc
:multiaccount-wallet-address
@ -131,11 +131,11 @@
:welcome)
nil)))
(fx/defn intro-wizard
(rf/defn intro-wizard
{:events [:multiaccounts.create.ui/intro-wizard]}
[{:keys [db] :as cofx}]
(let [accs (get db :multiaccounts/multiaccounts)]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(update :keycard dissoc :flow)
(dissoc :restored-account?))}
@ -144,15 +144,15 @@
(navigation/navigate-to-cofx :get-your-keys nil)
(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]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :flow] :create)
:keycard/check-nfc-enabled nil}
(intro-wizard)))
(fx/defn create-keycard-multiaccount
(rf/defn create-keycard-multiaccount
{:events [::create-keycard-multiaccount]
:interceptors [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]}
@ -187,7 +187,7 @@
{:keycard/generate-name-and-photo
{:public-key whisper-public-key
:on-success ::on-name-and-photo-generated}}
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :setup-step] nil)
(dissoc :intro-wizard))}
@ -214,9 +214,9 @@
encryption-public-key
{})))))
(fx/defn return-to-keycard-login
(rf/defn return-to-keycard-login
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(update-in [:keycard :pin]
assoc
@ -228,9 +228,9 @@
[:multiaccounts
:keycard-login-pin])))
(fx/defn on-backup-success
(rf/defn on-backup-success
[{:keys [db] :as cofx} backup-type]
(fx/merge cofx
(rf/merge cofx
{:utils/show-popup {:title (i18n/label (if (= backup-type :recovery-card)
:t/keycard-access-reset
:t/keycard-backup-success-title))
@ -262,7 +262,7 @@
(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}]
(let [pairing (get-in db [:keycard :secrets :pairing])
paired-on (get-in db [:keycard :secrets :paired-on])
@ -291,7 +291,7 @@
(dissoc :recovered-account?))
::finish-migration [account settings password encryption-pass login-params]}))
(fx/defn delete-multiaccount
(rf/defn delete-multiaccount
[{:keys [db]}]
(let [key-uid (get-in db [:multiaccounts/login :key-uid])]
{:keycard/delete-multiaccount-before-migration
@ -299,12 +299,12 @@
:on-error #(re-frame/dispatch [::delete-multiaccount-error %])
:on-success #(re-frame/dispatch [::create-keycard-multiaccount])}}))
(fx/defn handle-delete-multiaccount-error
(rf/defn handle-delete-multiaccount-error
{:events [::delete-multiaccount-error]}
[cofx _]
(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]
:interceptors [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]}
@ -312,7 +312,7 @@
(let [account-data (js->clj data :keywordize-keys true)
backup? (get-in db [:keycard :creating-backup?])
migration? (get-in db [:keycard :converting-account?])]
(fx/merge
(rf/merge
cofx
{:db (-> db
(assoc-in
@ -345,17 +345,17 @@
: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]}
[{:keys [db] :as cofx} {:keys [error code]}]
(log/debug "[keycard] generate and load key error: " error)
(when-not (common/tag-lost? error)
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :setup-error] error)}
(common/set-on-card-connected :keycard/load-loading-keys-screen)
(common/process-error code error))))
(fx/defn import-multiaccount
(rf/defn import-multiaccount
{:events [:keycard/import-multiaccount]}
[{:keys [db] :as cofx}]
(let [{:keys [pairing]} (get-in db [:keycard :secrets])
@ -363,7 +363,7 @@
key-uid (get-in db [:keycard :application-info :key-uid])
pairing' (or pairing (common/get-pairing db key-uid))
pin (common/vector->string (get-in db [:keycard :pin :import-multiaccount]))]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :multiaccount :instance-uid] instance-uid)
(assoc-in [:keycard :pin :status] :verifying)
@ -374,7 +374,7 @@
{:pin pin
: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]}
[cofx]
(common/show-connection-sheet
@ -382,12 +382,12 @@
{:on-card-connected :keycard/load-recovering-key-screen
: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]
:interceptors [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]}
[{:keys [db] :as cofx} whisper-name identicon]
(fx/merge
(rf/merge
cofx
{:db (update-in db
[:keycard :multiaccount]

View File

@ -3,12 +3,12 @@
[re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[status-im.keycard.common :as common]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.money :as money]
[status-im.utils.types :as types]
[taoensso.timbre :as log]))
(fx/defn sign
(rf/defn sign
{:events [:keycard/sign]}
[{:keys [db] :as cofx} hash on-success]
(let [card-connected? (get-in db [:keycard :card-connected?])
@ -34,7 +34,7 @@
(common/show-wrong-keycard-alert cofx)
(not card-connected?)
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:signing/sign :keycard-step] :signing)}
(common/set-on-card-connected :keycard/sign))
@ -57,7 +57,7 @@
(string/replace-first #"01$" "1c")
ethereum/normalized-hex))
(fx/defn sign-message
(rf/defn sign-message
{:events [:keycard/sign-message]}
[cofx params result]
(let [{:keys [result error]} (types/json->clj result)
@ -66,10 +66,10 @@
hash (ethereum/naked-address result)]
(sign cofx hash on-success)))
(fx/defn on-sign-message-success
(rf/defn on-sign-message-success
{:events [:keycard/on-sign-message-success]}
[{:keys [db] :as cofx} {:keys [tx-hash message-id chat-id value contract]} signature]
(fx/merge
(rf/merge
cofx
{:dispatch
(if message-id
@ -83,7 +83,7 @@
(common/get-application-info nil)
(common/hide-connection-sheet)))
(fx/defn sign-typed-data
(rf/defn sign-typed-data
{:events [:keycard/sign-typed-data]}
[{:keys [db] :as cofx}]
(let [card-connected? (get-in db [:keycard :card-connected?])
@ -93,11 +93,11 @@
(assoc-in [:keycard :card-read-in-progress?] true)
(assoc-in [:signing/sign :keycard-step] :signing))
:keycard/sign-typed-data {:hash (ethereum/naked-address hash)}}
(fx/merge cofx
(rf/merge cofx
(common/set-on-card-connected :keycard/sign-typed-data)
{: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]}
[{:keys [db]} {:keys [decimals symbol]}]
{:db (-> db
@ -108,7 +108,7 @@
(.dividedBy ^js (money/bignumber (:amount %))
(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]}
[{:keys [db] :as cofx} result]
(let [{:keys [result]} (types/json->clj result)
@ -119,11 +119,11 @@
:params [(ethereum/chain-id db) currency-contract]
:on-success #(re-frame/dispatch [:keycard/fetch-currency-token-on-success
%])}]})
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :hash] result)}
sign-typed-data)))
(fx/defn prepare-to-sign
(rf/defn prepare-to-sign
{:events [:keycard/prepare-to-sign]}
[{:keys [db] :as cofx}]
(common/show-connection-sheet
@ -131,16 +131,16 @@
{:on-card-connected :keycard/prepare-to-sign
:handler (common/get-application-info :keycard/sign)}))
(fx/defn sign-message-completed
(rf/defn sign-message-completed
[_ signature]
{:dispatch
[:signing/sign-message-completed signature]})
(fx/defn send-transaction-with-signature
(rf/defn 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]}
[{:keys [db] :as cofx} signature]
(log/debug "[keycard] sign success: " signature)
@ -149,13 +149,13 @@
tx-obj (select-keys transaction
[:from :to :value :gas :gasPrice :command? :chat-id :message-id])
command? (:command? transaction)]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :hash] nil)
(assoc-in [:keycard :transaction] nil))}
(when-not command?
(fn [{:keys [db] :as cofx}]
(fx/merge
(rf/merge
cofx
{:db (-> db
(assoc-in [:keycard :pin :sign] [])
@ -170,7 +170,7 @@
:on-completed #(re-frame/dispatch [:signing/transaction-completed % tx-obj])})
(sign-message-completed signature-json)))))
(fx/defn on-sign-error
(rf/defn on-sign-error
{:events [:keycard.callback/on-sign-error]}
[{:keys [db] :as cofx} error]
(log/debug "[keycard] sign error: " error)
@ -178,7 +178,7 @@
pin-retries (common/pin-retries (:error error))]
(when-not tag-was-lost?
(if (not (nil? pin-retries))
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :application-info :pin-retry-counter] pin-retries)
(update-in [:keycard :pin]
@ -190,6 +190,6 @@
(common/hide-connection-sheet)
(when (zero? pin-retries) (common/frozen-keycard-popup)))
(fx/merge cofx
(rf/merge cofx
(common/hide-connection-sheet)
(common/show-wrong-keycard-alert))))))

View File

@ -4,11 +4,11 @@
[status-im.keycard.common :as common]
[status-im.multiaccounts.key-storage.core :as key-storage]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im2.navigation.events :as navigation]
[taoensso.timbre :as log]))
(fx/defn unpair-card-pressed
(rf/defn unpair-card-pressed
{:events [:keycard-settings.ui/unpair-card-pressed]}
[_]
{:ui/show-confirmation {:title (i18n/label :t/unpair-card)
@ -19,27 +19,27 @@
[:keycard-settings.ui/unpair-card-confirmed])
:on-cancel #()}})
(fx/defn unpair-card-confirmed
(rf/defn unpair-card-confirmed
{:events [:keycard-settings.ui/unpair-card-confirmed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db
[:keycard :pin]
{:enter-step :current
:current []
:puk []
:status nil
:error-label nil
:on-verified :keycard/unpair})}
[:keycard :pin]
{:enter-step :current
:current []
:puk []
:status nil
:error-label nil
:on-verified :keycard/unpair})}
(common/navigate-to-enter-pin-screen)))
(fx/defn unpair
(rf/defn unpair
{:events [:keycard/unpair]}
[{:keys [db]}]
(let [pin (common/vector->string (get-in db [:keycard :pin :current]))]
{:keycard/unpair {:pin pin}}))
(fx/defn unpair-and-delete
(rf/defn unpair-and-delete
{:events [:keycard/unpair-and-delete]}
[cofx]
(common/show-connection-sheet
@ -51,9 +51,9 @@
{:keycard/unpair-and-delete
{:pin pin}}))}))
(fx/defn remove-pairing-from-multiaccount
(rf/defn remove-pairing-from-multiaccount
[cofx {:keys [remove-instance-uid?]}]
(fx/merge cofx
(rf/merge cofx
(multiaccounts.update/multiaccount-update
:keycard-pairing
nil
@ -68,12 +68,12 @@
nil
{}))))
(fx/defn on-unpair-success
(rf/defn on-unpair-success
{:events [:keycard.callback/on-unpair-success]}
[{:keys [db] :as cofx}]
(let [instance-uid (get-in db [:keycard :application-info :instance-uid])
pairings (get-in db [:keycard :pairings])]
(fx/merge
(rf/merge
cofx
{:db (-> db
(assoc-in [:keycard :secrets] nil)
@ -89,23 +89,23 @@
(remove-pairing-from-multiaccount nil)
(navigation/navigate-to-cofx :keycard-settings nil))))
(fx/defn on-unpair-error
(rf/defn on-unpair-error
{:events [:keycard.callback/on-unpair-error]}
[{:keys [db] :as cofx} error]
(log/debug "[keycard] unpair error" error)
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db
[:keycard :pin]
{:status nil
:error-label nil
:on-verified nil})
[:keycard :pin]
{:status nil
:error-label nil
:on-verified nil})
:keycard/get-application-info nil
:utils/show-popup {:title ""
:content (i18n/label :t/something-went-wrong)}}
(common/clear-on-card-connected)
(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]}
[cofx]
(common/show-connection-sheet
@ -122,7 +122,7 @@
(let [key-uid (get-in db [:multiaccount :key-uid])
instance-uid (get-in db [:keycard :application-info :instance-uid])
pairings (get-in db [:keycard :pairings])]
(fx/merge
(rf/merge
cofx
{:db (-> db
(update :multiaccounts/multiaccounts dissoc key-uid)
@ -152,36 +152,36 @@
(common/clear-on-card-connected)
(common/hide-connection-sheet))))
(fx/defn on-remove-key-success
(rf/defn on-remove-key-success
{:events [:keycard.callback/on-remove-key-success]}
[cofx]
(handle-account-removal cofx true))
(fx/defn on-remove-key-error
(rf/defn on-remove-key-error
{:events [:keycard.callback/on-remove-key-error]}
[{:keys [db] :as cofx} error]
(log/debug "[keycard] remove key error" error)
(let [tag-was-lost? (common/tag-lost? (:error error))]
(fx/merge cofx
(rf/merge cofx
(if tag-was-lost?
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :pin :status] nil)}
(common/set-on-card-connected :keycard/remove-key-with-unpair))
(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]}
[cofx]
(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]}
[{:keys [db] :as cofx} error]
(log/debug "[keycard] unpair and delete error" error)
(let [tag-was-lost? (common/tag-lost? (:error error))]
(fx/merge cofx
(rf/merge cofx
(if tag-was-lost?
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:keycard :pin :status] nil)}
(common/set-on-card-connected :keycard/unpair-and-delete))
(common/show-wrong-keycard-alert)))))

View File

@ -5,13 +5,13 @@
[status-im.ethereum.eip55 :as eip55]
[status-im.keycard.common :as common]
[status-im.ui.screens.wallet.add-new.views :as add-new.views]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.hex :as utils.hex]))
(fx/defn show-pin-sheet
(rf/defn show-pin-sheet
{:events [:keycard/new-account-pin-sheet]}
[{:keys [db] :as cofx}]
(fx/merge
(rf/merge
cofx
{:db (-> db
(assoc-in [:keycard :pin :enter-step] :export-key)
@ -19,19 +19,19 @@
:dismiss-keyboard nil}
(bottom-sheet/show-bottom-sheet {:view {:content add-new.views/pin}})))
(fx/defn verify-pin-with-delay
(rf/defn verify-pin-with-delay
[cofx]
{:utils/dispatch-later
;; We need to give previous sheet some time to be fully hidden
[{:ms 200
:dispatch [:wallet.accounts/verify-pin]}]})
(fx/defn hide-pin-sheet
(rf/defn hide-pin-sheet
{:events [:keycard/new-account-pin-sheet-hide]}
[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]}
[{:keys [db]}]
(let [path-num (inc (get-in db [:multiaccount :latest-derived-path]))
@ -53,7 +53,7 @@
:keycard/export-key {:pin pin :path path}}))
(fx/defn verify-pin
(rf/defn verify-pin
{:events [:wallet.accounts/verify-pin]}
[cofx]
(common/verify-pin

View File

@ -3,14 +3,14 @@
[status-im.i18n.i18n :as i18n]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.node.core :as node]
[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]}
[{:keys [db now] :as cofx} log-level]
(let [old-log-level (get-in db [:multiaccount :log-level])]
(when (not= old-log-level log-level)
(fx/merge cofx
(rf/merge cofx
(multiaccounts.update/multiaccount-update
:log-level
log-level
@ -18,7 +18,7 @@
(node/prepare-new-config
{: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]}
[_ {:keys [name value]}]
{:ui/show-confirmation

View File

@ -4,7 +4,7 @@
[status-im.i18n.i18n :as i18n]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.node.core :as node]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.mobile-sync :as mobile-network-utils]
[status-im2.navigation.events :as navigation]
[taoensso.timbre :as log]))
@ -52,7 +52,7 @@
current-fleet
vals)))))
(fx/defn disconnect-from-mailserver
(rf/defn disconnect-from-mailserver
{:events [::disconnect-from-mailserver]}
[{:keys [db] :as cofx}]
{:db (-> db
@ -74,7 +74,7 @@
::cancel-connection-popup
cancel-connection-popup!)
(fx/defn show-connection-error!
(rf/defn show-connection-error!
[cofx current-fleet preferred-mailserver]
(reset! showing-connection-error-popup? true)
{:ui/show-confirmation
@ -95,13 +95,13 @@
preferred-mailserver]))
:style "default"}]}})
(fx/defn handle-successful-request
(rf/defn handle-successful-request
{:events [::request-success]}
[{:keys [db] :as cofx} response-js]
{:db (dissoc db :mailserver/current-request)
:dispatch [:sanitize-messages-and-process-response response-js]})
(fx/defn handle-mailserver-not-working
(rf/defn handle-mailserver-not-working
[{:keys [db] :as cofx}]
(let [current-fleet (node/current-fleet-key db)
error-dismissed? (connection-error-dismissed db)
@ -111,12 +111,12 @@
(not @showing-connection-error-popup?))
(show-connection-error! cofx current-fleet pinned-mailserver))))
(fx/defn handle-request-error
(rf/defn handle-request-error
{:events [::request-error]}
[{:keys [db] :as cofx}]
{:db (dissoc db :mailserver/current-request)})
(fx/defn process-next-messages-request
(rf/defn process-next-messages-request
{:events [::request-messages]}
[{:keys [db now] :as cofx}]
(when (and
@ -135,7 +135,7 @@
(log/error "failed retrieve historical messages" %)
(re-frame/dispatch [::request-error]))}]}))
(fx/defn handle-mailserver-changed
(rf/defn handle-mailserver-changed
[{:keys [db] :as cofx} ms]
(if (seq ms)
{:db (assoc db
@ -143,29 +143,29 @@
:mailserver/current-id (keyword ms))}
{:db (assoc db :mailserver/state nil)}))
(fx/defn handle-mailserver-available
(rf/defn handle-mailserver-available
[{:keys [db] :as cofx} ms]
{::cancel-connection-popup []
:db (assoc db
:mailserver/state :connected
:mailserver/current-id (keyword ms))})
(fx/defn connected-to-mailserver
(rf/defn connected-to-mailserver
[{:keys [db] :as cofx}]
(let [{:keys [address]} (fetch-current db)]
(fx/merge
(rf/merge
cofx
{:mailserver/update-mailservers [[address] #(re-frame/dispatch [::request-messages])]})))
(fx/defn handle-request-success
(rf/defn handle-request-success
{:events [:mailserver.callback/request-success]}
[{{:keys [chats] :as db} :db} {:keys [request-id topics]}]
(when (:mailserver/current-request db)
{:db (assoc-in db
[:mailserver/current-request :request-id]
request-id)}))
[:mailserver/current-request :request-id]
request-id)}))
(fx/defn toggle-use-mailservers
(rf/defn toggle-use-mailservers
[cofx value]
{:json-rpc/call
[{:method "wakuext_toggleUseMailservers"
@ -173,23 +173,23 @@
:on-success #(log/info "successfully toggled use-mailservers" 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]}
[cofx use-mailservers?]
(fx/merge cofx
(rf/merge cofx
(multiaccounts.update/optimistic :use-mailservers? use-mailservers?)
(toggle-use-mailservers use-mailservers?)
(when use-mailservers?
(disconnect-from-mailserver))))
(fx/defn retry-next-messages-request
(rf/defn retry-next-messages-request
{:events [:mailserver.ui/retry-request-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (dissoc db :mailserver/request-error)}
(process-next-messages-request)))
(fx/defn show-request-error-popup
(rf/defn show-request-error-popup
{:events [:mailserver.ui/request-error-pressed]}
[{:keys [db]}]
(let [mailserver-error (:mailserver/request-error db)]
@ -216,7 +216,7 @@
(let [[initial host] (extract-url-components address)]
(str "enode://" initial "@" host)))
(fx/defn set-input
(rf/defn set-input
{:events [:mailserver.ui/input-changed]}
[{:keys [db]} input-key value]
{:db (update
@ -246,12 +246,12 @@
(def default? (comp not :custom fetch))
(fx/defn edit
(rf/defn edit
{:events [:mailserver.ui/custom-mailserver-selected]}
[{:keys [db] :as cofx} id]
(let [{:keys [id address name]} (fetch db id)
url (when address (build-url address))]
(fx/merge cofx
(rf/merge cofx
(set-input :id id)
(set-input :url (str url))
(set-input :name (str name))
@ -263,7 +263,7 @@
(assoc :fleet (name current-fleet))
(update :id name)))
(fx/defn upsert
(rf/defn upsert
{:events [:mailserver.ui/save-pressed]
:interceptors [(re-frame/inject-cofx :random-id-generator)]}
[{{:mailserver.edit/keys [mailserver] :keys [multiaccount] :as db} :db
@ -303,7 +303,7 @@
(not (or (default? db id)
(connected? db id))))
(fx/defn delete
(rf/defn delete
{:events [:mailserver.ui/delete-confirmed]}
[{:keys [db] :as cofx} id]
(if (can-delete? db id)
@ -321,7 +321,7 @@
: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]}
[{:keys [db]} mailserver-id]
(let [current-fleet (node/current-fleet-key db)]
@ -338,7 +338,7 @@
[:mailserver.ui/connect-confirmed current-fleet mailserver-id])
:on-cancel nil}}))
(fx/defn show-delete-confirmation
(rf/defn show-delete-confirmation
{:events [:mailserver.ui/delete-pressed]}
[{:keys [db]} mailserver-id]
{:ui/show-confirmation
@ -348,25 +348,25 @@
:on-accept #(re-frame/dispatch
[:mailserver.ui/delete-confirmed mailserver-id])}})
(fx/defn set-url-from-qr
(rf/defn set-url-from-qr
{:events [:mailserver.callback/qr-code-scanned]}
[cofx url]
(assoc (set-input cofx :url url)
:dispatch
[:navigate-back]))
(fx/defn dismiss-connection-error
(rf/defn dismiss-connection-error
{:events [:mailserver.ui/dismiss-connection-error]}
[{:keys [db]} new-state]
{:db (assoc db :mailserver/connection-error-dismissed new-state)})
(fx/defn pin-mailserver
(rf/defn pin-mailserver
{:events [:mailserver.ui/connect-confirmed]}
[{:keys [db] :as cofx} current-fleet mailserver-id]
(let [pinned-mailservers (-> db
(get-in [:multiaccount :pinned-mailservers])
(assoc current-fleet mailserver-id))]
(fx/merge cofx
(rf/merge cofx
{:db (assoc db :mailserver/current-id mailserver-id)
:json-rpc/call [{:method "wakuext_setPinnedMailservers"
:params [pinned-mailservers]
@ -374,14 +374,14 @@
:on-error #(log/error "failed to pin mailserver" %)}]}
(multiaccounts.update/optimistic :pinned-mailservers pinned-mailservers))))
(fx/defn unpin
(rf/defn unpin
{:events [:mailserver.ui/unpin-pressed]}
[{:keys [db] :as cofx}]
(let [current-fleet (node/current-fleet-key db)
pinned-mailservers (-> db
(get-in [:multiaccount :pinned-mailservers])
(dissoc current-fleet))]
(fx/merge cofx
(rf/merge cofx
{:json-rpc/call [{:method "wakuext_setPinnedMailservers"
:params [pinned-mailservers]
:on-success #(log/info "successfully unpinned mailserver")
@ -391,13 +391,13 @@
pinned-mailservers)
(dismiss-connection-error false))))
(fx/defn pin
(rf/defn pin
{:events [:mailserver.ui/pin-pressed]}
[{:keys [db] :as cofx}]
(let [current-fleet (node/current-fleet-key db)
mailserver-id (:mailserver/current-id db)
pinned-mailservers (get-in db [:multiaccount :pinned-mailservers])]
(fx/merge cofx
(rf/merge cofx
(multiaccounts.update/multiaccount-update
:pinned-mailservers
(assoc pinned-mailservers
@ -406,9 +406,9 @@
{})
(dismiss-connection-error false))))
(fx/defn mailserver-ui-add-pressed
(rf/defn mailserver-ui-add-pressed
{:events [:mailserver.ui/add-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (dissoc db :mailserver.edit/mailserver)}
(navigation/navigate-to-cofx :edit-mailserver nil)))

View File

@ -3,13 +3,13 @@
[status-im.mailserver.core :as mailserver]
[status-im.multiaccounts.model :as multiaccounts.model]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.mobile-sync :as utils]
[status-im.wallet.core :as wallet]
[status-im2.navigation.events :as navigation]
[taoensso.timbre :as log]))
(fx/defn sheet-defaults
(rf/defn sheet-defaults
[{:keys [db]}]
(let [remember-choice? (get-in db [:multiaccount :remember-syncing-choice?])]
{:db (assoc db
@ -17,13 +17,13 @@
(or (nil? remember-choice?)
remember-choice?))}))
(fx/defn on-network-status-change
(rf/defn on-network-status-change
[{:keys [db] :as cofx}]
(let [initialized? (get db :network-status/initialized?)
logged-in? (multiaccounts.model/logged-in? cofx)
{:keys [remember-syncing-choice?]} (:multiaccount db)]
(apply
fx/merge
rf/merge
cofx
{:db (assoc db :network-status/initialized? true)}
(cond
@ -62,7 +62,7 @@
"sunc?" sync?
"remember?" remember?
"cellular?" cellular?)
(fx/merge
(rf/merge
cofx
(multiaccounts.update/multiaccount-update
:syncing-on-mobile-network?
@ -76,47 +76,47 @@
(mailserver/process-next-messages-request))
(wallet/restart-wallet-service nil))))))
(fx/defn mobile-network-continue-syncing
(rf/defn mobile-network-continue-syncing
{:events [:mobile-network/continue-syncing]}
[cofx]
((apply-settings true) cofx))
(fx/defn mobile-network-stop-syncing
(rf/defn mobile-network-stop-syncing
{:events [:mobile-network/stop-syncing]}
[cofx]
((apply-settings false) cofx))
(fx/defn mobile-network-set-syncing
(rf/defn mobile-network-set-syncing
{:events [:mobile-network/set-syncing]}
[{:keys [db] :as cofx} syncing?]
(let [{:keys [remember-syncing-choice?]} (:multiaccount db)]
((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?]}
[{:keys [db] :as cofx} ask?]
(let [{:keys [syncing-on-mobile-network?]} (:multiaccount db)]
((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]}
[cofx]
((apply-settings false false) cofx))
(fx/defn mobile-network-remember-choice?
(rf/defn mobile-network-remember-choice?
{:events [:mobile-network/remember-choice?]}
[{:keys [db]} 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]}
[cofx]
(fx/merge
(rf/merge
cofx
(bottom-sheet/hide-bottom-sheet)
(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]}
[cofx]
(bottom-sheet/show-bottom-sheet

View File

@ -5,7 +5,7 @@
[status-im.i18n.i18n :as i18n]
[status-im.native-module.core :as status]
[status-im.popover.core :as popover]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.keychain.core :as keychain]
[status-im.utils.platform :as platform]
[taoensso.timbre :as log]))
@ -111,12 +111,12 @@
(get-supported callback)
(callback nil)))))))
(fx/defn set-supported-biometric-auth
(rf/defn set-supported-biometric-auth
{:events [:init.callback/get-supported-biometric-auth-success]}
[{:keys [db]} supported-biometric-auth]
{:db (assoc db :supported-biometric-auth supported-biometric-auth)})
(fx/defn authenticate
(rf/defn authenticate
[_ cb options]
{:biometric-auth/authenticate [cb options]})
@ -125,11 +125,11 @@
(fn [[cb options]]
(authenticate-fx #(cb %) options)))
(fx/defn update-biometric
(rf/defn update-biometric
[{db :db :as cofx} biometric-auth?]
(let [key-uid (or (get-in db [:multiaccount :key-uid])
(get-in db [:multiaccounts/login :key-uid]))]
(fx/merge cofx
(rf/merge cofx
(keychain/save-auth-method
key-uid
(if biometric-auth?
@ -138,7 +138,7 @@
#(when-not biometric-auth?
{:keychain/clear-user-password key-uid}))))
(fx/defn biometric-auth-switched
(rf/defn biometric-auth-switched
{:events [:multiaccounts.ui/biometric-auth-switched]}
[cofx biometric-auth?]
(if biometric-auth?
@ -148,7 +148,7 @@
{})
(update-biometric cofx false)))
(fx/defn show-message
(rf/defn show-message
[cofx bioauth-message bioauth-code]
(let [content (or (when (get #{"NOT_AVAILABLE" "NOT_ENROLLED"} bioauth-code)
(i18n/label :t/grant-face-id-permissions))
@ -158,7 +158,7 @@
{:title (i18n/label :t/biometric-auth-login-error-title)
:content content}})))
(fx/defn biometric-init-done
(rf/defn biometric-init-done
{:events [:biometric-init-done]}
[cofx {:keys [bioauth-success bioauth-message bioauth-code]}]
(if bioauth-success
@ -168,7 +168,7 @@
(popover/show-popover cofx {:view :enable-biometric}))
(show-message cofx bioauth-message bioauth-code)))
(fx/defn biometric-auth
(rf/defn biometric-auth
{:events [:biometric-authenticate]}
[cofx]
(authenticate
@ -177,25 +177,25 @@
{:reason (i18n/label :t/biometric-auth-reason-login)
:ios-fallback-label (i18n/label :t/biometric-auth-login-ios-fallback-label)}))
(fx/defn enable
(rf/defn enable
{:events [:biometric/enable]}
[cofx]
(fx/merge
(rf/merge
cofx
(popover/hide-popover)
(authenticate #(re-frame/dispatch [:biometric/setup-done %]) {})))
(fx/defn disable
(rf/defn disable
{:events [:biometric/disable]}
[{:keys [db] :as cofx}]
(fx/merge
(rf/merge
cofx
{:db (-> db
(assoc :auth-method keychain/auth-method-none)
(assoc-in [:multiaccounts/login :save-password?] false))}
(popover/hide-popover)))
(fx/defn setup-done
(rf/defn setup-done
{:events [:biometric/setup-done]}
[{:keys [db] :as cofx} {:keys [bioauth-success bioauth-message bioauth-code]}]
(log/debug "[biometric] setup-done"

View File

@ -7,7 +7,7 @@
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.native-module.core :as native-module]
[status-im.theme.core :as theme]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.gfycat.core :as gfycat]
[status-im.utils.identicon :as identicon]
[status-im.utils.utils :as utils]
@ -112,7 +112,7 @@
(fn [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]}
[cofx]
(multiaccounts.update/multiaccount-update cofx
@ -120,7 +120,7 @@
true
{}))
(fx/defn confirm-home-tooltip
(rf/defn confirm-home-tooltip
{:events [:multiaccounts.ui/hide-home-tooltip]}
[cofx]
(multiaccounts.update/multiaccount-update cofx
@ -128,27 +128,27 @@
true
{}))
(fx/defn switch-webview-debug
(rf/defn switch-webview-debug
{:events [:multiaccounts.ui/switch-webview-debug]}
[{:keys [db] :as cofx} value]
(fx/merge cofx
(rf/merge cofx
{::webview-debug-changed value}
(multiaccounts.update/multiaccount-update
:webview-debug
(boolean value)
{})))
(fx/defn switch-preview-privacy-mode
(rf/defn switch-preview-privacy-mode
{:events [:multiaccounts.ui/preview-privacy-mode-switched]}
[{:keys [db] :as cofx} private?]
(fx/merge cofx
(rf/merge cofx
{::blank-preview-flag-changed private?}
(multiaccounts.update/multiaccount-update
:preview-privacy?
(boolean private?)
{})))
(fx/defn switch-webview-permission-requests?
(rf/defn switch-webview-permission-requests?
{:events [:multiaccounts.ui/webview-permission-requests-switched]}
[cofx enabled?]
(multiaccounts.update/multiaccount-update
@ -157,7 +157,7 @@
(boolean enabled?)
{}))
(fx/defn switch-default-sync-period
(rf/defn switch-default-sync-period
{:events [:multiaccounts.ui/default-sync-period-switched]}
[cofx value]
(multiaccounts.update/multiaccount-update
@ -166,7 +166,7 @@
value
{}))
(fx/defn switch-preview-privacy-mode-flag
(rf/defn switch-preview-privacy-mode-flag
[{:keys [db]}]
(let [private? (get-in db [:multiaccount :preview-privacy?])]
{::blank-preview-flag-changed private?}))
@ -179,23 +179,23 @@
:light)]
(theme/change-theme theme))))
(fx/defn switch-appearance
(rf/defn switch-appearance
{:events [:multiaccounts.ui/appearance-switched]}
[cofx theme]
(fx/merge cofx
(rf/merge cofx
{:multiaccounts.ui/switch-theme 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]}
[cofx id]
(fx/merge cofx
(rf/merge cofx
{:json-rpc/call [{:method "wakuext_changeIdentityImageShowTo"
:params [id]
:on-success #(log/debug "picture settings changed successfully")}]}
(multiaccounts.update/optimistic :profile-pictures-show-to id)))
(fx/defn switch-appearance-profile
(rf/defn switch-appearance-profile
{:events [:multiaccounts.ui/appearance-profile-switched]}
[cofx id]
(multiaccounts.update/multiaccount-update cofx :profile-pictures-visibility id {}))
@ -206,22 +206,22 @@
(string/replace-first path #"file://" "")
(log/warn "[native-module] Empty path was provided")))
(fx/defn save-profile-picture
(rf/defn save-profile-picture
{:events [::save-profile-picture]}
[cofx path ax ay bx by]
(let [key-uid (get-in cofx [:db :multiaccount :key-uid])]
(fx/merge cofx
(rf/merge cofx
{:json-rpc/call [{:method "multiaccounts_storeIdentityImage"
:params [key-uid (clean-path path) ax ay bx by]
;; NOTE: In case of an error we can show a toast error
:on-success #(re-frame/dispatch [::update-local-picture %])}]}
(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]}
[cofx url]
(let [key-uid (get-in cofx [:db :multiaccount :key-uid])]
(fx/merge cofx
(rf/merge cofx
{:json-rpc/call [{:method "multiaccounts_storeIdentityImageFromURL"
:params [key-uid url]
:on-error #(log/error "::save-profile-picture-from-url error" %)
@ -233,11 +233,11 @@
[::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]}
[cofx name]
(let [key-uid (get-in cofx [:db :multiaccount :key-uid])]
(fx/merge cofx
(rf/merge cofx
{:json-rpc/call [{:method "multiaccounts_deleteIdentityImage"
:params [key-uid]
;; NOTE: In case of an error we could fallback to previous image in UI
@ -246,14 +246,14 @@
(multiaccounts.update/optimistic :images nil)
(bottom-sheet/hide-bottom-sheet))))
(fx/defn get-profile-picture
(rf/defn get-profile-picture
[cofx]
(let [key-uid (get-in cofx [:db :multiaccount :key-uid])]
{:json-rpc/call [{:method "multiaccounts_getIdentityImages"
:params [key-uid]
:on-success #(re-frame/dispatch [::update-local-picture %])}]}))
(fx/defn store-profile-picture
(rf/defn store-profile-picture
{:events [::update-local-picture]}
[cofx pics]
(multiaccounts.update/optimistic cofx :images pics))

View File

@ -9,7 +9,7 @@
[status-im.native-module.core :as status]
[status-im.node.core :as node]
[status-im.utils.config :as config]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.signing-phrase.core :as signing-phrase]
[status-im.utils.types :as types]
[utils.security.core :as security]))
@ -51,7 +51,7 @@
hashed-password
callback)))
(fx/defn create-multiaccount
(rf/defn create-multiaccount
{:events [:create-multiaccount]}
[{:keys [db]} key-code]
(let [{:keys [selected-id]} (:intro-wizard db)]
@ -71,8 +71,8 @@
(fn [name identicon]
(let [derived-whisper (derived-data constants/path-whisper-keyword)
derived-data-extended (assoc-in derived-data
[constants/path-whisper-keyword]
(merge derived-whisper {:name name :identicon identicon}))]
[constants/path-whisper-keyword]
(merge derived-whisper {:name name :identicon identicon}))]
(re-frame/dispatch [::store-multiaccount-success key-code derived-data-extended]))))))]}))
(re-frame/reg-fx
@ -88,7 +88,7 @@
(mapv normalize-multiaccount-data-keys
(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]}
[{:keys [db]} result]
{:db (update db
@ -102,7 +102,7 @@
:step :choose-key))))
:navigate-to-fx :choose-name})
(fx/defn generate-and-derive-addresses
(rf/defn generate-and-derive-addresses
{:events [:generate-and-derive-addresses]}
[{:keys [db]}]
{:db (-> db
@ -113,11 +113,11 @@
(dissoc :recovered-account?))
:multiaccount-generate-and-derive-addresses nil})
(fx/defn prepare-intro-wizard
(rf/defn prepare-intro-wizard
[{:keys [db]}]
{:db (assoc db :intro-wizard {})})
(fx/defn save-multiaccount-and-login-with-keycard
(rf/defn save-multiaccount-and-login-with-keycard
[_ args]
{:keycard/save-multiaccount-and-login args})
@ -132,7 +132,7 @@
config
accounts-data)))
(fx/defn save-account-and-login
(rf/defn save-account-and-login
[_ key-uid multiaccount-data password settings node-config accounts-data]
{::save-account-and-login [key-uid
(types/clj->json multiaccount-data)
@ -160,7 +160,7 @@
:path constants/path-whisper
:chat true})])
(fx/defn on-multiaccount-created
(rf/defn on-multiaccount-created
[{:keys [signing-phrase random-guid-generator db] :as cofx}
{:keys [address chat-key keycard-instance-uid key-uid
keycard-pairing keycard-paired-on mnemonic recovered]
@ -181,32 +181,32 @@
:address])
new-multiaccount
(cond->
(merge
{;; address of the master key
:address address
(merge
{;; address of the master key
:address address
;; sha256 of master public key
:key-uid key-uid
:key-uid key-uid
;; The address from which we derive any wallet
:wallet-root-address
(get-in multiaccount
[:derived
constants/path-wallet-root-keyword
:address])
:name name
:identicon identicon
:wallet-root-address
(get-in multiaccount
[:derived
constants/path-wallet-root-keyword
:address])
:name name
:identicon identicon
;; public key of the chat account
:public-key public-key
:public-key public-key
;; default address for Dapps
:dapps-address (:address wallet-account)
:latest-derived-path 0
:signing-phrase signing-phrase
:send-push-notifications? true
:backup-enabled? true
:installation-id (random-guid-generator)
:dapps-address (:address wallet-account)
:latest-derived-path 0
:signing-phrase signing-phrase
:send-push-notifications? true
:backup-enabled? true
:installation-id (random-guid-generator)
;; default mailserver (history node) setting
:use-mailservers? true
:recovered recovered}
config/default-multiaccount)
:use-mailservers? true
:recovered recovered}
config/default-multiaccount)
;; The address from which we derive any chat
;; account/encryption keys
eip1581-address
@ -231,7 +231,7 @@
settings (assoc new-multiaccount
:networks/current-network config/default-network
:networks/networks config/default-networks)]
(fx/merge cofx
(rf/merge cofx
{:db db}
(if keycard-multiaccount?
(save-multiaccount-and-login-with-keycard
@ -250,12 +250,12 @@
(node/get-new-config db)
accounts-data)))))
(fx/defn store-multiaccount-success
(rf/defn store-multiaccount-success
{:events [::store-multiaccount-success]
:interceptors [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx ::get-signing-phrase)]}
[{:keys [db] :as cofx} password derived]
(fx/merge cofx
(rf/merge cofx
{:db (dissoc db :intro-wizard)}
(on-multiaccount-created (assoc (let [{:keys [selected-id multiaccounts]} (:intro-wizard db)]
(some #(when (= selected-id (:id %)) %) multiaccounts))
@ -264,12 +264,12 @@
password
{:save-mnemonic? true})))
(fx/defn on-key-selected
(rf/defn on-key-selected
{:events [:intro-wizard/on-key-selected]}
[{:keys [db]} 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]}
[{:keys [db]} storage-type]
{:db (assoc-in db [:intro-wizard :selected-storage-type] storage-type)})

View File

@ -13,12 +13,12 @@
[status-im.multiaccounts.recover.core :as multiaccounts.recover]
[status-im.native-module.core :as native-module]
[status-im.popover.core :as popover]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.types :as types]
[status-im2.navigation.events :as navigation]
[utils.security.core :as security]))
(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"
{:events [::key-and-storage-management-pressed]}
[cofx]
@ -29,20 +29,20 @@
:actions-not-logged-in)
nil))
(fx/defn move-keystore-checked
(rf/defn move-keystore-checked
{:events [::move-keystore-checked]}
[{:keys [db] :as cofx} 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]}
[{:keys [db] :as cofx} checked?]
{:db (assoc-in db [:multiaccounts/key-storage :reset-db-checked?] checked?)})
(fx/defn navigate-back
(rf/defn navigate-back
{:events [::navigate-back]}
[{:keys [db] :as cofx}]
(fx/merge
(rf/merge
cofx
{:db (-> db
(dissoc :recovered-account?)
@ -53,16 +53,16 @@
:factory-reset-card?))}
(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"
{:events [::enter-seed-pressed]}
[{:keys [db] :as cofx}]
(fx/merge
(rf/merge
cofx
{:db (assoc db :recovered-account? true)}
(navigation/navigate-to-cofx :seed-phrase nil)))
(fx/defn seed-phrase-input-changed
(rf/defn seed-phrase-input-changed
{:events [::seed-phrase-input-changed]}
[{:keys [db] :as cofx} masked-seed-phrase]
(let [seed-phrase (security/safe-unmask-data masked-seed-phrase)]
@ -74,12 +74,12 @@
(not (mnemonic/valid-length? 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]}
[cofx _]
(popover/show-popover cofx {:view :seed-key-uid-mismatch}))
(fx/defn key-uid-matches
(rf/defn key-uid-matches
{:events [::key-uid-matches]}
[{:keys [db] :as cofx} _]
(let [backup? (get-in db [:keycard :creating-backup?])]
@ -108,7 +108,7 @@
:on-success #(re-frame/dispatch [::key-uid-matches])
: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]}
[{:keys [db] :as cofx} validation-error]
(let [error? (-> validation-error
@ -130,7 +130,7 @@
:application-info
:key-uid)))}})))
(fx/defn choose-storage-pressed
(rf/defn choose-storage-pressed
{:events [::choose-storage-pressed]}
[{:keys [db] :as cofx}]
(let [{:keys [seed-phrase]} (:multiaccounts/key-storage db)]
@ -138,7 +138,7 @@
[(mnemonic/sanitize-passphrase seed-phrase)
#(re-frame/dispatch [::seed-phrase-validated %])]}))
(fx/defn keycard-storage-pressed
(rf/defn keycard-storage-pressed
{:events [::keycard-storage-pressed]}
[{:keys [db]} selected?]
{:db (assoc-in db [:multiaccounts/key-storage :keycard-storage-selected?] selected?)})
@ -171,7 +171,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
"
(fx/defn import-multiaccount
(rf/defn import-multiaccount
[{:keys [db] :as cofx}]
{:dispatch [:bottom-sheet/hide]
::multiaccounts.recover/import-multiaccount
@ -179,27 +179,27 @@ We don't need to take the exact steps, just set the required state and redirect
:password nil
: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]}
[{:keys [db] :as cofx}]
(fx/merge
(rf/merge
{:dispatch [:bottom-sheet/hide]
:db (assoc-in db [:multiaccounts/key-storage :reset-db-checked?] true)}
(import-multiaccount)))
(fx/defn storage-selected
(rf/defn storage-selected
{:events [::storage-selected]}
[{:keys [db] :as cofx}]
(if (get-in db [:multiaccounts/key-storage :reset-db-checked?])
(popover/show-popover cofx {:view :transfer-multiaccount-to-keycard-warning})
(bottom-sheet/show-bottom-sheet cofx {:view :migrate-account-password})))
(fx/defn skip-password-pressed
(rf/defn skip-password-pressed
{:events [::skip-password-pressed]}
[cofx]
(popover/show-popover cofx {:view :transfer-multiaccount-to-keycard-warning}))
(fx/defn password-changed
(rf/defn password-changed
{:events [::password-changed]}
[{db :db} password]
(let [unmasked-pass (security/safe-unmask-data password)]
@ -209,18 +209,18 @@ We don't need to take the exact steps, just set the required state and redirect
:migration-password-error nil
:migration-password-valid? (and unmasked-pass (> (count unmasked-pass) 5)))}))
(fx/defn verify-password-result
(rf/defn verify-password-result
{:events [::verify-password-result]}
[{:keys [db] :as cofx} result]
(let [{:keys [error]} (types/json->clj result)]
(if (string/blank? error)
(fx/merge
(rf/merge
cofx
{:db (update db :keycard dissoc :migration-password-error :migration-password-valid?)}
(import-multiaccount))
{:db (assoc-in db [:keycard :migration-password-error] (i18n/label :t/wrong-password))})))
(fx/defn verify-password
(rf/defn verify-password
{:events [::verify-password]}
[{:keys [db] :as cofx}]
(native-module/verify-database-password
@ -228,10 +228,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])))
#(re-frame/dispatch [::verify-password-result %])))
(fx/defn handle-multiaccount-import
(rf/defn handle-multiaccount-import
{:events [::import-multiaccount-success]}
[{:keys [db] :as cofx} root-data derived-data]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(update :intro-wizard
assoc
@ -250,21 +250,21 @@ We don't need to take the exact steps, just set the required state and redirect
(common/listen-to-hardware-back-button)
(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]}
[cofx _]
(fx/merge cofx
(rf/merge cofx
(popover/hide-popover)
(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]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc db :goto-key-storage? true)}
(multiaccounts.logout/logout)))
(fx/defn logout-and-goto-key-storage
(rf/defn logout-and-goto-key-storage
{:events [::logout-and-goto-key-storage]}
[_]
{:ui/show-confirmation

View File

@ -27,7 +27,7 @@
[status-im.transport.core :as transport]
[status-im.ui.components.react :as react]
[status-im.utils.config :as config]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.keychain.core :as keychain]
[status-im.utils.mobile-sync :as utils.mobile-sync]
[status-im.utils.platform :as platform]
@ -121,7 +121,7 @@
"0x86a12d91c813f69a53349ff640e32af97d5f5c1f8d42d54cf4c8aa8dea231955"
"0x0011a30f5b2023bc228f6dd5608b3e7149646fa83f33350926ceb1925af78f08"})
(fx/defn check-invalid-ens
(rf/defn check-invalid-ens
[{:keys [db]}]
(async-storage/get-item
:invalid-ens-name-seen
@ -135,11 +135,11 @@
#(async-storage/set-item! :invalid-ens-name-seen true)))))
nil)
(fx/defn initialize-wallet
(rf/defn initialize-wallet
{:events [::initialize-wallet]}
[{:keys [db] :as cofx} accounts tokens custom-tokens
favourites scan-all-tokens? new-account?]
(fx/merge
(rf/merge
cofx
{:db (assoc db
:multiaccount/accounts
@ -173,7 +173,7 @@
(prices/update-prices)
(wallet-connect-legacy/get-connector-session-from-db)))
(fx/defn login
(rf/defn login
{:events [:multiaccounts.login.ui/password-input-submitted]}
[{:keys [db]}]
(let [{:keys [key-uid password name identicon]} (:multiaccounts/login db)]
@ -187,7 +187,7 @@
:identicon identicon})
(ethereum/sha3 (security/safe-unmask-data password))]}))
(fx/defn export-db-submitted
(rf/defn export-db-submitted
{:events [:multiaccounts.login.ui/export-db-submitted]}
[{:keys [db]}]
(let [{:keys [key-uid password name identicon]} (:multiaccounts/login db)]
@ -203,7 +203,7 @@
(clj->js {:title "Unencrypted database"
:url uri})))))]}))
(fx/defn import-db-submitted
(rf/defn import-db-submitted
{:events [:multiaccounts.login.ui/import-db-submitted]}
[{:keys [db]}]
(let [{:keys [key-uid password name identicon]} (:multiaccounts/login db)]
@ -213,11 +213,11 @@
:identicon identicon})
(ethereum/sha3 (security/safe-unmask-data password))]}))
(fx/defn finish-keycard-setup
(rf/defn finish-keycard-setup
[{:keys [db] :as cofx}]
{:db (update db :keycard dissoc :flow)})
(fx/defn initialize-dapp-permissions
(rf/defn initialize-dapp-permissions
{:events [::initialize-dapp-permissions]}
[{:keys [db]} all-dapp-permissions]
(let [dapp-permissions (reduce (fn [acc {:keys [dapp] :as dapp-permissions}]
@ -226,7 +226,7 @@
all-dapp-permissions)]
{:db (assoc db :dapps/permissions dapp-permissions)}))
(fx/defn initialize-browsers
(rf/defn initialize-browsers
{:events [::initialize-browsers]}
[{:keys [db]} all-stored-browsers]
(let [browsers (reduce (fn [acc {:keys [browser-id] :as browser}]
@ -235,7 +235,7 @@
all-stored-browsers)]
{:db (assoc db :browser/browsers browsers)}))
(fx/defn initialize-bookmarks
(rf/defn initialize-bookmarks
{:events [::initialize-bookmarks]}
[{:keys [db]} stored-bookmarks]
(let [bookmarks (reduce (fn [acc {:keys [url] :as bookmark}]
@ -244,7 +244,7 @@
stored-bookmarks)]
{:db (assoc db :bookmarks/bookmarks bookmarks)}))
(fx/defn initialize-invitations
(rf/defn initialize-invitations
{:events [::initialize-invitations]}
[{:keys [db]} invitations]
{:db (assoc db
@ -254,17 +254,17 @@
{}
invitations))})
(fx/defn initialize-web3-client-version
(rf/defn initialize-web3-client-version
{:events [::initialize-web3-client-version]}
[{:keys [db]} 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]}
[_]
{:ui/close-application nil})
(fx/defn check-network-version
(rf/defn check-network-version
[_ network-id]
{:json-rpc/call
[{:method "net_version"
@ -337,7 +337,7 @@
(.catch (fn [_]
(log/error "Failed to initialize wallet"))))))
(fx/defn initialize-browser
(rf/defn initialize-browser
[_]
{:json-rpc/call
[{:method "wakuext_getBrowsers"
@ -347,41 +347,41 @@
{:method "permissions_getDappPermissions"
:on-success #(re-frame/dispatch [::initialize-dapp-permissions %])}]})
(fx/defn initialize-appearance
(rf/defn initialize-appearance
[cofx]
{: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
[{:method "wakuext_getGroupChatInvitations"
:on-success #(re-frame/dispatch [::initialize-invitations %])}]})
(fx/defn initialize-communities-enabled
(rf/defn initialize-communities-enabled
[cofx]
{::initialize-communities-enabled nil})
(fx/defn initialize-transactions-management-enabled
(rf/defn initialize-transactions-management-enabled
[cofx]
{::initialize-transactions-management-enabled nil})
(fx/defn initialize-wallet-connect
(rf/defn initialize-wallet-connect
[cofx]
{::initialize-wallet-connect nil})
(fx/defn get-node-config-callback
(rf/defn get-node-config-callback
{:events [::get-node-config-callback]}
[{:keys [db] :as cofx} node-config-json]
(let [node-config (types/json->clj node-config-json)]
{:db (assoc-in db
[:multiaccount :wakuv2-config]
(get node-config :WakuV2Config))}))
[:multiaccount :wakuv2-config]
(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 %])))
(fx/defn get-settings-callback
(rf/defn get-settings-callback
{:events [::get-settings-callback]}
[{:keys [db] :as cofx} settings]
(let [{:networks/keys [current-network networks]
@ -392,7 +392,7 @@
;;for
;; existing accounts we have to merge them again into networks
merged-networks (merge networks config/default-networks-by-id)]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(dissoc :multiaccounts/login)
(assoc :networks/current-network current-network
@ -424,12 +424,12 @@
(when (= stored-key-uid key-uid)
(re-frame/dispatch [:chat.ui/navigate-to-chat chat-id])))))))))
(fx/defn check-last-chat
(rf/defn check-last-chat
{:events [::check-last-chat]}
[{:keys [db]}]
{::open-last-chat (get-in db [:multiaccount :key-uid])})
(fx/defn update-wallet-accounts
(rf/defn update-wallet-accounts
[{:keys [db]} accounts]
(let [existing-accounts (into {} (map #(vector (:address %1) %1) (:multiaccount/accounts db)))
reduce-fn (fn [existing-accs new-acc]
@ -440,7 +440,7 @@
new-accounts (reduce reduce-fn existing-accounts (rpc->accounts accounts))]
{:db (assoc db :multiaccount/accounts (vals new-accounts))}))
(fx/defn get-chats-callback
(rf/defn get-chats-callback
{:events [::get-chats-callback]}
[{:keys [db] :as cofx}]
(let [{:networks/keys [current-network networks]} db
@ -449,7 +449,7 @@
[current-network :config :NetworkId]))
remote-push-notifications-enabled?
(get-in db [:multiaccount :remote-push-notifications-enabled?])]
(fx/merge cofx
(rf/merge cofx
(cond-> {::eip1559/check-eip1559-activation
{:network-id network-id
:on-enabled #(log/info "eip1550 is activated")
@ -490,14 +490,14 @@
(re-frame/dispatch [:init-root (if config/new-ui-enabled? :shell-stack :chat-stack)])
(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?]
(let [auth-method (:auth-method db)
new-auth-method (get-new-auth-method auth-method save-password?)]
(log/debug "[login] login-only-events"
"auth-method" auth-method
"new-auth-method" new-auth-method)
(fx/merge cofx
(rf/merge cofx
{:db (assoc db :chats/loading? true)
:json-rpc/call
[{:method "settings_getSettings"
@ -509,7 +509,7 @@
(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?]
(let [{:keys [multiaccount
:multiaccounts/multiaccounts
@ -521,7 +521,7 @@
tos-accepted? (get db :tos/accepted?)
{:networks/keys [current-network networks]} db
network-id (str (get-in networks [current-network :config :NetworkId]))]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(dissoc :multiaccounts/login)
(assoc :tos/next-root :onboarding-notification :chats/loading? false)
@ -566,7 +566,7 @@
(assoc :logged-in-since now)
(assoc :view-id :home)))
(fx/defn multiaccount-login-success
(rf/defn multiaccount-login-success
[{:keys [db now] :as cofx}]
(let [{:keys [key-uid password save-password? creating?]}
(:multiaccounts/login db)
@ -583,7 +583,7 @@
(log/debug "[multiaccount] multiaccount-login-success"
"login-only?" login-only?
"recovered-account?" recovered-account?)
(fx/merge cofx
(rf/merge cofx
{:db (on-login-update-db db login-only? now)
:json-rpc/call
[{:method "web3_clientVersion"
@ -607,7 +607,7 @@
;; 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
;; make it clearer
(fx/defn open-login
(rf/defn open-login
[{:keys [db]} override-multiaccount]
{:db (-> db
(update :multiaccounts/login
@ -618,7 +618,7 @@
:error
:password))})
(fx/defn open-login-callback
(rf/defn open-login-callback
{:events [:multiaccounts.login.callback/get-user-password-success]}
[{:keys [db] :as cofx} password]
(let [key-uid (get-in db [:multiaccounts/login :key-uid])
@ -628,7 +628,7 @@
:keycard-pairing]))
goto-key-storage? (:goto-key-storage? db)]
(if password
(fx/merge
(rf/merge
cofx
{:db (update-in db
[:multiaccounts/login]
@ -637,7 +637,7 @@
:save-password? true)
:init-root-fx :progress}
login)
(fx/merge
(rf/merge
cofx
{:db (dissoc db :goto-key-storage?)}
(when keycard-account?
@ -650,7 +650,7 @@
#(when goto-key-storage?
(navigation/navigate-to-cofx % :actions-not-logged-in nil))))))
(fx/defn get-credentials
(rf/defn get-credentials
[{:keys [db] :as cofx} key-uid]
(let [keycard-multiaccount? (boolean (get-in db
[:multiaccounts/multiaccounts key-uid :keycard-pairing]))]
@ -661,7 +661,7 @@
(keychain/get-keycard-keys 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\""
{:events [:multiaccounts.login/get-auth-method-success]}
[{:keys [db] :as cofx} auth-method]
@ -671,7 +671,7 @@
(log/debug "[login] get-auth-method-success"
"auth-method" auth-method
"keycard-multiacc?" keycard-multiaccount?)
(fx/merge
(rf/merge
cofx
{:db (assoc db :auth-method auth-method)}
#(cond
@ -684,7 +684,7 @@
(keycard.common/get-application-info % nil))
(open-login-callback nil))))
(fx/defn biometric-auth-done
(rf/defn biometric-auth-done
{:events [:biometric-auth-done]}
[{:keys [db] :as cofx} {:keys [bioauth-success bioauth-message bioauth-code]}]
(let [key-uid (get-in db [:multiaccounts/login :key-uid])
@ -695,16 +695,16 @@
"bioauth-code" bioauth-code)
(if bioauth-success
(get-credentials cofx key-uid)
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db
[:multiaccounts/login :save-password?]
(= auth-method keychain/auth-method-biometric))}
[:multiaccounts/login :save-password?]
(= auth-method keychain/auth-method-biometric))}
(when-not (= auth-method keychain/auth-method-biometric)
(keychain/save-auth-method key-uid keychain/auth-method-none))
(biometric/show-message bioauth-message bioauth-code)
(open-login-callback nil)))))
(fx/defn save-password
(rf/defn save-password
{:events [:multiaccounts/save-password]}
[{:keys [db] :as cofx} save-password?]
(let [bioauth-supported? (boolean (get db :supported-biometric-auth))
@ -713,7 +713,7 @@
"save-password?" save-password?
"bioauth-supported?" bioauth-supported?
"previous-auth-method" previous-auth-method)
(fx/merge
(rf/merge
cofx
{:db (cond-> db
(not= previous-auth-method
@ -731,54 +731,54 @@
(when-not (= previous-auth-method keychain/auth-method-none)
(popover/show-popover {:view :disable-password-saving})))))))
(fx/defn welcome-lets-go
(rf/defn welcome-lets-go
{:events [:welcome-lets-go]}
[_]
{:init-root-fx :chat-stack})
(fx/defn multiaccount-selected
(rf/defn multiaccount-selected
{:events [:multiaccounts.login.ui/multiaccount-selected]}
[{:keys [db] :as cofx} key-uid]
;; 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])
keycard-multiaccount? (boolean (:keycard-pairing multiaccount))]
(fx/merge
(rf/merge
cofx
{:db (update db :keycard dissoc :application-info)
:navigate-to-fx (if keycard-multiaccount? :keycard-login-pin :login)}
(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]}
[{:keys [db]}]
{:db (assoc db :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]}
[{:keys [db]} {:keys [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]}
[_]
{::async-storage/get {:keys [:keycard-banner-hidden]
: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]}
[{:keys [db]} {:keys [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"
{:events [:get-opted-in-to-new-terms-of-service]}
[{:keys [db]}]
{::async-storage/get {:keys [:new-terms-of-service-accepted]
: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]}
[{:keys [db]}]
{::async-storage/set! {:new-terms-of-service-accepted true}

View File

@ -2,7 +2,7 @@
(:require [cljs.test :as test]
[status-im.multiaccounts.biometric.core :as biometric]
[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]))
(test/deftest save-password-test
@ -44,7 +44,7 @@
"uncheck save password")
(let [initial-cofx {:db {:auth-method keychain/auth-method-none
:supported-biometric-auth true}}
{:keys [db]} (login/save-password (fx/merge
{:keys [db]} (login/save-password (rf/merge
initial-cofx
(login/save-password true)
(biometric/enable)

View File

@ -4,16 +4,16 @@
[status-im.multiaccounts.core :as multiaccounts]
[status-im.native-module.core :as status]
[status-im.notifications.core :as notifications]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.keychain.core :as keychain]
[status-im.wallet.core :as wallet]
[status-im2.setup.events :as init]))
(fx/defn logout-method
(rf/defn logout-method
{:events [::logout-method]}
[{:keys [db] :as cofx} {:keys [auth-method logout?]}]
(let [key-uid (get-in db [:multiaccount :key-uid])]
(fx/merge cofx
(rf/merge cofx
{:init-root-fx :progress
:chat.ui/clear-inputs nil
:chat.ui/clear-inputs-old nil
@ -28,12 +28,12 @@
(wallet/clear-timeouts)
(init/initialize-app-db))))
(fx/defn logout
(rf/defn logout
{:events [:logout :multiaccounts.logout.ui/logout-confirmed
:multiaccounts.update.callback/save-settings-success]}
[cofx]
;; we need to disable notifications before starting the logout process
(fx/merge cofx
(rf/merge cofx
{:dispatch [:wallet-connect-legacy/clean-up-sessions]
:dispatch-later [{:ms 100
:dispatch [::logout-method
@ -41,7 +41,7 @@
:logout? true}]}]}
(notifications/logout-disable)))
(fx/defn show-logout-confirmation
(rf/defn show-logout-confirmation
{:events [:multiaccounts.logout.ui/logout-pressed]}
[_]
{:ui/show-confirmation
@ -51,10 +51,10 @@
:on-accept #(re-frame/dispatch [:multiaccounts.logout.ui/logout-confirmed])
:on-cancel nil}})
(fx/defn biometric-logout
(rf/defn biometric-logout
{:events [:biometric-logout]}
[cofx]
(fx/merge cofx
(rf/merge cofx
(logout-method {:auth-method keychain/auth-method-biometric-prepare
:logout? false})
(fn [{:keys [db]}]

View File

@ -11,7 +11,7 @@
[status-im.multiaccounts.create.core :as multiaccounts.create]
[status-im.native-module.core :as status]
[status-im.popover.core :as popover]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.types :as types]
[status-im.utils.utils :as utils]
[status-im2.navigation.events :as navigation]
@ -27,11 +27,11 @@
[recovery-phrase]
(cond (string/blank? recovery-phrase) :t/required-field))
(fx/defn set-phrase
(rf/defn set-phrase
{:events [:multiaccounts.recover/passphrase-input-changed]}
[{:keys [db]} masked-recovery-phrase]
(let [recovery-phrase (security/safe-unmask-data masked-recovery-phrase)]
(fx/merge
(rf/merge
{:db (update db
:intro-wizard assoc
:passphrase (string/lower-case recovery-phrase)
@ -39,14 +39,14 @@
:next-button-disabled? (or (empty? recovery-phrase)
(not (mnemonic/valid-length? recovery-phrase))))})))
(fx/defn validate-phrase-for-warnings
(rf/defn validate-phrase-for-warnings
[{:keys [db]}]
(let [recovery-phrase (get-in db [:intro-wizard :passphrase])]
{:db (update db
:intro-wizard assoc
:passphrase-error (check-phrase-warnings recovery-phrase))}))
(fx/defn on-store-multiaccount-success
(rf/defn on-store-multiaccount-success
{:events [::store-multiaccount-success]
:interceptors [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]}
@ -75,7 +75,7 @@
password
{})))))))
(fx/defn store-multiaccount
(rf/defn store-multiaccount
{:events [::recover-multiaccount-confirmed]}
[{:keys [db]} password]
(let [{:keys [root-key]} (:intro-wizard db)
@ -116,7 +116,7 @@
{:name name :identicon identicon})]
(re-frame/dispatch [success-event root-data derived-data-extended]))))))))))))
(fx/defn show-existing-multiaccount-alert
(rf/defn show-existing-multiaccount-alert
[_ key-uid]
{:utils/show-confirmation
{:title (i18n/label :t/multiaccount-exists-title)
@ -128,11 +128,11 @@
[:multiaccounts.login.ui/multiaccount-selected key-uid]))
: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]}
[{:keys [db] :as cofx} {:keys [key-uid] :as root-data} derived-data]
(let [multiaccounts (:multiaccounts/multiaccounts db)]
(fx/merge
(rf/merge
cofx
{:db (update db
:intro-wizard
@ -144,10 +144,10 @@
(show-existing-multiaccount-alert key-uid))
(navigation/navigate-to-cofx :recover-multiaccount-success nil))))
(fx/defn enter-phrase-pressed
(rf/defn enter-phrase-pressed
{:events [::enter-phrase-pressed]}
[{:keys [db] :as cofx}]
(fx/merge
(rf/merge
cofx
{:db (-> db
(assoc :intro-wizard
@ -162,7 +162,7 @@
(bottom-sheet/hide-bottom-sheet)
(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]}
[{:keys [db] :as cofx} phrase-warnings]
(let [{:keys [password passphrase]} (:intro-wizard db)]
@ -174,7 +174,7 @@
(security/safe-unmask-data password))
:success-event ::import-multiaccount-success}}))))
(fx/defn seed-phrase-next-pressed
(rf/defn seed-phrase-next-pressed
{:events [:multiaccounts.recover/enter-phrase-next-pressed]}
[{:keys [db] :as cofx}]
(let [{:keys [passphrase]} (:intro-wizard db)]
@ -182,17 +182,17 @@
#(re-frame/dispatch [:multiaccounts.recover/phrase-validated
%])]}))
(fx/defn continue-to-import-mnemonic
(rf/defn continue-to-import-mnemonic
{:events [::continue-pressed]}
[{:keys [db] :as cofx}]
(let [{:keys [password passphrase]} (:multiaccounts/recover db)]
(fx/merge cofx
(rf/merge cofx
{::import-multiaccount {:passphrase passphrase
:password password
:success-event ::import-multiaccount-success}}
(popover/hide-popover))))
(fx/defn dec-step
(rf/defn dec-step
{:events [:multiaccounts.recover/dec-step]}
[{:keys [db] :as cofx}]
(let [step (get-in db [:intro-wizard :step])]
@ -208,7 +208,7 @@
:confirm-failure? false
:key-code nil)})))
(fx/defn cancel-pressed
(rf/defn cancel-pressed
{:events [:multiaccounts.recover/cancel-pressed]}
[{:keys [db] :as cofx} skip-alert?]
;; Workaround for multiple Cancel button clicks
@ -220,11 +220,11 @@
(i18n/label :t/are-you-sure-to-cancel)
(i18n/label :t/you-will-start-from-scratch)
#(re-frame/dispatch [:multiaccounts.recover/cancel-pressed true]))
(fx/merge cofx
(rf/merge cofx
dec-step
navigation/navigate-back)))))
(fx/defn select-storage-next-pressed
(rf/defn select-storage-next-pressed
{:events [:multiaccounts.recover/select-storage-next-pressed]
:interceptors [(re-frame/inject-cofx :random-guid-generator)]}
[{:keys [db] :as cofx}]
@ -232,14 +232,14 @@
(if (= storage-type :advanced)
;;TODO: fix circular dependency to remove dispatch here
{:dispatch [:recovery.ui/keycard-option-pressed]}
(fx/merge cofx
(rf/merge cofx
{:db (update db :intro-wizard assoc :step :create-code)}
(navigation/navigate-to-cofx :create-password nil)))))
(fx/defn re-encrypt-pressed
(rf/defn re-encrypt-pressed
{:events [:multiaccounts.recover/re-encrypt-pressed]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (update db
:intro-wizard
assoc
@ -249,35 +249,35 @@
(navigation/navigate-to-cofx :select-key-storage nil)
(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]
:interceptors [(re-frame/inject-cofx :random-guid-generator)]}
[cofx key-code]
(store-multiaccount cofx key-code))
(fx/defn count-words
(rf/defn count-words
[{:keys [db]}]
(let [passphrase (get-in db [:intro-wizard :passphrase])]
{:db (assoc-in db
[:intro-wizard :passphrase-word-count]
(mnemonic/words-count passphrase))}))
[:intro-wizard :passphrase-word-count]
(mnemonic/words-count passphrase))}))
(fx/defn run-validation
(rf/defn run-validation
[{:keys [db] :as cofx}]
(let [passphrase (get-in db [:intro-wizard :passphrase])]
(when (= (last passphrase) " ")
(fx/merge cofx
(rf/merge cofx
(validate-phrase-for-warnings)))))
(fx/defn enter-phrase-input-changed
(rf/defn enter-phrase-input-changed
{:events [:multiaccounts.recover/enter-phrase-input-changed]}
[cofx input]
(fx/merge cofx
(rf/merge cofx
(set-phrase input)
(count-words)
(run-validation)))
(fx/defn enter-passphrase-input-changed
(rf/defn enter-passphrase-input-changed
{:events [:multiaccounts.recover/enter-passphrase-input-changed]}
[{:keys [db]} masked-passphrase]
{:db (update db

View File

@ -4,12 +4,12 @@
[status-im.ethereum.core :as ethereum]
[status-im.native-module.core :as status]
[status-im.popover.core :as popover]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.keychain.core :as keychain]
[status-im.utils.types :as types]
[utils.security.core :as security]))
(fx/defn on-input-change
(rf/defn on-input-change
{:events [::handle-input-change]}
[{:keys [db]} input-id value]
(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-errors input-id] error))}))
(fx/defn clear-form-vals
(rf/defn clear-form-vals
{:events [::clear-form-vals]}
[{:keys [db]}]
{: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]}
[{:keys [db]} 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]}
[{:keys [db] :as cofx}]
(let [{:keys [key-uid]} (:multiaccount db)
auth-method (get db :auth-method keychain/auth-method-none)
new-password (get-in db [:multiaccount/reset-password-form-vals :new-password])]
(fx/merge cofx
(rf/merge cofx
{:db (dissoc
db
:multiaccount/reset-password-form-vals
@ -65,11 +65,11 @@
(ethereum/sha3 (security/safe-unmask-data new-password))
change-db-password-cb)))
(fx/defn handle-verification-success
(rf/defn handle-verification-success
{:events [::handle-verification-success]}
[{:keys [db] :as cofx} form-vals]
(let [{:keys [key-uid name]} (:multiaccount db)]
(fx/merge cofx
(rf/merge cofx
{::change-db-password [key-uid form-vals]
:db (assoc db
:multiaccount/resetting-password?
@ -92,7 +92,7 @@
hashed-pass
(partial handle-verification form-vals)))))
(fx/defn reset
(rf/defn reset
{:events [::reset]}
[{:keys [db]} form-vals]
{::validate-current-password-and-reset

View File

@ -1,10 +1,10 @@
(ns status-im.multiaccounts.update.core
(:require [status-im.constants :as constants]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.types :as types]
[taoensso.timbre :as log]))
(fx/defn send-multiaccount-update
(rf/defn send-multiaccount-update
[{:keys [db] :as cofx}]
(let [multiaccount (:multiaccount db)
{:keys [name preferred-name address]} multiaccount]
@ -12,7 +12,7 @@
:params [(or preferred-name name) ""]
: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.
Optionally, one can specify a success-event to be dispatched after fields are persisted."
[{:keys [db] :as cofx}
@ -25,7 +25,7 @@
(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
(assoc-in db [:multiaccount setting] setting-value)
(update db :multiaccount dissoc setting))
@ -37,7 +37,7 @@
(#{:name :prefered-name} setting))
(send-multiaccount-update))))))
(fx/defn clean-seed-phrase
(rf/defn clean-seed-phrase
"A helper function that removes seed phrase from storage."
[cofx on-success]
(multiaccount-update cofx :mnemonic nil on-success))
@ -55,7 +55,7 @@
(:url)))
synced-stickers))
(fx/defn optimistic
(rf/defn optimistic
[{:keys [db] :as cofx} setting setting-value]
(let [current-multiaccount (:multiaccount db)
setting-value (if (= :currency setting)
@ -68,8 +68,8 @@
:stickers/packs-installed
(let [packs-installed-keys (keys (js->clj setting-value))]
(reduce #(assoc-in %1
[:stickers/packs %2 :status]
constants/sticker-pack-status-installed)
[:stickers/packs %2 :status]
constants/sticker-pack-status-installed)
db
packs-installed-keys))
:stickers/recent-stickers
@ -84,9 +84,9 @@
(assoc-in db [:multiaccount setting] setting-value)
(update db :multiaccount dissoc setting))}))
(fx/defn set-many-js
(rf/defn set-many-js
[cofx settings-js]
(apply fx/merge
(apply rf/merge
cofx
(map
#(optimistic
@ -94,15 +94,15 @@
(.-value %))
settings-js)))
(fx/defn toggle-backup-enabled
(rf/defn toggle-backup-enabled
{:events [:multiaccounts.ui/switch-backup-enabled]}
[cofx enabled?]
(multiaccount-update cofx :backup-enabled? enabled? {}))
(fx/defn toggle-opensea-nfts-visibility
(rf/defn toggle-opensea-nfts-visibility
{:events [::toggle-opensea-nfts-visiblity]}
[cofx visible?]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in (:db cofx) [:multiaccount :opensea-enabled?] visible?)
;; need to add fully qualified namespace to counter circular deps
:dispatch [:status-im.wallet.core/fetch-collectibles-collection]}

View File

@ -12,7 +12,7 @@
[status-im.ui.components.icons.icons :as icons]
[status-im.ui.components.react :as react]
[status-im.ui.screens.views :as views]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.platform :as platform]
[taoensso.timbre :as log]))
@ -21,7 +21,7 @@
(def splash-screen (-> rn .-NativeModules .-SplashScreen))
(defonce set-navigation-default-options
(.setDefaultOptions Navigation (clj->js {:layout {:orientation "portrait"}})))
(.setDefaultOptions Navigation (clj->js {:layout {:orientation "portrait"}})))
;; REGISTER COMPONENT (LAZY)
(defn reg-comp
@ -33,7 +33,7 @@
(.registerComponent Navigation key (fn [] (gestureHandlerRootHOC screen)) (fn [] screen)))))
(defonce rset-lazy-reg
(.setLazyComponentRegistrator Navigation reg-comp))
(.setLazyComponentRegistrator Navigation reg-comp))
(defn dismiss-all-modals
[]
@ -104,17 +104,17 @@
(.dismissModal Navigation (name (last @state/modals))))
(defonce register-nav-button-reg
(.registerNavigationButtonPressedListener
(.events Navigation)
(fn [^js evn]
(let [id (.-buttonId evn)]
(if (= "dismiss-modal" id)
(do
(when-let [event (get-in views/screens [(last @state/modals) :on-dissmiss])]
(re-frame/dispatch event))
(dissmissModal))
(when-let [handler (get-in views/screens [(keyword id) :right-handler])]
(handler)))))))
(.registerNavigationButtonPressedListener
(.events Navigation)
(fn [^js evn]
(let [id (.-buttonId evn)]
(if (= "dismiss-modal" id)
(do
(when-let [event (get-in views/screens [(last @state/modals) :on-dissmiss])]
(re-frame/dispatch event))
(dissmissModal))
(when-let [handler (get-in views/screens [(keyword id) :right-handler])]
(handler)))))))
(defn set-view-id
[view-id]
@ -126,53 +126,53 @@
(re-frame/dispatch on-focus))))
(defonce register-modal-reg
(.registerModalDismissedListener
(.events Navigation)
(fn [_]
(if (> (count @state/modals) 1)
(let [new-modals (butlast @state/modals)]
(reset! state/modals (vec new-modals))
(set-view-id (last new-modals)))
(do
(reset! state/modals [])
(reset! state/curr-modal false)
(set-view-id @state/pushed-screen-id)))
(.registerModalDismissedListener
(.events Navigation)
(fn [_]
(if (> (count @state/modals) 1)
(let [new-modals (butlast @state/modals)]
(reset! state/modals (vec new-modals))
(set-view-id (last new-modals)))
(do
(reset! state/modals [])
(reset! state/curr-modal false)
(set-view-id @state/pushed-screen-id)))
(let [comp @state/dissmissing]
(reset! state/dissmissing false)
(when (keyword? comp)
(open-modal comp))))))
(let [comp @state/dissmissing]
(reset! state/dissmissing false)
(when (keyword? comp)
(open-modal comp))))))
;; SCREEN DID APPEAR
(defonce screen-appear-reg
(.registerComponentDidAppearListener
(.events Navigation)
(fn [^js evn]
(let [view-id (keyword (.-componentName evn))]
(log/debug "screen-appear-reg" view-id)
(when (get views/screens view-id)
(when (and (not= view-id :bottom-sheet)
(not= view-id :popover)
(not= view-id :visibility-status-popover))
(set-view-id view-id)
(when-not @state/curr-modal
(reset! state/pushed-screen-id view-id))))))))
(.registerComponentDidAppearListener
(.events Navigation)
(fn [^js evn]
(let [view-id (keyword (.-componentName evn))]
(log/debug "screen-appear-reg" view-id)
(when (get views/screens view-id)
(when (and (not= view-id :bottom-sheet)
(not= view-id :popover)
(not= view-id :visibility-status-popover))
(set-view-id view-id)
(when-not @state/curr-modal
(reset! state/pushed-screen-id view-id))))))))
;; SCREEN DID DISAPPEAR
(defonce screen-disappear-reg
(.registerComponentDidDisappearListener
(.events Navigation)
(fn [^js evn]
(let [view-id (keyword (.-componentName evn))]
(when-not (#{"popover" "bottom-sheet" "signing-sheet" "visibility-status-popover"
"wallet-connect-sheet" "wallet-connect-success-sheet"
"wallet-connect-app-management-sheet"}
(.-componentName evn))
(re-frame/dispatch [::view-disappeared view-id])
(doseq [[_ {:keys [ref value]}] @quo.text-input/text-input-refs]
(.setNativeProps ^js ref (clj->js {:text value})))
(doseq [[^js text-input default-value] @react/text-input-refs]
(.setNativeProps text-input (clj->js {:text default-value}))))))))
(.registerComponentDidDisappearListener
(.events Navigation)
(fn [^js evn]
(let [view-id (keyword (.-componentName evn))]
(when-not (#{"popover" "bottom-sheet" "signing-sheet" "visibility-status-popover"
"wallet-connect-sheet" "wallet-connect-success-sheet"
"wallet-connect-app-management-sheet"}
(.-componentName evn))
(re-frame/dispatch [::view-disappeared view-id])
(doseq [[_ {:keys [ref value]}] @quo.text-input/text-input-refs]
(.setNativeProps ^js ref (clj->js {:text value})))
(doseq [[^js text-input default-value] @react/text-input-refs]
(.setNativeProps text-input (clj->js {:text default-value}))))))))
;; SET ROOT
(re-frame/reg-fx
@ -191,7 +191,7 @@
(reset! state/root-id @state/root-comp-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]}
[{:keys [db]}]
(log/debug :set-multiaccounts-root)
@ -203,19 +203,19 @@
{:init-root-fx (if keycard-account? :multiaccounts-keycard :multiaccounts)}))
(defonce
rset-app-launched
(.registerAppLaunchedListener (.events Navigation)
(fn []
(reset! state/curr-modal false)
(reset! state/dissmissing false)
(if (or (= @state/root-id :multiaccounts)
(= @state/root-id :multiaccounts-keycard))
(re-frame/dispatch-sync [::set-multiaccount-root])
(when @state/root-id
(reset! state/root-comp-id @state/root-id)
(.setRoot Navigation (clj->js (get (roots/roots) @state/root-id)))
(re-frame/dispatch [::login-core/check-last-chat])))
(.hide ^js splash-screen))))
rset-app-launched
(.registerAppLaunchedListener (.events Navigation)
(fn []
(reset! state/curr-modal false)
(reset! state/dissmissing false)
(if (or (= @state/root-id :multiaccounts)
(= @state/root-id :multiaccounts-keycard))
(re-frame/dispatch-sync [::set-multiaccount-root])
(when @state/root-id
(reset! state/root-comp-id @state/root-id)
(.setRoot Navigation (clj->js (get (roots/roots) @state/root-id)))
(re-frame/dispatch [::login-core/check-last-chat])))
(.hide ^js splash-screen))))
(defn get-screen-component
[comp]
@ -294,19 +294,19 @@
(.popToRoot Navigation (name comp))))
(defonce register-bottom-tab-reg
(.registerBottomTabSelectedListener
(.events Navigation)
(fn [^js evn]
(let [selected-tab-index (.-selectedTabIndex evn)
comp (get tab-root-ids selected-tab-index)
tab-key (get (clojure.set/map-invert tab-key-idx) selected-tab-index)]
(re-frame/dispatch [:set :current-tab tab-key])
(when (= @state/root-comp-id comp)
(when (= :chat tab-key)
(re-frame/dispatch [:close-chat]))
(when platform/android?
(.popToRoot Navigation (name comp))))
(reset! state/root-comp-id comp)))))
(.registerBottomTabSelectedListener
(.events Navigation)
(fn [^js evn]
(let [selected-tab-index (.-selectedTabIndex evn)
comp (get tab-root-ids selected-tab-index)
tab-key (get (clojure.set/map-invert tab-key-idx) selected-tab-index)]
(re-frame/dispatch [:set :current-tab tab-key])
(when (= @state/root-comp-id comp)
(when (= :chat tab-key)
(re-frame/dispatch [:close-chat]))
(when platform/android?
(.popToRoot Navigation (name comp))))
(reset! state/root-comp-id comp)))))
;; OVERLAY (Popover and bottom sheets)
(defn dissmiss-overlay
@ -331,20 +331,20 @@
;; POPOVER
(defonce popover-reg
(.registerComponent Navigation
"popover"
(fn [] (gestureHandlerRootHOC views/popover-comp))
(fn [] views/popover-comp)))
(.registerComponent Navigation
"popover"
(fn [] (gestureHandlerRootHOC views/popover-comp))
(fn [] views/popover-comp)))
(re-frame/reg-fx :show-popover (fn [] (show-overlay "popover")))
(re-frame/reg-fx :hide-popover (fn [] (dissmiss-overlay "popover")))
;; VISIBILITY STATUS POPOVER
(defonce visibility-status-popover-reg
(.registerComponent Navigation
"visibility-status-popover"
(fn [] (gestureHandlerRootHOC views/visibility-status-popover-comp))
(fn [] views/visibility-status-popover-comp)))
(.registerComponent Navigation
"visibility-status-popover"
(fn [] (gestureHandlerRootHOC views/visibility-status-popover-comp))
(fn [] views/visibility-status-popover-comp)))
(re-frame/reg-fx :show-visibility-status-popover
(fn [] (show-overlay "visibility-status-popover")))
@ -353,10 +353,10 @@
;; BOTTOM SHEETS
(defonce bottom-sheet-reg
(.registerComponent Navigation
"bottom-sheet"
(fn [] (gestureHandlerRootHOC views/sheet-comp))
(fn [] views/sheet-comp)))
(.registerComponent Navigation
"bottom-sheet"
(fn [] (gestureHandlerRootHOC views/sheet-comp))
(fn [] views/sheet-comp)))
(re-frame/reg-fx :show-bottom-sheet (fn [] (show-overlay "bottom-sheet")))
(re-frame/reg-fx :hide-bottom-sheet (fn [] (dissmiss-overlay "bottom-sheet")))
@ -364,22 +364,22 @@
;; WALLET CONNECT
(defonce wallet-connect-sheet-reg
(.registerComponent Navigation
"wallet-connect-sheet"
(fn [] (gestureHandlerRootHOC views/wallet-connect-comp))
(fn [] views/wallet-connect-comp)))
(.registerComponent Navigation
"wallet-connect-sheet"
(fn [] (gestureHandlerRootHOC views/wallet-connect-comp))
(fn [] views/wallet-connect-comp)))
(defonce wallet-connect-success-sheet-reg
(.registerComponent Navigation
"wallet-connect-success-sheet"
(fn [] (gestureHandlerRootHOC views/wallet-connect-success-comp))
(fn [] views/wallet-connect-success-comp)))
(.registerComponent Navigation
"wallet-connect-success-sheet"
(fn [] (gestureHandlerRootHOC views/wallet-connect-success-comp))
(fn [] views/wallet-connect-success-comp)))
(defonce wallet-connect-app-management-sheet-reg
(.registerComponent Navigation
"wallet-connect-app-management-sheet"
(fn [] (gestureHandlerRootHOC views/wallet-connect-app-management-comp))
(fn [] views/wallet-connect-app-management-comp)))
(.registerComponent Navigation
"wallet-connect-app-management-sheet"
(fn [] (gestureHandlerRootHOC views/wallet-connect-app-management-comp))
(fn [] views/wallet-connect-app-management-comp)))
(re-frame/reg-fx :show-wallet-connect-sheet (fn [] (show-overlay "wallet-connect-sheet")))
(re-frame/reg-fx :hide-wallet-connect-sheet (fn [] (dissmiss-overlay "wallet-connect-sheet")))
@ -395,10 +395,10 @@
;; SIGNING
(defonce signing-sheet-reg
(.registerComponent Navigation
"signing-sheet"
(fn [] (gestureHandlerRootHOC views/signing-comp))
(fn [] views/signing-comp)))
(.registerComponent Navigation
"signing-sheet"
(fn [] (gestureHandlerRootHOC views/signing-comp))
(fn [] views/signing-comp)))
(re-frame/reg-fx :show-signing-sheet (fn [] (show-overlay "signing-sheet")))
(re-frame/reg-fx :hide-signing-sheet (fn [] (dissmiss-overlay "signing-sheet")))
@ -407,10 +407,10 @@
;; TODO why is this not a regular bottom sheet ?
(defonce select-acc-sheet-reg
(.registerComponent Navigation
"select-acc-sheet"
(fn [] (gestureHandlerRootHOC views/select-acc-comp))
(fn [] views/select-acc-comp)))
(.registerComponent Navigation
"select-acc-sheet"
(fn [] (gestureHandlerRootHOC views/select-acc-comp))
(fn [] views/select-acc-comp)))
(re-frame/reg-fx :show-select-acc-sheet (fn [] (show-overlay "select-acc-sheet")))
(re-frame/reg-fx :hide-select-acc-sheet (fn [] (dissmiss-overlay "select-acc-sheet")))
@ -451,7 +451,7 @@
;; change view-id if it is still same after component is disappeared
;; https://github.com/wix/react-native-navigation/issues/5744#issuecomment-563226820
(fx/defn view-disappeared
(rf/defn view-disappeared
{:events [::view-disappeared]}
[{:keys [db]} view-id]
(when (= view-id (:view-id db))

View File

@ -4,7 +4,7 @@
[status-im.ethereum.core :as ethereum]
[status-im.i18n.i18n :as i18n]
[status-im.node.core :as node]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.http :as http]
[status-im.utils.types :as types]
[status-im2.navigation.events :as navigation]))
@ -63,7 +63,7 @@
[{:keys [db]} network-id]
(get-in db [:networks/networks network-id]))
(fx/defn set-input
(rf/defn set-input
{:events [::input-changed]}
[{:keys [db]} input-key value]
{:db (-> db
@ -71,13 +71,13 @@
(update-in [:networks/manage] validate-manage))})
;; No edit functionality actually implemented
(fx/defn edit
(rf/defn edit
{:events [::add-network-pressed]}
[{db :db}]
{:db (assoc db :networks/manage (validate-manage default-manage))
:dispatch [:navigate-to :edit-network]})
(fx/defn connect-success
(rf/defn connect-success
{:events [::connect-success]}
[_ network-id]
{:ui/show-confirmation
@ -87,14 +87,14 @@
:on-accept #(re-frame/dispatch [::save-network-settings-pressed network-id])
:on-cancel nil}})
(fx/defn connect-failure
(rf/defn connect-failure
{:events [::connect-failure]}
[_ reason]
{:utils/show-popup
{:title (i18n/label :t/error)
:content (str reason)}})
(fx/defn connect
(rf/defn connect
{:events [::connect-network-pressed]}
[{:keys [db] :as cofx} network-id]
(if-let [config (get-in db [:networks/networks network-id :config])]
@ -124,7 +124,7 @@
(connect-success cofx network-id))
(connect-failure cofx "A network with the specified id doesn't exist")))
(fx/defn delete
(rf/defn delete
{:events [::delete-network-pressed]}
[{:keys [db]} network]
(let [current-network? (= (:networks/current-network db) network)]
@ -138,17 +138,17 @@
network])
:on-cancel nil}})))
(fx/defn save-network-settings
(rf/defn save-network-settings
{:events [::save-network-settings-pressed]}
[{:keys [db] :as cofx} network]
(fx/merge cofx
(rf/merge cofx
{:db (assoc db :networks/current-network network)
:json-rpc/call [{:method "settings_saveSetting"
:params [:networks/current-network network]
:on-success #()}]}
(node/prepare-new-config {:on-success #(re-frame/dispatch [:logout])})))
(fx/defn remove-network
(rf/defn remove-network
{:events [::remove-network-confirmed]}
[{:keys [db] :as cofx} network]
(let [networks (dissoc (:networks/networks db) network)]
@ -170,7 +170,7 @@
:symbol symbol
:config config}))
(fx/defn save
(rf/defn save
{:events [::save-network-pressed]
:interceptors [(re-frame/inject-cofx :random-id-generator)]}
[{{:networks/keys [manage networks] :as db} :db
@ -199,7 +199,7 @@
{:ui/show-error "chain-id already defined"}))
{:ui/show-error "invalid network parameters"}))
(fx/defn open-network-details
(rf/defn open-network-details
{:events [::network-entry-pressed]}
[cofx network]
(navigation/navigate-to-cofx cofx :network-details {:networks/selected-network network}))

View File

@ -3,13 +3,13 @@
[re-frame.core :as re-frame]
[status-im.mobile-sync-settings.core :as mobile-network]
[status-im.native-module.core :as status]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.wallet.core :as wallet]
[taoensso.timbre :as log]))
(fx/defn change-network-status
(rf/defn change-network-status
[{:keys [db] :as cofx} is-connected?]
(fx/merge cofx
(rf/merge cofx
{:db (assoc db :network-status (if is-connected? :online :offline))}
(when (and is-connected?
(or (not= (count (get-in db [:wallet :accounts]))
@ -17,14 +17,14 @@
(wallet/has-empty-balances? db)))
(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?]
(fx/merge cofx
(rf/merge cofx
{:db (assoc db :network/type network-type)
:network/notify-status-go [network-type expensive?]}
(mobile-network/on-network-status-change)))
(fx/defn handle-network-info-change
(rf/defn handle-network-info-change
{:events [::network-info-changed]}
[{:keys [db] :as cofx} {:keys [isConnected type details] :as state}]
(let [old-network-status (:network-status db)
@ -38,7 +38,7 @@
"connectivity-status" connectivity-status
"type" type
"details" details)
(fx/merge cofx
(rf/merge cofx
(when-not status-changed?
(change-network-status isConnected))
(when-not type-changed?

View File

@ -2,7 +2,7 @@
(:require [re-frame.core :as re-frame]
[status-im.native-module.core :as status]
[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.types :as types]))
@ -189,7 +189,7 @@
[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
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`,
@ -201,7 +201,7 @@ app-db"
:params [:node-config config]
: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"
[{:keys [db]} {:keys [on-success]}]
(let [key-uid (get-in db [:multiaccount :key-uid])]

View File

@ -6,7 +6,7 @@
[status-im.notifications.android :as pn-android]
[status-im.notifications.local :as local]
[status-im.utils.config :as config]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[taoensso.timbre :as log]))
(def server-type-default 1)
@ -64,7 +64,7 @@
::request-permission
identity)
(fx/defn request-permission
(rf/defn request-permission
{:events [::request-permission]}
[_]
{::request-permission true})
@ -108,7 +108,7 @@
(doseq [chat-id chat-ids]
(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]}
[cofx token]
{:json-rpc/call [{:method "wakuext_registerForPushNotifications"
@ -117,7 +117,7 @@
:on-success #(log/info "[push-notifications] register-success" %)
: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]}
[cofx]
{:json-rpc/call [{:method "wakuext_unregisterFromPushNotifications"
@ -125,7 +125,7 @@
:on-success #(log/info "[push-notifications] unregister-success" %)
:on-error #(re-frame/dispatch [:notifications/switch-error false %])}]})
(fx/defn logout-disable
(rf/defn logout-disable
[cofx]
(merge {::logout-disable nil}
{:json-rpc/call [{:method "wakuext_unregisterFromPushNotifications"
@ -133,7 +133,7 @@
:on-success #(log/info "[push-notifications] unregister-success" %)
:on-error #(log/info "[push-notifications] unregister-error" %)}]}))
(fx/defn notification-switch-error
(rf/defn notification-switch-error
{:events [:notifications/switch-error]}
[cofx enabled?]
(multiaccounts.update/multiaccount-update
@ -142,10 +142,10 @@
(not enabled?)
{}))
(fx/defn notification-switch
(rf/defn notification-switch
{:events [::switch]}
[{:keys [db] :as cofx} enabled? remote-push-notifications?]
(fx/merge cofx
(rf/merge cofx
(if enabled?
{::enable remote-push-notifications?}
{::disable nil})
@ -158,25 +158,25 @@
(and (not remote-push-notifications?) enabled?)
{})))
(fx/defn notification-non-contacts-error
(rf/defn notification-non-contacts-error
{:events [::non-contacts-update-error]}
[cofx 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]}
[cofx 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]}
[{:keys [db] :as cofx} enabled?]
(let [method (if enabled?
"wakuext_enablePushNotificationsFromContactsOnly"
"wakuext_disablePushNotificationsFromContactsOnly")]
(fx/merge
(rf/merge
cofx
{:json-rpc/call [{:method method
:params []
@ -185,14 +185,14 @@
(multiaccounts.update/optimistic :push-notifications-from-contacts-only? (boolean enabled?)))))
(fx/defn notification-block-mentions
(rf/defn notification-block-mentions
{:events [::switch-block-mentions]}
[{:keys [db] :as cofx} enabled?]
(let [method (if enabled?
"wakuext_enablePushNotificationsBlockMentions"
"wakuext_disablePushNotificationsBlockMentions")]
(log/info "USING METHOD" method enabled?)
(fx/merge cofx
(rf/merge cofx
{:json-rpc/call [{:method method
:params []
:on-success #(log/info "[push-notifications] block-mentions-success" %)
@ -201,13 +201,13 @@
(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]}
[{:keys [db] :as cofx} enabled?]
(let [method (if enabled?
"wakuext_startPushNotificationsServer"
"wakuext_stopPushNotificationsServer")]
(fx/merge
(rf/merge
cofx
{:json-rpc/call [{:method method
:params []
@ -217,13 +217,13 @@
(multiaccounts.update/optimistic :push-notifications-server-enabled? (boolean enabled?)))))
(fx/defn switch-send-notifications
(rf/defn switch-send-notifications
{:events [::switch-send-push-notifications]}
[{:keys [db] :as cofx} enabled?]
(let [method (if enabled?
"wakuext_enableSendingNotifications"
"wakuext_disableSendingNotifications")]
(fx/merge cofx
(rf/merge cofx
{:json-rpc/call [{:method method
:params []
:on-success
@ -234,15 +234,15 @@
(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]}
[_ public-key error]
(log/error "failed to add server" public-key error))
(fx/defn add-server
(rf/defn add-server
{:events [::add-server]}
[{:keys [db] :as cofx} public-key]
(fx/merge cofx
(rf/merge cofx
{:json-rpc/call [{:method "wakuext_addPushNotificationsServer"
:params [public-key]
:on-success
@ -253,12 +253,12 @@
: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]}
[{:keys [db]} 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]}
[cofx]
{:json-rpc/call [{:method "wakuext_getPushNotificationsServers"
@ -269,12 +269,12 @@
;; Wallet transactions
(fx/defn handle-preferences-load
(rf/defn handle-preferences-load
{:events [::preferences-loaded]}
[{:keys [db]} preferences]
{:db (assoc db :push-notifications/preferences preferences)})
(fx/defn load-notification-preferences
(rf/defn load-notification-preferences
{:events [::load-notification-preferences]}
[cofx]
{:json-rpc/call [{:method "localnotifications_notificationPreferences"
@ -291,7 +291,7 @@
[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]}
[{:keys [db] :as cofx} enabled?]
{:db (update db

View File

@ -10,7 +10,7 @@
[status-im.ethereum.tokens :as tokens]
[status-im.i18n.i18n :as i18n]
[status-im.notifications.android :as pn-android]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.money :as money]
[status-im.utils.react-native :as react-native-utils]
[status-im.utils.types :as types]
@ -56,7 +56,7 @@
notification-event-ios
(fn [notification]
(handle-notification-press {:userInfo (bean/bean (.getData ^js
notification))})))
notification))})))
(.addListener ^js react-native-utils/device-event-emitter
notification-event-android
(fn [^js data]
@ -132,14 +132,14 @@
(fn [evt]
(-> evt create-notification local-push-ios)))
(fx/defn local-notification-android
(rf/defn local-notification-android
{:events [::local-notification-android]}
[cofx event]
(some->> event
(create-notification cofx)
local-push-android))
(fx/defn process
(rf/defn process
[cofx evt]
(if platform/ios?
{::local-push-ios evt}

View File

@ -3,7 +3,7 @@
[status-im.i18n.i18n :as i18n]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[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-im2.common.json-rpc.events :as json-rpc]
[status-im2.navigation.events :as navigation]
@ -56,26 +56,26 @@
[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]}
[_]
{:json-rpc/call [{:method "wakuext_sendPairInstallation"
:params []
:on-success #(log/info "sent pair installation message")}]})
(fx/defn prompt-dismissed
(rf/defn prompt-dismissed
{:events [:pairing.ui/prompt-dismissed]}
[{:keys [db]}]
{:db (assoc-in db [:pairing/prompt-user-pop-up] false)})
(fx/defn prompt-accepted
(rf/defn prompt-accepted
{:events [:pairing.ui/prompt-accepted]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:pairing/prompt-user-pop-up] false)}
(navigation/navigate-to-cofx :installations nil)))
(fx/defn prompt-user-on-new-installation
(rf/defn prompt-user-on-new-installation
[{:keys [db]}]
(when-not config/pairing-popup-disabled?
{:db (assoc-in db [:pairing/prompt-user-pop-up] true)
@ -87,7 +87,7 @@
:on-cancel #(re-frame/dispatch [:pairing.ui/prompt-dismissed])
:on-accept #(re-frame/dispatch [:pairing.ui/prompt-accepted])}}))
(fx/defn set-name
(rf/defn set-name
"Set the name of the device"
{:events [:pairing.ui/set-name-pressed]}
[{:keys [db]} installation-name]
@ -96,21 +96,21 @@
{:name installation-name
:deviceType utils.platform/os}]}))
(fx/defn init
(rf/defn init
[cofx]
{:pairing/get-our-installations nil})
(fx/defn enable
(rf/defn enable
[{:keys [db]} installation-id]
{:db (assoc-in db
[:pairing/installations installation-id :enabled?]
true)})
[:pairing/installations installation-id :enabled?]
true)})
(fx/defn disable
(rf/defn disable
[{:keys [db]} installation-id]
{:db (assoc-in db
[:pairing/installations installation-id :enabled?]
false)})
[:pairing/installations installation-id :enabled?]
false)})
(defn handle-enable-installation-response-success
"Callback to dispatch on enable signature response"
@ -158,7 +158,7 @@
[]
(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]}
[cofx installation-id]
(if (< (count (filter :enabled? (vals (get-in cofx [:db :pairing/installations]))))
@ -168,7 +168,7 @@
:content (i18n/label :t/pairing-maximum-number-reached-content)}}))
(fx/defn disable-fx
(rf/defn disable-fx
{:events [:pairing.ui/disable-installation-pressed]}
[_ installation-id]
{:pairing/disable-installation [installation-id]})
@ -192,7 +192,7 @@
:pairing/get-our-installations
get-our-installations)
(fx/defn send-installation-messages
(rf/defn send-installation-messages
{:events [:pairing.ui/synchronize-installation-pressed]}
[{:keys [db]}]
(let [multiaccount (:multiaccount db)
@ -209,7 +209,7 @@
:device-type (:deviceType metadata)
:enabled? enabled})
(fx/defn update-installation
(rf/defn update-installation
{:events [:pairing.callback/set-installation-metadata-success]}
[{:keys [db]} installation-id metadata]
{:db (update-in db
@ -219,7 +219,7 @@
:name (:name metadata)
:device-type (:deviceType metadata))})
(fx/defn handle-installations
(rf/defn handle-installations
[{:keys [db]} installations]
{:db (update db
:pairing/installations
@ -229,7 +229,7 @@
%
installations))})
(fx/defn load-installations
(rf/defn load-installations
{:events [:pairing.callback/get-our-installations-success]}
[{:keys [db]} installations]
{:db (assoc db
@ -242,16 +242,16 @@
{}
installations))})
(fx/defn enable-installation-success
(rf/defn enable-installation-success
{:events [:pairing.callback/enable-installation-success]}
[cofx installation-id]
(fx/merge cofx
(rf/merge cofx
(enable installation-id)
(multiaccounts.update/send-multiaccount-update)))
(fx/defn disable-installation-success
(rf/defn disable-installation-success
{:events [:pairing.callback/disable-installation-success]}
[cofx installation-id]
(fx/merge cofx
(rf/merge cofx
(disable installation-id)
(multiaccounts.update/send-multiaccount-update)))

View File

@ -1,7 +1,7 @@
(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]}
[_ value]
{:show-popover nil
@ -9,12 +9,12 @@
:dispatch-later [{:ms 250 :dispatch [:show-popover-db value]}]
:dismiss-keyboard nil})
(fx/defn show-popover-db
(rf/defn show-popover-db
{:events [:show-popover-db]}
[{:keys [db]} value]
{:db (assoc db :popover/popover value)})
(fx/defn hide-popover
(rf/defn hide-popover
{:events [:hide-popover]}
[{:keys [db]}]
{:db (dissoc db :popover/popover)

View File

@ -4,7 +4,7 @@
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.ui.components.list-selection :as list-selection]
[status-im.ui.components.react :as react]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.universal-links.utils :as universal-links]))
(re-frame/reg-fx
@ -31,8 +31,8 @@
(do (re-frame/dispatch [:set-in [:tooltips tooltip-id] opacity])
(when (< 10 cnt)
(swap! tooltips assoc-in
[tooltip-id :opacity]
(- opacity 0.05)))))))
[tooltip-id :opacity]
(- opacity 0.05)))))))
100)]
(swap! tooltips assoc tooltip-id {:opacity 1.0 :interval-id interval-id :cnt 0}))))))
@ -42,19 +42,19 @@
(let [link (universal-links/generate-link :user :external contact-code)]
(list-selection/open-share {:message link}))))
(fx/defn finish-success
(rf/defn finish-success
{:events [:my-profile/finish-success]}
[{:keys [db] :as cofx}]
{:db (update db :my-profile/seed assoc :step :finish :error nil :word nil)})
(fx/defn finish
(rf/defn finish
{:events [:my-profile/finish]}
[cofx]
(multiaccounts.update/clean-seed-phrase
cofx
{: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]}
[{:keys [db]}]
(let [{:keys [mnemonic]} (:multiaccount db)
@ -65,22 +65,22 @@
:first-word (first shuffled-mnemonic)
:second-word (second shuffled-mnemonic)})}))
(fx/defn set-step
(rf/defn set-step
{:events [:my-profile/set-step]}
[{:keys [db]} step]
{: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]}
[_ value]
{:copy-to-clipboard value})
(fx/defn show-tooltip
(rf/defn show-tooltip
{:events [:show-tooltip]}
[_ tooltip-id]
{:show-tooltip tooltip-id})
(fx/defn share-profile-link
(rf/defn share-profile-link
{:events [:profile/share-profile-link]}
[_ value]
{:profile/share-profile-link value})

View File

@ -7,12 +7,12 @@
[status-im.group-chats.core :as group-chats]
[status-im.i18n.i18n :as i18n]
[status-im.router.core :as router]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.utils :as utils]
[status-im2.navigation.events :as navigation]
[taoensso.timbre :as log]))
(fx/defn scan-qr-code
(rf/defn scan-qr-code
{:events [::scan-code]}
[_ opts]
{:request-permissions-fx
@ -24,43 +24,43 @@
(i18n/label :t/camera-access-error))
50))}})
(fx/defn set-qr-code
(rf/defn set-qr-code
{:events [:qr-scanner.callback/scan-qr-code-success]}
[{:keys [db]} opts data]
(when-let [handler (:handler 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]}
[cofx opts]
(fx/merge cofx
(rf/merge cofx
(navigation/navigate-back)
(when-let [handler (:cancel-handler opts)]
(fn [] {:dispatch [handler opts]}))))
(fx/defn handle-browse
(rf/defn handle-browse
[cofx {:keys [url]}]
(fx/merge cofx
(rf/merge cofx
{:browser/show-browser-selection url}
(navigation/navigate-back)))
(fx/defn handle-private-chat
(rf/defn handle-private-chat
[{:keys [db] :as cofx} {:keys [chat-id]}]
(if-not (new-chat.db/own-public-key? db chat-id)
(chat/start-chat cofx chat-id nil)
{:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)
:content (i18n/label :t/can-not-add-yourself)}}))
(fx/defn handle-public-chat
(rf/defn handle-public-chat
[cofx {:keys [topic]}]
(when (seq topic)
(chat/start-public-chat cofx topic)))
(fx/defn handle-group-chat
(rf/defn handle-group-chat
[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]}]
(let [own (new-chat.db/own-public-key? db public-key)]
(cond
@ -69,7 +69,7 @@
:pop-to-root-tab-fx :profile-stack}
(and public-key (not own))
(fx/merge cofx
(rf/merge cofx
{:dispatch [:chat.ui/show-profile public-key ens-name]}
(navigation/navigate-back))
@ -78,14 +78,14 @@
:content (i18n/label :t/ens-name-not-found)
:on-dismiss #(re-frame/dispatch [:pop-to-root-tab :chat-stack])}})))
(fx/defn handle-eip681
(rf/defn handle-eip681
[cofx data]
(fx/merge cofx
(rf/merge cofx
{:dispatch [:wallet/parse-eip681-uri-and-resolve-ens data]}
(navigation/change-tab :wallet)
(navigation/pop-to-root-tab :wallet-stack)))
(fx/defn handle-wallet-connect
(rf/defn handle-wallet-connect
{:events [::handle-wallet-connect-uri]}
[cofx data]
(let [wc-version (last (string/split (first (string/split data "?")) "@"))]
@ -93,12 +93,12 @@
{:dispatch [:wallet-connect-legacy/pair data]}
{:dispatch [:wallet-connect/pair data]})))
(fx/defn handle-local-pairing
(rf/defn handle-local-pairing
{:events [::handle-local-pairing-uri]}
[_ data]
{:dispatch [:syncing/input-connection-string-for-bootstrapping data]})
(fx/defn match-scan
(rf/defn match-scan
{:events [::match-scanned-value]}
[cofx {:keys [type] :as data}]
(case type
@ -118,7 +118,7 @@
:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)
:on-dismiss #(re-frame/dispatch [:pop-to-root-tab :chat-stack])}})))
(fx/defn on-scan
(rf/defn on-scan
{:events [::on-scan-success]}
[{:keys [db]} uri]
{::router/handle-uri {:chain (ethereum/chain-keyword db)

View File

@ -1,22 +1,22 @@
(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]}
[cofx 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]}
[cofx 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]}
[cofx 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]}
[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)})

View File

@ -7,20 +7,20 @@
[status-im.multiaccounts.login.core :as login]
[status-im.notifications.local :as local-notifications]
[status-im.transport.message.core :as transport.message]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.visibility-status-updates.core :as visibility-status-updates]
[taoensso.timbre :as log]))
(fx/defn status-node-started
(rf/defn status-node-started
[{db :db :as cofx} {:keys [error]}]
(log/debug "[signals] status-node-started"
"error"
error)
(if error
(cond->
{:db (-> db
(update :multiaccounts/login dissoc :processing)
(assoc-in [:multiaccounts/login :error]
{:db (-> db
(update :multiaccounts/login dissoc :processing)
(assoc-in [:multiaccounts/login :error]
;; NOTE: the only currently known error is
;; "file is not a database" which occurs
;; when the user inputs the wrong password
@ -29,24 +29,24 @@
;; to the user
;; in case of an unknown error we show the
;; error
(if (= error "file is not a database")
(i18n/label :t/wrong-password)
error)))}
(if (= error "file is not a database")
(i18n/label :t/wrong-password)
error)))}
(= (:view-id db) :progress)
(assoc :dispatch [:navigate-to :login]))
(login/multiaccount-login-success cofx)))
(fx/defn summary
(rf/defn summary
[{:keys [db] :as cofx} peers-summary]
(let [previous-summary (:peers-summary db)
peers-count (count peers-summary)]
(fx/merge cofx
(rf/merge cofx
{:db (assoc db
:peers-summary peers-summary
:peers-count peers-count)}
(visibility-status-updates/peers-summary-change peers-count))))
(fx/defn wakuv2-peer-stats
(rf/defn wakuv2-peer-stats
[{:keys [db]} peer-stats]
(let [previous-stats (:peer-stats db)]
{:db (assoc db
@ -58,7 +58,7 @@
(log/info "local pairing signal received"
{:signal-type signal-type}))
(fx/defn process
(rf/defn process
{:events [:signals/signal-received]}
[{:keys [db] :as cofx} event-str]
;; We only convert to clojure when strictly necessary or we know it

View File

@ -12,7 +12,7 @@
[status-im.native-module.core :as status]
[status-im.signing.eip1559 :as eip1559]
[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.money :as money]
[status-im.utils.types :as types]
@ -66,7 +66,7 @@
(get-in db [:contacts/contacts to])
{:address (ethereum/normalized-hex to)})))
(fx/defn change-password
(rf/defn change-password
{:events [:signing.ui/password-is-changed]}
[{db :db} password]
(let [unmasked-pass (security/safe-unmask-data password)]
@ -76,7 +76,7 @@
:error nil
:enabled? (and unmasked-pass (> (count unmasked-pass) 5)))}))
(fx/defn sign-message
(rf/defn sign-message
[{{:signing/keys [sign tx] :as db} :db}]
(let [{{:keys [data typed? from v4]} :message} tx
{:keys [in-progress? password]} sign
@ -98,7 +98,7 @@
:on-completed #(re-frame/dispatch [:signing/sign-message-completed
%])}})))))
(fx/defn send-transaction
(rf/defn send-transaction
{:events [:signing.ui/sign-is-pressed]}
[{{:signing/keys [sign tx] :as db} :db :as cofx}]
(let [{:keys [in-progress? password]} sign
@ -129,7 +129,7 @@
[: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 [value gasPrice maxFeePerGas maxPriorityFeePerGas gas data to from hash]} symbol amount]
(let [token (tokens/symbol->token (:wallet/all-tokens db) symbol)
@ -237,7 +237,7 @@
:maxPriorityFeePerGas (when maxPriorityFeePerGas
(money/bignumber maxPriorityFeePerGas))}))
(fx/defn show-sign
(rf/defn show-sign
[{:keys [db] :as cofx}]
(let [{:signing/keys [queue]} db
{{:keys [gas gasPrice maxFeePerGas] :as tx-obj} :tx-obj
@ -247,7 +247,7 @@
keycard-multiaccount? (boolean (get-in db [:multiaccount :keycard-pairing]))
wallet-set-up-passed? (get-in db [:multiaccount :wallet-set-up-passed?])]
(if message
(fx/merge
(rf/merge
cofx
{:db (assoc db
:signing/queue (drop-last queue)
@ -271,7 +271,7 @@
{:data data
:typed? true
:on-completed #(re-frame/dispatch [:keycard/store-hash-and-sign-typed %])})))
(fx/merge
(rf/merge
cofx
{:db (assoc db
:signing/queue (drop-last queue)
@ -302,13 +302,13 @@
:network-id (get-in (ethereum/current-network db)
[:config :NetworkId])}})))))
(fx/defn check-queue
(rf/defn check-queue
[{:keys [db] :as cofx}]
(let [{:signing/keys [tx queue]} db]
(when (and (not tx) (seq queue))
(show-sign cofx))))
(fx/defn send-transaction-message
(rf/defn send-transaction-message
{:events [:sign/send-transaction-message]}
[cofx chat-id value contract transaction-hash signature]
{:json-rpc/call [{:method "wakuext_sendTransaction"
@ -321,7 +321,7 @@
:on-success
#(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]}
[cofx message-id transaction-hash signature]
{:json-rpc/call [{:method "wakuext_acceptRequestTransaction"
@ -332,10 +332,10 @@
:on-success
#(re-frame/dispatch [:transport/message-sent %])}]})
(fx/defn transaction-result
(rf/defn transaction-result
[{:keys [db] :as cofx} result tx-obj]
(let [{:keys [on-result symbol amount from]} (get db :signing/tx)]
(fx/merge cofx
(rf/merge cofx
{:db (dissoc db :signing/tx :signing/sign)
:signing/show-transaction-result nil}
(prepare-unconfirmed-transaction result tx-obj symbol amount)
@ -344,13 +344,13 @@
#(when on-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 [message-id chat-id from] :as tx-obj}]
(let [{:keys [on-result symbol amount contract value]} (get db :signing/tx)
data (str (get-in db [:multiaccount :public-key])
(subs transaction-hash 2))]
(fx/merge
(rf/merge
cofx
{:db (dissoc db :signing/tx :signing/sign)}
(wallet/watch-tx (get from :address) transaction-hash)
@ -386,7 +386,7 @@
#(when on-result
{:dispatch (conj on-result transaction-hash)}))))
(fx/defn transaction-error
(rf/defn transaction-error
[{:keys [db]} {:keys [code message]}]
(let [on-error (get-in db [:signing/tx :on-error])]
(if (= code constants/send-transaction-err-decrypt)
@ -397,14 +397,14 @@
(when on-error
{: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]}
[{:keys [db] :as cofx}]
(fx/merge cofx
(rf/merge cofx
{:db (dissoc db :signing/tx :signing/sign)}
check-queue))
(fx/defn sign-message-completed
(rf/defn sign-message-completed
{:events [:signing/sign-message-completed]}
[{:keys [db] :as cofx} result]
(let [{:keys [result error]} (types/json->clj result)
@ -417,7 +417,7 @@
(i18n/label :t/wrong-password)
(:message error))
:in-progress? false)}
(fx/merge cofx
(rf/merge cofx
(when-not (= (-> db :signing/sign :type) :pinless)
(dissoc-signing-db-entries-and-check-queue))
#(when (= (-> db :signing/sign :type) :pinless)
@ -426,7 +426,7 @@
#(when on-result
{:dispatch (conj on-result result)})))))
(fx/defn transaction-completed
(rf/defn transaction-completed
{:events [:signing/transaction-completed]
:interceptors [(re-frame/inject-cofx :random-id-generator)]}
[cofx response tx-obj hashed-password]
@ -438,12 +438,12 @@
(command-transaction-result cofx-in-progress-false result hashed-password tx-obj)
(transaction-result cofx-in-progress-false result tx-obj)))))
(fx/defn discard
(rf/defn discard
"Discrad transaction signing"
{:events [:signing.ui/cancel-is-pressed]}
[{:keys [db] :as cofx}]
(let [{:keys [on-error]} (get-in db [:signing/tx])]
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc-in [:keycard :pin :status] nil)
(dissoc :signing/tx :signing/sign))
@ -458,7 +458,7 @@
[db tx]
(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
tx
{:tx-obj - transaction object to send https://github.com/ethereum/wiki/wiki/JavaScript-API#parameters-25
@ -467,11 +467,11 @@
:on-error - re-frame event vector}"
{:events [:signing.ui/sign]}
[{:keys [db] :as cofx} tx]
(fx/merge cofx
(rf/merge cofx
{:db (update db :signing/queue conj (normalize-tx-obj db tx))}
(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]}
[{:keys [db] :as cofx} {:keys [to amount from token]}]
(let [{:keys [symbol address]} token
@ -481,7 +481,7 @@
identity (:current-chat-id db)
db (dissoc db :wallet/prepare-transaction :signing/edit-fee)]
(if to-norm
(fx/merge
(rf/merge
cofx
{:db db}
(sign {:tx-obj (if (= symbol :ETH)
@ -506,7 +506,7 @@
:js-response true
: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]}
[{:keys [db] :as cofx} {:keys [amount from token]}]
(let [{:keys [request-parameters chat-id]} (:wallet/prepare-transaction db)
@ -514,7 +514,7 @@
amount-hex (str "0x" (status/number-to-hex amount))
to-norm (:address request-parameters)
from-address (:address from)]
(fx/merge cofx
(rf/merge cofx
{:db (dissoc db :wallet/prepare-transaction :signing/edit-fee)}
(fn [cofx]
(sign
@ -533,14 +533,14 @@
:chat-id chat-id
: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]}
[{:keys [db] :as cofx} {:keys [to amount from token gas gasPrice maxFeePerGas maxPriorityFeePerGas]}]
(let [{:keys [symbol address]} token
amount-hex (str "0x" (status/number-to-hex amount))
to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))
from-address (:address from)]
(fx/merge cofx
(rf/merge cofx
{:db (dissoc db :wallet/prepare-transaction :signing/edit-fee)}
(sign
{:tx-obj (merge (if (eip1559/sync-enabled?)
@ -567,17 +567,17 @@
:params [hash]
:on-success handler})))
(fx/defn cancel-transaction-pressed
(rf/defn cancel-transaction-pressed
{:events [:signing.ui/cancel-transaction-pressed]}
[_ hash]
{: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]}
[_ hash]
{: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]}
[cofx {:keys [from nonce hash]}]
(when (and from nonce hash)
@ -589,7 +589,7 @@
:cancel? true
:hash hash}})))
(fx/defn increase-gas
(rf/defn increase-gas
{:events [:signing/increase-gas]}
[cofx {:keys [from nonce] :as tx}]
(when (and from nonce)

View File

@ -6,7 +6,7 @@
[status-im.i18n.i18n :as i18n]
[status-im.popover.core :as popover]
[status-im.signing.eip1559 :as eip1559]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.money :as money]
[status-im2.common.json-rpc.events :as json-rpc]
[taoensso.timbre :as log]))
@ -151,7 +151,7 @@
validate-max-priority-fee])
db))
(fx/defn edit-value
(rf/defn edit-value
{:events [:signing.edit-fee.ui/edit-value]}
[{:keys [db]} key value]
{:db (-> db
@ -178,7 +178,7 @@
:tip 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]}
[{:keys [db] :as cofx} option]
(let [tip (get db :wallet/current-priority-fee)
@ -195,7 +195,7 @@
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]}
[{:keys [db]} value]
(let [{:keys [maxFeePerGas maxPriorityFeePerGas]}
@ -216,21 +216,21 @@
(update :signing/edit-fee build-edit :maxFeePerGas new-max-fee-value)
validate-eip1559-fees)}))
(fx/defn update-estimated-gas-success
(rf/defn update-estimated-gas-success
{:events [:signing/update-estimated-gas-success]}
[{db :db} gas]
{:db (-> db
(assoc-in [:signing/tx :gas] gas)
(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]}
[{db :db} price]
(if (eip1559/sync-enabled?)
(let [{:keys [normal-base-fee max-priority-fee]} price
max-priority-fee-bn (money/with-precision (get-suggested-tip
max-priority-fee)
0)]
0)]
{:db (-> db
(assoc-in [:signing/tx :maxFeePerGas]
(money/to-hex (money/add max-priority-fee-bn
@ -242,7 +242,7 @@
(assoc-in [:signing/tx :gasPrice] price)
(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]}
[{db :db} {:keys [message]}]
(log/warn "signing/update-estimated-gas-error" message)
@ -250,12 +250,12 @@
(assoc-in [:signing/edit-fee :gas-loading?] false)
(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]}
[{db :db}]
{: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]}
[{{:signing/keys [tx] :as db} :db :as cofx} sheet-opts]
(let [{:keys [gas gasPrice maxFeePerGas maxPriorityFeePerGas]} tx
@ -275,11 +275,11 @@
:maxFeePerGas max-fee
:maxPriorityFeePerGas
max-priority-fee})]
(fx/merge cofx
(rf/merge cofx
{:db (assoc db :signing/edit-fee edit-fee)}
(bottom-sheet/show-bottom-sheet {:view sheet-opts}))))
(fx/defn submit-fee
(rf/defn submit-fee
{:events [:signing.edit-fee.ui/submit]}
[{{:signing/keys [edit-fee] :as db} :db :as cofx} force?]
(let [{:keys [gas gasPrice maxFeePerGas maxPriorityFeePerGas]} edit-fee
@ -292,7 +292,7 @@
(if (and (seq errors?)
(not force?))
(popover/show-popover cofx {:view :fees-warning})
(fx/merge cofx
(rf/merge cofx
{:db (update db
:signing/tx assoc
:gas (:value-number gas)
@ -302,10 +302,10 @@
(:value-number maxPriorityFeePerGas)))}
(bottom-sheet/hide-bottom-sheet)))))
(fx/defn submit-nonce
(rf/defn submit-nonce
{:events [:signing.nonce/submit]}
[{db :db :as cofx} nonce]
(fx/merge cofx
(rf/merge cofx
{:db (assoc-in db [:signing/tx :nonce] (if (string/blank? nonce) nil nonce))}
(bottom-sheet/hide-bottom-sheet)))
@ -394,7 +394,7 @@
(money/sub (money/bignumber gas-price)
(money/bignumber base-fee))))
(fx/defn header-fetched
(rf/defn header-fetched
{:events [::header-fetched]}
[{{:networks/keys [current-network networks]} :db}
{:keys [error-callback success-callback fee-history] :as params}]

View File

@ -2,7 +2,7 @@
(:require [re-frame.core :as re-frame]
[status-im.i18n.i18n :as i18n]
[status-im.native-module.core :as status]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.types :as types]
[taoensso.timbre :as log]))
@ -53,7 +53,7 @@
nonce
(assoc :nonce nonce))))
(fx/defn hash-message
(rf/defn hash-message
[_ {:keys [v4 data typed? on-completed]}]
(if typed?
{::hash-typed-data
@ -72,7 +72,7 @@
[:signing.keycard.callback/hash-message-completed
data typed? %]))}}))
(fx/defn hash-message-completed
(rf/defn hash-message-completed
{:events [:signing.keycard.callback/hash-message-completed]}
[{:keys [db]} data typed? result]
(let [{:keys [result error]} (types/json->clj result)]
@ -86,7 +86,7 @@
:typed? typed?
:data data)})))
(fx/defn hash-transaction
(rf/defn hash-transaction
[{:keys [db]}]
(let [tx (prepare-transaction (:signing/tx db))]
(log/debug "hash-transaction" tx)
@ -95,7 +95,7 @@
:on-completed #(re-frame/dispatch
[:signing.keycard.callback/hash-transaction-completed tx %])}}))
(fx/defn hash-transaction-completed
(rf/defn hash-transaction-completed
{:events [:signing.keycard.callback/hash-transaction-completed]}
[{:keys [db]} original-tx result]
(let [{:keys [transaction hash]} (:result (types/json->clj result))]
@ -104,11 +104,11 @@
(merge original-tx transaction))
(assoc-in [:keycard :hash] hash))}))
(fx/defn sign-with-keycard
(rf/defn sign-with-keycard
{:events [:signing.ui/sign-with-keycard-pressed]}
[{:keys [db] :as cofx}]
(let [{:keys [message maxPriorityFeePerGas maxFeePerGas]} (get db :signing/tx)]
(fx/merge
(rf/merge
cofx
{:db (-> db
(assoc-in [:keycard :pin :enter-step] :sign)

View File

@ -4,7 +4,7 @@
[status-im.constants :as constants]
[status-im.ethereum.core :as ethereum]
[status-im.utils.config :as config]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.utils :as utils]
[status-im2.navigation.events :as navigation]))
@ -14,17 +14,17 @@
(utils/set-timeout #(re-frame/dispatch [:stickers/pending-timeout])
10000)))
(fx/defn install-stickers-pack
(rf/defn install-stickers-pack
{:events [:stickers/install-pack]}
[{db :db :as cofx} id]
(fx/merge
(rf/merge
cofx
{:db (assoc-in db [:stickers/packs id :status] constants/sticker-pack-status-installed)
:json-rpc/call [{:method "stickers_install"
:params [(ethereum/chain-id db) id]
:on-success #()}]}))
(fx/defn load-packs
(rf/defn load-packs
{:events [:stickers/load-packs]}
[{:keys [db]}]
{:json-rpc/call [{:method "stickers_market"
@ -40,7 +40,7 @@
:params []
:on-success #(re-frame/dispatch [:stickers/stickers-recent-success %])}]})
(fx/defn buy-pack
(rf/defn buy-pack
{:events [:stickers/buy-pack]}
[{db :db} pack-id]
{:json-rpc/call [{:method "stickers_buyPrepareTx"
@ -49,7 +49,7 @@
{:tx-obj %
:on-result [:stickers/pending-pack pack-id]}])}]})
(fx/defn pending-pack
(rf/defn pending-pack
{:events [:stickers/pending-pack]}
[{db :db} id]
{:db (-> db
@ -61,7 +61,7 @@
:params [(ethereum/chain-id db) (int id)]
:on-success #()}]})
(fx/defn pending-timeout
(rf/defn pending-timeout
{:events [:stickers/pending-timeout]}
[{{:stickers/keys [packs-pending] :as db} :db}]
(when (seq packs-pending)
@ -70,7 +70,7 @@
: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]}
[{{:stickers/keys [packs-pending packs] :as db} :db} purchased]
(let [purchased-ids (map :id (vals purchased))
@ -86,19 +86,19 @@
(when (seq packs-pending)
{:stickers/set-pending-timeout-fx nil}))))
(fx/defn stickers-market-success
(rf/defn stickers-market-success
{:events [:stickers/stickers-market-success]}
[{:keys [db]} packs]
(let [packs (reduce (fn [acc pack] (assoc acc (:id pack) pack)) {} packs)]
{:db (update db :stickers/packs merge packs)}))
(fx/defn stickers-installed-success
(rf/defn stickers-installed-success
{:events [:stickers/stickers-installed-success]}
[{:keys [db]} packs]
(let [packs (reduce (fn [acc [_ pack]] (assoc acc (:id pack) pack)) {} packs)]
{:db (update db :stickers/packs merge packs)}))
(fx/defn stickers-pending-success
(rf/defn stickers-pending-success
{:events [:stickers/stickers-pending-success]}
[{:keys [db]} packs]
(let [packs (reduce (fn [acc [_ pack]] (assoc acc (:id pack) pack)) {} packs)]
@ -109,18 +109,18 @@
(when (seq packs)
{:stickers/set-pending-timeout-fx nil}))))
(fx/defn stickers-recent-success
(rf/defn stickers-recent-success
{:events [:stickers/stickers-recent-success]}
[{:keys [db]} packs]
{:db (assoc db :stickers/recent-stickers packs)})
(fx/defn open-sticker-pack
(rf/defn open-sticker-pack
{:events [:stickers/open-sticker-pack]}
[{{:networks/keys [current-network]} :db :as cofx} id]
(when (and id (or config/stickers-test-enabled? (string/starts-with? current-network "mainnet")))
(navigation/open-modal cofx :stickers-pack {:id id})))
(fx/defn select-pack
(rf/defn select-pack
{:events [:stickers/select-pack]}
[{:keys [db]} id]
{:db (assoc db :stickers/selected-pack id)})

View File

@ -3,7 +3,8 @@
(:require [cljs.test :as ct]
[clojure.string :as string]
[shadow.test :as st]
[shadow.test.env :as env]))
[shadow.test.env :as env]
[utils.re-frame :as rf]))
(defonce repl? (atom false))
@ -111,6 +112,16 @@
(defn ^:export main
[& args]
(reset-test-data!)
(rf/set-mergeable-keys #{:filters/load-filters
:pairing/set-installation-metadata
:dispatch-n
:status-im.ens.core/verify-names
:shh/send-direct-message
:shh/remove-filter
:transport/confirm-messages-processed
:group-chats/extract-membership-signature
:utils/dispatch-later
:json-rpc/call})
(let [opts (parse-args args)]
(execute-cli opts)))

View File

@ -3,16 +3,16 @@
[status-im.pairing.core :as pairing]
[status-im.stickers.core :as stickers]
status-im.transport.shh
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.universal-links.core :as universal-links]
[taoensso.timbre :as log]))
(fx/defn set-node-info
(rf/defn set-node-info
{:events [:transport.callback/node-info-fetched]}
[{:keys [db]} 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"
:on-success #(re-frame/dispatch [:transport.callback/node-info-fetched %])
@ -27,12 +27,12 @@
(assoc :name (if (seq name) name id))
(dissoc :fleet))]
(assoc-in db
[:mailserver/mailservers (keyword fleet) (keyword id)]
updated-mailserver)))
[:mailserver/mailservers (keyword fleet) (keyword id)]
updated-mailserver)))
db
mailservers))
(fx/defn start-messenger
(rf/defn start-messenger
"We should only start receiving messages/processing topics once all the
initializiation is completed, otherwise we might receive messages/topics
when the state has not been properly initialized."
@ -41,11 +41,11 @@
:on-success #(re-frame/dispatch [::messenger-started %])
:on-error #(log/error "failed to start messenger")}]})
(fx/defn messenger-started
(rf/defn messenger-started
{:events [::messenger-started]}
[{:keys [db] :as cofx} {:keys [mailservers] :as response}]
(log/info "Messenger started")
(fx/merge cofx
(rf/merge cofx
{:db (-> db
(assoc :messenger/started? true)
(add-mailservers mailservers))}

View File

@ -18,19 +18,19 @@
[status-im.multiaccounts.model :as multiaccounts.model]
[status-im.multiaccounts.update.core :as update.core]
[status-im.pairing.core :as models.pairing]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.types :as types]
[status-im.visibility-status-updates.core :as models.visibility-status-updates]
[status-im2.contexts.activity-center.events :as activity-center]
[status-im2.contexts.chat.messages.pin.events :as messages.pin]))
(fx/defn process-next
(rf/defn process-next
[cofx ^js response-js sync-handler]
(if sync-handler
(sync-handler cofx response-js true)
{:utils/dispatch-later [{:ms 20 :dispatch [:process-response response-js]}]}))
(fx/defn process-response
(rf/defn process-response
{:events [:process-response]}
[{:keys [db] :as cofx} ^js response-js process-async]
(let [^js communities (.-communities response-js)
@ -58,7 +58,7 @@
(seq chats)
(do
(js-delete response-js "chats")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(models.chat/ensure-chats (map data-store.chats/<-rpc (types/js->clj chats)))))
@ -68,7 +68,7 @@
(seq activity-notifications)
(do
(js-delete response-js "activityCenterNotifications")
(fx/merge cofx
(rf/merge cofx
(->> activity-notifications
types/js->clj
(map data-store.activities/<-rpc)
@ -78,7 +78,7 @@
(seq installations)
(let [installations-clj (types/js->clj installations)]
(js-delete response-js "installations")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(models.pairing/handle-installations installations-clj)))
@ -87,7 +87,7 @@
^js chats (.-chatsForContacts response-js)]
(js-delete response-js "contacts")
(js-delete response-js "chatsForContacts")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(models.contact/ensure-contacts
(map data-store.contacts/<-rpc contacts-clj)
@ -96,69 +96,69 @@
(seq communities)
(let [communities-clj (types/js->clj communities)]
(js-delete response-js "communities")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(models.communities/handle-communities communities-clj)))
(seq bookmarks)
(let [bookmarks-clj (types/js->clj bookmarks)]
(js-delete response-js "bookmarks")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(browser/handle-bookmarks bookmarks-clj)))
(seq pin-messages)
(let [pin-messages (types/js->clj pin-messages)]
(js-delete response-js "pinMessages")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(messages.pin/receive-signal (map data-store.messages/<-rpc pin-messages))))
(seq removed-chats)
(let [removed-chats-clj (types/js->clj removed-chats)]
(js-delete response-js "removedChats")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(models.communities/handle-removed-chats removed-chats-clj)))
(seq 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)
(models.communities/handle-request-to-join request-js)))
(seq emoji-reactions)
(let [reactions (types/js->clj emoji-reactions)]
(js-delete response-js "emojiReactions")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(models.reactions/receive-signal (map data-store.reactions/<-rpc reactions))))
(seq invitations)
(let [invitations (types/js->clj invitations)]
(js-delete response-js "invitations")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(models.group/handle-invitations (map data-store.invitations/<-rpc invitations))))
(seq removed-messages)
(let [removed-messages-clj (types/js->clj removed-messages)]
(js-delete response-js "removedMessages")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(models.message/handle-removed-messages removed-messages-clj)))
(seq cleared-histories)
(let [cleared-histories-clj (types/js->clj cleared-histories)]
(js-delete response-js "clearedHistories")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(models.message/handle-cleared-histories-messages cleared-histories-clj)))
(seq visibility-status-updates)
(let [visibility-status-updates-clj (types/js->clj visibility-status-updates)]
(js-delete response-js "statusUpdates")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(models.visibility-status-updates/handle-visibility-status-updates
visibility-status-updates-clj)))
@ -166,28 +166,28 @@
(seq accounts)
(do
(js-delete response-js "accounts")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(multiaccounts.login/update-wallet-accounts (types/js->clj accounts))))
(seq settings)
(do
(js-delete response-js "settings")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(update.core/set-many-js settings)))
(seq identity-images)
(let [images-clj (map types/js->clj identity-images)]
(js-delete response-js "identityImages")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(update.core/optimistic :images images-clj)))
(some? current-visibility-status)
(let [current-visibility-status-clj (types/js->clj current-visibility-status)]
(js-delete response-js "currentStatus")
(fx/merge cofx
(rf/merge cofx
(process-next response-js sync-handler)
(models.visibility-status-updates/sync-visibility-status-update
current-visibility-status-clj))))))
@ -237,12 +237,12 @@
[response-js messages]
(if (seq messages)
(set! (.-messages response-js)
(.sort (to-array messages)
(fn [a b]
(- (.-clock b) (.-clock a)))))
(.sort (to-array messages)
(fn [a b]
(- (.-clock b) (.-clock a)))))
(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"
{:events [:sanitize-messages-and-process-response]}
[{:keys [db] :as cofx} ^js response-js process-async]
@ -258,7 +258,7 @@
:current-chat-id current-chat-id}
(.-messages response-js))]
(sort-js-messages! response-js messages)
(fx/merge cofx
(rf/merge cofx
{:db db
:utils/dispatch-later (concat []
(when (seq statuses)
@ -269,16 +269,16 @@
:dispatch [:watch-tx nil transaction-hash]})))}
(process-response response-js process-async)))))
(fx/defn remove-hash
(rf/defn remove-hash
[{:keys [db]} 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]
(when-let [{:keys [pending-confirmations not-sent]}
(get-in db [:transport/message-ids->confirmations message-id])]
(if (zero? (dec pending-confirmations))
(fx/merge cofx
(rf/merge cofx
{:db (update db
:transport/message-ids->confirmations
dissoc
@ -293,10 +293,10 @@
:not-sent (or not-sent
(= :not-sent status))}]
{:db (assoc-in db
[:transport/message-ids->confirmations message-id]
confirmations)}))))
[:transport/message-ids->confirmations message-id]
confirmations)}))))
(fx/defn update-envelope-status
(rf/defn update-envelope-status
[{:keys [db] :as cofx} message-id status]
(if-let [{:keys [chat-id]}
(get-in db [:transport/message-envelopes message-id])]
@ -306,13 +306,13 @@
;; came too early
{: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]
(when (or (not= status :not-sent)
(= :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"
[{:keys [db] :as cofx} chat-id message-id message-type]
;; Check first if the confirmation has already arrived
@ -329,15 +329,15 @@
:message-type message-type})
(update-in [:transport/message-ids->confirmations message-id]
#(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]}
[cofx response-js]
(let [set-hash-fxs (map (fn [{:keys [localChatId id messageType]}]
(set-message-envelope-hash localChatId id messageType))
(types/js->clj (.-messages response-js)))]
(apply fx/merge
(apply rf/merge
cofx
(conj set-hash-fxs
#(sanitize-messages-and-process-response % response-js false)))))

View File

@ -1,6 +1,6 @@
(ns ^{:doc "Protocol API and protocol utils"} status-im.transport.message.protocol
(:require [re-frame.core :as re-frame]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[taoensso.timbre :as log]))
(defn build-message
@ -25,7 +25,7 @@
:sticker sticker
:contentType content-type})
(fx/defn send-chat-messages
(rf/defn send-chat-messages
[_ messages]
{:json-rpc/call [{:method "wakuext_sendChatMessages"
:params [(mapv build-message messages)]
@ -35,7 +35,7 @@
(log/warn "failed to send a message" %)
(js/alert (str "failed to send a message: " %)))}]})
(fx/defn send-reaction
(rf/defn send-reaction
[_ {:keys [message-id chat-id emoji-id]}]
{:json-rpc/call [{:method "wakuext_sendEmojiReaction"
:params [chat-id message-id emoji-id]
@ -43,7 +43,7 @@
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
:on-error #(log/error "failed to send a reaction" %)}]})
(fx/defn send-retract-reaction
(rf/defn send-retract-reaction
[_ {:keys [emoji-reaction-id]}]
{:json-rpc/call [{:method "wakuext_sendEmojiReactionRetraction"
:params [emoji-reaction-id]

View File

@ -2,7 +2,7 @@
(:require [re-frame.core :as re-frame]
[status-im.i18n.i18n :as i18n]
[status-im.ui.components.react :as react]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.universal-links.utils :as universal-links]))
(re-frame/reg-fx
@ -10,7 +10,7 @@
(fn [content]
(.share ^js react/sharing (clj->js content))))
(fx/defn share-link
(rf/defn share-link
{:events [::share-link]}
[{:keys [db]}]
(let [{:keys [public-key preferred-name]} (get db :multiaccount)

View File

@ -15,7 +15,7 @@
[status-im.ui.screens.chat.components.input :as input]
[status-im.ui.screens.chat.components.style :as input.style]
[status-im.utils.fs :as fs]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.utils :as utils.utils]))
;; reference db levels
@ -74,7 +74,7 @@
;; to be called when app goes in background
(defonce on-background-cb (atom #()))
(fx/defn on-background
(rf/defn on-background
{:events [:audio-recorder/on-background]}
[_]
(when @on-background-cb
@ -267,15 +267,15 @@
(reset-timer timer)
(reset! state-cb #(update-state state))
(reset! max-recording-reached-cb
#(do
(when (= (:general @state) :recording)
(stop-recording {:rec-button-anim-value rec-button-anim-value
:ctrl-buttons-anim-value ctrl-buttons-anim-value
:timer timer
:max-recording-reached? true}))
(utils.utils/show-popup (i18n/label :t/audio-recorder)
(i18n/label
:t/audio-recorder-max-ms-reached))))
#(do
(when (= (:general @state) :recording)
(stop-recording {:rec-button-anim-value rec-button-anim-value
:ctrl-buttons-anim-value ctrl-buttons-anim-value
:timer timer
:max-recording-reached? true}))
(utils.utils/show-popup (i18n/label :t/audio-recorder)
(i18n/label
:t/audio-recorder-max-ms-reached))))
(reset! on-background-cb #(when (= (:general @state) :recording)
(pause-recording
{:rec-button-anim-value rec-button-anim-value

View File

@ -18,7 +18,7 @@
[status-im.ui.screens.chat.components.reply :as reply]
[status-im.ui.screens.chat.components.style :as styles]
[status-im.ui.screens.chat.photos :as photos]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.utils :as utils.utils]))
(defn input-focus
@ -104,13 +104,13 @@
;; typing. Timeout might be canceled on `on-change`.
(when platform/ios?
(reset!
timeout-id
(utils.utils/set-timeout
#(re-frame/dispatch [::mentions/on-selection-change
{:start start
:end end}
mentionable-users])
50)))
timeout-id
(utils.utils/set-timeout
#(re-frame/dispatch [::mentions/on-selection-change
{:start start
:end end}
mentionable-users])
50)))
;; NOTE(rasom): on Android we dispatch event only in case if there
;; was no text changes during last 50ms. `on-selection-change` is
;; dispatched after `on-change`, that's why there is no another way
@ -208,7 +208,7 @@
(when platform/ios?
(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
as arguments and returns new fx. Always clear all validation messages."
{:events [:chat.ui.input/set-chat-input-text]}
@ -314,32 +314,32 @@
(let [ens-name? (not= alias name)]
[list-item/list-item
(cond->
{:icon [photos/member-photo public-key]
:size :small
:text-size :small
:title
[text/text
{:weight :medium
:ellipsize-mode :tail
:number-of-lines 1
:size :small}
(if nickname
nickname
name)
(when nickname
[text/text
{:weight :regular
:color :secondary
:ellipsize-mode :tail
:size :small}
" "
(when ens-name?
"@")
name])]
:title-text-weight :medium
:on-press
(fn []
(re-frame/dispatch [:chat.ui/select-mention text-input-ref user]))}
{:icon [photos/member-photo public-key]
:size :small
:text-size :small
:title
[text/text
{:weight :medium
:ellipsize-mode :tail
:number-of-lines 1
:size :small}
(if nickname
nickname
name)
(when nickname
[text/text
{:weight :regular
:color :secondary
:ellipsize-mode :tail
:size :small}
" "
(when ens-name?
"@")
name])]
:title-text-weight :medium
:on-press
(fn []
(re-frame/dispatch [:chat.ui/select-mention text-input-ref user]))}
ens-name?
(assoc :subtitle alias))]))

View File

@ -10,7 +10,7 @@
[status-im.ui.components.react :as react]
[status-im.ui.components.slider :as slider]
[status-im.ui.screens.chat.styles.message.audio-old :as style]
[status-im.utils.fx :as fx]
[utils.re-frame :as rf]
[status-im.utils.platform :as platform]
[status-im.utils.utils :as utils]
[taoensso.timbre :as log]))
@ -30,17 +30,17 @@
(when @progress-timer
(utils/clear-interval @progress-timer))
(reset! progress-timer
(utils/set-interval
#(when (and @state-ref (not (:slider-seeking @state-ref)))
(let [ct (audio/get-player-current-time @player-ref)]
(reset! progress-ref ct)
(when ct
(anim/start (anim/timing progress-anim
{:toValue @progress-ref
:duration 100
:easing (.-linear ^js anim/easing)
:useNativeDriver true})))))
100))))
(utils/set-interval
#(when (and @state-ref (not (:slider-seeking @state-ref)))
(let [ct (audio/get-player-current-time @player-ref)]
(reset! progress-ref ct)
(when ct
(anim/start (anim/timing progress-anim
{:toValue @progress-ref
:duration 100
:easing (.-linear ^js anim/easing)
:useNativeDriver true})))))
100))))
(defn update-state
[{:keys [state-ref progress-ref progress-anim message-id seek-to-ms audio-duration-ms
@ -206,7 +206,7 @@
:accessibility-label :play-pause-audio-message-button
:color color}]])))
(fx/defn on-background
(rf/defn on-background
{:events [:audio-message/on-background]}
[_]
(when (and @current-active-state-ref-ref

View File

@ -7,7 +7,7 @@
[status-im.ui.components.list.views :as list]
[status-im.ui.components.react :as react]
[status-im.ui.screens.chat.message.message :as message]
[status-im.utils.handlers :refer [<sub]]))
[utils.re-frame :as rf]))
(def selected-unpin (reagent/atom nil))
@ -64,7 +64,7 @@
(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 {:height 60

View File

@ -5,37 +5,37 @@
[status-im.communities.core :as communities]
[status-im.i18n.i18n :as i18n]
[status-im.ui.components.profile-header.view :as profile-header]
[status-im.utils.handlers :refer [<sub >evt]]))
[utils.re-frame :as rf]))
(defn view
[]
(let [{:keys [chat-id]} (<sub [:get-screen-params])]
(let [{:keys [chat-id]} (rf/sub [:get-screen-params])]
(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 [position]} (<sub [:chats/community-chat-by-id
community-id chat-id])
category (<sub [:chats/category-by-chat-id
community-id chat-id])
{:keys [admin]} (<sub [:communities/community
community-id])
pinned-messages (<sub [:chats/pinned chat-id])]
{:keys [position]} (rf/sub [:chats/community-chat-by-id
community-id chat-id])
category (rf/sub [:chats/category-by-chat-id
community-id chat-id])
{:keys [admin]} (rf/sub [:communities/community
community-id])
pinned-messages (rf/sub [:chats/pinned chat-id])]
[quo/animated-header
{:left-accessories [{:icon :main-icons/arrow-left
:accessibility-label :back-button
:on-press #(>evt [:navigate-back])}]
:on-press #(rf/dispatch [:navigate-back])}]
:right-accessories (when admin
[{:icon :edit
:accessibility-label :invite-button
:on-press #(>evt [::communities/edit-channel-pressed
community-id
chat-name
description
color
emoji
chat-id
(:id category)
position])}])
:on-press #(rf/dispatch [::communities/edit-channel-pressed
community-id
chat-name
description
color
emoji
chat-id
(:id category)
position])}])
:extended-header (profile-header/extended-header
{:title chat-name
:color color
@ -50,10 +50,10 @@
(when admin
[quo/list-item
{:title (i18n/label :t/category)
:on-press #(>evt [:open-modal :select-category
{:chat current-chat
:category category
:community-id community-id}])
:on-press #(rf/dispatch [:open-modal :select-category
{:chat current-chat
:category category
:community-id community-id}])
:chevron true
:accessory :text
:accessory-text (if category

View File

@ -8,11 +8,11 @@
[status-im.ui.components.emoji-thumbnail.styles :as styles]
[status-im.ui.components.keyboard-avoid-presentation :as kb-presentation]
[status-im.ui.components.react :as react]
[status-im.utils.handlers :refer [<sub >evt]]))
[utils.re-frame :as rf]))
(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]
[rn/view styles/emoji-thumbnail-preview
[emoji-thumbnail-preview/emoji-thumbnail
@ -20,25 +20,25 @@
(defn color-circle
[item]
(let [{:keys [color]} (<sub [:communities/create-channel])
(let [{:keys [color]} (rf/sub [:communities/create-channel])
item-color (:color item)
key (:key key)
color-selected? (= (string/lower-case item-color) (string/lower-case color))]
[react/touchable-opacity
{:key key
: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 item-color)}]]]))
(defn update-emoji
[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
[]
(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))]

View File

@ -9,7 +9,7 @@
[status-im.ui.components.react :as react]
[status-im.ui.components.toolbar :as toolbar]
[status-im.ui.screens.communities.membership :as memberships]
[status-im.utils.handlers :refer [<sub >evt]]
[utils.re-frame :as rf]
[status-im.utils.image :as utils.image]
[utils.debounce :as debounce]))
@ -36,8 +36,8 @@
(js/setTimeout
(fn []
(react/show-image-picker
#(do (>evt [::communities/create-field :image (.-path ^js %)])
(>evt [::communities/create-field :new-image (.-path ^js %)]))
#(do (rf/dispatch [::communities/create-field :image (.-path ^js %)])
(rf/dispatch [::communities/create-field :new-image (.-path ^js %)]))
crop-opts))
300))
@ -48,8 +48,8 @@
(js/setTimeout
(fn []
(react/show-image-picker-camera
#(do (>evt [::communities/create-field :image (.-path ^js %)])
(>evt [::communities/create-field :new-image (.-path ^js %)]))
#(do (rf/dispatch [::communities/create-field :image (.-path ^js %)])
(rf/dispatch [::communities/create-field :new-image (.-path ^js %)]))
crop-opts))
300))
@ -63,7 +63,7 @@
:icon :main-icons/camera
:title (i18n/label :t/community-image-take)
:on-press #(do
(>evt [:bottom-sheet/hide])
(rf/dispatch [:bottom-sheet/hide])
(take-pic))}]
[quo/list-item
{:accessibility-label :pick-photo
@ -71,7 +71,7 @@
:theme :accent
:title (i18n/label :t/community-image-pick)
:on-press #(do
(>evt [:bottom-sheet/hide])
(rf/dispatch [:bottom-sheet/hide])
(pick-pic))}]
(when (and has-picture (not editing?))
[quo/list-item
@ -80,18 +80,18 @@
:theme :accent
:title (i18n/label :t/community-image-remove)
:on-press #(do
(>evt [:bottom-sheet/hide])
(>evt [::communities/remove-field :image]))}])]))
(rf/dispatch [:bottom-sheet/hide])
(rf/dispatch [::communities/remove-field :image]))}])]))
(defn photo-picker
[]
(let [{:keys [image editing?]} (<sub [:communities/create])]
(let [{:keys [image editing?]} (rf/sub [:communities/create])]
[rn/view
{:style {:padding-top 16
:align-items :center}}
[rn/touchable-opacity
{:on-press #(>evt [:bottom-sheet/show-sheet
{:content (bottom-sheet (boolean image) editing?)}])}
{:on-press #(rf/dispatch [:bottom-sheet/show-sheet
{:content (bottom-sheet (boolean image) editing?)}])}
[rn/view
{:style {:width 128
:height 128}}
@ -149,7 +149,7 @@
(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
:style {:flex 1}
@ -165,7 +165,7 @@
[quo/text-input
{:placeholder (i18n/label :t/name-your-community-placeholder)
:default-value name
:on-change-text #(>evt [::communities/create-field :name %])
:on-change-text #(rf/dispatch [::communities/create-field :name %])
:auto-focus true}]]
[rn/view
{:style {:padding-bottom 16
@ -179,7 +179,7 @@
{:placeholder (i18n/label :t/give-a-short-description-community)
:multiline true
: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}
(i18n/label :t/community-thumbnail-image)]
[photo-picker]
@ -192,7 +192,7 @@
[membership :title]
:t/membership-none))
:accessory :text
:on-press #(>evt [:navigate-to :community-membership])
:on-press #(rf/dispatch [:navigate-to :community-membership])
:chevron true
:size :small}]
[quo/list-footer
@ -201,7 +201,7 @@
(defn view
[]
(let [{:keys [name description]} (<sub [:communities/create])]
(let [{:keys [name description]} (rf/sub [:communities/create])]
[rn/keyboard-avoiding-view {:style {:flex 1}}
[form]
[toolbar/toolbar

View File

@ -9,7 +9,7 @@
[status-im.ui.components.react :as react]
[status-im.ui.components.toolbar :as toolbar]
[status-im.ui.screens.home.views.inner-item :as inner-item]
[status-im.utils.handlers :refer [<sub]]
[utils.re-frame :as rf]
[utils.debounce :as debounce]))
(defn valid?
@ -36,11 +36,11 @@
(defn view
[]
(let [{:keys [community-id]} (<sub [:get-screen-params])
(let [{:keys [community-id]} (rf/sub [:get-screen-params])
category-name (reagent/atom "")
_ (reset! selected-items #{})]
(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}}
[react/view {:flex 1}
[react/view {:padding-horizontal 16}

View File

@ -9,7 +9,7 @@
[status-im.ui.components.keyboard-avoid-presentation :as kb-presentation]
[status-im.ui.components.toolbar :as toolbar]
[status-im.ui.screens.communities.create :as create]
[status-im.utils.handlers :refer [<sub >evt]]
[utils.re-frame :as rf]
[utils.debounce :as debounce]))
(defn valid?
@ -21,16 +21,16 @@
(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]
[rn/view styles/emoji-thumbnail-preview
[emoji-thumbnail-preview/emoji-thumbnail-touchable
emoji color size
#(>evt [:open-modal :community-emoji-thumbnail-picker nil])]]))
#(rf/dispatch [:open-modal :community-emoji-thumbnail-picker nil])]]))
(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}
:content-container-style {:padding-bottom 16}}
@ -39,7 +39,7 @@
[rn/view {:padding-horizontal 16}
[quo/text-input
{: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
:auto-focus false}]]
[quo/separator {:style {:margin-vertical 16}}]
@ -52,11 +52,11 @@
{:placeholder (i18n/label :t/give-a-short-description-community)
:multiline true
:default-value description
:on-change-text #(>evt [::communities/create-channel-field :description %])}]]]]))
:on-change-text #(rf/dispatch [::communities/create-channel-field :description %])}]]]]))
(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}}
[quo/separator]
[form]

View File

@ -4,11 +4,11 @@
[status-im.i18n.i18n :as i18n]
[status-im.ui.components.toolbar :as toolbar]
[status-im.ui.screens.communities.create :as community.create]
[status-im.utils.handlers :refer [<sub >evt]]))
[utils.re-frame :as rf]))
(defn edit
[]
(let [{:keys [name description]} (<sub [:communities/create])]
(let [{:keys [name description]} (rf/sub [:communities/create])]
[:<>
[community.create/form]
[toolbar/toolbar
@ -17,5 +17,5 @@
[quo/button
{:disabled (not (community.create/valid? name description))
:type :secondary
:on-press #(>evt [::communities/edit-confirmation-pressed])}
:on-press #(rf/dispatch [::communities/edit-confirmation-pressed])}
(i18n/label :t/save)]}]]))

View File

@ -5,7 +5,7 @@
[status-im.i18n.i18n :as i18n]
[status-im.ui.components.toolbar :as toolbar]
[status-im.ui.screens.communities.create-channel :as create-channel]
[status-im.utils.handlers :refer [<sub]]
[utils.re-frame :as rf]
[utils.debounce :as debounce]))
(defn valid?
@ -14,7 +14,7 @@
(defn view
[]
(let [{:keys [name]} (<sub [:communities/create-channel])]
(let [{:keys [name]} (rf/sub [:communities/create-channel])]
(fn []
[:<>
[create-channel/form]

View File

@ -5,7 +5,7 @@
[status-im.communities.core :as communities]
[status-im.i18n.i18n :as i18n]
[status-im.ui.components.toolbar :as toolbar]
[status-im.utils.handlers :refer [>evt]]))
[utils.re-frame :as rf]))
(defn view
[]
@ -30,5 +30,5 @@
:center [quo/button
{:disabled (= @community-key "")
:type :secondary
:on-press #(>evt [::communities/import @community-key])}
:on-press #(rf/dispatch [::communities/import @community-key])}
(i18n/label :t/import)]}]])))

View File

@ -10,7 +10,8 @@
[status-im.ui.components.chat-icon.screen :as chat-icon.screen]
[status-im.ui.components.toolbar :as toolbar]
[status-im.ui.components.topbar :as topbar]
[status-im.utils.handlers :refer [<sub >evt-once]]))
[utils.debounce :as debounce]
[utils.re-frame :as rf]))
(defn header
[user-pk]
@ -46,12 +47,12 @@
[]
(let [user-pk (reagent/atom "")
contacts-selected (reagent/atom #{})
{:keys [invite?]} (<sub [:get-screen-params])]
{:keys [invite?]} (rf/sub [:get-screen-params])]
(fn []
(let [contacts-data (<sub [:contacts/active])
(let [contacts-data (rf/sub [:contacts/active])
{:keys [permissions
can-manage-users?]}
(<sub [:communities/edited-community])
(rf/sub [:communities/edited-community])
selected @contacts-selected
contacts (map (fn [{:keys [public-key] :as contact}]
(assoc contact :active (contains? selected public-key)))
@ -83,9 +84,10 @@
(zero? (count selected)))
:accessibility-label :share-community-link
:type :secondary
:on-press #(>evt-once
:on-press #(debounce/dispatch-and-chill
[(if can-invite?
::communities/invite-people-confirmation-pressed
::communities/share-community-confirmation-pressed) @user-pk
selected])}
selected]
3000)}
(i18n/label (if can-invite? :t/invite :t/share))]}]]))))

View File

@ -10,12 +10,12 @@
[status-im.ui.components.react :as react]
[status-im.ui.components.topbar :as topbar]
[status-im.ui.components.unviewed-indicator :as unviewed-indicator]
[status-im.utils.handlers :refer [<sub >evt]]))
[utils.re-frame :as rf]))
(defn hide-sheet-and-dispatch
[event]
(>evt [:bottom-sheet/hide])
(>evt event))
(rf/dispatch [:bottom-sheet/hide])
(rf/dispatch event))
(defn member-sheet
[first-name {:keys [public-key] :as member} community-id can-kick-users? can-manage-users? admin?]
@ -36,22 +36,22 @@
{:theme :negative
:icon :main-icons/arrow-left
: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?
[:<>
[quo/list-item
{:theme :negative
:icon :main-icons/cancel
: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?
[:<>
[quo/list-item
{:theme :accent
:icon :main-icons/make-admin
: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 _ _
@ -60,8 +60,8 @@
can-manage-users?
can-kick-users?
admin?]}]
(let [member (<sub [:contacts/contact-by-identity public-key])
[first-name second-name] (<sub [:contacts/contact-two-names-by-identity public-key])]
(let [member (rf/sub [:contacts/contact-by-identity public-key])
[first-name second-name] (rf/sub [:contacts/contact-two-names-by-identity public-key])]
[quo/list-item
{:title first-name
:subtitle second-name
@ -72,10 +72,10 @@
:accessory (when (not= public-key my-public-key)
[quo/button
{:on-press
#(>evt [:bottom-sheet/show-sheet
{:content (fn []
[member-sheet first-name member community-id
can-kick-users? can-manage-users? admin?])}])
#(rf/dispatch [:bottom-sheet/show-sheet
{:content (fn []
[member-sheet first-name member community-id
can-kick-users? can-manage-users? admin?])}])
:type :icon
:theme :icon
:accessibility-label :menu-option}
@ -89,12 +89,12 @@
:title (i18n/label :t/invite-people)
:accessibility-label :community-invite-people
: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}}]])
(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)]
[:<>
[quo/list-item
@ -103,21 +103,21 @@
[react/view {:flex-direction :row}
(when (pos? 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)}]
[quo/separator {:style {:margin-vertical 8}}]]))
(defn members
[]
(let [{:keys [community-id]} (<sub [:get-screen-params])]
(let [{:keys [community-id]} (rf/sub [:get-screen-params])]
(fn []
(let [my-public-key (<sub [:multiaccount/public-key])
(let [my-public-key (rf/sub [:multiaccount/public-key])
{:keys [permissions
can-manage-users?
admin]}
(<sub [:communities/community community-id])
sorted-members (<sub [:communities/sorted-community-members
community-id])]
(rf/sub [:communities/community community-id])
sorted-members (rf/sub [:communities/sorted-community-members
community-id])]
[:<>
[topbar/topbar
{:title (i18n/label :t/community-members-title)
@ -142,6 +142,6 @@
(reagent/create-class
{:display-name "community-members-view"
:component-did-mount (fn []
(communities/fetch-requests-to-join! (get (<sub [:get-screen-params])
(communities/fetch-requests-to-join! (get (rf/sub [:get-screen-params])
:community-id)))
:reagent-render members}))

View File

@ -5,7 +5,7 @@
[status-im.constants :as constants]
[status-im.i18n.i18n :as i18n]
[status-im.ui.components.toolbar :as toolbar]
[status-im.utils.handlers :refer [<sub >evt]]))
[utils.re-frame :as rf]))
(def options
{constants/community-on-request-access
@ -30,7 +30,7 @@
(defn membership
[]
(let [{:keys [membership]} (<sub [:communities/create])]
(let [{:keys [membership]} (rf/sub [:communities/create])]
[:<>
[rn/scroll-view {}
(doall
@ -38,10 +38,10 @@
^{:key (str "option-" id)}
[option o
{:selected (= id membership)
:on-select #(>evt [::communities/create-field :membership id])}]))]
:on-select #(rf/dispatch [::communities/create-field :membership id])}]))]
[toolbar/toolbar
{:show-border? true
:center [quo/button
{:type :secondary
:on-press #(>evt [:navigate-back])}
:on-press #(rf/dispatch [:navigate-back])}
(i18n/label :t/done)]}]]))

View File

@ -12,14 +12,14 @@
[status-im.ui.components.profile-header.view :as profile-header]
[status-im.ui.components.react :as react]
[status-im.ui.components.unviewed-indicator :as unviewed-indicator]
[status-im.utils.handlers :refer [<sub >evt]]))
[utils.re-frame :as rf]))
(defn management
[]
(let [{:keys [community-id]} (<sub [:get-screen-params])]
(let [{:keys [community-id]} (rf/sub [:get-screen-params])]
(fn []
(let [requests-to-join (<sub [:communities/requests-to-join-for-community community-id])
community (<sub [:communities/community community-id])
(let [requests-to-join (rf/sub [:communities/requests-to-join-for-community community-id])
community (rf/sub [:communities/community community-id])
{:keys [color members permissions description name admin]} community
roles false
notifications false
@ -30,11 +30,11 @@
[quo/animated-header
{:left-accessories [{:icon :main-icons/arrow-left
:accessibility-label :back-button
:on-press #(>evt [:navigate-back])}]
:on-press #(rf/dispatch [:navigate-back])}]
:right-accessories [{:icon :main-icons/share
: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
{:title name
:color (or color (rand-nth colors/chat-colors))
@ -82,7 +82,7 @@
(when (pos? members-count)
[quo/text {:color :secondary} (str members-count)])
[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)
:icon :main-icons/group-chat}])
(when (and admin roles)
@ -102,25 +102,25 @@
{:theme :accent
:icon :main-icons/edit
: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
:icon :main-icons/arrow-left
: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
(when false
[quo/list-item
{:theme :negative
:icon :main-icons/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
[]
(reagent/create-class
{:display-name "community-profile-view"
:component-did-mount (fn []
(communities/fetch-requests-to-join! (get (<sub [:get-screen-params])
(communities/fetch-requests-to-join! (get (rf/sub [:get-screen-params])
:community-id)))
:reagent-render management}))

View File

@ -16,7 +16,7 @@
[status-im.ui.components.topbar :as topbar]
[status-im.ui.screens.communities.community :as community]
[status-im.ui.screens.home.views.inner-item :as inner-item]
[status-im.utils.handlers :refer [<sub >evt]]
[utils.re-frame :as rf]
[status-im.utils.platform :as platform]
[status-im.utils.utils :as utils]))
@ -29,7 +29,7 @@
{:title (i18n/label :t/delete-confirmation)
:content (i18n/label :t/delete-chat-confirmation)
: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]
@ -37,7 +37,7 @@
{:title (i18n/label :t/delete-confirmation)
:content (i18n/label :t/delete-category-confirmation)
: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?
[]
@ -131,15 +131,15 @@
chat-id (string/replace id community-id "")]
(when-not (and (= new-position position) (= new-category categoryID))
(update-local-atom data-js)
(>evt [::communities/reorder-community-category-chat
community-id new-category chat-id new-position]))))
(rf/dispatch [::communities/reorder-community-category-chat
community-id new-category chat-id new-position]))))
(defn on-drag-end-category
[from to data-js]
(let [{:keys [id community-id position]} (get @data from)]
(when (and (< to (count @data)) (not= position to) (not= id ""))
(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]
@ -150,16 +150,16 @@
(defn reset-data
[categories chats]
(reset! data
(if (categories-tab?)
categories
(walk/postwalk-replace
{:chat-id :id}
(reduce (fn [acc category]
(-> acc
(conj category)
(into (get chats (:id category)))))
[]
categories)))))
(if (categories-tab?)
categories
(walk/postwalk-replace
{:chat-id :id}
(reduce (fn [acc category]
(-> acc
(conj category)
(into (get chats (:id category)))))
[]
categories)))))
(defn draggable-list
[]
@ -188,11 +188,11 @@
(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]}
(<sub [:communities/community community-id])
sorted-categories (<sub [:communities/sorted-categories
community-id])
(rf/sub [:communities/community community-id])
sorted-categories (rf/sub [:communities/sorted-categories
community-id])
categories (if (categories-tab?)
sorted-categories
(conj sorted-categories
@ -201,7 +201,7 @@
sorted-categories)
:name (i18n/label :t/none)
:community-id community-id}))
chats (<sub
chats (rf/sub
[:chats/sorted-categories-by-community-id
community-id])]
(reset-data categories chats)
@ -214,4 +214,4 @@
[community/blank-page (i18n/label :t/welcome-community-blank-message-edit-chats)]
[:<>
[chats_and_categories]
[draggable-list]])]))
[draggable-list]])]))

View File

@ -12,7 +12,7 @@
[status-im.ui.components.icons.icons :as icons]
[status-im.ui.components.react :as react]
[status-im.ui.components.topbar :as topbar]
[status-im.utils.handlers :refer [<sub]]))
[utils.re-frame :as rf]))
(defn request-actions
[community-id request-id]
@ -37,7 +37,7 @@
[{:keys [id public-key]} _ _
{:keys [community-id
can-manage-users?]}]
(let [member (or (<sub [:contacts/contact-by-identity public-key])
(let [member (or (rf/sub [:contacts/contact-by-identity public-key])
{:public-key public-key})]
[quo/list-item
{:title (multiaccounts/displayed-name member)
@ -52,10 +52,10 @@
(defn requests-to-join
[]
(let [{:keys [community-id]} (<sub [:get-screen-params])]
(let [{:keys [community-id]} (rf/sub [:get-screen-params])]
(fn []
(let [requests (<sub [:communities/requests-to-join-for-community community-id])
{:keys [can-manage-users?]} (<sub [:communities/community community-id])]
(let [requests (rf/sub [:communities/requests-to-join-for-community community-id])
{:keys [can-manage-users?]} (rf/sub [:communities/community community-id])]
[:<>
[topbar/topbar
{:title (i18n/label :t/community-requests-to-join-title)
@ -72,6 +72,6 @@
(reagent/create-class
{:display-name "community-requests-to-join-view"
:component-did-mount (fn []
(communities/fetch-requests-to-join! (get (<sub [:get-screen-params])
(communities/fetch-requests-to-join! (get (rf/sub [:get-screen-params])
:community-id)))
:reagent-render requests-to-join}))

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