Routing refactoring, preparations related to new navigation

- screens definition is separated from configuration
  (deduplicates screens which are used among several stacks)
- all four stacks moved to separate namespaces
- configuration is just a data
This commit is contained in:
Roman Volosovskyi 2019-02-12 15:07:26 +02:00
parent 2c77822a6c
commit 8c9e71c9d4
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
11 changed files with 438 additions and 13 deletions

1
.env
View File

@ -18,3 +18,4 @@ POW_TIME=1
RN_BRIDGE_THRESHOLD_WARNINGS=0
RPC_NETWORKS_ONLY=0
STICKERS_ENABLED=1
NEW_ROUTING=0

View File

@ -18,3 +18,4 @@ POW_TIME=1
RN_BRIDGE_THRESHOLD_WARNINGS=0
RPC_NETWORKS_ONLY=0
STICKERS_ENABLED=1
NEW_ROUTING=0

View File

@ -0,0 +1,47 @@
(ns status-im.ui.screens.routing.chat-stack
(:require [status-im.utils.config :as config]))
(def chat-stack
{:name :chat-stack
:screens [{:name :chat-main-stack
:screens (cond->
[:home
:chat
:profile
:new
:new-chat
:qr-scanner
:take-picture
:new-group
:add-participants-toggle-list
:contact-toggle-list
:group-chat-profile
:new-public-chat
:open-dapp
:dapp-description
:browser
:stickers
:stickers-pack
:login]
config/hardwallet-enabled?
(concat [:hardwallet-connect :enter-pin]))
:config {:initialRouteName :home}}
:wallet-modal
:chat-modal
:show-extension-modal
:stickers-pack-modal
{:name :wallet-send-modal-stack
:screens [:wallet-send-transaction-modal
:wallet-transaction-sent-modal
:wallet-transaction-fee]
:config {:initialRouteName :wallet-send-transaction-modal}}
{:name :wallet-send-modal-stack-with-onboarding
:screens [:wallet-onboarding-setup-modal
:wallet-send-transaction-modal
:wallet-transaction-sent-modal
:wallet-transaction-fee]
:config {:initialRouteName :wallet-onboarding-setup-modal}}
:wallet-sign-message-modal]
:config {:mode :modal
:initialRouteName :chat-main-stack}})

View File

@ -0,0 +1,112 @@
(ns status-im.ui.screens.routing.core
(:require
[status-im.ui.components.react :as react]
[status-im.ui.components.styles :as common-styles]
[status-im.utils.navigation :as navigation]
[cljs-react-navigation.reagent :as nav-reagent]
[re-frame.core :as re-frame]
[taoensso.timbre :as log]
[status-im.utils.platform :as platform]
[status-im.utils.core :as utils]
[status-im.ui.screens.routing.screens :as screens]
[status-im.ui.screens.routing.intro-login-stack :as intro-login-stack]
[status-im.ui.screens.routing.chat-stack :as chat-stack]
[status-im.ui.screens.routing.wallet-stack :as wallet-stack]
[status-im.ui.screens.routing.profile-stack :as profile-stack]))
(defn wrap [view-id component]
"Wraps screen with main view and adds navigation-events component"
(fn []
(let [main-view (react/create-main-screen-view view-id)]
[main-view common-styles/flex
[component]
[:> navigation/navigation-events
{:on-will-focus
(fn []
(log/debug :on-will-focus view-id)
(re-frame/dispatch [:screens/on-will-focus view-id]))}]])))
(defn wrap-modal [modal-view component]
"Wraps modal screen with necessary styling and adds :on-request-close handler
on Android"
(fn []
(if platform/android?
[react/view common-styles/modal
[react/modal
{:transparent true
:animation-type :slide
:on-request-close (fn []
(cond
(#{:wallet-send-transaction-modal
:wallet-sign-message-modal}
modal-view)
(re-frame/dispatch
[:wallet/discard-transaction-navigate-back])
:else
(re-frame/dispatch [:navigate-back])))}
[react/main-screen-modal-view modal-view
[component]]]]
[react/main-screen-modal-view modal-view
[component]])))
(defn prepare-config [config]
(-> config
(utils/update-if-present :initialRouteName name)
(utils/update-if-present :mode name)))
(defn stack-navigator [routes config]
(nav-reagent/stack-navigator
routes
(merge {:headerMode "none"} (prepare-config config))))
(defn switch-navigator [routes config]
(nav-reagent/switch-navigator
routes
(prepare-config config)))
(declare stack-screens)
(defn build-screen [screen]
"Builds screen from specified configuration. Currently screen can be
- keyword, which points to some specific route
- vector of [:modal :screen-key] type when screen should be wrapped as modal
- map with `name`, `screens`, `config` keys, where `screens` is a vector
of children and `config` is `stack-navigator` configuration"
(let [[screen-name screen-config]
(cond (keyword? screen)
[screen (screens/get-screen screen)]
(map? screen)
[(:name screen) screen]
:else screen)]
(let [res (cond
(map? screen-config)
(let [{:keys [screens config]} screen-config]
(stack-navigator
(stack-screens screens)
config))
(vector? screen-config)
(let [[_ screen] screen-config]
(nav-reagent/stack-screen
(wrap-modal screen-name screen)))
:else
(nav-reagent/stack-screen (wrap screen-name screen-config)))]
[screen-name {:screen res}])))
(defn stack-screens [screens-map]
(->> screens-map
(map build-screen)
(into {})))
(defn get-main-component [view-id]
(log/debug :component view-id)
(switch-navigator
(->> [(intro-login-stack/intro-login-stack view-id)
chat-stack/chat-stack
wallet-stack/wallet-stack
profile-stack/profile-stack]
(map build-screen)
(into {}))
{:initialRouteName :intro-login-stack}))

