-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1404 from WalletConnect/link-mode-SR
Link mode sr
- Loading branch information
Showing
28 changed files
with
355 additions
and
117 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Sources/Events/ExecutionTraces/PairingExecutionTraceEvents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Sources/Events/ExecutionTraces/SessionApproveExecutionTraceEvents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Sources/Events/ExecutionTraces/SessionAuthenticateTraceEvents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
import Foundation | ||
|
||
struct MessageEvent: Codable { | ||
struct Props: Codable { | ||
let event: String = "SUCCESS" | ||
let type: String | ||
let properties: Properties | ||
} | ||
|
||
struct Properties: Codable { | ||
let correlationId: Int64 | ||
let clientId: String | ||
let direction: Direction | ||
|
||
// Custom CodingKeys to map Swift property names to JSON keys | ||
enum CodingKeys: String, CodingKey { | ||
case correlationId = "correlation_id" | ||
case clientId = "client_id" | ||
case direction | ||
} | ||
} | ||
|
||
enum Direction: String, Codable { | ||
case sent | ||
case received | ||
} | ||
|
||
let eventId: String | ||
let bundleId: String | ||
let timestamp: Int64 | ||
let props: Props | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Foundation | ||
|
||
protocol MessageEventsStorage { | ||
func saveMessageEvent(_ eventType: MessageEventType) | ||
func fetchMessageEvents() -> [MessageEvent] | ||
func clearMessageEvents() | ||
} | ||
|
||
class UserDefaultsMessageEventsStorage: MessageEventsStorage { | ||
private let messageEventsKey = "com.walletconnect.sdk.messageEvents" | ||
private let maxEvents = 200 | ||
|
||
func saveMessageEvent(_ eventType: MessageEventType) { | ||
let correlationId = eventType.rpcId.integer | ||
let type = "\(eventType.tag)" | ||
let bundleId = Bundle.main.bundleIdentifier ?? "Unknown" | ||
let clientId = (try? Networking.interactor.getClientId()) ?? "Unknown" | ||
|
||
let props = MessageEvent.Props( | ||
type: type, | ||
properties: MessageEvent.Properties( | ||
correlationId: correlationId, | ||
clientId: clientId, | ||
direction: eventType.direction | ||
) | ||
) | ||
|
||
let event = MessageEvent( | ||
eventId: UUID().uuidString, | ||
bundleId: bundleId, | ||
timestamp: Int64(Date().timeIntervalSince1970 * 1000), | ||
props: props | ||
) | ||
|
||
// Fetch existing events from UserDefaults | ||
var existingEvents = fetchMessageEvents() | ||
existingEvents.append(event) | ||
|
||
// Ensure we keep only the last 200 events | ||
if existingEvents.count > maxEvents { | ||
existingEvents = Array(existingEvents.suffix(maxEvents)) | ||
} | ||
|
||
// Save updated events back to UserDefaults | ||
if let encoded = try? JSONEncoder().encode(existingEvents) { | ||
UserDefaults.standard.set(encoded, forKey: messageEventsKey) | ||
} | ||
} | ||
|
||
func fetchMessageEvents() -> [MessageEvent] { | ||
if let data = UserDefaults.standard.data(forKey: messageEventsKey), | ||
let events = try? JSONDecoder().decode([MessageEvent].self, from: data) { | ||
// Return only the last 200 events | ||
return Array(events.suffix(maxEvents)) | ||
} | ||
return [] | ||
} | ||
|
||
func clearMessageEvents() { | ||
UserDefaults.standard.removeObject(forKey: messageEventsKey) | ||
} | ||
} |
Oops, something went wrong.