Skip to content

Commit

Permalink
Add a screen for debugging blocks lag
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Jan 24, 2020
1 parent 19f9241 commit 30545f7
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/status_im/ui/screens/advanced_settings/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
85 changes: 85 additions & 0 deletions src/status_im/ui/screens/network_info/views.cljs
Original file line number Diff line number Diff line change
@@ -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]])
1 change: 1 addition & 0 deletions src/status_im/ui/screens/routing/profile_stack.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
:manage-dapps-permissions
:network-settings
:network-details
:network-info
:edit-network
:log-level-settings
:fleet-settings
Expand Down
4 changes: 3 additions & 1 deletion src/status_im/ui/screens/routing/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 30545f7

Please sign in to comment.