DEL: Widget center package

This commit is contained in:
Marcos Rodriguez Velez 2024-05-19 13:59:53 -04:00
parent 72439f36c1
commit d6982c92a5
No known key found for this signature in database
GPG key ID: 6030B2F48CCE86D7
16 changed files with 68 additions and 91 deletions

View file

@ -83,9 +83,3 @@ subprojects {
}
}
subprojects { subproject ->
if(project['name'] == 'react-native-widget-center') {
project.configurations { compile { } }
}
}

View file

@ -7,7 +7,6 @@ import Realm from 'realm';
import { LegacyWallet, SegwitBech32Wallet, SegwitP2SHWallet, TaprootWallet } from '../class';
import presentAlert from '../components/Alert';
import loc from '../loc';
import { reloadAllTimelines } from '../components/WidgetCommunication';
import RNFS from 'react-native-fs';
const ElectrumClient = require('electrum-client');
@ -212,8 +211,6 @@ export async function connectMain(): Promise<void> {
await DefaultPreference.set(ELECTRUM_TCP_PORT, usingPeer.tcp ?? '');
await DefaultPreference.set(ELECTRUM_SSL_PORT, usingPeer.ssl ?? '');
}
reloadAllTimelines();
} catch (e) {
// Must be running on Android
console.log(e);
@ -340,7 +337,6 @@ const presentNetworkErrorAlert = async (usingPeer?: Peer) => {
await DefaultPreference.clear(ELECTRUM_HOST);
await DefaultPreference.clear(ELECTRUM_SSL_PORT);
await DefaultPreference.clear(ELECTRUM_TCP_PORT);
reloadAllTimelines();
} catch (e) {
// Must be running on Android
console.log(e);

View file

@ -1,9 +0,0 @@
function WidgetCommunication() {
return null;
}
WidgetCommunication.isBalanceDisplayAllowed = () => {};
WidgetCommunication.setBalanceDisplayAllowed = () => {};
WidgetCommunication.reloadAllTimelines = () => {};
export default WidgetCommunication;

View file

@ -3,7 +3,6 @@ import DefaultPreference from 'react-native-default-preference';
import * as RNLocalize from 'react-native-localize';
import BigNumber from 'bignumber.js';
import { FiatUnit, FiatUnitType, getFiatRate } from '../models/fiatUnit';
import { reloadAllTimelines } from '../components/WidgetCommunication';
const PREFERRED_CURRENCY_STORAGE_KEY = 'preferredCurrency';
const PREFERRED_CURRENCY_LOCALE_STORAGE_KEY = 'preferredCurrencyLocale';
@ -32,8 +31,6 @@ async function setPreferredCurrency(item: FiatUnitType): Promise<void> {
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
await DefaultPreference.set(PREFERRED_CURRENCY_STORAGE_KEY, item.endPointKey);
await DefaultPreference.set(PREFERRED_CURRENCY_LOCALE_STORAGE_KEY, item.locale.replace('-', '_'));
// @ts-ignore: Convert to TSX later
reloadAllTimelines();
}
async function getPreferredCurrency(): Promise<FiatUnitType> {

View file

@ -1,7 +1,5 @@
import React, { useContext, useEffect } from 'react';
import DefaultPreference from 'react-native-default-preference';
// @ts-ignore: no type definitions
import RNWidgetCenter from 'react-native-widget-center';
import { BlueStorageContext } from '../blue_modules/storage-context';
import { TWallet } from '../class/wallets/types';
import { useSettings } from './Context/SettingsContext';
@ -13,10 +11,6 @@ enum WidgetCommunicationKeys {
LatestTransactionIsUnconfirmed = 'WidgetCommunicationLatestTransactionIsUnconfirmed',
}
export const reloadAllTimelines = (): void => {
RNWidgetCenter.reloadAllTimelines();
};
export const isBalanceDisplayAllowed = async (): Promise<boolean> => {
try {
await DefaultPreference.setName('group.io.bluewallet.bluewallet');
@ -34,7 +28,6 @@ export const setBalanceDisplayAllowed = async (value: boolean): Promise<void> =>
} else {
await DefaultPreference.clear(WidgetCommunicationKeys.DisplayBalanceAllowed);
}
reloadAllTimelines();
};
export const syncWidgetBalanceWithWallets = async (wallets: TWallet[], walletsInitialized: boolean): Promise<void> => {
@ -42,7 +35,6 @@ export const syncWidgetBalanceWithWallets = async (wallets: TWallet[], walletsIn
const { allWalletsBalance, latestTransactionTime } = await allWalletsBalanceAndTransactionTime(wallets, walletsInitialized);
await DefaultPreference.set(WidgetCommunicationKeys.AllWalletsSatoshiBalance, String(allWalletsBalance));
await DefaultPreference.set(WidgetCommunicationKeys.AllWalletsLatestTransactionTime, String(latestTransactionTime));
reloadAllTimelines();
};
const allWalletsBalanceAndTransactionTime = async (

View file

@ -7,8 +7,6 @@ export const isBalanceDisplayAllowed = async (): Promise<boolean> => {
export const setBalanceDisplayAllowed = async (value: boolean): Promise<void> => {};
export const reloadAllTimelines = (): void => {};
export const syncWidgetBalanceWithWallets = async (_wallets: TWallet[], _walletsInitialized: boolean): Promise<void> => {};
const WidgetCommunication: React.FC = () => {

View file

@ -2,4 +2,5 @@
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "AppDelegate.h"
#import <React/RCTBridgeModule.h>

View file

@ -153,9 +153,12 @@
B4A29A3D2B55C990002A67DF /* WidgetsExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 6DD4109C266CADF10087DE03 /* WidgetsExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
B4AB225D2B02AD12001F4328 /* XMLParserDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4AB225C2B02AD12001F4328 /* XMLParserDelegate.swift */; };
B4AB225E2B02AD12001F4328 /* XMLParserDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4AB225C2B02AD12001F4328 /* XMLParserDelegate.swift */; };
B4B1A4622BFA73110072E3BB /* WidgetHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4B1A4612BFA73110072E3BB /* WidgetHelper.swift */; };
B4B1A4642BFA73110072E3BB /* WidgetHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4B1A4612BFA73110072E3BB /* WidgetHelper.swift */; };
B4B1A4652BFA73110072E3BB /* WidgetHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4B1A4612BFA73110072E3BB /* WidgetHelper.swift */; };
B4EE583C226703320003363C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B40D4E35225841ED00428FCC /* Assets.xcassets */; };
C59F90CE0D04D3E4BB39BC5D /* libPods-BlueWalletUITests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6F02C2F7CA3591E4E0B06EBA /* libPods-BlueWalletUITests.a */; };
C978A716948AB7DEC5B6F677 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; };
C978A716948AB7DEC5B6F677 /* (null) in Frameworks */ = {isa = PBXBuildFile; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -444,6 +447,7 @@
B4A29A452B55C990002A67DF /* BlueWallet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BlueWallet.app; sourceTree = BUILT_PRODUCTS_DIR; };
B4A29A462B55C990002A67DF /* BlueWallet-NoLDK.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "BlueWallet-NoLDK.plist"; sourceTree = "<absolute>"; };
B4AB225C2B02AD12001F4328 /* XMLParserDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XMLParserDelegate.swift; sourceTree = "<group>"; };
B4B1A4612BFA73110072E3BB /* WidgetHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetHelper.swift; sourceTree = "<group>"; };
B4D3235A177F4580BA52F2F9 /* libRNCSlider.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNCSlider.a; sourceTree = "<group>"; };
B642AFB13483418CAB6FF25E /* libRCTQRCodeLocalImage.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRCTQRCodeLocalImage.a; sourceTree = "<group>"; };
B68F8552DD4428F64B11DCFB /* Pods-BlueWallet.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BlueWallet.debug.xcconfig"; path = "Target Support Files/Pods-BlueWallet/Pods-BlueWallet.debug.xcconfig"; sourceTree = "<group>"; };
@ -470,7 +474,7 @@
files = (
782F075B5DD048449E2DECE9 /* libz.tbd in Frameworks */,
764B49B1420D4AEB8109BF62 /* libsqlite3.0.tbd in Frameworks */,
C978A716948AB7DEC5B6F677 /* BuildFile in Frameworks */,
C978A716948AB7DEC5B6F677 /* (null) in Frameworks */,
773E382FE62E836172AAB98B /* libPods-BlueWallet.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -705,6 +709,7 @@
83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup;
children = (
B4B1A4612BFA73110072E3BB /* WidgetHelper.swift */,
B44033C82BCC34AC00162242 /* Shared */,
B41C2E552BB3DCB8000FE097 /* PrivacyInfo.xcprivacy */,
B4549F2E2B80FEA1002E3153 /* ci_scripts */,
@ -1110,7 +1115,7 @@
);
mainGroup = 83CBB9F61A601CBA00E9B192;
packageReferences = (
6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode.git" */,
6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode" */,
B41B76832B66B2FF002C48D5 /* XCRemoteSwiftPackageReference "bugsnag-cocoa" */,
);
productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */;
@ -1508,6 +1513,7 @@
B44034072BCC38A000162242 /* FiatUnit.swift in Sources */,
B44034002BCC37F800162242 /* Bundle+decode.swift in Sources */,
B44033E22BCC36CB00162242 /* Placeholders.swift in Sources */,
B4B1A4622BFA73110072E3BB /* WidgetHelper.swift in Sources */,
B44033DA2BCC369A00162242 /* Colors.swift in Sources */,
B44033D32BCC368800162242 /* UserDefaultsGroupKey.swift in Sources */,
32B5A32A2334450100F8D608 /* Bridge.swift in Sources */,
@ -1528,6 +1534,7 @@
B40FC3FA29CCD1D00007EBAC /* SwiftTCPClient.swift in Sources */,
6DD410A1266CADF10087DE03 /* Widgets.swift in Sources */,
6DD410AC266CAE470087DE03 /* PriceWidget.swift in Sources */,
B4B1A4642BFA73110072E3BB /* WidgetHelper.swift in Sources */,
B44033D52BCC368800162242 /* UserDefaultsGroupKey.swift in Sources */,
6DD410B2266CAF5C0087DE03 /* WalletInformationView.swift in Sources */,
B44034022BCC37F800162242 /* Bundle+decode.swift in Sources */,
@ -1624,6 +1631,7 @@
B44033C72BCC332400162242 /* Balance.swift in Sources */,
B44033FC2BCC379200162242 /* WidgetDataStore.swift in Sources */,
B44033C22BCC32F800162242 /* BitcoinUnit.swift in Sources */,
B4B1A4652BFA73110072E3BB /* WidgetHelper.swift in Sources */,
B44033F12BCC374500162242 /* Numeric+abbreviated.swift in Sources */,
B44034032BCC37F800162242 /* Bundle+decode.swift in Sources */,
B44033CD2BCC350A00162242 /* Currency.swift in Sources */,
@ -2619,7 +2627,7 @@
/* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */
6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode.git" */ = {
6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/EFPrefix/EFQRCode.git";
requirement = {
@ -2640,7 +2648,7 @@
/* Begin XCSwiftPackageProductDependency section */
6DFC806F24EA0B6C007B8700 /* EFQRCode */ = {
isa = XCSwiftPackageProductDependency;
package = 6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode.git" */;
package = 6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode" */;
productName = EFQRCode;
};
B41B76842B66B2FF002C48D5 /* Bugsnag */ = {

View file

@ -10,6 +10,8 @@
#import <React/RCTRootView.h>
#import <Bugsnag/Bugsnag.h>
#import "BlueWallet-Swift.h"
@interface AppDelegate() <UNUserNotificationCenterDelegate>
@property (nonatomic, strong) UIView *launchScreenView;
@ -51,6 +53,8 @@ NSUserDefaults *group = [[NSUserDefaults alloc] initWithSuiteName:@"group.io.blu
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[self setupUserDefaultsListener];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@ -69,6 +73,22 @@ NSUserDefaults *group = [[NSUserDefaults alloc] initWithSuiteName:@"group.io.blu
{
[self copyDeviceUID];
}
NSArray *keys = @[
@"WidgetCommunicationAllWalletsSatoshiBalance",
@"WidgetCommunicationAllWalletsLatestTransactionTime",
@"WidgetCommunicationDisplayBalanceAllowed",
@"WidgetCommunicationLatestTransactionIsUnconfirmed",
@"preferredCurrency",
@"preferredCurrencyLocale",
@"electrum_host",
@"electrum_tcp_port",
@"electrum_ssl_port"
];
if ([keys containsObject:keyPath]) {
[WidgetHelper reloadAllWidgets];
}
}
- (void)copyDeviceUID {
@ -86,6 +106,24 @@ NSUserDefaults *group = [[NSUserDefaults alloc] initWithSuiteName:@"group.io.blu
}
}
- (void)setupUserDefaultsListener {
NSString *appGroup = @"group.io.bluewallet.bluewallet";
NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:appGroup];
NSArray *keys = @[
@"WidgetCommunicationAllWalletsSatoshiBalance",
@"WidgetCommunicationAllWalletsLatestTransactionTime",
@"WidgetCommunicationDisplayBalanceAllowed",
@"WidgetCommunicationLatestTransactionIsUnconfirmed",
@"preferredCurrency",
@"preferredCurrencyLocale"
];
for (NSString *key in keys) {
[userDefaults addObserver:self forKeyPath:key options:NSKeyValueObservingOptionNew context:NULL];
}
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
@ -290,5 +328,4 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
}
}
@end

View file

@ -352,8 +352,6 @@ PODS:
- react-native-tcp-socket (6.0.6):
- CocoaAsyncSocket
- React-Core
- react-native-widget-center (0.0.9):
- React
- React-NativeModulesApple (0.72.14):
- hermes-engine
- React-callinvoker
@ -561,7 +559,6 @@ DEPENDENCIES:
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- react-native-secure-key-store (from `../node_modules/react-native-secure-key-store`)
- react-native-tcp-socket (from `../node_modules/react-native-tcp-socket`)
- react-native-widget-center (from `../node_modules/react-native-widget-center`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
- React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`)
@ -688,8 +685,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-secure-key-store"
react-native-tcp-socket:
:path: "../node_modules/react-native-tcp-socket"
react-native-widget-center:
:path: "../node_modules/react-native-widget-center"
React-NativeModulesApple:
:path: "../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios"
React-perflogger:
@ -817,7 +812,6 @@ SPEC CHECKSUMS:
react-native-safe-area-context: dcab599c527c2d7de2d76507a523d20a0b83823d
react-native-secure-key-store: 910e6df6bc33cb790aba6ee24bc7818df1fe5898
react-native-tcp-socket: e724380c910c2e704816ec817ed28f1342246ff7
react-native-widget-center: 12dfba20a4fa995850b52cf0afecf734397f4b9c
React-NativeModulesApple: 3107f777453f953906d9ba9dc5f8cbd91a6ef913
React-perflogger: daabc494c6328efc1784a4b49b8b74fca305d11c
React-RCTActionSheet: 0e0e64a7cf6c07f1de73d1f0a92d26a70262b256

11
ios/WidgetHelper.swift Normal file
View file

@ -0,0 +1,11 @@
import WidgetKit
@objc class WidgetHelper: NSObject {
@objc static func reloadAllWidgets() {
if #available(iOS 14.0, *) {
WidgetCenter.shared.reloadAllTimelines()
} else {
// Fallback on earlier versions
}
}
}

14
package-lock.json generated
View file

@ -97,7 +97,6 @@
"react-native-tcp-socket": "6.0.6",
"react-native-vector-icons": "10.1.0",
"react-native-watch-connectivity": "1.1.0",
"react-native-widget-center": "https://github.com/BlueWallet/react-native-widget-center#a128c38",
"readable-stream": "3.6.2",
"realm": "12.8.1",
"rn-ldk": "github:BlueWallet/rn-ldk#v0.8.4",
@ -19873,15 +19872,6 @@
"react-native": ">=0.40"
}
},
"node_modules/react-native-widget-center": {
"version": "0.0.9",
"resolved": "git+ssh://git@github.com/BlueWallet/react-native-widget-center.git#a128c389526d55afdd67937494f2fec224dd0009",
"license": "MIT",
"peerDependencies": {
"react": "^16.8.1",
"react-native": ">=0.60.0-rc.0 <1.0.x"
}
},
"node_modules/react-native/node_modules/@jest/types": {
"version": "26.6.2",
"resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz",
@ -37426,10 +37416,6 @@
"lodash.sortby": "^4.7.0"
}
},
"react-native-widget-center": {
"version": "git+ssh://git@github.com/BlueWallet/react-native-widget-center.git#a128c389526d55afdd67937494f2fec224dd0009",
"from": "react-native-widget-center@https://github.com/BlueWallet/react-native-widget-center#a128c38"
},
"react-refresh": {
"version": "0.4.3",
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.4.3.tgz",

View file

@ -56,7 +56,7 @@
"android:clean": "cd android; ./gradlew clean ; cd .. ; npm run android",
"ios": "react-native run-ios",
"postinstall": "rn-nodeify --install buffer,events,process,stream,inherits,path,assert,crypto --hack; npm run releasenotes2json; npm run branch2json; npm run patches",
"patches": "patch -p1 < scripts/rn-ldk.patch; patch -p1 < scripts/react-native-camera-kit.patch; patch -p1 < scripts/react-native-widget-center.patch",
"patches": "patch -p1 < scripts/rn-ldk.patch; patch -p1 < scripts/react-native-camera-kit.patch;",
"test": "npm run tslint && npm run lint && npm run unit && npm run jest",
"jest": "jest -b tests/integration/*",
"e2e:debug-build": "detox build -c android.debug",
@ -182,7 +182,6 @@
"react-native-tcp-socket": "6.0.6",
"react-native-vector-icons": "10.1.0",
"react-native-watch-connectivity": "1.1.0",
"react-native-widget-center": "https://github.com/BlueWallet/react-native-widget-center#a128c38",
"readable-stream": "3.6.2",
"realm": "12.8.1",
"rn-ldk": "github:BlueWallet/rn-ldk#v0.8.4",

View file

@ -28,7 +28,6 @@ import {
BlueDismissKeyboardInputAccessory,
} from '../../BlueComponents';
import { BlueCurrentTheme } from '../../components/themes';
import { reloadAllTimelines } from '../../components/WidgetCommunication';
import { BlueStorageContext } from '../../blue_modules/storage-context';
import presentAlert from '../../components/Alert';
import { scanQrHelper } from '../../helpers/scan-qr';
@ -170,7 +169,6 @@ export default class ElectrumSettings extends Component {
await DefaultPreference.clear(BlueElectrum.ELECTRUM_HOST);
await DefaultPreference.clear(BlueElectrum.ELECTRUM_SSL_PORT);
await DefaultPreference.clear(BlueElectrum.ELECTRUM_TCP_PORT);
reloadAllTimelines();
} catch (e) {
// Must be running on Android
console.log(e);
@ -199,7 +197,6 @@ export default class ElectrumSettings extends Component {
await DefaultPreference.set(BlueElectrum.ELECTRUM_HOST, host);
await DefaultPreference.set(BlueElectrum.ELECTRUM_TCP_PORT, port);
await DefaultPreference.set(BlueElectrum.ELECTRUM_SSL_PORT, sslPort);
reloadAllTimelines();
} catch (e) {
// Must be running on Android
console.log(e);

View file

@ -1,18 +0,0 @@
--- ../node_modules/react-native-widget-center/android/build.gradle 2023-11-10 11:25:36
+++ ../node_modules/react-native-widget-center/android/build.gradle 2023-11-10 11:25:42
@@ -103,12 +103,12 @@
}
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
- classifier = 'javadoc'
+ archiveClassifier.set('javadoc')
from androidJavadoc.destinationDir
}
task androidSourcesJar(type: Jar) {
- classifier = 'sources'
+ archiveClassifier.set('sources')
from android.sourceSets.main.java.srcDirs
include '**/*.java'
}

View file

@ -188,12 +188,6 @@ jest.mock('react-native-share', () => {
};
});
jest.mock('../components/WidgetCommunication', () => {
return {
reloadAllTimelines: jest.fn(),
};
});
const mockKeychain = {
SECURITY_LEVEL_ANY: 'MOCK_SECURITY_LEVEL_ANY',
SECURITY_LEVEL_SECURE_SOFTWARE: 'MOCK_SECURITY_LEVEL_SECURE_SOFTWARE',