Transaction screens: fee and title (#995)

* add estimated fee field
This commit is contained in:
Gustavo Nunes 2017-04-14 04:39:52 -03:00 committed by Roman Volosovskyi
parent dd2c3aa287
commit 3244fa49ce
7 changed files with 26 additions and 19 deletions

View File

@ -23,7 +23,7 @@
[status-im.accounts.recover.screen :refer [recover]]
[status-im.accounts.screen :refer [accounts]]
[status-im.transactions.screens.confirmation-success :refer [confirmation-success]]
[status-im.transactions.screens.pending-transactions :refer [pending-transactions]]
[status-im.transactions.screens.unsigned-transactions :refer [unsigned-transactions]]
[status-im.transactions.screens.transaction-details :refer [transaction-details]]
[status-im.chats-list.screen :refer [chats-list]]
[status-im.new-chat.screen :refer [new-chat]]
@ -151,7 +151,7 @@
(let [component (case @modal-view
:qr-scanner qr-scanner
:qr-code-view qr-code-view
:pending-transactions pending-transactions
:unsigned-transactions unsigned-transactions
:transaction-details transaction-details
:confirmation-success confirmation-success
:contact-list-modal contact-list-modal)]

View File

@ -21,7 +21,7 @@
[status-im.accounts.recover.screen :refer [recover]]
[status-im.accounts.screen :refer [accounts]]
[status-im.transactions.screens.confirmation-success :refer [confirmation-success]]
[status-im.transactions.screens.pending-transactions :refer [pending-transactions]]
[status-im.transactions.screens.unsigned-transactions :refer [unsigned-transactions]]
[status-im.transactions.screens.transaction-details :refer [transaction-details]]
[status-im.chats-list.screen :refer [chats-list]]
[status-im.new-chat.screen :refer [new-chat]]
@ -133,7 +133,7 @@
(let [component (case @modal-view
:qr-scanner qr-scanner
:qr-code-view qr-code-view
:pending-transactions pending-transactions
:unsigned-transactions unsigned-transactions
:transaction-details transaction-details
:confirmation-success confirmation-success
:contact-list-modal contact-list-modal)]

View File

@ -22,7 +22,7 @@
;; && :navigation-replace <- on success
(defmethod nav/preload-data! :pending-transactions
(defmethod nav/preload-data! :unsigned-transactions
[{:keys [transactions-queue] :as db} _]
(-> db
(assoc :transactions transactions-queue
@ -128,15 +128,17 @@
(status/discard-transaction id)))))
(register-handler ::transaction-queued
(after #(dispatch [:navigate-to-modal :pending-transactions]))
(after #(dispatch [:navigate-to-modal :unsigned-transactions]))
(fn [db [_ {:keys [id message_id args]}]]
(let [{:keys [from to value data]} args]
(let [{:keys [from to value data gas gasPrice]} args]
(if (valid-hex? to)
(let [transaction {:id id
:from from
:to to
:value (.toDecimal js/Web3.prototype value)
:data data
:gas (.toDecimal js/Web3.prototype gas)
:gas-price (.toDecimal js/Web3.prototype gasPrice)
:message-id message_id}]
(assoc-in db [:transactions-queue id] transaction))
db))))
@ -155,7 +157,7 @@
(dispatch [::check-completed-transaction!
{:message-id message-id}]))
(dispatch [::remove-transaction id]))
(when (#{:pending-transactions :transaction-details} modal)
(when (#{:unsigned-transactions :transaction-details} modal)
(dispatch [:navigate-to-modal :confirmation-success])))))))
(register-handler ::add-transactions-hash

View File

@ -16,7 +16,7 @@
(defn toolbar-view []
[toolbar/toolbar
{:background-color st/transactions-toolbar-background
:nav-action (act/back-white #(rf/dispatch [:navigate-to-modal :pending-transactions]))
:nav-action (act/back-white #(rf/dispatch [:navigate-to-modal :unsigned-transactions]))
:border-style st/toolbar-border
:custom-content [rn/view {:style st/toolbar-title-container}
[rn/text {:style st/toolbar-title-text
@ -35,26 +35,30 @@
[rn/text {:style st/details-data-title} (i18n/label :t/data)]
[rn/text {:style st/details-data-content} content]])
(defview details [{:keys [to data] :as transaction}]
(defview details [{:keys [to data gas gas-price] :as transaction}]
[current-account [:get-current-account]
recipient [:contact-by-address to]]
(let [recipient-name (or (:name recipient) to)]
(let [recipient-name (or (:name recipient) to)
gas-price (.fromWei js/Web3.prototype gas-price "ether")
fee-value (* gas gas-price)
estimated-fee (str fee-value " ETH")]
[rn/view st/details-container
[detail-item (i18n/label :t/to) recipient-name true]
[detail-item (i18n/label :t/from) (:name current-account) true]
[detail-item (i18n/label :t/estimated-fee) estimated-fee]
[detail-data data]]))
(defview transaction-details []
[{:keys [id] :as transaction} [:get :selected-transaction]
{:keys [password]} [:get :confirm-transactions]
confirmed? [:get-in [:transaction-details-ui-props :confirmed?]]]
{:component-did-update #(when-not transaction (rf/dispatch [:navigate-to-modal :pending-transactions]))
{:component-did-update #(when-not transaction (rf/dispatch [:navigate-to-modal :unsigned-transactions]))
:component-will-unmount #(rf/dispatch [:set-in [:transaction-details-ui-props :confirmed?] false])}
[rn/keyboard-avoiding-view {:style st/transactions-screen}
[status-bar/status-bar {:type (if platform/ios? :transparent :main)}]
[toolbar-view]
[rn/scroll-view st/details-screen-content-container
[transactions-list-item/view transaction #(rf/dispatch [:navigate-to-modal :pending-transactions])]
[transactions-list-item/view transaction #(rf/dispatch [:navigate-to-modal :unsigned-transactions])]
[common/separator st/details-separator st/details-separator-wrapper]
[details transaction]]
(when confirmed? [password-form/view 1])

View File

@ -1,4 +1,4 @@
(ns status-im.transactions.screens.pending-transactions
(ns status-im.transactions.screens.unsigned-transactions
(:require-macros [status-im.utils.views :refer [defview]])
(:require [re-frame.core :as rf]
[status-im.components.common.common :as common]
@ -23,7 +23,7 @@
:custom-content [rn/view {:style st/toolbar-title-container}
[rn/text {:style st/toolbar-title-text
:font :toolbar-title}
(i18n/label :t/pending-transactions)]
(i18n/label :t/unsigned-transactions)]
[rn/text {:style st/toolbar-title-count
:font :toolbar-title}
(count transactions)]]}])
@ -41,13 +41,13 @@
[rn/view
[transactions-list-item/view row]]]))
(defview pending-transactions []
(defview unsigned-transactions []
[transactions [:transactions]
{:keys [password]} [:get :confirm-transactions]
confirmed? [:get-in [:transactions-list-ui-props :confirmed?]]]
{:component-did-update #(when-not (seq transactions) (rf/dispatch [:navigate-back]))
:component-will-unmount #(rf/dispatch [:set-in [:transactions-list-ui-props :confirmed?] false])}
[rn/keyboard-avoiding-view {:style st/transactions-screen}
[(if platform/ios? rn/keyboard-avoiding-view rn/view) (merge {:behavior :padding} st/transactions-screen)
[status-bar/status-bar {:type (if platform/ios? :transparent :main)}]
[toolbar-view transactions]
[rn/view {:style st/transactions-screen-content-container}

View File

@ -33,7 +33,7 @@
{:ios {:background-color common/color-white
:opacity 0.1}})
;; pending-transactions
;; unsigned-transactions
(def transactions-screen
{:flex 1

View File

@ -279,7 +279,7 @@
:other "{{count}} transactions confirmed"
:zero "No transactions confirmed"}
:transaction "Transaction"
:pending-transactions "Pending transactions"
:unsigned-transactions "Unsigned transactions"
:enter-password-transactions {:one "Confirm transaction by entering your password"
:other "Confirm transactions by entering your password"}
:status "Status"
@ -287,6 +287,7 @@
:recipient "Recipient"
:one-more-item "One more item"
:fee "Fee"
:estimated-fee "Est. fee"
:value "Value"
:to "To"
:from "From"