-
Notifications
You must be signed in to change notification settings - Fork 9
/
ImportMnemonic.swift
733 lines (632 loc) · 22.1 KB
/
ImportMnemonic.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
import ComposableArchitecture
import Sargon
import SwiftUI
// MARK: - ImportMnemonic
public struct ImportMnemonic: Sendable, FeatureReducer {
public static let wordsPerRow = 3
public struct State: Sendable, Hashable {
public typealias Words = IdentifiedArrayOf<ImportMnemonicWord.State>
public var words: Words
public var idOfWordWithTextFieldFocus: ImportMnemonicWord.State.ID?
public var language: BIP39Language
public var wordCount: BIP39WordCount {
guard let wordCount = BIP39WordCount(wordCount: words.count) else {
assertionFailure("Should never happen")
return .twentyFour
}
return wordCount
}
public mutating func changeWordCount(to newWordCount: BIP39WordCount) {
let wordCount = words.count
let delta = Int(newWordCount.rawValue) - wordCount
if delta > 0 {
// is increasing word count
words.append(contentsOf: (wordCount ..< Int(newWordCount.rawValue)).map {
.init(
id: $0,
placeholder: ImportMnemonic.placeholder(
index: $0,
wordCount: newWordCount,
language: language
),
isReadonlyMode: mode.readonly != nil
)
})
} else if delta < 0 {
// is decreasing word count
words.removeLast(-delta)
}
}
public var bip39Passphrase: String = ""
public var mnemonic: Mnemonic? {
guard completedWords.count == words.count else {
return nil
}
return try? Mnemonic(
words: completedWords
)
}
public var completedWords: [BIP39Word] {
words.compactMap(\.completeWord)
}
public let isWordCountFixed: Bool
public var isAdvancedMode: Bool = false
public let header: Header?
public let warning: String?
public let warningOnContinue: OnContinueWarning?
public struct ReadonlyMode: Sendable, Hashable {
public enum Context: Sendable, Hashable {
case fromSettings
case fromBackupPrompt
}
public let context: Context
// FIXME: This aint pretty... but we are short on time, forgive me... we are putting WAY
// to much logic and responsibility into this reducer here... for when a mnemonic is displayed
// either from settings or from AccountDetails after user have pressed "Back up this mnemonic"
// prompt, we need to able to mark a mnemonic as "backed up by user", we do so by use of
// `FactorSourceIDFromHash` - which require a FactorSourceKind....
public let factorSourceID: FactorSourceIDFromHash
public init(context: Context, factorSourceID: FactorSourceIDFromHash) {
self.context = context
self.factorSourceID = factorSourceID
}
}
public struct WriteMode: Sendable, Hashable {
public var isProgressing: Bool
public let persistStrategy: PersistStrategy?
public let hideAdvancedMode: Bool
public let showCloseButton: Bool
}
public enum Mode: Sendable, Hashable {
case readonly(ReadonlyMode)
case write(WriteMode)
var readonly: ReadonlyMode? {
switch self {
case let .readonly(value): value
case .write: nil
}
}
var write: WriteMode? {
switch self {
case .readonly: nil
case let .write(value): value
}
}
mutating func update(isProgressing: Bool) {
guard var write = self.write else {
assertionFailure("Expected write mode")
return
}
write.isProgressing = isProgressing
self = .write(write)
}
}
public var mode: Mode
#if DEBUG
public var debugMnemonicPhraseSingleField = ""
#endif
@PresentationState
public var destination: Destination.State?
public struct PersistStrategy: Sendable, Hashable {
public enum Location: Sendable, Hashable {
case intoKeychainAndProfile
}
public enum OnMnemonicExistsStrategy: Sendable, Hashable {
case abort
case appendWithCryptoParamaters
}
public let onMnemonicExistsStrategy: OnMnemonicExistsStrategy
public let factorSourceKindOfMnemonic: OnDeviceMnemonicKind
public let location: Location
public init(
factorSourceKindOfMnemonic: OnDeviceMnemonicKind,
location: Location,
onMnemonicExistsStrategy: OnMnemonicExistsStrategy
) {
self.factorSourceKindOfMnemonic = factorSourceKindOfMnemonic
self.location = location
self.onMnemonicExistsStrategy = onMnemonicExistsStrategy
}
}
public struct OnContinueWarning: Sendable, Hashable {
let title: String
let text: String
let button: String
public init(title: String, text: String, button: String) {
self.title = title
self.text = text
self.button = button
}
}
public init(
header: Header? = nil,
warning: String? = nil,
hideAdvancedMode: Bool = false,
showCloseButton: Bool = false,
warningOnContinue: OnContinueWarning? = nil,
isWordCountFixed: Bool = false,
persistStrategy: PersistStrategy?,
language: BIP39Language = .english,
wordCount: BIP39WordCount = .twelve,
bip39Passphrase: String = ""
) {
precondition(wordCount.rawValue.isMultiple(of: UInt8(ImportMnemonic.wordsPerRow)))
self.mode = .write(
.init(
isProgressing: false,
persistStrategy: persistStrategy,
hideAdvancedMode: hideAdvancedMode,
showCloseButton: showCloseButton
)
)
self.language = language
self.bip39Passphrase = bip39Passphrase
self.isWordCountFixed = isWordCountFixed
self.words = []
self.header = header
self.warning = warning
self.warningOnContinue = warningOnContinue
changeWordCount(to: wordCount)
}
public init(
header: Header? = nil,
warning: String? = nil,
mnemonicWithPassphrase: MnemonicWithPassphrase,
readonlyMode: ReadonlyMode
) {
self.header = header
self.warning = warning
self.warningOnContinue = nil
let mnemonic = mnemonicWithPassphrase.mnemonic
self.language = mnemonic.language
self.mode = .readonly(readonlyMode)
self.isWordCountFixed = true
self.words = Self.words(from: mnemonic, isReadonlyMode: true)
self.bip39Passphrase = mnemonicWithPassphrase.passphrase
}
public static func words(
from mnemonic: Mnemonic,
isReadonlyMode: Bool
) -> Words {
.init(
uniqueElements: mnemonic.words
.enumerated()
.map {
ImportMnemonicWord.State(
id: $0.offset,
value: .complete(
text: $0.element.word,
word: $0.element,
completion: .auto(match: .exact)
),
placeholder: ImportMnemonic.placeholder(
index: $0.offset,
wordCount: mnemonic.wordCount,
language: mnemonic.language
),
isReadonlyMode: isReadonlyMode
)
}
)
}
public struct Header: Sendable, Hashable {
public let title: String
public let subtitle: String?
public init(title: String, subtitle: String? = nil) {
self.title = title
self.subtitle = subtitle
}
}
}
public enum ViewAction: Sendable, Equatable {
case appeared
case toggleModeButtonTapped
case passphraseChanged(String)
case changedWordCountTo(BIP39WordCount)
case doneViewing
case closeButtonTapped
case backButtonTapped
case continueButtonTapped(Mnemonic)
#if DEBUG
case debugCopyMnemonic
case debugMnemonicChanged(String, continue: Bool = false)
case debugUseBabylonTestingMnemonicWithActiveAccounts(continue: Bool)
case debugUseOlympiaTestingMnemonicWithActiveAccounts(continue: Bool)
case debugUseTestingMnemonicZooVote(continue: Bool)
case debugPasteMnemonic
#endif
}
public enum InternalAction: Sendable, Equatable {
public struct IntermediaryResult: Sendable, Equatable {
public let factorSource: FactorSource
public let savedIntoProfile: Bool
}
case focusNext(ImportMnemonicWord.State.ID)
case saveFactorSourceResult(
TaskResult<IntermediaryResult>
)
}
public enum ChildAction: Sendable, Equatable {
case word(id: ImportMnemonicWord.State.ID, child: ImportMnemonicWord.Action)
}
public enum DelegateAction: Sendable, Equatable {
case persistedNewFactorSourceInProfile(FactorSource)
case persistedMnemonicInKeychainOnly(FactorSource)
case notPersisted(MnemonicWithPassphrase)
case doneViewing(idOfBackedUpFactorSource: FactorSourceIdFromHash?) // `nil` means it was already marked as backed up
}
public struct Destination: DestinationReducer {
@CasePathable
public enum State: Sendable, Hashable {
case backupConfirmation(AlertState<Action.BackupConfirmation>)
case onContinueWarning(AlertState<Action.OnContinueWarning>)
case verifyMnemonic(VerifyMnemonic.State)
}
@CasePathable
public enum Action: Sendable, Equatable {
case backupConfirmation(BackupConfirmation)
case onContinueWarning(OnContinueWarning)
case verifyMnemonic(VerifyMnemonic.Action)
public enum BackupConfirmation: Sendable, Hashable {
case userHasBackedUp
case userHasNotBackedUp
}
public enum OnContinueWarning: Sendable, Hashable {
case buttonTapped
}
}
public var body: some Reducer<State, Action> {
Scope(state: \.verifyMnemonic, action: \.verifyMnemonic) {
VerifyMnemonic()
}
}
}
@Dependency(\.dismiss) var dismiss
@Dependency(\.errorQueue) var errorQueue
@Dependency(\.mnemonicClient) var mnemonicClient
@Dependency(\.continuousClock) var clock
@Dependency(\.factorSourcesClient) var factorSourcesClient
@Dependency(\.userDefaults) var userDefaults
@Dependency(\.overlayWindowClient) var overlayWindowClient
#if DEBUG
@Dependency(\.pasteboardClient) var pasteboardClient
#endif
public init() {}
public var body: some ReducerOf<Self> {
Reduce(core)
.forEach(\.words, action: /Action.child .. ChildAction.word) {
ImportMnemonicWord()
}
.ifLet(destinationPath, action: /Action.destination) {
Destination()
}
}
private let destinationPath: WritableKeyPath<State, PresentationState<Destination.State>> = \.$destination
public func reduce(into state: inout State, childAction: ChildAction) -> Effect<Action> {
switch childAction {
case let .word(id, child: .delegate(.lookupWord(input))):
let lookUpResult = lookup(input: input, state)
return updateWord(id: id, input: input, &state, lookupResult: lookUpResult)
case let .word(id, child: .delegate(.lostFocus(displayText))):
let lookupResult = lookup(input: displayText, state)
switch lookupResult {
case let .known(.ambigous(candidates, input)):
if let exactMatch = candidates.first(where: { $0.word == input.rawValue }) {
state.words[id: id]?.value = .complete(
text: displayText,
word: exactMatch,
completion: ImportMnemonicWord.State.WordValue.Completion.auto(
match: .exact
)
)
} else {
state.words[id: id]?.value = .incomplete(
text: displayText,
hasFailedValidation: true
)
}
return .none
case .unknown(.notInList):
state.words[id: id]?.value = .incomplete(
text: displayText,
hasFailedValidation: true
)
return .none
case let .known(.unambiguous(word, match, input)):
return completeWith(word: word, completion: .auto(match: match), id: id, input: input.rawValue, &state)
case .unknown(.tooShort):
return .none
}
case let .word(id, child: .delegate(.userSelectedCandidate(candidate, input))):
return completeWith(
word: candidate,
completion: .user,
id: id,
input: input,
&state
)
default:
return .none
}
}
public func reduce(into state: inout State, viewAction: ViewAction) -> Effect<Action> {
switch viewAction {
case .appeared:
return focusNext(&state)
case let .passphraseChanged(passphrase):
state.bip39Passphrase = passphrase
return .none
case .toggleModeButtonTapped:
state.isAdvancedMode.toggle()
return .none
case let .changedWordCountTo(newWordCount):
state.changeWordCount(to: newWordCount)
return .none
case let .continueButtonTapped(mnemonic):
if let warningOnContinue = state.warningOnContinue {
state.destination = .onContinueWarning(warningOnContinue)
return .none
}
return continueWithMnemonic(mnemonic: mnemonic, in: &state)
case .doneViewing:
assert(state.mode.readonly != nil)
return markAsBackedUpIfNeeded(&state)
case .backButtonTapped:
assert(state.mode.readonly?.context == .fromSettings)
return markAsBackedUpIfNeeded(&state)
case .closeButtonTapped:
if state.mode.readonly?.context == .fromBackupPrompt {
return markAsBackedUpIfNeeded(&state)
} else if state.mode.write?.showCloseButton == true {
return .run { _ in await dismiss() }
} else {
assertionFailure("Invalid mode: No close button should be visible")
return .none
}
#if DEBUG
case .debugCopyMnemonic:
if let mnemonic = state.mnemonic?.phrase {
pasteboardClient.copyString(mnemonic)
}
return .none
case let .debugMnemonicChanged(mnemonic, continueAutomatically):
state.debugMnemonicPhraseSingleField = mnemonic
if let mnemonic = try? Mnemonic(phrase: mnemonic, language: state.language) {
state.words = State.words(from: mnemonic, isReadonlyMode: state.mode.readonly != nil)
if continueAutomatically {
state.mode.update(isProgressing: true)
return .send(.view(.continueButtonTapped(mnemonic)))
}
}
return .none
case .debugPasteMnemonic:
let toPaste = pasteboardClient.getString() ?? ""
return .send(.view(.debugMnemonicChanged(toPaste)))
case let .debugUseOlympiaTestingMnemonicWithActiveAccounts(continueAutomatically):
return .send(.view(.debugMnemonicChanged("section canoe half crystal crew balcony duty scout half robot avocado gas all effort piece", continue: continueAutomatically)))
case let .debugUseBabylonTestingMnemonicWithActiveAccounts(continueAutomatically):
return .send(.view(.debugMnemonicChanged("wine over village stage barrel strategy cushion decline echo fiber salad carry empower fun awful cereal galaxy laundry practice appear bean flat mansion license", continue: continueAutomatically)))
case let .debugUseTestingMnemonicZooVote(continueAutomatically):
return .send(.view(.debugMnemonicChanged(Mnemonic.sample24ZooVote.phrase, continue: continueAutomatically)))
#endif
}
}
private func continueWithMnemonic(mnemonic: Mnemonic, in state: inout State) -> Effect<Action> {
guard let write = state.mode.write else {
preconditionFailure("expected write mode")
}
state.mode.update(isProgressing: true)
let mnemonicWithPassphrase = MnemonicWithPassphrase(
mnemonic: mnemonic,
passphrase: state.bip39Passphrase
)
guard let persistStrategy = write.persistStrategy else {
state.mode.update(isProgressing: false)
return .send(.delegate(.notPersisted(mnemonicWithPassphrase)))
}
switch persistStrategy.location {
case .intoKeychainAndProfile:
return .run { send in
await send(.internal(.saveFactorSourceResult(
TaskResult {
let saveIntoProfile = true
let factorSource = try await factorSourcesClient.addOnDeviceFactorSource(
onDeviceMnemonicKind: persistStrategy.factorSourceKindOfMnemonic,
mnemonicWithPassphrase: mnemonicWithPassphrase,
onMnemonicExistsStrategy: persistStrategy.onMnemonicExistsStrategy,
saveIntoProfile: saveIntoProfile
)
return .init(factorSource: factorSource.asGeneral, savedIntoProfile: saveIntoProfile)
}
)))
}
}
}
private func markAsBackedUpIfNeeded(_ state: inout State) -> Effect<Action> {
guard let factorSourceID = state.mode.readonly?.factorSourceID else {
return .none
}
let listOfBackedUpMnemonics = userDefaults.getFactorSourceIDOfBackedUpMnemonics()
if listOfBackedUpMnemonics.contains(factorSourceID) {
return .send(.delegate(.doneViewing(idOfBackedUpFactorSource: nil))) // user has already marked this mnemonic as "backed up"
} else {
state.destination = .askUserIfSheHasBackedUpMnemonic()
return .none
}
}
public func reduce(into state: inout State, internalAction: InternalAction) -> Effect<Action> {
switch internalAction {
case let .focusNext(id):
state.idOfWordWithTextFieldFocus = id
state.words[id: id]?.focus()
return .none
case let .saveFactorSourceResult(.failure(error)):
state.mode.update(isProgressing: false)
errorQueue.schedule(error)
loggerGlobal.error("Failed to save mnemonic in profile, error: \(error)")
return .none
case let .saveFactorSourceResult(.success(saved)):
state.mode.update(isProgressing: false)
overlayWindowClient.scheduleHUD(.seedPhraseImported)
let factorSource = saved.factorSource
if saved.savedIntoProfile {
return .send(.delegate(.persistedNewFactorSourceInProfile(factorSource)))
} else {
return .send(.delegate(.persistedMnemonicInKeychainOnly(factorSource)))
}
}
}
public func reduce(into state: inout State, presentedAction: Destination.Action) -> Effect<Action> {
switch presentedAction {
case .backupConfirmation(.userHasBackedUp):
guard let mnemonic = state.mnemonic else {
return .none
}
state.destination = .verifyMnemonic(.init(mnemonic: mnemonic))
return .none
case .backupConfirmation(.userHasNotBackedUp):
loggerGlobal.notice("User have not backed up")
return .send(.delegate(.doneViewing(idOfBackedUpFactorSource: nil)))
case .onContinueWarning(.buttonTapped):
guard let mnemonic = state.mnemonic else {
loggerGlobal.error("Can't read mnemonic")
struct FailedToReadMnemonic: Error {}
errorQueue.schedule(FailedToReadMnemonic())
return .none
}
return continueWithMnemonic(mnemonic: mnemonic, in: &state)
case .verifyMnemonic(.delegate(.mnemonicVerified)):
guard let factorSourceID = state.mode.readonly?.factorSourceID else {
return .none
}
return .run { send in
try userDefaults.addFactorSourceIDOfBackedUpMnemonic(factorSourceID)
await send(.delegate(.doneViewing(idOfBackedUpFactorSource: factorSourceID)))
} catch: { error, _ in
loggerGlobal.error("Failed to save mnemonic as backed up")
errorQueue.schedule(error)
}
default:
return .none
}
}
}
extension ImportMnemonic {
private func lookup(input: String, _ state: State) -> BIP39LookupResult {
mnemonicClient.lookup(.init(
language: state.language,
input: input,
minLenghForCandidatesLookup: 2
))
}
private func completeWith(
word: BIP39Word,
completion: ImportMnemonicWord.State.WordValue.Completion,
id: ImportMnemonicWord.State.ID,
input: String,
_ state: inout State
) -> Effect<Action> {
state.words[id: id]?.value = .complete(text: input, word: word, completion: completion)
return focusNext(&state)
}
private func updateWord(
id: ImportMnemonicWord.State.ID,
input: String,
_ state: inout State,
lookupResult: BIP39LookupResult
) -> Effect<Action> {
// FIXME: - 1.5.4 hot fix
/// Words strip is broken in latest iOS versions, so we don't count on users selecting the word
/// dissambiguate between them. Rather the Wallet will validate the word eagerly if it is a valid one.
/// Behaviour:
/// - User enters the first two characters, having the word `en` - the word is incomplete.
/// - User enters another character, having the word`end` - the word is valid.
/// - User enters additional character, having the word `endl` - the word is incomplete.
/// - User enters additional characters, having the word `endless` - the word is considered valid.
/// - User removes some characters, having the word `endle` - the word is incomplete.
/// - User removes more characters, having the word `end` - the word is valid.
/// - User removes another character, having the word `en` - the word is incomplete.
switch lookupResult {
case let .known(.ambigous(candidates, nonEmptyInput)):
guard let userInput = candidates.first(where: { $0.word == nonEmptyInput.rawValue }) else {
state.words[id: id]?.value = .incomplete(text: input, hasFailedValidation: false)
return .none
}
return completeWith(word: userInput, completion: .user, id: id, input: input, &state)
case let .known(.unambiguous(word, _, _)):
guard word.word == input else {
state.words[id: id]?.value = .incomplete(text: input, hasFailedValidation: false)
return .none
}
return completeWith(word: word, completion: .user, id: id, input: input, &state)
case .unknown(.notInList):
state.words[id: id]?.value = .incomplete(text: input, hasFailedValidation: true)
return .none
case .unknown(.tooShort):
state.words[id: id]?.value = .incomplete(text: input, hasFailedValidation: false)
return .none
}
}
private func focusNext(_ state: inout State) -> Effect<Action> {
if let current = state.idOfWordWithTextFieldFocus {
state.words[id: current]?.resignFocus()
}
guard let nextID = state.words.first(where: { !$0.isComplete })?.id else {
return .none
}
return .run { send in
try? await clock.sleep(for: .milliseconds(75))
await send(.internal(.focusNext(nextID)))
}
}
}
extension ImportMnemonic {
static func placeholder(
index: Int,
wordCount: BIP39WordCount,
language: BIP39Language
) -> String {
precondition(index <= 23, "Invalid BIP39 word index, got index: \(index), exected less than 24.")
let word: BIP39Word = {
let wordList = language.wordlist() // BIP39.wordList(for: language)
switch language {
case .english:
let bip39Alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", /* X is missing */ "y", "z"]
return wordList
// we use `last` simply because we did not like the words "abandon baby"
// which we get by using `first`, too sad a combination.
.last(
where: { $0.word.hasPrefix(bip39Alphabet[index]) }
)!
default:
let scale = UInt16(89) // 2048 / 23
let indexScaled = U11(inner: scale * UInt16(index))
return wordList.first(where: { $0.index == indexScaled })!
}
}()
return word.word
}
}
extension ImportMnemonic.Destination.State {
fileprivate static func askUserIfSheHasBackedUpMnemonic() -> Self {
.backupConfirmation(.init(
title: { TextState(L10n.ImportMnemonic.BackedUpAlert.title) },
actions: {
ButtonState(action: .userHasBackedUp, label: { TextState(L10n.ImportMnemonic.BackedUpAlert.confirmAction) })
ButtonState(action: .userHasNotBackedUp, label: { TextState(L10n.ImportMnemonic.BackedUpAlert.noAction) })
},
message: { TextState(L10n.ImportMnemonic.BackedUpAlert.message) }
))
}
fileprivate static func onContinueWarning(
_ warning: ImportMnemonic.State.OnContinueWarning
) -> Self {
.onContinueWarning(.init(
title: { TextState(warning.title) },
actions: {
ButtonState(action: .buttonTapped, label: { TextState(warning.button) })
},
message: { TextState(warning.text) }
))
}
}