Conversation
Track the SwiftUI scenePhase in PerpetualScene and call the view model when it changes. Adds an @Environment(\.scenePhase) property and an .onChange handler that forwards phase updates to PerpetualSceneViewModel. Implements onScenePhaseChange in the view model to trigger fetchCandlesticks() when the scene becomes .active (no-op for .inactive/.background). This ensures candlestick data is refreshed when the app/scene returns to the foreground.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the PerpetualScene by integrating SwiftUI's scene phase observation to ensure that candlestick data is automatically refreshed when the application or scene becomes active. This change addresses a known issue where data might become stale if the app was backgrounded and then brought back to the foreground, improving the user experience by always presenting up-to-date information. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds functionality to refresh candlestick data when the app scene becomes active. This is achieved by observing the scenePhase in PerpetualScene and triggering a data fetch in the PerpetualSceneViewModel. My review identifies a high-severity issue where errors during the data fetch are silently ignored, which could leave the UI in a perpetual loading state. I've suggested a fix to properly handle errors and update the UI state, consistent with other parts of the view model.
| func onScenePhaseChange(_ oldPhase: ScenePhase, _ newPhase: ScenePhase) { | ||
| switch newPhase { | ||
| case .active: Task { try? await fetchCandlesticks() } | ||
| case .inactive, .background: break | ||
| @unknown default: break | ||
| } | ||
| } |
There was a problem hiding this comment.
Silently ignoring the error from fetchCandlesticks() using try? can lead to a poor user experience. The fetchCandlesticks() function sets the state to .loading at the beginning. If it then throws an error, the state will remain .loading indefinitely, and the user will see a perpetual loading indicator without any error message. It's better to handle the potential error and update the UI state accordingly, similar to how it's done in onPeriodChange.
func onScenePhaseChange(_ oldPhase: ScenePhase, _ newPhase: ScenePhase) {
guard newPhase == .active else { return }
Task {
do {
try await fetchCandlesticks()
} catch {
state = .error(error)
}
}
}|
|
||
| func onScenePhaseChange(_ oldPhase: ScenePhase, _ newPhase: ScenePhase) { | ||
| switch newPhase { | ||
| case .active: Task { try? await fetchCandlesticks() } |
There was a problem hiding this comment.
| case .active: Task { try? await fetchCandlesticks() } | |
| case .active: Task { try? await updateCandlesticks() } |
|
@DRadmir make sure to fetch state for the market (prices / candle stick) and then connect websocket, same if you just open this screen |
…h-candlestick-when-the-app-becomes-active
…h-candlestick-when-the-app-becomes-active
6af509e to
479a347
Compare
Introduce fetchState() to concurrently update market data and candlesticks, and add updateCandlesticks() (renamed from fetchCandlesticks). Call fetchState() on onAppear and when the scene becomes active, and call updateCandlesticks() on period changes. Also remove the initial:true on the view's period onChange so the initial load is handled by fetchState(). These changes ensure market and candle data are fetched together and avoid duplicate initial period-triggered fetches; errors during initial load set state to .error.
479a347 to
f20b17e
Compare
…h-candlestick-when-the-app-becomes-active
Track the SwiftUI scenePhase in PerpetualScene and call the view model when it changes. Adds an @Environment(.scenePhase) property and an .onChange handler that forwards phase updates to PerpetualSceneViewModel. Implements onScenePhaseChange in the view model to trigger fetchCandlesticks() when the scene becomes .active (no-op for .inactive/.background). This ensures candlestick data is refreshed when the app/scene returns to the foreground.
Fix: #1760