This commit is contained in:
janherich 2017-10-12 12:24:01 +02:00 committed by Roman Volosovskyi
parent 748f1c6772
commit 5267d55ec8
5 changed files with 42 additions and 34 deletions

View File

@ -403,16 +403,7 @@ function handleSend(params, context) {
web3.eth.sendTransaction(data, function(error, hash) {
if (error) {
status.sendSignal("handler-result", {
status: "failed",
error: {
markup: status.components.validationMessage(
I18n.t('validation_tx_title'),
I18n.t('validation_tx_failed')
)
},
origParams: context["orig-params"]
});
// Do nothing, as error handling will be done as response to transaction.failed event from go
} else {
status.sendSignal("handler-result", {
status: "success",

View File

@ -18,9 +18,10 @@
(spec/def ::camera-flashlight #{:on :off})
(spec/def ::camera-permitted? boolean?)
(spec/def ::in-progress? boolean?)
(spec/def ::from-chat? boolean?)
(spec/def :wallet/send-transaction (allowed-keys
:opt-un [::amount ::to-address ::to-name ::amount-error ::password
::waiting-signal? ::signing? ::transaction-id ::later?
::camera-dimensions ::camera-flashlight ::in-progress?
::wrong-password? ::camera-permitted?]))
::wrong-password? ::camera-permitted? ::from-chat?]))

View File

@ -40,6 +40,11 @@
(assoc-in [:wallet/send-transaction :amount] amount)
(assoc-in [:wallet/send-transaction :amount-error] error))})))
(def ^:private clear-send-properties {:transaction-id nil
:wrong-password? false
:waiting-signal? false
:from-chat? false})
(handlers/register-handler-fx
::transaction-completed
(fn [{db :db} [_ {:keys [id response]}]]
@ -48,8 +53,7 @@
(if-not (and error (string? error) (not (string/blank? error)))
{:db (-> db'
(update-in [:wallet :transactions-unsigned] dissoc id)
(assoc-in [:wallet/send-transaction :transaction-id] nil)
(assoc-in [:wallet/send-transaction :wrong-password?] false))
(update :wallet/send-transaction merge clear-send-properties))
:dispatch [:navigate-to :wallet-transaction-sent]}
{:db db'}))))
@ -68,9 +72,7 @@
{:db db'}
{:db (-> db'
(update-in [:wallet :transactions-unsigned] dissoc id)
(update :wallet/send-transaction assoc
:transaction-id nil
:wrong-password? false))
(update :wallet/send-transaction merge clear-send-properties))
:dispatch [:navigate-back]}))))
(defn on-transactions-modal-completed [raw-results]
@ -121,16 +123,27 @@
:password password
:on-completed on-transactions-modal-completed}})))
(defn discard-transaction
[{{:wallet/keys [send-transaction] :as db} :db}]
(let [{:keys [transaction-id]} send-transaction]
(merge {:db (update db :wallet/send-transaction assoc
:signing? false
:transaction-id nil
:wrong-password? false)}
(when transaction-id
{:discard-transaction transaction-id}))))
(handlers/register-handler-fx
:wallet/discard-transaction
(fn [{{:wallet/keys [send-transaction] :as db} :db} _]
(let [{:keys [transaction-id]} send-transaction]
(merge {:db (update db :wallet/send-transaction assoc
:signing? false
:transaction-id nil
:wrong-password? false)}
(when transaction-id
{:discard-transaction transaction-id})))))
(fn [cofx _]
(discard-transaction cofx)))
(handlers/register-handler-fx
:wallet/discard-transaction-navigate-back
(fn [cofx _]
(-> cofx
discard-transaction
(assoc :dispatch [:navigate-back]))))
(handlers/register-handler-fx
:wallet/cancel-signing-modal

View File

@ -22,8 +22,7 @@
(defn toolbar-view [signing?]
[toolbar/toolbar2 {:style wallet.styles/toolbar}
[toolbar/nav-button (act/back-white (if signing?
#(do (re-frame/dispatch [:wallet/discard-transaction])
(act/default-handler))
#(re-frame/dispatch [:wallet/discard-transaction-navigate-back])
act/default-handler))]
[toolbar/content-title {:color :white} (i18n/label :t/send-transaction)]])
@ -144,9 +143,11 @@
[sign-panel])]
(when in-progress? [react/view send.styles/processing-view])])))
(defn toolbar-modal []
(defn toolbar-modal [from-chat?]
[toolbar/toolbar2 {:style wallet.styles/toolbar}
[toolbar/nav-button (act/close-white act/default-handler)]
[toolbar/nav-button (act/close-white (if from-chat?
#(re-frame/dispatch [:wallet/discard-transaction-navigate-back])
act/default-handler))]
[toolbar/content-title {:color :white} (i18n/label :t/send-transaction)]])
(defview send-transaction-modal []
@ -156,11 +157,12 @@
to-address [:get-in [:wallet/send-transaction :to-address]]
to-name [:get-in [:wallet/send-transaction :to-name]]
recipient [:contact-by-address @to-name]
in-progress? [:get-in [:wallet/send-transaction :in-progress?]]]
in-progress? [:get-in [:wallet/send-transaction :in-progress?]]
from-chat? [:get-in [:wallet/send-transaction :from-chat?]]]
[react/keyboard-avoiding-view wallet.styles/wallet-modal-container
[react/view components.styles/flex
[status-bar/status-bar {:type :wallet}]
[toolbar-modal]
[toolbar-modal from-chat?]
[react/scroll-view {:keyboardShouldPersistTaps :always}
[react/view components.styles/flex
[react/view wallet.styles/choose-participant-container

View File

@ -46,10 +46,11 @@
;;sending from wallet
{:dispatch [:wallet.send-transaction/transaction-queued id]}
;;sending from chat
{:dispatch [:navigate-to-modal :wallet-send-transaction-modal {:amount (str (money/wei->ether value))
{:dispatch [:navigate-to-modal :wallet-send-transaction-modal {:amount (str (money/wei->ether value))
:transaction-id id
:to-address to
:to-name to}]}))))
:to-address to
:to-name to
:from-chat? true}]}))))
{:discard-transaction id})))
;TRANSACTION FAILED signal from status-go
@ -74,4 +75,4 @@
(merge
{:db (update-in db [:wallet :transactions-unsigned] dissoc id)}
(when (and message_id (= current-account-address transaction-initiator-address))
{:dispatch [:set-chat-ui-props {:validation-messages error_message}]}))))))
{:dispatch [:set-chat-ui-props {:validation-messages error_message}]}))))))