mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-22 15:04:50 +01:00
WIP
This commit is contained in:
parent
644f5e85d3
commit
c2dc235665
8 changed files with 72 additions and 51 deletions
3
App.js
3
App.js
|
@ -26,7 +26,6 @@ import loc from './loc';
|
|||
import { BlueDefaultTheme, BlueDarkTheme } from './components/themes';
|
||||
import InitRoot from './Navigation';
|
||||
import BlueClipboard from './blue_modules/clipboard';
|
||||
import { isDesktop } from './blue_modules/environment';
|
||||
import { BlueStorageContext } from './blue_modules/storage-context';
|
||||
import WatchConnectivity from './WatchConnectivity';
|
||||
import DeviceQuickActions from './class/quick-actions';
|
||||
|
@ -387,8 +386,8 @@ const App = () => {
|
|||
<InitRoot />
|
||||
<Notifications onProcessNotifications={processPushNotifications} />
|
||||
</NavigationContainer>
|
||||
{walletsInitialized && !isDesktop && <WatchConnectivity />}
|
||||
</View>
|
||||
<WatchConnectivity />
|
||||
<DeviceQuickActions />
|
||||
<Biometric />
|
||||
<WidgetCommunication />
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { useContext, useEffect, useRef } from 'react';
|
||||
import React, { useContext, useEffect, useRef } from 'react';
|
||||
import {
|
||||
updateApplicationContext,
|
||||
watchEvents,
|
||||
useReachability,
|
||||
useInstalled,
|
||||
usePaired,
|
||||
transferCurrentComplicationUserInfo,
|
||||
transferUserInfo,
|
||||
} from 'react-native-watch-connectivity';
|
||||
import { Chain } from './models/bitcoinUnits';
|
||||
import loc, { formatBalance, transactionTimeToReadable } from './loc';
|
||||
|
@ -18,14 +18,13 @@ function WatchConnectivity() {
|
|||
const { walletsInitialized, wallets, fetchWalletTransactions, saveToDisk, txMetadata, preferredFiatCurrency } =
|
||||
useContext(BlueStorageContext);
|
||||
const isReachable = useReachability();
|
||||
const isPaired = usePaired();
|
||||
const isInstalled = useInstalled(); // true | false
|
||||
const messagesListenerActive = useRef(false);
|
||||
const lastPreferredCurrency = useRef(FiatUnit.USD.endPointKey);
|
||||
|
||||
useEffect(() => {
|
||||
let messagesListener = () => {};
|
||||
if (isPaired && isInstalled && isReachable && walletsInitialized && messagesListenerActive.current === false) {
|
||||
if (isInstalled && isReachable && walletsInitialized && messagesListenerActive.current === false) {
|
||||
messagesListener = watchEvents.addListener('message', handleMessages);
|
||||
messagesListenerActive.current = true;
|
||||
} else {
|
||||
|
@ -37,14 +36,26 @@ function WatchConnectivity() {
|
|||
messagesListenerActive.current = false;
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [walletsInitialized, isPaired, isReachable, isInstalled]);
|
||||
}, [walletsInitialized, isReachable, isInstalled]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isPaired && isInstalled && isReachable && walletsInitialized) {
|
||||
sendWalletsToWatch();
|
||||
console.warn(isInstalled, isReachable, walletsInitialized);
|
||||
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
|
||||
}, [walletsInitialized, wallets, isPaired, isReachable, isInstalled]);
|
||||
}, [walletsInitialized, wallets, isReachable, isInstalled]);
|
||||
|
||||
useEffect(() => {
|
||||
updateApplicationContext({ isWalletsInitialized: walletsInitialized, randomID: Math.floor(Math.random() * 11) });
|
||||
|
@ -78,8 +89,11 @@ function WatchConnectivity() {
|
|||
reply({});
|
||||
});
|
||||
} else if (message.message === 'sendApplicationContext') {
|
||||
sendWalletsToWatch();
|
||||
reply({});
|
||||
constructWalletsToSendToWatch().then(walletsToProcess => {
|
||||
if (walletsToProcess) {
|
||||
updateApplicationContext(walletsToProcess);
|
||||
}
|
||||
});
|
||||
} else if (message.message === 'fetchTransactions') {
|
||||
fetchWalletTransactions()
|
||||
.then(() => saveToDisk())
|
||||
|
@ -116,7 +130,7 @@ function WatchConnectivity() {
|
|||
}
|
||||
};
|
||||
|
||||
const sendWalletsToWatch = async () => {
|
||||
const constructWalletsToSendToWatch = async () => {
|
||||
if (!Array.isArray(wallets)) {
|
||||
console.log('No Wallets set to sync with Watch app. Exiting...');
|
||||
return;
|
||||
|
@ -218,10 +232,10 @@ function WatchConnectivity() {
|
|||
}
|
||||
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;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 52;
|
||||
objectVersion = 54;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
|
@ -781,12 +781,10 @@
|
|||
};
|
||||
B40D4E2F225841EC00428FCC = {
|
||||
CreatedOnToolsVersion = 10.2;
|
||||
DevelopmentTeam = A7W54YZ4WU;
|
||||
LastSwiftMigration = 1240;
|
||||
};
|
||||
B40D4E3B225841ED00428FCC = {
|
||||
CreatedOnToolsVersion = 10.2;
|
||||
DevelopmentTeam = A7W54YZ4WU;
|
||||
LastSwiftMigration = 1130;
|
||||
SystemCapabilities = {
|
||||
com.apple.Keychain = {
|
||||
|
@ -829,7 +827,7 @@
|
|||
);
|
||||
mainGroup = 83CBB9F61A601CBA00E9B192;
|
||||
packageReferences = (
|
||||
6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode.git" */,
|
||||
6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode" */,
|
||||
);
|
||||
productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */;
|
||||
projectDirPath = "";
|
||||
|
@ -1608,7 +1606,7 @@
|
|||
CURRENT_PROJECT_VERSION = 753;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
DEVELOPMENT_TEAM = A7W54YZ4WU;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
INFOPLIST_FILE = "BlueWalletWatch Extension/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
|
@ -1655,7 +1653,7 @@
|
|||
CURRENT_PROJECT_VERSION = 753;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
DEVELOPMENT_TEAM = "";
|
||||
DEVELOPMENT_TEAM = A7W54YZ4WU;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
INFOPLIST_FILE = "BlueWalletWatch Extension/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
|
@ -1701,7 +1699,7 @@
|
|||
CURRENT_PROJECT_VERSION = 753;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
DEVELOPMENT_TEAM = A7W54YZ4WU;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
IBSC_MODULE = BlueWalletWatch_Extension;
|
||||
INFOPLIST_FILE = BlueWalletWatch/Info.plist;
|
||||
|
@ -1746,7 +1744,7 @@
|
|||
CURRENT_PROJECT_VERSION = 753;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
DEVELOPMENT_TEAM = "";
|
||||
DEVELOPMENT_TEAM = A7W54YZ4WU;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
IBSC_MODULE = BlueWalletWatch_Extension;
|
||||
INFOPLIST_FILE = BlueWalletWatch/Info.plist;
|
||||
|
@ -1832,7 +1830,7 @@
|
|||
/* End XCConfigurationList section */
|
||||
|
||||
/* Begin XCRemoteSwiftPackageReference section */
|
||||
6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode.git" */ = {
|
||||
6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/EFPrefix/EFQRCode.git";
|
||||
requirement = {
|
||||
|
@ -1845,7 +1843,7 @@
|
|||
/* Begin XCSwiftPackageProductDependency section */
|
||||
6DFC806F24EA0B6C007B8700 /* EFQRCode */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode.git" */;
|
||||
package = 6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode" */;
|
||||
productName = EFQRCode;
|
||||
};
|
||||
/* End XCSwiftPackageProductDependency section */
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<key>WidgetsExtension.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>193</integer>
|
||||
<integer>129</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#import <RNCPushNotificationIOS.h>
|
||||
#import "EventEmitter.h"
|
||||
#import <React/RCTRootView.h>
|
||||
#import <WatchConnectivity/WatchConnectivity.h>
|
||||
|
||||
@interface AppDelegate() <UNUserNotificationCenterDelegate>
|
||||
|
||||
|
@ -103,9 +102,6 @@
|
|||
}
|
||||
|
||||
- (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"];
|
||||
[defaults removeObjectForKey:@"onUserActivityOpen"];
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
<?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">
|
||||
<plist version="1.0">
|
||||
<dict/>
|
||||
<dict>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.io.bluewallet.bluewallet</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
@ -10,20 +10,21 @@ import WatchKit
|
|||
import WatchConnectivity
|
||||
import Foundation
|
||||
|
||||
class InterfaceController: WKInterfaceController, WCSessionDelegate {
|
||||
class InterfaceController: WKInterfaceController {
|
||||
|
||||
@IBOutlet weak var walletsTable: WKInterfaceTable!
|
||||
@IBOutlet weak var noWalletsAvailableLabel: WKInterfaceLabel!
|
||||
private let userActivity: NSUserActivity = NSUserActivity(activityType: HandoffIdentifier.ReceiveOnchain.rawValue)
|
||||
var session: WCSession?
|
||||
|
||||
override func awake(withContext context: Any?) {
|
||||
super.awake(withContext: context)
|
||||
if let contextUnwrapped = context as? [String: Any] {
|
||||
WatchDataSource.shared.processData(data: contextUnwrapped)
|
||||
}
|
||||
if WCSession.isSupported() {
|
||||
print("Activating watch session")
|
||||
self.session = WCSession.default
|
||||
self.session?.delegate = self
|
||||
self.session?.activate()
|
||||
WCSession.default.delegate = self
|
||||
WCSession.default.activate()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,15 +33,12 @@ class InterfaceController: WKInterfaceController, WCSessionDelegate {
|
|||
super.willActivate()
|
||||
update(userActivity)
|
||||
|
||||
userActivity.userInfo = [HandOffUserInfoKey.ReceiveOnchain.rawValue: "bc1q2uvss3v0qh5smluggyqrzjgnqdg5xmun6afwpz"]
|
||||
userActivity.isEligibleForHandoff = true;
|
||||
userActivity.becomeCurrent()
|
||||
if (WatchDataSource.shared.wallets.isEmpty) {
|
||||
noWalletsAvailableLabel.setHidden(false)
|
||||
} else {
|
||||
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() {
|
||||
|
@ -65,26 +63,32 @@ class InterfaceController: WKInterfaceController, WCSessionDelegate {
|
|||
return rowIndex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension InterfaceController: WCSessionDelegate {
|
||||
|
||||
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
|
||||
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] = [:]) {
|
||||
WatchDataSource.shared.processData(data: userInfo)
|
||||
}
|
||||
|
||||
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
|
||||
WatchDataSource.shared.companionWalletsInitialized = activationState == .activated
|
||||
if activationState == .activated {
|
||||
WCSession.default.sendMessage(["message" : "sendApplicationContext"], replyHandler: { (replyData) in
|
||||
}) { (error) in
|
||||
print(error)
|
||||
}
|
||||
} else {
|
||||
WatchDataSource.shared.companionWalletsInitialized = false
|
||||
WatchDataSource.shared.processWalletsData(walletsInfo: WCSession.default.applicationContext)
|
||||
}
|
||||
}
|
||||
|
||||
func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
|
||||
WatchDataSource.shared.processData(data: message)
|
||||
}
|
||||
|
||||
override func didDeactivate() {
|
||||
WCSession.default.activate()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
<?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">
|
||||
<plist version="1.0">
|
||||
<dict/>
|
||||
<dict>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.io.bluewallet.bluewallet</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
Loading…
Add table
Reference in a new issue