From 12a99f40d296e8b59954081cee7982f39cf0a934 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 8 Oct 2021 11:30:11 +0300 Subject: [PATCH] [#12681] Enable UI for signing legacy txs on networks without eip1559 support --- .env | 1 - .env.e2e | 1 - .env.jenkins | 1 - .env.nightly | 1 - .env.release | 1 - src/status_im/signing/eip1559.cljs | 71 +++++++++------------ src/status_im/ui/screens/signing/views.cljs | 59 ++++++++--------- src/status_im/utils/config.cljs | 1 - 8 files changed, 57 insertions(+), 79 deletions(-) diff --git a/.env b/.env index 0c268547f8..1ceb03357e 100644 --- a/.env +++ b/.env @@ -29,6 +29,5 @@ APN_TOPIC=im.status.ethereum.pr COMMUNITIES_ENABLED=1 DATABASE_MANAGEMENT_ENABLED=1 METRICS_ENABLED=0 -EIP1559_ENABLED=1 DELETE_MESSAGE_ENABLED=1 COLLECTIBLES_ENABLED=1 diff --git a/.env.e2e b/.env.e2e index 9fde207a3f..a9782b1757 100644 --- a/.env.e2e +++ b/.env.e2e @@ -32,5 +32,4 @@ DATABASE_MANAGEMENT_ENABLED=1 COMMUNITIES_ENABLED=1 COMMUNITIES_MANAGEMENT_ENABLED=1 METRICS_ENABLED=0 -EIP1559_ENABLED=1 DELETE_MESSAGE_ENABLED=1 diff --git a/.env.jenkins b/.env.jenkins index be4fef3629..abd7313280 100644 --- a/.env.jenkins +++ b/.env.jenkins @@ -34,5 +34,4 @@ DATABASE_MANAGEMENT_ENABLED=1 COMMUNITIES_ENABLED=1 COMMUNITIES_MANAGEMENT_ENABLED=1 METRICS_ENABLED=0 -EIP1559_ENABLED=1 DELETE_MESSAGE_ENABLED=1 diff --git a/.env.nightly b/.env.nightly index c07f0525b2..3e47f2af76 100644 --- a/.env.nightly +++ b/.env.nightly @@ -23,5 +23,4 @@ BLANK_PREVIEW=0 COMMUNITIES_ENABLED=1 DATABASE_MANAGEMENT_ENABLED=1 METRICS_ENABLED=0 -EIP1559_ENABLED=1 DELETE_MESSAGE_ENABLED=1 diff --git a/.env.release b/.env.release index 2909810cf2..8261432674 100644 --- a/.env.release +++ b/.env.release @@ -19,6 +19,5 @@ ENABLE_ROOT_ALERT=1 MAX_IMAGES_BATCH=1 ENABLE_REFERRAL_INVITE=0 METRICS_ENABLED=0 -EIP1559_ENABLED=1 DELETE_MESSAGE_ENABLED=1 COLLECTIBLES_ENABLED=0 diff --git a/src/status_im/signing/eip1559.cljs b/src/status_im/signing/eip1559.cljs index 17a5d7695e..593d54863c 100644 --- a/src/status_im/signing/eip1559.cljs +++ b/src/status_im/signing/eip1559.cljs @@ -1,60 +1,49 @@ (ns status-im.signing.eip1559 (:require [re-frame.core :as re-frame] - [status-im.ethereum.json-rpc :as json-rpc] - [status-im.utils.config :as config] - [status-im.utils.money :as money])) + [status-im.ethereum.json-rpc :as json-rpc])) -(def activation-blocks - {"3" (money/bignumber 10499401)}) - -(defonce activated? (atom {})) +(defonce london-activated? (atom false)) (defonce activated-on-current-network? (atom nil)) -(defn get-activation-block [network-id] - (get activation-blocks (str network-id))) +(defn london-is-definitely-activated [network-id] + (contains? #{"1" "3"} network-id)) -(defn on-block [network-id callback header] - (let [london-activated? - (boolean - (and - (get-activation-block network-id) - (money/greater-than-or-equals - (money/bignumber (:number header)) - (get-activation-block network-id))))] - (swap! activated? assoc network-id london-activated?) - (reset! activated-on-current-network? london-activated?) - (callback london-activated?))) +(defn on-block [callback header] + (let [activated? (contains? header :baseFeePerGas)] + (reset! london-activated? activated?) + (callback activated?))) -(defn check-activation [network-id callback] +(defn check-activation [callback] (json-rpc/call {:method "eth_getBlockByNumber" :params ["latest" false] - :on-success (partial on-block network-id callback) + :on-success (partial on-block callback) :on-error #(callback nil)})) -(defn sync-enabled? [] - config/eip1559-enabled?) +(defn sync-enabled? [] @london-activated?) -(defn enabled? [network-id enabled-callback disabled-callback] - (let [london-activated? true] - (cond - (not config/eip1559-enabled?) - (disabled-callback) +(defn enabled? + ([] @london-activated?) + ([network-id enabled-callback disabled-callback] + (let [definitely-activated? (london-is-definitely-activated network-id)] + (cond + definitely-activated? + (do + (reset! london-activated? true) + (enabled-callback)) - (nil? london-activated?) - (check-activation - network-id - (fn [activated?] - (if activated? - (enabled-callback) - (disabled-callback)))) + (not definitely-activated?) + (check-activation + (fn [activated?] + (if activated? + (enabled-callback) + (disabled-callback)))) - london-activated? - (enabled-callback) - - :else - (disabled-callback)))) + :else + (do + (reset! london-activated? false) + (disabled-callback)))))) (re-frame/reg-fx ::check-eip1559-activation diff --git a/src/status_im/ui/screens/signing/views.cljs b/src/status_im/ui/screens/signing/views.cljs index 359f988f88..16fa734ef9 100644 --- a/src/status_im/ui/screens/signing/views.cljs +++ b/src/status_im/ui/screens/signing/views.cljs @@ -1,31 +1,32 @@ (ns status-im.ui.screens.signing.views (:require-macros [status-im.utils.views :as views]) - (:require [status-im.ui.components.react :as react] - [re-frame.core :as re-frame] - [status-im.multiaccounts.core :as multiaccounts] - [quo.design-system.colors :as colors] - [status-im.ui.components.copyable-text :as copyable-text] - [status-im.wallet.utils :as wallet.utils] - [status-im.keycard.common :as keycard.common] - [status-im.ui.screens.keycard.keycard-interaction :as keycard-sheet] - [status-im.ui.components.chat-icon.screen :as chat-icon] - [status-im.ui.components.icons.icons :as icons] - [status-im.i18n.i18n :as i18n] - [status-im.utils.security :as security] - [status-im.ui.screens.signing.sheets :as sheets] - [status-im.ethereum.tokens :as tokens] - [status-im.utils.types :as types] - [status-im.utils.platform :as platform] - [clojure.string :as string] + (:require [clojure.string :as string] [quo.core :as quo] + [quo.design-system.colors :as colors] [quo.gesture-handler :as gh] - [status-im.ui.screens.signing.styles :as styles] - [status-im.react-native.resources :as resources] - [status-im.ui.screens.keycard.pin.views :as pin.views] - [status-im.ui.components.bottom-panel.views :as bottom-panel] - [status-im.utils.utils :as utils] + [re-frame.core :as re-frame] [reagent.core :as reagent] - [status-im.ui.screens.wallet.components.views :as wallet.components])) + [status-im.ethereum.tokens :as tokens] + [status-im.i18n.i18n :as i18n] + [status-im.keycard.common :as keycard.common] + [status-im.multiaccounts.core :as multiaccounts] + [status-im.react-native.resources :as resources] + [status-im.signing.eip1559 :as eip1559] + [status-im.ui.components.bottom-panel.views :as bottom-panel] + [status-im.ui.components.chat-icon.screen :as chat-icon] + [status-im.ui.components.copyable-text :as copyable-text] + [status-im.ui.components.icons.icons :as icons] + [status-im.ui.components.react :as react] + [status-im.ui.screens.keycard.keycard-interaction :as keycard-sheet] + [status-im.ui.screens.keycard.pin.views :as pin.views] + [status-im.ui.screens.signing.sheets :as sheets] + [status-im.ui.screens.signing.styles :as styles] + [status-im.ui.screens.wallet.components.views :as wallet.components] + [status-im.utils.platform :as platform] + [status-im.utils.security :as security] + [status-im.utils.types :as types] + [status-im.utils.utils :as utils] + [status-im.wallet.utils :as wallet.utils])) (defn separator [] [react/view {:height 1 :background-color colors/gray-lighter}]) @@ -384,15 +385,9 @@ :on-press #(re-frame/dispatch [:signing.ui/open-fee-sheet {:content (fn [] - [sheets/fee-bottom-sheet-eip1559-custom fee-display-symbol]) - :content-height 270}]) - #_(re-frame/dispatch - [:signing.ui/open-fee-sheet - {:content (fn [] - (if (eip1559/sync-enabled?) - [sheets/fee-bottom-sheet-eip1559 fee-display-symbol] - [sheets/fee-bottom-sheet fee-display-symbol])) - :content-height 270}])}]))) + (if (eip1559/enabled?) + [sheets/fee-bottom-sheet-eip1559-custom fee-display-symbol] + [sheets/fee-bottom-sheet fee-display-symbol]))}])}]))) (views/defview network-item [] (views/letsubs [network-name [:network-name]] diff --git a/src/status_im/utils/config.cljs b/src/status_im/utils/config.cljs index db43809924..1c4a269d68 100644 --- a/src/status_im/utils/config.cljs +++ b/src/status_im/utils/config.cljs @@ -49,7 +49,6 @@ (def database-management-enabled? (enabled? (get-config :DATABASE_MANAGEMENT_ENABLED "0"))) (def debug-webview? (enabled? (get-config :DEBUG_WEBVIEW "0"))) (def metrics-enabled? (enabled? (get-config :METRICS_ENABLED "0"))) -(def eip1559-enabled? (enabled? (get-config :EIP1559_ENABLED "0"))) (def delete-message-enabled? (enabled? (get-config :DELETE_MESSAGE_ENABLED "0"))) (def collectibles-enabled? (enabled? (get-config :COLLECTIBLES_ENABLED "1"))) (def test-stateofus? (enabled? (get-config :TEST_STATEOFUS "0")))