fix pending transactions

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2020-01-10 15:42:00 +01:00
parent 48d3087f81
commit 1cac8f1161
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
5 changed files with 27 additions and 31 deletions

View File

@ -48,7 +48,7 @@
chain (ethereum/chain-keyword db)
chain-tokens (into {} (map (juxt :address identity)
(tokens/tokens-for all-tokens chain)))]
{:db (update-in db [:wallet :transactions]
{:db (update-in db [:wallet :accounts]
wallet/remove-transactions-since-block block-number)
::transactions/get-transfers {:chain-tokens chain-tokens
:from-block block-number}}))

View File

@ -113,8 +113,12 @@
(fx/defn check-watched-transactions
[{:keys [db] :as cofx}]
(let [watched-transactions
(select-keys (get-in db [:wallet :transactions])
(keys (get db :ethereum/watched-transactions)))]
(reduce-kv (fn [acc _ {:keys [transactions]}]
(merge acc
(select-keys transactions
(keys (get db :ethereum/watched-transactions)))))
{}
(get-in db [:wallet :accounts]))]
(apply fx/merge
cofx
(map (fn [[_ transaction]]
@ -151,12 +155,6 @@
transfers)))))]
(apply fx/merge cofx effects)))
(fx/defn handle-token-history
[{:keys [db]} transactions]
{:db (update-in db
[:wallet :transactions]
merge transactions)})
(re-frame/reg-fx
::get-transfers
(fn [{:keys [chain-tokens from-block to-block historical?]

View File

@ -1430,16 +1430,6 @@
(fn [cofx [_ id handler]]
(ethereum.subscriptions/register-subscription cofx id handler)))
(handlers/register-handler-fx
:ethereum.transactions.callback/etherscan-error
(fn [cofx [event error]]
(log/info event error)))
(handlers/register-handler-fx
:ethereum.transactions.callback/fetch-token-history-success
(fn [cofx [_ transactions]]
(ethereum.transactions/handle-token-history cofx transactions)))
;; wallet events
(handlers/register-handler-fx

View File

@ -96,11 +96,10 @@
:cb #(re-frame/dispatch [:signing/transaction-completed % tx-obj-to-send])}})))))
(fx/defn prepare-unconfirmed-transaction
[{:keys [db now]} hash {:keys [value gasPrice gas data to from]} symbol]
[{:keys [db now]} hash {:keys [value gasPrice gas data to from]} symbol amount]
(let [all-tokens (:wallet/all-tokens db)
chain (:chain db)
token (tokens/symbol->token all-tokens (keyword chain) symbol)]
{:db (assoc-in db [:wallet :transactions hash]
token (tokens/symbol->token all-tokens (ethereum/chain-keyword db) symbol)]
{:db (assoc-in db [:wallet :accounts from :transactions hash]
{:timestamp (str now)
:to to
:from from
@ -109,7 +108,9 @@
:data data
:token token
:symbol symbol
:value (money/to-fixed (money/bignumber value))
:value (if token
(money/unit->token amount (:decimals token))
(money/to-fixed (money/bignumber value)))
:gas-price (money/to-fixed (money/bignumber gasPrice))
:gas-limit (money/to-fixed (money/bignumber gas))})}))
@ -204,11 +205,11 @@
(fx/defn transaction-result
[{:keys [db] :as cofx} result tx-obj]
(let [{:keys [on-result symbol]} (get db :signing/tx)]
(let [{:keys [on-result symbol amount]} (get db :signing/tx)]
(fx/merge cofx
{:db (dissoc db :signing/tx :signing/in-progress? :signing/sign)
:signing/show-transaction-result nil}
(prepare-unconfirmed-transaction result tx-obj symbol)
(prepare-unconfirmed-transaction result tx-obj symbol amount)
(check-queue)
#(when on-result
{:dispatch (conj on-result result)}))))

View File

@ -71,8 +71,15 @@
0))
(defn remove-transactions-since-block
[transactions block]
(into empty-transaction-map
(drop-while (fn [[k v]]
(>= (int (:block v)) block))
transactions)))
[accounts block]
(reduce-kv (fn [acc account-address {:keys [transactions] :as account}]
(assoc acc account-address
(update account
:transactions
(fn [transactions]
(into empty-transaction-map
(drop-while (fn [[k v]]
(>= (int (:block v)) block))
transactions))))))
{}
accounts))