bugs #4724 and #5131 - fixed by adding wallet onboarding for dapp txs

Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
Goran Jovic 2018-07-22 11:05:10 +02:00 committed by Julien Eluard
parent 0f2af863e7
commit f38a95fd71
No known key found for this signature in database
GPG Key ID: 6FD7DB5437FCBEF6
6 changed files with 55 additions and 35 deletions

View File

@ -155,19 +155,22 @@
(fn [cofx [_ dev-mode]] (fn [cofx [_ dev-mode]]
(accounts.utils/account-update {:dev-mode? dev-mode} cofx))) (accounts.utils/account-update {:dev-mode? dev-mode} cofx)))
(defn wallet-set-up-passed [db cofx] (defn chat-send? [transaction]
(and (seq transaction)
(not (:in-progress? transaction))
(:from-chat? transaction)))
(defn wallet-set-up-passed [db modal? cofx]
(let [transaction (get-in db [:wallet :send-transaction])] (let [transaction (get-in db [:wallet :send-transaction])]
(merge (cond modal? {:dispatch [:navigate-to-modal :wallet-send-transaction-modal]}
{:db (navigation/navigate-back db)} (chat-send? transaction) {:db (navigation/navigate-back db)
(when (and (seq transaction) :dispatch [:navigate-to :wallet-send-transaction-chat]}
(not (:in-progress? transaction)) :else {:db (navigation/navigate-back db)})))
(:from-chat? transaction))
{:dispatch [:navigate-to :wallet-send-transaction-chat]}))))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet-set-up-passed :wallet-set-up-passed
(fn [{:keys [db] :as cofx}] (fn [{:keys [db] :as cofx} [_ modal?]]
(handlers-macro/merge-fx (handlers-macro/merge-fx
cofx cofx
(wallet-set-up-passed db) (wallet-set-up-passed db modal?)
(accounts.utils/account-update {:wallet-set-up-passed? true})))) (accounts.utils/account-update {:wallet-set-up-passed? true}))))

View File

@ -111,6 +111,7 @@
:wallet-transaction-sent-modal transaction-sent-modal :wallet-transaction-sent-modal transaction-sent-modal
:wallet-sign-message-modal sign-message-modal :wallet-sign-message-modal sign-message-modal
:wallet-transaction-fee wallet.send/transaction-fee :wallet-transaction-fee wallet.send/transaction-fee
:wallet-onboarding-setup-modal wallet.onboarding.setup/modal
[react/view [react/text (str "Unknown modal view: " modal-view)]])) [react/view [react/text (str "Unknown modal view: " modal-view)]]))
(defview main-modal [] (defview main-modal []

View File

@ -40,4 +40,8 @@
:padding-vertical 8}) :padding-vertical 8})
(def got-it-button-text (def got-it-button-text
{:padding-horizontal 0}) {:padding-horizontal 0})
(def modal
{:flex 1
:background-color colors/blue})

View File

