refactor #7571 - decoupled request transaction from send transaction flow
Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
parent
dccc81db7b
commit
fcb3cef110
|
@ -318,7 +318,7 @@
|
|||
:amount-text amount
|
||||
:amount-error error)
|
||||
(choose-recipient.events/fill-request-details
|
||||
(transaction-details recipient-contact symbol))
|
||||
(transaction-details recipient-contact symbol) false)
|
||||
(update-in [:wallet :send-transaction]
|
||||
dissoc :id :password :wrong-password?))
|
||||
;; TODO(janherich) - refactor wallet send events, updating gas price
|
||||
|
|
|
@ -20,11 +20,13 @@
|
|||
(defn- find-address-name [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))]}
|
||||
(let [name (or name (find-address-name db address))]
|
||||
(update-in
|
||||
db [:wallet :send-transaction]
|
||||
(let [name (or name (find-address-name db address))
|
||||
data-path (if request?
|
||||
[:wallet :request-transaction]
|
||||
[:wallet :send-transaction])]
|
||||
(update-in db data-path
|
||||
(fn [{old-symbol :symbol :as old-transaction}]
|
||||
(let [symbol-changed? (not= old-symbol symbol)]
|
||||
(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))]
|
||||
(cond-> {:db db
|
||||
: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)
|
||||
(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
|
||||
|
@ -119,6 +121,6 @@
|
|||
|
||||
(handlers/register-handler-fx
|
||||
:wallet/fill-request-from-contact
|
||||
(fn [{db :db} [_ {:keys [address name public-key]}]]
|
||||
{:db (fill-request-details db {:address address :name name :public-key public-key})
|
||||
(fn [{db :db} [_ {:keys [address name public-key]} request?]]
|
||||
{:db (fill-request-details db {:address address :name name :public-key public-key} request?)
|
||||
:dispatch [:navigate-back]}))
|
||||
|
|
|
@ -197,8 +197,8 @@
|
|||
:accessibility-label (if request? :contact-address-text :recipient-address-text)}
|
||||
(ethereum/normalized-address address)]]])))
|
||||
|
||||
(defn render-contact [contact]
|
||||
[list/touchable-item #(re-frame/dispatch [:wallet/fill-request-from-contact contact])
|
||||
(defn render-contact [contact request?]
|
||||
[list/touchable-item #(re-frame/dispatch [:wallet/fill-request-from-contact contact request?])
|
||||
[list/item
|
||||
[photos/photo (:photo-path contact) {:size list.styles/image-size}]
|
||||
[list/item-content
|
||||
|
@ -209,13 +209,14 @@
|
|||
(ethereum/normalized-address (:address contact))]]]])
|
||||
|
||||
(views/defview recent-recipients []
|
||||
(views/letsubs [contacts [:contacts/active]]
|
||||
(views/letsubs [contacts [:contacts/active]
|
||||
{:keys [request?]} [:get-screen-params :recent-recipients]]
|
||||
[simple-screen
|
||||
[toolbar (i18n/label :t/recipient)]
|
||||
[react/view styles/recent-recipients
|
||||
[list/flat-list {:data contacts
|
||||
:key-fn :address
|
||||
:render-fn render-contact}]]]))
|
||||
:render-fn #(render-contact % request?)}]]]))
|
||||
|
||||
(defn contact-code []
|
||||
(let [content (reagent/atom nil)]
|
||||
|
@ -250,11 +251,11 @@
|
|||
(i18n/label :t/camera-access-error)))
|
||||
50)}]))
|
||||
|
||||
(defn- on-choose-recipient [contact-only?]
|
||||
(defn- on-choose-recipient [contact-only? request?]
|
||||
(list-selection/show {:title (i18n/label :t/wallet-choose-recipient)
|
||||
:options (concat
|
||||
[{: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?
|
||||
[{:label (i18n/label :t/scan-qr)
|
||||
:action request-camera-permissions}
|
||||
|
@ -262,7 +263,7 @@
|
|||
:action #(re-frame/dispatch [:navigate-to :contact-code])}]))}))
|
||||
|
||||
(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?
|
||||
:icon :main-icons/more
|
||||
:icon-opts {:accessibility-label :choose-contact-button}}
|
||||
|
|
|
@ -21,7 +21,9 @@
|
|||
[status-im.utils.ethereum.eip681 :as eip681]
|
||||
[status-im.utils.utils :as utils]
|
||||
[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
|
||||
|
||||
|
@ -29,7 +31,8 @@
|
|||
;; TODO(jeluard) both send and request flows should be merged
|
||||
(views/letsubs [network [:account/network]
|
||||
{: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]
|
||||
all-tokens [:wallet/all-tokens]
|
||||
scroll (atom nil)]
|
||||
|
@ -43,8 +46,7 @@
|
|||
[components/recipient-selector {:contact-only? true
|
||||
:address to
|
||||
:name to-name
|
||||
:request? true
|
||||
:modal? false}]
|
||||
:request? true}]
|
||||
[components/asset-selector {:disabled? false
|
||||
:type :request
|
||||
:symbol symbol}]
|
||||
|
|
Loading…
Reference in New Issue