@objc ( LKSeedModal )
final class SeedModal : Modal {
private let mnemonic : String = {
let identityManager = OWSIdentityManager . shared ( )
let databaseConnection = identityManager . value ( forKey : " dbConnection " ) as ! YapDatabaseConnection
var hexEncodedSeed : String ! = databaseConnection . object ( forKey : " LKLokiSeed " , inCollection : OWSPrimaryStorageIdentityKeyStoreCollection ) as ! String ?
if hexEncodedSeed = = nil {
hexEncodedSeed = identityManager . identityKeyPair ( ) ! . hexEncodedPrivateKey // L e g a c y a c c o u n t
}
return Mnemonic . encode ( hexEncodedString : hexEncodedSeed )
} ( )
// MARK: L i f e c y c l e
override func populateContentView ( ) {
// S e t u p t i t l e l a b e l
let titleLabel = UILabel ( )
titleLabel . textColor = Colors . text
titleLabel . font = . boldSystemFont ( ofSize : Values . mediumFontSize )
titleLabel . text = NSLocalizedString ( " Your Recovery Phrase " , comment : " " )
titleLabel . numberOfLines = 0
titleLabel . lineBreakMode = . byWordWrapping
titleLabel . textAlignment = . center
// S e t u p m n e m o n i c l a b e l
let mnemonicLabel = UILabel ( )
mnemonicLabel . textColor = Colors . text
mnemonicLabel . font = . systemFont ( ofSize : Values . smallFontSize )
mnemonicLabel . text = mnemonic
mnemonicLabel . numberOfLines = 0
mnemonicLabel . lineBreakMode = . byWordWrapping
mnemonicLabel . textAlignment = . center
// S e t u p e x p l a n a t i o n l a b e l
let explanationLabel = UILabel ( )
explanationLabel . textColor = Colors . text . withAlphaComponent ( Values . unimportantElementOpacity )
explanationLabel . font = . systemFont ( ofSize : Values . smallFontSize )
explanationLabel . text = NSLocalizedString ( " This is your recovery phrase. With it, you can restore or migrate your Session ID to a new device. " , comment : " " )
explanationLabel . numberOfLines = 0
explanationLabel . lineBreakMode = . byWordWrapping
explanationLabel . textAlignment = . center
// S e t u p c o p y b u t t o n
let copyButton = UIButton ( )
copyButton . set ( . height , to : Values . mediumButtonHeight )
copyButton . layer . cornerRadius = Values . modalButtonCornerRadius
copyButton . backgroundColor = Colors . buttonBackground
copyButton . titleLabel ! . font = . systemFont ( ofSize : Values . smallFontSize )
copyButton . setTitleColor ( Colors . text , for : UIControl . State . normal )
copyButton . setTitle ( NSLocalizedString ( " Copy " , comment : " " ) , for : UIControl . State . normal )
copyButton . addTarget ( self , action : #selector ( copySeed ) , for : UIControl . Event . touchUpInside )
// S e t u p b u t t o n s t a c k v i e w
let buttonStackView = UIStackView ( arrangedSubviews : [ cancelButton , copyButton ] )
buttonStackView . axis = . horizontal
buttonStackView . spacing = Values . mediumSpacing
buttonStackView . distribution = . fillEqually
// S e t u p s t a c k v i e w
let stackView = UIStackView ( arrangedSubviews : [ titleLabel , mnemonicLabel , explanationLabel , buttonStackView ] )
stackView . axis = . vertical
stackView . spacing = Values . largeSpacing
contentView . addSubview ( stackView )
stackView . pin ( . leading , to : . leading , of : contentView , withInset : Values . largeSpacing )
stackView . pin ( . top , to : . top , of : contentView , withInset : Values . largeSpacing )
contentView . pin ( . trailing , to : . trailing , of : stackView , withInset : Values . largeSpacing )
contentView . pin ( . bottom , to : . bottom , of : stackView , withInset : Values . largeSpacing )
// M a r k s e e d a s v i e w e d
UserDefaults . standard [ . hasViewedSeed ] = true
NotificationCenter . default . post ( name : . seedViewed , object : nil )
}
// MARK: I n t e r a c t i o n
@objc private func copySeed ( ) {
UIPasteboard . general . string = mnemonic
dismiss ( animated : true , completion : nil )
}
}