diff --git a/src/status_im/chat/views/toolbar_content.cljs b/src/status_im/chat/views/toolbar_content.cljs index 703edea65d..4d9f33dc91 100644 --- a/src/status_im/chat/views/toolbar_content.cljs +++ b/src/status_im/chat/views/toolbar_content.cljs @@ -1,4 +1,5 @@ (ns status-im.chat.views.toolbar-content + (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch]] [clojure.string :as str] [cljs-time.core :as t] @@ -25,12 +26,24 @@ (label :t/active-unknown))) :else (label :t/active-unknown))) -(defn last-activity [{:keys [online-text sync-state]}] +(defn in-progress-text [{:keys [highestBlock currentBlock startBlock]}] + (let [total (- highestBlock startBlock) + ready (- currentBlock startBlock) + percentage (if (zero? ready) + 0 + (->> (/ ready total) + (* 100) + (.round js/Math)))] + + (str (label :t/sync-in-progress) " " percentage "% " currentBlock))) + +(defview last-activity [{:keys [online-text sync-state]}] + [state [:get :sync-data]] [refreshable-text {:style st/last-activity :text-style (get-in platform-specific [:component-styles :toolbar-last-activity]) :font :default :value (case sync-state - :in-progress (label :t/sync-in-progress) + :in-progress (in-progress-text state) :synced (label :t/sync-synced) online-text)}]) diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index 423b883b54..f3368749e0 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -51,8 +51,9 @@ (register-handler :update-sync-state (u/side-effect! - (fn [{:keys [sync-state]} [_ error sync]] - (let [{:keys [highestBlock currentBlock]} (js->clj sync :keywordize-keys true) + (fn [{:keys [sync-state sync-data]} [_ error sync]] + (let [{:keys [highestBlock currentBlock] :as state} + (js->clj sync :keywordize-keys true) syncing? (> (- highestBlock currentBlock) blocks-per-hour) new-state (cond error :offline @@ -63,6 +64,8 @@ (= sync-state :pending)) :done :synced))] + (when (and (not= sync-data state) (= :in-progress new-state)) + (dispatch [:set :sync-data state])) (when (not= sync-state new-state) (dispatch [:set :sync-state new-state]))))))