From 83afbd515a544798656d91bdc43a5a6374457a2f Mon Sep 17 00:00:00 2001 From: Andrey Shovkoplyas Date: Wed, 30 May 2018 18:41:00 +0300 Subject: [PATCH] show onboarding for transaction from chat [#4456] --- src/status_im/chat/events/shortcuts.cljs | 7 ++- src/status_im/ui/screens/accounts/events.cljs | 39 ++++++++----- src/status_im/ui/screens/navigation.cljs | 31 +++++----- src/status_im/ui/screens/wallet/events.cljs | 56 +++++++++++-------- .../wallet/onboarding/setup/views.cljs | 11 ++-- test/appium/support/test_rerun.py | 1 + test/appium/tests/test_chat_management.py | 4 ++ test/appium/tests/test_transaction.py | 10 +++- test/appium/views/base_view.py | 4 ++ test/appium/views/chat_view.py | 10 +++- 10 files changed, 110 insertions(+), 63 deletions(-) diff --git a/src/status_im/chat/events/shortcuts.cljs b/src/status_im/chat/events/shortcuts.cljs index dfae3e2501..60b493c265 100644 --- a/src/status_im/chat/events/shortcuts.cljs +++ b/src/status_im/chat/events/shortcuts.cljs @@ -12,11 +12,14 @@ :gas (ethereum/estimate-gas :ETH) :from-chat? true))) -(defn send-shortcut-fx [db contact params] +(defn send-shortcut-fx [{:account/keys [account] :as db} contact params] (merge {:db (-> db (send.events/set-and-validate-amount-db (:amount params) :ETH 18) (choose-recipient.events/fill-request-details (transaction-details contact)) - (navigation/navigate-to :wallet-send-transaction-chat))} + (navigation/navigate-to + (if (:wallet-set-up-passed? account) + :wallet-send-transaction-chat + :wallet-onboarding-setup)))} (send.events/update-gas-price db false))) (def shortcuts diff --git a/src/status_im/ui/screens/accounts/events.cljs b/src/status_im/ui/screens/accounts/events.cljs index c62cf76f65..af1d63811e 100644 --- a/src/status_im/ui/screens/accounts/events.cljs +++ b/src/status_im/ui/screens/accounts/events.cljs @@ -18,7 +18,8 @@ status-im.ui.screens.accounts.create.navigation [status-im.chat.models :as chat.models] [status-im.ui.screens.accounts.utils :as accounts.utils] - [status-im.data-store.accounts :as accounts-store])) + [status-im.data-store.accounts :as accounts-store] + [status-im.ui.screens.navigation :as navigation])) ;;;; COFX @@ -46,16 +47,16 @@ (handlers/register-handler-fx :create-account (fn [{{:accounts/keys [create] :as db} :db} _] - {:db (update db :accounts/create assoc :step :account-creating :error nil) + {:db (update db :accounts/create assoc :step :account-creating :error nil) ::create-account (:password create)})) (defn add-account "Takes db and new account, creates map of effects describing adding account to database and realm" [{:keys [network] :networks/keys [networks] :as db} {:keys [address] :as account}] (let [enriched-account (assoc account - :network network + :network network :networks networks - :address address)] + :address address)] {:db (assoc-in db [:accounts/accounts address] enriched-account) :data-store/base-tx [(accounts-store/save-account-tx enriched-account)]})) @@ -92,8 +93,8 @@ (map (fn [{:keys [address] :as account}] [address account])) (into {})) - ;;workaround for realm bug, migrating account v4 - events (mapv #(when (empty? (:networks %)) [:account-update-networks (:address %)]) (vals accounts))] + ;;workaround for realm bug, migrating account v4 + events (mapv #(when (empty? (:networks %)) [:account-update-networks (:address %)]) (vals accounts))] (merge {:db (assoc db :accounts/accounts accounts)} (when-not (empty? events) @@ -103,7 +104,7 @@ :account-update-networks (fn [{{:accounts/keys [accounts] :networks/keys [networks] :as db} :db} [_ id]] (let [current-account (get accounts id) - new-account (assoc current-account :networks networks)] + new-account (assoc current-account :networks networks)] {:db (assoc-in db [:accounts/accounts id] new-account) :data-store/base-tx [(accounts-store/save-account-tx new-account)]}))) @@ -112,18 +113,18 @@ ([settings success-event {{:keys [account/account] :as db} :db :as cofx}] (let [new-account (assoc account :settings settings)] {:db (assoc db :account/account new-account) - :data-store/base-tx [{:transaction (accounts-store/save-account-tx new-account) + :data-store/base-tx [{:transaction (accounts-store/save-account-tx new-account) :success-event success-event}]}))) (handlers/register-handler-fx :send-account-update-if-needed (fn [{:keys [db now] :as cofx} _] (let [{:keys [last-updated]} (:account/account db) - needs-update? (> (- now last-updated) time/week)] + needs-update? (> (- now last-updated) time/week)] (log/info "Need to send account-update: " needs-update?) (when needs-update? - ;; TODO(janherich): this is very strange and misleading, need to figure out why it'd necessary to update - ;; account with network update when last update was more then week ago + ;; TODO(janherich): this is very strange and misleading, need to figure out why it'd necessary to update + ;; account with network update when last update was more then week ago (accounts.utils/account-update nil cofx))))) (handlers/register-handler-fx @@ -137,7 +138,7 @@ (handlers/register-handler-fx :account-finalized (fn [{db :db} [_ show-welcome?]] - {:db (assoc db :accounts/create {:show-welcome? show-welcome?}) + {:db (assoc db :accounts/create {:show-welcome? show-welcome?}) :dispatch-n [[:navigate-to-clean :home] [:request-notifications]]})) @@ -161,7 +162,17 @@ (fn [cofx [_ dev-mode]] (accounts.utils/account-update {:dev-mode? dev-mode} cofx))) +(defn wallet-set-up-passed [db cofx] + (let [transaction (seq (get-in db [:wallet :send-transaction]))] + (merge + {:db (navigation/navigate-back db)} + (when transaction + {:dispatch [:navigate-to :wallet-send-transaction-chat]})))) + (handlers/register-handler-fx :wallet-set-up-passed - (fn [cofx] - (accounts.utils/account-update {:wallet-set-up-passed? true} cofx))) \ No newline at end of file + (fn [{:keys [db] :as cofx}] + (handlers-macro/merge-fx + cofx + (wallet-set-up-passed db) + (accounts.utils/account-update {:wallet-set-up-passed? true})))) \ No newline at end of file diff --git a/src/status_im/ui/screens/navigation.cljs b/src/status_im/ui/screens/navigation.cljs index 030f6781c5..96ced70dd6 100644 --- a/src/status_im/ui/screens/navigation.cljs +++ b/src/status_im/ui/screens/navigation.cljs @@ -90,23 +90,26 @@ (fn [cofx [_ view-id]] (replace-view view-id cofx))) +(defn navigate-back [{:keys [navigation-stack view-id modal] :as db}] + (cond + modal (assoc db :modal nil + :was-modal? true) + (>= 1 (count navigation-stack)) db + + :else + (let [[previous-view-id :as navigation-stack'] (pop navigation-stack) + first-in-stack (first navigation-stack)] + (if (= view-id first-in-stack) + (-> db + (assoc :view-id previous-view-id) + (assoc :navigation-stack navigation-stack')) + (assoc db :view-id first-in-stack))))) + (handlers/register-handler-db :navigate-back (re-frame/enrich -preload-data!) - (fn [{:keys [navigation-stack view-id modal] :as db} _] - (cond - modal (assoc db :modal nil - :was-modal? true) - (>= 1 (count navigation-stack)) db - - :else - (let [[previous-view-id :as navigation-stack'] (pop navigation-stack) - first-in-stack (first navigation-stack)] - (if (= view-id first-in-stack) - (-> db - (assoc :view-id previous-view-id) - (assoc :navigation-stack navigation-stack')) - (assoc db :view-id first-in-stack)))))) + (fn [db _] + (navigate-back db))) (handlers/register-handler-fx :navigate-to-clean diff --git a/src/status_im/ui/screens/wallet/events.cljs b/src/status_im/ui/screens/wallet/events.cljs index 462cf502ba..7b95080876 100644 --- a/src/status_im/ui/screens/wallet/events.cljs +++ b/src/status_im/ui/screens/wallet/events.cljs @@ -11,7 +11,8 @@ [taoensso.timbre :as log] status-im.ui.screens.wallet.request.events [status-im.utils.money :as money] - [status-im.constants :as constants])) + [status-im.constants :as constants] + [status-im.ui.screens.navigation :as navigation])) (defn get-balance [{:keys [web3 account-id on-success on-error]}] (if (and web3 account-id) @@ -48,21 +49,21 @@ (reg-fx :get-balance (fn [{:keys [web3 account-id success-event error-event]}] - (get-balance {:web3 web3 - :account-id account-id - :on-success #(re-frame/dispatch [success-event %]) - :on-error #(re-frame/dispatch [error-event %])}))) + (get-balance {:web3 web3 + :account-id account-id + :on-success #(re-frame/dispatch [success-event %]) + :on-error #(re-frame/dispatch [error-event %])}))) (reg-fx :get-tokens-balance (fn [{:keys [web3 symbols chain account-id success-event error-event]}] (doseq [symbol symbols] (let [contract (:address (tokens/symbol->token chain symbol))] - (get-token-balance {:web3 web3 - :contract contract - :account-id account-id - :on-success #(re-frame/dispatch [success-event symbol %]) - :on-error #(re-frame/dispatch [error-event %])}))))) + (get-token-balance {:web3 web3 + :contract contract + :account-id account-id + :on-success #(re-frame/dispatch [success-event symbol %]) + :on-error #(re-frame/dispatch [error-event %])}))))) (reg-fx :get-transactions @@ -109,25 +110,25 @@ currency-id (or (get-in settings [:wallet :currency]) :usd) currency (get constants/currencies currency-id)] (when (not= network-status :offline) - {:get-balance {:web3 web3 - :account-id address - :success-event :update-balance-success - :error-event :update-balance-fail} + {:get-balance {:web3 web3 + :account-id address + :success-event :update-balance-success + :error-event :update-balance-fail} :get-tokens-balance {:web3 web3 :account-id address :symbols symbols :chain chain :success-event :update-token-balance-success :error-event :update-token-balance-fail} - :get-prices {:from (if mainnet? (conj symbols "ETH") ["ETH"]) - :to [(:code currency)] - :success-event :update-prices-success - :error-event :update-prices-fail} - :db (-> db - (clear-error-message :prices-update) - (clear-error-message :balance-update) - (assoc-in [:wallet :balance-loading?] true) - (assoc :prices-loading? true))})))) + :get-prices {:from (if mainnet? (conj symbols "ETH") ["ETH"]) + :to [(:code currency)] + :success-event :update-prices-success + :error-event :update-prices-fail} + :db (-> db + (clear-error-message :prices-update) + (clear-error-message :balance-update) + (assoc-in [:wallet :balance-loading?] true) + (assoc :prices-loading? true))})))) (handlers/register-handler-fx :update-transactions @@ -226,7 +227,7 @@ (handlers/register-handler-fx :show-transaction-details (fn [{:keys [db]} [_ hash]] - {:db (assoc-in db [:wallet :current-transaction] hash) + {:db (assoc-in db [:wallet :current-transaction] hash) :dispatch [:navigate-to :wallet-transaction-details]})) (handlers/register-handler-fx @@ -258,3 +259,10 @@ :wallet/show-error (fn [] {:show-error (i18n/label :t/wallet-error)})) + +(handlers/register-handler-fx + :wallet-setup-navigate-back + (fn [{:keys [db]}] + {:db (-> db + (assoc-in [:wallet :send-transaction] {}) + (navigation/navigate-back))})) \ No newline at end of file diff --git a/src/status_im/ui/screens/wallet/onboarding/setup/views.cljs b/src/status_im/ui/screens/wallet/onboarding/setup/views.cljs index 7f02da4685..7feca11b8c 100644 --- a/src/status_im/ui/screens/wallet/onboarding/setup/views.cljs +++ b/src/status_im/ui/screens/wallet/onboarding/setup/views.cljs @@ -10,7 +10,8 @@ [status-im.ui.screens.wallet.onboarding.setup.styles :as styles] [status-im.ui.components.bottom-buttons.view :as bottom-buttons] [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])) (defn signing-word [word] [react/view styles/signing-word @@ -23,14 +24,16 @@ (utils/show-question (i18n/label :t/wallet-set-up-confirm-title) (i18n/label :t/wallet-set-up-confirm-description) - #(do (re-frame/dispatch [:wallet-set-up-passed]) - (re-frame/dispatch [:navigate-back])))) + #(re-frame/dispatch [:wallet-set-up-passed]))) (views/defview screen [] (views/letsubs [{:keys [signing-phrase]} [:get-current-account]] (let [signing-words (string/split signing-phrase #" ")] [comp/simple-screen {:avoid-keyboard? true} - [comp/toolbar (i18n/label :t/wallet-set-up-title)] + [comp/toolbar + {} + (actions/back-white #(re-frame/dispatch [:wallet-setup-navigate-back])) + (i18n/label :t/wallet-set-up-title)] [react/view components.styles/flex [react/view {:style styles/setup-image-container} [react/image {:source (:wallet-setup resources/ui) diff --git a/test/appium/support/test_rerun.py b/test/appium/support/test_rerun.py index 2951062513..e49a274a06 100644 --- a/test/appium/support/test_rerun.py +++ b/test/appium/support/test_rerun.py @@ -1,4 +1,5 @@ RERUN_ERRORS = [ + "can't receive further commands", 'Original error: Error: ESOCKETTIMEDOUT', "The server didn't respond in time.", 'An unknown server-side error occurred while processing the command.', diff --git a/test/appium/tests/test_chat_management.py b/test/appium/tests/test_chat_management.py index b707a8da27..e8e7191ff0 100644 --- a/test/appium/tests/test_chat_management.py +++ b/test/appium/tests/test_chat_management.py @@ -27,6 +27,10 @@ class TestChatManagementMultiple(MultipleDeviceTestCase): device_1_home_view = device_1_sign_in_view.get_home_view() device_2_home_view = device_2_sign_in_view.get_home_view() + for home in device_1_home_view, device_2_home_view: + wallet = home.wallet_button.click() + wallet.set_up_wallet() + wallet.home_button.click() # Device 1: Start new 1-1 chat device_1_home_view.add_contact(self.senders['h_user']['public_key']) diff --git a/test/appium/tests/test_transaction.py b/test/appium/tests/test_transaction.py index 924038611e..2a094a11a2 100644 --- a/test/appium/tests/test_transaction.py +++ b/test/appium/tests/test_transaction.py @@ -51,6 +51,11 @@ class TestTransaction(SingleDeviceTestCase): chat_view.commands_button.click() chat_view.send_command.click() chat_view.send_as_keyevent(transaction_amount) + wallet_view = chat_view.get_wallet_view() + chat_view.send_message_button.click_until_presence_of_element(wallet_view.sign_in_phrase) + wallet_view.done_button.click() + wallet_view.yes_button.click() + send_transaction_view = chat_view.get_send_transaction_view() chat_view.send_message_button.click_until_presence_of_element(send_transaction_view.sign_transaction_button) send_transaction_view.sign_transaction_button.click_until_presence_of_element( @@ -276,11 +281,10 @@ class TestTransactions(MultipleDeviceTestCase): device_1_chat.send_as_keyevent(amount) device_1_chat.send_message_button.click() request_button = device_2_chat.element_by_text_part('Requesting %s ETH' % amount, 'button') - device_2_chat.send_eth_to_request(request_button, sender['password']) + device_2_chat.send_eth_to_request(request_button, sender['password'], wallet_set_up=True) self.network_api.find_transaction_by_unique_amount(recipient['address'], amount) device_2_chat.back_button.click() device_2_wallet = device_2_home.wallet_button.click() - device_2_wallet.set_up_wallet() transactions_view = device_2_wallet.transactions_button.click() transactions_view.transactions_table.find_transaction(amount=amount) @@ -317,5 +321,5 @@ class TestTransactions(MultipleDeviceTestCase): one_to_one_chat_device_2.wait_for_visibility_of_element(120) one_to_one_chat_device_2.click() request_button = device_2_chat.element_by_text_part('Requesting %s ETH' % amount, 'button') - device_2_chat.send_eth_to_request(request_button, sender['password']) + device_2_chat.send_eth_to_request(request_button, sender['password'], wallet_set_up=True) self.network_api.find_transaction_by_unique_amount(recipient['address'], amount) diff --git a/test/appium/views/base_view.py b/test/appium/views/base_view.py index cd4f330c12..b88aa4dd46 100644 --- a/test/appium/views/base_view.py +++ b/test/appium/views/base_view.py @@ -278,6 +278,10 @@ class BaseView(object): from views.profile_view import ProfileView return ProfileView(self.driver) + def get_wallet_view(self): + from views.wallet_view import WalletView + return WalletView(self.driver) + def get_unique_amount(self): return '0.0%s' % datetime.now().strftime('%-m%-d%-H%-M%-S').strip('0') diff --git a/test/appium/views/chat_view.py b/test/appium/views/chat_view.py index 905b0656e2..4ad1e178c2 100644 --- a/test/appium/views/chat_view.py +++ b/test/appium/views/chat_view.py @@ -259,11 +259,17 @@ class ChatView(BaseView): errors.append("Message '%s' was received but username is '%s' instead of %s" % (message, element.text, username)) - def send_eth_to_request(self, request, sender_password): + def send_eth_to_request(self, request, sender_password, wallet_set_up=False): gas_popup = self.element_by_text_part('Specify amount') request.click_until_presence_of_element(gas_popup) send_transaction = self.get_send_transaction_view() - self.send_message_button.click_until_presence_of_element(send_transaction.sign_transaction_button) + if wallet_set_up: + wallet_view = self.get_wallet_view() + self.send_message_button.click_until_presence_of_element(wallet_view.sign_in_phrase) + wallet_view.done_button.click() + wallet_view.yes_button.click() + else: + self.send_message_button.click_until_presence_of_element(send_transaction.sign_transaction_button) send_transaction.sign_transaction(sender_password) def delete_chat(self, chat_name: str, errors: list):