[#10105] Add set max to Send transaction

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2020-06-25 15:17:35 +02:00
parent 7f4476b253
commit 24114f7fe8
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
9 changed files with 200 additions and 138 deletions

View File

@ -14,7 +14,7 @@
"eth_getBalance" "eth_getBalance"
{:on-result money/bignumber} {:on-result money/bignumber}
"eth_estimateGas" "eth_estimateGas"
{:on-result #(money/bignumber (int (* % 1.2)))} {:on-result #(money/bignumber (if (= (int %) 21000) % (int (* % 1.2))))}
"eth_gasPrice" "eth_gasPrice"
{:on-result money/bignumber} {:on-result money/bignumber}
"eth_getBlockByHash" "eth_getBlockByHash"

View File

@ -370,77 +370,73 @@
"Formats an amount of a currency based on the currency pattern "Formats an amount of a currency based on the currency pattern
If currency-symbol? is false, the currency symbol is excluded from the If currency-symbol? is false, the currency symbol is excluded from the
formatting" formatting"
([value currency-code] [value currency-code]
(format-currency value currency-code true)) (.addTier2Support ^js goog.i18n.currency)
([value currency-code currency-symbol?] (let [currency-code-to-nfs-map {"ZAR" ^js goog.i18n.NumberFormatSymbols_af
(.addTier2Support ^js goog.i18n.currency) "ETB" ^js goog.i18n.NumberFormatSymbols_am
(let [currency-code-to-nfs-map {"ZAR" ^js goog.i18n.NumberFormatSymbols_af "EGP" ^js goog.i18n.NumberFormatSymbols_ar
"ETB" ^js goog.i18n.NumberFormatSymbols_am "DZD" ^js goog.i18n.NumberFormatSymbols_ar_DZ
"EGP" ^js goog.i18n.NumberFormatSymbols_ar "AZN" ^js goog.i18n.NumberFormatSymbols_az
"DZD" ^js goog.i18n.NumberFormatSymbols_ar_DZ "BYN" ^js goog.i18n.NumberFormatSymbols_be
"AZN" ^js goog.i18n.NumberFormatSymbols_az "BGN" ^js goog.i18n.NumberFormatSymbols_bg
"BYN" ^js goog.i18n.NumberFormatSymbols_be "BDT" ^js goog.i18n.NumberFormatSymbols_bn
"BGN" ^js goog.i18n.NumberFormatSymbols_bg "EUR" ^js goog.i18n.NumberFormatSymbols_br
"BDT" ^js goog.i18n.NumberFormatSymbols_bn "BAM" ^js goog.i18n.NumberFormatSymbols_bs
"EUR" ^js goog.i18n.NumberFormatSymbols_br "USD" ^js goog.i18n.NumberFormatSymbols_en
"BAM" ^js goog.i18n.NumberFormatSymbols_bs "CZK" ^js goog.i18n.NumberFormatSymbols_cs
"USD" ^js goog.i18n.NumberFormatSymbols_en "GBP" ^js goog.i18n.NumberFormatSymbols_cy
"CZK" ^js goog.i18n.NumberFormatSymbols_cs "DKK" ^js goog.i18n.NumberFormatSymbols_da
"GBP" ^js goog.i18n.NumberFormatSymbols_cy "CHF" ^js goog.i18n.NumberFormatSymbols_de_CH
"DKK" ^js goog.i18n.NumberFormatSymbols_da "AUD" ^js goog.i18n.NumberFormatSymbols_en_AU
"CHF" ^js goog.i18n.NumberFormatSymbols_de_CH "CAD" ^js goog.i18n.NumberFormatSymbols_en_CA
"AUD" ^js goog.i18n.NumberFormatSymbols_en_AU "INR" ^js goog.i18n.NumberFormatSymbols_en_IN
"CAD" ^js goog.i18n.NumberFormatSymbols_en_CA "SGD" ^js goog.i18n.NumberFormatSymbols_en_SG
"INR" ^js goog.i18n.NumberFormatSymbols_en_IN "MXN" ^js goog.i18n.NumberFormatSymbols_es_419
"SGD" ^js goog.i18n.NumberFormatSymbols_en_SG "IRR" ^js goog.i18n.NumberFormatSymbols_fa
"MXN" ^js goog.i18n.NumberFormatSymbols_es_419 "PHP" ^js goog.i18n.NumberFormatSymbols_fil
"IRR" ^js goog.i18n.NumberFormatSymbols_fa "ILS" ^js goog.i18n.NumberFormatSymbols_he
"PHP" ^js goog.i18n.NumberFormatSymbols_fil "HRK" ^js goog.i18n.NumberFormatSymbols_hr
"ILS" ^js goog.i18n.NumberFormatSymbols_he "HUF" ^js goog.i18n.NumberFormatSymbols_hu
"HRK" ^js goog.i18n.NumberFormatSymbols_hr "AMD" ^js goog.i18n.NumberFormatSymbols_hy
"HUF" ^js goog.i18n.NumberFormatSymbols_hu "IDR" ^js goog.i18n.NumberFormatSymbols_id
"AMD" ^js goog.i18n.NumberFormatSymbols_hy "ISK" ^js goog.i18n.NumberFormatSymbols_is
"IDR" ^js goog.i18n.NumberFormatSymbols_id "JPY" ^js goog.i18n.NumberFormatSymbols_ja
"ISK" ^js goog.i18n.NumberFormatSymbols_is "GEL" ^js goog.i18n.NumberFormatSymbols_ka
"JPY" ^js goog.i18n.NumberFormatSymbols_ja "KZT" ^js goog.i18n.NumberFormatSymbols_kk
"GEL" ^js goog.i18n.NumberFormatSymbols_ka "KHR" ^js goog.i18n.NumberFormatSymbols_km
"KZT" ^js goog.i18n.NumberFormatSymbols_kk "KRW" ^js goog.i18n.NumberFormatSymbols_ko
"KHR" ^js goog.i18n.NumberFormatSymbols_km "KGS" ^js goog.i18n.NumberFormatSymbols_ky
"KRW" ^js goog.i18n.NumberFormatSymbols_ko "CDF" ^js goog.i18n.NumberFormatSymbols_ln
"KGS" ^js goog.i18n.NumberFormatSymbols_ky "LAK" ^js goog.i18n.NumberFormatSymbols_lo
"CDF" ^js goog.i18n.NumberFormatSymbols_ln "MKD" ^js goog.i18n.NumberFormatSymbols_mk
"LAK" ^js goog.i18n.NumberFormatSymbols_lo "MNT" ^js goog.i18n.NumberFormatSymbols_mn
"MKD" ^js goog.i18n.NumberFormatSymbols_mk "MDL" ^js goog.i18n.NumberFormatSymbols_mo
"MNT" ^js goog.i18n.NumberFormatSymbols_mn "MYR" ^js goog.i18n.NumberFormatSymbols_ms
"MDL" ^js goog.i18n.NumberFormatSymbols_mo "MMK" ^js goog.i18n.NumberFormatSymbols_my
"MYR" ^js goog.i18n.NumberFormatSymbols_ms "NOK" ^js goog.i18n.NumberFormatSymbols_nb
"MMK" ^js goog.i18n.NumberFormatSymbols_my "NPR" ^js goog.i18n.NumberFormatSymbols_ne
"NOK" ^js goog.i18n.NumberFormatSymbols_nb "PLN" ^js goog.i18n.NumberFormatSymbols_pl
"NPR" ^js goog.i18n.NumberFormatSymbols_ne "BRL" ^js goog.i18n.NumberFormatSymbols_pt
"PLN" ^js goog.i18n.NumberFormatSymbols_pl "RON" ^js goog.i18n.NumberFormatSymbols_ro
"BRL" ^js goog.i18n.NumberFormatSymbols_pt "RUB" ^js goog.i18n.NumberFormatSymbols_ru
"RON" ^js goog.i18n.NumberFormatSymbols_ro "RSD" ^js goog.i18n.NumberFormatSymbols_sh
"RUB" ^js goog.i18n.NumberFormatSymbols_ru "LKR" ^js goog.i18n.NumberFormatSymbols_si
"RSD" ^js goog.i18n.NumberFormatSymbols_sh "ALL" ^js goog.i18n.NumberFormatSymbols_sq
"LKR" ^js goog.i18n.NumberFormatSymbols_si "SEK" ^js goog.i18n.NumberFormatSymbols_sv
"ALL" ^js goog.i18n.NumberFormatSymbols_sq "TZS" ^js goog.i18n.NumberFormatSymbols_sw
"SEK" ^js goog.i18n.NumberFormatSymbols_sv "THB" ^js goog.i18n.NumberFormatSymbols_th
"TZS" ^js goog.i18n.NumberFormatSymbols_sw "TRY" ^js goog.i18n.NumberFormatSymbols_tr
"THB" ^js goog.i18n.NumberFormatSymbols_th "UAH" ^js goog.i18n.NumberFormatSymbols_uk
"TRY" ^js goog.i18n.NumberFormatSymbols_tr "PKR" ^js goog.i18n.NumberFormatSymbols_ur
"UAH" ^js goog.i18n.NumberFormatSymbols_uk "UZS" ^js goog.i18n.NumberFormatSymbols_uz
"PKR" ^js goog.i18n.NumberFormatSymbols_ur "VND" ^js goog.i18n.NumberFormatSymbols_vi
"UZS" ^js goog.i18n.NumberFormatSymbols_uz "CNY" ^js goog.i18n.NumberFormatSymbols_zh
"VND" ^js goog.i18n.NumberFormatSymbols_vi "HKD" ^js goog.i18n.NumberFormatSymbols_zh_HK
"CNY" ^js goog.i18n.NumberFormatSymbols_zh "TWD" ^js goog.i18n.NumberFormatSymbols_zh_TW}
"HKD" ^js goog.i18n.NumberFormatSymbols_zh_HK nfs (or (get currency-code-to-nfs-map currency-code)
"TWD" ^js goog.i18n.NumberFormatSymbols_zh_TW} ^js goog.i18n.NumberFormatSymbols_en)]
nfs (or (get currency-code-to-nfs-map currency-code) (.format
^js goog.i18n.NumberFormatSymbols_en)] ^js (new ^js goog.i18n.NumberFormat
(.format (let [pattern (.-CURRENCY_PATTERN ^js nfs)]
^js (new ^js goog.i18n.NumberFormat (string/replace pattern #"\s*¤\s*" "")))
(let [pattern (.-CURRENCY_PATTERN ^js nfs)] value)))
(if currency-symbol?
pattern
(string/replace pattern #"\s*¤\s*" ""))))
value))))

View File

@ -207,7 +207,7 @@
(prices/update-prices) (prices/update-prices)
#(when-not gas #(when-not gas
{:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true) {:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true)
:signing/update-estimated-gas {:obj tx-obj :signing/update-estimated-gas {:obj (dissoc tx-obj :gasPrice)
:success-event :signing/update-estimated-gas-success :success-event :signing/update-estimated-gas-success
:error-event :signing/update-estimated-gas-error}}) :error-event :signing/update-estimated-gas-error}})
#(when-not gasPrice #(when-not gasPrice

View File

@ -1077,7 +1077,7 @@
(-> balance-total-value (-> balance-total-value
(money/with-precision 2) (money/with-precision 2)
str str
(i18n/format-currency (:code currency) false)) (i18n/format-currency (:code currency)))
"0")) "0"))
"..."))) "...")))
@ -1096,7 +1096,7 @@
(-> balance-total-value (-> balance-total-value
(money/with-precision 2) (money/with-precision 2)
str str
(i18n/format-currency (:code currency) false)) (i18n/format-currency (:code currency)))
"0")) "0"))
"..."))) "...")))
@ -1182,7 +1182,7 @@
(money/crypto->fiat price) (money/crypto->fiat price)
(money/with-precision 2) (money/with-precision 2)
str str
(i18n/format-currency (:code currency) false))))))) (i18n/format-currency (:code currency))))))))
(re-frame/reg-sub (re-frame/reg-sub
:wallet/visible-assets-with-values :wallet/visible-assets-with-values

View File

@ -326,7 +326,8 @@
" • "] " • "]
(if prices-loading? (if prices-loading?
[react/small-loading-indicator] [react/small-loading-indicator]
[react/text {:style {:color colors/black}} (i18n/format-currency converted-value (:code wallet-currency))]) [react/text {:style {:color colors/black}}
(i18n/format-currency converted-value (:code wallet-currency))])
[react/text {:style {:color colors/gray}} (str " " (:code wallet-currency))]]]}])) [react/text {:style {:color colors/gray}} (str " " (:code wallet-currency))]]]}]))
(views/defview fee-item [prices wallet-currency fee-display-symbol fee gas-error gas-error-state prices-loading?] (views/defview fee-item [prices wallet-currency fee-display-symbol fee gas-error gas-error-state prices-loading?]
@ -353,7 +354,8 @@
" • "] " • "]
(if prices-loading? (if prices-loading?
[react/small-loading-indicator] [react/small-loading-indicator]
[react/text {:style {:color colors/black}} (i18n/format-currency converted-fee-value (:code wallet-currency))]) [react/text {:style {:color colors/black}}
(i18n/format-currency converted-fee-value (:code wallet-currency))])
[react/text {:style {:color colors/gray}} (str " " (:code wallet-currency))]] [react/text {:style {:color colors/gray}} (str " " (:code wallet-currency))]]
:chevron])) :chevron]))
:on-press #(re-frame/dispatch :on-press #(re-frame/dispatch

