[#16422] Merge profile and profile overview into one map in status-go (#16507)

* [#16422] Merge profile and profile overview into one map in status-go
This commit is contained in:
flexsurfer 2023-07-06 19:46:21 +02:00 committed by GitHub
parent 26dcc16ea6
commit 4327653b0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 487 additions and 646 deletions

View File

@ -619,3 +619,40 @@
bookmarks) bookmarks)
stored-bookmarks (get-in db [:bookmarks/bookmarks])] stored-bookmarks (get-in db [:bookmarks/bookmarks])]
{:db (assoc-in db [:bookmarks/bookmarks] (merge stored-bookmarks changed-bookmarks))})) {:db (assoc-in db [:bookmarks/bookmarks] (merge stored-bookmarks changed-bookmarks))}))
(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}]
(assoc acc dapp dapp-permissions))
{}
all-dapp-permissions)]
{:db (assoc db :dapps/permissions dapp-permissions)}))
(rf/defn initialize-browsers
{:events [::initialize-browsers]}
[{:keys [db]} all-stored-browsers]
(let [browsers (reduce (fn [acc {:keys [browser-id] :as browser}]
(assoc acc browser-id browser))
{}
all-stored-browsers)]
{:db (assoc db :browser/browsers browsers)}))
(rf/defn initialize-bookmarks
{:events [::initialize-bookmarks]}
[{:keys [db]} stored-bookmarks]
(let [bookmarks (reduce (fn [acc {:keys [url] :as bookmark}]
(assoc acc url bookmark))
{}
stored-bookmarks)]
{:db (assoc db :bookmarks/bookmarks bookmarks)}))
(rf/defn initialize-browser
[_]
{:json-rpc/call
[{:method "wakuext_getBrowsers"
:on-success #(re-frame/dispatch [::initialize-browsers %])}
{:method "browsers_getBookmarks"
:on-success #(re-frame/dispatch [::initialize-bookmarks %])}
{:method "permissions_getDappPermissions"
:on-success #(re-frame/dispatch [::initialize-dapp-permissions %])}]})

View File

@ -109,7 +109,7 @@
rpc->type rpc->type
unmarshal-members)) unmarshal-members))
(rf/defn fetch-chats-rpc (rf/defn fetch-chats-preview
[_ {:keys [on-success]}] [_ {:keys [on-success]}]
{:json-rpc/call [{:method "wakuext_chatsPreview" {:json-rpc/call [{:method "wakuext_chatsPreview"
:params [] :params []

View File

@ -1,7 +1,8 @@
(ns status-im.data-store.settings (ns status-im.data-store.settings
(:require [status-im.data-store.visibility-status-updates :as visibility-status-updates] (:require [status-im.data-store.visibility-status-updates :as visibility-status-updates]
[status-im.ethereum.eip55 :as eip55] [status-im.ethereum.eip55 :as eip55]
[status-im2.config :as config])) [status-im2.config :as config]
[clojure.set :as set]))
(defn rpc->networks (defn rpc->networks
[networks] [networks]
@ -33,27 +34,20 @@
{} {}
custom-bootnodes)) custom-bootnodes))
(defn rpc->stickers-packs
[stickers-packs]
(reduce-kv (fn [acc pack-id stickers-pack]
(assoc acc (js/parseInt (name pack-id)) stickers-pack))
{}
stickers-packs))
(defn rpc->settings (defn rpc->settings
[settings] [settings]
(-> settings (-> settings
(update :dapps-address eip55/address->checksum) (update :dapps-address eip55/address->checksum)
(update :address eip55/address->checksum) (update :address eip55/address->checksum)
(update :networks/networks rpc->networks) (update :networks/networks rpc->networks)
(update :networks/current-network (update :networks/current-network #(if (seq %) % config/default-network))
#(if (seq %)
%
config/default-network))
(update :wallet/visible-tokens rpc->visible-tokens) (update :wallet/visible-tokens rpc->visible-tokens)
(update :pinned-mailservers rpc->pinned-mailservers) (update :pinned-mailservers rpc->pinned-mailservers)
(update :link-previews-enabled-sites set) (update :link-previews-enabled-sites set)
(update :custom-bootnodes rpc->custom-bootnodes) (update :custom-bootnodes rpc->custom-bootnodes)
(update :custom-bootnodes-enabled? rpc->custom-bootnodes) (update :custom-bootnodes-enabled? rpc->custom-bootnodes)
(update :currency keyword) (update :currency keyword)
(visibility-status-updates/<-rpc-settings))) (visibility-status-updates/<-rpc-settings)
(dissoc :networks/current-network :networks/networks)
(set/rename-keys {:compressedKey :compressed-key
:emojiHash :emoji-hash})))

View File

@ -9,7 +9,8 @@
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im2.contexts.shell.activity-center.events :as activity-center] [status-im2.contexts.shell.activity-center.events :as activity-center]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[utils.re-frame :as rf])) [utils.re-frame :as rf]
[status-im.data-store.invitations :as data-store.invitations]))
(rf/defn navigate-chat-updated (rf/defn navigate-chat-updated
{:events [:navigate-chat-updated]} {:events [:navigate-chat-updated]}
@ -258,3 +259,19 @@
:on-accept #(do :on-accept #(do
(re-frame/dispatch [:bottom-sheet/hide-old]) (re-frame/dispatch [:bottom-sheet/hide-old])
(re-frame/dispatch [:group-chats.ui/leave-chat-confirmed chat-id]))}})) (re-frame/dispatch [:group-chats.ui/leave-chat-confirmed chat-id]))}}))
(rf/defn initialize-invitations
{:events [::initialize-invitations]}
[{:keys [db]} invitations]
{:db (assoc db
:group-chat/invitations
(reduce (fn [acc {:keys [id] :as inv}]
(assoc acc id (data-store.invitations/<-rpc inv)))
{}
invitations))})
(rf/defn get-group-chat-invitations
[_]
{:json-rpc/call
[{:method "wakuext_getGroupChatInvitations"
:on-success #(re-frame/dispatch [::initialize-invitations %])}]})

View File

@ -1,57 +1,13 @@
(ns status-im.multiaccounts.login.core (ns status-im.multiaccounts.login.core
(:require (:require
[clojure.string :as string]
[clojure.set :as set]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.async-storage.core :as async-storage]
[status-im.communities.core :as communities]
[status-im.data-store.chats :as data-store.chats]
[status-im.data-store.invitations :as data-store.invitations]
[status-im.data-store.settings :as data-store.settings]
[status-im.data-store.switcher-cards :as switcher-cards-store]
[status-im.data-store.visibility-status-updates :as visibility-status-updates-store]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.ethereum.eip55 :as eip55]
[status-im.ethereum.tokens :as tokens]
[status-im.ethereum.transactions.core :as transactions]
[status-im.fleet.core :as fleet]
[utils.i18n :as i18n]
[status-im.mobile-sync-settings.core :as mobile-network]
[status-im.multiaccounts.core :as multiaccounts]
[native-module.core :as native-module] [native-module.core :as native-module]
[status-im.notifications.core :as notifications]
[status-im.signing.eip1559 :as eip1559]
[status-im.transport.core :as transport]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[status-im2.config :as config]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im.utils.mobile-sync :as utils.mobile-sync]
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[status-im.utils.utils :as utils] [utils.security.core :as security]))
[status-im.utils.wallet-connect :as wallet-connect]
[status-im.wallet.core :as wallet]
[status-im.wallet.prices :as prices]
[status-im2.common.json-rpc.events :as json-rpc]
[status-im2.contexts.shell.activity-center.events :as activity-center]
[status-im2.contexts.chat.messages.link-preview.events :as link-preview]
[status-im2.contexts.contacts.events :as contacts]
[status-im2.navigation.events :as navigation]
[status-im2.contexts.shell.jump-to.constants :as shell.constants]
[status-im2.contexts.communities.discover.events :as contract-communities]
[status-im2.common.log :as logging]
[taoensso.timbre :as log]
[status-im2.contexts.shell.jump-to.utils :as shell.utils]
[utils.security.core :as security]
[status-im2.common.keychain.events :as keychain]))
(re-frame/reg-fx
::initialize-transactions-management-enabled
(fn []
(let [callback #(re-frame/dispatch [:multiaccounts.ui/switch-transactions-management-enabled %])]
(async-storage/get-item
:transactions-management-enabled?
callback))))
(re-frame/reg-fx (re-frame/reg-fx
::export-db ::export-db
@ -63,104 +19,6 @@
(fn [[key-uid account-data hashed-password]] (fn [[key-uid account-data hashed-password]]
(native-module/import-db key-uid account-data hashed-password))) (native-module/import-db key-uid account-data hashed-password)))
(re-frame/reg-fx
::enable-local-notifications
(fn []
(native-module/start-local-notifications)))
(re-frame/reg-fx
::initialize-wallet-connect
(fn []
(wallet-connect/init
#(re-frame/dispatch [:wallet-connect/client-init %])
#(log/error "[wallet-connect]" %))))
(defn rpc->accounts
[accounts]
(reduce (fn [acc {:keys [chat type wallet] :as account}]
(if chat
acc
(let [account (cond-> (update account
:address
eip55/address->checksum)
type
(update :type keyword))]
;; if the account is the default wallet we
;; put it first in the list
(if wallet
(into [account] acc)
(conj acc account)))))
[]
accounts))
;;TODO remove this code after all invalid names will be fixed (ask chu or flexsurfer)
(def invalid-addrr
#{"0x9575cf381f71368a54e09b8138ebe046a1ef31ce93e6c37661513b21faaf741e"
"0x56fa5de8cd4f2a3cbc122e7c51ac8690c6fc739b7c3724add97d0c55cc783d45"
"0xf0e49d178fa34ac3ade4625e144f51e5f982434f0912bcbe23b6467343f48305"
"0x60d1bf67e9d0d34368a6422c55f034230cc0997b186dd921fd18e89b7f0df5f2"
"0x5fe69d562990616a02f4a5f934aa973b27bf02c4fc774f9ad82f105379f16789"
"0xf1cabf2d74576ef76dfcb1182fd59a734a26c95ea6e68fc8f91ca4bfa1ea0594"
"0x21d8ce6c0e32481506f98218920bee88f03d9c1b45dab3546948ccc34b1aadea"
"0xbf7a74b39090fb5b1366f61fb4ac3ecc4b7f99f0fd3cb326dc5c18c58d58d7b6"
"0xeeb570494d442795235589284100812e4176e9c29d151a81df43b6286ef66c49"
"0x86a12d91c813f69a53349ff640e32af97d5f5c1f8d42d54cf4c8aa8dea231955"
"0x0011a30f5b2023bc228f6dd5608b3e7149646fa83f33350926ceb1925af78f08"})
(rf/defn check-invalid-ens
[{:keys [db]}]
(async-storage/get-item
:invalid-ens-name-seen
(fn [already-seen]
(when (and (not already-seen)
(boolean (get invalid-addrr
(ethereum/sha3 (string/lower-case (ethereum/default-address db))))))
(utils/show-popup
(i18n/label :t/warning)
(i18n/label :t/ens-username-invalid-name-warning)
#(async-storage/set-item! :invalid-ens-name-seen true)))))
nil)
(rf/defn initialize-wallet
{:events [::initialize-wallet]}
[{:keys [db] :as cofx} accounts tokens custom-tokens
favourites scan-all-tokens? new-account?]
(rf/merge
cofx
{:db (assoc db
:profile/wallet-accounts
(rpc->accounts accounts))
;; NOTE: Local notifications should be enabled only after wallet was started
::enable-local-notifications nil}
(check-invalid-ens)
(wallet/initialize-tokens tokens custom-tokens)
(wallet/initialize-favourites favourites)
(wallet/get-pending-transactions)
(wallet/fetch-collectibles-collection)
(cond
(and new-account?
(not scan-all-tokens?))
(wallet/set-zero-balances (first accounts))
(and new-account?
scan-all-tokens?
(not (utils.mobile-sync/cellular? (:network/type db))))
(wallet/set-max-block (get (first accounts) :address) 0)
:else
(wallet/get-cached-balances scan-all-tokens?))
(when-not (get db :wallet/new-account)
(wallet/restart-wallet-service nil))
(when (or (not (utils.mobile-sync/syncing-allowed? cofx))
(ethereum/binance-chain? db))
(transactions/get-fetched-transfers))
(when (ethereum/binance-chain? db)
(wallet/request-current-block-update))
(prices/update-prices)))
(rf/defn export-db-submitted (rf/defn export-db-submitted
{:events [:multiaccounts.login.ui/export-db-submitted]} {:events [:multiaccounts.login.ui/export-db-submitted]}
[{:keys [db]}] [{:keys [db]}]
@ -184,404 +42,3 @@
(types/clj->json {:name name (types/clj->json {:name name
:key-uid key-uid}) :key-uid key-uid})
(ethereum/sha3 (security/safe-unmask-data password))]})) (ethereum/sha3 (security/safe-unmask-data password))]}))
(rf/defn finish-keycard-setup
[{:keys [db] :as cofx}]
{:db (update db :keycard dissoc :flow)})
(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}]
(assoc acc dapp dapp-permissions))
{}
all-dapp-permissions)]
{:db (assoc db :dapps/permissions dapp-permissions)}))
(rf/defn initialize-browsers
{:events [::initialize-browsers]}
[{:keys [db]} all-stored-browsers]
(let [browsers (reduce (fn [acc {:keys [browser-id] :as browser}]
(assoc acc browser-id browser))
{}
all-stored-browsers)]
{:db (assoc db :browser/browsers browsers)}))
(rf/defn initialize-bookmarks
{:events [::initialize-bookmarks]}
[{:keys [db]} stored-bookmarks]
(let [bookmarks (reduce (fn [acc {:keys [url] :as bookmark}]
(assoc acc url bookmark))
{}
stored-bookmarks)]
{:db (assoc db :bookmarks/bookmarks bookmarks)}))
(rf/defn initialize-invitations
{:events [::initialize-invitations]}
[{:keys [db]} invitations]
{:db (assoc db
:group-chat/invitations
(reduce (fn [acc {:keys [id] :as inv}]
(assoc acc id (data-store.invitations/<-rpc inv)))
{}
invitations))})
(rf/defn initialize-web3-client-version
{:events [::initialize-web3-client-version]}
[{:keys [db]} node-version]
{:db (assoc db :web3-node-version node-version)})
(rf/defn handle-close-app-confirmed
{:events [::close-app-confirmed]}
[_]
{:ui/close-application nil})
(rf/defn check-network-version
[_ network-id]
{:json-rpc/call
[{:method "net_version"
:on-success
(fn [fetched-network-id]
(when (not= network-id (str (int fetched-network-id)))
;;TODO: this shouldn't happen but in case it does
;;we probably want a better error message
(utils/show-popup
(i18n/label :t/ethereum-node-started-incorrectly-title)
(i18n/label :t/ethereum-node-started-incorrectly-description
{:network-id network-id
:fetched-network-id fetched-network-id})
#(re-frame/dispatch [::close-app-confirmed]))))}]})
(defn normalize-tokens
[network-id tokens]
(mapv #(-> %
(update :symbol keyword)
((partial tokens/update-icon (ethereum/chain-id->chain-keyword (int network-id)))))
tokens))
(re-frame/reg-fx
::get-tokens
(fn [[network-id accounts recovered-account?]]
(utils/set-timeout
(fn []
(json-rpc/call {:method "wallet_getTokens"
:params [(int network-id)]
:on-success #(re-frame/dispatch [::initialize-wallet
accounts
(normalize-tokens network-id %)
nil nil
recovered-account?
true])}))
2000)))
(re-frame/reg-fx
;;TODO: this could be replaced by a single API call on status-go side
::initialize-wallet
(fn [[network-id network callback]]
(-> (js/Promise.all
(clj->js
[(js/Promise.
(fn [resolve reject]
(json-rpc/call {:method "accounts_getAccounts"
:on-success resolve
:on-error reject})))
(js/Promise.
(fn [resolve _]
(json-rpc/call
{:method "wallet_addEthereumChain"
:params
[{:isTest false
:tokenOverrides []
:rpcUrl (get-in network [:config :UpstreamConfig :URL])
:chainColor "green"
:chainName (:name network)
:nativeCurrencyDecimals 10
:shortName "erc20"
:layer 1
:chainId (int network-id)
:enabled false
:fallbackURL (get-in network [:config :UpstreamConfig :URL])}]
:on-success resolve
:on-error (fn [_] (resolve nil))})))
(js/Promise.
(fn [resolve _]
(json-rpc/call {:method "wallet_getTokens"
:params [(int network-id)]
:on-success resolve
:on-error (fn [_]
(resolve nil))})))
(js/Promise.
(fn [resolve reject]
(json-rpc/call {:method "wallet_getCustomTokens"
:on-success resolve
:on-error reject})))
(js/Promise.
(fn [resolve reject]
(json-rpc/call {:method "wallet_getSavedAddresses"
:on-success resolve
:on-error reject})))]))
(.then (fn [[accounts _ tokens custom-tokens favourites]]
(callback accounts
(normalize-tokens network-id tokens)
(mapv #(update % :symbol keyword) custom-tokens)
(filter :favourite favourites))))
(.catch (fn [_]
(log/error "Failed to initialize wallet"))))))
(rf/defn initialize-browser
[_]
{:json-rpc/call
[{:method "wakuext_getBrowsers"
:on-success #(re-frame/dispatch [::initialize-browsers %])}
{:method "browsers_getBookmarks"
:on-success #(re-frame/dispatch [::initialize-bookmarks %])}
{:method "permissions_getDappPermissions"
:on-success #(re-frame/dispatch [::initialize-dapp-permissions %])}]})
(rf/defn get-group-chat-invitations
[_]
{:json-rpc/call
[{:method "wakuext_getGroupChatInvitations"
:on-success #(re-frame/dispatch [::initialize-invitations %])}]})
(rf/defn initialize-transactions-management-enabled
[cofx]
{::initialize-transactions-management-enabled nil})
(rf/defn initialize-wallet-connect
[cofx]
{::initialize-wallet-connect nil})
(rf/defn get-node-config-callback
{:events [::get-node-config-callback]}
[{:keys [db]} node-config-json]
(let [node-config (types/json->clj node-config-json)]
{:db (assoc-in db
[:profile/profile :wakuv2-config]
(get node-config :WakuV2Config))}))
(rf/defn get-node-config
[_]
(native-module/get-node-config #(re-frame/dispatch [::get-node-config-callback %])))
(rf/defn redirect-to-root
"Decides which root should be initialised depending on user and app state"
[{:keys [db] :as cofx}]
(let [pairing-completed? (= (get-in db [:syncing :pairing-status]) :completed)]
(cond
pairing-completed?
{:db (dissoc db :syncing)
:dispatch [:init-root :syncing-results]}
(get db :onboarding-2/new-account?)
{:dispatch [:onboarding-2/finalize-setup]}
:else
(rf/merge
cofx
(multiaccounts/switch-theme nil :shell-stack)
(navigation/init-root :shell-stack)))))
(rf/defn get-settings-callback
{:events [::get-settings-callback]}
[{:keys [db] :as cofx} settings]
(let [{:networks/keys [current-network networks]
:as settings}
(data-store.settings/rpc->settings settings)
multiaccount (-> settings
(dissoc :networks/current-network :networks/networks)
(set/rename-keys {:compressedKey :compressed-key
:emojiHash :emoji-hash}))
;;for some reason we save default networks in db, in case when we want to modify default-networks
;;for
;; existing accounts we have to merge them again into networks
merged-networks (merge networks config/default-networks-by-id)]
(rf/merge cofx
{:db (-> db
(dissoc :profile/login)
(assoc :networks/current-network current-network
:networks/networks merged-networks
:profile/profile multiaccount))}
(data-store.chats/fetch-chats-rpc
{:on-success
#(do (re-frame/dispatch [:chats-list/load-success %])
(rf/dispatch [:communities/get-user-requests-to-join])
(re-frame/dispatch [::get-chats-callback]))})
(get-node-config)
(communities/fetch)
(contract-communities/fetch-contract-communities)
(communities/fetch-collapsed-community-categories)
(communities/check-and-delete-pending-request-to-join)
(logging/set-log-level (:log-level multiaccount))
(activity-center/notifications-fetch-pending-contact-requests)
(activity-center/update-seen-state)
(activity-center/notifications-fetch-unread-count)
(redirect-to-root))))
(re-frame/reg-fx
::open-last-chat
(fn [key-uid]
(async-storage/get-item
:chat-id
(fn [chat-id]
(when chat-id
(async-storage/get-item
:key-uid
(fn [stored-key-uid]
(when (= stored-key-uid key-uid)
(re-frame/dispatch [:chat/navigate-to-chat chat-id
shell.constants/open-screen-without-animation])))))))))
(rf/defn check-last-chat
{:events [::check-last-chat]}
[{:keys [db]}]
{::open-last-chat (get-in db [:profile/profile :key-uid])})
(rf/defn update-wallet-accounts
[{:keys [db]} accounts]
(let [existing-accounts (into {} (map #(vector (:address %1) %1) (:profile/wallet-accounts db)))
reduce-fn (fn [existing-accs new-acc]
(let [address (:address new-acc)]
(if (:removed new-acc)
(dissoc existing-accs address)
(assoc existing-accs address new-acc))))
new-accounts (reduce reduce-fn existing-accounts (rpc->accounts accounts))]
{:db (assoc db :profile/wallet-accounts (vals new-accounts))}))
(rf/defn get-chats-callback
{:events [::get-chats-callback]}
[{:keys [db] :as cofx}]
(let [{:networks/keys [current-network networks]} db
notifications-enabled? (get-in db [:profile/profile :notifications-enabled?])
current-network-config (get networks current-network)
network-id (str (get-in networks
[current-network :config :NetworkId]))
remote-push-notifications-enabled?
(get-in db [:profile/profile :remote-push-notifications-enabled?])]
(rf/merge cofx
(cond-> {::eip1559/check-eip1559-activation
{:network-id network-id
:on-enabled #(log/info "eip1550 is activated")
:on-disabled #(log/info "eip1559 is not activated")}
::initialize-wallet
[network-id
current-network-config
(fn [accounts tokens custom-tokens favourites]
(re-frame/dispatch [::initialize-wallet
accounts tokens custom-tokens favourites]))]
::open-last-chat (get-in db [:profile/profile :key-uid])}
(or notifications-enabled? remote-push-notifications-enabled?)
(assoc ::notifications/enable remote-push-notifications-enabled?))
(transport/start-messenger)
(initialize-transactions-management-enabled)
(check-network-version network-id)
(contacts/initialize-contacts)
(initialize-browser)
(mobile-network/on-network-status-change)
(get-group-chat-invitations)
(multiaccounts/get-profile-picture)
(multiaccounts/switch-preview-privacy-mode-flag)
(link-preview/request-link-preview-whitelist)
(visibility-status-updates-store/fetch-visibility-status-updates-rpc)
(switcher-cards-store/fetch-switcher-cards-rpc))))
(defn get-new-auth-method
[auth-method save-password?]
(when save-password?
(when-not (= keychain/auth-method-biometric auth-method)
(when (= auth-method keychain/auth-method-biometric-prepare)
keychain/auth-method-biometric))))
(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)
(rf/merge cofx
{:db (assoc db :chats/loading? true)
:json-rpc/call
[{:method "settings_getSettings"
:on-success #(re-frame/dispatch [::get-settings-callback %])}]}
(notifications/load-notification-preferences)
(keychain/save-auth-method key-uid
(or new-auth-method auth-method keychain/auth-method-none)))))
(rf/defn create-only-events
[{:keys [db] :as cofx} recovered-account?]
(let [{:profile/keys [profile profiles-overview wallet-accounts]}
db
{:keys [creating?]} (:profile/login db)
first-account? (and creating? (empty? profiles-overview))
{:networks/keys [current-network networks]} db
network-id (str (get-in networks [current-network :config :NetworkId]))]
(shell.utils/change-selected-stack-id :communities-stack true nil)
(rf/merge cofx
{:db (-> db
(dissoc :profile/login)
(assoc :chats/loading? false)
(assoc-in [:profile/profile :multiaccounts/first-account]
first-account?))
::get-tokens [network-id wallet-accounts recovered-account?]}
(finish-keycard-setup)
(transport/start-messenger)
(communities/fetch)
(data-store.chats/fetch-chats-rpc
{:on-success #(re-frame/dispatch [:chats-list/load-success %])})
(multiaccounts/switch-preview-privacy-mode-flag)
(link-preview/request-link-preview-whitelist)
(logging/set-log-level (:log-level profile))
(navigation/init-root :enable-notifications))))
(defn- keycard-setup?
[cofx]
(boolean (get-in cofx [:db :keycard :flow])))
(defn on-login-update-db
[db now]
(-> db
(dissoc :connectivity/ui-status-properties)
(update :keycard dissoc :from-key-storage-and-migration?)
(update :keycard dissoc
:on-card-read
:card-read-in-progress?
:pin
:profile/profile)
(assoc :logged-in-since now)
(assoc :view-id :home)))
(rf/defn multiaccount-login-success
[{:keys [db now] :as cofx}]
(let [{:keys [key-uid password save-password? creating?]}
(:profile/login db)
multiaccounts (:profile/profiles-overview db)
recovered-account? (get db :recovered-account?)
login-only? (not (or creating?
recovered-account?
(keycard-setup? cofx)))
from-migration? (get-in db
[:keycard
:from-key-storage-and-migration?])
nodes nil]
(log/debug "[multiaccount] multiaccount-login-success"
"login-only?" login-only?
"recovered-account?" recovered-account?)
(rf/merge cofx
{:db (on-login-update-db db now)
:json-rpc/call
[{:method "web3_clientVersion"
:on-success #(re-frame/dispatch [::initialize-web3-client-version %])}]}
;;FIXME
(when nodes
(fleet/set-nodes :eth.contract nodes))
(when (and (not login-only?)
(not recovered-account?))
(wallet/set-initial-blocks-range))
(when from-migration?
(utils/show-popup (i18n/label :t/migration-successful)
(i18n/label :t/migration-successful-text)))
(if login-only?
(login-only-events key-uid password save-password?)
(create-only-events recovered-account?)))))

View File

@ -276,7 +276,7 @@
(rf/defn load-notification-preferences (rf/defn load-notification-preferences
{:events [::load-notification-preferences]} {:events [::load-notification-preferences]}
[cofx] [_]
{:json-rpc/call [{:method "localnotifications_notificationPreferences" {:json-rpc/call [{:method "localnotifications_notificationPreferences"
:params [] :params []
:on-success #(re-frame/dispatch [::preferences-loaded %])}]}) :on-success #(re-frame/dispatch [::preferences-loaded %])}]})

View File

@ -1,9 +1,7 @@
(ns status-im.signals.core (ns status-im.signals.core
(:require [status-im.chat.models.message :as models.message] (:require [status-im.chat.models.message :as models.message]
[status-im.ethereum.subscriptions :as ethereum.subscriptions] [status-im.ethereum.subscriptions :as ethereum.subscriptions]
[utils.i18n :as i18n]
[status-im.mailserver.core :as mailserver] [status-im.mailserver.core :as mailserver]
[status-im.multiaccounts.login.core :as login]
[status-im.notifications.local :as local-notifications] [status-im.notifications.local :as local-notifications]
[status-im.transport.message.core :as transport.message] [status-im.transport.message.core :as transport.message]
[status-im.visibility-status-updates.core :as visibility-status-updates] [status-im.visibility-status-updates.core :as visibility-status-updates]
@ -11,32 +9,9 @@
[status-im2.contexts.chat.messages.link-preview.events :as link-preview] [status-im2.contexts.chat.messages.link-preview.events :as link-preview]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[quo2.foundations.colors :as colors])) [quo2.foundations.colors :as colors]
[status-im2.contexts.profile.login.events :as profile.login]
(rf/defn status-node-started [utils.transforms :as transforms]))
[{db :db :as cofx} {:keys [error]}]
(log/debug "[signals] status-node-started"
"error"
error)
(if error
(cond->
{:db (-> db
(update :profile/login dissoc :processing)
(assoc-in [:profile/login :error]
;; NOTE: the only currently known error is
;; "file is not a database" which occurs
;; when the user inputs the wrong password
;; if that is the error that is found
;; we show the i18n label for wrong password
;; 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)))}
(= (:view-id db) :progress)
(assoc :dispatch [:navigate-to :login]))
(login/multiaccount-login-success cofx)))
(rf/defn summary (rf/defn summary
[{:keys [db] :as cofx} peers-summary] [{:keys [db] :as cofx} peers-summary]
@ -50,13 +25,10 @@
(rf/defn wakuv2-peer-stats (rf/defn wakuv2-peer-stats
[{:keys [db]} peer-stats] [{:keys [db]} peer-stats]
(let [previous-stats (:peer-stats db)] {:db (assoc db :peer-stats peer-stats :peers-count (count (:peers peer-stats)))})
{:db (assoc db
:peer-stats peer-stats
:peers-count (count (:peers peer-stats)))}))
(rf/defn handle-local-pairing-signals (rf/defn handle-local-pairing-signals
[{:keys [db] :as cofx} {:keys [type action data error] :as event}] [{:keys [db]} {:keys [type action data error] :as event}]
(log/info "local pairing signal received" (log/info "local pairing signal received"
{:event event}) {:event event})
(let [{:keys [account password]} data (let [{:keys [account password]} data
@ -123,7 +95,7 @@
^js event-js (.-event data) ^js event-js (.-event data)
type (.-type data)] type (.-type data)]
(case type (case type
"node.login" (status-node-started cofx (js->clj event-js :keywordize-keys true)) "node.login" (profile.login/login-node-signal cofx (transforms/js->clj event-js))
"backup.performed" {:db (assoc-in db "backup.performed" {:db (assoc-in db
[:profile/profile :last-backup] [:profile/profile :last-backup]
(.-lastBackup event-js))} (.-lastBackup event-js))}

View File

@ -4,8 +4,6 @@
(defonce london-activated? (atom false)) (defonce london-activated? (atom false))
(defonce activated-on-current-network? (atom nil))
(defn london-is-definitely-activated (defn london-is-definitely-activated
[network-id] [network-id]
(contains? #{"1" "3"} network-id)) (contains? #{"1" "3"} network-id))
@ -29,7 +27,9 @@
(defn enabled? (defn enabled?
([] @london-activated?) ([] @london-activated?)
([network-id enabled-callback disabled-callback] ([network-id enabled-callback disabled-callback]
(let [definitely-activated? (london-is-definitely-activated network-id)] (let [definitely-activated? (london-is-definitely-activated network-id)
enabled-callback (or enabled-callback #())
disabled-callback (or disabled-callback #())]
(cond (cond
definitely-activated? definitely-activated?
(do (do
@ -49,7 +49,6 @@
(disabled-callback)))))) (disabled-callback))))))
(re-frame/reg-fx (re-frame/reg-fx
::check-eip1559-activation :check-eip1559-activation
(fn [{:keys [network-id on-enabled on-disabled]}] (fn [network-id]
(enabled? network-id on-enabled on-disabled))) (enabled? network-id nil nil)))

View File

@ -13,14 +13,14 @@
[status-im.data-store.invitations :as data-store.invitations] [status-im.data-store.invitations :as data-store.invitations]
[status-im.data-store.reactions :as data-store.reactions] [status-im.data-store.reactions :as data-store.reactions]
[status-im.group-chats.core :as models.group] [status-im.group-chats.core :as models.group]
[status-im.multiaccounts.login.core :as multiaccounts.login]
[status-im.multiaccounts.update.core :as update.core] [status-im.multiaccounts.update.core :as update.core]
[status-im.pairing.core :as models.pairing] [status-im.pairing.core :as models.pairing]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[status-im.visibility-status-updates.core :as models.visibility-status-updates] [status-im.visibility-status-updates.core :as models.visibility-status-updates]
[status-im2.contexts.shell.activity-center.events :as activity-center] [status-im2.contexts.shell.activity-center.events :as activity-center]
[status-im2.contexts.chat.messages.pin.events :as messages.pin])) [status-im2.contexts.chat.messages.pin.events :as messages.pin]
[status-im.wallet.core :as wallet]))
(rf/defn process-next (rf/defn process-next
[cofx ^js response-js sync-handler] [cofx ^js response-js sync-handler]
@ -171,7 +171,7 @@
(js-delete response-js "accounts") (js-delete response-js "accounts")
(rf/merge cofx (rf/merge cofx
(process-next response-js sync-handler) (process-next response-js sync-handler)
(multiaccounts.login/update-wallet-accounts (types/js->clj accounts)))) (wallet/update-wallet-accounts (types/js->clj accounts))))
(seq settings) (seq settings)
(do (do

View File

@ -26,6 +26,17 @@
(string/join "\n" (log/get-logs-queue)) (string/join "\n" (log/get-logs-queue))
#(re-frame/dispatch [callback-handler %])))) #(re-frame/dispatch [callback-handler %]))))
(rf/defn store-web3-client-version
{:events [:logging/store-web3-client-version]}
[{:keys [db]} node-version]
{:db (assoc db :web3-node-version node-version)})
(rf/defn initialize-web3-client-version
{:events [:logging/initialize-web3-client-version]}
[_]
{:json-rpc/call [{:method "web3_clientVersion"
:on-success #(re-frame/dispatch [:logging/store-web3-client-version %])}]})
(defn email-body (defn email-body
"logs attached" "logs attached"
[{:keys [:web3-node-version :mailserver/current-id [{:keys [:web3-node-version :mailserver/current-id

View File

@ -21,7 +21,6 @@
[status-im.utils.core :as utils.core] [status-im.utils.core :as utils.core]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[utils.datetime :as datetime] [utils.datetime :as datetime]
[status-im.utils.mobile-sync :as mobile-network-utils]
[status-im.utils.money :as money] [status-im.utils.money :as money]
[status-im.utils.utils :as utils.utils] [status-im.utils.utils :as utils.utils]
[status-im.wallet.db :as wallet.db] [status-im.wallet.db :as wallet.db]
@ -30,7 +29,9 @@
[status-im.wallet.utils :as wallet.utils] [status-im.wallet.utils :as wallet.utils]
[status-im2.common.json-rpc.events :as json-rpc] [status-im2.common.json-rpc.events :as json-rpc]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[status-im.utils.mobile-sync :as utils.mobile-sync]
[native-module.core :as native-module]))
(defn get-balance (defn get-balance
[{:keys [address on-success on-error]}] [{:keys [address on-success on-error]}]
@ -732,7 +733,7 @@
{:keys [force-restart? on-recent-history-fetching] {:keys [force-restart? on-recent-history-fetching]
:as params}] :as params}]
(when (:profile/profile db) (when (:profile/profile db)
(let [syncing-allowed? (mobile-network-utils/syncing-allowed? cofx) (let [syncing-allowed? (utils.mobile-sync/syncing-allowed? cofx)
binance-chain? (ethereum/binance-chain? db)] binance-chain? (ethereum/binance-chain? db)]
(log/info "restart-wallet-service" (log/info "restart-wallet-service"
"force-restart?" force-restart? "force-restart?" force-restart?
@ -929,6 +930,7 @@
:on-error #(log/info "Initial blocks range was not set")}))) :on-error #(log/info "Initial blocks range was not set")})))
(rf/defn set-initial-blocks-range (rf/defn set-initial-blocks-range
{:events [:wallet/set-initial-blocks-range]}
[{:keys [db]}] [{:keys [db]}]
{:db (assoc db :wallet/new-account true) {:db (assoc db :wallet/new-account true)
::set-inital-range nil}) ::set-inital-range nil})
@ -1029,6 +1031,12 @@
{::async-storage/set! {:transactions-management-enabled? enabled?} {::async-storage/set! {:transactions-management-enabled? enabled?}
:db (assoc db :wallet/transactions-management-enabled? enabled?)}) :db (assoc db :wallet/transactions-management-enabled? enabled?)})
(re-frame/reg-fx
:wallet/initialize-transactions-management-enabled
(fn []
(let [callback #(re-frame/dispatch [:multiaccounts.ui/switch-transactions-management-enabled %])]
(async-storage/get-item :transactions-management-enabled? callback))))
(rf/defn update-current-block (rf/defn update-current-block
{:events [::update-current-block]} {:events [::update-current-block]}
[{:keys [db]} block] [{:keys [db]} block]
@ -1045,3 +1053,179 @@
(rf/defn request-current-block-update (rf/defn request-current-block-update
[_] [_]
{::request-current-block-update nil}) {::request-current-block-update nil})
(defn normalize-tokens
[network-id tokens]
(mapv #(-> %
(update :symbol keyword)
((partial tokens/update-icon (ethereum/chain-id->chain-keyword (int network-id)))))
tokens))
(re-frame/reg-fx
:wallet/get-tokens
(fn [[network-id accounts recovered-account?]]
(utils.utils/set-timeout
(fn []
(json-rpc/call {:method "wallet_getTokens"
:params [(int network-id)]
:on-success #(re-frame/dispatch [:wallet/initialize-wallet
accounts
(normalize-tokens network-id %)
nil nil
recovered-account?
true])}))
2000)))
(re-frame/reg-fx
;;TODO: this could be replaced by a single API call on status-go side
:wallet/initialize-wallet
(fn [[network-id network callback]]
(-> (js/Promise.all
(clj->js
[(js/Promise.
(fn [resolve reject]
(json-rpc/call {:method "accounts_getAccounts"
:on-success resolve
:on-error reject})))
(js/Promise.
(fn [resolve _]
(json-rpc/call
{:method "wallet_addEthereumChain"
:params
[{:isTest false
:tokenOverrides []
:rpcUrl (get-in network [:config :UpstreamConfig :URL])
:chainColor "green"
:chainName (:name network)
:nativeCurrencyDecimals 10
:shortName "erc20"
:layer 1
:chainId (int network-id)
:enabled false
:fallbackURL (get-in network [:config :UpstreamConfig :URL])}]
:on-success resolve
:on-error (fn [_] (resolve nil))})))
(js/Promise.
(fn [resolve _]
(json-rpc/call {:method "wallet_getTokens"
:params [(int network-id)]
:on-success resolve
:on-error (fn [_]
(resolve nil))})))
(js/Promise.
(fn [resolve reject]
(json-rpc/call {:method "wallet_getCustomTokens"
:on-success resolve
:on-error reject})))
(js/Promise.
(fn [resolve reject]
(json-rpc/call {:method "wallet_getSavedAddresses"
:on-success resolve
:on-error reject})))]))
(.then (fn [[accounts _ tokens custom-tokens favourites]]
(callback accounts
(normalize-tokens network-id tokens)
(mapv #(update % :symbol keyword) custom-tokens)
(filter :favourite favourites))))
(.catch (fn [_]
(log/error "Failed to initialize wallet"))))))
(defn rpc->accounts
[accounts]
(reduce (fn [acc {:keys [chat type wallet] :as account}]
(if chat
acc
(let [account (cond-> (update account
:address
eip55/address->checksum)
type
(update :type keyword))]
;; if the account is the default wallet we
;; put it first in the list
(if wallet
(into [account] acc)
(conj acc account)))))
[]
accounts))
;;TODO remove this code after all invalid names will be fixed (ask chu or flexsurfer)
(def invalid-addrr
#{"0x9575cf381f71368a54e09b8138ebe046a1ef31ce93e6c37661513b21faaf741e"
"0x56fa5de8cd4f2a3cbc122e7c51ac8690c6fc739b7c3724add97d0c55cc783d45"
"0xf0e49d178fa34ac3ade4625e144f51e5f982434f0912bcbe23b6467343f48305"
"0x60d1bf67e9d0d34368a6422c55f034230cc0997b186dd921fd18e89b7f0df5f2"
"0x5fe69d562990616a02f4a5f934aa973b27bf02c4fc774f9ad82f105379f16789"
"0xf1cabf2d74576ef76dfcb1182fd59a734a26c95ea6e68fc8f91ca4bfa1ea0594"
"0x21d8ce6c0e32481506f98218920bee88f03d9c1b45dab3546948ccc34b1aadea"
"0xbf7a74b39090fb5b1366f61fb4ac3ecc4b7f99f0fd3cb326dc5c18c58d58d7b6"
"0xeeb570494d442795235589284100812e4176e9c29d151a81df43b6286ef66c49"
"0x86a12d91c813f69a53349ff640e32af97d5f5c1f8d42d54cf4c8aa8dea231955"
"0x0011a30f5b2023bc228f6dd5608b3e7149646fa83f33350926ceb1925af78f08"})
(rf/defn check-invalid-ens
[{:keys [db]}]
(async-storage/get-item
:invalid-ens-name-seen
(fn [already-seen]
(when (and (not already-seen)
(boolean (get invalid-addrr
(ethereum/sha3 (string/lower-case (ethereum/default-address db))))))
(utils.utils/show-popup
(i18n/label :t/warning)
(i18n/label :t/ens-username-invalid-name-warning)
#(async-storage/set-item! :invalid-ens-name-seen true)))))
nil)
(re-frame/reg-fx
::enable-local-notifications
(fn []
(native-module/start-local-notifications)))
(rf/defn initialize-wallet
{:events [:wallet/initialize-wallet]}
[{:keys [db] :as cofx} accounts tokens custom-tokens
favourites scan-all-tokens? new-account?]
(rf/merge
cofx
{:db (assoc db
:profile/wallet-accounts
(rpc->accounts accounts))
;; NOTE: Local notifications should be enabled only after wallet was started
::enable-local-notifications nil
:dispatch-n [(when (or (not (utils.mobile-sync/syncing-allowed? cofx))
(ethereum/binance-chain? db))
[:transaction/get-fetched-transfers])]}
(check-invalid-ens)
(initialize-tokens tokens custom-tokens)
(initialize-favourites favourites)
(get-pending-transactions)
(fetch-collectibles-collection)
(cond
(and new-account?
(not scan-all-tokens?))
(set-zero-balances (first accounts))
(and new-account?
scan-all-tokens?
(not (utils.mobile-sync/cellular? (:network/type db))))
(set-max-block (get (first accounts) :address) 0)
:else
(get-cached-balances scan-all-tokens?))
(when-not (get db :wallet/new-account)
(restart-wallet-service nil))
(when (ethereum/binance-chain? db)
(request-current-block-update))
(prices/update-prices)))
(rf/defn update-wallet-accounts
[{:keys [db]} accounts]
(let [existing-accounts (into {} (map #(vector (:address %1) %1) (:profile/wallet-accounts db)))
reduce-fn (fn [existing-accs new-acc]
(let [address (:address new-acc)]
(if (:removed new-acc)
(dissoc existing-accs address)
(assoc existing-accs address new-acc))))
new-accounts (reduce reduce-fn existing-accounts (rpc->accounts accounts))]
{:db (assoc db :profile/wallet-accounts (vals new-accounts))}))

View File

@ -17,7 +17,10 @@
[status-im.utils.types :as types] [status-im.utils.types :as types]
[reagent.core :as reagent] [reagent.core :as reagent]
[quo2.foundations.colors :as colors] [quo2.foundations.colors :as colors]
[utils.datetime :as datetime])) [utils.datetime :as datetime]
[re-frame.core :as re-frame]
[status-im.async-storage.core :as async-storage]
[status-im2.contexts.shell.jump-to.constants :as shell.constants]))
(defn- get-chat (defn- get-chat
[cofx chat-id] [cofx chat-id]
@ -417,3 +420,22 @@
{:events [:chat.ui/lightbox-scale]} {:events [:chat.ui/lightbox-scale]}
[{:keys [db]} value] [{:keys [db]} value]
{:db (assoc db :lightbox/scale value)}) {:db (assoc db :lightbox/scale value)})
(re-frame/reg-fx
:chat/open-last-chat
(fn [key-uid]
(async-storage/get-item
:chat-id
(fn [chat-id]
(when chat-id
(async-storage/get-item
:key-uid
(fn [stored-key-uid]
(when (= stored-key-uid key-uid)
(re-frame/dispatch [:chat/navigate-to-chat chat-id
shell.constants/open-screen-without-animation])))))))))
(rf/defn check-last-chat
{:events [:chat/check-last-chat]}
[{:keys [db]}]
{:chat/open-last-chat (get-in db [:profile/profile :key-uid])})

View File

@ -97,7 +97,7 @@
(rf/defn enable-all (rf/defn enable-all
{:events [:chat.ui/enable-all-link-previews]} {:events [:chat.ui/enable-all-link-previews]}
[{{:profile/keys [profile]} :db :as cofx} link-previews-whitelist enabled?] [cofx link-previews-whitelist enabled?]
(multiaccounts.update/multiaccount-update (multiaccounts.update/multiaccount-update
cofx cofx
:link-previews-enabled-sites :link-previews-enabled-sites

View File

@ -1,7 +1,9 @@
(ns status-im2.contexts.profile.config (ns status-im2.contexts.profile.config
(:require [status-im2.config :as config] (:require [status-im2.config :as config]
[native-module.core :as native-module] [native-module.core :as native-module]
[clojure.string :as string])) [clojure.string :as string]
[utils.transforms :as types]
[utils.re-frame :as rf]))
(defn login (defn login
[] []
@ -40,3 +42,15 @@
[path] [path]
(when path (when path
(string/replace-first path "file://" ""))) (string/replace-first path "file://" "")))
(rf/defn get-node-config-callback
{:events [:profile.config/get-node-config-callback]}
[{:keys [db]} node-config-json]
(let [node-config (types/json->clj node-config-json)]
{:db (assoc-in db
[:profile/profile :wakuv2-config]
(get node-config :WakuV2Config))}))
(rf/defn get-node-config
[_]
(native-module/get-node-config #(rf/dispatch [:profile.config/get-node-config-callback %])))

View File

@ -4,7 +4,15 @@
[status-im2.contexts.profile.config :as profile.config] [status-im2.contexts.profile.config :as profile.config]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[utils.security.core :as security] [utils.security.core :as security]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]
[status-im2.contexts.shell.jump-to.utils :as shell.utils]
[status-im.transport.core :as transport]
[status-im.communities.core :as communities]
[status-im.data-store.chats :as data-store.chats]
[status-im.multiaccounts.core :as multiaccounts]
[status-im2.contexts.chat.messages.link-preview.events :as link-preview]
[status-im2.common.log :as logging]
[status-im2.navigation.events :as navigation]))
(re-frame/reg-fx (re-frame/reg-fx
::create-profile-and-login ::create-profile-and-login
@ -21,3 +29,22 @@
:password (ethereum/sha3 (security/safe-unmask-data password)) :password (ethereum/sha3 (security/safe-unmask-data password))
:imagePath (profile.config/strip-file-prefix image-path) :imagePath (profile.config/strip-file-prefix image-path)
:customizationColor color})}) :customizationColor color})})
(rf/defn login-new-profile
[{:keys [db] :as cofx} recovered-account?]
(let [{:profile/keys [profile profiles-overview wallet-accounts]
:networks/keys [current-network networks]} db
network-id
(str (get-in networks [current-network :config :NetworkId]))]
(shell.utils/change-selected-stack-id :communities-stack true nil)
(rf/merge cofx
{:db (assoc db :chats/loading? false)
:wallet/get-tokens [network-id wallet-accounts recovered-account?]}
(transport/start-messenger)
(communities/fetch)
(data-store.chats/fetch-chats-preview
{:on-success #(re-frame/dispatch [:chats-list/load-success %])})
(multiaccounts/switch-preview-privacy-mode-flag)
(link-preview/request-link-preview-whitelist)
(logging/set-log-level (:log-level profile))
(navigation/init-root :enable-notifications))))

View File

@ -1,6 +1,6 @@
(ns status-im2.contexts.profile.events (ns status-im2.contexts.profile.events
(:require [utils.re-frame :as rf] (:require [utils.re-frame :as rf]
[clojure.string :as string] [status-im2.contexts.profile.rpc :as profile.rpc]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[native-module.core :as native-module] [native-module.core :as native-module]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
@ -26,18 +26,11 @@
{:db (assoc db :profile/profiles-overview profiles)} {:db (assoc db :profile/profiles-overview profiles)}
(profile-selected key-uid))) (profile-selected key-uid)))
(defn rpc->profiles-overview
[{:keys [customizationColor keycard-pairing] :as profile}]
(-> profile
(dissoc :customizationColor)
(assoc :customization-color (keyword customizationColor))
(assoc :keycard-pairing (when-not (string/blank? keycard-pairing) keycard-pairing))))
(defn reduce-profiles (defn reduce-profiles
[profiles] [profiles]
(reduce (reduce
(fn [acc {:keys [key-uid] :as profile}] (fn [acc {:keys [key-uid] :as profile}]
(assoc acc key-uid (rpc->profiles-overview profile))) (assoc acc key-uid (profile.rpc/rpc->profiles-overview profile)))
{} {}
profiles)) profiles))

View File

@ -1,13 +1,34 @@
(ns status-im2.contexts.profile.login.events (ns status-im2.contexts.profile.login.events
(:require [utils.re-frame :as rf] (:require
[status-im.ethereum.core :as ethereum] [utils.re-frame :as rf]
[utils.security.core :as security] [status-im.ethereum.core :as ethereum]
[re-frame.core :as re-frame] [utils.security.core :as security]
[native-module.core :as native-module] [re-frame.core :as re-frame]
[status-im2.navigation.events :as navigation] [native-module.core :as native-module]
[status-im2.common.keychain.events :as keychain] [status-im2.navigation.events :as navigation]
[status-im2.common.biometric.events :as biometric] [status-im2.common.keychain.events :as keychain]
[status-im2.contexts.profile.config :as profile.config])) [status-im2.common.biometric.events :as biometric]
[status-im2.contexts.profile.config :as profile.config]
[taoensso.timbre :as log]
[status-im.notifications.core :as notifications]
[status-im2.contexts.profile.create.events :as profile.create]
[status-im2.config :as config]
[status-im.data-store.settings :as data-store.settings]
[status-im2.contexts.communities.discover.events :as contract-communities]
[status-im.communities.core :as communities]
[status-im2.common.log :as logging]
[status-im2.contexts.shell.activity-center.events :as activity-center]
[status-im.data-store.chats :as data-store.chats]
[status-im2.contexts.profile.rpc :as profile.rpc]
[status-im.multiaccounts.core :as multiaccounts]
[status-im.transport.core :as transport]
[status-im2.contexts.contacts.events :as contacts]
[status-im.mobile-sync-settings.core :as mobile-network]
[status-im2.contexts.chat.messages.link-preview.events :as link-preview]
[status-im.data-store.visibility-status-updates :as visibility-status-updates-store]
[status-im.data-store.switcher-cards :as switcher-cards-store]
[status-im.browser.core :as browser]
[status-im.group-chats.core :as group-chats]))
(re-frame/reg-fx (re-frame/reg-fx
::login ::login
@ -29,6 +50,102 @@
(let [{:keys [key-uid password]} (get-in db [:syncing :profile])] (let [{:keys [key-uid password]} (get-in db [:syncing :profile])]
{::login [key-uid password]})) {::login [key-uid password]}))
(rf/defn redirect-to-root
[{:keys [db] :as cofx}]
(let [pairing-completed? (= (get-in db [:syncing :pairing-status]) :completed)]
(cond
pairing-completed?
{:db (dissoc db :syncing)
:dispatch [:init-root :syncing-results]}
(get db :onboarding-2/new-account?)
{:dispatch [:onboarding-2/finalize-setup]}
:else
(rf/merge
cofx
(multiaccounts/switch-theme nil :shell-stack)
(navigation/init-root :shell-stack)))))
;; login phase 1, we want to load and show chats faster so we split login into 2 phases
(rf/defn login-existing-profile
[{:keys [db] :as cofx} settings account]
(let [{:networks/keys [current-network networks]
:as settings}
(data-store.settings/rpc->settings settings)
profile (profile.rpc/rpc->profiles-overview account)]
(rf/merge cofx
{:db (assoc db
:chats/loading? true
:networks/current-network current-network
:networks/networks (merge networks config/default-networks-by-id)
:profile/profile (merge profile settings))}
(notifications/load-notification-preferences)
(data-store.chats/fetch-chats-preview
{:on-success
#(do (re-frame/dispatch [:chats-list/load-success %])
(rf/dispatch [:communities/get-user-requests-to-join])
(re-frame/dispatch [:profile.login/get-chats-callback]))})
(profile.config/get-node-config)
(communities/fetch)
(contract-communities/fetch-contract-communities)
(communities/fetch-collapsed-community-categories)
(communities/check-and-delete-pending-request-to-join)
(logging/set-log-level (:log-level settings))
(activity-center/notifications-fetch-pending-contact-requests)
(activity-center/update-seen-state)
(activity-center/notifications-fetch-unread-count)
(redirect-to-root))))
;; login phase 2, we want to load and show chats faster so we split login into 2 phases
(rf/defn get-chats-callback
{:events [:profile.login/get-chats-callback]}
[{:keys [db] :as cofx}]
(let [{:networks/keys [current-network networks]} db
notifications-enabled? (get-in db [:profile/profile :notifications-enabled?])
current-network-config (get networks current-network)
network-id (str (get-in networks
[current-network :config :NetworkId]))
remote-push-notifications-enabled?
(get-in db [:profile/profile :remote-push-notifications-enabled?])]
(rf/merge cofx
(cond-> {:wallet/initialize-transactions-management-enabled nil
:wallet/initialize-wallet
[network-id
current-network-config
(fn [accounts tokens custom-tokens favourites]
(re-frame/dispatch [:wallet/initialize-wallet
accounts tokens custom-tokens favourites]))]
:check-eip1559-activation {:network-id network-id}
:chat/open-last-chat (get-in db [:profile/profile :key-uid])}
(or notifications-enabled? remote-push-notifications-enabled?)
(assoc ::notifications/enable remote-push-notifications-enabled?))
(transport/start-messenger)
(contacts/initialize-contacts)
(browser/initialize-browser)
(mobile-network/on-network-status-change)
(group-chats/get-group-chat-invitations)
(multiaccounts/get-profile-picture)
(multiaccounts/switch-preview-privacy-mode-flag)
(link-preview/request-link-preview-whitelist)
(visibility-status-updates-store/fetch-visibility-status-updates-rpc)
(switcher-cards-store/fetch-switcher-cards-rpc))))
(rf/defn login-node-signal
[{{:keys [recovered-account?] :as db} :db :as cofx} {:keys [settings account error]}]
(log/debug "[signals] node.login" "error" error)
(if error
{:db (update db :profile/login #(-> % (dissoc :processing) (assoc :error error)))}
(let [{:keys [creating?]} (:profile/login db)]
(rf/merge cofx
{:db (dissoc db :profile/login)
:dispatch-n [[:logging/initialize-web3-client-version]
(when (and creating? (not recovered-account?))
[:wallet/set-initial-blocks-range])]}
(if (or creating? recovered-account?)
(profile.create/login-new-profile recovered-account?)
(login-existing-profile settings account))))))
(rf/defn login-with-biometric-if-available (rf/defn login-with-biometric-if-available
{:events [:profile.login/login-with-biometric-if-available]} {:events [:profile.login/login-with-biometric-if-available]}
[_ key-uid] [_ key-uid]

View File

@ -0,0 +1,9 @@
(ns status-im2.contexts.profile.rpc
(:require [clojure.string :as string]))
(defn rpc->profiles-overview
[{:keys [customizationColor keycard-pairing] :as profile}]
(-> profile
(dissoc :customizationColor)
(assoc :customization-color (keyword customizationColor))
(assoc :keycard-pairing (when-not (string/blank? keycard-pairing) keycard-pairing))))

View File

@ -3,7 +3,6 @@
[react-native.core :as rn] [react-native.core :as rn]
[react-native.gesture :as gesture] [react-native.gesture :as gesture]
[react-native.navigation :as navigation] [react-native.navigation :as navigation]
[status-im.multiaccounts.login.core :as login-core]
[status-im2.navigation.roots :as roots] [status-im2.navigation.roots :as roots]
[status-im2.navigation.state :as state] [status-im2.navigation.state :as state]
[status-im2.navigation.view :as views] [status-im2.navigation.view :as views]
@ -30,7 +29,7 @@
(when @state/root-id (when @state/root-id
(reset! theme/device-theme (rn/get-color-scheme)) (reset! theme/device-theme (rn/get-color-scheme))
(re-frame/dispatch [:init-root @state/root-id]) (re-frame/dispatch [:init-root @state/root-id])
(re-frame/dispatch [::login-core/check-last-chat]))) (re-frame/dispatch [:chat/check-last-chat])))
(rn/hide-splash-screen))) (rn/hide-splash-screen)))
(defn set-view-id (defn set-view-id

View File

@ -10,13 +10,6 @@
[utils.security.core :as security] [utils.security.core :as security]
[status-im2.constants :as constants])) [status-im2.constants :as constants]))
(re-frame/reg-sub
:profile/profile
:<- [:profile/profile-settings]
:<- [:profile/profiles-overview]
(fn [[{:keys [key-uid] :as profile} profiles-overview]]
(merge (get profiles-overview key-uid) profile)))
(re-frame/reg-sub (re-frame/reg-sub
:profile/customization-color :profile/customization-color
:<- [:profile/profile] :<- [:profile/profile]

View File

@ -66,8 +66,6 @@
(reg-root-key-sub :get-pairing-installations :pairing/installations) (reg-root-key-sub :get-pairing-installations :pairing/installations)
(reg-root-key-sub :tooltips :tooltips) (reg-root-key-sub :tooltips :tooltips)
(reg-root-key-sub :biometric/supported-type :biometric/supported-type) (reg-root-key-sub :biometric/supported-type :biometric/supported-type)
(reg-root-key-sub :connectivity/ui-status-properties :connectivity/ui-status-properties)
(reg-root-key-sub :logged-in-since :logged-in-since)
(reg-root-key-sub :app-state :app-state) (reg-root-key-sub :app-state :app-state)
(reg-root-key-sub :home-items-show-number :home-items-show-number) (reg-root-key-sub :home-items-show-number :home-items-show-number)
(reg-root-key-sub :waku/v2-peer-stats :peer-stats) (reg-root-key-sub :waku/v2-peer-stats :peer-stats)
@ -87,9 +85,7 @@
;;profiles ;;profiles
(reg-root-key-sub :profile/profiles-overview :profile/profiles-overview) (reg-root-key-sub :profile/profiles-overview :profile/profiles-overview)
(reg-root-key-sub :profile/login :profile/login) (reg-root-key-sub :profile/login :profile/login)
;; we have some fields only in overview, would be cool to merge them in status-go (reg-root-key-sub :profile/profile :profile/profile)
;; https://github.com/status-im/status-mobile/issues/16422
(reg-root-key-sub :profile/profile-settings :profile/profile)
(reg-root-key-sub :profile/wallet-accounts :profile/wallet-accounts) (reg-root-key-sub :profile/wallet-accounts :profile/wallet-accounts)
(reg-root-key-sub :multiaccount/reset-password-form-vals :multiaccount/reset-password-form-vals) (reg-root-key-sub :multiaccount/reset-password-form-vals :multiaccount/reset-password-form-vals)

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>", "_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.160.2", "version": "v0.161.2",
"commit-sha1": "b058ab41da726ba1b985f64d1d749089f7687279", "commit-sha1": "b7390f43558adeeeede7498a789da2ef50aa44e6",
"src-sha256": "12hfl9x88igrw9k0461casni3znh22431dpx158qqm45mymmgc7i" "src-sha256": "1rj0l3vphzypja9c7salmznvr90gm2crrr6fagx6il6pg2nnavb1"
} }