Skip to content

Commit

Permalink
[refactor] transaction details
Browse files Browse the repository at this point in the history
  • Loading branch information
yenda committed May 17, 2019
1 parent 961219a commit 8d41cbb
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 111 deletions.
146 changes: 85 additions & 61 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,18 @@
(-> selected-participants
(contains? element))))

(re-frame/reg-sub
:ethereum/chain-keyword
:<- [:network]
(fn [network]
(ethereum/network->chain-keyword network)))

(re-frame/reg-sub
:ethereum/native-currency
:<- [:ethereum/chain-keyword]
(fn [chain-keyword]
(tokens/native-currency chain-keyword)))

;;ACCOUNT ==============================================================================================================

(re-frame/reg-sub
Expand Down Expand Up @@ -903,23 +915,11 @@
(fn [prices [_ fsym tsym]]
(get-in prices [fsym tsym :last-day])))

(re-frame/reg-sub
:wallet-transactions
:<- [:wallet]
(fn [wallet]
(get wallet :transactions)))

(re-frame/reg-sub
:wallet.settings/currency
:<- [:account-settings]
(fn [sett]
(or (get-in sett [:wallet :currency]) :usd)))

(re-frame/reg-sub
:wallet.transactions/filters
:<- [:wallet.transactions]
(fn [txs]
(get txs :filters)))
(fn [settings]
(or (get-in settings [:wallet :currency]) :usd)))

(re-frame/reg-sub
:asset-value
Expand All @@ -935,7 +935,8 @@
str
(i18n/format-currency (:code currency))))))

