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

Commit

Permalink
refactor!: remove Closure based APIs
Browse files Browse the repository at this point in the history
These APIs have a cost to be maintained and can be easily done by
partners if they do no wish to use async await.
  • Loading branch information
CassiusPacheco committed Nov 9, 2022
1 parent c0c278d commit 3acb01d
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 344 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ for soon-to-be removed features.
### Removed

- (Breaking): all clients have been removed in favour of direct methods in the ImmutableX instance.
- (Breaking): removed closure based APIs from ImmutableX instance.

### Fixed

Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ let collections = try await CollectionsAPI.listCollections(

View the [OpenAPI spec](openapi.json) for a full list of API requests available in the Core SDK.

NOTE: Closure based APIs are also available.

### Wallet Connection

In order to use any workflow functions, you will need to pass in the connected wallet provider. This means you will need to implement your own Wallet L1 [Signer](https://github.com/immutable/imx-core-sdk-swift/blob/main/Sources/ImmutableXCore/Signer.swift) and L2 [StarkSigner](https://github.com/immutable/imx-core-sdk-swift/blob/main/Sources/ImmutableXCore/Signer.swift).
Expand Down
129 changes: 0 additions & 129 deletions Sources/ImmutableXCore/ImmutableX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,6 @@ public struct ImmutableX {
try await buyWorkflow.buy(orderId: orderId, fees: fees, signer: signer, starkSigner: starkSigner)
}

/// This is a utility function that will chain the necessary calls to buy an existing order.
///
/// - Parameters:
/// - orderId: the id of an existing order to be bought
/// - fees: taker fees information to be used in the buy order.
/// - signer: represents the users L1 wallet to get the address
/// - starkSigner: represents the users L2 wallet used to sign and verify the L2 transaction
/// - Returns: a ``CreateTradeResponse`` tthat will provide the Trade id if successful
/// or an ``ImmutableXError`` error through the `onCompletion` callback
///
/// - Note: `onCompletion` is executed on the Main Thread
public func buy(orderId: String, fees: [FeeEntry] = [], signer: Signer, starkSigner: StarkSigner, onCompletion: @escaping (Result<CreateTradeResponse, ImmutableXError>) -> Void) {
Task { @MainActor in
do {
let response = try await buyWorkflow.buy(orderId: orderId, fees: fees, signer: signer, starkSigner: starkSigner)
onCompletion(.success(response))
} catch {
onCompletion(.failure(error.asImmutableXError))
}
}
}

/// This is a utility function that will chain the necessary calls to sell an asset.
///
/// - Parameters:
Expand All @@ -102,29 +80,6 @@ public struct ImmutableX {
try await sellWorkflow.sell(asset: asset, sellToken: sellToken, fees: fees, signer: signer, starkSigner: starkSigner)
}

/// This is a utility function that will chain the necessary calls to sell an asset.
///
/// - Parameters:
/// - asset: the asset to sell
/// - sellToken: the type of token and how much of it to sell the asset for
/// - fees: maker fees information to be used in the sell order.
/// - signer: represents the users L1 wallet to get the address
/// - starkSigner: represents the users L2 wallet used to sign and verify the L2 transaction
/// - Returns: a ``CreateOrderResponse`` that will provide the Order id if successful
/// or an ``ImmutableXError`` error through the `onCompletion` callback
///
/// - Note: `onCompletion` is executed on the Main Thread
public func sell(asset: AssetModel, sellToken: AssetModel, fees: [FeeEntry], signer: Signer, starkSigner: StarkSigner, onCompletion: @escaping (Result<CreateOrderResponse, ImmutableXError>) -> Void) {
Task { @MainActor in
do {
let response = try await sellWorkflow.sell(asset: asset, sellToken: sellToken, fees: fees, signer: signer, starkSigner: starkSigner)
onCompletion(.success(response))
} catch {
onCompletion(.failure(error.asImmutableXError))
}
}
}

/// This is a utility function that will chain the necessary calls to cancel an existing order.
///
/// - Parameters:
Expand All @@ -137,27 +92,6 @@ public struct ImmutableX {
try await cancelOrderWorkflow.cancel(orderId: orderId, signer: signer, starkSigner: starkSigner)
}

/// This is a utility function that will chain the necessary calls to cancel an existing order.
///
/// - Parameters:
/// - orderId: the id of an existing order to be bought
/// - signer: represents the users L1 wallet to get the address
/// - starkSigner: represents the users L2 wallet used to sign and verify the L2 transaction
/// - Returns: a ``CancelOrderResponse`` that will provide the cancelled Order id if successful
/// or an ``ImmutableXError`` error through the `onCompletion` callback
///
/// - Note: `onCompletion` is executed on the Main Thread
public func cancelOrder(orderId: String, signer: Signer, starkSigner: StarkSigner, onCompletion: @escaping (Result<CancelOrderResponse, ImmutableXError>) -> Void) {
Task { @MainActor in
do {
let response = try await cancelOrderWorkflow.cancel(orderId: orderId, signer: signer, starkSigner: starkSigner)
onCompletion(.success(response))
} catch {
onCompletion(.failure(error.asImmutableXError))
}
}
}

/// This is a utility function that will chain the necessary calls to transfer a token.
///
/// - Parameters:
Expand All @@ -171,28 +105,6 @@ public struct ImmutableX {
try await transferWorkflow.transfer(token: token, recipientAddress: recipientAddress, signer: signer, starkSigner: starkSigner)
}

/// This is a utility function that will chain the necessary calls to transfer a token.
///
/// - Parameters:
/// - token: to be transferred (ETH, ERC20, or ERC721)
/// - recipientAddress: of the wallet that will receive the token
/// - signer: represents the users L1 wallet to get the address
/// - starkSigner: represents the users L2 wallet used to sign and verify the L2 transaction
/// - Returns: a ``CreateTransferResponse`` that will provide the transfer id if successful
/// or an ``ImmutableXError`` error through the `onCompletion` callback
///
/// - Note: `onCompletion` is executed on the Main Thread
public func transfer(token: AssetModel, recipientAddress: String, signer: Signer, starkSigner: StarkSigner, onCompletion: @escaping (Result<CreateTransferResponse, ImmutableXError>) -> Void) {
Task { @MainActor in
do {
let response = try await transferWorkflow.transfer(token: token, recipientAddress: recipientAddress, signer: signer, starkSigner: starkSigner)
onCompletion(.success(response))
} catch {
onCompletion(.failure(error.asImmutableXError))
}
}
}

/// This is a utility function that will register a user to Immutable X if they aren't already
///
/// - Parameters:
Expand All @@ -204,26 +116,6 @@ public struct ImmutableX {
_ = try await registerWorkflow.registerOffchain(signer: signer, starkSigner: starkSigner)
}

/// This is a utility function that will register a user to Immutable X if they aren't already
///
/// - Parameters:
/// - signer: represents the users L1 wallet to get the address
/// - starkSigner: represents the users L2 wallet used to sign and verify the L2 transaction
/// - Returns: `Void` if user is registered or an ``ImmutableXError`` error through
/// the `onCompletion` callback
///
/// - Note: `onCompletion` is executed on the Main Thread
public func registerOffchain(signer: Signer, starkSigner: StarkSigner, onCompletion: @escaping (Result<Void, ImmutableXError>) -> Void) {
Task { @MainActor in
do {
_ = try await registerWorkflow.registerOffchain(signer: signer, starkSigner: starkSigner)
onCompletion(.success(()))
} catch {
onCompletion(.failure(error.asImmutableXError))
}
}
}

/// Gets a URL to MoonPay that provides a service for buying crypto directly on Immutable in exchange for fiat.
///
/// - Parameters:
Expand All @@ -235,25 +127,4 @@ public struct ImmutableX {
public func buyCryptoURL(colorCodeHex: String = "#00818e", signer: Signer) async throws -> String {
try await buyCryptoWorkflow.buyCryptoURL(colorCodeHex: colorCodeHex, signer: signer)
}

/// Gets a URL to MoonPay that provides a service for buying crypto directly on Immutable in exchange for fiat.
///
/// - Parameters:
/// - colorCodeHex: the color code in hex (e.g. #00818e) for the Moon pay widget main color.
/// It is used for buttons, links and highlighted text. Defaults to `#00818e`
/// - signer: represents the users L1 wallet to get the address
/// - Returns: a website URL string to be used to launch a WebView or Browser to buy crypto if successful
/// or an ``ImmutableXError`` error through the `onCompletion` callback
///
/// - Note: `onCompletion` is executed on the Main Thread
public func buyCryptoURL(colorCodeHex: String = "#00818e", signer: Signer, onCompletion: @escaping (Result<String, ImmutableXError>) -> Void) {
Task { @MainActor in
do {
let response = try await buyCryptoWorkflow.buyCryptoURL(colorCodeHex: colorCodeHex, signer: signer)
onCompletion(.success(response))
} catch {
onCompletion(.failure(error.asImmutableXError))
}
}
}
}
Loading

0 comments on commit 3acb01d

Please sign in to comment.