diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 3cf89572d2..67b4a205c6 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -441,6 +441,8 @@ (fn [chain-keyword] (tokens/native-currency chain-keyword))) +(reg-root-key-sub :ethereum/current-block :ethereum/current-block) + ;;MULTIACCOUNT ============================================================================================================== (re-frame/reg-sub diff --git a/src/status_im/ui/screens/advanced_settings/views.cljs b/src/status_im/ui/screens/advanced_settings/views.cljs index ade98b1aab..ec8f9f353c 100644 --- a/src/status_im/ui/screens/advanced_settings/views.cljs +++ b/src/status_im/ui/screens/advanced_settings/views.cljs @@ -15,6 +15,13 @@ :on-press #(re-frame/dispatch [:navigate-to :network-settings]) :accessories [network-name :chevron]} + {:type :small + :title :t/network-info + :accessibility-label :network-button + :container-margin-top 8 + :on-press + #(re-frame/dispatch [:navigate-to :network-info]) + :accessories [:chevron]} ;; TODO - uncomment when implemented ;; {:type :small ;; :title :t/les-ulc diff --git a/src/status_im/ui/screens/network_info/views.cljs b/src/status_im/ui/screens/network_info/views.cljs new file mode 100644 index 0000000000..85f9808426 --- /dev/null +++ b/src/status_im/ui/screens/network_info/views.cljs @@ -0,0 +1,85 @@ +(ns status-im.ui.screens.network-info.views + (:require [status-im.ui.components.topbar :as topbar] + [status-im.ui.components.react :as react] + [re-frame.core :as re-frame] + [status-im.ui.components.styles :as components.styles] + [reagent.core :as reagent] + [status-im.ethereum.json-rpc :as json-rpc] + [status-im.ethereum.decode :as decode] + [status-im.ethereum.abi-spec :as abi-spec] + [status-im.utils.datetime :as time])) + +(defn get-block [block callback] + (json-rpc/call + {:method "eth_getBlockByNumber" + :params [block false] + :on-success callback + :on-error #(js/alert (str "can't fetch latest block" %))})) + +(defn last-loaded-block-number [] + @(re-frame/subscribe [:ethereum/current-block])) + +(defn to-date [timestamp] + (time/timestamp->long-date + (* 1000 timestamp))) + +(defn check-lag [] + (let [latest-block (reagent/atom nil) + last-loaded-block (reagent/atom nil) + on-press + (fn [] + (get-block + "latest" + (fn [res] + (reset! latest-block res) + (get-block + (str "0x" (abi-spec/number-to-hex + (last-loaded-block-number))) + (fn [res] + (reset! last-loaded-block res))))))] + (fn [] + [react/view + {:style {:flex 1 + :margin-horizontal 16}} + (if-not @latest-block + [react/text + {:on-press on-press} + "PRESS TO REFRESH"] + [react/text + {:on-press on-press} + (let [latest-block-number + (decode/uint (:number @latest-block)) + + latest-block-timestamp + (decode/uint (:timestamp @latest-block)) + + last-loaded-block-number + (decode/uint (:number @last-loaded-block)) + + last-loaded-block-timestamp + (decode/uint (:timestamp @last-loaded-block))] + (str "Latest block number: " + latest-block-number + "\n" + "Latest block time: " + (to-date latest-block-timestamp) + "\n" + "Last loaded block: " + last-loaded-block-number + "\n" + "Last loaded block time: " + (to-date last-loaded-block-timestamp) + "\n" + "Seconds diff: " (- latest-block-timestamp + last-loaded-block-timestamp) + "\n" + "Blocks diff: " (- latest-block-number + last-loaded-block-number) + "\n" + "PRESS TO REFRESH"))])]))) + +(defn network-info [] + [react/view components.styles/flex + [topbar/topbar + {:title :t/network-info}] + [check-lag]]) diff --git a/src/status_im/ui/screens/routing/profile_stack.cljs b/src/status_im/ui/screens/routing/profile_stack.cljs index 5db35818c3..ccc6cb1198 100644 --- a/src/status_im/ui/screens/routing/profile_stack.cljs +++ b/src/status_im/ui/screens/routing/profile_stack.cljs @@ -30,6 +30,7 @@ :manage-dapps-permissions :network-settings :network-details + :network-info :edit-network :log-level-settings :fleet-settings diff --git a/src/status_im/ui/screens/routing/screens.cljs b/src/status_im/ui/screens/routing/screens.cljs index 1c1fe6964d..9dadd52eaf 100644 --- a/src/status_im/ui/screens/routing/screens.cljs +++ b/src/status_im/ui/screens/routing/screens.cljs @@ -64,7 +64,8 @@ [status-im.ui.screens.wallet.accounts.views :as wallet.accounts] [status-im.ui.screens.wallet.account.views :as wallet.account] [status-im.ui.screens.wallet.add-new.views :as add-account] - [status-im.ui.screens.wallet.account-settings.views :as account-settings])) + [status-im.ui.screens.wallet.account-settings.views :as account-settings] + [status-im.ui.screens.network-info.views :as network-info])) (def all-screens {:login login/login @@ -170,6 +171,7 @@ :manage-dapps-permissions dapps-permissions/manage :network-settings network/network-settings-view :network-details network/network-details-view + :network-info network-info/network-info :edit-network network/edit-network-view :log-level-settings log-level-settings/log-level-settings :fleet-settings fleet-settings/fleet-settings diff --git a/translations/en.json b/translations/en.json index 1672b3ce98..90ac8f8833 100644 --- a/translations/en.json +++ b/translations/en.json @@ -718,6 +718,7 @@ "network": "Network", "network-chain": "Network chain", "network-details": "Network details", + "network-info": "Network info", "network-fee": "Network fee", "network-id": "Network ID", "network-invalid-network-id": "Specified network id doesn't correspond to network id by RPC url",