secant-ios-wallet/secant/Features/BackupFlow/RecoveryPhraseDisplayStore....

159 lines
4.6 KiB
Swift
Raw Permalink Normal View History

//
// RecoveryPhraseDisplayStore.swift
// secant-testnet
//
// Created by Francisco Gindre on 10/26/21.
//
import Foundation
import ComposableArchitecture
import UIKit
enum RecoveryPhraseError: Error {
/// This error is thrown then the Recovery Phrase can't be generated
case unableToGeneratePhrase
}
struct FeedbackGenerator {
let generateFeedback: () -> Void
}
extension FeedbackGenerator {
static let haptic = FeedbackGenerator(
generateFeedback: { UINotificationFeedbackGenerator().notificationOccurred(.error) }
)
static let silent = FeedbackGenerator(
generateFeedback: { }
)
}
struct Pasteboard {
let setString: (String) -> Void
let getString: () -> String?
}
extension Pasteboard {
private struct TestPasteboard {
static var general = TestPasteboard()
var string: String?
}
static let live = Pasteboard(
setString: { UIPasteboard.general.string = $0 },
getString: { UIPasteboard.general.string }
)
static let test = Pasteboard(
setString: { TestPasteboard.general.string = $0 },
getString: { TestPasteboard.general.string }
)
}
struct BackupPhraseEnvironment {
let mainQueue: AnySchedulerOf<DispatchQueue>
let newPhrase: () -> Effect<RecoveryPhrase, RecoveryPhraseError>
let pasteboard: Pasteboard
let feedbackGenerator: FeedbackGenerator
}
extension BackupPhraseEnvironment {
private struct DemoPasteboard {
static var general = Self()
var string: String?
}
static let demo = Self(
mainQueue: DispatchQueue.main.eraseToAnyScheduler(),
Issue #44: Recovery Phrase Validation flow + tests Rename struct to RecoveryPhraseValidationState. Add docs WordGrid + tests Make Word Groups Droppable and Blue word chips draggable cleanup Rename Stores and adopt aliases and default pattern for reducers Fix drop not working FIX: apply background to header. Spacing Fix compilation errors. Add validation demo to AppView Fix: the empty chips are rendered once, because they are not uniquely identifiable Add the Validation screen to the App Home make mutating functions static fix project warnings Fix Tests Fixed .complete test refactoring the Enum. first step Move given() to RecoveryPhraseValidationState and fix tests Add canary test for computed property of State Move RecoveryPhraseValidationStep to a nested type of RecoveryPhraseValidationState rename RecoveryPhraseValidationState.RecoveryPhraseValidationStep to RecoveryPhraseValidationState.Step Move static functions from RecoveryPhraseValidationStep to RecoveryPhraseValidationState Move creational factory methods together to the same extension Remove unused functions remove associated values from Step enum Fix: Avoid Drop being disable between chips 0.0.1-10 add navigation bar to phrase validation demo Reduce spacing between groups. Code cleanup Remove RecoveryPhraseValidationStep.swift Move remaining code to proper places PR Fixes. Move .initial factory method to test target. Rename given() to apply(chip:group:) and make it a member function Cleanup. Remove .validate, .invalid and .valid states. Figure word chips out of the state. Fix randomIndices() Tie view's title to state Connect Header to State BlueChip is now ColoredChip. Success Screen fix project Connect Success Screen to successful validation Add Red color to backgrounds Validation Failed Screen Connect SuccessValidation Screen to home hide back button on Success view Connect Phrase Display to validation 0.0.1-11 Fix word grid background colors View Modifier to add scrollview when the content is being scaled up by DynamicType Adjust UI spacing and padding to designs Add Placeholder states for SwiftUI Previews Flatten EnumeratedChip Hierarchy Flatten EnumeratedChip view hierarchy Fix: LazyVGrid can't take GeometryReader on its items' bodies Fix: Colored Chip does not adjust Fix: Vertical separation between wordgroups is too tall. Fix: Accesibility fixes for Validation Failed screen Rename ValidationFailedView Accessibility Pass on Validation success screen FIX: Colored chips too big when scaled up Fix: ValidationFailedScreen does not scroll well when scaled up Fix Empty chip shadow color for dark color scheme Fix: chip grid background does not bleed out to bottom of the screen build 12 Fix: pre success/failure screen step shrinks the screen because word grid is missing Resolved PR comments Fixes to resolve PR conversations Fixes to resolve PR conversations Fix PhraseChip preview Make ScrollableWhenScaledUp modifier fileprivate Remove comments and clean up code Fix Swiftlint issues Renamed RecoveryPhraseStepFulfillment to ValidationWord Rename pickWordsFromMissingIndices PR fixes PR suggestions PR suggestions Move words(fromMissingIndices:size) to RecoveryPhrase Make ScrollableWhenScaled struct fileprivate PR Suggestions Part two PR Suggestion changes remove unused PR suggestions suggested rename PR suggestions remove apply(chip:into) move that to Reducer Formatting changes more formatting changes Fix: iPhone 13 Pro Max displays 4 columns instead of three Fix: Recovery Phrase puzzle shows incorrect number of columns and margin alignment on bigger devices Add test to catch state not changing as intended Phrase validation reducer refactor + tests make step computed property a bool make isComplete a single line PR Suggestions Rename ValidationSuccededView.swift Fix Bug: valid phrase should contemplate that the phrase is complete first PR Suggestion refactor and add Unit Tests for resultingPhrase, isComplete, isValid
2021-12-13 12:50:04 -08:00
newPhrase: { Effect(value: .init(words: RecoveryPhrase.placeholder.words)) },
pasteboard: .test,
feedbackGenerator: .silent
)
static let live = Self(
mainQueue: DispatchQueue.main.eraseToAnyScheduler(),
Issue #44: Recovery Phrase Validation flow + tests Rename struct to RecoveryPhraseValidationState. Add docs WordGrid + tests Make Word Groups Droppable and Blue word chips draggable cleanup Rename Stores and adopt aliases and default pattern for reducers Fix drop not working FIX: apply background to header. Spacing Fix compilation errors. Add validation demo to AppView Fix: the empty chips are rendered once, because they are not uniquely identifiable Add the Validation screen to the App Home make mutating functions static fix project warnings Fix Tests Fixed .complete test refactoring the Enum. first step Move given() to RecoveryPhraseValidationState and fix tests Add canary test for computed property of State Move RecoveryPhraseValidationStep to a nested type of RecoveryPhraseValidationState rename RecoveryPhraseValidationState.RecoveryPhraseValidationStep to RecoveryPhraseValidationState.Step Move static functions from RecoveryPhraseValidationStep to RecoveryPhraseValidationState Move creational factory methods together to the same extension Remove unused functions remove associated values from Step enum Fix: Avoid Drop being disable between chips 0.0.1-10 add navigation bar to phrase validation demo Reduce spacing between groups. Code cleanup Remove RecoveryPhraseValidationStep.swift Move remaining code to proper places PR Fixes. Move .initial factory method to test target. Rename given() to apply(chip:group:) and make it a member function Cleanup. Remove .validate, .invalid and .valid states. Figure word chips out of the state. Fix randomIndices() Tie view's title to state Connect Header to State BlueChip is now ColoredChip. Success Screen fix project Connect Success Screen to successful validation Add Red color to backgrounds Validation Failed Screen Connect SuccessValidation Screen to home hide back button on Success view Connect Phrase Display to validation 0.0.1-11 Fix word grid background colors View Modifier to add scrollview when the content is being scaled up by DynamicType Adjust UI spacing and padding to designs Add Placeholder states for SwiftUI Previews Flatten EnumeratedChip Hierarchy Flatten EnumeratedChip view hierarchy Fix: LazyVGrid can't take GeometryReader on its items' bodies Fix: Colored Chip does not adjust Fix: Vertical separation between wordgroups is too tall. Fix: Accesibility fixes for Validation Failed screen Rename ValidationFailedView Accessibility Pass on Validation success screen FIX: Colored chips too big when scaled up Fix: ValidationFailedScreen does not scroll well when scaled up Fix Empty chip shadow color for dark color scheme Fix: chip grid background does not bleed out to bottom of the screen build 12 Fix: pre success/failure screen step shrinks the screen because word grid is missing Resolved PR comments Fixes to resolve PR conversations Fixes to resolve PR conversations Fix PhraseChip preview Make ScrollableWhenScaledUp modifier fileprivate Remove comments and clean up code Fix Swiftlint issues Renamed RecoveryPhraseStepFulfillment to ValidationWord Rename pickWordsFromMissingIndices PR fixes PR suggestions PR suggestions Move words(fromMissingIndices:size) to RecoveryPhrase Make ScrollableWhenScaled struct fileprivate PR Suggestions Part two PR Suggestion changes remove unused PR suggestions suggested rename PR suggestions remove apply(chip:into) move that to Reducer Formatting changes more formatting changes Fix: iPhone 13 Pro Max displays 4 columns instead of three Fix: Recovery Phrase puzzle shows incorrect number of columns and margin alignment on bigger devices Add test to catch state not changing as intended Phrase validation reducer refactor + tests make step computed property a bool make isComplete a single line PR Suggestions Rename ValidationSuccededView.swift Fix Bug: valid phrase should contemplate that the phrase is complete first PR Suggestion refactor and add Unit Tests for resultingPhrase, isComplete, isValid
2021-12-13 12:50:04 -08:00
newPhrase: { Effect(value: .init(words: RecoveryPhrase.placeholder.words)) },
pasteboard: .live,
feedbackGenerator: .haptic
)
}
typealias RecoveryPhraseDisplayStore = Store<RecoveryPhraseDisplayState, RecoveryPhraseDisplayAction>
struct RecoveryPhrase: Equatable {
Issue #44: Recovery Phrase Validation flow + tests Rename struct to RecoveryPhraseValidationState. Add docs WordGrid + tests Make Word Groups Droppable and Blue word chips draggable cleanup Rename Stores and adopt aliases and default pattern for reducers Fix drop not working FIX: apply background to header. Spacing Fix compilation errors. Add validation demo to AppView Fix: the empty chips are rendered once, because they are not uniquely identifiable Add the Validation screen to the App Home make mutating functions static fix project warnings Fix Tests Fixed .complete test refactoring the Enum. first step Move given() to RecoveryPhraseValidationState and fix tests Add canary test for computed property of State Move RecoveryPhraseValidationStep to a nested type of RecoveryPhraseValidationState rename RecoveryPhraseValidationState.RecoveryPhraseValidationStep to RecoveryPhraseValidationState.Step Move static functions from RecoveryPhraseValidationStep to RecoveryPhraseValidationState Move creational factory methods together to the same extension Remove unused functions remove associated values from Step enum Fix: Avoid Drop being disable between chips 0.0.1-10 add navigation bar to phrase validation demo Reduce spacing between groups. Code cleanup Remove RecoveryPhraseValidationStep.swift Move remaining code to proper places PR Fixes. Move .initial factory method to test target. Rename given() to apply(chip:group:) and make it a member function Cleanup. Remove .validate, .invalid and .valid states. Figure word chips out of the state. Fix randomIndices() Tie view's title to state Connect Header to State BlueChip is now ColoredChip. Success Screen fix project Connect Success Screen to successful validation Add Red color to backgrounds Validation Failed Screen Connect SuccessValidation Screen to home hide back button on Success view Connect Phrase Display to validation 0.0.1-11 Fix word grid background colors View Modifier to add scrollview when the content is being scaled up by DynamicType Adjust UI spacing and padding to designs Add Placeholder states for SwiftUI Previews Flatten EnumeratedChip Hierarchy Flatten EnumeratedChip view hierarchy Fix: LazyVGrid can't take GeometryReader on its items' bodies Fix: Colored Chip does not adjust Fix: Vertical separation between wordgroups is too tall. Fix: Accesibility fixes for Validation Failed screen Rename ValidationFailedView Accessibility Pass on Validation success screen FIX: Colored chips too big when scaled up Fix: ValidationFailedScreen does not scroll well when scaled up Fix Empty chip shadow color for dark color scheme Fix: chip grid background does not bleed out to bottom of the screen build 12 Fix: pre success/failure screen step shrinks the screen because word grid is missing Resolved PR comments Fixes to resolve PR conversations Fixes to resolve PR conversations Fix PhraseChip preview Make ScrollableWhenScaledUp modifier fileprivate Remove comments and clean up code Fix Swiftlint issues Renamed RecoveryPhraseStepFulfillment to ValidationWord Rename pickWordsFromMissingIndices PR fixes PR suggestions PR suggestions Move words(fromMissingIndices:size) to RecoveryPhrase Make ScrollableWhenScaled struct fileprivate PR Suggestions Part two PR Suggestion changes remove unused PR suggestions suggested rename PR suggestions remove apply(chip:into) move that to Reducer Formatting changes more formatting changes Fix: iPhone 13 Pro Max displays 4 columns instead of three Fix: Recovery Phrase puzzle shows incorrect number of columns and margin alignment on bigger devices Add test to catch state not changing as intended Phrase validation reducer refactor + tests make step computed property a bool make isComplete a single line PR Suggestions Rename ValidationSuccededView.swift Fix Bug: valid phrase should contemplate that the phrase is complete first PR Suggestion refactor and add Unit Tests for resultingPhrase, isComplete, isValid
2021-12-13 12:50:04 -08:00
struct Group: Hashable {
var startIndex: Int
var words: [String]
}
let words: [String]
Issue #44: Recovery Phrase Validation flow + tests Rename struct to RecoveryPhraseValidationState. Add docs WordGrid + tests Make Word Groups Droppable and Blue word chips draggable cleanup Rename Stores and adopt aliases and default pattern for reducers Fix drop not working FIX: apply background to header. Spacing Fix compilation errors. Add validation demo to AppView Fix: the empty chips are rendered once, because they are not uniquely identifiable Add the Validation screen to the App Home make mutating functions static fix project warnings Fix Tests Fixed .complete test refactoring the Enum. first step Move given() to RecoveryPhraseValidationState and fix tests Add canary test for computed property of State Move RecoveryPhraseValidationStep to a nested type of RecoveryPhraseValidationState rename RecoveryPhraseValidationState.RecoveryPhraseValidationStep to RecoveryPhraseValidationState.Step Move static functions from RecoveryPhraseValidationStep to RecoveryPhraseValidationState Move creational factory methods together to the same extension Remove unused functions remove associated values from Step enum Fix: Avoid Drop being disable between chips 0.0.1-10 add navigation bar to phrase validation demo Reduce spacing between groups. Code cleanup Remove RecoveryPhraseValidationStep.swift Move remaining code to proper places PR Fixes. Move .initial factory method to test target. Rename given() to apply(chip:group:) and make it a member function Cleanup. Remove .validate, .invalid and .valid states. Figure word chips out of the state. Fix randomIndices() Tie view's title to state Connect Header to State BlueChip is now ColoredChip. Success Screen fix project Connect Success Screen to successful validation Add Red color to backgrounds Validation Failed Screen Connect SuccessValidation Screen to home hide back button on Success view Connect Phrase Display to validation 0.0.1-11 Fix word grid background colors View Modifier to add scrollview when the content is being scaled up by DynamicType Adjust UI spacing and padding to designs Add Placeholder states for SwiftUI Previews Flatten EnumeratedChip Hierarchy Flatten EnumeratedChip view hierarchy Fix: LazyVGrid can't take GeometryReader on its items' bodies Fix: Colored Chip does not adjust Fix: Vertical separation between wordgroups is too tall. Fix: Accesibility fixes for Validation Failed screen Rename ValidationFailedView Accessibility Pass on Validation success screen FIX: Colored chips too big when scaled up Fix: ValidationFailedScreen does not scroll well when scaled up Fix Empty chip shadow color for dark color scheme Fix: chip grid background does not bleed out to bottom of the screen build 12 Fix: pre success/failure screen step shrinks the screen because word grid is missing Resolved PR comments Fixes to resolve PR conversations Fixes to resolve PR conversations Fix PhraseChip preview Make ScrollableWhenScaledUp modifier fileprivate Remove comments and clean up code Fix Swiftlint issues Renamed RecoveryPhraseStepFulfillment to ValidationWord Rename pickWordsFromMissingIndices PR fixes PR suggestions PR suggestions Move words(fromMissingIndices:size) to RecoveryPhrase Make ScrollableWhenScaled struct fileprivate PR Suggestions Part two PR Suggestion changes remove unused PR suggestions suggested rename PR suggestions remove apply(chip:into) move that to Reducer Formatting changes more formatting changes Fix: iPhone 13 Pro Max displays 4 columns instead of three Fix: Recovery Phrase puzzle shows incorrect number of columns and margin alignment on bigger devices Add test to catch state not changing as intended Phrase validation reducer refactor + tests make step computed property a bool make isComplete a single line PR Suggestions Rename ValidationSuccededView.swift Fix Bug: valid phrase should contemplate that the phrase is complete first PR Suggestion refactor and add Unit Tests for resultingPhrase, isComplete, isValid
2021-12-13 12:50:04 -08:00
private let groupSize = 6
Issue #44: Recovery Phrase Validation flow + tests Rename struct to RecoveryPhraseValidationState. Add docs WordGrid + tests Make Word Groups Droppable and Blue word chips draggable cleanup Rename Stores and adopt aliases and default pattern for reducers Fix drop not working FIX: apply background to header. Spacing Fix compilation errors. Add validation demo to AppView Fix: the empty chips are rendered once, because they are not uniquely identifiable Add the Validation screen to the App Home make mutating functions static fix project warnings Fix Tests Fixed .complete test refactoring the Enum. first step Move given() to RecoveryPhraseValidationState and fix tests Add canary test for computed property of State Move RecoveryPhraseValidationStep to a nested type of RecoveryPhraseValidationState rename RecoveryPhraseValidationState.RecoveryPhraseValidationStep to RecoveryPhraseValidationState.Step Move static functions from RecoveryPhraseValidationStep to RecoveryPhraseValidationState Move creational factory methods together to the same extension Remove unused functions remove associated values from Step enum Fix: Avoid Drop being disable between chips 0.0.1-10 add navigation bar to phrase validation demo Reduce spacing between groups. Code cleanup Remove RecoveryPhraseValidationStep.swift Move remaining code to proper places PR Fixes. Move .initial factory method to test target. Rename given() to apply(chip:group:) and make it a member function Cleanup. Remove .validate, .invalid and .valid states. Figure word chips out of the state. Fix randomIndices() Tie view's title to state Connect Header to State BlueChip is now ColoredChip. Success Screen fix project Connect Success Screen to successful validation Add Red color to backgrounds Validation Failed Screen Connect SuccessValidation Screen to home hide back button on Success view Connect Phrase Display to validation 0.0.1-11 Fix word grid background colors View Modifier to add scrollview when the content is being scaled up by DynamicType Adjust UI spacing and padding to designs Add Placeholder states for SwiftUI Previews Flatten EnumeratedChip Hierarchy Flatten EnumeratedChip view hierarchy Fix: LazyVGrid can't take GeometryReader on its items' bodies Fix: Colored Chip does not adjust Fix: Vertical separation between wordgroups is too tall. Fix: Accesibility fixes for Validation Failed screen Rename ValidationFailedView Accessibility Pass on Validation success screen FIX: Colored chips too big when scaled up Fix: ValidationFailedScreen does not scroll well when scaled up Fix Empty chip shadow color for dark color scheme Fix: chip grid background does not bleed out to bottom of the screen build 12 Fix: pre success/failure screen step shrinks the screen because word grid is missing Resolved PR comments Fixes to resolve PR conversations Fixes to resolve PR conversations Fix PhraseChip preview Make ScrollableWhenScaledUp modifier fileprivate Remove comments and clean up code Fix Swiftlint issues Renamed RecoveryPhraseStepFulfillment to ValidationWord Rename pickWordsFromMissingIndices PR fixes PR suggestions PR suggestions Move words(fromMissingIndices:size) to RecoveryPhrase Make ScrollableWhenScaled struct fileprivate PR Suggestions Part two PR Suggestion changes remove unused PR suggestions suggested rename PR suggestions remove apply(chip:into) move that to Reducer Formatting changes more formatting changes Fix: iPhone 13 Pro Max displays 4 columns instead of three Fix: Recovery Phrase puzzle shows incorrect number of columns and margin alignment on bigger devices Add test to catch state not changing as intended Phrase validation reducer refactor + tests make step computed property a bool make isComplete a single line PR Suggestions Rename ValidationSuccededView.swift Fix Bug: valid phrase should contemplate that the phrase is complete first PR Suggestion refactor and add Unit Tests for resultingPhrase, isComplete, isValid
2021-12-13 12:50:04 -08:00
func toGroups() -> [Group] {
let chunks = words.count / groupSize
return zip(0 ..< chunks, words.chunked(into: groupSize)).map {
Group(startIndex: $0 * groupSize + 1, words: $1)
}
}
func toString() -> String {
words.joined(separator: " ")
}
Issue #44: Recovery Phrase Validation flow + tests Rename struct to RecoveryPhraseValidationState. Add docs WordGrid + tests Make Word Groups Droppable and Blue word chips draggable cleanup Rename Stores and adopt aliases and default pattern for reducers Fix drop not working FIX: apply background to header. Spacing Fix compilation errors. Add validation demo to AppView Fix: the empty chips are rendered once, because they are not uniquely identifiable Add the Validation screen to the App Home make mutating functions static fix project warnings Fix Tests Fixed .complete test refactoring the Enum. first step Move given() to RecoveryPhraseValidationState and fix tests Add canary test for computed property of State Move RecoveryPhraseValidationStep to a nested type of RecoveryPhraseValidationState rename RecoveryPhraseValidationState.RecoveryPhraseValidationStep to RecoveryPhraseValidationState.Step Move static functions from RecoveryPhraseValidationStep to RecoveryPhraseValidationState Move creational factory methods together to the same extension Remove unused functions remove associated values from Step enum Fix: Avoid Drop being disable between chips 0.0.1-10 add navigation bar to phrase validation demo Reduce spacing between groups. Code cleanup Remove RecoveryPhraseValidationStep.swift Move remaining code to proper places PR Fixes. Move .initial factory method to test target. Rename given() to apply(chip:group:) and make it a member function Cleanup. Remove .validate, .invalid and .valid states. Figure word chips out of the state. Fix randomIndices() Tie view's title to state Connect Header to State BlueChip is now ColoredChip. Success Screen fix project Connect Success Screen to successful validation Add Red color to backgrounds Validation Failed Screen Connect SuccessValidation Screen to home hide back button on Success view Connect Phrase Display to validation 0.0.1-11 Fix word grid background colors View Modifier to add scrollview when the content is being scaled up by DynamicType Adjust UI spacing and padding to designs Add Placeholder states for SwiftUI Previews Flatten EnumeratedChip Hierarchy Flatten EnumeratedChip view hierarchy Fix: LazyVGrid can't take GeometryReader on its items' bodies Fix: Colored Chip does not adjust Fix: Vertical separation between wordgroups is too tall. Fix: Accesibility fixes for Validation Failed screen Rename ValidationFailedView Accessibility Pass on Validation success screen FIX: Colored chips too big when scaled up Fix: ValidationFailedScreen does not scroll well when scaled up Fix Empty chip shadow color for dark color scheme Fix: chip grid background does not bleed out to bottom of the screen build 12 Fix: pre success/failure screen step shrinks the screen because word grid is missing Resolved PR comments Fixes to resolve PR conversations Fixes to resolve PR conversations Fix PhraseChip preview Make ScrollableWhenScaledUp modifier fileprivate Remove comments and clean up code Fix Swiftlint issues Renamed RecoveryPhraseStepFulfillment to ValidationWord Rename pickWordsFromMissingIndices PR fixes PR suggestions PR suggestions Move words(fromMissingIndices:size) to RecoveryPhrase Make ScrollableWhenScaled struct fileprivate PR Suggestions Part two PR Suggestion changes remove unused PR suggestions suggested rename PR suggestions remove apply(chip:into) move that to Reducer Formatting changes more formatting changes Fix: iPhone 13 Pro Max displays 4 columns instead of three Fix: Recovery Phrase puzzle shows incorrect number of columns and margin alignment on bigger devices Add test to catch state not changing as intended Phrase validation reducer refactor + tests make step computed property a bool make isComplete a single line PR Suggestions Rename ValidationSuccededView.swift Fix Bug: valid phrase should contemplate that the phrase is complete first PR Suggestion refactor and add Unit Tests for resultingPhrase, isComplete, isValid
2021-12-13 12:50:04 -08:00
func words(fromMissingIndices indices: [Int]) -> [PhraseChip.Kind] {
assert((indices.count - 1) * groupSize <= self.words.count)
return indices.enumerated().map { index, position in
.unassigned(word: self.words[(index * groupSize) + position])
}
}
}
struct RecoveryPhraseDisplayState: Equatable {
var phrase: RecoveryPhrase?
var showCopyToBufferAlert = false
}
enum RecoveryPhraseDisplayAction: Equatable {
case createPhrase
case copyToBufferPressed
case finishedPressed
case phraseResponse(Result<RecoveryPhrase, RecoveryPhraseError>)
}
typealias RecoveryPhraseDisplayReducer = Reducer<RecoveryPhraseDisplayState, RecoveryPhraseDisplayAction, BackupPhraseEnvironment>
extension RecoveryPhraseDisplayReducer {
static let `default` = RecoveryPhraseDisplayReducer { state, action, environment in
switch action {
case .createPhrase:
return environment.newPhrase()
.receive(on: environment.mainQueue)
.catchToEffect(RecoveryPhraseDisplayAction.phraseResponse)
case .copyToBufferPressed:
guard let phrase = state.phrase?.toString() else { return .none }
environment.pasteboard.setString(phrase)
state.showCopyToBufferAlert = true
return .none
case .finishedPressed:
// TODO: remove this when feature is implemented in https://github.com/zcash/secant-ios-wallet/issues/47
return .none
case let .phraseResponse(.success(phrase)):
state.phrase = phrase
return .none
case .phraseResponse(.failure):
// TODO: remove this when feature is implemented in https://github.com/zcash/secant-ios-wallet/issues/129
return .none
}
}
}
extension Array {
func chunked(into size: Int) -> [[Element]] {
return stride(from: 0, to: count, by: size).map {
Array(self[$0 ..< Swift.min($0 + size, count)])
}
}
}