mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-13 11:09:20 +01:00
ADD: Toggle balance visibility on watch app
This commit is contained in:
parent
91a1cfd4a0
commit
9a94113e5b
3 changed files with 62 additions and 10 deletions
|
@ -28,6 +28,11 @@ function WatchConnectivity() {
|
|||
sendWalletsToWatch();
|
||||
} else if (message.message === 'fetchTransactions') {
|
||||
fetchWalletTransactions().then(() => saveToDisk());
|
||||
} else if (message.message === 'hideBalance') {
|
||||
const walletIndex = message.walletIndex;
|
||||
const wallet = wallets[walletIndex];
|
||||
wallet.hideBalance = message.hideBalance;
|
||||
saveToDisk().finally(() => reply({}));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -35,9 +35,10 @@ class WatchDataSource: NSObject, WCSessionDelegate {
|
|||
if let walletsToProcess = walletsInfo["wallets"] as? [[String: Any]] {
|
||||
wallets.removeAll();
|
||||
for (index, entry) in walletsToProcess.enumerated() {
|
||||
guard let label = entry["label"] as? String, let balance = entry["balance"] as? String, let type = entry["type"] as? String, let preferredBalanceUnit = entry["preferredBalanceUnit"] as? String, let transactions = entry["transactions"] as? [[String: Any]], let hideBalance = entry["hideBalance"] as? Bool ?? false else {
|
||||
guard let label = entry["label"] as? String, let balance = entry["balance"] as? String, let type = entry["type"] as? String, let preferredBalanceUnit = entry["preferredBalanceUnit"] as? String, let transactions = entry["transactions"] as? [[String: Any]] else {
|
||||
continue
|
||||
}
|
||||
|
||||
var transactionsProcessed = [Transaction]()
|
||||
for transactionEntry in transactions {
|
||||
guard let time = transactionEntry["time"] as? String, let memo = transactionEntry["memo"] as? String, let amount = transactionEntry["amount"] as? String, let type = transactionEntry["type"] as? String else { continue }
|
||||
|
@ -46,6 +47,7 @@ class WatchDataSource: NSObject, WCSessionDelegate {
|
|||
}
|
||||
let receiveAddress = entry["receiveAddress"] as? String ?? ""
|
||||
let xpub = entry["xpub"] as? String ?? ""
|
||||
let hideBalance = entry["hideBalance"] as? Bool ?? false
|
||||
let wallet = Wallet(label: label, balance: balance, type: type, preferredBalanceUnit: preferredBalanceUnit, receiveAddress: receiveAddress, transactions: transactionsProcessed, identifier: index, xpub: xpub, hideBalance: hideBalance)
|
||||
wallets.append(wallet)
|
||||
}
|
||||
|
@ -79,6 +81,20 @@ class WatchDataSource: NSObject, WCSessionDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
static func toggleWalletHideBalance(walletIdentifier: Int, hideBalance: Bool, responseHandler: @escaping (_ invoice: String) -> Void) {
|
||||
guard WatchDataSource.shared.wallets.count > walletIdentifier else {
|
||||
responseHandler("")
|
||||
return
|
||||
}
|
||||
WCSession.default.sendMessage(["message": "hideBalance", "walletIndex": walletIdentifier, "hideBalance": hideBalance], replyHandler: { (reply: [String : Any]) in
|
||||
responseHandler("")
|
||||
}) { (error) in
|
||||
print(error)
|
||||
responseHandler("")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
|
||||
WatchDataSource.shared.processWalletsData(walletsInfo: applicationContext)
|
||||
}
|
||||
|
|
|
@ -29,24 +29,55 @@ class WalletDetailsInterfaceController: WKInterfaceController {
|
|||
pop()
|
||||
return
|
||||
}
|
||||
let wallet = WatchDataSource.shared.wallets[identifier]
|
||||
self.wallet = wallet
|
||||
walletBalanceLabel.setHidden(wallet.hideBalance)
|
||||
walletBalanceLabel.setText(wallet.hideBalance ? "" : wallet.balance)
|
||||
walletNameLabel.setText(wallet.label)
|
||||
walletBasicsGroup.setBackgroundImageNamed(WalletGradient(rawValue: wallet.type)?.imageString)
|
||||
createInvoiceButton.setHidden(wallet.type != "lightningCustodianWallet")
|
||||
processWalletsTable()
|
||||
addMenuItems()
|
||||
processInterface(identifier: identifier)
|
||||
}
|
||||
|
||||
func processInterface(identifier: Int) {
|
||||
let wallet = WatchDataSource.shared.wallets[identifier]
|
||||
self.wallet = wallet
|
||||
walletBalanceLabel.setHidden(wallet.hideBalance)
|
||||
walletBalanceLabel.setText(wallet.hideBalance ? "" : wallet.balance)
|
||||
walletNameLabel.setText(wallet.label)
|
||||
walletBasicsGroup.setBackgroundImageNamed(WalletGradient(rawValue: wallet.type)?.imageString)
|
||||
createInvoiceButton.setHidden(wallet.type != "lightningCustodianWallet")
|
||||
processWalletsTable()
|
||||
addMenuItems()
|
||||
}
|
||||
|
||||
func addMenuItems() {
|
||||
guard let wallet = wallet else {
|
||||
return
|
||||
}
|
||||
|
||||
clearAllMenuItems()
|
||||
if wallet.type != "lightningCustodianWallet" && !(wallet.xpub ?? "").isEmpty {
|
||||
addMenuItem(with: .share, title: "View XPub", action: #selector(viewXPubMenuItemTapped))
|
||||
}
|
||||
if wallet.hideBalance {
|
||||
addMenuItem(with: .accept, title: "Show Balance", action: #selector(showBalanceMenuItemTapped))
|
||||
}else{
|
||||
addMenuItem(with: .decline, title: "Hide Balance", action: #selector(hideBalanceMenuItemTapped))
|
||||
}
|
||||
}
|
||||
|
||||
@objc func showBalanceMenuItemTapped() {
|
||||
guard let identifier = wallet?.identifier else { return }
|
||||
WatchDataSource.toggleWalletHideBalance(walletIdentifier: identifier, hideBalance: false) { [weak self] _ in
|
||||
DispatchQueue.main.async {
|
||||
WatchDataSource.postDataUpdatedNotification()
|
||||
self?.processInterface(identifier: identifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func hideBalanceMenuItemTapped() {
|
||||
guard let identifier = wallet?.identifier else { return }
|
||||
WatchDataSource.toggleWalletHideBalance(walletIdentifier: identifier, hideBalance: true) { [weak self] _ in
|
||||
DispatchQueue.main.async {
|
||||
WatchDataSource.postDataUpdatedNotification()
|
||||
self?.processInterface(identifier: identifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func viewXPubMenuItemTapped() {
|
||||
|
|
Loading…
Add table
Reference in a new issue