Skip to content

Commit

Permalink
[Electric-Coin-Company#1092] Adopt proposal API
Browse files Browse the repository at this point in the history
- TCA sdkSYnchronizer dependency extended with 3 new Proposal APIs
- proposeTransfer tested, works as expected

[Electric-Coin-Company#1092] Adopt proposal API

- send transaction via new proposal API implemented

[Electric-Coin-Company#1092] Adopt proposal API

- code cleaned up and finished

[Electric-Coin-Company#1092] Adopt proposal API

- unit tests fixed

[Electric-Coin-Company#1092] Adopt proposal API

- Typical Fee < 0.001 localized and updated in the UI

[Electric-Coin-Company#1092] Adopt proposal API

- awaiting all transaction results with use of new proposal.transactionCount() method

[Electric-Coin-Company#1092] Adopt proposal API

- Implemented new PartialProposalError reducer and view
- Contact support mail with transaction IDs logic implemented
- Fallback to share logic implemented
- PPE integrated into SendFlow
- PPE integrated into Shielding

[Electric-Coin-Company#1092] Adopt proposal API

- Changelog updated

[Electric-Coin-Company#1092] Adopt proposal API

- SDK's fee constant removed

[Electric-Coin-Company#1092] Adopt proposal API (Electric-Coin-Company#1117)

- debug code reverted

[Electric-Coin-Company#1092] Adopt proposal API (Electric-Coin-Company#1117)

- copy change

[Electric-Coin-Company#1092] Adopt proposal API (Electric-Coin-Company#1117)

- code cleanup

[Electric-Coin-Company#1092] Adopt proposal API (Electric-Coin-Company#1117)

- proposed total fee
  • Loading branch information
LukasKorba committed Mar 19, 2024
1 parent d3adf88 commit 1bf484c
Show file tree
Hide file tree
Showing 28 changed files with 679 additions and 142 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ directly impact users rather than highlighting other crucial architectural updat
## [Unreleased]

### Added
- Proposal API integrated with error handling for multi-transaction Proposals.
- Privacy info manifest.

### Fixed
Expand Down
16 changes: 15 additions & 1 deletion modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let package = Package(
.library(name: "Models", targets: ["Models"]),
.library(name: "NumberFormatter", targets: ["NumberFormatter"]),
.library(name: "OnboardingFlow", targets: ["OnboardingFlow"]),
.library(name: "PartialProposalError", targets: ["PartialProposalError"]),
.library(name: "Pasteboard", targets: ["Pasteboard"]),
.library(name: "PrivateDataConsent", targets: ["PrivateDataConsent"]),
.library(name: "RecoveryPhraseDisplay", targets: ["RecoveryPhraseDisplay"]),
Expand Down Expand Up @@ -67,7 +68,7 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/swift-url-routing", from: "0.6.0"),
.package(url: "https://github.com/zcash-hackworks/MnemonicSwift", from: "2.2.4"),
.package(url: "https://github.com/zcash/ZcashLightClientKit", from: "2.0.10"),
.package(url: "https://github.com/zcash/ZcashLightClientKit", from: "2.0.11"),
.package(url: "https://github.com/firebase/firebase-ios-sdk", from: "10.17.0")
],
targets: [
Expand Down Expand Up @@ -106,6 +107,7 @@ let package = Package(
"MnemonicClient",
"Models",
"NumberFormatter",
"PartialProposalError",
"RestoreWalletStorage",
"SDKSynchronizer",
"SyncProgress",
Expand Down Expand Up @@ -305,6 +307,17 @@ let package = Package(
],
path: "Sources/Features/OnboardingFlow"
),
.target(
name: "PartialProposalError",
dependencies: [
"Generated",
"SupportDataGenerator",
"UIComponents",
"Utils",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture")
],
path: "Sources/Features/PartialProposalError"
),
.target(
name: "Pasteboard",
dependencies: [
Expand Down Expand Up @@ -462,6 +475,7 @@ let package = Package(
"DerivationTool",
"MnemonicClient",
"Models",
"PartialProposalError",
"Scan",
"SDKSynchronizer",
"UIComponents",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ extension DependencyValues {
}

public struct SDKSynchronizerClient {
public enum CreateProposedTransactionsResult: Equatable {
case failure
case partial(txIds: [String])
case success
}

public let stateStream: () -> AnyPublisher<SynchronizerState, Never>
public let eventStream: () -> AnyPublisher<SynchronizerEvent, Never>
public let latestState: () -> SynchronizerState
Expand All @@ -43,4 +49,9 @@ public struct SDKSynchronizerClient {
public var wipe: () -> AnyPublisher<Void, Error>?

public var switchToEndpoint: (LightWalletEndpoint) async throws -> Void

// Proposals
public var proposeTransfer: (Int, Recipient, Zatoshi, Memo?) async throws -> Proposal
public var createProposedTransactions: (Proposal, UnifiedSpendingKey) async throws -> CreateProposedTransactionsResult
public var proposeShielding: (Int, Zatoshi, Memo, TransparentAddress?) async throws -> Proposal?
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,58 @@ extension SDKSynchronizerClient: DependencyKey {
wipe: { synchronizer.wipe() },
switchToEndpoint: { endpoint in
try await synchronizer.switchTo(endpoint: endpoint)
},
proposeTransfer: { accountIndex, recipient, amount, memo in
try await synchronizer.proposeTransfer(
accountIndex: accountIndex,
recipient: recipient,
amount: amount,
memo: memo
)
},
createProposedTransactions: { proposal, spendingKey in
let stream = try await synchronizer.createProposedTransactions(
proposal: proposal,
spendingKey: spendingKey
)

let transactionCount = proposal.transactionCount()
var successCount = 0
var iterator = stream.makeAsyncIterator()

var txIds: [String] = []

for _ in 1...transactionCount {
if let transactionSubmitResult = try await iterator.next() {
switch transactionSubmitResult {
case .success(txId: let id):
successCount += 1
txIds.append(id.toHexStringTxId())
case .grpcFailure(txId: let id, error: _):
txIds.append(id.toHexStringTxId())
case .submitFailure(txId: let id, code: _, description: _):
txIds.append(id.toHexStringTxId())
case .notAttempted(txId: let id):
txIds.append(id.toHexStringTxId())
}
}
}

if successCount == 0 {
return .failure
} else if successCount == transactionCount {
return .success
} else {
return .partial(txIds: txIds)
}
},
proposeShielding: { accountIndex, shieldingThreshold, memo, transparentReceiver in
try await synchronizer.proposeShielding(
accountIndex: accountIndex,
shieldingThreshold: shieldingThreshold,
memo: memo,
transparentReceiver: transparentReceiver
)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ extension SDKSynchronizerClient: TestDependencyKey {
sendTransaction: XCTUnimplemented("\(Self.self).sendTransaction", placeholder: .placeholder()),
shieldFunds: XCTUnimplemented("\(Self.self).shieldFunds", placeholder: .placeholder()),
wipe: XCTUnimplemented("\(Self.self).wipe"),
switchToEndpoint: XCTUnimplemented("\(Self.self).switchToEndpoint")
switchToEndpoint: XCTUnimplemented("\(Self.self).switchToEndpoint"),
proposeTransfer: XCTUnimplemented("\(Self.self).proposeTransfer", placeholder: .testOnlyFakeProposal(totalFee: 0)),
createProposedTransactions: XCTUnimplemented("\(Self.self).createProposedTransactions", placeholder: .success),
proposeShielding: XCTUnimplemented("\(Self.self).proposeShielding", placeholder: nil)
)
}

Expand All @@ -52,7 +55,10 @@ extension SDKSynchronizerClient {
sendTransaction: { _, _, _, _ in return .placeholder() },
shieldFunds: { _, _, _ in return .placeholder() },
wipe: { Empty<Void, Error>().eraseToAnyPublisher() },
switchToEndpoint: { _ in }
switchToEndpoint: { _ in },
proposeTransfer: { _, _, _, _ in .testOnlyFakeProposal(totalFee: 0) },
createProposedTransactions: { _, _ in .success },
proposeShielding: { _, _, _, _ in nil }
)

public static let mock = Self.mocked()
Expand Down Expand Up @@ -172,7 +178,13 @@ extension SDKSynchronizerClient {
)
},
wipe: @escaping () -> AnyPublisher<Void, Error>? = { Fail(error: "Error").eraseToAnyPublisher() },
switchToEndpoint: @escaping (LightWalletEndpoint) async throws -> Void = { _ in }
switchToEndpoint: @escaping (LightWalletEndpoint) async throws -> Void = { _ in },
proposeTransfer:
@escaping (Int, Recipient, Zatoshi, Memo?) async throws -> Proposal = { _, _, _, _ in .testOnlyFakeProposal(totalFee: 0) },
createProposedTransactions:
@escaping (Proposal, UnifiedSpendingKey) async throws -> CreateProposedTransactionsResult = { _, _ in .success },
proposeShielding:
@escaping (Int, Zatoshi, Memo, TransparentAddress?) async throws -> Proposal? = { _, _, _, _ in nil }
) -> SDKSynchronizerClient {
SDKSynchronizerClient(
stateStream: stateStream,
Expand All @@ -191,7 +203,10 @@ extension SDKSynchronizerClient {
sendTransaction: sendTransaction,
shieldFunds: shieldFunds,
wipe: wipe,
switchToEndpoint: switchToEndpoint
switchToEndpoint: switchToEndpoint,
proposeTransfer: proposeTransfer,
createProposedTransactions: createProposedTransactions,
proposeShielding: proposeShielding
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum SupportDataGenerator {
public enum Constants {
public static let email = "support@electriccoin.co"
public static let subject = "Zashi"
public static let subjectPPE = "Zashi - transaction error"
}

public static func generate() -> SupportData {
Expand All @@ -43,6 +44,31 @@ public enum SupportDataGenerator {

return SupportData(toAddress: Constants.email, subject: Constants.subject, message: message)
}

public static func generatePartialProposalError(txIds: [String]) -> SupportData {
let data = SupportDataGenerator.generate()

let idsString = txIds.map { id in
"- ID: \(id)"
}
.joined(separator: "\n")

let message =
"""
Hi Zashi Team,
While sending a transaction, I encountered an error state.
This is the list of the transaction IDs:
\(idsString.description)
Thanks for your support.
\(data.message)
"""

return SupportData(toAddress: Constants.email, subject: Constants.subjectPPE, message: message)
}
}

private protocol SupportDataGeneratorItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ public struct ZcashSDKEnvironment {
public let network: ZcashNetwork
public let requiredTransactionConfirmations: Int
public let sdkVersion: String
public let shieldingThreshold: Zatoshi
public let tokenName: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extension ZcashSDKEnvironment {
network: network,
requiredTransactionConfirmations: ZcashSDKConstants.requiredTransactionConfirmations,
sdkVersion: "0.18.1-beta",
shieldingThreshold: Zatoshi(100_000),
tokenName: network.networkType == .testnet ? "TAZ" : "ZEC"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extension ZcashSDKEnvironment: TestDependencyKey {
network: ZcashNetworkBuilder.network(for: .testnet),
requiredTransactionConfirmations: ZcashSDKConstants.requiredTransactionConfirmations,
sdkVersion: "0.18.1-beta",
shieldingThreshold: Zatoshi(100_000),
tokenName: "TAZ"
)
}
Loading

0 comments on commit 1bf484c

Please sign in to comment.