[Feature] Enable Sepolia as default test network (#18917)

This commit:
- enables Sepolia test network by default
- adds a toggle to switch to the Goerli test network

Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com>
This commit is contained in:
Mohamed Javid 2024-02-23 16:18:35 +05:30 committed by GitHub
parent 9fab422e0c
commit 4f5480e36f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 66 additions and 54 deletions

View File

@ -20,7 +20,7 @@
current-fleet current-fleet
webview-debug webview-debug
test-networks-enabled? test-networks-enabled?
is-sepolia-enabled?]}] is-goerli-enabled?]}]
(keep (keep
identity identity
[{:size :small [{:size :small
@ -112,13 +112,13 @@
:accessory :switch :accessory :switch
:active test-networks-enabled?} :active test-networks-enabled?}
{:size :small {:size :small
:title "Enable Sepolia as test network" :title "Enable Goerli as test network"
:accessibility-label :enable-sepolia-as-test-network :accessibility-label :enable-sepolia-as-test-network
:container-margin-bottom 8 :container-margin-bottom 8
:on-press :on-press
#(re-frame/dispatch [:profile.settings/toggle-sepolia-test-network]) #(re-frame/dispatch [:profile.settings/toggle-goerli-test-network])
:accessory :switch :accessory :switch
:active is-sepolia-enabled?} :active is-goerli-enabled?}
{:size :small {:size :small
:title (i18n/label :t/set-currency) :title (i18n/label :t/set-currency)
:accessibility-label :wallet-change-currency :accessibility-label :wallet-change-currency
@ -139,7 +139,7 @@
(views/defview advanced-settings (views/defview advanced-settings
[] []
(views/letsubs [test-networks-enabled? [:profile/test-networks-enabled?] (views/letsubs [test-networks-enabled? [:profile/test-networks-enabled?]
is-sepolia-enabled? [:profile/is-sepolia-enabled?] is-goerli-enabled? [:profile/is-goerli-enabled?]
light-client-enabled? [:profile/light-client-enabled?] light-client-enabled? [:profile/light-client-enabled?]
webview-debug [:profile/webview-debug] webview-debug [:profile/webview-debug]
network-name [:network-name] network-name [:network-name]
@ -156,6 +156,6 @@
:dev-mode? false :dev-mode? false
:webview-debug webview-debug :webview-debug webview-debug
:test-networks-enabled? test-networks-enabled? :test-networks-enabled? test-networks-enabled?
:is-sepolia-enabled? is-sepolia-enabled?}) :is-goerli-enabled? is-goerli-enabled?})
:key-fn (fn [_ i] (str i)) :key-fn (fn [_ i] (str i))
:render-fn render-item}])) :render-fn render-item}]))

View File

@ -415,14 +415,14 @@
(def ^:const ens-action-type-set-pub-key 2) (def ^:const ens-action-type-set-pub-key 2)
;; wallet ;; wallet
(def ^:const ethereum-chain-id 1) (def ^:const ethereum-mainnet-chain-id 1)
(def ^:const goerli-chain-id 5) (def ^:const ethereum-goerli-chain-id 5)
(def ^:const arbitrum-chain-id 42161)
(def ^:const arbitrum-testnet-chain-id 421613)
(def ^:const optimism-chain-id 10)
(def ^:const optimism-testnet-chain-id 420)
(def ^:const ethereum-sepolia-chain-id 11155111) (def ^:const ethereum-sepolia-chain-id 11155111)
(def ^:const arbitrum-mainnet-chain-id 42161)
(def ^:const arbitrum-goerli-chain-id 421613)
(def ^:const arbitrum-sepolia-chain-id 421614) (def ^:const arbitrum-sepolia-chain-id 421614)
(def ^:const optimism-mainnet-chain-id 10)
(def ^:const optimism-goerli-chain-id 420)
(def ^:const optimism-sepolia-chain-id 11155420) (def ^:const optimism-sepolia-chain-id 11155420)
(def ^:const mainnet-short-name "eth") (def ^:const mainnet-short-name "eth")

View File

