diff --git a/src/app/modules/main/wallet_section/transactions/controller.nim b/src/app/modules/main/wallet_section/transactions/controller.nim index d6f8247d9e..367f2f4f7b 100644 --- a/src/app/modules/main/wallet_section/transactions/controller.nim +++ b/src/app/modules/main/wallet_section/transactions/controller.nim @@ -62,8 +62,6 @@ proc init*(self: Controller) = let accounts = self.getWalletAccounts() let addresses = accounts.map(account => account.address) self.delegate.setHistoryFetchState(addresses, false) - else: - echo "Unhandled wallet signal: ", data.eventType self.events.on(SIGNAL_TRANSACTIONS_LOADED) do(e:Args): let args = TransactionsLoadedArgs(e) @@ -87,9 +85,6 @@ proc init*(self: Controller) = proc checkPendingTransactions*(self: Controller): seq[TransactionDto] = return self.transactionService.checkPendingTransactions() -proc checkRecentHistory*(self: Controller, calledFromTimerOrInit = false) = - self.walletAccountService.checkRecentHistory(calledFromTimerOrInit) - proc getWalletAccounts*(self: Controller): seq[WalletAccountDto] = self.walletAccountService.getWalletAccounts() diff --git a/src/app/modules/main/wallet_section/transactions/io_interface.nim b/src/app/modules/main/wallet_section/transactions/io_interface.nim index 2ebeb7d5dc..0e97248946 100644 --- a/src/app/modules/main/wallet_section/transactions/io_interface.nim +++ b/src/app/modules/main/wallet_section/transactions/io_interface.nim @@ -16,9 +16,6 @@ method load*(self: AccessInterface) {.base.} = method isLoaded*(self: AccessInterface): bool {.base.} = raise newException(ValueError, "No implementation available") -method checkRecentHistory*(self: AccessInterface, calledFromTimerOrInit: bool) {.base.} = - raise newException(ValueError, "No implementation available") - method switchAccount*(self: AccessInterface, accountIndex: int) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/wallet_section/transactions/module.nim b/src/app/modules/main/wallet_section/transactions/module.nim index 49e8be337e..5f7fca7633 100644 --- a/src/app/modules/main/wallet_section/transactions/module.nim +++ b/src/app/modules/main/wallet_section/transactions/module.nim @@ -58,7 +58,6 @@ method isLoaded*(self: Module): bool = return self.moduleLoaded method viewDidLoad*(self: Module) = - self.controller.checkRecentHistory(calledFromTimerOrInit = true) let accounts = self.getWalletAccounts() self.moduleLoaded = true diff --git a/src/app_service/service/wallet_account/service.nim b/src/app_service/service/wallet_account/service.nim index 2fb4f19469..09231ba01e 100644 --- a/src/app_service/service/wallet_account/service.nim +++ b/src/app_service/service/wallet_account/service.nim @@ -95,10 +95,6 @@ type KeycardActivityArgs* = ref object of Args keycardNewName*: string keyPair*: KeyPairDto -const CheckBalanceSlotExecuteIntervalInSeconds = 15 * 60 # 15 mins -const CheckBalanceTimerIntervalInMilliseconds = 5000 # 5 sec -const CheckHistoryIntervalInMilliseconds = 20 * 60 * 1000 # 20 mins - include async_tasks include ../../common/json_utils @@ -120,9 +116,9 @@ QtObject: isHistoryFetchTimerAlreadyRunning: bool # Forward declaration - proc buildAllTokens(self: Service, calledFromTimerOrInit = false) - proc startBuildingTokensTimer(self: Service, resetTimeToNow = true) - proc startFetchingHistoryTimer(self: Service, resetTimeToNow = true) + proc buildAllTokens(self: Service) + proc checkRecentHistory*(self: Service) + proc startWallet(self: Service) proc delete*(self: Service) = self.closingApp = true @@ -184,7 +180,9 @@ QtObject: account.relatedAccounts = accounts.filter(x => not account.derivedFrom.isEmptyOrWhitespace and (cmpIgnoreCase(x.derivedFrom, account.derivedFrom) == 0)) self.walletAccounts[account.address] = account - self.buildAllTokens(true) + self.buildAllTokens() + self.checkRecentHistory() + self.startWallet() except Exception as e: let errDesription = e.msg error "error: ", errDesription @@ -200,17 +198,10 @@ QtObject: self.events.on(SignalType.Wallet.event) do(e:Args): var data = WalletSignal(e) case data.eventType: - of "recent-history-ready": - # run timer again... - self.startFetchingHistoryTimer() - of "non-archival-node-detected": - # run timer again... - self.startFetchingHistoryTimer() - of "fetching-history-error": - # run timer again... - self.startFetchingHistoryTimer() - else: - echo "Unhandled wallet signal: ", data.eventType + of "wallet-tick-reload": + self.checkRecentHistory() + self.buildAllTokens() + proc getAccountByAddress*(self: Service, address: string): WalletAccountDto = if not self.walletAccounts.hasKey(address): @@ -231,14 +222,16 @@ QtObject: if(accounts[i].address == address): return i - proc checkRecentHistory*(self: Service, calledFromTimerOrInit = false) = + proc startWallet(self: Service) = + if(not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): + return - # Since we don't have a way to re-run TimerTaskArg (to stop it and run again), we introduced some flags which will - # just ignore buildAllTokens in case that proc is called by some action in the time window between two successive calls - # initiated by TimerTaskArg. - if not calledFromTimerOrInit: - self.ignoreTimeInitiatedHistoryFetchBuild = true + discard backend.startWallet() + proc checkRecentHistory*(self: Service) = + if(not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): + return + try: let addresses = self.getWalletAccounts().map(a => a.address) let chainIds = self.networkService.getNetworks().map(a => a.chainId) @@ -450,32 +443,6 @@ QtObject: data.error = e.msg self.events.emit(SIGNAL_WALLET_ACCOUNT_DERIVED_ADDRESS_DETAILS_FETCHED, data) - proc onStartBuildingTokensTimer*(self: Service, response: string) {.slot.} = - if ((now().toTime().toUnix() - self.timerStartTimeInSeconds) < CheckBalanceSlotExecuteIntervalInSeconds): - self.startBuildingTokensTimer(resetTimeToNow = false) - return - - if self.ignoreTimeInitiatedTokensBuild: - self.ignoreTimeInitiatedTokensBuild = false - return - - self.buildAllTokens(true) - - proc startBuildingTokensTimer(self: Service, resetTimeToNow = true) = - if(self.closingApp): - return - - if (resetTimeToNow): - self.timerStartTimeInSeconds = now().toTime().toUnix() - - let arg = TimerTaskArg( - tptr: cast[ByteAddress](timerTask), - vptr: cast[ByteAddress](self.vptr), - slot: "onStartBuildingTokensTimer", - timeoutInMilliseconds: CheckBalanceTimerIntervalInMilliseconds - ) - self.threadpool.start(arg) - proc onAllTokensBuilt*(self: Service, response: string) {.slot.} = try: let responseObj = response.parseJson @@ -495,19 +462,10 @@ QtObject: except Exception as e: error "error: ", procName="onAllTokensBuilt", errName = e.name, errDesription = e.msg - # run timer again... - self.startBuildingTokensTimer() - - proc buildAllTokens(self: Service, calledFromTimerOrInit = false) = - if(self.closingApp or not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): + proc buildAllTokens(self: Service) = + if(not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()): return - # Since we don't have a way to re-run TimerTaskArg (to stop it and run again), we introduced some flags which will - # just ignore buildAllTokens in case that proc is called by some action in the time window between two successive calls - # initiated by TimerTaskArg. - if not calledFromTimerOrInit: - self.ignoreTimeInitiatedTokensBuild = true - let arg = BuildTokensTaskArg( tptr: cast[ByteAddress](prepareTokensTask), vptr: cast[ByteAddress](self.vptr), @@ -517,6 +475,8 @@ QtObject: proc onIsWalletEnabledChanged*(self: Service) {.slot.} = self.buildAllTokens() + self.checkRecentHistory() + self.startWallet() proc getNetworkCurrencyBalance*(self: Service, network: NetworkDto): float64 = for walletAccount in toSeq(self.walletAccounts.values): @@ -651,28 +611,4 @@ QtObject: self.addNewAccountToLocalStore() except Exception as e: error "error: ", procName="deleteKeycard", errName = e.name, errDesription = e.msg - return "error: " & e.msg - - proc onStartHistoryFetchingTimer*(self: Service, response: string) {.slot.} = - self.isHistoryFetchTimerAlreadyRunning = false - if self.ignoreTimeInitiatedHistoryFetchBuild: - self.ignoreTimeInitiatedHistoryFetchBuild = false - return - - self.checkRecentHistory(true) - - proc startFetchingHistoryTimer(self: Service, resetTimeToNow = true) = - if(self.closingApp or - not singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled() or - self.isHistoryFetchTimerAlreadyRunning): - return - - # TODO move this to status-go, because the 20 minutes timer leaves the app hanging when trying to leave - # self.isHistoryFetchTimerAlreadyRunning = true - # let arg = TimerTaskArg( - # tptr: cast[ByteAddress](timerTask), - # vptr: cast[ByteAddress](self.vptr), - # slot: "onStartHistoryFetchingTimer", - # timeoutInMilliseconds: CheckHistoryIntervalInMilliseconds - # ) - # self.threadpool.start(arg) + return "error: " & e.msg \ No newline at end of file diff --git a/src/backend/backend.nim b/src/backend/backend.nim index 44e0d0a2a8..6af6cb55d7 100644 --- a/src/backend/backend.nim +++ b/src/backend/backend.nim @@ -91,6 +91,9 @@ rpc(getPendingTransactionsByChainIDs, "wallet"): rpc(getWalletToken, "wallet"): discard +rpc(startWallet, "wallet"): + discard + rpc(getTransactionEstimatedTime, "wallet"): chainId: int maxFeePerGas: float diff --git a/vendor/status-go b/vendor/status-go index 1501c40717..c735e2a6bb 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit 1501c4071734de0730849dd9af02f803c9d0da70 +Subproject commit c735e2a6bbef9874173378121316798d3d6fe981