diff --git a/src/status_im/ui/screens/chat/input/send_button.cljs b/src/status_im/ui/screens/chat/input/send_button.cljs index 4b3c428344..fe63b97ad7 100644 --- a/src/status_im/ui/screens/chat/input/send_button.cljs +++ b/src/status_im/ui/screens/chat/input/send_button.cljs @@ -14,17 +14,20 @@ (animation/timing spin-value {:toValue to-spin-value :duration 300}))))) -(defn sendable? [input-text] +(defn sendable? [input-text network-status] (let [trimmed (string/trim input-text)] - (not (or (string/blank? trimmed) (= trimmed "/"))))) + (not (or (string/blank? trimmed) + (= trimmed "/") + (= :offline network-status))))) (defview send-button-view [] (letsubs [{:keys [command-completion]} [:selected-chat-command] {:keys [input-text seq-arg-input-text]} [:get-current-chat] + network-status [:network-status] spin-value (animation/create-value 1)] {:component-did-update (send-button-view-on-update {:spin-value spin-value :command-completion command-completion})} - (when (and (sendable? input-text) + (when (and (sendable? input-text network-status) (or (not command-completion) (#{:complete :less-than-needed} command-completion))) [react/touchable-highlight {:on-press #(re-frame/dispatch [:send-current-message])} diff --git a/src/status_im/ui/screens/wallet/components/views.cljs b/src/status_im/ui/screens/wallet/components/views.cljs index 7422fd8342..d845a5365f 100644 --- a/src/status_im/ui/screens/wallet/components/views.cljs +++ b/src/status_im/ui/screens/wallet/components/views.cljs @@ -288,7 +288,8 @@ (str (money/to-fixed (money/internal->formatted amount symbol decimals))) amount-text)} (if disabled? - {:editable false} + {:editable false + :placeholder ""} {:keyboard-type :numeric :placeholder (i18n/label :t/amount-placeholder) :style components.styles/flex diff --git a/src/status_im/ui/screens/wallet/request/views.cljs b/src/status_im/ui/screens/wallet/request/views.cljs index c1c1f6952e..1fb0302de4 100644 --- a/src/status_im/ui/screens/wallet/request/views.cljs +++ b/src/status_im/ui/screens/wallet/request/views.cljs @@ -29,6 +29,7 @@ (views/letsubs [network [:get-current-account-network] {:keys [to to-name whisper-identity]} [:wallet.send/transaction] {:keys [amount amount-error amount-text symbol]} [:wallet.request/transaction] + network-status [:network-status] scroll (atom nil)] (let [{:keys [decimals] :as token} (tokens/asset-for (ethereum/network->chain-keyword network) symbol)] [wallet.components/simple-screen {:avoid-keyboard? true} @@ -46,6 +47,7 @@ :type :request :symbol symbol}] [components/amount-selector {:error amount-error + :disabled? (= :offline network-status) :amount amount :amount-text amount-text :input-options {:on-focus (fn [] (when @scroll (utils/set-timeout #(.scrollToEnd @scroll) 100))) diff --git a/src/status_im/ui/screens/wallet/send/subs.cljs b/src/status_im/ui/screens/wallet/send/subs.cljs index fa955eb9cf..63bc84c421 100644 --- a/src/status_im/ui/screens/wallet/send/subs.cljs +++ b/src/status_im/ui/screens/wallet/send/subs.cljs @@ -70,7 +70,7 @@ (defn check-sufficient-gas [transaction balance symbol amount] (assoc transaction :sufficient-gas? (or (nil? amount) - (let [available-ether (get balance :ETH) + (let [available-ether (get balance :ETH (money/bignumber 0)) available-for-gas (if (= :ETH symbol) (.minus available-ether (money/bignumber amount)) available-ether)] diff --git a/src/status_im/ui/screens/wallet/send/views.cljs b/src/status_im/ui/screens/wallet/send/views.cljs index e258088223..d176a5b35a 100644 --- a/src/status_im/ui/screens/wallet/send/views.cljs +++ b/src/status_im/ui/screens/wallet/send/views.cljs @@ -19,6 +19,7 @@ [status-im.ui.screens.wallet.send.animations :as send.animations] [status-im.ui.screens.wallet.send.styles :as styles] [status-im.ui.screens.wallet.styles :as wallet.styles] + [status-im.ui.screens.wallet.main.views :as wallet.main.views] [status-im.utils.money :as money] [status-im.utils.security :as security] [status-im.utils.utils :as utils] @@ -97,7 +98,8 @@ ;; "Cancel" and "Sign Transaction >" or "Sign >" buttons, signing with password (defview enter-password-buttons [spinning? cancel-handler sign-handler sign-label] - (letsubs [sign-enabled? [:wallet.send/sign-password-enabled?]] + (letsubs [sign-enabled? [:wallet.send/sign-password-enabled?] + network-status [:network-status]] [bottom-buttons/bottom-buttons styles/sign-buttons [button/button {:style components.styles/flex @@ -106,18 +108,21 @@ (i18n/label :t/cancel)] [button/button {:style (wallet.styles/button-container sign-enabled?) :on-press sign-handler - :disabled? (or spinning? (not sign-enabled?)) + :disabled? (or spinning? + (not sign-enabled?) + (= :offline network-status)) :accessibility-label :sign-transaction-button} (i18n/label sign-label) [vector-icons/icon :icons/forward {:color :white}]]])) ;; "Sign Transaction >" button -(defn- sign-transaction-button [amount-error to amount sufficient-funds? sufficient-gas? modal?] +(defn- sign-transaction-button [amount-error to amount sufficient-funds? sufficient-gas? modal? online?] (let [sign-enabled? (and (nil? amount-error) (or modal? (not (empty? to))) ;;NOTE(goranjovic) - contract creation will have empty `to` (not (nil? amount)) sufficient-funds? - sufficient-gas?)] + sufficient-gas? + online?)] [bottom-buttons/bottom-buttons styles/sign-buttons [react/view] @@ -131,10 +136,11 @@ (i18n/label :t/transactions-sign-transaction) [vector-icons/icon :icons/forward {:color (if sign-enabled? :white :gray)}]]])) -(defn- render-send-transaction-view [{:keys [modal? transaction scroll advanced? network amount-input]}] +(defn- render-send-transaction-view [{:keys [modal? transaction scroll advanced? network amount-input network-status]}] (let [{:keys [amount amount-text amount-error asset-error show-password-input? to to-name sufficient-funds? sufficient-gas? in-progress? from-chat? symbol]} transaction - {:keys [decimals] :as token} (tokens/asset-for (ethereum/network->chain-keyword network) symbol)] + {:keys [decimals] :as token} (tokens/asset-for (ethereum/network->chain-keyword network) symbol) + online? (= :online network-status)] [wallet.components/simple-screen {:avoid-keyboard? (not modal?) :status-bar-type (if modal? :modal-wallet :wallet)} [toolbar modal? (i18n/label :t/send-transaction)] @@ -144,6 +150,8 @@ :ref #(reset! scroll %) :on-content-size-change #(when (and (not modal?) scroll @scroll) (.scrollToEnd @scroll))} + (when-not online? + [wallet.main.views/snackbar :t/error-cant-send-transaction-offline]) [react/view styles/send-transaction-form [components/recipient-selector {:disabled? (or from-chat? modal?) :address to @@ -167,7 +175,7 @@ #(re-frame/dispatch [:wallet/cancel-entering-password]) #(re-frame/dispatch [:wallet/send-transaction]) :t/transactions-sign-transaction] - [sign-transaction-button amount-error to amount sufficient-funds? sufficient-gas? modal?]) + [sign-transaction-button amount-error to amount sufficient-funds? sufficient-gas? modal? online?]) (when show-password-input? [password-input-panel :t/signing-phrase-description in-progress?]) (when in-progress? [react/view styles/processing-view])]])) @@ -191,21 +199,31 @@ ;; SEND TRANSACTION FROM WALLET (CHAT) (defview send-transaction [] (letsubs [transaction [:wallet.send/transaction] - advanced? [:wallet.send/advanced?] - network [:get-current-account-network] - scroll (atom nil)] - [send-transaction-view {:modal? false :transaction transaction :scroll scroll :advanced? advanced? - :network network}])) + advanced? [:wallet.send/advanced?] + network [:get-current-account-network] + scroll (atom nil) + network-status [:network-status]] + [send-transaction-view {:modal? false + :transaction transaction + :scroll scroll + :advanced? advanced? + :network network + :network-status network-status}])) ;; SEND TRANSACTION FROM DAPP (defview send-transaction-modal [] (letsubs [transaction [:wallet.send/transaction] - advanced? [:wallet.send/advanced?] - network [:get-current-account-network] - scroll (atom nil)] + advanced? [:wallet.send/advanced?] + network [:get-current-account-network] + scroll (atom nil) + network-status [:network-status]] (if transaction - [send-transaction-view {:modal? true :transaction transaction :scroll scroll :advanced? advanced? - :network network}] + [send-transaction-view {:modal? true + :transaction transaction + :scroll scroll + :advanced? advanced? + :network network + :network-status network-status}] [react/view wallet.styles/wallet-modal-container [react/view components.styles/flex [status-bar/status-bar {:type :modal-wallet}] @@ -215,11 +233,14 @@ ;; SIGN MESSAGE FROM DAPP (defview sign-message-modal [] - (letsubs [{:keys [data in-progress?]} [:wallet.send/transaction]] + (letsubs [{:keys [data in-progress?]} [:wallet.send/transaction] + network-status [:network-status]] [wallet.components/simple-screen {:status-bar-type :modal-wallet} [toolbar true (i18n/label :t/sign-message)] [react/view components.styles/flex [react/scroll-view + (when (= network-status :offline) + [wallet.main.views/snackbar :t/error-cant-sign-message-offline]) [react/view styles/send-transaction-form [wallet.components/cartouche {:disabled? true} (i18n/label :t/message) diff --git a/translations/en.json b/translations/en.json index 78129a66eb..311ee259bc 100644 --- a/translations/en.json +++ b/translations/en.json @@ -332,6 +332,8 @@ "your-wallets": "Your wallets", "phone-international": "International 2", "error-unable-to-get-token-balance": "Unable to get token balance", + "error-cant-send-transaction-offline": "Can't send transaction in offline mode", + "error-cant-sign-message-offline": "Can't sign message in offline mode", "enter-word": "Enter word", "sync-in-progress": "Syncing...", "enter-password": "Enter password",