-
Notifications
You must be signed in to change notification settings - Fork 57
Refactor OnstartAsyncService with modular runners #1539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1a52f89
Refactor OnstartAsyncService with modular runners
gemdev111 e299a68
Merge branch 'main' into onstartasync-updates
gemdev111 3e242ec
Refactor device update logic and remove DeviceUpdateRunner
gemdev111 f01d9b9
Combine SwapAssetsUpdateRunner and SwappableAssetsRunner into SwapAss…
gemdev111 709dadf
Refactor async runners and asset update logic
gemdev111 edbbbc1
Merge branch 'main' into onstartasync-updates
gemdev111 4e1e20e
Update core
gemdev111 4cec9d3
Remove runner execution order test and helpers
gemdev111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,9 @@ import Components | |
| import DeviceService | ||
| import EventPresenterService | ||
| import Foundation | ||
| import GemstonePrimitives | ||
| import LockManager | ||
| import Localization | ||
| import NameService | ||
| import Onboarding | ||
| import Primitives | ||
| import SwiftUI | ||
|
|
@@ -16,20 +16,21 @@ import TransactionsService | |
| import WalletConnector | ||
| import WalletService | ||
| import WalletsService | ||
| import NameService | ||
| import AvatarService | ||
|
|
||
| @Observable | ||
| @MainActor | ||
| final class RootSceneViewModel { | ||
| private let onstartAsyncService: OnstartAsyncService | ||
| private let onstartWalletService: OnstartWalletService | ||
| private let transactionStateService: TransactionStateService | ||
| private let connectionsService: ConnectionsService | ||
| private let deviceObserverService: DeviceObserverService | ||
| private let notificationHandler: NotificationHandler | ||
| private let walletsService: WalletsService | ||
| private let releaseAlertService: ReleaseAlertService | ||
| private let rateService: RateService | ||
| private let eventPresenterService: EventPresenterService | ||
| private let deviceService: DeviceService | ||
|
|
||
| let walletService: WalletService | ||
| let nameService: NameService | ||
|
|
@@ -66,7 +67,6 @@ final class RootSceneViewModel { | |
|
|
||
| init( | ||
| walletConnectorPresenter: WalletConnectorPresenter, | ||
| onstartAsyncService: OnstartAsyncService, | ||
| onstartWalletService: OnstartWalletService, | ||
| transactionStateService: TransactionStateService, | ||
| connectionsService: ConnectionsService, | ||
|
|
@@ -76,11 +76,13 @@ final class RootSceneViewModel { | |
| walletService: WalletService, | ||
| walletsService: WalletsService, | ||
| nameService: NameService, | ||
| releaseAlertService: ReleaseAlertService, | ||
| rateService: RateService, | ||
| eventPresenterService: EventPresenterService, | ||
| avatarService: AvatarService | ||
| avatarService: AvatarService, | ||
| deviceService: DeviceService | ||
| ) { | ||
| self.walletConnectorPresenter = walletConnectorPresenter | ||
| self.onstartAsyncService = onstartAsyncService | ||
| self.onstartWalletService = onstartWalletService | ||
| self.transactionStateService = transactionStateService | ||
| self.connectionsService = connectionsService | ||
|
|
@@ -90,26 +92,24 @@ final class RootSceneViewModel { | |
| self.walletService = walletService | ||
| self.walletsService = walletsService | ||
| self.nameService = nameService | ||
| self.releaseAlertService = releaseAlertService | ||
| self.rateService = rateService | ||
| self.eventPresenterService = eventPresenterService | ||
| self.avatarService = avatarService | ||
| self.deviceService = deviceService | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Business Logic | ||
|
|
||
| extension RootSceneViewModel { | ||
| func setup() { | ||
| onstartAsyncService.releaseAction = { [weak self] in | ||
| self?.setupUpdateReleaseAlert($0) | ||
| } | ||
| onstartAsyncService.setup() | ||
| rateService.perform() | ||
| Task { await checkForUpdate() } | ||
| Task { try await deviceService.update() } | ||
| transactionStateService.setup() | ||
| Task { | ||
| try await connectionsService.setup() | ||
| } | ||
| Task { | ||
| try await deviceObserverService.startSubscriptionsObserver() | ||
| } | ||
| Task { try await connectionsService.setup() } | ||
| Task { try await deviceObserverService.startSubscriptionsObserver() } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -158,49 +158,48 @@ extension RootSceneViewModel { | |
| isPresentingConnectorError = error.localizedDescription | ||
| } | ||
| } | ||
|
|
||
| private func setupUpdateReleaseAlert(_ release: Release) { | ||
| } | ||
|
|
||
| // MARK: - Private | ||
|
|
||
| extension RootSceneViewModel { | ||
| private func setup(wallet: Wallet) { | ||
| onstartWalletService.setup(wallet: wallet) | ||
| do { | ||
| try walletsService.setup(wallet: wallet) | ||
| } catch { | ||
| debugLog("RootSceneViewModel setupWallet error: \(error)") | ||
| } | ||
| } | ||
|
|
||
| private func checkForUpdate() async { | ||
| guard let release = await releaseAlertService.checkForUpdate() else { return } | ||
| updateVersionAlertMessage = makeUpdateAlert(for: release) | ||
| } | ||
|
Comment on lines
+175
to
+178
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the proposed change in private func checkForUpdate() async {
do {
guard let release = try await releaseAlertService.checkForUpdate() else { return }
updateVersionAlertMessage = makeUpdateAlert(for: release)
} catch {
debugLog("Failed to check for app update: \(error)")
}
} |
||
|
|
||
| private func makeUpdateAlert(for release: Release) -> AlertMessage { | ||
| let skipAction = AlertAction( | ||
| title: Localized.Common.skip, | ||
| role: .cancel, | ||
| action: { [weak self] in | ||
| Task { @MainActor in | ||
| self?.onstartAsyncService.skipRelease(release.version) | ||
| } | ||
| action: { [releaseAlertService] in | ||
| releaseAlertService.skipRelease(release) | ||
| } | ||
| ) | ||
| let updateAction = AlertAction( | ||
| title: Localized.UpdateApp.action, | ||
| isDefaultAction: true, | ||
| action: { | ||
| action: { [releaseAlertService] in | ||
| Task { @MainActor in | ||
| UIApplication.shared.open(PublicConstants.url(.appStore)) | ||
| releaseAlertService.openAppStore() | ||
| } | ||
| } | ||
| ) | ||
| let actions = if release.upgradeRequired { | ||
| [updateAction] | ||
| } else { | ||
| [skipAction, updateAction] | ||
| } | ||
|
|
||
| updateVersionAlertMessage = AlertMessage( | ||
| let actions = release.upgradeRequired ? [updateAction] : [skipAction, updateAction] | ||
|
|
||
| return AlertMessage( | ||
| title: Localized.UpdateApp.title, | ||
| message: Localized.UpdateApp.description(release.version), | ||
| actions: actions | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Private | ||
|
|
||
| extension RootSceneViewModel { | ||
| private func setup(wallet: Wallet) { | ||
| onstartWalletService.setup(wallet: wallet) | ||
| do { | ||
| try walletsService.setup(wallet: wallet) | ||
| } catch { | ||
| debugLog("RootSceneViewModel setupWallet error: \(error)") | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
assetStoreis being passed toImportAssetsServicehere, butassetsService(passed on the previous line) already contains a publicassetStoreproperty. This is redundant. For cleaner dependency injection, consider refactoringImportAssetsServiceto only takeassetsServiceand access the store viaassetsService.assetStore. This would simplify its initialization here.