[wallet] cleanup

This commit is contained in:
Roman Volosovskyi 2021-04-02 13:10:48 +03:00
parent 965438bc87
commit 2116847fc6
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
10 changed files with 50 additions and 133 deletions

View File

@ -1139,18 +1139,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
Statusgo.appStateChange(type);
}
@ReactMethod
public void stopWallet() {
Log.d(TAG, "StopWallet");
Statusgo.stopWallet();
}
@ReactMethod
public void startWallet(final boolean watchNewBlocks) {
Log.d(TAG, "StartWallet");
Statusgo.startWallet(watchNewBlocks);
}
@ReactMethod
public void stopLocalNotifications() {
Log.d(TAG, "stopLocalNotifications");

View File

@ -771,20 +771,6 @@ RCT_EXPORT_METHOD(appStateChange:(NSString *)type) {
StatusgoAppStateChange(type);
}
RCT_EXPORT_METHOD(stopWallet) {
#if DEBUG
NSLog(@"StopWallet() method called");
#endif
StatusgoStopWallet();
}
RCT_EXPORT_METHOD(startWallet:(BOOL)watchNewBlocks) {
#if DEBUG
NSLog(@"StartWallet() method called");
#endif
StatusgoStartWallet(watchNewBlocks);
}
RCT_EXPORT_METHOD(stopLocalNotifications) {
#if DEBUG
NSLog(@"StopLocalNotifications() method called");

View File

@ -136,19 +136,17 @@
"rpcstats_reset" {}
"localnotifications_switchWalletNotifications" {}
"localnotifications_notificationPreferences" {}
"wallet_getTransfers" {}
"wallet_getTokensBalances" {}
"wallet_setInitialBlocksRange" {}
"wallet_getBlocksByAddress" {}
"wallet_getTransfersFromBlock" {}
"wallet_getTransfersByAddress" {}
"wallet_watchTransaction" {}
"wallet_checkRecentHistory" {}
"wallet_getTokensBalances" {}
"wallet_getCustomTokens" {}
"wallet_addCustomToken" {}
"wallet_addFavourite" {}
"wallet_getFavourites" {}
"wallet_deleteCustomToken" {}
"wallet_getCryptoOnRamps" {}
"wallet_watchTransaction" {}
"browsers_getBrowsers" {}
"browsers_addBrowser" {}
"browsers_deleteBrowser" {}

View File

@ -21,40 +21,12 @@
[{:keys [db]} id handler]
{:db (assoc-in db [:ethereum/subscriptions id] handler)})
(fx/defn max-known-block
[{:keys [db]} block-number]
{:db (assoc db :wallet/max-known-block block-number)})
(fx/defn new-block
[{:keys [db] :as cofx} historical? block-number accounts transactions-per-account]
(log/debug "[wallet-subs] new-block"
(fx/defn new-transfers
[{:keys [db] :as cofx} block-number accounts]
(log/debug "[wallet-subs] new-transfers"
"accounts" accounts
"block" block-number
"transactions-per-account" transactions-per-account
"max-known-block" (:wallet/max-known-block db))
(when (>= block-number (:wallet/max-known-block db))
(fx/merge cofx
(cond-> {}
(not historical?)
(assoc :db (assoc db :ethereum/current-block block-number))
;;NOTE only get transfers if the new block contains some
;; from/to one of the multiaccount accounts
(not-empty accounts)
(assoc :transactions/get-transfers
{:chain-tokens (:wallet/all-tokens db)
:addresses accounts
:before-block block-number
:historical? historical?}))
(transactions/check-watched-transactions))))
(fx/defn reorg
[{:keys [db] :as cofx} {:keys [blockNumber accounts]}]
(log/debug "[wallet-subs] reorg"
"accounts" accounts
"block-number" blockNumber)
{:db (update-in db [:wallet :transactions]
wallet/remove-transactions-since-block blockNumber)})
"block" block-number)
(transactions/check-watched-transactions cofx))
(fx/defn recent-history-fetching-started
[{:keys [db]} accounts]
@ -76,6 +48,7 @@
(fx/merge
cofx
{:db (-> db
(assoc :ethereum/current-block blockNumber)
(update-in [:wallet :accounts]
wallet/remove-transactions-since-block blockNumber)
(transactions/update-fetching-status accounts :recent? false)
@ -95,8 +68,7 @@
[]
accounts)
:before-block blockNumber
:limit 20
:historical? true}}
:limit 20}}
(wallet.core/restart-wallet-service-default)))
(fx/defn fetching-error
@ -104,7 +76,7 @@
(fx/merge
cofx
{:db (assoc db :wallet/fetching-error message)}
(wallet.core/stop-wallet)))
(wallet.core/after-checking-history)))
(fx/defn non-archival-node-detected
[{:keys [db] :as cofx} _]
@ -112,13 +84,12 @@
(fx/defn new-wallet-event
[cofx {:keys [type blockNumber accounts newTransactions] :as event}]
(log/debug "[wallet-subs] new-wallet-event"
"event-type" type)
(log/info "[wallet-subs] new-wallet-event"
"event-type" type
"blockNumber" blockNumber
"accounts" accounts)
(case type
"newblock" (new-block cofx false blockNumber accounts newTransactions)
"history" (new-block cofx true blockNumber accounts nil)
"maxKnownBlock" (max-known-block cofx blockNumber)
"reorg" (reorg cofx event)
"new-transfers" (new-transfers cofx blockNumber accounts)
"recent-history-fetching" (recent-history-fetching-started cofx accounts)
"recent-history-ready" (recent-history-fetching-ended cofx event)
"fetching-history-error" (fetching-error cofx event)

View File

@ -329,7 +329,6 @@
{:chain-tokens (:wallet/all-tokens db)
:addresses [address]
:before-block min-known-block
:historical? true
:fetch-more? (utils.mobile-sync/syncing-allowed? cofx)
;; Transfers are requested before and including `min-known-block` because
;; there is no guarantee that all transfers from that block are shown

View File

@ -95,6 +95,8 @@
:else
(wallet/update-balances nil scan-all-tokens?))
(when-not (get db :wallet/new-account)
(wallet/restart-wallet-service {:force-start? true}))
(when-not (utils.mobile-sync/syncing-allowed? cofx)
(transactions/get-fetched-transfers))
(prices/update-prices)))
@ -360,10 +362,9 @@
;;FIXME
(when nodes
(fleet/set-nodes :eth.contract nodes))
(if (and (not login-only?)
(not recovered-account?))
(wallet/set-initial-blocks-range)
(wallet/restart-wallet-service {:force-start? true}))
(when (and (not login-only?)
(not recovered-account?))
(wallet/set-initial-blocks-range))
(if login-only?
(login-only-events key-uid password save-password?)
(create-only-events)))))

View File

@ -273,15 +273,6 @@
(log/debug "[native-module] app-state-change")
(.appStateChange ^js (status) state))
(defn stop-wallet []
(log/debug "[native-module] stop-wallet")
(.stopWallet ^js (status)))
(defn start-wallet [watch-new-blocks?]
(log/debug "[native-module] start-wallet" watch-new-blocks?)
(when (status)
(.startWallet ^js (status) watch-new-blocks?)))
(defn stop-local-notifications []
(log/debug "[native-module] stop-local-notifications")
(.stopLocalNotifications ^js (status)))

View File

@ -155,7 +155,6 @@
(reg-root-key-sub :wallet/custom-token-screen :wallet/custom-token-screen)
(reg-root-key-sub :wallet/prepare-transaction :wallet/prepare-transaction)
(reg-root-key-sub :wallet-service/manual-setting :wallet-service/manual-setting)
(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?)

View File

@ -22,7 +22,6 @@
[status-im.bottom-sheet.core :as bottom-sheet]
[status-im.wallet.prices :as prices]
[status-im.wallet.utils :as wallet.utils]
[status-im.native-module.core :as status]
[status-im.utils.mobile-sync :as mobile-network-utils]
[status-im.utils.datetime :as datetime]
status-im.wallet.recipient.core
@ -556,16 +555,14 @@
:on-cancel #()}})
(re-frame/reg-fx
::stop-wallet
(fn []
(log/info "stop-wallet fx")
(status/stop-wallet)))
(re-frame/reg-fx
::start-wallet
(fn [watch-new-blocks?]
(log/info "start-wallet fx" watch-new-blocks?)
(status/start-wallet watch-new-blocks?)))
::check-recent-history
(fn [addresses]
(log/info "[wallet] check recent history" addresses)
(json-rpc/call
{:method "wallet_checkRecentHistory"
:params [addresses]
:on-success #(log/info "[wallet] wallet_checkRecentHistory success")
:on-error #(log/error "[wallet] wallet_checkRecentHistory error" %)})))
(def ms-10-min (datetime/minutes 10))
(def ms-20-min (datetime/minutes 20))
@ -605,60 +602,46 @@
ms-2-min
ms-10-min))
(fx/defn stop-wallet
(fx/defn after-checking-history
[{:keys [db] :as cofx}]
(let [state (get db :wallet-service/state)
old-timeout (get db :wallet-service/restart-timeout)
timeout (or
old-timeout
(when-let [interval (get-restart-interval db)]
(utils.utils/set-timeout
#(re-frame.core/dispatch [::restart])
interval)))
max-known-block (get db :wallet/max-known-block 0)]
{:db (-> db
(assoc :wallet-service/state :stopped)
(assoc :wallet/max-known-block max-known-block)
(assoc :wallet-service/restart-timeout timeout)
(dissoc :wallet/recent-history-fetching-started?
:wallet/waiting-for-recent-history?
:wallet/refreshing-history?))
::stop-wallet nil}))
(log/info "[wallet] after-checking-history")
{:db (dissoc db
:wallet/recent-history-fetching-started?
:wallet/waiting-for-recent-history?
:wallet/refreshing-history?)})
(fx/defn start-wallet
[{:keys [db] :as cofx} watch-new-blocks? on-recent-history-fetching]
(let [old-timeout (get db :wallet-service/restart-timeout)
state (get db :wallet-service/state)
(fx/defn check-recent-history
[{:keys [db] :as cofx} on-recent-history-fetching]
(let [addresses (map :address (get db :multiaccount/accounts))
old-timeout (get db :wallet-service/restart-timeout)
timeout (when-let [interval (get-restart-interval db)]
(utils.utils/set-timeout
#(re-frame.core/dispatch [::restart])
interval))]
{:db (-> db
(assoc :wallet-service/state :started
:wallet-service/restart-timeout timeout
(assoc :wallet-service/restart-timeout timeout
:wallet/was-started? true
:wallet/on-recent-history-fetching on-recent-history-fetching))
::start-wallet watch-new-blocks?
::check-recent-history addresses
::utils.utils/clear-timeouts
[old-timeout]}))
(fx/defn restart-wallet-service
[{:keys [db] :as cofx}
{:keys [force-start? watch-new-blocks? ignore-syncing-settings? on-recent-history-fetching]}]
{:keys [force-start? ignore-syncing-settings? on-recent-history-fetching]}]
(when (or force-start? (:multiaccount db))
(let [waiting? (get db :wallet/waiting-for-recent-history?)
syncing-allowed? (mobile-network-utils/syncing-allowed? cofx)]
(log/info "restart-wallet-service"
"force-start?" force-start?
"syncing-allowed?" syncing-allowed?
"watch-new-blocks?" watch-new-blocks?)
"syncing-allowed?" syncing-allowed?)
(if (and (or syncing-allowed?
ignore-syncing-settings?)
(or
waiting?
force-start?))
(start-wallet cofx (boolean watch-new-blocks?) on-recent-history-fetching)
(stop-wallet cofx)))))
(check-recent-history cofx on-recent-history-fetching)
(after-checking-history cofx)))))
(def background-cooldown-time (datetime/minutes 3))
@ -828,7 +811,8 @@
(fx/defn set-initial-blocks-range
[{:keys [db]}]
{::set-inital-range nil})
{:db (assoc db :wallet/new-account true)
::set-inital-range nil})
(fx/defn tab-opened
{:events [:wallet/tab-opened]}

View File

@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "v0.74.2",
"commit-sha1": "1724ecffa178e9bcb04ae6d9d95d276c02878b6f",
"src-sha256": "1kn6996brpva1bdj8bv1mscwx17hynqk8xb667ai6qpdriscr22d"
"version": "v0.75.0",
"commit-sha1": "27f5ad23cf7e34e390d1bc48a0cef0b45d7286a3",
"src-sha256": "01l9nblb900br78g6yxcs4f2nfcv7kkhgq0v97g026fihpqpdq2r"
}