Skip to content

Commit

Permalink
Revert SkusScript MethodIDs and change them to string instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon-T committed Dec 13, 2024
1 parent 3adb3fa commit 3c38973
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class BraveSkusScriptHandler: TabContentScript {

return WKUserScript(
source: secureScript(
handlerNamesMap: ["$<message_handler>": messageHandlerName],
handlerNamesMap: ["$<message_handler>": messageHandlerName]
.merging(Method.map, uniquingKeysWith: { $1 }),
securityToken: scriptId,
script: script
),
Expand Down Expand Up @@ -68,7 +69,7 @@ class BraveSkusScriptHandler: TabContentScript {
return
}

guard let requestedMethod = response["method_id"] as? Int,
guard let requestedMethod = response["method_id"] as? String,
let method = Method(rawValue: requestedMethod)
else {
Logger.module.error("Brave skus request with invalid method-id")
Expand Down Expand Up @@ -139,12 +140,12 @@ class BraveSkusScriptHandler: TabContentScript {
}

extension BraveSkusScriptHandler {
private enum Method: Int, CaseIterable {
case refreshOrder = 1
case fetchOrderCredentials = 2
case prepareCredentialsPresentation = 3
case credentialsSummary = 4
case setLocalStorageReceipt = 5
private enum Method: String, CaseIterable {
case refreshOrder
case fetchOrderCredentials
case prepareCredentialsPresentation
case credentialsSummary
case setLocalStorageReceipt

static var map: [String: String] {
var jsDict = [String: String]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ window.__firefox__.includeOnce("BraveSkusScript", function($) {
}

// Request VPN Receipt
sendMessage($<setLocalStorageReceipt>, { "message": "vpn" })
sendMessage('$<setLocalStorageReceipt>', { "message": "vpn" })
.then(function(jsonData) {
if (jsonData) {
window.localStorage.setItem(jsonData["key"], jsonData["data"]);
Expand All @@ -31,7 +31,7 @@ window.__firefox__.includeOnce("BraveSkusScript", function($) {
});

// Request Leo Receipt
sendMessage($<setLocalStorageReceipt>, { "message": "leo" })
sendMessage('$<setLocalStorageReceipt>', { "message": "leo" })
.then(function(jsonData) {
if (jsonData) {
window.localStorage.setItem("braveLeo.orderId", jsonData["braveLeo.orderId"])
Expand All @@ -49,19 +49,19 @@ window.__firefox__.includeOnce("BraveSkusScript", function($) {
writable: false,
value: {
refresh_order(orderId) {
return sendMessage($<refreshOrder>, { orderId });
return sendMessage('$<refreshOrder>', { orderId });
},

fetch_order_credentials(orderId) {
return sendMessage($<fetchOrderCredentials>, { orderId });
return sendMessage('$<fetchOrderCredentials>', { orderId });
},

prepare_credentials_presentation(domain, path) {
return sendMessage($<prepareCredentialsPresentation>, { domain, path });
return sendMessage('$<prepareCredentialsPresentation>', { domain, path });
},

credential_summary(domain) {
return sendMessage($<credentialsSummary>, { domain });
return sendMessage('$<credentialsSummary>', { domain });
}
}
});
Expand Down

0 comments on commit 3c38973

Please sign in to comment.