@ -6,12 +6,13 @@
[status-im.react-native.resources :as resources] [status-im.react-native.resources :as resources]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[status-im.ui.components.styles :as components.styles] [status-im.ui.components.styles :as components.styles]
[status-im.ui.screens.wallet.components :as comp] [status-im.ui.screens.wallet.components :as wallet.components]
[status-im.ui.screens.wallet.onboarding.setup.styles :as styles] [status-im.ui.screens.wallet.onboarding.setup.styles :as styles]
[status-im.ui.components.bottom-buttons.view :as bottom-buttons] [status-im.ui.components.bottom-buttons.view :as bottom-buttons]
[status-im.ui.components.button.view :as button] [status-im.ui.components.button.view :as button]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im.ui.components.toolbar.actions :as actions])) [status-im.ui.components.toolbar.actions :as actions]
[status-im.ui.components.status-bar.view :as status-bar]))
(defn signing-word [word] (defn signing-word [word]
[react/view styles/signing-word [react/view styles/signing-word
@ -20,17 +21,19 @@
:number-of-lines 1} :number-of-lines 1}
word]]) word]])
(defn display-confirmation [] (defn display-confirmation [modal?]
(utils/show-question (utils/show-question
(i18n/label :t/wallet-set-up-confirm-title) (i18n/label :t/wallet-set-up-confirm-title)
(i18n/label :t/wallet-set-up-confirm-description) (i18n/label :t/wallet-set-up-confirm-description)
#(re-frame/dispatch [:wallet-set-up-passed]))) #(re-frame/dispatch [:wallet-set-up-passed modal?])))
(views/defview screen [] (views/defview onboarding-panel [modal?]
(views/letsubs [{:keys [signing-phrase]} [:get-current-account]] (views/letsubs [{:keys [signing-phrase]} [:get-current-account]]
(let [signing-words (string/split signing-phrase #" ")] (let [signing-words (string/split signing-phrase #" ")
[comp/simple-screen {:avoid-keyboard? true} container (if modal? react/view wallet.components/simple-screen)
[comp/toolbar container-opts (if modal? components.styles/flex {:avoid-keyboard? true})]
[container container-opts
[wallet.components/toolbar
{} {}
(actions/back-white #(re-frame/dispatch [:wallet-setup-navigate-back])) (actions/back-white #(re-frame/dispatch [:wallet-setup-navigate-back]))
(i18n/label :t/wallet-set-up-title)] (i18n/label :t/wallet-set-up-title)]
@ -46,8 +49,16 @@
(i18n/label :t/wallet-set-up-signing-phrase)] (i18n/label :t/wallet-set-up-signing-phrase)]
[bottom-buttons/bottom-buttons styles/bottom-buttons [bottom-buttons/bottom-buttons styles/bottom-buttons
nil nil
[button/button {:on-press display-confirmation [button/button {:on-press (partial display-confirmation modal?)
:text-style styles/got-it-button-text :text-style styles/got-it-button-text
:accessibility-label :done-button} :accessibility-label :done-button}
(i18n/label :t/got-it) (i18n/label :t/got-it)
nil]]]]))) nil]]]])))
(views/defview screen []
[onboarding-panel false])
(views/defview modal []
[react/view styles/modal
[status-bar/status-bar {:type :modal-wallet}]
[onboarding-panel true]])

View File

@ -194,20 +194,23 @@
;;SEND TRANSACTION ;;SEND TRANSACTION
(= method constants/web3-send-transaction) (= method constants/web3-send-transaction)
(let [{:keys [gas gasPrice]} args (let [{:keys [gas gasPrice]} args
transaction (prepare-transaction queued-transaction now) transaction (prepare-transaction queued-transaction now)
sending-from-bot-or-dapp? (not (get-in db [:wallet :send-transaction :waiting-signal?])) sending-from-dapp? (not (get-in db [:wallet :send-transaction :waiting-signal?]))
new-db (assoc-in db' [:wallet :transactions-unsigned id] transaction) new-db (assoc-in db' [:wallet :transactions-unsigned id] transaction)
sending-db {:id id sender-account (:account/account db)
:method method sending-db {:id id
:from-chat? (or :method method
sending-from-bot-or-dapp? :from-chat? (or sending-from-dapp? ;;TODO(goranjovic): figure out why we need to
;; have from-chat? flag for dapp txs and get rid of this
(get-in db [:wallet :send-transaction :from-chat?]))}] (get-in db [:wallet :send-transaction :from-chat?]))}]
(if sending-from-bot-or-dapp? (if sending-from-dapp?
;;SENDING FROM BOT (CHAT) OR DAPP ;;SENDING FROM DAPP
{:db (assoc-in new-db [:wallet :send-transaction] sending-db) ; we need to completely reset sending state here {:db (assoc-in new-db [:wallet :send-transaction] sending-db) ; we need to completely reset sending state here
:dispatch-n [[:update-wallet] :dispatch-n [[:update-wallet]
[:navigate-to-modal :wallet-send-transaction-modal] [:navigate-to-modal (if (:wallet-set-up-passed? sender-account)
:wallet-send-transaction-modal
:wallet-onboarding-setup-modal)]
(when-not (seq gas) (when-not (seq gas)
[:wallet/update-estimated-gas transaction]) [:wallet/update-estimated-gas transaction])
(when-not (seq gasPrice) (when-not (seq gasPrice)

View File

@ -260,22 +260,20 @@
(defview send-transaction [] (defview send-transaction []
(letsubs [transaction [:wallet.send/transaction] (letsubs [transaction [:wallet.send/transaction]
symbol [:wallet.send/symbol]
advanced? [:wallet.send/advanced?] advanced? [:wallet.send/advanced?]
network [:get-current-account-network] network [:get-current-account-network]
scroll (atom nil)] scroll (atom nil)]
[send-transaction-panel {:modal? false :transaction transaction :scroll scroll :advanced? advanced? [send-transaction-panel {:modal? false :transaction transaction :scroll scroll :advanced? advanced?
:symbol symbol :network network}])) :network network}]))
(defview send-transaction-modal [] (defview send-transaction-modal []
(letsubs [transaction [:wallet.send/unsigned-transaction] (letsubs [transaction [:wallet.send/unsigned-transaction]
symbol [:wallet.send/symbol]
advanced? [:wallet.send/advanced?] advanced? [:wallet.send/advanced?]
network [:get-current-account-network] network [:get-current-account-network]
scroll (atom nil)] scroll (atom nil)]
(if transaction (if transaction
[send-transaction-panel {:modal? true :transaction transaction :scroll scroll :advanced? advanced? [send-transaction-panel {:modal? true :transaction transaction :scroll scroll :advanced? advanced?
symbol symbol :network network}] :network network}]
[react/view wallet.styles/wallet-modal-container [react/view wallet.styles/wallet-modal-container
[react/view components.styles/flex [react/view components.styles/flex
[status-bar/status-bar {:type :modal-wallet}] [status-bar/status-bar {:type :modal-wallet}]