diff --git a/secant.xcodeproj/project.pbxproj b/secant.xcodeproj/project.pbxproj index 271114a..75427bb 100644 --- a/secant.xcodeproj/project.pbxproj +++ b/secant.xcodeproj/project.pbxproj @@ -42,6 +42,8 @@ 0DACFA9927209FA70039EEA5 /* Roboto-BlackItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 0DACFA8C27209FA70039EEA5 /* Roboto-BlackItalic.ttf */; }; 0DACFA9A27209FA70039EEA5 /* Roboto-Light.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 0DACFA8D27209FA70039EEA5 /* Roboto-Light.ttf */; }; 0DACFA9C27209FA70039EEA5 /* Roboto-ThinItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 0DACFA8F27209FA70039EEA5 /* Roboto-ThinItalic.ttf */; }; + 0DB4E0B12881F2DB00947B78 /* WalletBalance+testing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DB4E0B02881F2DB00947B78 /* WalletBalance+testing.swift */; }; + 0DB4E0B42881FD9100947B78 /* ZcashLightClientKit in Frameworks */ = {isa = PBXBuildFile; productRef = 0DB4E0B32881FD9100947B78 /* ZcashLightClientKit */; }; 0DB8AA81271DC7520035BC9D /* DesignGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DB8AA80271DC7520035BC9D /* DesignGuide.swift */; }; 0DC487C32772574C00BE6A63 /* RecoveryPhraseBackupSucceededView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DC487C22772574C00BE6A63 /* RecoveryPhraseBackupSucceededView.swift */; }; 0DDB6A5127737D4A0012A410 /* RecoveryPhraseBackupFailedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DDB6A5027737D4A0012A410 /* RecoveryPhraseBackupFailedView.swift */; }; @@ -97,7 +99,6 @@ 9E2F1C8F280EDE09004E65FE /* Drawer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E2F1C8E280EDE09004E65FE /* Drawer.swift */; }; 9E37A2B827C8F59F00AE57B3 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9E37A2B727C8F59F00AE57B3 /* Localizable.strings */; }; 9E391124283E4CAC0073DD9A /* ImportWalletTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E391123283E4CAC0073DD9A /* ImportWalletTests.swift */; }; - 9E391129283F74590073DD9A /* Zatoshi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E391128283F74590073DD9A /* Zatoshi.swift */; }; 9E39112E283F91600073DD9A /* ZatoshiTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E39112D283F91600073DD9A /* ZatoshiTests.swift */; }; 9E391132284644580073DD9A /* AppInitializationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E391131284644580073DD9A /* AppInitializationTests.swift */; }; 9E3911392848AD500073DD9A /* HomeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E3911382848AD500073DD9A /* HomeTests.swift */; }; @@ -266,6 +267,7 @@ 0DACFA8C27209FA70039EEA5 /* Roboto-BlackItalic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-BlackItalic.ttf"; sourceTree = ""; }; 0DACFA8D27209FA70039EEA5 /* Roboto-Light.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Light.ttf"; sourceTree = ""; }; 0DACFA8F27209FA70039EEA5 /* Roboto-ThinItalic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-ThinItalic.ttf"; sourceTree = ""; }; + 0DB4E0B02881F2DB00947B78 /* WalletBalance+testing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WalletBalance+testing.swift"; sourceTree = ""; }; 0DB8AA80271DC7520035BC9D /* DesignGuide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DesignGuide.swift; sourceTree = ""; }; 0DC487C22772574C00BE6A63 /* RecoveryPhraseBackupSucceededView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecoveryPhraseBackupSucceededView.swift; sourceTree = ""; }; 0DDB6A5027737D4A0012A410 /* RecoveryPhraseBackupFailedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecoveryPhraseBackupFailedView.swift; sourceTree = ""; }; @@ -319,7 +321,6 @@ 9E2F1C8E280EDE09004E65FE /* Drawer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Drawer.swift; sourceTree = ""; }; 9E37A2B727C8F59F00AE57B3 /* Localizable.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = ""; }; 9E391123283E4CAC0073DD9A /* ImportWalletTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportWalletTests.swift; sourceTree = ""; }; - 9E391128283F74590073DD9A /* Zatoshi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Zatoshi.swift; sourceTree = ""; }; 9E39112D283F91600073DD9A /* ZatoshiTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZatoshiTests.swift; sourceTree = ""; }; 9E391131284644580073DD9A /* AppInitializationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInitializationTests.swift; sourceTree = ""; }; 9E3911382848AD500073DD9A /* HomeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeTests.swift; sourceTree = ""; }; @@ -430,6 +431,7 @@ 9EF8139827F1FAEC0075AF48 /* ZcashLightClientKit in Frameworks */, 9E6612312878337F00C75B70 /* Lottie in Frameworks */, 9E7CB6182872D3DF00A02233 /* URLRouting in Frameworks */, + 0DB4E0B42881FD9100947B78 /* ZcashLightClientKit in Frameworks */, 9E2AC0FF27D8EC120042AA47 /* MnemonicSwift in Frameworks */, 6654C73A2715A38000901167 /* ComposableArchitecture in Frameworks */, 9EAB466F285A0468002904A0 /* _URLRouting in Frameworks */, @@ -977,7 +979,6 @@ 0D35CC45277A36E00074316A /* ScrollableWhenScaled.swift */, 2EDA07A327EDE2A900D6F09B /* DebugFrame.swift */, 9E2F1C832809B606004E65FE /* DebugMenu.swift */, - 9E391128283F74590073DD9A /* Zatoshi.swift */, 9E7CB619287310EC00A02233 /* QRCodeGenerator.swift */, ); path = Utils; @@ -1164,6 +1165,7 @@ 9EF8135B27ECC25E0075AF48 /* UserPreferencesStorageTests.swift */, 9E02B56B27FED475005B809B /* DatabaseFilesTests.swift */, 9E39112D283F91600073DD9A /* ZatoshiTests.swift */, + 0DB4E0B02881F2DB00947B78 /* WalletBalance+testing.swift */, ); path = UtilTests; sourceTree = ""; @@ -1298,6 +1300,7 @@ 9EAB466E285A0468002904A0 /* _URLRouting */, 9E7CB6172872D3DF00A02233 /* URLRouting */, 9E6612302878337F00C75B70 /* Lottie */, + 0DB4E0B32881FD9100947B78 /* ZcashLightClientKit */, ); productName = secant; productReference = 0D4E7A0526B364170058B01E /* secant-testnet.app */; @@ -1379,6 +1382,7 @@ 9EAB466B285A0468002904A0 /* XCRemoteSwiftPackageReference "swift-parsing" */, 9E7CB6162872D3DF00A02233 /* XCRemoteSwiftPackageReference "swift-url-routing" */, 9E66122F2878337F00C75B70 /* XCRemoteSwiftPackageReference "lottie-ios" */, + 0DB4E0B22881FD9100947B78 /* XCRemoteSwiftPackageReference "ZcashLightClientKit" */, ); productRefGroup = 0D4E7A0626B364170058B01E /* Products */; projectDirPath = ""; @@ -1523,7 +1527,6 @@ 9E66122C2877188700C75B70 /* SyncStatusSnapshot.swift in Sources */, 9E4DC6E227C4C6B700E657F4 /* SecantButtonStyles.swift in Sources */, 0DDB6A5127737D4A0012A410 /* RecoveryPhraseBackupFailedView.swift in Sources */, - 9E391129283F74590073DD9A /* Zatoshi.swift in Sources */, 0D6D628B276A528E002FB4CC /* DropDelegate.swift in Sources */, 9E2DF99D27CF704D00649636 /* ImportSeedEditor.swift in Sources */, F9971A5327680DD000A2DB75 /* ProfileStore.swift in Sources */, @@ -1658,6 +1661,7 @@ 9E9ECC9C28589E150099D5A2 /* OnboardingSnapshotTests.swift in Sources */, 9E9ECC9728589E150099D5A2 /* HomeSnapshotTests.swift in Sources */, 9EF8135C27ECC25E0075AF48 /* WalletStorageTests.swift in Sources */, + 0DB4E0B12881F2DB00947B78 /* WalletBalance+testing.swift in Sources */, 9E02B56C27FED475005B809B /* DatabaseFilesTests.swift in Sources */, 9EF8135D27ECC25E0075AF48 /* UserPreferencesStorageTests.swift in Sources */, ); @@ -1977,6 +1981,14 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ + 0DB4E0B22881FD9100947B78 /* XCRemoteSwiftPackageReference "ZcashLightClientKit" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/zcash/ZcashLightClientKit/"; + requirement = { + branch = master; + kind = branch; + }; + }; 6654C7382715A38000901167 /* XCRemoteSwiftPackageReference "swift-composable-architecture" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/pointfreeco/swift-composable-architecture"; @@ -2021,13 +2033,18 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/zcash/ZcashLightClientKit"; requirement = { - kind = exactVersion; - version = "0.14.0-beta"; + branch = master; + kind = branch; }; }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 0DB4E0B32881FD9100947B78 /* ZcashLightClientKit */ = { + isa = XCSwiftPackageProductDependency; + package = 0DB4E0B22881FD9100947B78 /* XCRemoteSwiftPackageReference "ZcashLightClientKit" */; + productName = ZcashLightClientKit; + }; 6654C7392715A38000901167 /* ComposableArchitecture */ = { isa = XCSwiftPackageProductDependency; package = 6654C7382715A38000901167 /* XCRemoteSwiftPackageReference "swift-composable-architecture" */; diff --git a/secant.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/secant.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 9453bc5..7cda378 100644 --- a/secant.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/secant.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/grpc/grpc-swift.git", "state" : { - "revision" : "d772b688d718c2eb29f99b535fc4d92ebba031c5", - "version" : "1.8.1" + "revision" : "4c63368b7462305903507e8acebd77264c0fb695", + "version" : "1.8.2" } }, { @@ -140,8 +140,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-ssl.git", "state" : { - "revision" : "42436a25ff32c390465567f5c089a9a8ce8d7baf", - "version" : "2.20.0" + "revision" : "c30c680c78c99afdabf84805a83c8745387c4ac7", + "version" : "2.20.2" } }, { @@ -203,8 +203,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/zcash/ZcashLightClientKit", "state" : { - "revision" : "74f3ae20f26748e162c051e5fa343c71febc4294", - "version" : "0.14.0-beta" + "branch" : "master", + "revision" : "4e260419e1e07af094e9795f47f350a9d4008383" } } ], diff --git a/secant/Features/App/AppStore.swift b/secant/Features/App/AppStore.swift index be6b24d..1d7d912 100644 --- a/secant/Features/App/AppStore.swift +++ b/secant/Features/App/AppStore.swift @@ -501,7 +501,7 @@ extension AppReducer { case .home: return Effect(value: .deeplinkHome) case let .send(amount, address, memo): - return Effect(value: .deeplinkSend(Zatoshi(amount: amount), address, memo)) + return Effect(value: .deeplinkSend(Zatoshi(amount), address, memo)) } } } diff --git a/secant/Features/Home/HomeStore.swift b/secant/Features/Home/HomeStore.swift index 801b721..c309fa4 100644 --- a/secant/Features/Home/HomeStore.swift +++ b/secant/Features/Home/HomeStore.swift @@ -65,7 +65,7 @@ enum HomeAction: Equatable { case scan(ScanAction) case synchronizerStateChanged(WrappedSDKSynchronizerState) case walletEvents(WalletEventsFlowAction) - case updateBalance(Balance) + case updateBalance(WalletBalance) case updateDrawer(DrawerOverlay) case updateRoute(HomeState.Route?) case updateSynchronizerStatus @@ -139,8 +139,8 @@ extension HomeReducer { return Effect(value: .updateSynchronizerStatus) case .updateBalance(let balance): - state.totalBalance = Zatoshi(amount: balance.total) - state.verifiedBalance = Zatoshi(amount: balance.verified) + state.totalBalance = balance.total + state.verifiedBalance = balance.verified return .none case .updateDrawer(let drawerOverlay): @@ -155,7 +155,7 @@ extension HomeReducer { state.synchronizerStatusSnapshot = environment.SDKSynchronizer.statusSnapshot() return environment.SDKSynchronizer.getShieldedBalance() .receive(on: environment.scheduler) - .map({ Balance(verified: $0.verified, total: $0.total) }) + .map({ WalletBalance(verified: $0.verified, total: $0.total) }) .map(HomeAction.updateBalance) .eraseToEffect() diff --git a/secant/Features/SendFlow/SendFlowStore.swift b/secant/Features/SendFlow/SendFlowStore.swift index 9d4be38..19b36cf 100644 --- a/secant/Features/SendFlow/SendFlowStore.swift +++ b/secant/Features/SendFlow/SendFlowStore.swift @@ -36,7 +36,7 @@ struct SendFlowState: Equatable { } var amount: Zatoshi { - get { Zatoshi(amount: transactionAmountInputState.amount) } + get { Zatoshi(transactionAmountInputState.amount) } set { transactionAmountInputState.amount = newValue.amount transactionAmountInputState.textFieldState.text = newValue.amount == 0 ? @@ -119,7 +119,7 @@ extension SendFlowReducer { return .none case .updateRoute(.confirmation): - state.amount = Zatoshi(amount: state.transactionAmountInputState.amount) + state.amount = Zatoshi(state.transactionAmountInputState.amount) state.address = state.transactionAddressInputState.textFieldState.text state.route = .confirmation return .none @@ -183,7 +183,7 @@ extension SendFlowReducer { case .synchronizerStateChanged(.synced): return environment.SDKSynchronizer.getShieldedBalance() .receive(on: environment.scheduler) - .map({ Zatoshi(amount: $0.total) }) + .map({ $0.total }) .map(SendFlowAction.updateBalance) .eraseToEffect() diff --git a/secant/Features/SendFlow/Views/CreateTransactionView.swift b/secant/Features/SendFlow/Views/CreateTransactionView.swift index 8ff29a5..b8cc4dc 100644 --- a/secant/Features/SendFlow/Views/CreateTransactionView.swift +++ b/secant/Features/SendFlow/Views/CreateTransactionView.swift @@ -10,7 +10,7 @@ struct CreateTransaction: View { return WithViewStore(store) { viewStore in VStack { VStack(spacing: 0) { - Text("Balance \(viewStore.totalBalance.decimalString()) ZEC") + Text("WalletBalance \(viewStore.totalBalance.decimalString()) ZEC") Text("($\(viewStore.totalCurrencyBalance.decimalString()))") .font(.system(size: 13)) .opacity(0.6) diff --git a/secant/Features/WalletEventsFlow/Views/TransactionDetailView.swift b/secant/Features/WalletEventsFlow/Views/TransactionDetailView.swift index fb3a6e0..6ab158e 100644 --- a/secant/Features/WalletEventsFlow/Views/TransactionDetailView.swift +++ b/secant/Features/WalletEventsFlow/Views/TransactionDetailView.swift @@ -1,5 +1,6 @@ import SwiftUI import ComposableArchitecture +import ZcashLightClientKit struct TransactionDetailView: View { enum RowMark { @@ -259,11 +260,11 @@ struct TransactionDetail_Previews: PreviewProvider { """, minedHeight: 1_875_256, zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", - fee: Zatoshi(amount: 1_000_000), + fee: Zatoshi(1_000_000), id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8", status: .paid(success: true), timestamp: 1234567, - zecAmount: Zatoshi(amount: 25_000_000) + zecAmount: Zatoshi(25_000_000) ), viewStore: ViewStore( WalletEventsFlowStore( diff --git a/secant/Features/WalletEventsFlow/Views/TransactionRowView.swift b/secant/Features/WalletEventsFlow/Views/TransactionRowView.swift index 60daa90..649ae4c 100644 --- a/secant/Features/WalletEventsFlow/Views/TransactionRowView.swift +++ b/secant/Features/WalletEventsFlow/Views/TransactionRowView.swift @@ -6,6 +6,7 @@ // import SwiftUI +import ZcashLightClientKit struct TransactionRowView: View { var transaction: TransactionState @@ -107,11 +108,11 @@ struct TransactionRowView_Previews: PreviewProvider { transaction: .init( zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), id: "2", status: .paid(success: true), timestamp: 1234567, - zecAmount: Zatoshi(amount: 123_000_000) + zecAmount: Zatoshi(123_000_000) ) ) .preferredColorScheme(.dark) diff --git a/secant/Features/WalletEventsFlow/WalletEventsFlowStore.swift b/secant/Features/WalletEventsFlow/WalletEventsFlowStore.swift index bb735aa..353d099 100644 --- a/secant/Features/WalletEventsFlow/WalletEventsFlowStore.swift +++ b/secant/Features/WalletEventsFlow/WalletEventsFlowStore.swift @@ -135,22 +135,22 @@ extension TransactionState { static var placeholder: Self { .init( zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), id: "2", status: .paid(success: true), timestamp: 1234567, - zecAmount: Zatoshi(amount: 123_000_000) + zecAmount: Zatoshi(123_000_000) ) } static func statePlaceholder(_ status: Status) -> Self { .init( zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), id: "2", status: status, timestamp: 1234567, - zecAmount: Zatoshi(amount: 123_000_000) + zecAmount: Zatoshi(123_000_000) ) } } @@ -185,11 +185,11 @@ extension IdentifiedArrayOf where Element == TransactionState { return .init( uniqueElements: (0..<30).map { TransactionState( - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), id: String($0), status: .paid(success: true), timestamp: 1234567, - zecAmount: Zatoshi(amount: 25) + zecAmount: Zatoshi(25) ) } ) diff --git a/secant/Models/TransactionState.swift b/secant/Models/TransactionState.swift index c17020e..eeb3d7d 100644 --- a/secant/Models/TransactionState.swift +++ b/secant/Models/TransactionState.swift @@ -32,7 +32,7 @@ struct TransactionState: Equatable, Identifiable { var address: String { zAddress ?? "" } var date: Date { Date(timeIntervalSince1970: timestamp) } - var totalAmount: Zatoshi { Zatoshi(amount: zecAmount.amount + fee.amount) } + var totalAmount: Zatoshi { Zatoshi(zecAmount.amount + fee.amount) } var viewOnlineURL: URL? { URL(string: "https://blockchair.com/zcash/transaction/\(id)") } @@ -53,8 +53,8 @@ extension TransactionState { shielded = true status = sent ? .paid(success: confirmedTransaction.minedHeight > 0) : .received zAddress = confirmedTransaction.toAddress - zecAmount = sent ? Zatoshi(amount: -Int64(confirmedTransaction.value)) : Zatoshi(amount: Int64(confirmedTransaction.value)) - fee = Zatoshi(amount: 10) + zecAmount = sent ? Zatoshi(-confirmedTransaction.value.amount) : confirmedTransaction.value + fee = Zatoshi(10) if let memo = confirmedTransaction.memo { self.memo = memo.asZcashTransactionMemo() } @@ -71,8 +71,8 @@ extension TransactionState { .pending expirationHeight = pendingTransaction.expiryHeight zAddress = pendingTransaction.toAddress - zecAmount = Zatoshi(amount: -Int64(pendingTransaction.value)) - fee = Zatoshi(amount: 10) + zecAmount = pendingTransaction.value + fee = Zatoshi(10) if let memo = pendingTransaction.memo { self.memo = memo.asZcashTransactionMemo() } @@ -102,7 +102,7 @@ extension TransactionState { id: uuid, status: status, timestamp: timestamp, - zecAmount: status == .received ? amount : Zatoshi(amount: -amount.amount) + zecAmount: status == .received ? amount : Zatoshi(-amount.amount) ) } } diff --git a/secant/Models/WalletEvent.swift b/secant/Models/WalletEvent.swift index 076d4ff..0c3a018 100644 --- a/secant/Models/WalletEvent.swift +++ b/secant/Models/WalletEvent.swift @@ -78,7 +78,7 @@ private extension WalletEvent { switch Int.random(in: 0..<6) { case 1: return .received(.statePlaceholder(.received)) case 2: return .failed(.statePlaceholder(.failed)) - case 3: return .shielded(Zatoshi(amount: 234_000_000)) + case 3: return .shielded(Zatoshi(234_000_000)) case 4: return .walletImport(BlockHeight(1_629_724)) case 5: return .pending(.statePlaceholder(.pending)) default: return .send(.placeholder) diff --git a/secant/SecantApp.swift b/secant/SecantApp.swift index 0155036..3e0c368 100644 --- a/secant/SecantApp.swift +++ b/secant/SecantApp.swift @@ -7,6 +7,7 @@ import SwiftUI import ComposableArchitecture +import ZcashLightClientKit final class AppDelegate: NSObject, UIApplicationDelegate { var appStore: AppStore = .placeholder diff --git a/secant/UI Components/TextFields/TransactionAmount/TransactionAmountTextFieldStore.swift b/secant/UI Components/TextFields/TransactionAmount/TransactionAmountTextFieldStore.swift index 339398d..23ce255 100644 --- a/secant/UI Components/TextFields/TransactionAmount/TransactionAmountTextFieldStore.swift +++ b/secant/UI Components/TextFields/TransactionAmount/TransactionAmountTextFieldStore.swift @@ -6,7 +6,7 @@ // import ComposableArchitecture - +import ZcashLightClientKit typealias TransactionAmountTextFieldReducer = Reducer< TransactionAmountTextFieldState, TransactionAmountTextFieldAction, diff --git a/secant/Utils/Zatoshi.swift b/secant/Utils/Zatoshi.swift deleted file mode 100644 index d5afefe..0000000 --- a/secant/Utils/Zatoshi.swift +++ /dev/null @@ -1,82 +0,0 @@ -// -// Zatoshi.swift -// secant-testnet -// -// Created by Lukáš Korba on 26.05.2022. -// - -import Foundation - -struct Zatoshi { - enum Constants { - static let oneZecInZatoshi: Int64 = 100_000_000 - static let maxZecSupply: Int64 = 21_000_000 - static let maxZatoshi: Int64 = Constants.oneZecInZatoshi * Constants.maxZecSupply - } - - static var zero: Zatoshi { Zatoshi() } - - static let decimalHandler = NSDecimalNumberHandler( - roundingMode: NSDecimalNumber.RoundingMode.bankers, - scale: 8, - raiseOnExactness: true, - raiseOnOverflow: true, - raiseOnUnderflow: true, - raiseOnDivideByZero: true - ) - - @Clamped(-Constants.maxZatoshi...Constants.maxZatoshi) - var amount: Int64 = 0 - - /// Converts `Zatoshi` to `NSDecimalNumber` - var decimalValue: NSDecimalNumber { - NSDecimalNumber(decimal: Decimal(amount) / Decimal(Constants.oneZecInZatoshi)) - } - - /// Converts `Zatoshi` to human readable format, up to 8 fraction digits - func decimalString(formatter: NumberFormatter = NumberFormatter.zcashNumberFormatter) -> String { - formatter.string(from: decimalValue.roundedZec) ?? "" - } - - /// Converts `Decimal` to `Zatoshi` - static func from(decimal: Decimal) -> Zatoshi { - let roundedZec = NSDecimalNumber(decimal: decimal).roundedZec - let zec2zatoshi = Decimal(Constants.oneZecInZatoshi) * roundedZec.decimalValue - return Zatoshi(amount: NSDecimalNumber(decimal: zec2zatoshi).int64Value) - } - - /// Converts `String` to `Zatoshi` - static func from(decimalString: String, formatter: NumberFormatter = NumberFormatter.zcashNumberFormatter) -> Zatoshi? { - if let number = formatter.number(from: decimalString) { - return Zatoshi.from(decimal: number.decimalValue) - } - - return nil - } - - static func + (left: Zatoshi, right: Zatoshi) -> Zatoshi { - Zatoshi(amount: left.amount + right.amount) - } - - static func - (left: Zatoshi, right: Zatoshi) -> Zatoshi { - Zatoshi(amount: left.amount - right.amount) - } -} - -extension Zatoshi: Equatable { - static func == (lhs: Zatoshi, rhs: Zatoshi) -> Bool { - lhs.amount == rhs.amount - } -} - -extension NSDecimalNumber { - /// Round the decimal to 8 fraction digits - var roundedZec: NSDecimalNumber { - self.rounding(accordingToBehavior: Zatoshi.decimalHandler) - } - - /// Converts `NSDecimalNumber` to human readable format, up to 8 fraction digits - var decimalString: String { - self.roundedZec.stringValue - } -} diff --git a/secant/Wrappers/WrappedSDKSynchronizer.swift b/secant/Wrappers/WrappedSDKSynchronizer.swift index 0dc645e..481904b 100644 --- a/secant/Wrappers/WrappedSDKSynchronizer.swift +++ b/secant/Wrappers/WrappedSDKSynchronizer.swift @@ -12,7 +12,6 @@ import ComposableArchitecture enum WrappedSDKSynchronizerState: Equatable { case unknown - case transactionsUpdated case started case progressUpdated @@ -32,11 +31,6 @@ enum WrappedSDKSynchronizerState: Equatable { case connectionStateChanged } -struct Balance: WalletBalance, Equatable { - var verified: Int64 - var total: Int64 -} - protocol WrappedSDKSynchronizer { var synchronizer: SDKSynchronizer? { get } var stateChanged: CurrentValueSubject { get } @@ -47,7 +41,7 @@ protocol WrappedSDKSynchronizer { func stop() func statusSnapshot() -> SyncStatusSnapshot - func getShieldedBalance() -> Effect + func getShieldedBalance() -> Effect func getAllClearedTransactions() -> Effect<[WalletEvent], Never> func getAllPendingTransactions() -> Effect<[WalletEvent], Never> func getAllTransactions() -> Effect<[WalletEvent], Never> @@ -151,10 +145,10 @@ class LiveWrappedSDKSynchronizer: WrappedSDKSynchronizer { return SyncStatusSnapshot.snapshotFor(state: synchronizer.status) } - func getShieldedBalance() -> Effect { - if let shieldedVerifiedBalance = synchronizer?.getShieldedVerifiedBalance(), - let shieldedTotalBalance = synchronizer?.getShieldedBalance(accountIndex: 0) { - return Effect(value: Balance(verified: shieldedVerifiedBalance, total: shieldedTotalBalance)) + func getShieldedBalance() -> Effect { + if let shieldedVerifiedBalance: Zatoshi = synchronizer?.getShieldedVerifiedBalance(), + let shieldedTotalBalance: Zatoshi = synchronizer?.getShieldedBalance(accountIndex: 0) { + return Effect(value: WalletBalance(verified: shieldedVerifiedBalance, total: shieldedTotalBalance)) } return .none @@ -232,7 +226,7 @@ class LiveWrappedSDKSynchronizer: WrappedSDKSynchronizer { Future { [weak self] promise in self?.synchronizer?.sendToAddress( spendingKey: spendingKey, - zatoshi: zatoshi.amount, + zatoshi: zatoshi, toAddress: recipientAddress, memo: memo, from: account) { result in @@ -289,17 +283,17 @@ class MockWrappedSDKSynchronizer: WrappedSDKSynchronizer { return SyncStatusSnapshot.snapshotFor(state: synchronizer.status) } - func getShieldedBalance() -> Effect { - return Effect(value: Balance(verified: 12345000, total: 12345000)) + func getShieldedBalance() -> Effect { + return Effect(value: WalletBalance(verified: Zatoshi(12345000), total: Zatoshi(12345000))) } func getAllClearedTransactions() -> Effect<[WalletEvent], Never> { let mocked: [TransactionStateMockHelper] = [ - TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(amount: 1), status: .paid(success: false), uuid: "1"), - TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(amount: 2), uuid: "2"), - TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(amount: 3), status: .paid(success: true), uuid: "3"), - TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(amount: 4), uuid: "4"), - TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(amount: 5), uuid: "5") + TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(1), status: .paid(success: false), uuid: "1"), + TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(2), uuid: "2"), + TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(3), status: .paid(success: true), uuid: "3"), + TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(4), uuid: "4"), + TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(5), uuid: "5") ] return Effect( @@ -307,7 +301,7 @@ class MockWrappedSDKSynchronizer: WrappedSDKSynchronizer { mocked.map { let transaction = TransactionState.placeholder( amount: $0.amount, - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), shielded: $0.shielded, status: $0.status, timestamp: $0.date, @@ -320,10 +314,10 @@ class MockWrappedSDKSynchronizer: WrappedSDKSynchronizer { func getAllPendingTransactions() -> Effect<[WalletEvent], Never> { let mocked: [TransactionStateMockHelper] = [ - TransactionStateMockHelper(date: 1651039606, amount: Zatoshi(amount: 6), status: .paid(success: false)), - TransactionStateMockHelper(date: 1651039303, amount: Zatoshi(amount: 7)), - TransactionStateMockHelper(date: 1651039707, amount: Zatoshi(amount: 8), status: .paid(success: true)), - TransactionStateMockHelper(date: 1651039808, amount: Zatoshi(amount: 9)) + TransactionStateMockHelper(date: 1651039606, amount: Zatoshi(6), status: .paid(success: false)), + TransactionStateMockHelper(date: 1651039303, amount: Zatoshi(7)), + TransactionStateMockHelper(date: 1651039707, amount: Zatoshi(8), status: .paid(success: true)), + TransactionStateMockHelper(date: 1651039808, amount: Zatoshi(9)) ] return Effect( @@ -331,7 +325,7 @@ class MockWrappedSDKSynchronizer: WrappedSDKSynchronizer { mocked.map { let transaction = TransactionState.placeholder( amount: $0.amount, - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), shielded: $0.shielded, status: $0.status, timestamp: $0.date @@ -368,11 +362,11 @@ class MockWrappedSDKSynchronizer: WrappedSDKSynchronizer { minedHeight: 50, shielded: true, zAddress: "tteafadlamnelkqe", - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), id: "id", status: .paid(success: true), timestamp: 1234567, - zecAmount: Zatoshi(amount: 10) + zecAmount: Zatoshi(10) ) return Effect(value: Result.success(transactionState)) @@ -399,17 +393,17 @@ class TestWrappedSDKSynchronizer: WrappedSDKSynchronizer { func statusSnapshot() -> SyncStatusSnapshot { .default } - func getShieldedBalance() -> Effect { + func getShieldedBalance() -> Effect { return .none } func getAllClearedTransactions() -> Effect<[WalletEvent], Never> { let mocked: [TransactionStateMockHelper] = [ - TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(amount: 1), status: .paid(success: false), uuid: "aa11"), - TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(amount: 2), uuid: "bb22"), - TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(amount: 3), status: .paid(success: true), uuid: "cc33"), - TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(amount: 4), uuid: "dd44"), - TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(amount: 5), uuid: "ee55") + TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(1), status: .paid(success: false), uuid: "aa11"), + TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(2), uuid: "bb22"), + TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(3), status: .paid(success: true), uuid: "cc33"), + TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(4), uuid: "dd44"), + TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(5), uuid: "ee55") ] return Effect( @@ -417,7 +411,7 @@ class TestWrappedSDKSynchronizer: WrappedSDKSynchronizer { mocked.map { let transaction = TransactionState.placeholder( amount: $0.amount, - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), shielded: $0.shielded, status: $0.status, timestamp: $0.date, @@ -432,13 +426,13 @@ class TestWrappedSDKSynchronizer: WrappedSDKSynchronizer { let mocked: [TransactionStateMockHelper] = [ TransactionStateMockHelper( date: 1651039606, - amount: Zatoshi(amount: 6), + amount: Zatoshi(6), status: .paid(success: false), uuid: "ff66" ), - TransactionStateMockHelper(date: 1651039303, amount: Zatoshi(amount: 7), uuid: "gg77"), - TransactionStateMockHelper(date: 1651039707, amount: Zatoshi(amount: 8), status: .paid(success: true), uuid: "hh88"), - TransactionStateMockHelper(date: 1651039808, amount: Zatoshi(amount: 9), uuid: "ii99") + TransactionStateMockHelper(date: 1651039303, amount: Zatoshi(7), uuid: "gg77"), + TransactionStateMockHelper(date: 1651039707, amount: Zatoshi(8), status: .paid(success: true), uuid: "hh88"), + TransactionStateMockHelper(date: 1651039808, amount: Zatoshi(9), uuid: "ii99") ] return Effect( @@ -446,7 +440,7 @@ class TestWrappedSDKSynchronizer: WrappedSDKSynchronizer { mocked.map { let transaction = TransactionState.placeholder( amount: $0.amount, - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), shielded: $0.shielded, status: $0.amount.amount > 5 ? .pending : $0.status, timestamp: $0.date, diff --git a/secantTests/DeeplinkTests/DeeplinkTests.swift b/secantTests/DeeplinkTests/DeeplinkTests.swift index 12444ff..2ee030d 100644 --- a/secantTests/DeeplinkTests/DeeplinkTests.swift +++ b/secantTests/DeeplinkTests/DeeplinkTests.swift @@ -60,7 +60,7 @@ class DeeplinkTests: XCTestCase { environment: testEnvironment ) - let amount = Zatoshi(amount: 123_000_000) + let amount = Zatoshi(123_000_000) let address = "address" let memo = "testing some memo" @@ -150,7 +150,7 @@ class DeeplinkTests: XCTestCase { store.send(.deeplink(url)) - let amount = Zatoshi(amount: 123_000_000) + let amount = Zatoshi(123_000_000) let address = "" let memo = "" @@ -199,7 +199,7 @@ class DeeplinkTests: XCTestCase { store.send(.deeplink(url)) - let amount = Zatoshi(amount: 123_000_000) + let amount = Zatoshi(123_000_000) let address = "address" let memo = "some text" diff --git a/secantTests/HomeTests/HomeTests.swift b/secantTests/HomeTests/HomeTests.swift index 9323287..d319c3d 100644 --- a/secantTests/HomeTests/HomeTests.swift +++ b/secantTests/HomeTests/HomeTests.swift @@ -8,6 +8,7 @@ import XCTest @testable import secant_testnet import ComposableArchitecture +import ZcashLightClientKit class HomeTests: XCTestCase { func testSynchronizerStateChanged_AnyButSynced() throws { @@ -37,10 +38,10 @@ class HomeTests: XCTestCase { store.receive(.updateSynchronizerStatus) - let balance = Balance(verified: 12_345_000, total: 12_345_000) + let balance = WalletBalance(verified: Zatoshi(12_345_000), total: Zatoshi(12_345_000)) store.receive(.updateBalance(balance)) { state in - state.totalBalance = Zatoshi(amount: 12_345_000) - state.verifiedBalance = Zatoshi(amount: 12_345_000) + state.totalBalance = Zatoshi(12_345_000) + state.verifiedBalance = Zatoshi(12_345_000) } } @@ -78,16 +79,16 @@ class HomeTests: XCTestCase { // ad 2. let transactionsHelper: [TransactionStateMockHelper] = [ - TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(amount: 1), status: .paid(success: false), uuid: "1"), - TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(amount: 2), uuid: "2"), - TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(amount: 3), status: .paid(success: true), uuid: "3"), - TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(amount: 4), uuid: "4"), - TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(amount: 5), uuid: "5") + TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(1), status: .paid(success: false), uuid: "1"), + TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(2), uuid: "2"), + TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(3), status: .paid(success: true), uuid: "3"), + TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(4), uuid: "4"), + TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(5), uuid: "5") ] let walletEvents: [WalletEvent] = transactionsHelper.map { let transaction = TransactionState.placeholder( amount: $0.amount, - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), shielded: $0.shielded, status: $0.status, timestamp: $0.date, @@ -99,11 +100,11 @@ class HomeTests: XCTestCase { store.receive(.updateWalletEvents(walletEvents)) // ad 3. - let balance = Balance(verified: 12_345_000, total: 12_345_000) + let balance = WalletBalance(verified: Zatoshi(12_345_000), total: Zatoshi(12_345_000)) store.receive(.updateBalance(balance)) { state in - state.verifiedBalance = Zatoshi(amount: 12_345_000) - state.totalBalance = Zatoshi(amount: 12_345_000) + state.verifiedBalance = Zatoshi(12_345_000) + state.totalBalance = Zatoshi(12_345_000) } } @@ -226,10 +227,10 @@ class HomeTests: XCTestCase { store.receive(.synchronizerStateChanged(.unknown)) store.receive(.updateSynchronizerStatus) - let balance = Balance(verified: 12_345_000, total: 12_345_000) + let balance = WalletBalance(verified: Zatoshi(12_345_000), total: Zatoshi(12_345_000)) store.receive(.updateBalance(balance)) { state in - state.totalBalance = Zatoshi(amount: 12_345_000) - state.verifiedBalance = Zatoshi(amount: 12_345_000) + state.totalBalance = Zatoshi(12_345_000) + state.verifiedBalance = Zatoshi(12_345_000) } // long-living (cancelable) effects need to be properly canceled. diff --git a/secantTests/SendTests/SendTests.swift b/secantTests/SendTests/SendTests.swift index 0968514..722b623 100644 --- a/secantTests/SendTests/SendTests.swift +++ b/secantTests/SendTests/SendTests.swift @@ -64,11 +64,11 @@ class SendTests: XCTestCase { minedHeight: 50, shielded: true, zAddress: "tteafadlamnelkqe", - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), id: "id", status: .paid(success: true), timestamp: 1234567, - zecAmount: Zatoshi(amount: 10) + zecAmount: Zatoshi(10) ) // check the success transaction to be received back diff --git a/secantTests/SnapshotTests/HomeSnapshotTests/HomeCircularProgressSnapshotTests.swift b/secantTests/SnapshotTests/HomeSnapshotTests/HomeCircularProgressSnapshotTests.swift index b02a7c9..ef14e2b 100644 --- a/secantTests/SnapshotTests/HomeSnapshotTests/HomeCircularProgressSnapshotTests.swift +++ b/secantTests/SnapshotTests/HomeSnapshotTests/HomeCircularProgressSnapshotTests.swift @@ -25,7 +25,7 @@ class HomeCircularProgressSnapshotTests: XCTestCase { } } - let balance = Balance(verified: 15_345_000, total: 15_345_000) + let balance = WalletBalance(verified: Zatoshi(15_345_000), total: Zatoshi(15_345_000)) let testScheduler = DispatchQueue.test @@ -48,9 +48,9 @@ class HomeCircularProgressSnapshotTests: XCTestCase { sendState: .placeholder, scanState: .placeholder, synchronizerStatusSnapshot: .default, - totalBalance: Zatoshi(amount: balance.total), + totalBalance: balance.total, walletEventsState: .emptyPlaceHolder, - verifiedBalance: Zatoshi(amount: balance.verified) + verifiedBalance: balance.verified ), reducer: .default, environment: testEnvironment @@ -73,7 +73,7 @@ class HomeCircularProgressSnapshotTests: XCTestCase { } } - let balance = Balance(verified: 15_345_000, total: 15_345_000) + let balance = WalletBalance(verified: 15_345_000, total: 15_345_000) let testScheduler = DispatchQueue.test @@ -96,9 +96,9 @@ class HomeCircularProgressSnapshotTests: XCTestCase { sendState: .placeholder, scanState: .placeholder, synchronizerStatusSnapshot: .default, - totalBalance: Zatoshi(amount: balance.total), + totalBalance: balance.total, walletEventsState: .emptyPlaceHolder, - verifiedBalance: Zatoshi(amount: balance.verified) + verifiedBalance: balance.verified ), reducer: .default, environment: testEnvironment @@ -114,7 +114,7 @@ class HomeCircularProgressSnapshotTests: XCTestCase { } } - let balance = Balance(verified: 15_345_000, total: 15_345_000) + let balance = WalletBalance(verified: 15_345_000, total: 15_345_000) let testScheduler = DispatchQueue.test @@ -137,9 +137,9 @@ class HomeCircularProgressSnapshotTests: XCTestCase { sendState: .placeholder, scanState: .placeholder, synchronizerStatusSnapshot: .default, - totalBalance: Zatoshi(amount: balance.total), + totalBalance: balance.total, walletEventsState: .emptyPlaceHolder, - verifiedBalance: Zatoshi(amount: balance.verified) + verifiedBalance: balance.verified ), reducer: .default, environment: testEnvironment diff --git a/secantTests/SnapshotTests/HomeSnapshotTests/HomeSnapshotTests.swift b/secantTests/SnapshotTests/HomeSnapshotTests/HomeSnapshotTests.swift index 98fcbef..2693466 100644 --- a/secantTests/SnapshotTests/HomeSnapshotTests/HomeSnapshotTests.swift +++ b/secantTests/SnapshotTests/HomeSnapshotTests/HomeSnapshotTests.swift @@ -8,20 +8,21 @@ import XCTest @testable import secant_testnet import ComposableArchitecture +import ZcashLightClientKit class HomeSnapshotTests: XCTestCase { func testHomeSnapshot() throws { let transactionsHelper: [TransactionStateMockHelper] = [ - TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(amount: 1), status: .paid(success: true), uuid: "1"), - TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(amount: 2), status: .pending, uuid: "2"), - TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(amount: 3), status: .received, uuid: "3"), - TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(amount: 4), status: .failed, uuid: "4") + TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(1), status: .paid(success: true), uuid: "1"), + TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(2), status: .pending, uuid: "2"), + TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(3), status: .received, uuid: "3"), + TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(4), status: .failed, uuid: "4") ] let walletEvents: [WalletEvent] = transactionsHelper.map { var transaction = TransactionState.placeholder( amount: $0.amount, - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), shielded: $0.shielded, status: $0.status, timestamp: $0.date, @@ -32,7 +33,7 @@ class HomeSnapshotTests: XCTestCase { return WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp) } - let balance = Balance(verified: 12_345_000, total: 12_345_000) + let balance = WalletBalance(verified: 12_345_000, total: 12_345_000) let store = HomeStore( initialState: .init( @@ -42,9 +43,9 @@ class HomeSnapshotTests: XCTestCase { sendState: .placeholder, scanState: .placeholder, synchronizerStatusSnapshot: .default, - totalBalance: Zatoshi(amount: balance.total), + totalBalance: balance.total, walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: walletEvents)), - verifiedBalance: Zatoshi(amount: balance.verified) + verifiedBalance: balance.verified ), reducer: .default, environment: .demo diff --git a/secantTests/SnapshotTests/WalletEventsSnapshotTests/WalletEventsSnapshotTests.swift b/secantTests/SnapshotTests/WalletEventsSnapshotTests/WalletEventsSnapshotTests.swift index ba7e2bd..f921fc5 100644 --- a/secantTests/SnapshotTests/WalletEventsSnapshotTests/WalletEventsSnapshotTests.swift +++ b/secantTests/SnapshotTests/WalletEventsSnapshotTests/WalletEventsSnapshotTests.swift @@ -8,21 +8,22 @@ import XCTest @testable import secant_testnet import ComposableArchitecture +import ZcashLightClientKit // swiftlint:disable type_body_length class WalletEventsSnapshotTests: XCTestCase { func testFullWalletEventsSnapshot() throws { let transactionsHelper: [TransactionStateMockHelper] = [ - TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(amount: 1), status: .paid(success: true), uuid: "1"), - TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(amount: 2), status: .pending, uuid: "2"), - TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(amount: 3), status: .received, uuid: "3"), - TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(amount: 4), status: .failed, uuid: "4") + TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(1), status: .paid(success: true), uuid: "1"), + TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(2), status: .pending, uuid: "2"), + TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(3), status: .received, uuid: "3"), + TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(4), status: .failed, uuid: "4") ] let walletEvents: [WalletEvent] = transactionsHelper.map { var transaction = TransactionState.placeholder( amount: $0.amount, - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), shielded: $0.shielded, status: $0.status, timestamp: $0.date, @@ -33,7 +34,7 @@ class WalletEventsSnapshotTests: XCTestCase { return WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp) } - let balance = Balance(verified: 12_345_000, total: 12_345_000) + let balance = WalletBalance(verified: 12_345_000, total: 12_345_000) let store = HomeStore( initialState: .init( @@ -43,9 +44,9 @@ class WalletEventsSnapshotTests: XCTestCase { sendState: .placeholder, scanState: .placeholder, synchronizerStatusSnapshot: .default, - totalBalance: Zatoshi(amount: balance.total), + totalBalance: balance.total, walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: walletEvents)), - verifiedBalance: Zatoshi(amount: balance.verified) + verifiedBalance: balance.verified ), reducer: .default, environment: .demo @@ -72,16 +73,16 @@ class WalletEventsSnapshotTests: XCTestCase { """, minedHeight: 1_875_256, zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", - fee: Zatoshi(amount: 1_000_000), + fee: Zatoshi(1_000_000), id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8", status: .paid(success: true), timestamp: 1234567, - zecAmount: Zatoshi(amount: 25_000_000) + zecAmount: Zatoshi(25_000_000) ) let walletEvent = WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp) - let balance = Balance(verified: 12_345_000, total: 12_345_000) + let balance = WalletBalance(verified: 12_345_000, total: 12_345_000) let store = HomeStore( initialState: .init( drawerOverlay: .partial, @@ -90,9 +91,9 @@ class WalletEventsSnapshotTests: XCTestCase { sendState: .placeholder, scanState: .placeholder, synchronizerStatusSnapshot: .default, - totalBalance: Zatoshi(amount: balance.total), + totalBalance: balance.total, walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: [walletEvent])), - verifiedBalance: Zatoshi(amount: balance.verified) + verifiedBalance: balance.verified ), reducer: .default, environment: .demo @@ -129,16 +130,16 @@ class WalletEventsSnapshotTests: XCTestCase { """, minedHeight: 1_875_256, zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", - fee: Zatoshi(amount: 1_000_000), + fee: Zatoshi(1_000_000), id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8", status: .received, timestamp: 1234567, - zecAmount: Zatoshi(amount: 25_000_000) + zecAmount: Zatoshi(25_000_000) ) let walletEvent = WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp) - let balance = Balance(verified: 12_345_000, total: 12_345_000) + let balance = WalletBalance(verified: 12_345_000, total: 12_345_000) let store = HomeStore( initialState: .init( drawerOverlay: .partial, @@ -147,9 +148,9 @@ class WalletEventsSnapshotTests: XCTestCase { sendState: .placeholder, scanState: .placeholder, synchronizerStatusSnapshot: .default, - totalBalance: Zatoshi(amount: balance.total), + totalBalance: balance.total, walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: [walletEvent])), - verifiedBalance: Zatoshi(amount: balance.verified) + verifiedBalance: balance.verified ), reducer: .default, environment: .demo @@ -186,16 +187,16 @@ class WalletEventsSnapshotTests: XCTestCase { """, minedHeight: 1_875_256, zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", - fee: Zatoshi(amount: 1_000_000), + fee: Zatoshi(1_000_000), id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8", status: .pending, timestamp: 1234567, - zecAmount: Zatoshi(amount: 25_000_000) + zecAmount: Zatoshi(25_000_000) ) let walletEvent = WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp) - let balance = Balance(verified: 12_345_000, total: 12_345_000) + let balance = WalletBalance(verified: 12_345_000, total: 12_345_000) let store = HomeStore( initialState: .init( drawerOverlay: .partial, @@ -204,9 +205,9 @@ class WalletEventsSnapshotTests: XCTestCase { sendState: .placeholder, scanState: .placeholder, synchronizerStatusSnapshot: .default, - totalBalance: Zatoshi(amount: balance.total), + totalBalance: balance.total, walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: [walletEvent])), - verifiedBalance: Zatoshi(amount: balance.verified) + verifiedBalance: balance.verified ), reducer: .default, environment: .demo @@ -249,16 +250,16 @@ class WalletEventsSnapshotTests: XCTestCase { """, minedHeight: 1_875_256, zAddress: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po", - fee: Zatoshi(amount: 1_000_000), + fee: Zatoshi(1_000_000), id: "ff3927e1f83df9b1b0dc75540ddc59ee435eecebae914d2e6dfe8576fbedc9a8", status: .failed, timestamp: 1234567, - zecAmount: Zatoshi(amount: 25_000_000) + zecAmount: Zatoshi(25_000_000) ) let walletEvent = WalletEvent(id: transaction.id, state: .send(transaction), timestamp: transaction.timestamp) - let balance = Balance(verified: 12_345_000, total: 12_345_000) + let balance = WalletBalance(verified: 12_345_000, total: 12_345_000) let store = HomeStore( initialState: .init( drawerOverlay: .partial, @@ -267,9 +268,9 @@ class WalletEventsSnapshotTests: XCTestCase { sendState: .placeholder, scanState: .placeholder, synchronizerStatusSnapshot: .default, - totalBalance: Zatoshi(amount: balance.total), + totalBalance: balance.total, walletEventsState: .init(walletEvents: IdentifiedArrayOf(uniqueElements: [walletEvent])), - verifiedBalance: Zatoshi(amount: balance.verified) + verifiedBalance: balance.verified ), reducer: .default, environment: .demo diff --git a/secantTests/UtilTests/WalletBalance+testing.swift b/secantTests/UtilTests/WalletBalance+testing.swift new file mode 100644 index 0000000..b144035 --- /dev/null +++ b/secantTests/UtilTests/WalletBalance+testing.swift @@ -0,0 +1,15 @@ +// +// WalletBalance+testing.swift +// secantTests +// +// Created by Francisco Gindre on 7/15/22. +// + +import Foundation +import ZcashLightClientKit + +extension WalletBalance { + init(verified: Int, total: Int) { + self.init(verified: Zatoshi(Int64(verified)), total: Zatoshi(Int64(verified))) + } +} diff --git a/secantTests/UtilTests/ZatoshiTests.swift b/secantTests/UtilTests/ZatoshiTests.swift index b5cf3cb..5756e20 100644 --- a/secantTests/UtilTests/ZatoshiTests.swift +++ b/secantTests/UtilTests/ZatoshiTests.swift @@ -7,6 +7,7 @@ import XCTest @testable import secant_testnet +import ZcashLightClientKit class ZatoshiTests: XCTestCase { let usNumberFormatter = NumberFormatter() @@ -21,7 +22,7 @@ class ZatoshiTests: XCTestCase { } func testLowerBound() throws { - let number = Zatoshi(amount: -Zatoshi.Constants.maxZatoshi - 1) + let number = Zatoshi(-Zatoshi.Constants.maxZatoshi - 1) XCTAssertEqual( -Zatoshi.Constants.maxZatoshi, @@ -31,7 +32,7 @@ class ZatoshiTests: XCTestCase { } func testUpperBound() throws { - let number = Zatoshi(amount: Zatoshi.Constants.maxZatoshi + 1) + let number = Zatoshi(Zatoshi.Constants.maxZatoshi + 1) XCTAssertEqual( Zatoshi.Constants.maxZatoshi, @@ -41,37 +42,37 @@ class ZatoshiTests: XCTestCase { } func testAddingZatoshi() throws { - let numberA1 = Zatoshi(amount: 100_000) - let numberB1 = Zatoshi(amount: 200_000) + let numberA1 = Zatoshi(100_000) + let numberB1 = Zatoshi(200_000) let result1 = numberA1 + numberB1 XCTAssertEqual( result1.amount, - Zatoshi(amount: 300_000).amount, + Zatoshi(300_000).amount, "Zatoshi tests: `testAddingZatoshi` the value is expected to be 300_000 but it's \(result1.amount)" ) - let numberA2 = Zatoshi(amount: -100_000) - let numberB2 = Zatoshi(amount: 200_000) + let numberA2 = Zatoshi(-100_000) + let numberB2 = Zatoshi(200_000) let result2 = numberA2 + numberB2 XCTAssertEqual( result2.amount, - Zatoshi(amount: 100_000).amount, + Zatoshi(100_000).amount, "Zatoshi tests: `testAddingZatoshi` the value is expected to be 100_000 but it's \(result2.amount)" ) - let numberA3 = Zatoshi(amount: 100_000) - let numberB3 = Zatoshi(amount: -200_000) + let numberA3 = Zatoshi(100_000) + let numberB3 = Zatoshi(-200_000) let result3 = numberA3 + numberB3 XCTAssertEqual( result3.amount, - Zatoshi(amount: -100_000).amount, + Zatoshi(-100_000).amount, "Zatoshi tests: `testAddingZatoshi` the value is expected to be -100_000 but it's \(result3.amount)" ) - let number = Zatoshi(amount: Zatoshi.Constants.maxZatoshi) + let number = Zatoshi(Zatoshi.Constants.maxZatoshi) let result4 = number + number XCTAssertEqual( @@ -82,37 +83,37 @@ class ZatoshiTests: XCTestCase { } func testSubtractingZatoshi() throws { - let numberA1 = Zatoshi(amount: 100_000) - let numberB1 = Zatoshi(amount: 200_000) + let numberA1 = Zatoshi(100_000) + let numberB1 = Zatoshi(200_000) let result1 = numberA1 - numberB1 XCTAssertEqual( result1.amount, - Zatoshi(amount: -100_000).amount, + Zatoshi(-100_000).amount, "Zatoshi tests: `testSubtractingZatoshi` the value is expected to be -100_000 but it's \(result1.amount)" ) - let numberA2 = Zatoshi(amount: -100_000) - let numberB2 = Zatoshi(amount: 200_000) + let numberA2 = Zatoshi(-100_000) + let numberB2 = Zatoshi(200_000) let result2 = numberA2 - numberB2 XCTAssertEqual( result2.amount, - Zatoshi(amount: -300_000).amount, + Zatoshi(-300_000).amount, "Zatoshi tests: `testSubtractingZatoshi` the value is expected to be -300_000 but it's \(result2.amount)" ) - let numberA3 = Zatoshi(amount: 100_000) - let numberB3 = Zatoshi(amount: -200_000) + let numberA3 = Zatoshi(100_000) + let numberB3 = Zatoshi(-200_000) let result3 = numberA3 - numberB3 XCTAssertEqual( result3.amount, - Zatoshi(amount: 300_000).amount, + Zatoshi(300_000).amount, "Zatoshi tests: `testSubtractingZatoshi` the value is expected to be 300_000 but it's \(result3.amount)" ) - let number = Zatoshi(amount: -Zatoshi.Constants.maxZatoshi) + let number = Zatoshi(-Zatoshi.Constants.maxZatoshi) let result4 = number + number XCTAssertEqual( diff --git a/secantTests/WalletEventsTests/WalletEventsTests.swift b/secantTests/WalletEventsTests/WalletEventsTests.swift index e56140f..aea0df9 100644 --- a/secantTests/WalletEventsTests/WalletEventsTests.swift +++ b/secantTests/WalletEventsTests/WalletEventsTests.swift @@ -8,6 +8,7 @@ import XCTest @testable import secant_testnet import ComposableArchitecture +import ZcashLightClientKit class WalletEventsTests: XCTestCase { static let testScheduler = DispatchQueue.test @@ -42,26 +43,26 @@ class WalletEventsTests: XCTestCase { func testSynchronizerStateChanged2Synced() throws { let mocked: [TransactionStateMockHelper] = [ - TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(amount: 1), status: .paid(success: false), uuid: "aa11"), - TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(amount: 2), uuid: "bb22"), - TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(amount: 3), status: .paid(success: true), uuid: "cc33"), - TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(amount: 4), uuid: "dd44"), - TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(amount: 5), uuid: "ee55"), + TransactionStateMockHelper(date: 1651039202, amount: Zatoshi(1), status: .paid(success: false), uuid: "aa11"), + TransactionStateMockHelper(date: 1651039101, amount: Zatoshi(2), uuid: "bb22"), + TransactionStateMockHelper(date: 1651039000, amount: Zatoshi(3), status: .paid(success: true), uuid: "cc33"), + TransactionStateMockHelper(date: 1651039505, amount: Zatoshi(4), uuid: "dd44"), + TransactionStateMockHelper(date: 1651039404, amount: Zatoshi(5), uuid: "ee55"), TransactionStateMockHelper( date: 1651039606, - amount: Zatoshi(amount: 6), + amount: Zatoshi(6), status: .paid(success: false), uuid: "ff66" ), - TransactionStateMockHelper(date: 1651039303, amount: Zatoshi(amount: 7), uuid: "gg77"), - TransactionStateMockHelper(date: 1651039707, amount: Zatoshi(amount: 8), status: .paid(success: true), uuid: "hh88"), - TransactionStateMockHelper(date: 1651039808, amount: Zatoshi(amount: 9), uuid: "ii99") + TransactionStateMockHelper(date: 1651039303, amount: Zatoshi(7), uuid: "gg77"), + TransactionStateMockHelper(date: 1651039707, amount: Zatoshi(8), status: .paid(success: true), uuid: "hh88"), + TransactionStateMockHelper(date: 1651039808, amount: Zatoshi(9), uuid: "ii99") ] let walletEvents: [WalletEvent] = mocked.map { let transaction = TransactionState.placeholder( amount: $0.amount, - fee: Zatoshi(amount: 10), + fee: Zatoshi(10), shielded: $0.shielded, status: $0.amount.amount > 5 ? .pending : $0.status, timestamp: $0.date,