show onboarding for transaction from chat [#4456]

This commit is contained in:
Andrey Shovkoplyas 2018-05-30 18:41:00 +03:00 committed by Roman Volosovskyi
parent 68eb36f7b1
commit 83afbd515a
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
10 changed files with 110 additions and 63 deletions

View File

@ -12,11 +12,14 @@
:gas (ethereum/estimate-gas :ETH) :gas (ethereum/estimate-gas :ETH)
:from-chat? true))) :from-chat? true)))
(defn send-shortcut-fx [db contact params] (defn send-shortcut-fx [{:account/keys [account] :as db} contact params]
(merge {:db (-> db (merge {:db (-> db
(send.events/set-and-validate-amount-db (:amount params) :ETH 18) (send.events/set-and-validate-amount-db (:amount params) :ETH 18)
(choose-recipient.events/fill-request-details (transaction-details contact)) (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))) (send.events/update-gas-price db false)))
(def shortcuts (def shortcuts

View File

@ -18,7 +18,8 @@
status-im.ui.screens.accounts.create.navigation status-im.ui.screens.accounts.create.navigation
[status-im.chat.models :as chat.models] [status-im.chat.models :as chat.models]
[status-im.ui.screens.accounts.utils :as accounts.utils] [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 ;;;; COFX
@ -46,16 +47,16 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:create-account :create-account
(fn [{{:accounts/keys [create] :as db} :db} _] (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)})) ::create-account (:password create)}))
(defn add-account (defn add-account
"Takes db and new account, creates map of effects describing adding account to database and realm" "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}] [{:keys [network] :networks/keys [networks] :as db} {:keys [address] :as account}]
(let [enriched-account (assoc account (let [enriched-account (assoc account
:network network :network network
:networks networks :networks networks
:address address)] :address address)]
{:db (assoc-in db [:accounts/accounts address] enriched-account) {:db (assoc-in db [:accounts/accounts address] enriched-account)
:data-store/base-tx [(accounts-store/save-account-tx enriched-account)]})) :data-store/base-tx [(accounts-store/save-account-tx enriched-account)]}))
@ -92,8 +93,8 @@
(map (fn [{:keys [address] :as account}] (map (fn [{:keys [address] :as account}]
[address account])) [address account]))
(into {})) (into {}))
;;workaround for realm bug, migrating account v4 ;;workaround for realm bug, migrating account v4
events (mapv #(when (empty? (:networks %)) [:account-update-networks (:address %)]) (vals accounts))] events (mapv #(when (empty? (:networks %)) [:account-update-networks (:address %)]) (vals accounts))]
(merge (merge
{:db (assoc db :accounts/accounts accounts)} {:db (assoc db :accounts/accounts accounts)}
(when-not (empty? events) (when-not (empty? events)
@ -103,7 +104,7 @@
:account-update-networks :account-update-networks
(fn [{{:accounts/keys [accounts] :networks/keys [networks] :as db} :db} [_ id]] (fn [{{:accounts/keys [accounts] :networks/keys [networks] :as db} :db} [_ id]]
(let [current-account (get accounts 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) {:db (assoc-in db [:accounts/accounts id] new-account)
:data-store/base-tx [(accounts-store/save-account-tx 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}] ([settings success-event {{:keys [account/account] :as db} :db :as cofx}]
(let [new-account (assoc account :settings settings)] (let [new-account (assoc account :settings settings)]
{:db (assoc db :account/account new-account) {: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}]}))) :success-event success-event}]})))
(handlers/register-handler-fx (handlers/register-handler-fx
:send-account-update-if-needed :send-account-update-if-needed
(fn [{:keys [db now] :as cofx} _] (fn [{:keys [db now] :as cofx} _]
(let [{:keys [last-updated]} (:account/account db) (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?) (log/info "Need to send account-update: " needs-update?)
(when needs-update? (when needs-update?
;; TODO(janherich): this is very strange and misleading, need to figure out why it'd necessary to 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 ;; account with network update when last update was more then week ago
(accounts.utils/account-update nil cofx))))) (accounts.utils/account-update nil cofx)))))
(handlers/register-handler-fx (handlers/register-handler-fx
@ -137,7 +138,7 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:account-finalized :account-finalized
(fn [{db :db} [_ show-welcome?]] (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] :dispatch-n [[:navigate-to-clean :home]
[:request-notifications]]})) [:request-notifications]]}))
@ -161,7 +162,17 @@
(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]
(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 (handlers/register-handler-fx
:wallet-set-up-passed :wallet-set-up-passed
(fn [cofx] (fn [{:keys [db] :as cofx}]
(accounts.utils/account-update {:wallet-set-up-passed? true} cofx))) (handlers-macro/merge-fx
cofx
(wallet-set-up-passed db)
(accounts.utils/account-update {:wallet-set-up-passed? true}))))

