- TCATextField migrated to ReducerProtocol - unit tests fixed
This commit is contained in:
parent
df61f72459
commit
13061e7a1a
|
@ -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)
|
||||
|
|
|
@ -7,37 +7,25 @@
|
|||
|
||||
import ComposableArchitecture
|
||||
|
||||
typealias TCATextFieldReducer = Reducer<TCATextFieldState, TCATextFieldAction, TCATextFieldEnvironment>
|
||||
typealias TCATextFieldStore = Store<TCATextFieldState, TCATextFieldAction>
|
||||
typealias TCATextFieldViewStore = ViewStore<TCATextFieldState, TCATextFieldAction>
|
||||
typealias TCATextFieldStore = Store<TCATextFieldReducer.State, TCATextFieldReducer.Action>
|
||||
|
||||
// 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<Action> {
|
||||
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: ""
|
||||
)
|
||||
|
|
|
@ -16,14 +16,16 @@ typealias TransactionAddressTextFieldReducer = Reducer<
|
|||
|
||||
typealias TransactionAddressTextFieldStore = Store<TransactionAddressTextFieldState, TransactionAddressTextFieldAction>
|
||||
|
||||
typealias AnyTCATextFieldReducerAddress = AnyReducer<TCATextFieldReducer.State, TCATextFieldReducer.Action, TransactionAddressTextFieldEnvironment>
|
||||
|
||||
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 }
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -17,11 +17,13 @@ typealias TransactionAmountTextFieldReducer = Reducer<
|
|||
|
||||
typealias TransactionAmountTextFieldStore = Store<TransactionAmountTextFieldState, TransactionAmountTextFieldAction>
|
||||
|
||||
typealias AnyTCATextFieldReducerAmount = AnyReducer<TCATextFieldReducer.State, TCATextFieldReducer.Action, TransactionAmountTextFieldEnvironment>
|
||||
|
||||
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,
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -15,7 +15,7 @@ class TransactionAddressTextFieldTests: XCTestCase {
|
|||
initialState:
|
||||
TransactionAddressTextFieldState(
|
||||
textFieldState:
|
||||
TCATextFieldState(
|
||||
TCATextFieldReducer.State(
|
||||
validationType: nil,
|
||||
text: "t1gXqfSSQt6WfpwyuCU3Wi7sSVZ66DYQ3Po"
|
||||
)
|
||||
|
|
|
@ -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"
|
||||
),
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue