2019-05-02 22:33:03 +02:00
|
|
|
//
|
|
|
|
// WalletDetailsInterfaceController.swift
|
|
|
|
// BlueWalletWatch Extension
|
|
|
|
//
|
|
|
|
// Created by Marcos Rodriguez on 3/11/19.
|
|
|
|
// Copyright © 2019 Facebook. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import WatchKit
|
|
|
|
import Foundation
|
2020-08-17 03:20:16 +02:00
|
|
|
import WatchConnectivity
|
2019-05-02 22:33:03 +02:00
|
|
|
|
|
|
|
class WalletDetailsInterfaceController: WKInterfaceController {
|
|
|
|
|
|
|
|
var wallet: Wallet?
|
|
|
|
static let identifier = "WalletDetailsInterfaceController"
|
|
|
|
@IBOutlet weak var walletBasicsGroup: WKInterfaceGroup!
|
|
|
|
@IBOutlet weak var walletBalanceLabel: WKInterfaceLabel!
|
2019-11-11 07:26:39 +01:00
|
|
|
@IBOutlet weak var createInvoiceButton: WKInterfaceButton!
|
2019-05-02 22:33:03 +02:00
|
|
|
@IBOutlet weak var walletNameLabel: WKInterfaceLabel!
|
|
|
|
@IBOutlet weak var receiveButton: WKInterfaceButton!
|
|
|
|
@IBOutlet weak var noTransactionsLabel: WKInterfaceLabel!
|
|
|
|
@IBOutlet weak var transactionsTable: WKInterfaceTable!
|
|
|
|
|
2019-11-11 07:26:39 +01:00
|
|
|
|
2019-05-02 22:33:03 +02:00
|
|
|
override func awake(withContext context: Any?) {
|
|
|
|
super.awake(withContext: context)
|
|
|
|
guard let identifier = context as? Int else {
|
|
|
|
pop()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let wallet = WatchDataSource.shared.wallets[identifier]
|
|
|
|
self.wallet = wallet
|
|
|
|
walletBalanceLabel.setText(wallet.balance)
|
|
|
|
walletNameLabel.setText(wallet.label)
|
|
|
|
walletBasicsGroup.setBackgroundImageNamed(WalletGradient(rawValue: wallet.type)?.imageString)
|
2019-11-11 07:26:39 +01:00
|
|
|
createInvoiceButton.setHidden(wallet.type != "lightningCustodianWallet")
|
2019-05-02 22:33:03 +02:00
|
|
|
processWalletsTable()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func willActivate() {
|
|
|
|
super.willActivate()
|
|
|
|
transactionsTable.setHidden(wallet?.transactions.isEmpty ?? true)
|
|
|
|
noTransactionsLabel.setHidden(!(wallet?.transactions.isEmpty ?? false))
|
2019-11-11 07:26:39 +01:00
|
|
|
receiveButton.setHidden(wallet?.receiveAddress.isEmpty ?? true)
|
2020-08-17 03:20:16 +02:00
|
|
|
createInvoiceButton.setEnabled(WCSession.default.isReachable)
|
2019-05-02 22:33:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func receiveMenuItemTapped() {
|
2019-11-11 07:26:39 +01:00
|
|
|
presentController(withName: ReceiveInterfaceController.identifier, context: (wallet, "receive"))
|
2019-05-02 22:33:03 +02:00
|
|
|
}
|
|
|
|
|
2019-11-11 07:26:39 +01:00
|
|
|
|
2019-05-02 22:33:03 +02:00
|
|
|
@objc private func processWalletsTable() {
|
|
|
|
transactionsTable.setNumberOfRows(wallet?.transactions.count ?? 0, withRowType: TransactionTableRow.identifier)
|
|
|
|
|
|
|
|
for index in 0..<transactionsTable.numberOfRows {
|
|
|
|
guard let controller = transactionsTable.rowController(at: index) as? TransactionTableRow, let transaction = wallet?.transactions[index] else { continue }
|
|
|
|
|
|
|
|
controller.amount = transaction.amount
|
|
|
|
controller.type = transaction.type
|
|
|
|
controller.memo = transaction.memo
|
|
|
|
controller.time = transaction.time
|
|
|
|
}
|
|
|
|
transactionsTable.setHidden(wallet?.transactions.isEmpty ?? true)
|
|
|
|
noTransactionsLabel.setHidden(!(wallet?.transactions.isEmpty ?? false))
|
|
|
|
}
|
|
|
|
|
2019-11-11 07:26:39 +01:00
|
|
|
@IBAction func createInvoiceTapped() {
|
2020-08-17 03:20:16 +02:00
|
|
|
if (WCSession.default.isReachable) {
|
|
|
|
pushController(withName: ReceiveInterfaceController.identifier, context: (wallet?.identifier, "createInvoice"))
|
|
|
|
}
|
2019-11-11 07:26:39 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 22:33:03 +02:00
|
|
|
override func contextForSegue(withIdentifier segueIdentifier: String) -> Any? {
|
2019-11-11 07:26:39 +01:00
|
|
|
return (wallet?.identifier, "receive")
|
2019-05-02 22:33:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|