[refactor] transaction details
This commit is contained in:
parent
b274ed9fa9
commit
f1b8ba8764
|
@ -281,6 +281,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
|
||||
|
@ -905,23 +917,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
|
||||
|
@ -937,7 +937,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))
|
||||
|
@ -984,11 +985,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]
|
||||
|
@ -1030,12 +1026,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])
|
||||
|
@ -1112,48 +1115,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)}))))))
|
||||
(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/confirmations
|
||||
: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 ==========================================================================================================
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
@ -331,7 +330,6 @@
|
|||
:chat/access-scope->command-id
|
||||
:wallet/wallet
|
||||
:wallet/wallet.transactions
|
||||
:wallet/wallet-selected-asset
|
||||
:prices/prices
|
||||
:prices/prices-loading?
|
||||
:notifications/notifications
|
||||
|
|
|
@ -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 _]
|
||||
|
@ -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]
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -49,14 +49,18 @@
|
|||
(:postponed :pending) (transaction-icon :main-icons/arrow-right colors/gray-light colors/gray)
|
||||
(throw (str "Unknown transaction type: " k))))
|
||||
|
||||
(defn render-transaction [{:keys [hash from-contact to-contact to from type value time-formatted symbol]}
|
||||
network all-tokens hide-details?]
|
||||
(let [[label contact address
|
||||
contact-accessibility-label
|
||||
address-accessibility-label] (if (inbound? type)
|
||||
[(i18n/label :t/from) from-contact from :sender-text :sender-address-text]
|
||||
[(i18n/label :t/to) to-contact to :recipient-name-text :recipient-address-text])
|
||||
{:keys [decimals] :as token} (tokens/asset-for all-tokens (ethereum/network->chain-keyword network) symbol)]
|
||||
(defn render-transaction
|
||||
[{:keys [hash from-contact to-contact to from type value time-formatted symbol]}
|
||||
network all-tokens hide-details?]
|
||||
(let [[label contact address contact-accessibility-label
|
||||
address-accessibility-label]
|
||||
(if (inbound? type)
|
||||
[(i18n/label :t/from) from-contact from :sender-text :sender-address-text]
|
||||
[(i18n/label :t/to) to-contact to :recipient-name-text :recipient-address-text])
|
||||
{:keys [decimals] :as token}
|
||||
(tokens/asset-for all-tokens
|
||||
(ethereum/network->chain-keyword network)
|
||||
symbol)]
|
||||
[list/touchable-item #(when-not hide-details? (re-frame/dispatch [:show-transaction-details hash]))
|
||||
[react/view {:accessibility-label :transaction-item}
|
||||
[list/item
|
||||
|
@ -96,7 +100,10 @@
|
|||
(:checked? (some #(when (= (:type transaction) (:id %)) %) (:type filter-data))))
|
||||
|
||||
(defn update-transactions [m filter-data]
|
||||
(update m :data (fn [v] (filter #(filtered-transaction? % filter-data) v))))
|
||||
(update m
|
||||
:data
|
||||
(fn [v]
|
||||
(filter #(filtered-transaction? % filter-data) v))))
|
||||
|
||||
(defview history-list [& [hide-details?]]
|
||||
(letsubs [transactions-history-list [:wallet.transactions/transactions-history-list]
|
||||
|
@ -157,34 +164,26 @@
|
|||
[toolbar-view filter-data]
|
||||
[history-list]]))
|
||||
|
||||
(defn- pretty-print-asset [symbol amount token]
|
||||
(if amount
|
||||
(if (= :ETH symbol)
|
||||
(->> amount (money/wei-> :eth) money/to-fixed str)
|
||||
(-> amount (money/token->unit (:decimals token)) money/to-fixed str))
|
||||
"..."))
|
||||
|
||||
(defn details-header [network all-tokens {:keys [value date type symbol token]}]
|
||||
(let [asset (tokens/asset-for all-tokens (ethereum/network->chain-keyword network) symbol)]
|
||||
[react/view {:style styles/details-header}
|
||||
[react/view {:style styles/details-header-icon}
|
||||
(when type
|
||||
[list/item-icon (transaction-type->icon type)])]
|
||||
[react/view {:style styles/details-header-infos}
|
||||
[react/nested-text {:style styles/details-header-value}
|
||||
[{:accessibility-label :amount-text}
|
||||
(pretty-print-asset symbol value token)]
|
||||
" "
|
||||
[{:accessibility-label :currency-text}
|
||||
(wallet.utils/display-symbol asset)]]
|
||||
[react/text {:style styles/details-header-date} date]]]))
|
||||
(defn details-header
|
||||
[date type amount-text currency-text]
|
||||
[react/view {:style styles/details-header}
|
||||
[react/view {:style styles/details-header-icon}
|
||||
(when type
|
||||
[list/item-icon (transaction-type->icon type)])]
|
||||
[react/view {:style styles/details-header-infos}
|
||||
[react/nested-text {:style styles/details-header-value}
|
||||
[{:accessibility-label :amount-text} amount-text]
|
||||
" "
|
||||
[{:accessibility-label :currency-text} currency-text]]
|
||||
[react/text {:style styles/details-header-date} date]]])
|
||||
|
||||
(defn progress-bar [progress failed?]
|
||||
[react/view {:style styles/progress-bar}
|
||||
[react/view {:style (styles/progress-bar-done progress failed?)}]
|
||||
[react/view {:style (styles/progress-bar-todo (- 100 progress) failed?)}]])
|
||||
|
||||
(defn details-confirmations [confirmations confirmations-progress type]
|
||||
(defn details-confirmations
|
||||
[confirmations confirmations-progress type]
|
||||
[react/view {:style styles/details-block}
|
||||
[progress-bar confirmations-progress (failed? type)]
|
||||
(if (failed? type)
|
||||
|
@ -213,10 +212,12 @@
|
|||
[react/text (merge {:style styles/details-item-extra-value} extra-props)
|
||||
(str extra-value)]]])))
|
||||
|
||||
(defn details-list [{:keys [block hash
|
||||
from from-wallet from-contact
|
||||
to to-wallet to-contact
|
||||
gas-limit gas-price-gwei gas-price-eth gas-used cost nonce data]}]
|
||||
(defn details-list
|
||||
[{:keys [block hash
|
||||
from from-wallet from-contact
|
||||
to to-wallet to-contact
|
||||
gas-limit gas-price-gwei gas-price-eth gas-used
|
||||
cost nonce data]}]
|
||||
[react/view {:style styles/details-block}
|
||||
[details-list-row :t/block block]
|
||||
[details-list-row :t/hash hash]
|
||||
|
@ -240,15 +241,16 @@
|
|||
[details-list-row :t/data data]])
|
||||
|
||||
(defn details-action [hash url]
|
||||
[(actions/opts [{:label (i18n/label :t/copy-transaction-hash) :action #(react/copy-to-clipboard hash)}
|
||||
{:label (i18n/label :t/open-on-etherscan) :action #(.openURL react/linking url)}])])
|
||||
[(actions/opts [{:label (i18n/label :t/copy-transaction-hash)
|
||||
:action #(react/copy-to-clipboard hash)}
|
||||
{:label (i18n/label :t/open-on-etherscan)
|
||||
:action #(.openURL react/linking url)}])])
|
||||
|
||||
(defview transaction-details []
|
||||
(letsubs [{:keys [hash url type] :as transaction} [:wallet.transactions/transaction-details]
|
||||
confirmations [:wallet.transactions.details/confirmations]
|
||||
confirmations-progress [:wallet.transactions.details/confirmations-progress]
|
||||
network [:account/network]
|
||||
all-tokens [:wallet/all-tokens]]
|
||||
(letsubs [{:keys [hash url type confirmations confirmations-progress
|
||||
date amount-text currency-text]
|
||||
:as transaction}
|
||||
[:wallet.transactions.details/screen]]
|
||||
[react/view {:style components.styles/flex}
|
||||
[status-bar/status-bar]
|
||||
[toolbar/toolbar {}
|
||||
|
@ -256,7 +258,7 @@
|
|||
[toolbar/content-title (i18n/label :t/transaction-details)]
|
||||
(when transaction [toolbar/actions (details-action hash url)])]
|
||||
[react/scroll-view {:style components.styles/main-container}
|
||||
[details-header network all-tokens transaction]
|
||||
[details-header date type amount-text currency-text]
|
||||
[details-confirmations confirmations confirmations-progress type]
|
||||
[react/view {:style styles/details-separator}]
|
||||
[details-list transaction]]]))
|
||||
|
|
Loading…
Reference in New Issue