View File

@ -90,23 +90,26 @@
(fn [cofx [_ view-id]] (fn [cofx [_ view-id]]
(replace-view view-id cofx))) (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 (handlers/register-handler-db
:navigate-back :navigate-back
(re-frame/enrich -preload-data!) (re-frame/enrich -preload-data!)
(fn [{:keys [navigation-stack view-id modal] :as db} _] (fn [db _]
(cond (navigate-back db)))
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-fx (handlers/register-handler-fx
:navigate-to-clean :navigate-to-clean

View File

@ -11,7 +11,8 @@
[taoensso.timbre :as log] [taoensso.timbre :as log]
status-im.ui.screens.wallet.request.events status-im.ui.screens.wallet.request.events
[status-im.utils.money :as money] [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]}] (defn get-balance [{:keys [web3 account-id on-success on-error]}]
(if (and web3 account-id) (if (and web3 account-id)
@ -48,21 +49,21 @@
(reg-fx (reg-fx
:get-balance :get-balance
(fn [{:keys [web3 account-id success-event error-event]}] (fn [{:keys [web3 account-id success-event error-event]}]
(get-balance {:web3 web3 (get-balance {:web3 web3
:account-id account-id :account-id account-id
:on-success #(re-frame/dispatch [success-event %]) :on-success #(re-frame/dispatch [success-event %])
:on-error #(re-frame/dispatch [error-event %])}))) :on-error #(re-frame/dispatch [error-event %])})))
(reg-fx (reg-fx
:get-tokens-balance :get-tokens-balance
(fn [{:keys [web3 symbols chain account-id success-event error-event]}] (fn [{:keys [web3 symbols chain account-id success-event error-event]}]
(doseq [symbol symbols] (doseq [symbol symbols]
(let [contract (:address (tokens/symbol->token chain symbol))] (let [contract (:address (tokens/symbol->token chain symbol))]
(get-token-balance {:web3 web3 (get-token-balance {:web3 web3
:contract contract :contract contract
:account-id account-id :account-id account-id
:on-success #(re-frame/dispatch [success-event symbol %]) :on-success #(re-frame/dispatch [success-event symbol %])
:on-error #(re-frame/dispatch [error-event %])}))))) :on-error #(re-frame/dispatch [error-event %])})))))
(reg-fx (reg-fx
:get-transactions :get-transactions
@ -109,25 +110,25 @@
currency-id (or (get-in settings [:wallet :currency]) :usd) currency-id (or (get-in settings [:wallet :currency]) :usd)
currency (get constants/currencies currency-id)] currency (get constants/currencies currency-id)]
(when (not= network-status :offline) (when (not= network-status :offline)
{:get-balance {:web3 web3 {:get-balance {:web3 web3
:account-id address :account-id address
:success-event :update-balance-success :success-event :update-balance-success
:error-event :update-balance-fail} :error-event :update-balance-fail}
:get-tokens-balance {:web3 web3 :get-tokens-balance {:web3 web3
:account-id address :account-id address
:symbols symbols :symbols symbols
:chain chain :chain chain
:success-event :update-token-balance-success :success-event :update-token-balance-success
:error-event :update-token-balance-fail} :error-event :update-token-balance-fail}
:get-prices {:from (if mainnet? (conj symbols "ETH") ["ETH"]) :get-prices {:from (if mainnet? (conj symbols "ETH") ["ETH"])
:to [(:code currency)] :to [(:code currency)]
:success-event :update-prices-success :success-event :update-prices-success
:error-event :update-prices-fail} :error-event :update-prices-fail}
:db (-> db :db (-> db
(clear-error-message :prices-update) (clear-error-message :prices-update)
(clear-error-message :balance-update) (clear-error-message :balance-update)
(assoc-in [:wallet :balance-loading?] true) (assoc-in [:wallet :balance-loading?] true)
(assoc :prices-loading? true))})))) (assoc :prices-loading? true))}))))
(handlers/register-handler-fx (handlers/register-handler-fx
:update-transactions :update-transactions
@ -226,7 +227,7 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:show-transaction-details :show-transaction-details
(fn [{:keys [db]} [_ hash]] (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]})) :dispatch [:navigate-to :wallet-transaction-details]}))
(handlers/register-handler-fx (handlers/register-handler-fx
@ -258,3 +259,10 @@
:wallet/show-error :wallet/show-error
(fn [] (fn []
{:show-error (i18n/label :t/wallet-error)})) {: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))}))

View File

@ -10,7 +10,8 @@
[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]))
(defn signing-word [word] (defn signing-word [word]
[react/view styles/signing-word [react/view styles/signing-word
@ -23,14 +24,16 @@
(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)
#(do (re-frame/dispatch [:wallet-set-up-passed]) #(re-frame/dispatch [:wallet-set-up-passed])))
(re-frame/dispatch [:navigate-back]))))
(views/defview screen [] (views/defview screen []
(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} [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 components.styles/flex
[react/view {:style styles/setup-image-container} [react/view {:style styles/setup-image-container}
[react/image {:source (:wallet-setup resources/ui) [react/image {:source (:wallet-setup resources/ui)

View File

@ -1,4 +1,5 @@
RERUN_ERRORS = [ RERUN_ERRORS = [
"can't receive further commands",
'Original error: Error: ESOCKETTIMEDOUT', 'Original error: Error: ESOCKETTIMEDOUT',
"The server didn't respond in time.", "The server didn't respond in time.",
'An unknown server-side error occurred while processing the command.', 'An unknown server-side error occurred while processing the command.',

View File

@ -27,6 +27,10 @@ class TestChatManagementMultiple(MultipleDeviceTestCase):
device_1_home_view = device_1_sign_in_view.get_home_view() device_1_home_view = device_1_sign_in_view.get_home_view()
device_2_home_view = device_2_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: Start new 1-1 chat
device_1_home_view.add_contact(self.senders['h_user']['public_key']) device_1_home_view.add_contact(self.senders['h_user']['public_key'])

View File

@ -51,6 +51,11 @@ class TestTransaction(SingleDeviceTestCase):
chat_view.commands_button.click() chat_view.commands_button.click()
chat_view.send_command.click() chat_view.send_command.click()
chat_view.send_as_keyevent(transaction_amount) 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() 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) 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( 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_as_keyevent(amount)
device_1_chat.send_message_button.click() device_1_chat.send_message_button.click()
request_button = device_2_chat.element_by_text_part('Requesting %s ETH' % amount, 'button') 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) self.network_api.find_transaction_by_unique_amount(recipient['address'], amount)
device_2_chat.back_button.click() device_2_chat.back_button.click()
device_2_wallet = device_2_home.wallet_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 = device_2_wallet.transactions_button.click()
transactions_view.transactions_table.find_transaction(amount=amount) 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.wait_for_visibility_of_element(120)
one_to_one_chat_device_2.click() one_to_one_chat_device_2.click()
request_button = device_2_chat.element_by_text_part('Requesting %s ETH' % amount, 'button') 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) self.network_api.find_transaction_by_unique_amount(recipient['address'], amount)

View File

@ -278,6 +278,10 @@ class BaseView(object):
from views.profile_view import ProfileView from views.profile_view import ProfileView
return ProfileView(self.driver) return ProfileView(self.driver)
def get_wallet_view(self):
from views.wallet_view import WalletView
return WalletView(self.driver)
def get_unique_amount(self): def get_unique_amount(self):
return '0.0%s' % datetime.now().strftime('%-m%-d%-H%-M%-S').strip('0') return '0.0%s' % datetime.now().strftime('%-m%-d%-H%-M%-S').strip('0')

View File

@ -259,11 +259,17 @@ class ChatView(BaseView):
errors.append("Message '%s' was received but username is '%s' instead of %s" % errors.append("Message '%s' was received but username is '%s' instead of %s" %
(message, element.text, username)) (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') gas_popup = self.element_by_text_part('Specify amount')
request.click_until_presence_of_element(gas_popup) request.click_until_presence_of_element(gas_popup)
send_transaction = self.get_send_transaction_view() 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) send_transaction.sign_transaction(sender_password)
def delete_chat(self, chat_name: str, errors: list): def delete_chat(self, chat_name: str, errors: list):