Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Sources/MagicSDK/Core/Magic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public class Magic: NSObject {
/// - apiKey: Your client ID. From https://dashboard.Magic.com
/// - ethNetwork: Network setting
public convenience init(apiKey: String, network: EthNetwork, locale: String = Locale.current.identifier) {
self.init(urlBuilder: URLBuilder(apiKey: apiKey, network: EthNetworkConfiguration(network: network), locale: locale))
self.init(urlBuilder: URLBuilder(apiKey: apiKey, network: network, locale: locale))
}

public convenience init(apiKey: String, customNode: CustomNodeConfiguration, locale: String = Locale.current.identifier) {
self.init(urlBuilder: URLBuilder(apiKey: apiKey, customNode: customNode, locale: locale))
}

public convenience init(apiKey: String, locale: String = Locale.current.identifier) {
self.init(urlBuilder: URLBuilder(apiKey: apiKey, network: EthNetworkConfiguration(network: apiKey.contains("live") ? EthNetwork.mainnet: EthNetwork.rinkeby), locale: locale))
self.init(urlBuilder: URLBuilder(apiKey: apiKey, network: EthNetwork.mainnet, locale: locale))
}

private init(urlBuilder: URLBuilder) {
Expand Down
16 changes: 4 additions & 12 deletions Sources/MagicSDK/Core/Relayer/URLBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public struct URLBuilder {
self.init(data: data, host: URLBuilder.host, apiKey: apiKey)
}

init(apiKey: String, network: EthNetworkConfiguration, locale: String) {
init(apiKey: String, network: EthNetwork, locale: String) {
let options = EthNetworkOptions(apiKey: apiKey, network: network, locale: locale)
let data = try! JSONEncoder().encode(options)
self.init(data: data, host: URLBuilder.host, apiKey: apiKey)
Expand All @@ -50,11 +50,11 @@ public struct URLBuilder {
let API_KEY: String
let host = URLBuilder.host
let sdk = "magic-sdk-ios"
let ETH_NETWORK: EthNetworkConfiguration
let ETH_NETWORK: String
let locale: String
let bundleId = Bundle.main.bundleIdentifier
init(apiKey: String, network: EthNetworkConfiguration, locale: String) {
self.ETH_NETWORK = network
init(apiKey: String, network: EthNetwork, locale: String) {
self.ETH_NETWORK = network.rawValue
self.API_KEY = apiKey
self.locale = locale
}
Expand Down Expand Up @@ -84,11 +84,3 @@ public struct CustomNodeConfiguration: Encodable {
self.chainId = chainId
}
}

internal struct EthNetworkConfiguration: Encodable {
let network: String

init (network: EthNetwork) {
self.network = network.rawValue
}
}
22 changes: 10 additions & 12 deletions Sources/MagicSDK/Modules/Web3/Web3Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import PromiseKit

// MARK: - web3 extension with closure
public extension Web3.Eth {

func getCoinbase(response: @escaping Web3.Web3ResponseCompletion<EthereumAddress>) {
let req = BasicRPCRequest(
id: properties.rpcId,
Expand All @@ -22,7 +22,7 @@ public extension Web3.Eth {
)
properties.provider.send(request: req, response: response)
}

func sign(from: EthereumAddress, message: EthereumData, response: @escaping Web3.Web3ResponseCompletion<EthereumData>) {
let req = RPCRequest<EthereumValue>(
id: properties.rpcId,
Expand All @@ -32,7 +32,7 @@ public extension Web3.Eth {
)
properties.provider.send(request: req, response: response)
}

func signTypedDataV1(
data: [EIP712TypedDataLegacyFields],
account: EthereumAddress,
Expand All @@ -48,7 +48,7 @@ public extension Web3.Eth {
)
properties.provider.send(request: req, response: response)
}

func signTypedDataV3(
account: EthereumAddress,
data: EIP712TypedData,
Expand All @@ -69,26 +69,26 @@ public extension Web3.Eth {
// MARK: - web3 extension Promises
///
public extension Web3.Eth {

func getCoinbase() -> Promise<EthereumAddress> {
return Promise { resolver in
getCoinbase(response: promiseResolver(resolver))
}
}

func sign(from: EthereumAddress, message: EthereumData) -> Promise<EthereumData> {
return Promise { resolver in
sign(from: from, message: message, response: promiseResolver(resolver))
}
}

func signTypedDataLegacy(
account: EthereumAddress, data: [EIP712TypedDataLegacyFields]) -> Promise<EthereumData> {
return Promise { resolver in
signTypedDataV1(data: data, account: account, response: promiseResolver(resolver))
}
}

func signTypedData(
account: EthereumAddress, data: EIP712TypedData) -> Promise<EthereumData> {
return Promise { resolver in
Expand All @@ -98,7 +98,7 @@ public extension Web3.Eth {
}

public extension RPCRequest {

init(method: String, params: Params) {
self = RPCRequest(id: generateRandomId(), jsonrpc: "2.0", method: method, params: params)
}
Expand All @@ -109,7 +109,5 @@ public extension RPCRequest {
/// Note: Conforms to Hashable so that we can use these as a Dictionary key
public enum EthNetwork: String {
case mainnet
case kovan
case rinkeby
case ropsten
case goerli
}