Skip to content

[Paywalls V2] Support variable mapping#4740

Merged
joshdholtz merged 3 commits into
mainfrom
paywalls-v2/support-variable-mapping
Jan 29, 2025
Merged

[Paywalls V2] Support variable mapping#4740
joshdholtz merged 3 commits into
mainfrom
paywalls-v2/support-variable-mapping

Conversation

@joshdholtz

@joshdholtz joshdholtz commented Jan 29, 2025

Copy link
Copy Markdown
Member

Motivation

Support the backward compatibility variable mapping

Description

  • Unknown variables and functions will map existing ones that have a sensible match
  • Super unknown (which shouldn't happen) just leave leave empty string for variable and no-op for functions

@joshdholtz joshdholtz force-pushed the paywalls-v2/support-variable-mapping branch from 3e53565 to 0c534f3 Compare January 29, 2025 17:57
@joshdholtz joshdholtz requested review from a team January 29, 2025 17:59
@joshdholtz joshdholtz marked this pull request as ready for review January 29, 2025 17:59

@JayShortway JayShortway left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good to have this in! 💪

private func findVariable(_ variableRaw: String) -> VariablesV2 {
guard let originalVariable = VariablesV2(rawValue: variableRaw) else {

let backSupportedVariableRaw = self.variableCompatibilityMap[variableRaw]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wild thought: should this support recursion? E.g. backSupportedVariableRaw is also unsupported, and we go look in the variableCompatibilityMap again to see if there's a backBackSupportedVariableRaw. Probably not right? 😅

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ha! I don't think it needs to since we are defining this on the backend so we will just never do a recursion thing 🤷

case productRelativeDiscount = "product.relative_discount"
case productStoreProductName = "product.store_product_name"

case unsupported = "__unsupported__"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd be okay if findVariable and findFunction returned nil if the variable / function is not found, as nil indicates absence of data, but not a blocker.

@joshdholtz joshdholtz merged commit 56bf2c5 into main Jan 29, 2025
@joshdholtz joshdholtz deleted the paywalls-v2/support-variable-mapping branch January 29, 2025 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants