[wallet] Pull to refresh tx history
This commit is contained in:
parent
64840f74a7
commit
92aaa194a8
|
@ -22,6 +22,7 @@
|
|||
:ReanimatedModule {:configureProps (fn [])}}
|
||||
|
||||
:View {}
|
||||
:RefreshControl {}
|
||||
:FlatList {}
|
||||
:Text {}
|
||||
:ProgressBarAndroid {}
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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}]
|
||||
|
|
|
@ -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)))))
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue