[fix] wallet on-error dispatch

the code to dispatch an event on transaction error was not working
this fixes it

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2019-04-19 15:06:09 +02:00
parent fa18f3b746
commit c4f719352e
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
3 changed files with 21 additions and 18 deletions

View File

@ -160,22 +160,23 @@
(update :gas-price str) (update :gas-price str)
(dissoc :message-id :id :gas))))) (dissoc :message-id :id :gas)))))
(defn handle-transaction-error [{:keys [db]} {:keys [code message]}] (fx/defn handle-transaction-error
[{:keys [db] :as cofx} {:keys [code message]}]
(let [{:keys [on-error]} (get-in db [:wallet :send-transaction])] (let [{:keys [on-error]} (get-in db [:wallet :send-transaction])]
(case code (case code
;;WRONG PASSWORD ;;WRONG PASSWORD
constants/send-transaction-err-decrypt constants/send-transaction-err-decrypt
{:db (-> db {:db (-> db
(assoc-in [:wallet :send-transaction :wrong-password?] true))} (assoc-in [:wallet :send-transaction :wrong-password?] true))}
(fx/merge {:db (-> db (fx/merge cofx
(assoc-in [:wallet :transactions-queue] nil) (merge {:db (-> db
(assoc-in [:wallet :send-transaction] {}))} (assoc-in [:wallet :transactions-queue] nil)
{:wallet/show-transaction-error message} (assoc-in [:wallet :send-transaction] {}))
(navigation/navigate-back) :wallet/show-transaction-error message}
(when on-error (when on-error
{:dispatch (conj on-error message)}))))) {:dispatch (conj on-error message)}))
navigation/navigate-back))))
(defn clear-error-message [db error-type] (defn clear-error-message [db error-type]
(update-in db [:wallet :errors] dissoc error-type)) (update-in db [:wallet :errors] dissoc error-type))

View File

@ -114,7 +114,7 @@
:wallet.callback/transaction-completed :wallet.callback/transaction-completed
[(re-frame/inject-cofx :random-id-generator)] [(re-frame/inject-cofx :random-id-generator)]
(fn [{:keys [db now] :as cofx} [_ {:keys [result error]}]] (fn [{:keys [db now] :as cofx} [_ {:keys [result error]}]]
(let [{:keys [id method public-key to symbol amount-text on-result (let [{:keys [id method public-key to symbol amount-text on-result on-error
send-transaction-message?]} send-transaction-message?]}
(get-in db [:wallet :send-transaction]) (get-in db [:wallet :send-transaction])
db' (assoc-in db [:wallet :send-transaction :in-progress?] false)] db' (assoc-in db [:wallet :send-transaction :in-progress?] false)]

View File

@ -40,7 +40,7 @@
callback))) callback)))
(fx/defn call (fx/defn call
[{:keys [db] :as cofx} {:keys [contract method params callback on-result]}] [{:keys [db] :as cofx} {:keys [contract method params callback on-result on-error details]}]
(let [chain-keyword (-> (get-in db [:account/account :networks (:network db)]) (let [chain-keyword (-> (get-in db [:account/account :networks (:network db)])
ethereum/network->chain-keyword) ethereum/network->chain-keyword)
contract-address (get-in contracts [contract :address chain-keyword])] contract-address (get-in contracts [contract :address chain-keyword])]
@ -51,13 +51,15 @@
(if write? (if write?
(wallet/open-sign-transaction-flow (wallet/open-sign-transaction-flow
cofx cofx
{:to contract-address (merge {:to contract-address
:data data :data data
:id "approve" :id "approve"
:symbol :ETH :symbol :ETH
:method "eth_sendTransaction" :method "eth_sendTransaction"
:amount (money/bignumber 0) :amount (money/bignumber 0)
:on-result on-result}) :on-result on-result
:on-error on-error}
details))
{::call {:address contract-address {::call {:address contract-address
:data data :data data
:callback #(callback (if (empty? return-params) :callback #(callback (if (empty? return-params)