This commit is contained in:
Marcos Rodriguez Velez 2023-10-30 12:38:12 -04:00
parent 644f5e85d3
commit c2dc235665
No known key found for this signature in database
GPG key ID: 6030B2F48CCE86D7
8 changed files with 72 additions and 51 deletions

3
App.js
View file

@ -26,7 +26,6 @@ import loc from './loc';
import { BlueDefaultTheme, BlueDarkTheme } from './components/themes'; import { BlueDefaultTheme, BlueDarkTheme } from './components/themes';
import InitRoot from './Navigation'; import InitRoot from './Navigation';
import BlueClipboard from './blue_modules/clipboard'; import BlueClipboard from './blue_modules/clipboard';
import { isDesktop } from './blue_modules/environment';
import { BlueStorageContext } from './blue_modules/storage-context'; import { BlueStorageContext } from './blue_modules/storage-context';
import WatchConnectivity from './WatchConnectivity'; import WatchConnectivity from './WatchConnectivity';
import DeviceQuickActions from './class/quick-actions'; import DeviceQuickActions from './class/quick-actions';
@ -387,8 +386,8 @@ const App = () => {
<InitRoot /> <InitRoot />
<Notifications onProcessNotifications={processPushNotifications} /> <Notifications onProcessNotifications={processPushNotifications} />
</NavigationContainer> </NavigationContainer>
{walletsInitialized && !isDesktop && <WatchConnectivity />}
</View> </View>
<WatchConnectivity />
<DeviceQuickActions /> <DeviceQuickActions />
<Biometric /> <Biometric />
<WidgetCommunication /> <WidgetCommunication />

View file

@ -1,11 +1,11 @@
import { useContext, useEffect, useRef } from 'react'; import React, { useContext, useEffect, useRef } from 'react';
import { import {
updateApplicationContext, updateApplicationContext,
watchEvents, watchEvents,
useReachability, useReachability,
useInstalled, useInstalled,
usePaired,
transferCurrentComplicationUserInfo, transferCurrentComplicationUserInfo,
transferUserInfo,
} from 'react-native-watch-connectivity'; } from 'react-native-watch-connectivity';
import { Chain } from './models/bitcoinUnits'; import { Chain } from './models/bitcoinUnits';
import loc, { formatBalance, transactionTimeToReadable } from './loc'; import loc, { formatBalance, transactionTimeToReadable } from './loc';
@ -18,14 +18,13 @@ function WatchConnectivity() {
const { walletsInitialized, wallets, fetchWalletTransactions, saveToDisk, txMetadata, preferredFiatCurrency } = const { walletsInitialized, wallets, fetchWalletTransactions, saveToDisk, txMetadata, preferredFiatCurrency } =
useContext(BlueStorageContext); useContext(BlueStorageContext);
const isReachable = useReachability(); const isReachable = useReachability();
const isPaired = usePaired();
const isInstalled = useInstalled(); // true | false const isInstalled = useInstalled(); // true | false
const messagesListenerActive = useRef(false); const messagesListenerActive = useRef(false);
const lastPreferredCurrency = useRef(FiatUnit.USD.endPointKey); const lastPreferredCurrency = useRef(FiatUnit.USD.endPointKey);
useEffect(() => { useEffect(() => {
let messagesListener = () => {}; let messagesListener = () => {};
if (isPaired && isInstalled && isReachable && walletsInitialized && messagesListenerActive.current === false) { if (isInstalled && isReachable && walletsInitialized && messagesListenerActive.current === false) {
messagesListener = watchEvents.addListener('message', handleMessages); messagesListener = watchEvents.addListener('message', handleMessages);
messagesListenerActive.current = true; messagesListenerActive.current = true;
} else { } else {
@ -37,14 +36,26 @@ function WatchConnectivity() {
messagesListenerActive.current = false; messagesListenerActive.current = false;
}; };
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [walletsInitialized, isPaired, isReachable, isInstalled]); }, [walletsInitialized, isReachable, isInstalled]);
useEffect(() => { useEffect(() => {
if (isPaired && isInstalled && isReachable && walletsInitialized) { console.warn(isInstalled, isReachable, walletsInitialized);
sendWalletsToWatch(); if (isInstalled && walletsInitialized) {
constructWalletsToSendToWatch().then(walletsToProcess => {
console.warn(walletsToProcess);
if (walletsToProcess) {
if (isReachable) {
transferUserInfo(walletsToProcess);
console.warn('sent info to watch transferUserInfo');
} else {
updateApplicationContext(walletsToProcess);
console.warn('sent info to watch context');
}
}
});
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [walletsInitialized, wallets, isPaired, isReachable, isInstalled]); }, [walletsInitialized, wallets, isReachable, isInstalled]);
useEffect(() => { useEffect(() => {
updateApplicationContext({ isWalletsInitialized: walletsInitialized, randomID: Math.floor(Math.random() * 11) }); updateApplicationContext({ isWalletsInitialized: walletsInitialized, randomID: Math.floor(Math.random() * 11) });
@ -78,8 +89,11 @@ function WatchConnectivity() {
reply({}); reply({});
}); });
} else if (message.message === 'sendApplicationContext') { } else if (message.message === 'sendApplicationContext') {
sendWalletsToWatch(); constructWalletsToSendToWatch().then(walletsToProcess => {
reply({}); if (walletsToProcess) {
updateApplicationContext(walletsToProcess);
}
});
} else if (message.message === 'fetchTransactions') { } else if (message.message === 'fetchTransactions') {
fetchWalletTransactions() fetchWalletTransactions()
.then(() => saveToDisk()) .then(() => saveToDisk())
@ -116,7 +130,7 @@ function WatchConnectivity() {
} }
}; };
const sendWalletsToWatch = async () => { const constructWalletsToSendToWatch = async () => {
if (!Array.isArray(wallets)) { if (!Array.isArray(wallets)) {
console.log('No Wallets set to sync with Watch app. Exiting...'); console.log('No Wallets set to sync with Watch app. Exiting...');
return; return;
@ -218,10 +232,10 @@ function WatchConnectivity() {
} }
walletsToProcess.push(walletInformation); walletsToProcess.push(walletInformation);
} }
updateApplicationContext({ wallets: walletsToProcess, randomID: Math.floor(Math.random() * 11) }); return { wallets: walletsToProcess, randomID: Math.floor(Math.random() * 11) };
}; };
return null; return <></>;
} }
export default WatchConnectivity; export default WatchConnectivity;

View file

@ -3,7 +3,7 @@
archiveVersion = 1; archiveVersion = 1;
classes = { classes = {
}; };
objectVersion = 52; objectVersion = 54;
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
@ -781,12 +781,10 @@
}; };
B40D4E2F225841EC00428FCC = { B40D4E2F225841EC00428FCC = {
CreatedOnToolsVersion = 10.2; CreatedOnToolsVersion = 10.2;
DevelopmentTeam = A7W54YZ4WU;
LastSwiftMigration = 1240; LastSwiftMigration = 1240;
}; };
B40D4E3B225841ED00428FCC = { B40D4E3B225841ED00428FCC = {
CreatedOnToolsVersion = 10.2; CreatedOnToolsVersion = 10.2;
DevelopmentTeam = A7W54YZ4WU;
LastSwiftMigration = 1130; LastSwiftMigration = 1130;
SystemCapabilities = { SystemCapabilities = {
com.apple.Keychain = { com.apple.Keychain = {
@ -829,7 +827,7 @@
); );
mainGroup = 83CBB9F61A601CBA00E9B192; mainGroup = 83CBB9F61A601CBA00E9B192;
packageReferences = ( packageReferences = (
6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode.git" */, 6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode" */,
); );
productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */;
projectDirPath = ""; projectDirPath = "";
@ -1608,7 +1606,7 @@
CURRENT_PROJECT_VERSION = 753; CURRENT_PROJECT_VERSION = 753;
DEAD_CODE_STRIPPING = YES; DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf; DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = A7W54YZ4WU;
GCC_C_LANGUAGE_STANDARD = gnu11; GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "BlueWalletWatch Extension/Info.plist"; INFOPLIST_FILE = "BlueWalletWatch Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
@ -1655,7 +1653,7 @@
CURRENT_PROJECT_VERSION = 753; CURRENT_PROJECT_VERSION = 753;
DEAD_CODE_STRIPPING = YES; DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = A7W54YZ4WU;
GCC_C_LANGUAGE_STANDARD = gnu11; GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "BlueWalletWatch Extension/Info.plist"; INFOPLIST_FILE = "BlueWalletWatch Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
@ -1701,7 +1699,7 @@
CURRENT_PROJECT_VERSION = 753; CURRENT_PROJECT_VERSION = 753;
DEAD_CODE_STRIPPING = YES; DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf; DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = A7W54YZ4WU;
GCC_C_LANGUAGE_STANDARD = gnu11; GCC_C_LANGUAGE_STANDARD = gnu11;
IBSC_MODULE = BlueWalletWatch_Extension; IBSC_MODULE = BlueWalletWatch_Extension;
INFOPLIST_FILE = BlueWalletWatch/Info.plist; INFOPLIST_FILE = BlueWalletWatch/Info.plist;
@ -1746,7 +1744,7 @@
CURRENT_PROJECT_VERSION = 753; CURRENT_PROJECT_VERSION = 753;
DEAD_CODE_STRIPPING = YES; DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = A7W54YZ4WU;
GCC_C_LANGUAGE_STANDARD = gnu11; GCC_C_LANGUAGE_STANDARD = gnu11;
IBSC_MODULE = BlueWalletWatch_Extension; IBSC_MODULE = BlueWalletWatch_Extension;
INFOPLIST_FILE = BlueWalletWatch/Info.plist; INFOPLIST_FILE = BlueWalletWatch/Info.plist;
@ -1832,7 +1830,7 @@
/* End XCConfigurationList section */ /* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */ /* Begin XCRemoteSwiftPackageReference section */
6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode.git" */ = { 6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode" */ = {
isa = XCRemoteSwiftPackageReference; isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/EFPrefix/EFQRCode.git"; repositoryURL = "https://github.com/EFPrefix/EFQRCode.git";
requirement = { requirement = {
@ -1845,7 +1843,7 @@
/* Begin XCSwiftPackageProductDependency section */ /* Begin XCSwiftPackageProductDependency section */
6DFC806F24EA0B6C007B8700 /* EFQRCode */ = { 6DFC806F24EA0B6C007B8700 /* EFQRCode */ = {
isa = XCSwiftPackageProductDependency; isa = XCSwiftPackageProductDependency;
package = 6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode.git" */; package = 6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode" */;
productName = EFQRCode; productName = EFQRCode;
}; };
/* End XCSwiftPackageProductDependency section */ /* End XCSwiftPackageProductDependency section */

View file

@ -47,7 +47,7 @@
<key>WidgetsExtension.xcscheme_^#shared#^_</key> <key>WidgetsExtension.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>193</integer> <integer>129</integer>
</dict> </dict>
</dict> </dict>
<key>SuppressBuildableAutocreation</key> <key>SuppressBuildableAutocreation</key>

View file

@ -10,7 +10,6 @@
#import <RNCPushNotificationIOS.h> #import <RNCPushNotificationIOS.h>
#import "EventEmitter.h" #import "EventEmitter.h"
#import <React/RCTRootView.h> #import <React/RCTRootView.h>
#import <WatchConnectivity/WatchConnectivity.h>
@interface AppDelegate() <UNUserNotificationCenterDelegate> @interface AppDelegate() <UNUserNotificationCenterDelegate>
@ -103,9 +102,6 @@
} }
- (void)applicationWillTerminate:(UIApplication *)application { - (void)applicationWillTerminate:(UIApplication *)application {
if ([WCSession defaultSession].activationState == WCSessionActivationStateActivated && [[WCSession defaultSession] isReachable]) {
[WCSession.defaultSession updateApplicationContext:@{@"isWalletsInitialized": @NO} error:nil];
}
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.io.bluewallet.bluewallet"]; NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.io.bluewallet.bluewallet"];
[defaults removeObjectForKey:@"onUserActivityOpen"]; [defaults removeObjectForKey:@"onUserActivityOpen"];
} }

View file

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict/> <dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.io.bluewallet.bluewallet</string>
</array>
</dict>
</plist> </plist>

View file

@ -10,20 +10,21 @@ import WatchKit
import WatchConnectivity import WatchConnectivity
import Foundation import Foundation
class InterfaceController: WKInterfaceController, WCSessionDelegate { class InterfaceController: WKInterfaceController {
@IBOutlet weak var walletsTable: WKInterfaceTable! @IBOutlet weak var walletsTable: WKInterfaceTable!
@IBOutlet weak var noWalletsAvailableLabel: WKInterfaceLabel! @IBOutlet weak var noWalletsAvailableLabel: WKInterfaceLabel!
private let userActivity: NSUserActivity = NSUserActivity(activityType: HandoffIdentifier.ReceiveOnchain.rawValue) private let userActivity: NSUserActivity = NSUserActivity(activityType: HandoffIdentifier.ReceiveOnchain.rawValue)
var session: WCSession?
override func awake(withContext context: Any?) { override func awake(withContext context: Any?) {
super.awake(withContext: context) super.awake(withContext: context)
if let contextUnwrapped = context as? [String: Any] {
WatchDataSource.shared.processData(data: contextUnwrapped)
}
if WCSession.isSupported() { if WCSession.isSupported() {
print("Activating watch session") print("Activating watch session")
self.session = WCSession.default WCSession.default.delegate = self
self.session?.delegate = self WCSession.default.activate()
self.session?.activate()
} }
} }
@ -32,15 +33,12 @@ class InterfaceController: WKInterfaceController, WCSessionDelegate {
super.willActivate() super.willActivate()
update(userActivity) update(userActivity)
userActivity.userInfo = [HandOffUserInfoKey.ReceiveOnchain.rawValue: "bc1q2uvss3v0qh5smluggyqrzjgnqdg5xmun6afwpz"]
userActivity.isEligibleForHandoff = true;
userActivity.becomeCurrent()
if (WatchDataSource.shared.wallets.isEmpty) { if (WatchDataSource.shared.wallets.isEmpty) {
noWalletsAvailableLabel.setHidden(false) noWalletsAvailableLabel.setHidden(false)
} else { } else {
processWalletsTable() processWalletsTable()
} }
NotificationCenter.default.addObserver(self, selector: #selector(processWalletsTable), name: WatchDataSource.NotificationName.dataUpdated, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(processWalletsTable), name: WatchDataSource.NotificationName.dataUpdated, object: nil)
} }
@objc private func processWalletsTable() { @objc private func processWalletsTable() {
@ -65,26 +63,32 @@ class InterfaceController: WKInterfaceController, WCSessionDelegate {
return rowIndex; return rowIndex;
} }
}
extension InterfaceController: WCSessionDelegate {
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) { func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
WatchDataSource.shared.processData(data: applicationContext) WatchDataSource.shared.processData(data: applicationContext)
} }
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
WatchDataSource.shared.processData(data: applicationContext)
}
func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any] = [:]) { func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any] = [:]) {
WatchDataSource.shared.processData(data: userInfo) WatchDataSource.shared.processData(data: userInfo)
} }
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
WatchDataSource.shared.companionWalletsInitialized = activationState == .activated
if activationState == .activated { if activationState == .activated {
WCSession.default.sendMessage(["message" : "sendApplicationContext"], replyHandler: { (replyData) in WatchDataSource.shared.processWalletsData(walletsInfo: WCSession.default.applicationContext)
}) { (error) in
print(error)
}
} else {
WatchDataSource.shared.companionWalletsInitialized = false
} }
} }
func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
WatchDataSource.shared.processData(data: message)
}
override func didDeactivate() {
WCSession.default.activate()
}
} }

View file

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict/> <dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.io.bluewallet.bluewallet</string>
</array>
</dict>
</plist> </plist>