View File

@ -12,4 +12,15 @@
:align-items :center :align-items :center
:justify-content :space-between :justify-content :space-between
:padding-top (when-not small-screen? 16) :padding-top (when-not small-screen? 16)
:padding-left 16}) :padding-left 16})
(def set-max-button
{:height 35
:border-radius 40
:background-color colors/blue-light
:margin-horizontal 12
:align-self :flex-start
:margin-bottom 12
:align-items :center
:justify-content :center
:padding-horizontal 12})

View File

@ -18,37 +18,34 @@
[status-im.ui.screens.wallet.send.sheets :as sheets] [status-im.ui.screens.wallet.send.sheets :as sheets]
[status-im.ui.screens.wallet.components.views :as components] [status-im.ui.screens.wallet.components.views :as components]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im.ui.components.button :as button] [status-im.ethereum.core :as ethereum]
[status-im.ethereum.core :as ethereum])) [status-im.utils.money :as money]))
(defn header [{:keys [label small-screen? on-cancel]}] (defn header [{:keys [label small-screen?]}]
[react/view (styles/header small-screen?) [react/view (styles/header small-screen?)
[react/view {:flex 1} [react/view {:flex 1}
[react/text {:style (merge {:typography :title-bold} (when small-screen? {:font-size 15}))} [react/text {:style (merge {:typography :title-bold} (when small-screen? {:font-size 15}))}
(i18n/label (or label :t/send-transaction))]] (i18n/label (or label :t/send-transaction))]]])
[button/button {:type :secondary
:container-style {:padding-horizontal 24}
:label (i18n/label :t/cancel)
:on-press on-cancel}]])
(defn asset-selector [{:keys [request? token from]}] (defn asset-selector [{:keys [request? token from]} window-width]
(let [{:keys [name icon color]} token] (let [{:keys [name icon color]} token]
[react/touchable-highlight [react/touchable-highlight
{:style {:flex 1} {:on-press (when-not request?
:on-press (when-not request? #(do #(do
(re-frame/dispatch [:dismiss-keyboard]) (re-frame/dispatch [:dismiss-keyboard])
(re-frame/dispatch [:bottom-sheet/show-sheet (re-frame/dispatch [:bottom-sheet/show-sheet
{:content (fn [] [sheets/assets (:address from)]) {:content (fn [] [sheets/assets (:address from)])
:content-height 300}])))} :content-height 300}])))}
[react/view {:style {:flex-direction :row [react/view {:style {:flex-direction :row
:align-items :center :align-items :center
:flex 1 :margin-left 16} :margin-left 16}
:accessibility-label :choose-asset-button} :accessibility-label :choose-asset-button}
(if icon (if icon
[list/item-image (assoc icon :style {:background-color colors/gray-lighter [list/item-image (assoc icon :style {:background-color colors/gray-lighter
:border-radius 50} :image-style {:width 32 :height 32})] :border-radius 50} :image-style {:width 32 :height 32})]
[chat-icon/custom-icon-view-list name color 32]) [chat-icon/custom-icon-view-list name color 32])
[react/text {:style {:margin-left 8 :flex-shrink 0.5} [react/text {:style {:margin-left 8
:max-width (/ window-width 4)}
:number-of-lines 2} :number-of-lines 2}
(wallet.utils/display-symbol token)] (wallet.utils/display-symbol token)]
(when-not request? (when-not request?
@ -58,9 +55,10 @@
[list-item/list-item [list-item/list-item
{:icon [chat-icon/custom-icon-view-list (:name account) (:color account)] {:icon [chat-icon/custom-icon-view-list (:name account) (:color account)]
:title (:name account) :title (:name account)
:subtitle (str (wallet.utils/format-amount amount decimals) :subtitle (when token
" " (str (wallet.utils/format-amount amount decimals)
(wallet.utils/display-symbol token)) " "
(wallet.utils/display-symbol token)))
:accessories [:chevron] :accessories [:chevron]
:on-press #(do :on-press #(do
(re-frame/dispatch [:dismiss-keyboard]) (re-frame/dispatch [:dismiss-keyboard])
@ -70,40 +68,56 @@
(defn render-contact [contact from-chat?] (defn render-contact [contact from-chat?]
(if from-chat? (if from-chat?
[list-item/list-item {:title (multiaccounts/displayed-name contact) [list-item/list-item {:title (multiaccounts/displayed-name contact)
:subtitle (:address contact) :subtitle (:address contact)
:icon (multiaccounts/displayed-photo contact)}] :icon (multiaccounts/displayed-photo contact)}]
[list-item/list-item [list-item/list-item
{:title (utils/get-shortened-checksum-address {:title (utils/get-shortened-checksum-address
(if (string? contact) contact (:address contact))) (if (string? contact) contact (:address contact)))
:subtitle (when-not contact (i18n/label :t/wallet-choose-recipient)) :subtitle (when-not contact (i18n/label :t/wallet-choose-recipient))
:accessibility-label :choose-recipient-button :accessibility-label :choose-recipient-button
:on-press #(do :on-press #(do
(re-frame/dispatch [:dismiss-keyboard]) (re-frame/dispatch [:dismiss-keyboard])
(re-frame/dispatch [:bottom-sheet/show-sheet (re-frame/dispatch [:bottom-sheet/show-sheet
{:content sheets/choose-recipient {:content sheets/choose-recipient
:content-height 200}])) :content-height 200}]))
:accessories [:chevron]}])) :accessories [:chevron]}]))
(defn set-max [token]
[react/touchable-highlight
{:on-press
#(when token
(re-frame/dispatch [:wallet.send/set-max-amount token]))}
[react/view {:style styles/set-max-button}
[react/text {:style {:color colors/blue}} (i18n/label :t/set-max)]]])
(defn fiat-value [amount {:keys [symbol]} prices wallet-currency]
(when-let [price (get-in prices [(keyword symbol) (keyword (:code wallet-currency)) :price])]
(let [norm-amount (js/parseFloat (money/normalize amount))
amount (if (js/isNaN norm-amount) 0 norm-amount)]
[react/text {:style {:color colors/gray :margin-left 16 :margin-bottom 8
:font-size 15 :line-height 22}}
(str (i18n/format-currency (* amount price) (:code wallet-currency)) " " (:code wallet-currency))])))
(views/defview sheet [_] (views/defview sheet [_]
(views/letsubs [{:keys [amount-error amount-text (views/letsubs [{:keys [amount-error amount-text
request? request?
from token to sign-enabled? from-chat?] :as tx} from token to sign-enabled? from-chat?] :as tx}
[:wallet.send/prepare-transaction-with-balance] [:wallet.send/prepare-transaction-with-balance]
prices [:prices]
wallet-currency [:wallet/currency]
window-height [:dimensions/window-height] window-height [:dimensions/window-height]
window-width [:dimensions/window-width]
keyboard-height [:keyboard-height]] keyboard-height [:keyboard-height]]
(let [small-screen? (< (- window-height keyboard-height) 450) (let [small-screen? (< (- window-height keyboard-height) 450)
to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))] to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))]
[react/view {:style (styles/sheet small-screen?)} [react/view {:style (styles/sheet small-screen?)}
[header {:small-screen? small-screen? [react/view {:flex-direction :row :padding-horizontal 16 :align-items :center
:on-cancel #(re-frame/dispatch [:wallet/cancel-transaction-command])}] :margin-top 12 :margin-bottom 4}
[react/view {:flex-direction :row :padding-horizontal 24 :align-items :center
:flex 1
:margin-vertical (if small-screen? 8 16)}
[react/text-input [react/text-input
{:style {:font-size (if small-screen? 24 38) {:style {:font-size (if small-screen? 24 38)
:color (if amount-error colors/red colors/black) :max-width (- (* (/ window-width 4) 3) 106)
:flex-shrink 1} :color (if amount-error colors/red colors/black)}
:keyboard-type :decimal-pad :keyboard-type :decimal-pad
:auto-capitalize :words :auto-capitalize :words
:accessibility-label :amount-input :accessibility-label :amount-input
@ -112,13 +126,16 @@
:auto-focus true :auto-focus true
:on-change-text #(re-frame/dispatch [:wallet.send/set-amount-text %]) :on-change-text #(re-frame/dispatch [:wallet.send/set-amount-text %])
:placeholder "0.0 "}] :placeholder "0.0 "}]
[asset-selector tx] [asset-selector tx window-width]
(when amount-error (when amount-error
[tooltip/tooltip (if from [tooltip/tooltip (if from
amount-error amount-error
(i18n/label :t/select-account-first)) (i18n/label :t/select-account-first))
{:bottom-value 2 {:bottom-value 2
:font-size 12}])] :font-size 12}])]
[fiat-value amount-text token prices wallet-currency]
(when-not (or request? from-chat?)
[set-max token])
[components/separator] [components/separator]
(when-not small-screen? (when-not small-screen?
[list-item/list-item {:type :section-header :title :t/from}]) [list-item/list-item {:type :section-header :title :t/from}])
@ -135,7 +152,11 @@
[react/view {:flex 1} [react/view {:flex 1}
[render-contact to from-chat?]]] [render-contact to from-chat?]]]
[toolbar/toolbar [toolbar/toolbar
{:center {:left
{:label :t/cancel
:type :secondary
:on-press #(re-frame/dispatch [:wallet/cancel-transaction-command])}
:right
{:label (if (and (not request?) from-chat? (not to-norm)) :t/wallet-send :t/next) {:label (if (and (not request?) from-chat? (not to-norm)) :t/wallet-send :t/next)
:accessibility-label :send-transaction-bottom-sheet :accessibility-label :send-transaction-bottom-sheet
:disabled? (not sign-enabled?) :disabled? (not sign-enabled?)
@ -152,17 +173,19 @@
(views/letsubs [{:keys [amount-error amount-text from token sign-enabled?] :as tx} (views/letsubs [{:keys [amount-error amount-text from token sign-enabled?] :as tx}
[:wallet.request/prepare-transaction-with-balance] [:wallet.request/prepare-transaction-with-balance]
window-height [:dimensions/window-height] window-height [:dimensions/window-height]
window-width [:dimensions/window-width]
prices [:prices]
wallet-currency [:wallet/currency]
keyboard-height [:keyboard-height]] keyboard-height [:keyboard-height]]
(let [small-screen? (< (- window-height keyboard-height) 450)] (let [small-screen? (< (- window-height keyboard-height) 450)]
[react/view {:style (styles/sheet small-screen?)} [react/view {:style (styles/sheet small-screen?)}
[header {:small-screen? small-screen? [header {:small-screen? small-screen?
:label :t/request-transaction :label :t/request-transaction}]
:on-cancel #(re-frame/dispatch [:wallet/cancel-transaction-command])}] [react/view {:flex-direction :row :padding-horizontal 24 :align-items :center
[react/view {:flex-direction :row :padding-horizontal 24 :align-items :center
:margin-vertical (if small-screen? 8 16)} :margin-vertical (if small-screen? 8 16)}
[react/text-input [react/text-input
{:style {:font-size (if small-screen? 24 38) {:style {:font-size (if small-screen? 24 38)
:color (when amount-error colors/red) :color (when amount-error colors/red)
:flex-shrink 1} :flex-shrink 1}
:keyboard-type :decimal-pad :keyboard-type :decimal-pad
:auto-capitalize :words :auto-capitalize :words
@ -171,10 +194,11 @@
:auto-focus true :auto-focus true
:on-change-text #(re-frame/dispatch [:wallet.request/set-amount-text %]) :on-change-text #(re-frame/dispatch [:wallet.request/set-amount-text %])
:placeholder "0.0 "}] :placeholder "0.0 "}]
[asset-selector tx] [asset-selector tx window-width]
(when amount-error (when amount-error
[tooltip/tooltip amount-error {:bottom-value 2 [tooltip/tooltip amount-error {:bottom-value 2
:font-size 12}])] :font-size 12}])]
[fiat-value amount-text token prices wallet-currency]
[components/separator] [components/separator]
(when-not small-screen? (when-not small-screen?
[list-item/list-item {:type :section-header :title :t/to}]) [list-item/list-item {:type :section-header :title :t/to}])
@ -184,7 +208,11 @@
[react/view {:flex 1} [react/view {:flex 1}
[render-account from token :wallet.request/set-field]]] [render-account from token :wallet.request/set-field]]]
[toolbar/toolbar [toolbar/toolbar
{:center {:left
{:label :t/cancel
:type :secondary
:on-press #(re-frame/dispatch [:wallet/cancel-transaction-command])}
:right
{:label :t/wallet-request {:label :t/wallet-request
:accessibility-label :request-transaction-bottom-sheet :accessibility-label :request-transaction-bottom-sheet
:disabled? (not sign-enabled?) :disabled? (not sign-enabled?)
@ -197,9 +225,8 @@
(let [small-screen? (< (- window-height keyboard-height) 450)] (let [small-screen? (< (- window-height keyboard-height) 450)]
[react/view {:style (styles/sheet small-screen?)} [react/view {:style (styles/sheet small-screen?)}
[header {:small-screen? small-screen? [header {:small-screen? small-screen?
:label :t/select-account :label :t/select-account}]
:on-cancel #(re-frame/dispatch [:set :commands/select-account nil])}] [react/view {:flex-direction :row :padding-horizontal 24 :align-items :center
[react/view {:flex-direction :row :padding-horizontal 24 :align-items :center
:margin-vertical (if small-screen? 8 16)}] :margin-vertical (if small-screen? 8 16)}]
(when-not small-screen? (when-not small-screen?
[list-item/list-item {:type :section-header :title :t/from}]) [list-item/list-item {:type :section-header :title :t/from}])
@ -209,8 +236,12 @@
[react/view {:flex 1} [react/view {:flex 1}
[render-account from nil ::commands/set-selected-account]]] [render-account from nil ::commands/set-selected-account]]]
[toolbar/toolbar [toolbar/toolbar
{:center {:left
{:label :t/select {:label :t/cancel
:type :secondary
:on-press #(re-frame/dispatch [:set :commands/select-account nil])}
:right
{:label :t/share
:accessibility-label :select-account-bottom-sheet :accessibility-label :select-account-bottom-sheet
:disabled? (nil? from) :disabled? (nil? from)
:on-press #(re-frame/dispatch :on-press #(re-frame/dispatch

View File

@ -23,7 +23,8 @@
[status-im.ethereum.ens :as ens] [status-im.ethereum.ens :as ens]
[status-im.ethereum.stateofus :as stateofus] [status-im.ethereum.stateofus :as stateofus]
[status-im.ui.components.bottom-sheet.core :as bottom-sheet] [status-im.ui.components.bottom-sheet.core :as bottom-sheet]
[status-im.wallet.prices :as prices])) [status-im.wallet.prices :as prices]
[status-im.wallet.utils :as wallet.utils]))
(defn get-balance (defn get-balance
[{:keys [address on-success on-error]}] [{:keys [address on-success on-error]}]
@ -305,6 +306,24 @@
[{:keys [db]} amount] [{:keys [db]} amount]
{:db (assoc-in db [:wallet/prepare-transaction :amount-text] amount)}) {:db (assoc-in db [:wallet/prepare-transaction :amount-text] amount)})
(fx/defn wallet-send-gas-price-success
{:events [:wallet.send/update-gas-price-success]}
[{db :db} price]
{:db (assoc-in db [:wallet/prepare-transaction :gasPrice] price)})
(fx/defn set-max-amount
{:events [:wallet.send/set-max-amount]}
[{:keys [db]} {:keys [amount decimals symbol]}]
(let [^js gas (money/bignumber 21000)
^js gasPrice (get-in db [:wallet/prepare-transaction :gasPrice])
^js fee (when gasPrice (.times gas gasPrice))
amount-text (if (= :ETH symbol)
(when (and fee (money/sufficient-funds? fee amount))
(str (wallet.utils/format-amount (.minus amount fee) decimals)))
(str (wallet.utils/format-amount amount decimals)))]
(when amount-text
{:db (assoc-in db [:wallet/prepare-transaction :amount-text] amount-text)})))
(fx/defn set-and-validate-request-amount (fx/defn set-and-validate-request-amount
{:events [:wallet.request/set-amount-text]} {:events [:wallet.request/set-amount-text]}
[{:keys [db]} amount] [{:keys [db]} amount]
@ -466,7 +485,8 @@
(fx/defn on-recipient-address-resolved (fx/defn on-recipient-address-resolved
{:events [::recipient-address-resolved]} {:events [::recipient-address-resolved]}
[{:keys [db]} address] [{:keys [db]} address]
{:db (assoc-in db [:wallet/prepare-transaction :to :address] address)}) {:db (assoc-in db [:wallet/prepare-transaction :to :address] address)
:signing/update-gas-price {:success-event :wallet.send/update-gas-price-success}})
(fx/defn prepare-transaction-from-chat (fx/defn prepare-transaction-from-chat
{:events [:wallet/prepare-transaction-from-chat]} {:events [:wallet/prepare-transaction-from-chat]}
@ -515,7 +535,8 @@
{:from account {:from account
:to nil :to nil
:symbol :ETH :symbol :ETH
:from-chat? false})}) :from-chat? false})
:signing/update-gas-price {:success-event :wallet.send/update-gas-price-success}})
(fx/defn cancel-transaction-command (fx/defn cancel-transaction-command
{:events [:wallet/cancel-transaction-command]} {:events [:wallet/cancel-transaction-command]}

View File

@ -1156,5 +1156,6 @@
"tx-fail-description1" : "This transaction is likely to fail. Sign at your own risk using custom network fee.", "tx-fail-description1" : "This transaction is likely to fail. Sign at your own risk using custom network fee.",
"tx-fail-description2" : "This transaction is likely to fail. Set a custom network fee to sign at your own risk.", "tx-fail-description2" : "This transaction is likely to fail. Set a custom network fee to sign at your own risk.",
"set-custom-fee" : "Set custom fee", "set-custom-fee" : "Set custom fee",
"not-enough-snt": "Not enough SNT" "not-enough-snt": "Not enough SNT",
"set-max": "Set max"
} }