View File

@ -0,0 +1,24 @@
(ns status-im.ui.screens.routing.intro-login-stack
(:require [status-im.utils.config :as config]))
(defn intro-login-stack [view-id]
{:name :intro-login-stack
:screens (cond-> [:login
:progress
:create-account
:recover
:accounts]
(= :intro view-id)
(conj :intro)
config/hardwallet-enabled?
(concat [:hardwallet-authentication-method
:hardwallet-connect
:enter-pin
:hardwallet-setup
:hardwallet-success]))
:config (when
;; add view-id here if you'd like that view to be
;; first view when app is started
(#{:intro :login :progress :accounts} view-id)
{:initialRouteName view-id})})

View File

@ -0,0 +1,47 @@
(ns status-im.ui.screens.routing.profile-stack
(:require [status-im.utils.config :as config]))
(def profile-stack
{:name :profile-stack
:screens [{:name :main-profile-stack
:screens (cond-> [:my-profile
:contacts-list
:blocked-users-list
:profile-photo-capture
:about-app
:bootnodes-settings
:installations
:edit-bootnode
:offline-messaging-settings
:edit-mailserver
:help-center
:dapps-permissions
:manage-dapps-permissions
:extensions-settings
:edit-extension
:show-extension
:network-settings
:network-details
:edit-network
:log-level-settings
:fleet-settings
:currency-settings
:backup-seed
:login
:create-account
:recover
:accounts
:qr-scanner]
config/hardwallet-enabled?
(concat [:hardwallet-authentication-method
:hardwallet-connect
:hardwallet-setup
:hardwallet-success
:keycard-settings
:reset-card
:enter-pin]))
:config {:initialRouteName :my-profile}}
:profile-qr-viewer]
:config {:mode :modal
:initialRouteName :main-profile-stack}})

View File

@ -0,0 +1,145 @@
(ns status-im.ui.screens.routing.screens
(:require
[status-im.ui.screens.main-tabs.views :as main-tabs]
[status-im.ui.screens.accounts.login.views :as login]
[status-im.ui.screens.accounts.recover.views :as recover]
[status-im.ui.screens.accounts.views :as accounts]
[status-im.ui.screens.progress.views :as progress]
[status-im.ui.screens.chat.views :as chat]
[status-im.ui.screens.add-new.views :as add-new]
[status-im.ui.screens.add-new.new-chat.views :as new-chat]
[status-im.ui.screens.add-new.new-public-chat.view :as new-public-chat]
[status-im.ui.screens.qr-scanner.views :as qr-scanner]
[status-im.ui.screens.group.views :as group]
[status-im.ui.screens.profile.user.views :as profile.user]
[status-im.ui.screens.profile.contact.views :as profile.contact]
[status-im.ui.screens.profile.group-chat.views :as profile.group-chat]
[status-im.ui.screens.profile.photo-capture.views :as photo-capture]
[status-im.extensions.views :as extensions]
[status-im.ui.screens.wallet.main.views :as wallet.main]
[status-im.ui.screens.wallet.collectibles.views :as collectibles]
[status-im.ui.screens.wallet.send.views :as send]
[status-im.ui.screens.wallet.request.views :as request]
[status-im.ui.screens.wallet.components.views :as wallet.components]
[status-im.ui.screens.wallet.onboarding.views :as wallet.onboarding]
[status-im.ui.screens.wallet.transaction-fee.views :as wallet.transaction-fee]
[status-im.ui.screens.wallet.settings.views :as wallet-settings]
[status-im.ui.screens.wallet.transactions.views :as wallet-transactions]
[status-im.ui.screens.wallet.transaction-sent.views :as transaction-sent]
[status-im.ui.screens.contacts-list.views :as contacts-list]
[status-im.ui.screens.network-settings.views :as network-settings]
[status-im.ui.screens.network-settings.network-details.views :as network-details]
[status-im.ui.screens.network-settings.edit-network.views :as edit-network]
[status-im.ui.screens.extensions.views :as screens.extensions]
[status-im.ui.screens.log-level-settings.views :as log-level-settings]
[status-im.ui.screens.fleet-settings.views :as fleet-settings]
[status-im.ui.screens.offline-messaging-settings.views :as offline-messaging-settings]
[status-im.ui.screens.offline-messaging-settings.edit-mailserver.views :as edit-mailserver]
[status-im.ui.screens.extensions.add.views :as extensions.add]
[status-im.ui.screens.bootnodes-settings.views :as bootnodes-settings]
[status-im.ui.screens.pairing.views :as pairing]
[status-im.ui.screens.bootnodes-settings.edit-bootnode.views :as edit-bootnode]
[status-im.ui.screens.currency-settings.views :as currency-settings]
[status-im.ui.screens.hardwallet.settings.views :as hardwallet.settings]
[status-im.ui.screens.help-center.views :as help-center]
[status-im.ui.screens.browser.views :as browser]
[status-im.ui.screens.add-new.open-dapp.views :as open-dapp]
[status-im.ui.screens.intro.views :as intro]
[status-im.ui.screens.accounts.create.views :as accounts.create]
[status-im.ui.screens.hardwallet.authentication-method.views :as hardwallet.authentication]
[status-im.ui.screens.hardwallet.connect.views :as hardwallet.connect]
[status-im.ui.screens.hardwallet.pin.views :as hardwallet.pin]
[status-im.ui.screens.hardwallet.setup.views :as hardwallet.setup]
[status-im.ui.screens.hardwallet.success.views :as hardwallet.success]
[status-im.ui.screens.profile.seed.views :as profile.seed]
[status-im.ui.screens.about-app.views :as about-app]
[status-im.ui.screens.stickers.views :as stickers]
[status-im.ui.screens.dapps-permissions.views :as dapps-permissions]))
(def all-screens
{:login login/login
:progress progress/progress
:create-account accounts.create/create-account
:recover recover/recover
:accounts accounts/accounts
:intro intro/intro
:hardwallet-authentication-method hardwallet.authentication/hardwallet-authentication-method
:hardwallet-connect hardwallet.connect/hardwallet-connect
:enter-pin hardwallet.pin/enter-pin
:hardwallet-setup hardwallet.setup/hardwallet-setup
:hardwallet-success hardwallet.success/hardwallet-success
:home (main-tabs/get-main-tab :home)
:chat chat/chat
:profile profile.contact/profile
:new add-new/add-new
:new-chat new-chat/new-chat
:qr-scanner qr-scanner/qr-scanner
:profile-qr-viewer [:modal profile.user/qr-viewer]
:take-picture extensions/take-picture
:new-group group/new-group
:add-participants-toggle-list group/add-participants-toggle-list
:contact-toggle-list group/contact-toggle-list
:group-chat-profile profile.group-chat/group-chat-profile
:new-public-chat new-public-chat/new-public-chat
:open-dapp open-dapp/open-dapp
:dapp-description open-dapp/dapp-description
:browser browser/browser
:stickers stickers/packs
:stickers-pack stickers/pack
:stickers-pack-modal [:modal stickers/pack-modal]
:wallet-modal [:modal wallet.main/wallet-modal]
:chat-modal [:modal chat/chat-modal]
:show-extension-modal [:modal extensions.add/show-extension-modal]
:wallet-send-transaction-modal [:modal send/send-transaction-modal]
:wallet-transaction-sent-modal [:modal transaction-sent/transaction-sent-modal]
:wallet-transaction-fee [:modal wallet.transaction-fee/transaction-fee]
:wallet-onboarding-setup-modal [:modal wallet.onboarding/modal]
:wallet-sign-message-modal [:modal send/sign-message-modal]
:wallet (main-tabs/get-main-tab :wallet)
:collectibles-list collectibles/collectibles-list
:wallet-onboarding-setup wallet.onboarding/screen
:wallet-send-transaction-chat send/send-transaction
:contact-code wallet.components/contact-code
:wallet-send-transaction send/send-transaction
:recent-recipients wallet.components/recent-recipients
:wallet-transaction-sent transaction-sent/transaction-sent
:recipient-qr-code wallet.components/recipient-qr-code
:wallet-send-assets wallet.components/send-assets
:wallet-request-transaction request/request-transaction
:wallet-send-transaction-request request/send-transaction-request
:wallet-request-assets wallet.components/request-assets
:unsigned-transactions wallet-transactions/transactions
:transactions-history wallet-transactions/transactions
:wallet-transaction-details wallet-transactions/transaction-details
:wallet-settings-hook wallet-settings/settings-hook
:selection-modal-screen [:modal screens.extensions/selection-modal-screen]
:wallet-settings-assets [:modal wallet-settings/manage-assets]
:wallet-transactions-filter [:modal wallet-transactions/filter-history]
:my-profile (main-tabs/get-main-tab :my-profile)
:contacts-list contacts-list/contacts-list
:blocked-users-list contacts-list/blocked-users-list
:profile-photo-capture photo-capture/profile-photo-capture
:about-app about-app/about-app
:bootnodes-settings bootnodes-settings/bootnodes-settings
:installations pairing/installations
:edit-bootnode edit-bootnode/edit-bootnode
:offline-messaging-settings offline-messaging-settings/offline-messaging-settings
:edit-mailserver edit-mailserver/edit-mailserver
:help-center help-center/help-center
:dapps-permissions dapps-permissions/dapps-permissions
:manage-dapps-permissions dapps-permissions/manage
:extensions-settings screens.extensions/extensions-settings
:edit-extension extensions.add/edit-extension
:show-extension extensions.add/show-extension
:network-settings network-settings/network-settings
:network-details network-details/network-details
:edit-network edit-network/edit-network
:log-level-settings log-level-settings/log-level-settings
:fleet-settings fleet-settings/fleet-settings
:currency-settings currency-settings/currency-settings
:backup-seed profile.seed/backup-seed
:reset-card hardwallet.settings/reset-card
:keycard-settings hardwallet.settings/keycard-settings})
(defn get-screen [screen]
(get all-screens screen #(throw (str "Screen " screen " is not defined."))))

View File

@ -0,0 +1,44 @@
(ns status-im.ui.screens.routing.wallet-stack)
(def wallet-stack
{:name :wallet-stack
:screens [{:name :main-wallet-stack
:screens [:wallet
:collectibles-list
:wallet-onboarding-setup
:wallet-send-transaction-chat
:contact-code
{:name :send-transaction-stack
:screens [:wallet-send-transaction
:recent-recipients
:wallet-transaction-sent
:recipient-qr-code
:wallet-send-assets]}
{:name :request-transaction-stack
:screens [:wallet-request-transaction
:wallet-send-transaction-request
:wallet-request-assets
:recent-recipients]}
:unsigned-transactions
:transactions-history
:wallet-transaction-details
:login
:wallet-settings-hook]
:config {:initialRouteName :wallet}}
:selection-modal-screen
{:name :wallet-send-modal-stack
:screens [:wallet-send-transaction-modal
:wallet-transaction-sent-modal
:wallet-transaction-fee]
:config {:initialRouteName :wallet-send-transaction-modal}}
{:name :wallet-send-modal-stack-with-onboarding
:screens [:wallet-onboarding-setup-modal
:wallet-send-transaction-modal
:wallet-transaction-sent
:wallet-transaction-fee]
:config {:initialRouteName :wallet-send-modal-stack-with-onboarding}}
:wallet-settings-assets
:wallet-transaction-fee
:wallet-transactions-filter]
:config {:mode :modal
:initialRouteName :main-wallet-stack}})

View File

@ -79,7 +79,8 @@
[taoensso.timbre :as log]
[status-im.utils.platform :as platform]
[status-im.utils.config :as config]
[status-im.ui.screens.mobile-network-settings.view :as mobile-network-settings]))
[status-im.ui.screens.mobile-network-settings.view :as mobile-network-settings]
[status-im.ui.screens.routing.core :as routing]))
(defn wrap [view-id component]
(fn []
@ -375,14 +376,10 @@
"chat-stack"
"intro-login-stack")}))
(defn get-main-component [view-id]
(case view-id
:new-group new-group
:add-participants-toggle-list add-participants-toggle-list
:contact-toggle-list contact-toggle-list
:group-chat-profile profile.group-chat/group-chat-profile
:contact-code contact-code
[react/view [react/text (str "Unknown view: " view-id)]]))
(def get-main-component
(if config/new-routing-enabled?
routing/get-main-component
get-main-component2))
(defonce rand-label (rand/id))
@ -416,7 +413,7 @@
(or
js/goog.DEBUG
(not @main-component)))
(reset! main-component (get-main-component2
(reset! main-component (get-main-component
(if js/goog.DEBUG
@initial-view-id
@view-id)))))
@ -427,7 +424,7 @@
(when-not @initial-view-id
(reset! initial-view-id @view-id))
(when (and @initial-view-id (not @main-component))
(reset! main-component (get-main-component2
(reset! main-component (get-main-component
(if js/goog.DEBUG
@initial-view-id
@view-id))))

View File

@ -18,7 +18,8 @@
[status-im.utils.money :as money]
[status-im.utils.security :as security]
[status-im.utils.types :as types]
[status-im.utils.utils :as utils]))
[status-im.utils.utils :as utils]
[status-im.utils.config :as config]))
;;;; FX
@ -165,7 +166,12 @@
(fx/merge cofx
#(when send-command?
(commands-sending/send % chat-id send-command? params))
(navigation/navigate-to-clean :wallet-transaction-sent {})))))
(navigation/navigate-to-clean
(if (or (= (:view-id db) :wallet-send-transaction)
(not config/new-routing-enabled?))
:wallet-transaction-sent
:wallet-transaction-sent-modal)
{})))))
(defn set-and-validate-amount-db [db amount symbol decimals]
(let [{:keys [value error]} (wallet.db/parse-amount amount decimals)]

View File

@ -32,6 +32,7 @@
(def dev-build? (enabled? (get-config :DEV_BUILD 0)))
(def erc20-contract-warnings-enabled? (enabled? (get-config :ERC20_CONTRACT_WARNINGS)))
(def partitioned-topic-enabled? (enabled? (get-config :PARTITIONED_TOPIC "0")))
(def new-routing-enabled? (enabled? (get-config :NEW_ROUTING "0")))
;; CONFIG VALUES
(def log-level