diff --git a/src/mocks/js_dependencies.cljs b/src/mocks/js_dependencies.cljs index 4154a9b3a4..a4425610cd 100644 --- a/src/mocks/js_dependencies.cljs +++ b/src/mocks/js_dependencies.cljs @@ -22,6 +22,7 @@ :ReanimatedModule {:configureProps (fn [])}} :View {} + :RefreshControl {} :FlatList {} :Text {} :ProgressBarAndroid {} diff --git a/src/quo/react_native.cljs b/src/quo/react_native.cljs index 72732e6cae..3733e6fba2 100644 --- a/src/quo/react_native.cljs +++ b/src/quo/react_native.cljs @@ -17,6 +17,7 @@ (def scroll-view (reagent/adapt-react-class (.-ScrollView ^js rn))) (def modal (reagent/adapt-react-class (.-Modal ^js rn))) +(def refresh-control (reagent/adapt-react-class (.-RefreshControl ^js rn))) (def touchable-opacity (reagent/adapt-react-class (.-TouchableOpacity ^js rn))) (def touchable-highlight (reagent/adapt-react-class (.-TouchableHighlight ^js rn))) diff --git a/src/status_im/ethereum/subscriptions.cljs b/src/status_im/ethereum/subscriptions.cljs index cf477014b4..7616bd9397 100644 --- a/src/status_im/ethereum/subscriptions.cljs +++ b/src/status_im/ethereum/subscriptions.cljs @@ -66,7 +66,8 @@ (update-in [:wallet :accounts] wallet/remove-transactions-since-block blockNumber) (transactions/update-fetching-status accounts :recent? false) - (dissoc :wallet/waiting-for-recent-history?)) + (dissoc :wallet/waiting-for-recent-history? + :wallet/refreshing-history?)) :transactions/get-transfers {:chain-tokens (:wallet/all-tokens db) :addresses (reduce @@ -81,7 +82,7 @@ :before-block blockNumber :limit 20 :historical? true}} - (wallet.core/restart-wallet-service false false))) + (wallet.core/restart-wallet-service-default))) (fx/defn new-wallet-event [cofx {:keys [type blockNumber accounts newTransactions] :as event}] diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 430c763671..9a95ea97a5 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -1184,7 +1184,7 @@ (dissoc :app-in-background-since) (assoc :app-active-since now))} (mailserver/process-next-messages-request) - (wallet/restart-wallet-service true false) + (wallet/restart-wallet-service {:force-start? true}) #(when requires-bio-auth (biometric/authenticate % on-biometric-auth-result authentication-options))))) diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index ffc7679c86..a92c772f3c 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -318,7 +318,7 @@ ;;FIXME (when nodes (fleet/set-nodes :eth.contract nodes)) - (wallet/restart-wallet-service true false) + (wallet/restart-wallet-service {:force-start? true}) (if login-only? (login-only-events key-uid password save-password?) (create-only-events)) diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 4c91fe4192..abab1442f5 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -169,6 +169,7 @@ (reg-root-key-sub :wallet-service/state :wallet-service/state) (reg-root-key-sub :wallet/recipient :wallet/recipient) (reg-root-key-sub :wallet/favourites :wallet/favourites) +(reg-root-key-sub :wallet/refreshing-history? :wallet/refreshing-history?) ;;commands (reg-root-key-sub :commands/select-account :commands/select-account) diff --git a/src/status_im/ui/screens/mobile_network_settings/events.cljs b/src/status_im/ui/screens/mobile_network_settings/events.cljs index f7e19997b9..f3c50af79c 100644 --- a/src/status_im/ui/screens/mobile_network_settings/events.cljs +++ b/src/status_im/ui/screens/mobile_network_settings/events.cljs @@ -37,7 +37,7 @@ logged-in? [(mailserver/process-next-messages-request) (bottom-sheet/hide-bottom-sheet) - (wallet/restart-wallet-service false false)])))) + (wallet/restart-wallet-service-default)])))) (defn apply-settings ([sync?] (apply-settings sync? :default)) @@ -62,7 +62,7 @@ (bottom-sheet/hide-bottom-sheet) (when (and cellular? sync?) (mailserver/process-next-messages-request)) - (wallet/restart-wallet-service false false)))))) + (wallet/restart-wallet-service-default)))))) (handlers/register-handler-fx :mobile-network/continue-syncing diff --git a/src/status_im/ui/screens/wallet/account/views.cljs b/src/status_im/ui/screens/wallet/account/views.cljs index 144718ca0d..d390bb9036 100644 --- a/src/status_im/ui/screens/wallet/account/views.cljs +++ b/src/status_im/ui/screens/wallet/account/views.cljs @@ -16,7 +16,9 @@ [status-im.ui.screens.wallet.transactions.views :as history] [status-im.utils.money :as money] [status-im.wallet.utils :as wallet.utils] - [status-im.ui.components.tabs :as tabs]) + [status-im.ui.components.tabs :as tabs] + [quo.react-native :as rn] + [status-im.utils.utils :as utils.utils]) (:require-macros [status-im.utils.views :as views])) (def state (reagent/atom {:tab :assets})) @@ -185,6 +187,29 @@ (styles/bottom-send-recv-buttons-lower anim-y button-group-height) #(reset! to-show false)))))))) +;; Note(rasom): sometimes `refreshing` might get stuck on iOS if action happened +;; too fast. By updating this atom in 1s we ensure that `refreshing?` property +;; is updated properly in this case. +(def updates-counter (reagent/atom 0)) + +(defn schedule-counter-reset [] + (utils.utils/set-timeout + (fn [] + (swap! updates-counter inc) + (when @(re-frame/subscribe [:wallet/refreshing-history?]) + (schedule-counter-reset))) + 1000)) + +(defn refresh-action [] + (schedule-counter-reset) + (re-frame/dispatch [:wallet.ui/pull-to-refresh-history])) + +(defn refresh-control [refreshing?] + (reagent/as-element + [rn/refresh-control + {:refreshing (boolean refreshing?) + :onRefresh refresh-action}])) + (views/defview account [] (views/letsubs [{:keys [name address] :as account} [:multiaccount/current-account]] (let [anim-y (animation/create-value button-group-height) @@ -197,7 +222,11 @@ :on-scroll (animation/event [{:nativeEvent {:contentOffset {:y scroll-y}}}] {:useNativeDriver true}) - :scrollEventThrottle 1} + :scrollEventThrottle 1 + :refreshControl (refresh-control + (and + @updates-counter + @(re-frame/subscribe [:wallet/refreshing-history?])))} [react/view {:padding-left 16} [react/scroll-view {:horizontal true} [react/view {:flex-direction :row :padding-top 8 :padding-bottom 12} diff --git a/src/status_im/ui/screens/wallet/transactions/views.cljs b/src/status_im/ui/screens/wallet/transactions/views.cljs index 8600605cbf..ca160d33ef 100644 --- a/src/status_im/ui/screens/wallet/transactions/views.cljs +++ b/src/status_im/ui/screens/wallet/transactions/views.cljs @@ -10,8 +10,7 @@ [status-im.ui.components.topbar :as topbar] [status-im.ui.screens.wallet.transactions.styles :as styles] [quo.core :as quo] - [status-im.ui.components.toolbar :as toolbar] - [status-im.wallet.core :as wallet]) + [status-im.ui.components.toolbar :as toolbar]) (:require-macros [status-im.utils.views :refer [defview letsubs]])) (defn- transaction-icon @@ -105,20 +104,6 @@ {:style {:color colors/blue}} (i18n/label :t/check-on-etherscan)]]])) -(defn refresh [] - [react/touchable-highlight - {:on-press #(re-frame/dispatch [::wallet/restart])} - [react/view - {:style {:flex 1 - :padding-horizontal 14 - :flex-direction :row - :align-items :center - :background-color colors/blue-light - :height 52}} - [react/text - {:style {:color colors/blue}} - (i18n/label :t/refresh)]]]) - (defn history-list [transactions-history-sections address] (let [fetching-recent-history? @(re-frame/subscribe [:wallet/fetching-recent-tx-history? address]) @@ -126,7 +111,6 @@ all-fetched? @(re-frame/subscribe [:wallet/tx-history-fetched? address])] [react/view components.styles/flex [etherscan-link address] - [refresh] (when fetching-recent-history? [react/view {:style {:flex 1 @@ -142,8 +126,7 @@ [react/i18n-text {:style styles/empty-text :key (if (or fetching-recent-history? fetching-more-history?) :transactions-history-loading - :transactions-history-empty)}] - :refreshing false}] + :transactions-history-empty)}]}] (when (and (not fetching-recent-history?) (not all-fetched?)) (if fetching-more-history? diff --git a/src/status_im/wallet/core.cljs b/src/status_im/wallet/core.cljs index fd0dc4d6b8..963db52642 100644 --- a/src/status_im/wallet/core.cljs +++ b/src/status_im/wallet/core.cljs @@ -576,7 +576,8 @@ [old-timeout]})) (fx/defn restart-wallet-service - [{:keys [db] :as cofx} force-start? watch-new-blocks?] + [{:keys [db] :as cofx} + {:keys [force-start? watch-new-blocks? ignore-syncing-settings?]}] (when (or force-start? (:multiaccount db)) (let [watching-txs? (get db :wallet/watch-txs) waiting? (get db :wallet/waiting-for-recent-history?) @@ -586,7 +587,8 @@ "watching-txs?" watching-txs? "syncing-allowed?" syncing-allowed? "watch-new-blocks?" watch-new-blocks?) - (if (and syncing-allowed? + (if (and (or syncing-allowed? + ignore-syncing-settings?) (or waiting? force-start? @@ -594,12 +596,32 @@ (start-wallet cofx (boolean (or watch-new-blocks? watching-txs?))) (stop-wallet cofx))))) +(fx/defn restart-wallet-service-default + [cofx] + (restart-wallet-service cofx nil)) + (fx/defn restart {:events [::restart]} [{:keys [db] :as cofx}] - (fx/merge - {:db (dissoc db :wallet-service/restart-timeout)} - (restart-wallet-service true false))) + (restart-wallet-service cofx {:force-start? true})) + +(def pull-to-refresh-cooldown-period (* 1 60 1000)) + +(fx/defn restart-on-pull + {:events [:wallet.ui/pull-to-refresh-history]} + [{:keys [db now] :as cofx}] + (let [last-pull (get db :wallet/last-pull-time) + watching? (get db :wallet/watch-txs)] + (when (and (not watching?) + (or (not last-pull) + (> (- now last-pull) pull-to-refresh-cooldown-period))) + (fx/merge + {:db (assoc db + :wallet/last-pull-time now + :wallet/refreshing-history? true)} + (restart-wallet-service + {:force-start? true + :ignore-syncing-settings? true}))))) (fx/defn watch-tx {:events [:watch-tx]} @@ -616,7 +638,8 @@ (assoc :wallet/watch-txs-timeout timeout)) ::utils.utils/clear-timeouts [old-timeout]} - (restart-wallet-service true true)))) + (restart-wallet-service {:force-start? true + :watch-new-blocks? true})))) (fx/defn stop-watching-txs {:events [::stop-watching-txs]} @@ -625,7 +648,7 @@ {:db (dissoc db :wallet/watch-txs :wallet/watch-txs-timeout)} - (restart-wallet-service false false))) + (restart-wallet-service-default))) (fx/defn stop-watching-tx [{:keys [db] :as cofx} tx]