@ -70,14 +70,16 @@
{:on-success on-success}]) {:on-success on-success}])
:on-cancel nil}]]}))) :on-cancel nil}]]})))
(rf/reg-event-fx :profile.settings/toggle-sepolia-test-network (rf/reg-event-fx :profile.settings/toggle-goerli-test-network
(fn [{:keys [db]}] (fn [{:keys [db]}]
(let [value (get-in db [:profile/profile :is-sepolia-enabled?]) (let [value (get-in db [:profile/profile :is-goerli-enabled?])
on-success #(rf/dispatch [:wallet/initialize])] on-success #(rf/dispatch [:logout])]
{:fx [[:dispatch {:fx [[:ui/show-confirmation
[:profile.settings/profile-update :is-sepolia-enabled? {:content (i18n/label :t/goerli-testnet-toggle-confirmation)
(not value) :on-accept #(rf/dispatch [:profile.settings/profile-update :is-goerli-enabled?
{:on-success on-success}]]]}))) (not value)
{:on-success on-success}])
:on-cancel nil}]]})))
(rf/defn change-preview-privacy-flag (rf/defn change-preview-privacy-flag
{:events [:profile.settings/change-preview-privacy]} {:events [:profile.settings/change-preview-privacy]}

View File

@ -191,29 +191,37 @@
address)) address))
(def id->network (def id->network
{constants/ethereum-chain-id :ethereum {constants/ethereum-mainnet-chain-id :ethereum
constants/goerli-chain-id :ethereum constants/ethereum-goerli-chain-id :ethereum
constants/ethereum-sepolia-chain-id :ethereum constants/ethereum-sepolia-chain-id :ethereum
constants/optimism-chain-id :optimism constants/optimism-mainnet-chain-id :optimism
constants/optimism-testnet-chain-id :optimism constants/optimism-goerli-chain-id :optimism
constants/optimism-sepolia-chain-id :optimism constants/optimism-sepolia-chain-id :optimism
constants/arbitrum-chain-id :arbitrum constants/arbitrum-mainnet-chain-id :arbitrum
constants/arbitrum-testnet-chain-id :arbitrum constants/arbitrum-goerli-chain-id :arbitrum
constants/arbitrum-sepolia-chain-id :arbitrum}) constants/arbitrum-sepolia-chain-id :arbitrum})
(defn- get-chain-id (defn- get-chain-id
[test-net?] [testnet-enabled? goerli-enabled?]
(if test-net? (cond
{:eth constants/goerli-chain-id (and testnet-enabled? goerli-enabled?)
:opt constants/optimism-testnet-chain-id {:eth constants/ethereum-goerli-chain-id
:arb1 constants/arbitrum-testnet-chain-id} :opt constants/optimism-goerli-chain-id
{:eth constants/ethereum-chain-id :arb1 constants/arbitrum-goerli-chain-id}
:opt constants/optimism-chain-id
:arb1 constants/arbitrum-chain-id})) testnet-enabled?
{:eth constants/ethereum-sepolia-chain-id
:opt constants/optimism-sepolia-chain-id
:arb1 constants/arbitrum-sepolia-chain-id}
:else
{:eth constants/ethereum-mainnet-chain-id
:opt constants/optimism-mainnet-chain-id
:arb1 constants/arbitrum-mainnet-chain-id}))
(defn short-name->id (defn short-name->id
[short-name test-net?] [short-name testnet-enabled? goerli-enabled?]
(let [chain-id-map (get-chain-id test-net?)] (let [chain-id-map (get-chain-id testnet-enabled? goerli-enabled?)]
(get chain-id-map short-name))) (get chain-id-map short-name)))
(defn get-standard-fiat-format (defn get-standard-fiat-format

View File

@ -63,10 +63,11 @@
(fn [{:keys [db]} [{:keys [address token recipient stack-id]}]] (fn [{:keys [db]} [{:keys [address token recipient stack-id]}]]
(let [[prefix to-address] (utils/split-prefix-and-address address) (let [[prefix to-address] (utils/split-prefix-and-address address)
test-net? (get-in db [:profile/profile :test-networks-enabled?]) test-net? (get-in db [:profile/profile :test-networks-enabled?])
goerli-enabled? (get-in db [:profile/profile :is-goerli-enabled?])
prefix-seq (string/split prefix #":") prefix-seq (string/split prefix #":")
selected-networks (->> prefix-seq selected-networks (->> prefix-seq
(remove string/blank?) (remove string/blank?)
(mapv #(utils/short-name->id (keyword %) test-net?)))] (mapv #(utils/short-name->id (keyword %) test-net? goerli-enabled?)))]
{:db (-> db {:db (-> db
(assoc-in [:wallet :ui :send :recipient] (or recipient address)) (assoc-in [:wallet :ui :send :recipient] (or recipient address))
(assoc-in [:wallet :ui :send :to-address] to-address) (assoc-in [:wallet :ui :send :to-address] to-address)

View File

@ -107,10 +107,10 @@
(:test-networks-enabled? profile))) (:test-networks-enabled? profile)))
(re-frame/reg-sub (re-frame/reg-sub
:profile/is-sepolia-enabled? :profile/is-goerli-enabled?
:<- [:profile/profile] :<- [:profile/profile]
(fn [profile] (fn [profile]
(:is-sepolia-enabled? profile))) (:is-goerli-enabled? profile)))
(re-frame/reg-sub (re-frame/reg-sub
:multiaccount/contact :multiaccount/contact

View File

@ -33,16 +33,16 @@
(defn get-network-details (defn get-network-details
[chain-id] [chain-id]
(case chain-id (case chain-id
(constants/ethereum-chain-id constants/goerli-chain-id (constants/ethereum-mainnet-chain-id constants/ethereum-goerli-chain-id
constants/ethereum-sepolia-chain-id) constants/ethereum-sepolia-chain-id)
mainnet-network-details mainnet-network-details
(constants/arbitrum-chain-id constants/arbitrum-testnet-chain-id (constants/arbitrum-mainnet-chain-id constants/arbitrum-goerli-chain-id
constants/arbitrum-sepolia-chain-id) constants/arbitrum-sepolia-chain-id)
arbitrum-network-details arbitrum-network-details
(constants/optimism-chain-id constants/optimism-testnet-chain-id (constants/optimism-mainnet-chain-id constants/optimism-goerli-chain-id
constants/optimism-sepolia-chain-id) constants/optimism-sepolia-chain-id)
optimism-network-details optimism-network-details
nil)) nil))

View File

@ -66,12 +66,12 @@
(defn assert-ethereum-chains (defn assert-ethereum-chains
[response] [response]
(is (= number-of-networks (count response))) (is (= number-of-networks (count response)))
(is (some #(= constants/ethereum-chain-id (get-in % [:Prod :chainId])) response)) (is (some #(= constants/ethereum-mainnet-chain-id (get-in % [:Prod :chainId])) response))
(is (some #(= constants/optimism-chain-id (get-in % [:Prod :chainId])) response)) (is (some #(= constants/optimism-mainnet-chain-id (get-in % [:Prod :chainId])) response))
(is (some #(= constants/arbitrum-chain-id (get-in % [:Prod :chainId])) response)) (is (some #(= constants/arbitrum-mainnet-chain-id (get-in % [:Prod :chainId])) response))
(is (some #(= constants/goerli-chain-id (get-in % [:Test :chainId])) response)) (is (some #(= constants/ethereum-sepolia-chain-id (get-in % [:Test :chainId])) response))
(is (some #(= constants/arbitrum-testnet-chain-id (get-in % [:Test :chainId])) response)) (is (some #(= constants/arbitrum-sepolia-chain-id (get-in % [:Test :chainId])) response))
(is (some #(= constants/optimism-testnet-chain-id (get-in % [:Test :chainId])) response))) (is (some #(= constants/optimism-sepolia-chain-id (get-in % [:Test :chainId])) response)))
(deftest accounts-get-chains-contract (deftest accounts-get-chains-contract
(h/log-headline :contract/wallet_get-ethereum-chains) (h/log-headline :contract/wallet_get-ethereum-chains)

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>", "_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.175.3", "version": "v0.175.4",
"commit-sha1": "23ee898754f71341dc53e71657ef0633165f7bd3", "commit-sha1": "5304406079a5e3e1cfea285fef892ac56f2c3aad",
"src-sha256": "0zabdfpplzwi0dmb650cdvhrn3z7zqz70f261b3cyaxc68hc117w" "src-sha256": "08xprnmpw0nz2zjm1wp8ypjhdyfvgmh7pqrlk69prgr23xa31ady"
} }

View File

@ -2517,5 +2517,6 @@
"generating-keypair": "Generating keypair...", "generating-keypair": "Generating keypair...",
"keypair-name": "Keypair name", "keypair-name": "Keypair name",
"keypair-name-description": "Name keypair for your own personal reference", "keypair-name-description": "Name keypair for your own personal reference",
"keypair-name-input-placeholder": "Collectibles account, Old vault...." "keypair-name-input-placeholder": "Collectibles account, Old vault....",
"goerli-testnet-toggle-confirmation": "Are you sure you want to toggle Goerli? This will log you out and you will have to login again."
} }