(defn- get-balance-total-value [balance prices currency token->decimals]
(defn- get-balance-total-value
[balance prices currency token->decimals]
(reduce-kv (fn [acc symbol value]
(if-let [price (get-in prices [symbol currency :price])]
(+ acc (or (some-> (money/internal->formatted value symbol (token->decimals symbol))
Expand Down Expand Up @@ -982,11 +983,6 @@
(or (get-in wallet [:errors :balance-update])
(get-in wallet [:errors :prices-update]))))

(re-frame/reg-sub
:get-wallet-unread-messages-number
(fn [db]
0))

(re-frame/reg-sub
:wallet/visible-tokens-symbols
:<- [:network]
Expand Down Expand Up @@ -1028,12 +1024,19 @@
;;WALLET TRANSACTIONS ==================================================================================================

(re-frame/reg-sub
:wallet.transactions/current-tab
:wallet-transactions
:<- [:wallet]
(fn [wallet]
(get wallet :current-tab 0)))
(get wallet :transactions)))

(defn enrich-transaction [{:keys [type to from timestamp] :as transaction} contacts]
(re-frame/reg-sub
:wallet.transactions/filters
:<- [:wallet.transactions]
(fn [txs]
(get txs :filters)))

(defn enrich-transaction
[{:keys [type to from timestamp] :as transaction} contacts]
(let [[contact-address key-contact key-wallet] (if (= type :inbound)
[from :from-contact :to-wallet]
[to :to-contact :from-wallet])
Expand Down Expand Up @@ -1110,48 +1113,69 @@
(:current-transaction wallet)))

(re-frame/reg-sub
:wallet.transactions/transaction-details
:wallet.transactions.details/current-transaction
:<- [:wallet.transactions/transactions]
:<- [:wallet.transactions/current-transaction]
:<- [:network]
(fn [[transactions current-transaction network]]
(let [{:keys [gas-used gas-price hash timestamp type] :as transaction} (get transactions current-transaction)
chain (ethereum/network->chain-keyword network)
native-currency (tokens/native-currency chain)
display-unit (wallet.utils/display-symbol native-currency)]
:<- [:ethereum/native-currency]
:<- [:ethereum/chain-keyword]
(fn [[transactions current-transaction native-currency chain-keyword]]
(let [{:keys [gas-used gas-price hash timestamp type token value]
:as transaction}
(get transactions current-transaction)]
(when transaction
(merge transaction
{:gas-price-eth (if gas-price (money/wei->str :eth gas-price display-unit) "-")
:gas-price-gwei (if gas-price (money/wei->str :gwei gas-price) "-")
:date (datetime/timestamp->long-date timestamp)}
(if (= type :unsigned)
{:block (i18n/label :not-applicable)
:cost (i18n/label :not-applicable)
:gas-limit (i18n/label :not-applicable)
:gas-used (i18n/label :not-applicable)
:nonce (i18n/label :not-applicable)
:hash (i18n/label :not-applicable)}
{:cost (when gas-used
(money/wei->str :eth (money/fee-value gas-used gas-price) display-unit))
:url (transactions.etherscan/get-transaction-details-url chain hash)}))))))

(re-frame/reg-sub
:wallet.transactions.details/confirmations
(let [{:keys [symbol-display symbol decimals] :as asset}
(or token native-currency)
amount-text (if value
(wallet.utils/format-amount value decimals)
"...")
currency-text (when asset
(clojure.core/name (or symbol-display symbol)))
native-currency-text (-> native-currency
:symbol-display
name)]
(merge transaction
{:amount-text amount-text
:currency-text currency-text
:gas-price-eth (if gas-price
(money/wei->str :eth
gas-price
native-currency-text)
"-")
:gas-price-gwei (if gas-price
(money/wei->str :gwei
gas-price)
"-")
:date (datetime/timestamp->long-date timestamp)}
(if (= type :unsigned)
{:block (i18n/label :not-applicable)
:cost (i18n/label :not-applicable)
:gas-limit (i18n/label :not-applicable)
:gas-used (i18n/label :not-applicable)
:nonce (i18n/label :not-applicable)
:hash (i18n/label :not-applicable)}
{:cost (when gas-used
(money/wei->str :eth
(money/fee-value gas-used gas-price)
native-currency-text))
:url (transactions.etherscan/get-transaction-details-url
chain-keyword
hash)})))))))

(re-frame/reg-sub
:wallet.transactions.details/screen
:<- [:wallet.transactions.details/current-transaction]
:<- [:ethereum/current-block]
:<- [:wallet.transactions/transaction-details]
(fn [[current-block {:keys [block]}]]
(if (and current-block block)
(inc (- current-block block))
0)))

(re-frame/reg-sub
:wallet.transactions.details/confirmations-progress
:<- [:wallet.transactions.details/confirmations]
(fn [confirmations]
(let [max-confirmations 10]
(if (>= confirmations max-confirmations)
100
(* 100 (/ confirmations max-confirmations))))))
(fn [[{:keys [block] :as transaction} current-block]]
:wallet.transactions.details/current-transaction
(let [confirmations (if (and current-block block)
(inc (- current-block block))
0)]
(assoc transaction
:confirmations confirmations
:confirmations-progress
(if (>= confirmations transactions/confirmations-count-threshold)
100
(* 100 (/ confirmations transactions/confirmations-count-threshold)))))))

;;WALLET SEND ==========================================================================================================

Expand Down
1 change: 0 additions & 1 deletion src/status_im/ui/components/bottom_bar/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
{:nav-stack :wallet-stack
:content {:title (i18n/label :t/wallet)
:icon :main-icons/wallet}
:count-subscription :get-wallet-unread-messages-number
:accessibility-label :wallet-tab-button})
{:nav-stack :profile-stack
:content {:title (i18n/label :t/profile)
Expand Down
2 changes: 0 additions & 2 deletions src/status_im/ui/screens/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
:sync-state :done
:app-state "active"
:wallet.transactions constants/default-wallet-transactions
:wallet-selected-asset {}
:wallet/all-tokens {}
:prices {}
:peers-count 0
Expand Down Expand Up @@ -328,7 +327,6 @@
:chat/access-scope->command-id
:wallet/wallet
:wallet/wallet.transactions
:wallet/wallet-selected-asset
:prices/prices
:prices/prices-loading?
:notifications/notifications
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/ui/screens/wallet/navigation.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(re-frame/dispatch [:wallet.ui/pull-to-refresh])
(re-frame/dispatch [:update-wallet]))
500)
(assoc-in db [:wallet :current-tab] 0))
db)

(defmethod navigation/preload-data! :wallet-stack
[db _]
Expand All @@ -24,7 +24,7 @@
(re-frame/dispatch [:wallet.ui/pull-to-refresh])
(re-frame/dispatch [:update-wallet]))
500)
(assoc-in db [:wallet :current-tab] 0))
db)

(def transaction-send-default
(let [symbol :ETH]
Expand Down
14 changes: 12 additions & 2 deletions src/status_im/ui/screens/wallet/transactions/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
(:require [status-im.utils.handlers :as handlers]))

(defn- mark-all-checked [filters]
(update filters :type #(map (fn [m] (assoc m :checked? true)) %)))
(update filters
:type
#(map (fn [m]
(assoc m :checked? true))
%)))

(defn- mark-checked [filters {:keys [type]} checked?]
(update filters :type #(map (fn [{:keys [id] :as m}] (if (= type id) (assoc m :checked? checked?) m)) %)))
(update filters
:type
#(map (fn [{:keys [id] :as m}]
(if (= type id)
(assoc m :checked? checked?)
m))
%)))

(defn- update-filters [db f]
(update-in db [:wallet.transactions :filters] f))
Expand Down
Loading

0 comments on commit 8d41cbb

Please sign in to comment.