Edit coins on iOS

This commit is contained in:
Ivan Grachev 2022-05-08 22:15:31 +03:00
parent de72afc7c0
commit de928134d8
2 changed files with 33 additions and 5 deletions

View File

@ -45,10 +45,30 @@ class EditAccountsViewController: UIViewController {
} }
} }
private func toggleAccountAtIndex(_ index: Int) {
cellModels[index].isEnabled.toggle()
okButton.isEnabled = cellModels.contains(where: { $0.isEnabled })
}
@IBAction func okButtonTapped(_ sender: Any) { @IBAction func okButtonTapped(_ sender: Any) {
// TODO: implement updating accounts let newDerivations: [CoinDerivation] = cellModels.compactMap { model in
print("yo") if model.isEnabled {
dismissAnimated() return model.coinDerivation
} else {
return nil
}
}
if newDerivations != initialDerivations {
do {
try walletsManager.update(wallet: wallet, coinDerivations: newDerivations)
dismissAnimated()
} catch {
showMessageAlert(text: Strings.somethingWentWrong)
}
} else {
dismissAnimated()
}
} }
} }
@ -56,7 +76,9 @@ class EditAccountsViewController: UIViewController {
extension EditAccountsViewController: UITableViewDelegate { extension EditAccountsViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
(tableView.cellForRow(at: indexPath) as? CoinDerivationTableViewCell)?.toggle()
toggleAccountAtIndex(indexPath.row)
} }
} }
@ -79,7 +101,9 @@ extension EditAccountsViewController: UITableViewDataSource {
extension EditAccountsViewController: CoinDerivationTableViewCellDelegate { extension EditAccountsViewController: CoinDerivationTableViewCellDelegate {
func didToggleSwitch(_ sender: CoinDerivationTableViewCell) { func didToggleSwitch(_ sender: CoinDerivationTableViewCell) {
// TODO: update model if let index = tableView.indexPath(for: sender)?.row {
toggleAccountAtIndex(index)
}
} }
} }

View File

@ -22,6 +22,10 @@ class CoinDerivationTableViewCell: UITableViewCell {
coinSwitch.isOn = isEnabled coinSwitch.isOn = isEnabled
} }
func toggle() {
coinSwitch.isOn.toggle()
}
@IBAction func didToggleSwitch(_ sender: Any) { @IBAction func didToggleSwitch(_ sender: Any) {
cellDelegate?.didToggleSwitch(self) cellDelegate?.didToggleSwitch(self)
} }