diff --git a/secant/UI Components/TextFields/SingleLineTextField.swift b/secant/UI Components/TextFields/SingleLineTextField.swift index 6c3673bb..86eb9896 100644 --- a/secant/UI Components/TextFields/SingleLineTextField.swift +++ b/secant/UI Components/TextFields/SingleLineTextField.swift @@ -103,8 +103,7 @@ struct SingleLineTextField_Previews: PreviewProvider { validationType: .floatingPoint, text: "" ), - reducer: .default, - environment: .init() + reducer: TCATextFieldReducer() ) ) .preferredColorScheme(.dark) @@ -118,8 +117,7 @@ struct SingleLineTextField_Previews: PreviewProvider { validationType: .email, text: "" ), - reducer: .default, - environment: .init() + reducer: TCATextFieldReducer() ) ) .preferredColorScheme(.light) diff --git a/secant/UI Components/TextFields/TCATextField/TCATextFieldStore.swift b/secant/UI Components/TextFields/TCATextField/TCATextFieldStore.swift index 8513223d..10ee0297 100644 --- a/secant/UI Components/TextFields/TCATextField/TCATextFieldStore.swift +++ b/secant/UI Components/TextFields/TCATextField/TCATextFieldStore.swift @@ -7,37 +7,25 @@ import ComposableArchitecture -typealias TCATextFieldReducer = Reducer -typealias TCATextFieldStore = Store -typealias TCATextFieldViewStore = ViewStore +typealias TCATextFieldStore = Store -// MARK: - State +struct TCATextFieldReducer: ReducerProtocol { + struct State: Equatable { + var validationType: String.ValidationType? + var text: String + var valid = false -struct TCATextFieldState: Equatable { - var validationType: String.ValidationType? - var text: String - var valid = false - - init(validationType: String.ValidationType?, text: String) { - self.validationType = validationType - self.text = text + init(validationType: String.ValidationType?, text: String) { + self.validationType = validationType + self.text = text + } } -} -// MARK: - Action - -enum TCATextFieldAction: Equatable { - case set(String) -} - -// MARK: - Environment - -struct TCATextFieldEnvironment { } - -// MARK: - Reducer - -extension TCATextFieldReducer { - static let `default` = TCATextFieldReducer { state, action, _ in + enum Action: Equatable { + case set(String) + } + + func reduce(into state: inout State, action: Action) -> ComposableArchitecture.EffectTask { switch action { case .set(let text): state.text = text @@ -53,29 +41,27 @@ extension TCATextFieldStore { static var transaction: Self { .init( initialState: .init(validationType: .customFloatingPoint(.zcashNumberFormatter), text: ""), - reducer: .default, - environment: .init() + reducer: TCATextFieldReducer() ) } static var address: Self { .init( initialState: .init(validationType: .email, text: ""), - reducer: .default, - environment: .init() + reducer: TCATextFieldReducer() ) } } // MARK: - Placeholders -extension TCATextFieldState { - static let placeholder = TCATextFieldState( +extension TCATextFieldReducer.State { + static let placeholder = TCATextFieldReducer.State( validationType: nil, text: "" ) - static let amount = TCATextFieldState( + static let amount = TCATextFieldReducer.State( validationType: .floatingPoint, text: "" ) diff --git a/secant/UI Components/TextFields/TransactionAddress/TransactionAddressTextFieldStore.swift b/secant/UI Components/TextFields/TransactionAddress/TransactionAddressTextFieldStore.swift index ad9befe2..0f3b29cf 100644 --- a/secant/UI Components/TextFields/TransactionAddress/TransactionAddressTextFieldStore.swift +++ b/secant/UI Components/TextFields/TransactionAddress/TransactionAddressTextFieldStore.swift @@ -16,14 +16,16 @@ typealias TransactionAddressTextFieldReducer = Reducer< typealias TransactionAddressTextFieldStore = Store +typealias AnyTCATextFieldReducerAddress = AnyReducer + struct TransactionAddressTextFieldState: Equatable { var isValidAddress = false - var textFieldState: TCATextFieldState + var textFieldState: TCATextFieldReducer.State } enum TransactionAddressTextFieldAction: Equatable { case clearAddress - case textField(TCATextFieldAction) + case textField(TCATextFieldReducer.Action) } struct TransactionAddressTextFieldEnvironment { @@ -55,10 +57,13 @@ extension TransactionAddressTextFieldReducer { } } - private static let textFieldReducer: TransactionAddressTextFieldReducer = TCATextFieldReducer.default.pullback( + private static let textFieldReducer: TransactionAddressTextFieldReducer = AnyTCATextFieldReducerAddress { _ in + TCATextFieldReducer() + } + .pullback( state: \TransactionAddressTextFieldState.textFieldState, action: /TransactionAddressTextFieldAction.textField, - environment: { _ in return .init() } + environment: { $0 } ) } diff --git a/secant/UI Components/TextFields/TransactionAmount/TransactionAmountTextFieldStore.swift b/secant/UI Components/TextFields/TransactionAmount/TransactionAmountTextFieldStore.swift index a1ee143c..bcb8b969 100644 --- a/secant/UI Components/TextFields/TransactionAmount/TransactionAmountTextFieldStore.swift +++ b/secant/UI Components/TextFields/TransactionAmount/TransactionAmountTextFieldStore.swift @@ -17,11 +17,13 @@ typealias TransactionAmountTextFieldReducer = Reducer< typealias TransactionAmountTextFieldStore = Store +typealias AnyTCATextFieldReducerAmount = AnyReducer + struct TransactionAmountTextFieldState: Equatable { var amount: Int64 = 0 var currencySelectionState: CurrencySelectionState var maxValue: Int64 = 0 - var textFieldState: TCATextFieldState + var textFieldState: TCATextFieldReducer.State // TODO [#311]: - Get the ZEC price from the SDK, https://github.com/zcash/secant-ios-wallet/issues/311 var zecPrice = Decimal(140.0) @@ -34,7 +36,7 @@ enum TransactionAmountTextFieldAction: Equatable { case clearValue case currencySelection(CurrencySelectionAction) case setMax - case textField(TCATextFieldAction) + case textField(TCATextFieldReducer.Action) case updateAmount } @@ -104,12 +106,15 @@ extension TransactionAmountTextFieldReducer { } } - private static let textFieldReducer: TransactionAmountTextFieldReducer = TCATextFieldReducer.default.pullback( + private static let textFieldReducer: TransactionAmountTextFieldReducer = AnyTCATextFieldReducerAmount { _ in + TCATextFieldReducer() + } + .pullback( state: \TransactionAmountTextFieldState.textFieldState, action: /TransactionAmountTextFieldAction.textField, - environment: { _ in return .init() } + environment: { $0 } ) - + private static let currencySelectionReducer: TransactionAmountTextFieldReducer = CurrencySelectionReducer.default.pullback( state: \TransactionAmountTextFieldState.currencySelectionState, action: /TransactionAmountTextFieldAction.currencySelection, diff --git a/secantTests/SendTests/SendTests.swift b/secantTests/SendTests/SendTests.swift index 033db492..10df89f4 100644 --- a/secantTests/SendTests/SendTests.swift +++ b/secantTests/SendTests/SendTests.swift @@ -319,7 +319,7 @@ class SendTests: XCTestCase { currencySelectionState: CurrencySelectionState(), maxValue: 501_300, textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .customFloatingPoint(usNumberFormatter), text: "" ) @@ -398,7 +398,7 @@ class SendTests: XCTestCase { TransactionAmountTextFieldState( currencySelectionState: CurrencySelectionState(), textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .customFloatingPoint(usNumberFormatter), text: "" ) @@ -433,7 +433,7 @@ class SendTests: XCTestCase { currencySelectionState: CurrencySelectionState(), maxValue: 501_302, textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .customFloatingPoint(usNumberFormatter), text: "0.00501301" ) @@ -481,7 +481,7 @@ class SendTests: XCTestCase { currencySelectionState: CurrencySelectionState(), maxValue: 501_300, textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .floatingPoint, text: "0.00501301" ) @@ -529,7 +529,7 @@ class SendTests: XCTestCase { currencySelectionState: CurrencySelectionState(), maxValue: 501_302, textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .floatingPoint, text: "0.00501301" ) @@ -577,7 +577,7 @@ class SendTests: XCTestCase { currencySelectionState: CurrencySelectionState(), maxValue: 501_302, textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .floatingPoint, text: "0.0.0501301" ) @@ -624,7 +624,7 @@ class SendTests: XCTestCase { TransactionAddressTextFieldState( isValidAddress: true, textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .none, text: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po" ) @@ -635,7 +635,7 @@ class SendTests: XCTestCase { currencySelectionState: CurrencySelectionState(), maxValue: 501_302, textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .floatingPoint, text: "0.0.0501301" ) @@ -679,7 +679,7 @@ class SendTests: XCTestCase { currencySelectionState: CurrencySelectionState(), maxValue: 501_302, textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .floatingPoint, text: "0.0.0501301" ) diff --git a/secantTests/SendTests/TransactionAddressInputTests.swift b/secantTests/SendTests/TransactionAddressInputTests.swift index fc08aadd..66e966f1 100644 --- a/secantTests/SendTests/TransactionAddressInputTests.swift +++ b/secantTests/SendTests/TransactionAddressInputTests.swift @@ -15,7 +15,7 @@ class TransactionAddressTextFieldTests: XCTestCase { initialState: TransactionAddressTextFieldState( textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: nil, text: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po" ) diff --git a/secantTests/SendTests/TransactionAmountInputTests.swift b/secantTests/SendTests/TransactionAmountInputTests.swift index 314e716d..f2dd0008 100644 --- a/secantTests/SendTests/TransactionAmountInputTests.swift +++ b/secantTests/SendTests/TransactionAmountInputTests.swift @@ -28,7 +28,7 @@ class TransactionAmountTextFieldTests: XCTestCase { currencySelectionState: CurrencySelectionState(), maxValue: 501_301, textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .customFloatingPoint(usNumberFormatter), text: "0.002" ) @@ -56,7 +56,7 @@ class TransactionAmountTextFieldTests: XCTestCase { currencySelectionState: CurrencySelectionState(), maxValue: 501_301, textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .floatingPoint, text: "0.002" ) @@ -83,7 +83,7 @@ class TransactionAmountTextFieldTests: XCTestCase { currencyType: .zec ), textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .customFloatingPoint(usNumberFormatter), text: "1.0" ), @@ -115,7 +115,7 @@ class TransactionAmountTextFieldTests: XCTestCase { currencyType: .zec ), textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .customFloatingPoint(usNumberFormatter), text: "25000" ), @@ -147,7 +147,7 @@ class TransactionAmountTextFieldTests: XCTestCase { currencyType: .usd ), textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .customFloatingPoint(usNumberFormatter), text: "1 000" ), @@ -180,7 +180,7 @@ class TransactionAmountTextFieldTests: XCTestCase { ), maxValue: 100_000_000, textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .customFloatingPoint(usNumberFormatter), text: "5" ), @@ -222,7 +222,7 @@ class TransactionAmountTextFieldTests: XCTestCase { ), maxValue: 200_000_000, textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .customFloatingPoint(usNumberFormatter), text: "5" ), @@ -254,7 +254,7 @@ class TransactionAmountTextFieldTests: XCTestCase { ), maxValue: 200_000_000, textFieldState: - TCATextFieldState( + TCATextFieldReducer.State( validationType: .customFloatingPoint(usNumberFormatter), text: "5" ), diff --git a/secantTests/SnapshotTests/SendSnapshotTests/TransactionConfirmationSnapshotTests.swift b/secantTests/SnapshotTests/SendSnapshotTests/TransactionConfirmationSnapshotTests.swift index 275bf691..1dce3cd8 100644 --- a/secantTests/SnapshotTests/SendSnapshotTests/TransactionConfirmationSnapshotTests.swift +++ b/secantTests/SnapshotTests/SendSnapshotTests/TransactionConfirmationSnapshotTests.swift @@ -26,14 +26,14 @@ class TransactionConfirmationSnapshotTests: XCTestCase { var state = SendFlowState.placeholder state.addMemoState = true state.transactionAddressInputState = TransactionAddressTextFieldState( - textFieldState: TCATextFieldState( + textFieldState: TCATextFieldReducer.State( validationType: nil, text: "ztestmockeddestinationaddress" ) ) state.transactionAmountInputState = TransactionAmountTextFieldState( currencySelectionState: CurrencySelectionState(), - textFieldState: TCATextFieldState( + textFieldState: TCATextFieldReducer.State( validationType: nil, text: "2.91" ) @@ -63,14 +63,14 @@ class TransactionConfirmationSnapshotTests: XCTestCase { var state = SendFlowState.placeholder state.addMemoState = true state.transactionAddressInputState = TransactionAddressTextFieldState( - textFieldState: TCATextFieldState( + textFieldState: TCATextFieldReducer.State( validationType: nil, text: "ztestmockeddestinationaddress" ) ) state.transactionAmountInputState = TransactionAmountTextFieldState( currencySelectionState: CurrencySelectionState(), - textFieldState: TCATextFieldState( + textFieldState: TCATextFieldReducer.State( validationType: nil, text: "2.91" ) diff --git a/secantTests/SnapshotTests/SendSnapshotTests/TransactionSendingTests.swift b/secantTests/SnapshotTests/SendSnapshotTests/TransactionSendingTests.swift index 3d4328f2..5f70803f 100644 --- a/secantTests/SnapshotTests/SendSnapshotTests/TransactionSendingTests.swift +++ b/secantTests/SnapshotTests/SendSnapshotTests/TransactionSendingTests.swift @@ -26,14 +26,14 @@ class TransactionSendingTests: XCTestCase { var state = SendFlowState.placeholder state.addMemoState = true state.transactionAddressInputState = TransactionAddressTextFieldState( - textFieldState: TCATextFieldState( + textFieldState: TCATextFieldReducer.State( validationType: nil, text: "ztestmockeddestinationaddress" ) ) state.transactionAmountInputState = TransactionAmountTextFieldState( currencySelectionState: CurrencySelectionState(), - textFieldState: TCATextFieldState( + textFieldState: TCATextFieldReducer.State( validationType: nil, text: "2.91" )