mirror of
https://github.com/status-im/status-react.git
synced 2025-02-21 15:18:41 +00:00
add unsigned transactions bindings in new wallet
This commit is contained in:
parent
498f641c8a
commit
62affda881
@ -365,7 +365,7 @@
|
|||||||
:transactions-sign "Sign"
|
:transactions-sign "Sign"
|
||||||
:transactions-sign-all "Sign all"
|
:transactions-sign-all "Sign all"
|
||||||
:transactions-sign-all-text "Sign the transaction by entering your password.\nMake sure that the words above match your secret signing phrase"
|
:transactions-sign-all-text "Sign the transaction by entering your password.\nMake sure that the words above match your secret signing phrase"
|
||||||
:transactions-sign-input-placeholder "Enter your passphrase"
|
:transactions-sign-input-placeholder "Enter your password"
|
||||||
:transactions-history "History"
|
:transactions-history "History"
|
||||||
:transactions-unsigned "Unsigned"
|
:transactions-unsigned "Unsigned"
|
||||||
:transactions-history-empty "You don't have a history transactions"
|
:transactions-history-empty "You don't have a history transactions"
|
||||||
@ -374,6 +374,8 @@
|
|||||||
:transactions-filter-tokens "Tokens"
|
:transactions-filter-tokens "Tokens"
|
||||||
:transactions-filter-type "Type"
|
:transactions-filter-type "Type"
|
||||||
:transactions-filter-select-all "Select all"
|
:transactions-filter-select-all "Select all"
|
||||||
|
:not-applicable "Not applicable for unsigned transactions"
|
||||||
|
|
||||||
;; Wallet Send
|
;; Wallet Send
|
||||||
:wallet-send-transaction "Send a Transaction"
|
:wallet-send-transaction "Send a Transaction"
|
||||||
:wallet-send-step-one "Step 1 of 3"
|
:wallet-send-step-one "Step 1 of 3"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
(ns status-im.ui.screens.wallet.transactions.subs
|
(ns status-im.ui.screens.wallet.transactions.subs
|
||||||
(:require [re-frame.core :refer [reg-sub subscribe]]
|
(:require [re-frame.core :refer [reg-sub subscribe]]
|
||||||
|
[status-im.i18n :as i18n]
|
||||||
[status-im.utils.datetime :as datetime]
|
[status-im.utils.datetime :as datetime]
|
||||||
[status-im.utils.money :as money]
|
[status-im.utils.money :as money]
|
||||||
[status-im.utils.transactions :as transactions]))
|
[status-im.utils.transactions :as transactions]))
|
||||||
@ -24,6 +25,32 @@
|
|||||||
(fn [transactions]
|
(fn [transactions]
|
||||||
(group-by :type (vals transactions))))
|
(group-by :type (vals transactions))))
|
||||||
|
|
||||||
|
(defn format-unsigned-transaction [{:keys [message-id gas-price] :as transaction}]
|
||||||
|
(-> transaction
|
||||||
|
(update :value money/wei->ether)
|
||||||
|
(assoc :type :unsigned
|
||||||
|
:confirmations 0
|
||||||
|
:symbol "ETH"
|
||||||
|
:hash message-id)))
|
||||||
|
|
||||||
|
(reg-sub :wallet.transactions/unsigned-transactions
|
||||||
|
:<- [:transactions]
|
||||||
|
(fn [transactions]
|
||||||
|
(reduce (fn [acc {:keys [message-id] :as transaction}]
|
||||||
|
(assoc acc message-id (format-unsigned-transaction transaction)))
|
||||||
|
{}
|
||||||
|
transactions)))
|
||||||
|
|
||||||
|
(reg-sub :wallet.transactions/unsigned-transactions-count
|
||||||
|
:<- [:wallet.transactions/unsigned-transactions]
|
||||||
|
(fn [unsigned-transactions]
|
||||||
|
(count unsigned-transactions)))
|
||||||
|
|
||||||
|
(reg-sub :wallet.transactions/unsigned-transactions-list
|
||||||
|
:<- [:wallet.transactions/unsigned-transactions]
|
||||||
|
(fn [unsigned-transactions]
|
||||||
|
(vals unsigned-transactions)))
|
||||||
|
|
||||||
(reg-sub :wallet.transactions/postponed-transactions-list
|
(reg-sub :wallet.transactions/postponed-transactions-list
|
||||||
:<- [:wallet.transactions/grouped-transactions]
|
:<- [:wallet.transactions/grouped-transactions]
|
||||||
(fn [{:keys [postponed]}]
|
(fn [{:keys [postponed]}]
|
||||||
@ -69,17 +96,25 @@
|
|||||||
(:current-transaction wallet)))
|
(:current-transaction wallet)))
|
||||||
|
|
||||||
(reg-sub :wallet.transactions/transaction-details
|
(reg-sub :wallet.transactions/transaction-details
|
||||||
|
:<- [:wallet.transactions/unsigned-transactions]
|
||||||
:<- [:wallet.transactions/transactions]
|
:<- [:wallet.transactions/transactions]
|
||||||
:<- [:wallet.transactions/current-transaction]
|
:<- [:wallet.transactions/current-transaction]
|
||||||
:<- [:network]
|
:<- [:network]
|
||||||
(fn [[transactions current-transaction network]]
|
(fn [[unsigned-transactions transactions current-transaction network]]
|
||||||
(let [{:keys [gas-used gas-price hash timestamp type] :as transaction} (get transactions current-transaction)]
|
(let [transactions (merge transactions unsigned-transactions)
|
||||||
|
{:keys [gas-used gas-price hash timestamp type] :as transaction} (get transactions current-transaction)]
|
||||||
(merge transaction
|
(merge transaction
|
||||||
{:cost (money/wei->ether (money/fee-value gas-used gas-price))
|
{:gas-price-eth (money/wei->str :eth gas-price)
|
||||||
:gas-price-eth (money/wei->str :eth gas-price)
|
|
||||||
:gas-price-gwei (money/wei->str :gwei gas-price)
|
:gas-price-gwei (money/wei->str :gwei gas-price)
|
||||||
:date (datetime/timestamp->long-date timestamp)
|
:date (datetime/timestamp->long-date timestamp)}
|
||||||
:url (transactions/get-transaction-details-url network hash)}
|
(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)}
|
||||||
|
{:cost (money/wei->str :eth (money/fee-value gas-used gas-price))
|
||||||
|
:url (transactions/get-transaction-details-url network hash)})
|
||||||
;; TODO (yenda) proper wallet logic when wallet switching is impletmented
|
;; TODO (yenda) proper wallet logic when wallet switching is impletmented
|
||||||
(if (= type :inbound)
|
(if (= type :inbound)
|
||||||
{:to-wallet "Main wallet"}
|
{:to-wallet "Main wallet"}
|
||||||
|
@ -20,39 +20,60 @@
|
|||||||
(utils/show-popup "TODO" "Not implemented yet!"))
|
(utils/show-popup "TODO" "Not implemented yet!"))
|
||||||
|
|
||||||
(defn on-sign-transaction
|
(defn on-sign-transaction
|
||||||
[m]
|
[password]
|
||||||
;; TODO(yenda) implement
|
;; TODO(yenda) implement
|
||||||
(utils/show-popup "TODO" "Sign Transaction"))
|
(re-frame/dispatch [:accept-transactions password]))
|
||||||
|
|
||||||
(defn on-delete-transaction
|
(defn on-delete-transaction
|
||||||
[m]
|
[m]
|
||||||
;; TODO(yenda) implement
|
;; TODO(yenda) implement
|
||||||
(utils/show-popup "TODO" "Delete Transaction"))
|
(utils/show-popup "TODO" "Delete Transaction"))
|
||||||
|
|
||||||
(defn unsigned-action []
|
(defn unsigned-action [unsigned-transactions-count]
|
||||||
;; TODO subscribe to unsigned-transactions-count or pass it as parameter ?
|
[toolbar/text-action {:disabled? (zero? unsigned-transactions-count)
|
||||||
[toolbar/text-action {:disabled? (zero? 0 #_(count unsigned-transactions)) :handler #(re-frame/dispatch [:navigate-to-modal :wallet-transactions-sign-all])}
|
:handler #(re-frame/dispatch [:navigate-to-modal :wallet-transactions-sign-all])}
|
||||||
(i18n/label :t/transactions-sign-all)])
|
(i18n/label :t/transactions-sign-all)])
|
||||||
|
|
||||||
(def history-action
|
(def history-action
|
||||||
{:icon :icons/filter
|
{:icon :icons/filter
|
||||||
:handler #(utils/show-popup "TODO" "Not implemented") #_(re-frame/dispatch [:navigate-to-modal :wallet-transactions-sign-all])})
|
:handler #(utils/show-popup "TODO" "Not implemented") #_(re-frame/dispatch [:navigate-to-modal :wallet-transactions-sign-all])})
|
||||||
|
|
||||||
(defn toolbar-view [view-id]
|
(defn toolbar-view [view-id unsigned-transactions-count]
|
||||||
[toolbar/toolbar2 {:flat? true}
|
[toolbar/toolbar2 {:flat? true}
|
||||||
toolbar/default-nav-back
|
toolbar/default-nav-back
|
||||||
[toolbar/content-title (i18n/label :t/transactions)]
|
[toolbar/content-title (i18n/label :t/transactions)]
|
||||||
(case @view-id
|
(case @view-id
|
||||||
:wallet-transactions-unsigned
|
:wallet-transactions-unsigned
|
||||||
[unsigned-action]
|
[unsigned-action unsigned-transactions-count]
|
||||||
|
|
||||||
:wallet-transactions-history
|
:wallet-transactions-history
|
||||||
[toolbar/actions
|
[toolbar/actions
|
||||||
[history-action]])])
|
[history-action]])])
|
||||||
|
|
||||||
|
;; Sign all
|
||||||
|
|
||||||
|
(defview sign-all []
|
||||||
|
[]
|
||||||
|
[react/keyboard-avoiding-view {:style transactions.styles/sign-all-view}
|
||||||
|
[react/view {:style transactions.styles/sign-all-done}
|
||||||
|
[button/primary-button {:style transactions.styles/sign-all-done-button
|
||||||
|
:text (i18n/label :t/done)
|
||||||
|
:on-press #(re-frame/dispatch [:navigate-back])}]]
|
||||||
|
[react/view {:style transactions.styles/sign-all-popup}
|
||||||
|
[react/text {:style transactions.styles/sign-all-popup-sign-phrase} "one two three"] ;; TODO hook
|
||||||
|
[react/text {:style transactions.styles/sign-all-popup-text} (i18n/label :t/transactions-sign-all-text)]
|
||||||
|
[react/view {:style transactions.styles/sign-all-actions}
|
||||||
|
[react/text-input {:style transactions.styles/sign-all-input
|
||||||
|
:secure-text-entry true
|
||||||
|
:placeholder (i18n/label :t/transactions-sign-input-placeholder)}]
|
||||||
|
[button/primary-button {:text (i18n/label :t/transactions-sign-all) :on-press #(println %)}]]]])
|
||||||
|
|
||||||
|
|
||||||
(defn action-buttons [m]
|
(defn action-buttons [m]
|
||||||
[react/view {:style transactions.styles/action-buttons}
|
[react/view {:style transactions.styles/action-buttons}
|
||||||
[button/primary-button {:text (i18n/label :t/transactions-sign) :on-press #(on-sign-transaction m)}]
|
[button/primary-button {:text (i18n/label :t/transactions-sign)
|
||||||
|
|
||||||
|
:on-press #(re-frame/dispatch [:navigate-to-modal :wallet-transactions-sign-all])}]
|
||||||
[button/secondary-button {:text (i18n/label :t/delete) :on-press #(on-delete-transaction m)}]])
|
[button/secondary-button {:text (i18n/label :t/delete) :on-press #(on-delete-transaction m)}]])
|
||||||
|
|
||||||
(defn- inbound? [type] (= "inbound" type))
|
(defn- inbound? [type] (= "inbound" type))
|
||||||
@ -103,45 +124,24 @@
|
|||||||
:refreshing (boolean transactions-loading?)}]]))
|
:refreshing (boolean transactions-loading?)}]]))
|
||||||
|
|
||||||
(defview unsigned-list []
|
(defview unsigned-list []
|
||||||
[]
|
(letsubs [transactions [:wallet.transactions/unsigned-transactions-list]]
|
||||||
(let [transactions nil] ;; TODO replace by letsubs later
|
|
||||||
[react/view {:style styles/flex}
|
[react/view {:style styles/flex}
|
||||||
[list/flat-list {:data transactions
|
[list/flat-list {:data transactions
|
||||||
:render-fn render-transaction
|
:render-fn render-transaction
|
||||||
:empty-component (empty-text (i18n/label :t/transactions-unsigned-empty))}]]))
|
:empty-component (empty-text (i18n/label :t/transactions-unsigned-empty))}]]))
|
||||||
|
|
||||||
(defn- unsigned-transactions-title []
|
(defn- unsigned-transactions-title [unsigned-transactions-count]
|
||||||
;; TODO subscribe to unsigned-transactions-count or pass it as parameter ?
|
|
||||||
(let [count 0 #_(count transactions)]
|
|
||||||
(str (i18n/label :t/transactions-unsigned)
|
(str (i18n/label :t/transactions-unsigned)
|
||||||
(if (pos? count) (str " " count)))))
|
(if (pos? unsigned-transactions-count) (str " " unsigned-transactions-count))))
|
||||||
|
|
||||||
(defn- tab-list []
|
(defn- tab-list [unsigned-transactions-count]
|
||||||
[{:view-id :wallet-transactions-history
|
[{:view-id :wallet-transactions-history
|
||||||
:title (i18n/label :t/transactions-history)
|
:title (i18n/label :t/transactions-history)
|
||||||
:screen [history-list]}
|
:screen [history-list]}
|
||||||
{:view-id :wallet-transactions-unsigned
|
{:view-id :wallet-transactions-unsigned
|
||||||
:title (unsigned-transactions-title)
|
:title (unsigned-transactions-title unsigned-transactions-count)
|
||||||
:screen [unsigned-list]}])
|
:screen [unsigned-list]}])
|
||||||
|
|
||||||
;; Sign all
|
|
||||||
|
|
||||||
(defview sign-all []
|
|
||||||
[]
|
|
||||||
[react/keyboard-avoiding-view {:style transactions.styles/sign-all-view}
|
|
||||||
[react/view {:style transactions.styles/sign-all-done}
|
|
||||||
[button/primary-button {:style transactions.styles/sign-all-done-button
|
|
||||||
:text (i18n/label :t/done)
|
|
||||||
:on-press #(re-frame/dispatch [:navigate-back])}]]
|
|
||||||
[react/view {:style transactions.styles/sign-all-popup}
|
|
||||||
[react/text {:style transactions.styles/sign-all-popup-sign-phrase} "one two three"] ;; TODO hook
|
|
||||||
[react/text {:style transactions.styles/sign-all-popup-text} (i18n/label :t/transactions-sign-all-text)]
|
|
||||||
[react/view {:style transactions.styles/sign-all-actions}
|
|
||||||
[react/text-input {:style transactions.styles/sign-all-input
|
|
||||||
:secure-text-entry true
|
|
||||||
:placeholder (i18n/label :t/transactions-sign-input-placeholder)}]
|
|
||||||
[button/primary-button {:text (i18n/label :t/transactions-sign-all) :on-press #(on-sign-transaction %)}]]]])
|
|
||||||
|
|
||||||
;; Filter history
|
;; Filter history
|
||||||
|
|
||||||
(defn- item-tokens [{:keys [symbol label checked?]}]
|
(defn- item-tokens [{:keys [symbol label checked?]}]
|
||||||
@ -195,13 +195,14 @@
|
|||||||
;; TODO(yenda) must reflect selected wallet
|
;; TODO(yenda) must reflect selected wallet
|
||||||
|
|
||||||
(defview transactions []
|
(defview transactions []
|
||||||
(let [tabs (tab-list)
|
(letsubs [unsigned-transactions-count [:wallet.transactions/unsigned-transactions-count]]
|
||||||
|
(let [tabs (tab-list unsigned-transactions-count)
|
||||||
default-view (get-in tabs [0 :view-id])
|
default-view (get-in tabs [0 :view-id])
|
||||||
view-id (reagent/atom default-view)]
|
view-id (reagent/atom default-view)]
|
||||||
[react/view {:style styles/flex}
|
[react/view {:style styles/flex}
|
||||||
[status-bar/status-bar]
|
[status-bar/status-bar]
|
||||||
[toolbar-view view-id]
|
[toolbar-view view-id unsigned-transactions-count]
|
||||||
[main-section view-id tabs]]))
|
[main-section view-id tabs]])))
|
||||||
|
|
||||||
(defn transaction-details-header [{:keys [value date type]}]
|
(defn transaction-details-header [{:keys [value date type]}]
|
||||||
[react/view {:style transactions.styles/transaction-details-header}
|
[react/view {:style transactions.styles/transaction-details-header}
|
||||||
@ -243,7 +244,7 @@
|
|||||||
[transaction-details-list-row :t/gas-limit gas-limit]
|
[transaction-details-list-row :t/gas-limit gas-limit]
|
||||||
[transaction-details-list-row :t/gas-price gas-price-gwei gas-price-eth]
|
[transaction-details-list-row :t/gas-price gas-price-gwei gas-price-eth]
|
||||||
[transaction-details-list-row :t/gas-used gas-used]
|
[transaction-details-list-row :t/gas-used gas-used]
|
||||||
[transaction-details-list-row :t/cost-fee (str cost " ETH")]
|
[transaction-details-list-row :t/cost-fee cost]
|
||||||
[transaction-details-list-row :t/nonce nonce]
|
[transaction-details-list-row :t/nonce nonce]
|
||||||
[transaction-details-list-row :t/data data]])
|
[transaction-details-list-row :t/data data]])
|
||||||
|
|
||||||
@ -252,7 +253,7 @@
|
|||||||
{:text (i18n/label :t/open-on-etherscan) :value #(.openURL react/linking url)}])])
|
{:text (i18n/label :t/open-on-etherscan) :value #(.openURL react/linking url)}])])
|
||||||
|
|
||||||
(defview transaction-details []
|
(defview transaction-details []
|
||||||
(letsubs [{:keys [hash url] :as transaction-details} [:wallet.transactions/transaction-details]
|
(letsubs [{:keys [hash url type] :as transaction-details} [:wallet.transactions/transaction-details]
|
||||||
confirmations [:wallet.transactions.details/confirmations]
|
confirmations [:wallet.transactions.details/confirmations]
|
||||||
confirmations-progress [:wallet.transactions.details/confirmations-progress]]
|
confirmations-progress [:wallet.transactions.details/confirmations-progress]]
|
||||||
[react/view {:style styles/flex}
|
[react/view {:style styles/flex}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user