Skip to content
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: ensure modal shared key removed from individual events #13

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Sources/PayPalMessages/PayPalMessageModalViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class PayPalMessageModalViewModel: NSObject, WKNavigationDelegate, WKScriptMessa
let bodyData = bodyString.data(using: .utf8),
let json = try? JSONSerialization.jsonObject(with: bodyData) as? [String: Any],
let eventName = json["name"] as? String,
let eventArgs = json["args"] as? [[String: Any]] else {
var eventArgs = json["args"] as? [[String: Any]] else {
log(.error, "Unable to parse modal event body")
return
}
Expand All @@ -254,9 +254,12 @@ class PayPalMessageModalViewModel: NSObject, WKNavigationDelegate, WKScriptMessa

guard !eventArgs.isEmpty else { return }

let shared = eventArgs[0]["__shared__"] as? [String: Any] ?? [:]
for (key, value) in shared {
logger.dynamicData[key] = AnyCodable(value)
// If __shared__ exists, remove it from the individual event and include it as
// part of the component level logger dynamic data
if let shared = eventArgs[0].removeValue(forKey: "__shared__") as? [String: Any] {
for (key, value) in shared {
logger.dynamicData[key] = AnyCodable(value)
}
}

var encodableDict: [String: AnyCodable] = [:]
Expand Down