diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java index afc35042d4..d83d75d19e 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java @@ -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"); diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.m b/modules/react-native-status/ios/RCTStatus/RCTStatus.m index a77efbc85e..ef8dbbb99e 100644 --- a/modules/react-native-status/ios/RCTStatus/RCTStatus.m +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.m @@ -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"); diff --git a/src/status_im/ethereum/json_rpc.cljs b/src/status_im/ethereum/json_rpc.cljs index 216e1eba7b..d94fe9f363 100644 --- a/src/status_im/ethereum/json_rpc.cljs +++ b/src/status_im/ethereum/json_rpc.cljs @@ -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" {} diff --git a/src/status_im/ethereum/subscriptions.cljs b/src/status_im/ethereum/subscriptions.cljs index 1311778a14..0bcc37ba47 100644 --- a/src/status_im/ethereum/subscriptions.cljs +++ b/src/status_im/ethereum/subscriptions.cljs @@ -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) diff --git a/src/status_im/ethereum/transactions/core.cljs b/src/status_im/ethereum/transactions/core.cljs index 42aabba6c3..4df0fffbeb 100644 --- a/src/status_im/ethereum/transactions/core.cljs +++ b/src/status_im/ethereum/transactions/core.cljs @@ -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 diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index d96ac70835..7424bc60e3 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -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))))) diff --git a/src/status_im/native_module/core.cljs b/src/status_im/native_module/core.cljs index ba7d97eeb3..83e8890075 100644 --- a/src/status_im/native_module/core.cljs +++ b/src/status_im/native_module/core.cljs @@ -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))) diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 366c66b210..8d8556ceb5 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -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?) diff --git a/src/status_im/wallet/core.cljs b/src/status_im/wallet/core.cljs index 84de0f1e59..ac7cd90f0c 100644 --- a/src/status_im/wallet/core.cljs +++ b/src/status_im/wallet/core.cljs @@ -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]} diff --git a/status-go-version.json b/status-go-version.json index ce8b4da197..9ac0b34192 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -2,7 +2,7 @@ "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh ' 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" }