refactor #7571 - decoupled request transaction from send transaction flow

Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
Goran Jovic 2019-02-25 16:40:28 +01:00
parent dccc81db7b
commit fcb3cef110
No known key found for this signature in database
GPG Key ID: D429D1A9B2EB8A8E
4 changed files with 35 additions and 30 deletions

View File

@ -318,7 +318,7 @@
:amount-text amount :amount-text amount
:amount-error error) :amount-error error)
(choose-recipient.events/fill-request-details (choose-recipient.events/fill-request-details
(transaction-details recipient-contact symbol)) (transaction-details recipient-contact symbol) false)
(update-in [:wallet :send-transaction] (update-in [:wallet :send-transaction]
dissoc :id :password :wrong-password?)) dissoc :id :password :wrong-password?))
;; TODO(janherich) - refactor wallet send events, updating gas price ;; TODO(janherich) - refactor wallet send events, updating gas price

View File

@ -20,11 +20,13 @@
(defn- find-address-name [db address] (defn- find-address-name [db address]
(:name (contact.db/find-contact-by-address (:contacts/contacts db) address))) (:name (contact.db/find-contact-by-address (:contacts/contacts db) address)))
(defn- fill-request-details [db {:keys [address name value symbol gas gasPrice public-key from-chat?]}] (defn- fill-request-details [db {:keys [address name value symbol gas gasPrice public-key from-chat?]} request?]
{:pre [(not (nil? address))]} {:pre [(not (nil? address))]}
(let [name (or name (find-address-name db address))] (let [name (or name (find-address-name db address))
(update-in data-path (if request?
db [:wallet :send-transaction] [:wallet :request-transaction]
[:wallet :send-transaction])]
(update-in db data-path
(fn [{old-symbol :symbol :as old-transaction}] (fn [{old-symbol :symbol :as old-transaction}]
(let [symbol-changed? (not= old-symbol symbol)] (let [symbol-changed? (not= old-symbol symbol)]
(cond-> (assoc old-transaction :to address :to-name name :public-key public-key) (cond-> (assoc old-transaction :to address :to-name name :public-key public-key)
@ -105,7 +107,7 @@
symbol-changed? (and old-symbol new-symbol (not= old-symbol new-symbol))] symbol-changed? (and old-symbol new-symbol (not= old-symbol new-symbol))]
(cond-> {:db db (cond-> {:db db
:dispatch [:navigate-back]} :dispatch [:navigate-back]}
(and address valid-network?) (update :db #(fill-request-details % details)) (and address valid-network?) (update :db #(fill-request-details % details false))
symbol-changed? (changed-asset old-symbol new-symbol) symbol-changed? (changed-asset old-symbol new-symbol)
(and old-amount new-amount (not= old-amount new-amount)) (changed-amount-warning old-amount new-amount) (and old-amount new-amount (not= old-amount new-amount)) (changed-amount-warning old-amount new-amount)
;; NOTE(goranjovic) - the next line is there is because QR code scanning switches the amount to ETH ;; NOTE(goranjovic) - the next line is there is because QR code scanning switches the amount to ETH
@ -119,6 +121,6 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/fill-request-from-contact :wallet/fill-request-from-contact
(fn [{db :db} [_ {:keys [address name public-key]}]] (fn [{db :db} [_ {:keys [address name public-key]} request?]]
{:db (fill-request-details db {:address address :name name :public-key public-key}) {:db (fill-request-details db {:address address :name name :public-key public-key} request?)
:dispatch [:navigate-back]})) :dispatch [:navigate-back]}))

View File

@ -197,8 +197,8 @@
:accessibility-label (if request? :contact-address-text :recipient-address-text)} :accessibility-label (if request? :contact-address-text :recipient-address-text)}
(ethereum/normalized-address address)]]]))) (ethereum/normalized-address address)]]])))
(defn render-contact [contact] (defn render-contact [contact request?]
[list/touchable-item #(re-frame/dispatch [:wallet/fill-request-from-contact contact]) [list/touchable-item #(re-frame/dispatch [:wallet/fill-request-from-contact contact request?])
[list/item [list/item
[photos/photo (:photo-path contact) {:size list.styles/image-size}] [photos/photo (:photo-path contact) {:size list.styles/image-size}]
[list/item-content [list/item-content
@ -209,13 +209,14 @@
(ethereum/normalized-address (:address contact))]]]]) (ethereum/normalized-address (:address contact))]]]])
(views/defview recent-recipients [] (views/defview recent-recipients []
(views/letsubs [contacts [:contacts/active]] (views/letsubs [contacts [:contacts/active]
{:keys [request?]} [:get-screen-params :recent-recipients]]
[simple-screen [simple-screen
[toolbar (i18n/label :t/recipient)] [toolbar (i18n/label :t/recipient)]
[react/view styles/recent-recipients [react/view styles/recent-recipients
[list/flat-list {:data contacts [list/flat-list {:data contacts
:key-fn :address :key-fn :address
:render-fn render-contact}]]])) :render-fn #(render-contact % request?)}]]]))
(defn contact-code [] (defn contact-code []
(let [content (reagent/atom nil)] (let [content (reagent/atom nil)]
@ -250,11 +251,11 @@
(i18n/label :t/camera-access-error))) (i18n/label :t/camera-access-error)))
50)}])) 50)}]))
(defn- on-choose-recipient [contact-only?] (defn- on-choose-recipient [contact-only? request?]
(list-selection/show {:title (i18n/label :t/wallet-choose-recipient) (list-selection/show {:title (i18n/label :t/wallet-choose-recipient)
:options (concat :options (concat
[{:label (i18n/label :t/recent-recipients) [{:label (i18n/label :t/recent-recipients)
:action #(re-frame/dispatch [:navigate-to :recent-recipients])}] :action #(re-frame/dispatch [:navigate-to :recent-recipients {:request? request?}])}]
(when-not contact-only? (when-not contact-only?
[{:label (i18n/label :t/scan-qr) [{:label (i18n/label :t/scan-qr)
:action request-camera-permissions} :action request-camera-permissions}
@ -262,7 +263,7 @@
:action #(re-frame/dispatch [:navigate-to :contact-code])}]))})) :action #(re-frame/dispatch [:navigate-to :contact-code])}]))}))
(defn recipient-selector [{:keys [name address disabled? contact-only? request? modal?]}] (defn recipient-selector [{:keys [name address disabled? contact-only? request? modal?]}]
[cartouche {:on-press #(on-choose-recipient contact-only?) [cartouche {:on-press #(on-choose-recipient contact-only? request?)
:disabled? disabled? :disabled? disabled?
:icon :main-icons/more :icon :main-icons/more
:icon-opts {:accessibility-label :choose-contact-button}} :icon-opts {:accessibility-label :choose-contact-button}}

View File

@ -21,7 +21,9 @@
[status-im.utils.ethereum.eip681 :as eip681] [status-im.utils.ethereum.eip681 :as eip681]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im.utils.ethereum.tokens :as tokens] [status-im.utils.ethereum.tokens :as tokens]
[status-im.ui.screens.wallet.utils :as wallet.utils])) [status-im.ui.screens.wallet.utils :as wallet.utils]
[status-im.ui.screens.chat.photos :as photos]
[status-im.ui.components.list.styles :as list.styles]))
;; Request screen ;; Request screen
@ -29,7 +31,8 @@
;; TODO(jeluard) both send and request flows should be merged ;; TODO(jeluard) both send and request flows should be merged
(views/letsubs [network [:account/network] (views/letsubs [network [:account/network]
{:keys [to to-name public-key]} [:wallet.send/transaction] {:keys [to to-name public-key]} [:wallet.send/transaction]
{:keys [amount amount-error amount-text symbol]} [:wallet.request/transaction] {:keys [amount amount-error amount-text symbol
to to-name public-key]} [:wallet.request/transaction]
network-status [:network-status] network-status [:network-status]
all-tokens [:wallet/all-tokens] all-tokens [:wallet/all-tokens]
scroll (atom nil)] scroll (atom nil)]
@ -43,8 +46,7 @@
[components/recipient-selector {:contact-only? true [components/recipient-selector {:contact-only? true
:address to :address to
:name to-name :name to-name
:request? true :request? true}]
:modal? false}]
[components/asset-selector {:disabled? false [components/asset-selector {:disabled? false
:type :request :type :request
:symbol symbol}] :symbol symbol}]