[#432] Navigation is broken for 2nd+ sending flow (#433)

- obsolete bindings removed
- clear send form when the transaction is finished
- fixed broken navigation
This commit is contained in:
Lukas Korba 2022-10-08 00:51:03 +02:00 committed by GitHub
parent e7f36bc0cf
commit b505abef48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 31 deletions

View File

@ -27,9 +27,7 @@ struct SandboxView: View {
SendFlowView(
store: .init(
initialState: .placeholder,
reducer: SendFlowReducer.default(
whenDone: { SandboxViewStore(store).send(.updateRoute(nil)) }
),
reducer: SendFlowReducer.default,
environment: SendFlowEnvironment(
derivationTool: .live(),
mnemonic: .live,

View File

@ -120,6 +120,14 @@ extension SendFlowReducer {
case .addMemo:
return .none
case .updateRoute(.done):
state.route = nil
state.memoState.text = ""
state.transactionAmountInputState.textFieldState.text = ""
state.transactionAmountInputState.amount = 0
state.transactionAddressInputState.textFieldState.text = ""
return .none
case .updateRoute(.failure):
state.route = .failure
state.isSendingTransaction = false
@ -160,7 +168,10 @@ extension SendFlowReducer {
.map(SendFlowAction.sendTransactionResult)
.eraseToEffect()
return .concatenate(Effect(value: .updateRoute(.inProgress)), sendTransActionEffect)
return .concatenate(
Effect(value: .updateRoute(.inProgress)),
sendTransActionEffect
)
} catch {
return Effect(value: .updateRoute(.failure))
}
@ -236,17 +247,6 @@ extension SendFlowReducer {
action: /SendFlowAction.memo,
environment: { _ in MultiLineTextFieldEnvironment() }
)
static func `default`(whenDone: @escaping () -> Void) -> SendFlowReducer {
SendFlowReducer { state, action, environment in
switch action {
case let .updateRoute(route) where route == .done:
return Effect.fireAndForget(whenDone)
default:
return Self.default.run(&state, action, environment)
}
}
}
}
// MARK: - Store
@ -281,9 +281,9 @@ extension SendFlowViewStore {
self.routeBinding.map(
extract: {
$0 == .confirmation ||
self.bindingForInProgress.wrappedValue ||
self.bindingForSuccess.wrappedValue ||
self.bindingForFailure.wrappedValue
$0 == .inProgress ||
$0 == .success ||
$0 == .failure
},
embed: { $0 ? SendFlowState.Route.confirmation : nil }
)
@ -293,8 +293,8 @@ extension SendFlowViewStore {
self.routeBinding.map(
extract: {
$0 == .inProgress ||
self.bindingForSuccess.wrappedValue ||
self.bindingForFailure.wrappedValue
$0 == .success ||
$0 == .failure
},
embed: { $0 ? SendFlowState.Route.inProgress : SendFlowState.Route.confirmation }
)
@ -302,22 +302,15 @@ extension SendFlowViewStore {
var bindingForSuccess: Binding<Bool> {
self.routeBinding.map(
extract: { $0 == .success || self.bindingForDone.wrappedValue },
embed: { $0 ? SendFlowState.Route.success : SendFlowState.Route.inProgress }
extract: { $0 == .success },
embed: { _ in SendFlowState.Route.success }
)
}
var bindingForFailure: Binding<Bool> {
self.routeBinding.map(
extract: { $0 == .failure || self.bindingForDone.wrappedValue },
embed: { $0 ? SendFlowState.Route.failure : SendFlowState.Route.inProgress }
)
}
var bindingForDone: Binding<Bool> {
self.routeBinding.map(
extract: { $0 == .done },
embed: { $0 ? SendFlowState.Route.done : SendFlowState.Route.confirmation }
extract: { $0 == .failure },
embed: { _ in SendFlowState.Route.failure }
)
}
}