Skip to content

Instantly share code, notes, and snippets.

@impul
Created March 18, 2020 16:24
Show Gist options
  • Save impul/e33f0c17fe945135274240ee897f27fd to your computer and use it in GitHub Desktop.
Save impul/e33f0c17fe945135274240ee897f27fd to your computer and use it in GitHub Desktop.
//
// MnemonicPhraseCopyViewController.swift
// ImpulseWallet
//
// Created by Pavlo Boiko on 20.07.18.
// Copyright © 2018 Impulse. All rights reserved.
//
import UIKit
import ImpCore
import ImpUI
import ImpResources
import ImpDI
class MnemonicPhraseCopyViewController: BaseTableAdapterController, SwipeableNavigation {
private lazy var colorProvider: AppColorInterface = inject()
// MARK: - Store
private let mnemonic: String
private var isCopySelected: Bool = false
// MARK: - Init
required init(mnemonic: String) {
self.mnemonic = mnemonic
super.init()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override var state: [TableComponent] {
[.tabBarSpace,
.navigationBar(left: LS("Back"),
right: "",
title: "",
lAction: backAction,
rAction: nil),
.title(bold: true, title: LS("MnemonicPhrase.Title")),
.description(title: LS("MnemonicPhrase.Description"), background: .backgroundColor),
.empty(height: 20.0, background: .backgroundColor),
.wordEntering(words: words),
.empty(height: 40.0, background: .backgroundColor),
.smallCenteredButton(title: isCopySelected ? LS("MnemonicPhrase.Copied") : LS("MnemonicPhrase.Copy"),
isEnable: !isCopySelected,
action: copyAction,
background: .backgroundColor),
.calculableSpace(background: .backgroundColor),
.centeredButton(title: LS("MnemonicPhrase.Continue"),
isEnable: isCopySelected,
action: continueAction,
background: .backgroundColor),
.empty(height: 20, background: .backgroundColor)
]
}
private var words: [PhraseEnteringState] {
return mnemonic.split(separator: " ").map {
return PhraseEnteringState.entered(String($0), editingIndex: 0)
}
}
// MARK: - Actions
private lazy var backAction: () -> Void = {
(inject() as WalletRouterInterface).pop()
}
private lazy var copyAction: () -> Void = {
UIPasteboard.general.string = self.mnemonic
self.isCopySelected = true
self.tableAdapter.performTableUpdate(newState: self.state, withAnimation: .fade)
}
private lazy var continueAction: () -> Void = {
(inject() as UserStorageServiceInterface).update({ (user) in
user.backup.currentlyBackup.add(.mnemonic)
})
(inject() as SettingsRouterInterface).pop()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment