From dfb8420353a916a2e1b739adee0bb7e1bc175913 Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 23 Jun 2020 11:45:15 +0200 Subject: [PATCH] Disable Register button if not enough SNT for ENS name Signed-off-by: andrey --- src/status_im/ethereum/tokens.cljs | 2 + src/status_im/subs.cljs | 18 +++++---- src/status_im/ui/screens/ens/views.cljs | 50 ++++++++++++------------- translations/en.json | 3 +- 4 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/status_im/ethereum/tokens.cljs b/src/status_im/ethereum/tokens.cljs index e98e80ea73..3ad03e842c 100644 --- a/src/status_im/ethereum/tokens.cljs +++ b/src/status_im/ethereum/tokens.cljs @@ -11,6 +11,8 @@ :decimals 18 :icon {:source (js/require "../resources/images/tokens/default-native.png")}}))) +(def snt-icon-source (js/require "../resources/images/tokens/mainnet/SNT.png")) + (def all-native-currencies (ethereum.macros/resolve-native-currency-icons {:mainnet {:name "Ether" diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 847758f925..cc4fcbe07b 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -1986,14 +1986,18 @@ :<- [:multiaccount/default-account] :<- [:multiaccount/public-key] :<- [:chain-id] + :<- [:balance-default] (fn [[{:keys [custom-domain? username]} - registrar default-account public-key chain-id]] - {:address (ethereum/normalized-hex (:address default-account)) - :username username - :public-key public-key - :custom-domain? custom-domain? - :contract registrar - :amount-label (ens-amount-label chain-id)})) + registrar default-account public-key chain-id balance]] + {:address (ethereum/normalized-hex (:address default-account)) + :username username + :public-key public-key + :custom-domain? custom-domain? + :contract registrar + :amount-label (ens-amount-label chain-id) + :sufficient-funds? (money/sufficient-funds? + (money/formatted->internal (money/bignumber 10) :SNT 18) + (get balance :SNT))})) (re-frame/reg-sub :ens/confirmation-screen diff --git a/src/status_im/ui/screens/ens/views.cljs b/src/status_im/ui/screens/ens/views.cljs index 691d3717ce..9a6d522205 100644 --- a/src/status_im/ui/screens/ens/views.cljs +++ b/src/status_im/ui/screens/ens/views.cljs @@ -24,7 +24,9 @@ [status-im.ui.screens.chat.photos :as photos] [status-im.ui.screens.profile.components.views :as profile.components] [status-im.utils.debounce :as debounce] - [clojure.string :as string]) + [clojure.string :as string] + [status-im.ethereum.tokens :as tokens] + [quo.core :as quo]) (:require-macros [status-im.utils.views :as views])) (defn- button @@ -276,28 +278,26 @@ "\n" (i18n/label :t/ens-understand)]]) -(defn- registration-bottom-bar - [checked? amount-label] - [react/view {:style {:height 60 - :border-top-width 1 - :border-top-color colors/gray-lighter}} - [react/view {:style {:margin-horizontal 16 - :flex-direction :row - :justify-content :space-between}} - [react/view {:flex-direction :row} - [react/view {:style {:margin-top 12 :margin-right 8}} - [components.common/logo - {:size 36 - :icon-size 16}]] - [react/view {:flex-direction :column :margin-vertical 8} - [react/text {:style {:font-size 15}} - amount-label] - [react/text {:style {:color colors/gray :font-size 15}} - (i18n/label :t/ens-deposit)]]] - [button {:disabled? (not @checked?) - :label-style (when (not @checked?) {:color colors/gray}) - :on-press #(debounce/dispatch-and-chill [::ens/register-name-pressed] 2000)} - (i18n/label :t/ens-register)]]]) +(defn- registration-bottom-bar [checked? amount-label sufficient-funds?] + [react/view {:style {:border-top-width 1 + :border-top-color colors/gray-lighter + :padding-horizontal 16 + :padding-vertical 8 + :flex-direction :row + :justify-content :space-between}} + [react/view {:flex-direction :row :align-items :center} + [react/image {:source tokens/snt-icon-source + :style {:width 36 :height 36}}] + [react/view {:flex-direction :column :margin 8} + [react/text {:style {:font-size 15}} + amount-label] + [react/text {:style {:color colors/gray :font-size 15}} + (i18n/label :t/ens-deposit)]]] + [quo/button {:disabled (or (not @checked?) (not sufficient-funds?)) + :on-press #(debounce/dispatch-and-chill [::ens/register-name-pressed] 2000)} + (if sufficient-funds? + (i18n/label :t/ens-register) + (i18n/label :t/not-enough-snt))]]) (defn- registration [checked contract address public-key] @@ -311,7 +311,7 @@ (views/defview checkout [] (views/letsubs [{:keys [username address custom-domain? public-key - contract amount-label]} + contract amount-label sufficient-funds?]} [:ens/checkout-screen]] (let [checked? (reagent/atom false)] [react/keyboard-avoiding-view {:flex 1} @@ -340,7 +340,7 @@ (domain-label custom-domain?)] [react/view {:flex 1 :min-width 24}]]] [registration checked? contract address public-key]] - [registration-bottom-bar checked? amount-label]]))) + [registration-bottom-bar checked? amount-label sufficient-funds?]]))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; CONFIRMATION SCREEN diff --git a/translations/en.json b/translations/en.json index 3ec25de41a..c3bc80589e 100644 --- a/translations/en.json +++ b/translations/en.json @@ -1154,5 +1154,6 @@ "sign-anyway" : "Sign anyway", "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.", - "set-custom-fee" : "Set custom fee" + "set-custom-fee" : "Set custom fee", + "not-enough-snt": "Not enough SNT" }