Skip to content

Conversation

@ianrumac
Copy link
Collaborator

@ianrumac ianrumac commented Jan 26, 2026

Changes in this pull request

  • Add paywall state to paywall info

Checklist

  • All unit tests pass.
  • All UI tests pass.
  • Demo project builds and runs.
  • I added/updated tests or detailed why my change isn't tested.
  • I added an entry to the CHANGELOG.md for any breaking changes, enhancements, or bug fixes.
  • I have run ktlint in the main directory and fixed any issues.
  • I have updated the SDK documentation as well as the online docs.
  • I have reviewed the contributing guide

Greptile Overview

Greptile Summary

This PR adds paywall state persistence by capturing the webview state when a paywall is dismissed. The implementation adds a new state field to both Paywall and PaywallInfo models, retrieves the state from the webview's JavaScript context via window.app.getAllState(), and stores it for later use.

Key changes:

  • Added state: Map<String, Any> field to Paywall and PaywallInfo with @Transient annotation
  • Implemented getState() suspend function in PaywallMessageHandler to retrieve state via JavaScript evaluation
  • Added SetPaywallState update class to handle state updates in PaywallViewState
  • State is captured in PaywallView.destroyed() before the paywall is fully dismissed

Minor issue found:

  • Threading pattern in getState() uses mainScope.launch instead of withContext(Dispatchers.Main) like other evaluate calls in the same file (style consistency)

Confidence Score: 4/5

  • Safe to merge with minor style improvement recommended
  • The implementation is straightforward and follows existing patterns. The state field is properly annotated as @Transient to avoid serialization issues. State retrieval uses existing JavaScript evaluation infrastructure. Only minor style inconsistency with threading pattern in getState() function, which doesn't affect functionality but could be improved for consistency
  • Pay attention to PaywallMessageHandler.kt - consider aligning the threading pattern in getState() with other evaluate calls in the file

Important Files Changed

Filename Overview
superwall/src/main/java/com/superwall/sdk/models/paywall/Paywall.kt Added state field to store paywall state with proper serialization annotation
superwall/src/main/java/com/superwall/sdk/paywall/view/PaywallView.kt Retrieves paywall state from webview before dismissing and updates controller
superwall/src/main/java/com/superwall/sdk/paywall/view/webview/messaging/PaywallMessageHandler.kt Added getState() function to retrieve state via JavaScript; minor threading pattern inconsistency

Sequence Diagram

sequenceDiagram
    participant PV as PaywallView
    participant PMH as PaywallMessageHandler
    participant WV as WebView
    participant Controller as PaywallViewController
    participant Paywall as Paywall Model
    
    Note over PV: Paywall is being dismissed
    PV->>PV: "destroyed()"
    PV->>PMH: "getState()"
    
    Note over PMH: Suspend function to get state
    PMH->>PMH: "mainScope.launch"
    PMH->>WV: "evaluate(window.app.getAllState())"
    WV-->>PMH: "JavaScript result (JSON string)"
    
    alt Valid JSON result
        PMH->>PMH: "parseToJsonElement(result)"
        PMH->>PMH: "jsonElementToMap(parsed)"
        PMH-->>PV: "Map<String, Any>"
    else Null or Parse Error
        PMH-->>PV: "emptyMap()"
    end
    
    PV->>Controller: "updateState(SetPaywallState(paywallState))"
    Controller->>Paywall: "copy(state = paywallState)"
    
    Note over PV,Paywall: State preserved for PaywallInfo
    PV->>PV: "trackClose()"
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants