Skip to content

Commit

Permalink
[#10105] Add set max to Send transaction
Browse files Browse the repository at this point in the history
Signed-off-by: andrey <motor4ik@gmail.com>
  • Loading branch information
flexsurfer committed Jul 2, 2020
1 parent 7f4476b commit 24114f7
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 138 deletions.
2 changes: 1 addition & 1 deletion src/status_im/ethereum/json_rpc.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"eth_getBalance"
{:on-result money/bignumber}
"eth_estimateGas"
{:on-result #(money/bignumber (int (* % 1.2)))}
{:on-result #(money/bignumber (if (= (int %) 21000) % (int (* % 1.2))))}
"eth_gasPrice"
{:on-result money/bignumber}
"eth_getBlockByHash"
Expand Down
144 changes: 70 additions & 74 deletions src/status_im/goog/i18n.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -370,77 +370,73 @@
"Formats an amount of a currency based on the currency pattern
If currency-symbol? is false, the currency symbol is excluded from the
formatting"
([value currency-code]
(format-currency value currency-code true))
([value currency-code currency-symbol?]
(.addTier2Support ^js goog.i18n.currency)
(let [currency-code-to-nfs-map {"ZAR" ^js goog.i18n.NumberFormatSymbols_af
"ETB" ^js goog.i18n.NumberFormatSymbols_am
"EGP" ^js goog.i18n.NumberFormatSymbols_ar
"DZD" ^js goog.i18n.NumberFormatSymbols_ar_DZ
"AZN" ^js goog.i18n.NumberFormatSymbols_az
"BYN" ^js goog.i18n.NumberFormatSymbols_be
"BGN" ^js goog.i18n.NumberFormatSymbols_bg
"BDT" ^js goog.i18n.NumberFormatSymbols_bn
"EUR" ^js goog.i18n.NumberFormatSymbols_br
"BAM" ^js goog.i18n.NumberFormatSymbols_bs
"USD" ^js goog.i18n.NumberFormatSymbols_en
"CZK" ^js goog.i18n.NumberFormatSymbols_cs
"GBP" ^js goog.i18n.NumberFormatSymbols_cy
"DKK" ^js goog.i18n.NumberFormatSymbols_da
"CHF" ^js goog.i18n.NumberFormatSymbols_de_CH
"AUD" ^js goog.i18n.NumberFormatSymbols_en_AU
"CAD" ^js goog.i18n.NumberFormatSymbols_en_CA
"INR" ^js goog.i18n.NumberFormatSymbols_en_IN
"SGD" ^js goog.i18n.NumberFormatSymbols_en_SG
"MXN" ^js goog.i18n.NumberFormatSymbols_es_419
"IRR" ^js goog.i18n.NumberFormatSymbols_fa
"PHP" ^js goog.i18n.NumberFormatSymbols_fil
"ILS" ^js goog.i18n.NumberFormatSymbols_he
"HRK" ^js goog.i18n.NumberFormatSymbols_hr
"HUF" ^js goog.i18n.NumberFormatSymbols_hu
"AMD" ^js goog.i18n.NumberFormatSymbols_hy
"IDR" ^js goog.i18n.NumberFormatSymbols_id
"ISK" ^js goog.i18n.NumberFormatSymbols_is
"JPY" ^js goog.i18n.NumberFormatSymbols_ja
"GEL" ^js goog.i18n.NumberFormatSymbols_ka
"KZT" ^js goog.i18n.NumberFormatSymbols_kk
"KHR" ^js goog.i18n.NumberFormatSymbols_km
"KRW" ^js goog.i18n.NumberFormatSymbols_ko
"KGS" ^js goog.i18n.NumberFormatSymbols_ky
"CDF" ^js goog.i18n.NumberFormatSymbols_ln
"LAK" ^js goog.i18n.NumberFormatSymbols_lo
"MKD" ^js goog.i18n.NumberFormatSymbols_mk
"MNT" ^js goog.i18n.NumberFormatSymbols_mn
"MDL" ^js goog.i18n.NumberFormatSymbols_mo
"MYR" ^js goog.i18n.NumberFormatSymbols_ms
"MMK" ^js goog.i18n.NumberFormatSymbols_my
"NOK" ^js goog.i18n.NumberFormatSymbols_nb
"NPR" ^js goog.i18n.NumberFormatSymbols_ne
"PLN" ^js goog.i18n.NumberFormatSymbols_pl
"BRL" ^js goog.i18n.NumberFormatSymbols_pt
"RON" ^js goog.i18n.NumberFormatSymbols_ro
"RUB" ^js goog.i18n.NumberFormatSymbols_ru
"RSD" ^js goog.i18n.NumberFormatSymbols_sh
"LKR" ^js goog.i18n.NumberFormatSymbols_si
"ALL" ^js goog.i18n.NumberFormatSymbols_sq
"SEK" ^js goog.i18n.NumberFormatSymbols_sv
"TZS" ^js goog.i18n.NumberFormatSymbols_sw
"THB" ^js goog.i18n.NumberFormatSymbols_th
"TRY" ^js goog.i18n.NumberFormatSymbols_tr
"UAH" ^js goog.i18n.NumberFormatSymbols_uk
"PKR" ^js goog.i18n.NumberFormatSymbols_ur
"UZS" ^js goog.i18n.NumberFormatSymbols_uz
"VND" ^js goog.i18n.NumberFormatSymbols_vi
"CNY" ^js goog.i18n.NumberFormatSymbols_zh
"HKD" ^js goog.i18n.NumberFormatSymbols_zh_HK
"TWD" ^js goog.i18n.NumberFormatSymbols_zh_TW}
nfs (or (get currency-code-to-nfs-map currency-code)
^js goog.i18n.NumberFormatSymbols_en)]
(.format
^js (new ^js goog.i18n.NumberFormat
(let [pattern (.-CURRENCY_PATTERN ^js nfs)]
(if currency-symbol?
pattern
(string/replace pattern #"\s\s*" ""))))
value))))
[value currency-code]
(.addTier2Support ^js goog.i18n.currency)
(let [currency-code-to-nfs-map {"ZAR" ^js goog.i18n.NumberFormatSymbols_af
"ETB" ^js goog.i18n.NumberFormatSymbols_am
"EGP" ^js goog.i18n.NumberFormatSymbols_ar
"DZD" ^js goog.i18n.NumberFormatSymbols_ar_DZ
"AZN" ^js goog.i18n.NumberFormatSymbols_az
"BYN" ^js goog.i18n.NumberFormatSymbols_be
"BGN" ^js goog.i18n.NumberFormatSymbols_bg
"BDT" ^js goog.i18n.NumberFormatSymbols_bn
"EUR" ^js goog.i18n.NumberFormatSymbols_br
"BAM" ^js goog.i18n.NumberFormatSymbols_bs
"USD" ^js goog.i18n.NumberFormatSymbols_en
"CZK" ^js goog.i18n.NumberFormatSymbols_cs
"GBP" ^js goog.i18n.NumberFormatSymbols_cy
"DKK" ^js goog.i18n.NumberFormatSymbols_da
"CHF" ^js goog.i18n.NumberFormatSymbols_de_CH
"AUD" ^js goog.i18n.NumberFormatSymbols_en_AU
"CAD" ^js goog.i18n.NumberFormatSymbols_en_CA
"INR" ^js goog.i18n.NumberFormatSymbols_en_IN
"SGD" ^js goog.i18n.NumberFormatSymbols_en_SG
"MXN" ^js goog.i18n.NumberFormatSymbols_es_419
"IRR" ^js goog.i18n.NumberFormatSymbols_fa
"PHP" ^js goog.i18n.NumberFormatSymbols_fil
"ILS" ^js goog.i18n.NumberFormatSymbols_he
"HRK" ^js goog.i18n.NumberFormatSymbols_hr
"HUF" ^js goog.i18n.NumberFormatSymbols_hu
"AMD" ^js goog.i18n.NumberFormatSymbols_hy
"IDR" ^js goog.i18n.NumberFormatSymbols_id
"ISK" ^js goog.i18n.NumberFormatSymbols_is
"JPY" ^js goog.i18n.NumberFormatSymbols_ja
"GEL" ^js goog.i18n.NumberFormatSymbols_ka
"KZT" ^js goog.i18n.NumberFormatSymbols_kk
"KHR" ^js goog.i18n.NumberFormatSymbols_km
"KRW" ^js goog.i18n.NumberFormatSymbols_ko
"KGS" ^js goog.i18n.NumberFormatSymbols_ky
"CDF" ^js goog.i18n.NumberFormatSymbols_ln
"LAK" ^js goog.i18n.NumberFormatSymbols_lo
"MKD" ^js goog.i18n.NumberFormatSymbols_mk
"MNT" ^js goog.i18n.NumberFormatSymbols_mn
"MDL" ^js goog.i18n.NumberFormatSymbols_mo
"MYR" ^js goog.i18n.NumberFormatSymbols_ms
"MMK" ^js goog.i18n.NumberFormatSymbols_my
"NOK" ^js goog.i18n.NumberFormatSymbols_nb
"NPR" ^js goog.i18n.NumberFormatSymbols_ne
"PLN" ^js goog.i18n.NumberFormatSymbols_pl
"BRL" ^js goog.i18n.NumberFormatSymbols_pt
"RON" ^js goog.i18n.NumberFormatSymbols_ro
"RUB" ^js goog.i18n.NumberFormatSymbols_ru
"RSD" ^js goog.i18n.NumberFormatSymbols_sh
"LKR" ^js goog.i18n.NumberFormatSymbols_si
"ALL" ^js goog.i18n.NumberFormatSymbols_sq
"SEK" ^js goog.i18n.NumberFormatSymbols_sv
"TZS" ^js goog.i18n.NumberFormatSymbols_sw
"THB" ^js goog.i18n.NumberFormatSymbols_th
"TRY" ^js goog.i18n.NumberFormatSymbols_tr
"UAH" ^js goog.i18n.NumberFormatSymbols_uk
"PKR" ^js goog.i18n.NumberFormatSymbols_ur
"UZS" ^js goog.i18n.NumberFormatSymbols_uz
"VND" ^js goog.i18n.NumberFormatSymbols_vi
"CNY" ^js goog.i18n.NumberFormatSymbols_zh
"HKD" ^js goog.i18n.NumberFormatSymbols_zh_HK
"TWD" ^js goog.i18n.NumberFormatSymbols_zh_TW}
nfs (or (get currency-code-to-nfs-map currency-code)
^js goog.i18n.NumberFormatSymbols_en)]
(.format
^js (new ^js goog.i18n.NumberFormat
(let [pattern (.-CURRENCY_PATTERN ^js nfs)]
(string/replace pattern #"\s\s*" "")))
value)))
2 changes: 1 addition & 1 deletion src/status_im/signing/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
(prices/update-prices)
#(when-not gas
{: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
:error-event :signing/update-estimated-gas-error}})
#(when-not gasPrice
Expand Down
6 changes: 3 additions & 3 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@
(-> balance-total-value
(money/with-precision 2)
str
(i18n/format-currency (:code currency) false))
(i18n/format-currency (:code currency)))
"0"))
"...")))

Expand All @@ -1096,7 +1096,7 @@
(-> balance-total-value
(money/with-precision 2)
str
(i18n/format-currency (:code currency) false))
(i18n/format-currency (:code currency)))
"0"))
"...")))

Expand Down Expand Up @@ -1182,7 +1182,7 @@
(money/crypto->fiat price)
(money/with-precision 2)
str
(i18n/format-currency (:code currency) false)))))))
(i18n/format-currency (:code currency))))))))

(re-frame/reg-sub
:wallet/visible-assets-with-values
Expand Down
6 changes: 4 additions & 2 deletions src/status_im/ui/screens/signing/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@
""]
(if prices-loading?
[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))]]]}]))

(views/defview fee-item [prices wallet-currency fee-display-symbol fee gas-error gas-error-state prices-loading?]
Expand All @@ -353,7 +354,8 @@
""]
(if prices-loading?
[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))]]
:chevron]))
:on-press #(re-frame/dispatch
Expand Down
13 changes: 12 additions & 1 deletion src/status_im/ui/screens/wallet/send/styles.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@
:align-items :center
:justify-content :space-between
: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})
Loading

0 comments on commit 24114f7

Please sign in to comment.