Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Use magic_get_info instead of magic_auth_get_metadata (#32)
Browse files Browse the repository at this point in the history
* Use magic_get_info instead of magic_auth_get_metadata

* Major version bump
  • Loading branch information
romin-halltari authored Nov 22, 2023
1 parent c172428 commit ae5bf3b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 12 deletions.
2 changes: 1 addition & 1 deletion MagicSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'MagicSDK'
s.version = '9.1.1'
s.version = '10.0.0'
s.summary = 'Magic IOS SDK'

s.description = <<-DESC
Expand Down
24 changes: 24 additions & 0 deletions Sources/MagicSDK/Modules/User/RecoveryFactor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// UserResponse.swift
// Magic
//
// Created by Romin Halltari on 11/22/2023.
// Copyright © 2020 Magic Labs Inc. All rights reserved.
//


import Foundation

public class RecoveryFactor: Codable {
public var value: String
public var type: RecoveryMethodType

public init(value: String, type: RecoveryMethodType) {
self.value = value
self.type = type
}

public var description: String {
return "value: \(value)\ntype: \(type.rawValue)\n"
}
}
17 changes: 17 additions & 0 deletions Sources/MagicSDK/Modules/User/RecoveryMethodType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// RecoveryMethodType.swift
// Magic
//
// Created by Romin Halltari on 11/22/2023.
// Copyright © 2020 Magic Labs Inc. All rights reserved.
//

import Foundation

public enum RecoveryMethodType: String, Codable {
case phoneNumber = "PHONE_NUMBER"

public var description: String {
return rawValue.lowercased()
}
}
2 changes: 1 addition & 1 deletion Sources/MagicSDK/Modules/User/UserMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal enum UserMethod: String, CaseIterable {
// Auth
case magic_auth_get_id_token
case magic_auth_generate_id_token
case magic_auth_get_metadata
case magic_get_info
case magic_auth_logout
case magic_auth_settings
case magic_auth_update_email
Expand Down
18 changes: 9 additions & 9 deletions Sources/MagicSDK/Modules/User/UserModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ public class UserModule: BaseModule {


/**
Get Metadata
Get Info
*/
public func getMetadata(response: @escaping Web3ResponseCompletion<UserMetadata>) {
public func getInfo(response: @escaping Web3ResponseCompletion<UserInfo>) {
if #available(iOS 14.0, *) {
UserModule.logger.warning("getMetadata: \(BaseWarningLog.MA_Method)")
UserModule.logger.warning("getInfo: \(BaseWarningLog.MA_Method)")
} else {
print("getMetadata: \(BaseWarningLog.MA_Method)")
print("getInfo: \(BaseWarningLog.MA_Method)")
}

let request = BasicRPCRequest(method: UserMethod.magic_auth_get_metadata.rawValue, params: [])
let request = BasicRPCRequest(method: UserMethod.magic_get_info.rawValue, params: [])
return self.provider.send(request: request, response: response)
}

public func getMetadata() -> Promise<UserMetadata> {
public func getInfo() -> Promise<UserInfo> {
return Promise { resolver in
getMetadata(response: promiseResolver(resolver))
getInfo(response: promiseResolver(resolver))
}
}

Expand Down Expand Up @@ -141,7 +141,7 @@ public class UserModule: BaseModule {
/**
showSettings
*/
public func showSettings(response: @escaping Web3ResponseCompletion<UserMetadata>) {
public func showSettings(response: @escaping Web3ResponseCompletion<UserInfo>) {
if #available(iOS 14.0, *) {
UserModule.logger.warning("showSettings: \(BaseWarningLog.MA_Method)")
} else {
Expand All @@ -152,7 +152,7 @@ public class UserModule: BaseModule {
self.provider.send(request: request, response: response)
}

public func showSettings() -> Promise<UserMetadata> {
public func showSettings() -> Promise<UserInfo> {
return Promise { resolver in
showSettings(response: promiseResolver(resolver))
}
Expand Down
15 changes: 14 additions & 1 deletion Sources/MagicSDK/Modules/User/UserResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@ import MagicSDK_Web3
public protocol MagicResponse: Codable {}

/// Get Id Token configuration
public struct UserMetadata: MagicResponse {
public struct UserInfo: MagicResponse {

public let issuer: String?
public let publicAddress: String?
public let email: String?
public let phoneNumber: String?
public let isMfaEnabled: Bool
public let recoveryFactors: [RecoveryFactor]

public var description: String {
return """
issuer: \(issuer ?? "nil")
publicAddress: \(publicAddress ?? "nil")
email: \(email ?? "nil")
phoneNumber: \(phoneNumber ?? "nil")
isMfaEnabled: \(isMfaEnabled)
recoveryFactors: \(recoveryFactors)
"""
}
}

0 comments on commit ae5bf3b

Please sign in to comment.