-
Notifications
You must be signed in to change notification settings - Fork 3
[3.x backport] fix(instant): make forced conversion sheet non-dismissible #126
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
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 |
|---|---|---|
|
|
@@ -24,6 +24,26 @@ class BottomSheetViewController: UIViewController { | |
| var latestTargetHeight: CGFloat = 0.9 | ||
| var isKeyboardOpen = false | ||
|
|
||
| // When true, swipe-to-dismiss and tap-outside-to-dismiss are disabled for this presentation, | ||
| // and the Hub's `can_touch_background_to_dismiss` message cannot re-enable them. Programmatic | ||
| // dismissal (e.g. after a successful sign-in) is unaffected. Reset on viewDidDisappear. | ||
| // The didSet applies the change to a live sheetController, so toggling the lock after | ||
| // presentation still takes effect (and unlock restores the Hub's most recent preference). | ||
| var isUserDismissalDisabled: Bool = false { | ||
| didSet { | ||
| guard isUserDismissalDisabled != oldValue, let sheetController = sheetController else { return } | ||
| if isUserDismissalDisabled { | ||
| sheetController.setCanTouchDimmingBackgroundToDismiss(false) | ||
|
Comment on lines
+27
to
+36
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. issue (bug_risk): The lock currently also blocks programmatic dismissals, which contradicts the comment and may be too strict. The docstring says programmatic dismissal is unaffected, but def hideBottomSheet(_ completion: (() -> Void)? = nil) {
if isUserDismissalDisabled {
logger.debug("Ignoring hideBottomSheet: forced-conversion lock is active")
return
}
sheetController?.dismiss(completion)
}So all calls into |
||
| } else { | ||
| sheetController.setCanTouchDimmingBackgroundToDismiss(hubRequestedCanTouchToDismiss) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Tracks the most recent Hub-requested dismissibility state so that releasing the lock | ||
| // restores whatever the Hub last asked for instead of unconditionally re-enabling. | ||
| private var hubRequestedCanTouchToDismiss: Bool = true | ||
|
|
||
| override func viewWillAppear(_ animated: Bool) { | ||
| super.viewWillAppear(animated) | ||
| guard let controller = controller else { | ||
|
|
@@ -54,6 +74,9 @@ class BottomSheetViewController: UIViewController { | |
|
|
||
| sheetController = presentAsBottomSheet(controller, theme: theme, behavior: behavior) | ||
|
|
||
| if isUserDismissalDisabled { | ||
| sheetController?.setCanTouchDimmingBackgroundToDismiss(false) | ||
| } | ||
| } | ||
|
|
||
| override func viewDidLoad() { | ||
|
|
@@ -69,6 +92,8 @@ class BottomSheetViewController: UIViewController { | |
| override func viewDidDisappear(_ animated: Bool) { | ||
| super.viewDidDisappear(animated) | ||
| self.controller = nil | ||
| self.isUserDismissalDisabled = false | ||
| self.hubRequestedCanTouchToDismiss = true | ||
| } | ||
|
|
||
| func updateBottomSheetHeight(_ number: CGFloat) { | ||
|
|
@@ -77,6 +102,10 @@ class BottomSheetViewController: UIViewController { | |
| } | ||
|
|
||
| public func hideBottomSheet(_ completion: (() -> Void)? = nil) { | ||
| if isUserDismissalDisabled { | ||
| logger.debug("Ignoring hideBottomSheet: forced-conversion lock is active") | ||
| return | ||
| } | ||
| sheetController?.dismiss(completion) | ||
| } | ||
|
|
||
|
|
@@ -99,6 +128,10 @@ class BottomSheetViewController: UIViewController { | |
| } | ||
|
|
||
| func canTouchDimmingBackgroundToDismiss(_ enable: Bool) { | ||
| hubRequestedCanTouchToDismiss = enable | ||
| if isUserDismissalDisabled && enable { | ||
| return | ||
| } | ||
| if let sheetController = sheetController { | ||
| sheetController.setCanTouchDimmingBackgroundToDismiss(enable) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ class InstantUsersTests: XCTestCase { | |
|
|
||
| override func tearDown() { | ||
| Rownd.config = originalConfig | ||
| // Reset the singleton lock so it does not leak between tests. | ||
| Rownd.releaseForcedConversionLock() | ||
| super.tearDown() | ||
| } | ||
|
|
||
|
|
@@ -197,4 +199,125 @@ class InstantUsersTests: XCTestCase { | |
|
|
||
| _ = instantUsers | ||
| } | ||
|
|
||
| /// Verifies that the forced-conversion lock is engaged on the singleton bottom | ||
| /// sheet when the conversion subscription fires for an instant user. | ||
| func testLockIsEngagedWhenConversionTriggers() async throws { | ||
| let store = createStore() | ||
| _ = Context(store) | ||
|
|
||
| Rownd.config.forceInstantUserConversion = true | ||
| XCTAssertFalse(Rownd._bottomSheetIsLocked, "Pre-condition: lock should start cleared") | ||
|
|
||
| let instantUsers = InstantUsers(context: Context.currentContext) | ||
| instantUsers.tmpForceInstantUserConversionIfRequested() | ||
|
|
||
| try await Task.sleep(nanoseconds: 50_000_000) | ||
|
|
||
| store.dispatch(SetAuthState(payload: AuthState( | ||
| accessToken: generateJwt(expires: Date(timeIntervalSinceNow: 3600).timeIntervalSince1970), | ||
| refreshToken: generateJwt(expires: Date(timeIntervalSinceNow: 36000).timeIntervalSince1970) | ||
| ))) | ||
| store.dispatch(SetClockSync(clockSyncState: .synced)) | ||
| store.dispatch(SetUserState(payload: UserState( | ||
| data: ["user_id": "test_instant_user"], | ||
| authLevel: .instant | ||
| ))) | ||
|
|
||
| try await waitUntil(timeout: 2.0) { Rownd._bottomSheetIsLocked } | ||
| XCTAssertTrue(Rownd._bottomSheetIsLocked, "Lock should engage when authLevel transitions to .instant") | ||
|
|
||
| _ = instantUsers | ||
| } | ||
|
|
||
| /// Verifies that the lock releases once the user transitions from `.instant` | ||
| /// to a non-instant identifier auth level (e.g. `.verified`). | ||
| func testLockReleasesAfterVerifiedConversion() async throws { | ||
| let store = createStore() | ||
| _ = Context(store) | ||
|
|
||
| Rownd.config.forceInstantUserConversion = true | ||
|
|
||
| let instantUsers = InstantUsers(context: Context.currentContext) | ||
| instantUsers.tmpForceInstantUserConversionIfRequested() | ||
|
|
||
| try await Task.sleep(nanoseconds: 50_000_000) | ||
|
|
||
| store.dispatch(SetAuthState(payload: AuthState( | ||
| accessToken: generateJwt(expires: Date(timeIntervalSinceNow: 3600).timeIntervalSince1970), | ||
| refreshToken: generateJwt(expires: Date(timeIntervalSinceNow: 36000).timeIntervalSince1970) | ||
| ))) | ||
| store.dispatch(SetClockSync(clockSyncState: .synced)) | ||
| store.dispatch(SetUserState(payload: UserState( | ||
| data: ["user_id": "test_instant_user"], | ||
| authLevel: .instant | ||
| ))) | ||
|
|
||
| try await waitUntil(timeout: 2.0) { Rownd._bottomSheetIsLocked } | ||
|
|
||
| // Simulate successful conversion: user-data fetch returns with verified level. | ||
| store.dispatch(SetUserState(payload: UserState( | ||
| data: ["user_id": "test_verified_user", "email": "[email protected]"], | ||
| authLevel: .verified | ||
| ))) | ||
|
|
||
| try await waitUntil(timeout: 2.0) { !Rownd._bottomSheetIsLocked } | ||
| XCTAssertFalse(Rownd._bottomSheetIsLocked, "Lock should release once authLevel becomes .verified") | ||
|
|
||
| _ = instantUsers | ||
| } | ||
|
|
||
| /// Verifies that the `hasTriggeredConversion` gate prevents the conversion | ||
| /// flow from re-triggering after a successful conversion + lock release. | ||
| /// (The customer-confirmed behavior is once-per-session.) | ||
| func testConversionDoesNotRetriggerAfterRelease() async throws { | ||
| let store = createStore() | ||
| _ = Context(store) | ||
|
|
||
| Rownd.config.forceInstantUserConversion = true | ||
|
|
||
| let instantUsers = InstantUsers(context: Context.currentContext) | ||
| instantUsers.tmpForceInstantUserConversionIfRequested() | ||
|
|
||
| try await Task.sleep(nanoseconds: 50_000_000) | ||
|
|
||
| // First .instant → lock should engage. | ||
| store.dispatch(SetAuthState(payload: AuthState( | ||
| accessToken: generateJwt(expires: Date(timeIntervalSinceNow: 3600).timeIntervalSince1970), | ||
| refreshToken: generateJwt(expires: Date(timeIntervalSinceNow: 36000).timeIntervalSince1970) | ||
| ))) | ||
| store.dispatch(SetClockSync(clockSyncState: .synced)) | ||
| store.dispatch(SetUserState(payload: UserState( | ||
| data: ["user_id": "test_instant_user"], | ||
| authLevel: .instant | ||
| ))) | ||
| try await waitUntil(timeout: 2.0) { Rownd._bottomSheetIsLocked } | ||
|
|
||
| // Convert and release. | ||
| store.dispatch(SetUserState(payload: UserState( | ||
| data: ["user_id": "test_user", "email": "[email protected]"], | ||
| authLevel: .verified | ||
| ))) | ||
| try await waitUntil(timeout: 2.0) { !Rownd._bottomSheetIsLocked } | ||
|
|
||
| // Drop back to .instant — should NOT re-engage the lock (once-per-session). | ||
| store.dispatch(SetUserState(payload: UserState( | ||
| data: ["user_id": "test_user"], | ||
| authLevel: .instant | ||
| ))) | ||
| try await Task.sleep(nanoseconds: 200_000_000) | ||
| XCTAssertFalse(Rownd._bottomSheetIsLocked, "Conversion must not re-trigger after a successful release") | ||
|
|
||
| _ = instantUsers | ||
| } | ||
|
|
||
| // MARK: - helpers | ||
|
|
||
| private func waitUntil(timeout: TimeInterval, condition: @escaping () -> Bool) async throws { | ||
| let deadline = Date().addingTimeInterval(timeout) | ||
| while Date() < deadline { | ||
| if condition() { return } | ||
| try await Task.sleep(nanoseconds: 25_000_000) | ||
| } | ||
| } | ||
| } | ||
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.
1. Auto-close can be skipped
🐞 Bug☼ ReliabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools