Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit 3ca78cd

Browse files
authored
Removes deprecated Product Consolidation Warnings + Adds makeProductAnnouncement capabilities (#38)
* Removes deprecated Product Consolidation Warnings * Adds makeProductAnnouncement capabilities * Version bump * Return to using https://box.magic.link * Update MagicEventResponse and ProductAnnouncement Struct * Silently catch error * Removes IDType
1 parent aa4f0e8 commit 3ca78cd

File tree

10 files changed

+54
-142
lines changed

10 files changed

+54
-142
lines changed

MagicSDK.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'MagicSDK'
6-
s.version = '10.0.0'
6+
s.version = '10.1.0'
77
s.summary = 'Magic IOS SDK'
88

99
s.description = <<-DESC

Sources/MagicSDK/Core/Relayer/Types/BasicTypes.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum InboundMessageType: String, CaseIterable {
1414
case MAGIC_SHOW_OVERLAY
1515
case MAGIC_HIDE_OVERLAY
1616
case MAGIC_HANDLE_EVENT
17+
case MAGIC_SEND_PRODUCT_ANNOUNCEMENT
1718
}
1819

1920
enum OutboundMessageType: String, CaseIterable {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// ProductAnnouncement.swift
3+
//
4+
//
5+
// Created by Arian Flores - Magic on 2/28/24.
6+
//
7+
8+
import Foundation
9+
10+
struct ProductAnnouncement: Codable {
11+
let product_announcement: String
12+
}

Sources/MagicSDK/Core/Relayer/WebViewController.swift

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88

99
import WebKit
1010
import UIKit
11+
import os
1112

1213
/// An instance of the Fortmatc Phantom WebView
1314
class WebViewController: UIViewController, WKUIDelegate, WKScriptMessageHandler, WKNavigationDelegate, UIScrollViewDelegate {
14-
15+
@available(iOS 14.0, *)
16+
private static let logger = Logger(
17+
subsystem: Bundle.main.bundleIdentifier!,
18+
category: String(describing: WebViewController.self)
19+
)
20+
1521
/// Various errors that may occur while processing Web3 requests
1622
public enum AuthRelayerError: Error {
1723

@@ -99,6 +105,8 @@ class WebViewController: UIViewController, WKUIDelegate, WKScriptMessageHandler,
99105
try handleEvent(payloadStr: payloadStr)
100106
} else if payloadStr.contains(InboundMessageType.MAGIC_HANDLE_RESPONSE.rawValue) {
101107
try handleResponse(payloadStr: payloadStr)
108+
} else if payloadStr.contains(InboundMessageType.MAGIC_SEND_PRODUCT_ANNOUNCEMENT.rawValue) {
109+
try makeProductAnnouncement(payloadStr: payloadStr)
102110
}
103111
}
104112
try self.dequeue()
@@ -115,8 +123,9 @@ class WebViewController: UIViewController, WKUIDelegate, WKScriptMessageHandler,
115123

116124
// post event to the obeserver
117125
let event = eventResponse.response
118-
let eventName = event.result.event
119-
NotificationCenter.default.post(name: Notification.Name.init(eventName), object: nil, userInfo: ["event": event.result])
126+
if let eventName = event.result.event {
127+
NotificationCenter.default.post(name: Notification.Name.init(eventName), object: nil, userInfo: ["event": event.result])
128+
}
120129
}
121130

122131
private func handleResponse(payloadStr: String) throws -> Void {
@@ -143,6 +152,24 @@ class WebViewController: UIViewController, WKUIDelegate, WKScriptMessageHandler,
143152
throw RpcProvider.ProviderError.invalidJsonResponse(json: payloadStr)
144153
}
145154
}
155+
156+
private func makeProductAnnouncement(payloadStr: String) throws {
157+
// Decoding the JSON string into the Payload struct
158+
guard let data = payloadStr.data(using: .utf8) else { return }
159+
160+
// Define a typealias for the expected payload type
161+
typealias PayloadType = MagicResponseData<MagicEventResponse<ProductAnnouncement>>
162+
163+
let payload = try JSONDecoder().decode(PayloadType.self, from: data)
164+
if let announcement = payload.response.result.product_announcement {
165+
if #available(iOS 14.0, *) {
166+
os_log("%{public}@", log: .default, type: .info, announcement)
167+
} else {
168+
print(announcement)
169+
}
170+
}
171+
}
172+
146173

147174

148175
// MARK: - Post Messages

Sources/MagicSDK/Modules/Auth/AuthModule.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,10 @@
99
import Foundation
1010
import MagicSDK_Web3
1111
import PromiseKit
12-
import os
1312

1413
public class AuthModule: BaseModule {
15-
@available(iOS 14.0, *)
16-
private static let logger = Logger(
17-
subsystem: Bundle.main.bundleIdentifier!,
18-
category: String(describing: AuthModule.self)
19-
)
20-
2114
// MARK: - Login with SMS
2215
public func loginWithSMS (_ configuration: LoginWithSmsConfiguration, response: @escaping Web3ResponseCompletion<String> ) {
23-
if #available(iOS 14.0, *) {
24-
AuthModule.logger.warning("loginWithSMS: \(BaseWarningLog.MA_Method)")
25-
} else {
26-
print("loginWithSMS: \(BaseWarningLog.MA_Method)")
27-
}
2816
let request = RPCRequest<[LoginWithSmsConfiguration]>(method: AuthMethod.magic_auth_login_with_sms.rawValue, params: [configuration])
2917
self.provider.send(request: request, response: response)
3018
}
@@ -37,12 +25,6 @@ public class AuthModule: BaseModule {
3725

3826
// MARK: - Login with EmailOTP
3927
public func loginWithEmailOTP (_ configuration: LoginWithEmailOTPConfiguration, response: @escaping Web3ResponseCompletion<String> ) {
40-
if #available(iOS 14.0, *) {
41-
AuthModule.logger.warning("loginWithEmailOTP: \(BaseWarningLog.MA_Method)")
42-
} else {
43-
print("loginWithEmailOTP: \(BaseWarningLog.MA_Method)")
44-
}
45-
4628
let request = RPCRequest<[LoginWithEmailOTPConfiguration]>(method: AuthMethod.magic_auth_login_with_email_otp.rawValue, params: [configuration])
4729
self.provider.send(request: request, response: response)
4830
}

Sources/MagicSDK/Modules/BaseWarningLog.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.

