BlueWallet/ios/BlueWalletWatch Extension/InterfaceController.swift

58 lines
2.2 KiB
Swift
Raw Normal View History

2019-05-02 16:33:03 -04:00
//
// InterfaceController.swift
// BlueWalletWatch Extension
//
// Created by Marcos Rodriguez on 3/6/19.
// Copyright © 2019 Facebook. All rights reserved.
//
import WatchKit
import WatchConnectivity
import Foundation
class InterfaceController: WKInterfaceController {
@IBOutlet weak var walletsTable: WKInterfaceTable!
@IBOutlet weak var noWalletsAvailableLabel: WKInterfaceLabel!
2021-09-27 23:05:45 -04:00
private let userActivity: NSUserActivity = NSUserActivity(activityType: HandoffIdentifier.ReceiveOnchain.rawValue)
2019-05-02 16:33:03 -04:00
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
2021-09-27 23:05:45 -04:00
update(userActivity)
2019-05-02 16:33:03 -04:00
2021-09-27 23:05:45 -04:00
userActivity.userInfo = [HandOffUserInfoKey.ReceiveOnchain.rawValue: "bc1q2uvss3v0qh5smluggyqrzjgnqdg5xmun6afwpz"]
userActivity.isEligibleForHandoff = true;
userActivity.becomeCurrent()
2019-05-02 16:33:03 -04:00
if (WatchDataSource.shared.wallets.isEmpty) {
noWalletsAvailableLabel.setHidden(false)
} else {
processWalletsTable()
}
NotificationCenter.default.addObserver(self, selector: #selector(processWalletsTable), name: WatchDataSource.NotificationName.dataUpdated, object: nil)
}
@objc private func processWalletsTable() {
walletsTable.setNumberOfRows(WatchDataSource.shared.wallets.count, withRowType: WalletInformation.identifier)
for index in 0..<walletsTable.numberOfRows {
guard let controller = walletsTable.rowController(at: index) as? WalletInformation else { continue }
let wallet = WatchDataSource.shared.wallets[index]
if wallet.identifier == nil {
WatchDataSource.shared.wallets[index].identifier = index
}
controller.walletBalanceLabel.setHidden(wallet.hideBalance)
2019-05-02 16:33:03 -04:00
controller.name = wallet.label
controller.balance = wallet.hideBalance ? "" : wallet.balance
2019-05-02 16:33:03 -04:00
controller.type = WalletGradient(rawValue: wallet.type) ?? .SegwitHD
}
noWalletsAvailableLabel.setHidden(!WatchDataSource.shared.wallets.isEmpty)
walletsTable.setHidden(WatchDataSource.shared.wallets.isEmpty)
}
override func contextForSegue(withIdentifier segueIdentifier: String, in table: WKInterfaceTable, rowIndex: Int) -> Any? {
return rowIndex;
}
}