Skip to content

Commit

Permalink
[ABW-2589] Transaction History (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
kugel3 committed Mar 15, 2024
1 parent 2b7449a commit 3dea7a9
Show file tree
Hide file tree
Showing 95 changed files with 4,358 additions and 1,727 deletions.
116 changes: 84 additions & 32 deletions RadixWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ import Foundation

extension CoreAPI {
public struct BinaryPlaintextMessageContent: Codable, Hashable {
public private(set) var type: PlaintextMessageContentType
/** The hex-encoded value of a message that the author decided to provide as raw bytes. */
public private(set) var valueHex: String

public init(type: PlaintextMessageContentType, valueHex: String) {
self.type = type
public init(valueHex: String) {
self.valueHex = valueHex
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case type
case valueHex = "value_hex"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ extension CoreAPI {
case type
}

public var string: String? {
guard case let .string(value) = self else { return nil }
return value.value
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ extension CoreAPI {
case type
}

public var plaintext: PlaintextTransactionMessage? {
guard case let .plaintext(value) = self else { return nil }
return value
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public typealias TransactionReceiptStatus = GatewayAPI.TransactionReceiptStatus
extension GatewayAPI {
/** The status of the transaction */
public enum TransactionReceiptStatus: String, Codable, CaseIterable {
case succeeded = "Succeeded"
case failed = "Failed"
case succeeded = "CommittedSuccess"
case failed = "CommittedFailure"
case rejected = "Rejected"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public struct GatewayAPIClient: Sendable, DependencyKey {
public var submitTransaction: SubmitTransaction
public var transactionStatus: GetTransactionStatus
public var transactionPreview: TransactionPreview
public var streamTransactions: StreamTransactions
}

extension GatewayAPIClient {
Expand All @@ -50,6 +51,7 @@ extension GatewayAPIClient {
public typealias SubmitTransaction = @Sendable (GatewayAPI.TransactionSubmitRequest) async throws -> GatewayAPI.TransactionSubmitResponse
public typealias GetTransactionStatus = @Sendable (GatewayAPI.TransactionStatusRequest) async throws -> GatewayAPI.TransactionStatusResponse
public typealias TransactionPreview = @Sendable (GatewayAPI.TransactionPreviewRequest) async throws -> GatewayAPI.TransactionPreviewResponse
public typealias StreamTransactions = @Sendable (GatewayAPI.StreamTransactionsRequest) async throws -> GatewayAPI.StreamTransactionsResponse
}

extension GatewayAPIClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,12 @@ extension GatewayAPIClient {
@Sendable
func post<Response>(
request: some Encodable,
dateEncodingStrategy: JSONEncoder.DateEncodingStrategy = .deferredToDate,
urlFromBase: @escaping @Sendable (URL) -> URL
) async throws -> Response
where
Response: Decodable
{
) async throws -> Response where Response: Decodable {
jsonEncoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]
jsonEncoder.dateEncodingStrategy = dateEncodingStrategy
let httpBody = try jsonEncoder.encode(request)

return try await makeRequest(httpBodyData: httpBody, urlFromBase: urlFromBase)
}

Expand Down Expand Up @@ -237,6 +235,12 @@ extension GatewayAPIClient {
try await post(
request: transactionPreviewRequest
) { $0.appendingPathComponent("transaction/preview") }
},
streamTransactions: { streamTransactionsRequest in
try await post(
request: streamTransactionsRequest,
dateEncodingStrategy: .iso8601
) { $0.appendingPathComponent("stream/transactions") }
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ extension GatewayAPIClient: TestDependencyKey {
getNonFungibleData: unimplemented("\(Self.self).getNonFungibleData"),
submitTransaction: unimplemented("\(Self.self).submitTransaction"),
transactionStatus: unimplemented("\(Self.self).transactionStatus"),
transactionPreview: unimplemented("\(Self.self).transactionPreview")
transactionPreview: unimplemented("\(Self.self).transactionPreview"),
streamTransactions: unimplemented("\(Self.self).streamTransactions")
)

// TODO: convert to noop, don't use in tests.
Expand Down Expand Up @@ -49,7 +50,8 @@ extension GatewayAPIClient: TestDependencyKey {
errorMessage: nil
)
},
transactionPreview: unimplemented("\(self).transactionPreview")
transactionPreview: unimplemented("\(self).transactionPreview"),
streamTransactions: unimplemented("\(self).streamTransactions")
)
}
}
Expand Down
Loading

0 comments on commit 3dea7a9

Please sign in to comment.