Add a screen for debugging blocks lag
This commit is contained in:
parent
19f92413de
commit
30545f77d2
|
@ -441,6 +441,8 @@
|
||||||
(fn [chain-keyword]
|
(fn [chain-keyword]
|
||||||
(tokens/native-currency chain-keyword)))
|
(tokens/native-currency chain-keyword)))
|
||||||
|
|
||||||
|
(reg-root-key-sub :ethereum/current-block :ethereum/current-block)
|
||||||
|
|
||||||
;;MULTIACCOUNT ==============================================================================================================
|
;;MULTIACCOUNT ==============================================================================================================
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
|
|
|
@ -15,6 +15,13 @@
|
||||||
:on-press
|
:on-press
|
||||||
#(re-frame/dispatch [:navigate-to :network-settings])
|
#(re-frame/dispatch [:navigate-to :network-settings])
|
||||||
:accessories [network-name :chevron]}
|
: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
|
;; TODO - uncomment when implemented
|
||||||
;; {:type :small
|
;; {:type :small
|
||||||
;; :title :t/les-ulc
|
;; :title :t/les-ulc
|
||||||
|
|
|
@ -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]])
|
|
@ -30,6 +30,7 @@
|
||||||
:manage-dapps-permissions
|
:manage-dapps-permissions
|
||||||
:network-settings
|
:network-settings
|
||||||
:network-details
|
:network-details
|
||||||
|
:network-info
|
||||||
:edit-network
|
:edit-network
|
||||||
:log-level-settings
|
:log-level-settings
|
||||||
:fleet-settings
|
:fleet-settings
|
||||||
|
|
|
@ -64,7 +64,8 @@
|
||||||
[status-im.ui.screens.wallet.accounts.views :as wallet.accounts]
|
[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.account.views :as wallet.account]
|
||||||
[status-im.ui.screens.wallet.add-new.views :as add-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
|
(def all-screens
|
||||||
{:login login/login
|
{:login login/login
|
||||||
|
@ -170,6 +171,7 @@
|
||||||
:manage-dapps-permissions dapps-permissions/manage
|
:manage-dapps-permissions dapps-permissions/manage
|
||||||
:network-settings network/network-settings-view
|
:network-settings network/network-settings-view
|
||||||
:network-details network/network-details-view
|
:network-details network/network-details-view
|
||||||
|
:network-info network-info/network-info
|
||||||
:edit-network network/edit-network-view
|
:edit-network network/edit-network-view
|
||||||
:log-level-settings log-level-settings/log-level-settings
|
:log-level-settings log-level-settings/log-level-settings
|
||||||
:fleet-settings fleet-settings/fleet-settings
|
:fleet-settings fleet-settings/fleet-settings
|
||||||
|
|
|
@ -718,6 +718,7 @@
|
||||||
"network": "Network",
|
"network": "Network",
|
||||||
"network-chain": "Network chain",
|
"network-chain": "Network chain",
|
||||||
"network-details": "Network details",
|
"network-details": "Network details",
|
||||||
|
"network-info": "Network info",
|
||||||
"network-fee": "Network fee",
|
"network-fee": "Network fee",
|
||||||
"network-id": "Network ID",
|
"network-id": "Network ID",
|
||||||
"network-invalid-network-id": "Specified network id doesn't correspond to network id by RPC url",
|
"network-invalid-network-id": "Specified network id doesn't correspond to network id by RPC url",
|
||||||
|
|
Loading…
Reference in New Issue