-
Notifications
You must be signed in to change notification settings - Fork 1
fix: various fixes #289
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
fix: various fixes #289
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -35,13 +35,22 @@ class ToastWindowManager: ObservableObject { | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| func showToast(_ toast: Toast) { | ||||||||||||||||
| // Ensure window is set up before showing toast | ||||||||||||||||
| ensureWindowExists() | ||||||||||||||||
|
|
||||||||||||||||
| // If window still doesn't exist after trying to set it up, log and return | ||||||||||||||||
| guard let window = toastWindow else { | ||||||||||||||||
| Logger.error("ToastWindowManager: Cannot show toast - window not available") | ||||||||||||||||
| return | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Dismiss any existing toast first | ||||||||||||||||
| cancelAutoHide() | ||||||||||||||||
| toastWindow?.hasToast = false | ||||||||||||||||
| toastWindow?.toastFrame = .zero | ||||||||||||||||
| window.hasToast = false | ||||||||||||||||
| window.toastFrame = .zero | ||||||||||||||||
|
|
||||||||||||||||
| // Update window's toast state for hit testing | ||||||||||||||||
| toastWindow?.hasToast = true | ||||||||||||||||
| window.hasToast = true | ||||||||||||||||
|
|
||||||||||||||||
| // Show the toast with animation | ||||||||||||||||
| withAnimation(.easeInOut(duration: 0.4)) { | ||||||||||||||||
|
|
@@ -68,7 +77,7 @@ class ToastWindowManager: ObservableObject { | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| func pauseAutoHide() { | ||||||||||||||||
| guard autoHideStartTime != nil else { return } // Already paused or no auto-hide | ||||||||||||||||
| guard autoHideStartTime != nil else { return } // No active auto-hide to pause | ||||||||||||||||
| cancelAutoHide() | ||||||||||||||||
|
|
||||||||||||||||
| // Calculate remaining time | ||||||||||||||||
|
|
@@ -124,11 +133,32 @@ class ToastWindowManager: ObservableObject { | |||||||||||||||
| autoHideDuration = 0 | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| private func ensureWindowExists() { | ||||||||||||||||
| // Check if window already exists and is still valid | ||||||||||||||||
| if let existingWindow = toastWindow, | ||||||||||||||||
| existingWindow.windowScene != nil, | ||||||||||||||||
| !existingWindow.isHidden | ||||||||||||||||
| { | ||||||||||||||||
| return | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Window doesn't exist or is invalid, try to set it up | ||||||||||||||||
| setupToastWindow() | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| private func setupToastWindow() { | ||||||||||||||||
| guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene else { | ||||||||||||||||
| // Try to find an active window scene | ||||||||||||||||
| guard let windowScene = findActiveWindowScene() else { | ||||||||||||||||
| Logger.warn("ToastWindowManager: No active window scene available") | ||||||||||||||||
| return | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Clean up old window if it exists | ||||||||||||||||
| if let oldWindow = toastWindow { | ||||||||||||||||
| oldWindow.isHidden = true | ||||||||||||||||
| oldWindow.rootViewController = nil | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| let window = PassThroughWindow(windowScene: windowScene) | ||||||||||||||||
| window.windowLevel = UIWindow.Level.alert + 1 // Above alerts and sheets | ||||||||||||||||
| window.backgroundColor = .clear | ||||||||||||||||
|
|
@@ -143,6 +173,20 @@ class ToastWindowManager: ObservableObject { | |||||||||||||||
| toastWindow = window | ||||||||||||||||
| toastHostingController = hostingController | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| private func findActiveWindowScene() -> UIWindowScene? { | ||||||||||||||||
| // Try to find an active window scene from connected scenes | ||||||||||||||||
| for scene in UIApplication.shared.connectedScenes { | ||||||||||||||||
| if let windowScene = scene as? UIWindowScene, | ||||||||||||||||
| windowScene.activationState == .foregroundActive || windowScene.activationState == .foregroundInactive | ||||||||||||||||
|
Comment on lines
+179
to
+181
|
||||||||||||||||
| for scene in UIApplication.shared.connectedScenes { | |
| if let windowScene = scene as? UIWindowScene, | |
| windowScene.activationState == .foregroundActive || windowScene.activationState == .foregroundInactive | |
| let validStates: [UIScene.ActivationState] = [.foregroundActive, .foregroundInactive] | |
| for scene in UIApplication.shared.connectedScenes { | |
| if let windowScene = scene as? UIWindowScene, | |
| validStates.contains(windowScene.activationState) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,14 @@ struct SendAmountView: View { | |
| maxSendableAmount = nil | ||
| } | ||
| } | ||
| .onChange(of: wallet.selectedFeeRateSatsPerVByte) { _ in | ||
| // Recalculate max sendable amount when fee rate becomes available or changes | ||
| if app.selectedWalletToPayFrom == .onchain { | ||
| Task { | ||
| await calculateMaxSendableAmount() | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+177
to
+184
|
||
| } | ||
|
|
||
| private func onContinue() async { | ||
|
|
@@ -258,8 +266,8 @@ struct SendAmountView: View { | |
| } catch { | ||
| Logger.error("Failed to calculate max sendable amount: \(error)") | ||
| await MainActor.run { | ||
| // Fall back to total balance if calculation fails | ||
| maxSendableAmount = UInt64(wallet.spendableOnchainBalanceSats) | ||
| // Keep as nil on error - availableAmount will fall back to total balance | ||
| maxSendableAmount = nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
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 condition checks if the window is not hidden, but a valid window could be hidden and still functional. Consider removing the
!existingWindow.isHiddencheck, as the window should be shown when needed regardless of its current hidden state.