Sources/MagicSDK/Modules/Event/EventCenter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public class EventCenter {
2727
/// Recieve events
2828
@objc func onDidReceiveEventOnce(_ notification: Notification) {
2929

30-
if let eventResult = (notification.userInfo?["event"]) as? MagicEventResult<[AnyValue]>, let handler = eventHandlerDict[eventResult.event] {
30+
if let eventResult = (notification.userInfo?["event"]) as? MagicEventResult<[AnyValue]>, let event = eventResult.event, let handler = eventHandlerDict[event] {
3131

3232
if (eventLog) {
3333
print("MagicSDK Event: \(eventResult)")
3434
}
3535

36-
NotificationCenter.default.removeObserver(self, name: Notification.Name(eventResult.event), object: nil)
36+
NotificationCenter.default.removeObserver(self, name: Notification.Name(event), object: nil)
3737
handler()
3838
} else {
3939
// handleRollbarError(Error.eventCallbackMissing)

Sources/MagicSDK/Modules/Event/EventResponse.swift

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,24 @@
88
import Foundation
99

1010

11-
internal struct MagicEventResponse<Params: Codable>: Codable {
12-
13-
/// The rpc id
14-
public let id: Int
15-
16-
/// The jsonrpc version. Typically 2.0
11+
internal struct MagicEventResponse<ResultType: Codable>: Codable {
12+
public let id: Int?
1713
public let jsonrpc: String
18-
19-
/// The result
20-
public let result: MagicEventResult<Params>
21-
22-
/// The error
14+
public let result: MagicEventResult<ResultType?>
2315
public let error: Error?
24-
16+
17+
// Error struct remains the same
2518
public struct Error: Swift.Error, Codable {
26-
27-
/// The error code
2819
public let code: Int
29-
30-
/// The error message
3120
public let message: String
32-
33-
/// Description
3421
public var localizedDescription: String {
3522
return "Magic Event Error (\(code)) \(message)"
3623
}
3724
}
3825
}
3926

4027
internal struct MagicEventResult<Params: Codable>: Codable {
41-
let event: String
42-
let params: Params
28+
let event: String?
29+
let params: Params?
30+
let product_announcement: String?
4331
}

Sources/MagicSDK/Modules/User/UserModule.swift

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,12 @@
88
import Foundation
99
import MagicSDK_Web3
1010
import PromiseKit
11-
import os
1211

1312
public class UserModule: BaseModule {
14-
@available(iOS 14.0, *)
15-
private static let logger = Logger(
16-
subsystem: Bundle.main.bundleIdentifier!,
17-
category: String(describing: UserModule.self)
18-
)
1913
/**
2014
GetIdToken
2115
*/
2216
public func getIdToken(_ configuration: GetIdTokenConfiguration? = nil, response: @escaping Web3ResponseCompletion<String>) {
23-
if #available(iOS 14.0, *) {
24-
UserModule.logger.warning("getIdToken: \(BaseWarningLog.MA_Method)")
25-
} else {
26-
print("getIdToken: \(BaseWarningLog.MA_Method)")
27-
}
28-
2917
let request = RPCRequest<[GetIdTokenConfiguration?]>(method: UserMethod.magic_auth_get_id_token.rawValue, params: [configuration])
3018

3119
return self.provider.send(request: request, response: response)
@@ -41,12 +29,6 @@ public class UserModule: BaseModule {
4129
Generate Id Token
4230
*/
4331
public func generateIdToken(_ configuration: GenerateIdTokenConfiguration? = nil, response: @escaping Web3ResponseCompletion<String>) {
44-
if #available(iOS 14.0, *) {
45-
UserModule.logger.warning("generateIdToken: \(BaseWarningLog.MA_Method)")
46-
} else {
47-
print("generateIdToken: \(BaseWarningLog.MA_Method)")
48-
}
49-
5032
let request = RPCRequest<[GenerateIdTokenConfiguration?]>(method: UserMethod.magic_auth_generate_id_token.rawValue, params: [configuration])
5133

5234
return self.provider.send(request: request, response: response)
@@ -63,12 +45,6 @@ public class UserModule: BaseModule {
6345
Get Info
6446
*/
6547
public func getInfo(response: @escaping Web3ResponseCompletion<UserInfo>) {
66-
if #available(iOS 14.0, *) {
67-
UserModule.logger.warning("getInfo: \(BaseWarningLog.MA_Method)")
68-
} else {
69-
print("getInfo: \(BaseWarningLog.MA_Method)")
70-
}
71-
7248
let request = BasicRPCRequest(method: UserMethod.magic_get_info.rawValue, params: [])
7349
return self.provider.send(request: request, response: response)
7450
}
@@ -83,11 +59,6 @@ public class UserModule: BaseModule {
8359
IsLogged In
8460
*/
8561
public func isLoggedIn(response: @escaping Web3ResponseCompletion<Bool>) {
86-
if #available(iOS 14.0, *) {
87-
UserModule.logger.warning("isLoggedIn: \(BaseWarningLog.MA_Method)")
88-
} else {
89-
print("isLoggedIn: \(BaseWarningLog.MA_Method)")
90-
}
9162
let request = BasicRPCRequest(method: UserMethod.magic_auth_is_logged_in.rawValue, params: [])
9263
self.provider.send(request: request, response: response)
9364
}
@@ -123,12 +94,6 @@ public class UserModule: BaseModule {
12394
Logout
12495
*/
12596
public func logout (response: @escaping Web3ResponseCompletion<Bool>) {
126-
if #available(iOS 14.0, *) {
127-
UserModule.logger.warning("logout: \(BaseWarningLog.MA_Method)")
128-
} else {
129-
print("logout: \(BaseWarningLog.MA_Method)")
130-
}
131-
13297
let request = BasicRPCRequest(method: UserMethod.magic_auth_logout.rawValue, params: [])
13398
self.provider.send(request: request, response: response)
13499
}
@@ -142,12 +107,6 @@ public class UserModule: BaseModule {
142107
showSettings
143108
*/
144109
public func showSettings(response: @escaping Web3ResponseCompletion<UserInfo>) {
145-
if #available(iOS 14.0, *) {
146-
UserModule.logger.warning("showSettings: \(BaseWarningLog.MA_Method)")
147-
} else {
148-
print("showSettings: \(BaseWarningLog.MA_Method)")
149-
}
150-
151110
let request = BasicRPCRequest(method: UserMethod.magic_auth_settings.rawValue, params: [])
152111
self.provider.send(request: request, response: response)
153112
}
@@ -176,12 +135,6 @@ public class UserModule: BaseModule {
176135
recoverAccount
177136
*/
178137
public func recoverAccount(_ configuration: RecoverAccountConfiguration, response: @escaping Web3ResponseCompletion<Bool>) {
179-
if #available(iOS 14.0, *) {
180-
UserModule.logger.warning("recoverAccount: \(BaseWarningLog.MA_Method)")
181-
} else {
182-
print("recoverAccount: \(BaseWarningLog.MA_Method)")
183-
}
184-
185138
let request = RPCRequest<[RecoverAccountConfiguration]>(method: UserMethod.magic_auth_recover_account.rawValue, params: [configuration])
186139

187140
return self.provider.send(request: request, response: response)

Sources/MagicSDK/Modules/Wallet/WalletModule.swift

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,12 @@
77

88
import Foundation
99
import MagicSDK_Web3
10-
import os
1110

1211
public class WalletModule: BaseModule {
13-
@available(iOS 14.0, *)
14-
private static let logger = Logger(
15-
subsystem: Bundle.main.bundleIdentifier!,
16-
category: String(describing: WalletModule.self)
17-
)
18-
19-
2012
/**
2113
connectWithUI
2214
*/
2315
public func connectWithUI(response: @escaping Web3ResponseCompletion<[String]>) {
24-
if #available(iOS 14.0, *) {
25-
WalletModule.logger.warning("connectWithUI: \(BaseWarningLog.MC_Method)")
26-
} else {
27-
print("connectWithUI: \(BaseWarningLog.MC_Method)")
28-
}
29-
3016
let request = BasicRPCRequest(method: WalletMethod.mc_login.rawValue, params: [])
3117

3218
return self.provider.send(request: request, response: response)
@@ -36,12 +22,6 @@ public class WalletModule: BaseModule {
3622
showUI
3723
*/
3824
public func showUI(response: @escaping Web3ResponseCompletion<Bool>) {
39-
if #available(iOS 14.0, *) {
40-
WalletModule.logger.warning("showUI: \(BaseWarningLog.MC_Method)")
41-
} else {
42-
print("showUI: \(BaseWarningLog.MC_Method)")
43-
}
44-
4525
let request = BasicRPCRequest(method: WalletMethod.mc_wallet.rawValue, params: [])
4626

4727
return self.provider.send(request: request, response: response)
@@ -51,12 +31,6 @@ public class WalletModule: BaseModule {
5131
getInfo
5232
*/
5333
public func getInfo(response: @escaping Web3ResponseCompletion<WalletInfoResponse>) {
54-
if #available(iOS 14.0, *) {
55-
WalletModule.logger.warning("getInfo: \(BaseWarningLog.MC_Method)")
56-
} else {
57-
print("getInfo: \(BaseWarningLog.MC_Method)")
58-
}
59-
6034
let request = BasicRPCRequest(method: WalletMethod.mc_get_wallet_info.rawValue, params: [])
6135

6236
return self.provider.send(request: request, response: response)
@@ -67,12 +41,6 @@ public class WalletModule: BaseModule {
6741
requestUserInfoWithUI
6842
*/
6943
public func requestUserInfoWithUI(_ configuration: RequestUserInfoWithUIConfiguration? = nil, response: @escaping Web3ResponseCompletion<UserInfoResponse>) {
70-
if #available(iOS 14.0, *) {
71-
WalletModule.logger.warning("requestUserInfoWithUI: \(BaseWarningLog.MC_Method)")
72-
} else {
73-
print("requestUserInfoWithUI: \(BaseWarningLog.MC_Method)")
74-
}
75-
7644
let request = RPCRequest<[RequestUserInfoWithUIConfiguration?]>(method: WalletMethod.mc_request_user_info.rawValue, params: (configuration != nil) ? [configuration]: [])
7745

7846
return self.provider.send(request: request, response: response)
@@ -82,12 +50,6 @@ public class WalletModule: BaseModule {
8250
disconnect
8351
*/
8452
public func disconnect(response: @escaping Web3ResponseCompletion<Bool>) {
85-
if #available(iOS 14.0, *) {
86-
WalletModule.logger.warning("disconnect: \(BaseWarningLog.MC_Method)")
87-
} else {
88-
print("disconnect: \(BaseWarningLog.MC_Method)")
89-
}
90-
9153
let request = BasicRPCRequest(method: WalletMethod.mc_disconnect.rawValue, params: [])
9254

9355
return self.provider.send(request: request, response: response)

0 commit comments

Comments
 (0)