Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add errors to transaction #66

Merged
merged 5 commits into from Jul 5, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,11 +6,20 @@ All notable changes to this project will be documented in this file.
- `0.10.x` Betas
- [0.10.0](#0100)
- [0.10.1](#0101)
- [0.10.2](#0102)


- `0.9.x` Betas
- [0.9.11](#0911)

---
## [0.10.2](https://github.com/omisego/ios-sdk/releases/tag/0.10.2)
Released on 2018-7-5. All issues associated with this milestone can be found using this [filter](https://github.com/omisego/ios-sdk/issues?utf8=%E2%9C%93&q=milestone%3A0.10.2).

#### Fixed
- decoding optional parameters for accounts.
- Updated by [Mederic](https://github.com/mederic-p) in Pull Request [#66](https://github.com/omisego/ios-sdk/pull/66)

---
## [0.10.1](https://github.com/omisego/ios-sdk/releases/tag/0.10.1)
Released on 2018-6-27. All issues associated with this milestone can be found using this [filter](https://github.com/omisego/ios-sdk/issues?utf8=%E2%9C%93&q=milestone%3A0.10.1).
Expand Down
2 changes: 1 addition & 1 deletion OmiseGO.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'OmiseGO'
s.version = '0.10.1'
s.version = '0.10.2'
s.license = 'Apache'
s.summary = 'The OmiseGO iOS SDK allows developers to easily interact with a node of the OmiseGO eWallet.'
s.homepage = 'https://github.com/omisego/ios-sdk'
Expand Down
2 changes: 1 addition & 1 deletion OmiseGO.xcodeproj/project.pbxproj
Expand Up @@ -716,7 +716,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint lint\n swiftlint lint --config .swiftlint-test.yml\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\nif which swiftformat >/dev/null; then\n swiftformat . --commas false --self insert\nelse\n echo \"warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi";
shellScript = "if which swiftformat >/dev/null; then\n swiftformat . --commas false --self insert\nelse\n echo \"warning: SwiftFormat not installed, download from https://github.com/nicklockwood/SwiftFormat\"\nfi\nif which swiftlint >/dev/null; then\n swiftlint lint\n swiftlint lint --config .swiftlint-test.yml\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
};
66B9F6BC22AA32602097E785 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
2 changes: 2 additions & 0 deletions OmiseGOTests/CodingTests/DecodeTests.swift
Expand Up @@ -444,6 +444,8 @@ class DecodeTests: XCTestCase {
XCTAssertEqual(decodedData.createdAt, "2018-01-01T00:00:00Z".toDate(withFormat: "yyyy-MM-dd'T'HH:mm:ssZ"))
XCTAssertTrue(decodedData.metadata.isEmpty)
XCTAssertTrue(decodedData.encryptedMetadata.isEmpty)
XCTAssertNil(decodedData.errorCode)
XCTAssertNil(decodedData.errorDescription)
} catch let thrownError {
XCTFail(thrownError.localizedDescription)
}
Expand Down
Expand Up @@ -53,7 +53,9 @@
"status": "confirmed",
"metadata": {},
"encrypted_metadata": {},
"created_at": "2018-01-01T00:00:00Z"
"created_at": "2018-01-01T00:00:00Z",
"error_code": null,
"error_description": null
}

],
Expand Down
4 changes: 3 additions & 1 deletion OmiseGOTests/FixtureTests/Fixtures/objects/transaction.json
Expand Up @@ -47,5 +47,7 @@
"status": "confirmed",
"metadata": {},
"encrypted_metadata": {},
"created_at": "2018-01-01T00:00:00Z"
"created_at": "2018-01-01T00:00:00Z",
"error_code": null,
"error_description": null
}
8 changes: 6 additions & 2 deletions OmiseGOTests/Helpers/StubGenerator.swift
Expand Up @@ -215,7 +215,9 @@ class StubGenerator {
exchange: TransactionExchange? = nil,
metadata: [String: Any]? = nil,
encryptedMetadata: [String: Any]? = nil,
createdAt: Date? = nil)
createdAt: Date? = nil,
errorCode: String? = nil,
errorDescription: String? = nil)
-> Transaction {
let v: Transaction = self.stub(forResource: "transaction")
return Transaction(
Expand All @@ -226,7 +228,9 @@ class StubGenerator {
exchange: exchange ?? v.exchange,
metadata: metadata ?? v.metadata,
encryptedMetadata: encryptedMetadata ?? v.encryptedMetadata,
createdAt: createdAt ?? v.createdAt)
createdAt: createdAt ?? v.createdAt,
errorCode: errorCode ?? v.errorCode,
errorDescription: errorDescription ?? v.errorDescription)
}

class func transactionSource(
Expand Down
28 changes: 14 additions & 14 deletions README.md
Expand Up @@ -295,9 +295,9 @@ let params = TransactionCreateParams(fromAddress: "1e3982f5-4a27-498d-a91b-7bb2e
Transaction.create(using: client, params: params) { (result) in
switch result {
case .success(data: let transaction):
// TODO: Do something with the transaction
// TODO: Do something with the transaction
case .fail(error: let error):
XCTFail("\(error)")
//TODO: Handle the error
}
}
```
Expand Down Expand Up @@ -359,13 +359,13 @@ Where:
The previously created `transactionRequest` can then be consumed:

```swift
guard let params = TransactionConsumptionParams(transactionRequest: transactionRequest,
address: "an address",
amount: 1337,
idempotencyToken: "an idempotency token",
correlationId: "a correlation id",
metadata: [:],
encryptedMetadata: [:])!
let params = TransactionConsumptionParams(transactionRequest: transactionRequest,
address: "an address",
amount: 1337,
idempotencyToken: "an idempotency token",
correlationId: "a correlation id",
metadata: [:],
encryptedMetadata: [:])!
TransactionConsumption.consumeTransactionRequest(using: client, params: params) { (transactionConsumptionResult) in
switch transactionConsumptionResult {
case .success(data: let transactionConsumption):
Expand Down Expand Up @@ -475,7 +475,7 @@ let configuration = ClientConfiguration(baseURL: "wss://your.base.url/api/socket
apiKey: "apiKey",
authenticationToken: "authenticationToken",
debugLog: false)
let client = SocketClient(config: configuration, delegate: self)
let socketClient = SocketClient(config: configuration, delegate: self)
```

Where:
Expand Down Expand Up @@ -507,7 +507,7 @@ And for each of the listenable resource there is an other specific method to rec

When creating a `TransactionRequest` that requires a confirmation it is possible to listen for all incoming confirmation using:

`transactionRequest.startListeningEvents(withClient: client, eventDelegate: self)`
`transactionRequest.startListeningEvents(withClient: socketClient, eventDelegate: self)`

Where:
- `client` is a `SocketClient`
Expand All @@ -533,7 +533,7 @@ This method will be called if a `TransactionConsumption` fails to consume the re

Similarly to transaction request events, a `TransactionConsumption` can be listened for incoming confirmations using:

`consumption.startListeningEvents(withClient: client, eventDelegate: self)`
`consumption.startListeningEvents(withClient: socketClient, eventDelegate: self)`

Where:
- `client` is a `SocketClient`
Expand All @@ -553,7 +553,7 @@ This method will be called if the `TransactionConsumption` fails to consume the

A `User` can also be listened and will receive all events that are related to him:

`user.startListeningEvents(withClient: self.socketClient, eventDelegate: self)`
`user.startListeningEvents(withClient: socketClient, eventDelegate: self)`

Where:
- `client` is a `SocketClient`
Expand All @@ -566,7 +566,7 @@ This method will be called when any event regarding the user is received. `Webso

#### Stop listening for events

When you don't need to receive events anymore, you should call `stopListening(withClient client: SocketClient)` for the corresponding `Listenable` object. This will leave the corresponding socket channel and close the connection if no other channel is active.
When you don't need to receive events anymore, you should call `stopListening(withClient client: socketClient)` for the corresponding `Listenable` object. This will leave the corresponding socket channel and close the connection if no other channel is active.

---

Expand Down
2 changes: 1 addition & 1 deletion Source/Info.plist
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.10.1</string>
<string>0.10.2</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
4 changes: 2 additions & 2 deletions Source/Models/Account.swift
Expand Up @@ -11,7 +11,7 @@ public struct Account {
/// The unique identifier of the account
public let id: String
/// The id of the parent account
public let parentId: String
public let parentId: String?
/// The name of the account
public let name: String
/// The description of the account
Expand Down Expand Up @@ -47,7 +47,7 @@ extension Account: Decodable {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decode(String.self, forKey: .id)
parentId = try container.decode(String.self, forKey: .parentId)
parentId = try container.decodeIfPresent(String.self, forKey: .parentId)
name = try container.decode(String.self, forKey: .name)
description = try container.decode(String.self, forKey: .description)
isMaster = try container.decode(Bool.self, forKey: .isMaster)
Expand Down
8 changes: 4 additions & 4 deletions Source/Models/Avatar.swift
Expand Up @@ -9,11 +9,11 @@
/// Represents an avatar containing urls of different sizes
public struct Avatar: Decodable {
/// The url of the original image
public let original: String
public let original: String?
/// The url of the large image
public let large: String
public let large: String?
/// The url of the small image
public let small: String
public let small: String?
/// The url of the thumbnail image
public let thumb: String
public let thumb: String?
}
8 changes: 8 additions & 0 deletions Source/Models/Transaction.swift
Expand Up @@ -35,6 +35,10 @@ public struct Transaction {
public let encryptedMetadata: [String: Any]
/// The creation date of the transaction
public let createdAt: Date
/// An error code if the transaction encountered an error
public let errorCode: String?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the type should be the same as property code in APIError object?

image

Just asking I'm not sure about your implementation anyway 😄

/// The description of the encountered error
public let errorDescription: String?
}

extension Transaction: Decodable {
Expand All @@ -47,6 +51,8 @@ extension Transaction: Decodable {
case metadata
case encryptedMetadata = "encrypted_metadata"
case createdAt = "created_at"
case errorCode = "error_code"
case errorDescription = "error_description"
}

public init(from decoder: Decoder) throws {
Expand All @@ -59,6 +65,8 @@ extension Transaction: Decodable {
createdAt = try container.decode(Date.self, forKey: .createdAt)
metadata = try container.decode([String: Any].self, forKey: .metadata)
encryptedMetadata = try container.decode([String: Any].self, forKey: .encryptedMetadata)
errorCode = try container.decodeIfPresent(String.self, forKey: .errorCode)
errorDescription = try container.decodeIfPresent(String.self, forKey: .errorDescription)
}
}

Expand Down