Merge branch 'master' into renovate/react-native-svg-15.x

This commit is contained in:
Marcos Rodriguez Vélez 2024-11-15 21:33:57 -04:00 committed by GitHub
commit 5b4c364696
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 196 additions and 215 deletions

View File

@ -12,7 +12,6 @@ const BlueApp = BlueAppClass.getInstance();
*/
let userHasOptedOut: boolean = false;
if (process.env.NODE_ENV !== 'development') {
(async () => {
const uniqueID = await getUniqueId();
const doNotTrack = await BlueApp.isDoNotTrackEnabled();
@ -31,7 +30,6 @@ if (process.env.NODE_ENV !== 'development') {
},
});
})();
}
const A = async (event: string) => {};

View File

@ -1,7 +1,7 @@
import 'react-native-gesture-handler'; // should be on top
import { CommonActions } from '@react-navigation/native';
import React, { lazy, Suspense, useCallback, useEffect, useRef } from 'react';
import { useCallback, useEffect, useRef } from 'react';
import { AppState, AppStateStatus, Linking } from 'react-native';
import A from '../blue_modules/analytics';
import { getClipboardContent } from '../blue_modules/clipboard';
@ -25,12 +25,10 @@ import { useStorage } from '../hooks/context/useStorage';
import RNQRGenerator from 'rn-qr-generator';
import presentAlert from './Alert';
import useMenuElements from '../hooks/useMenuElements';
import { useSettings } from '../hooks/context/useSettings';
import useWidgetCommunication from '../hooks/useWidgetCommunication';
import useWatchConnectivity from '../hooks/useWatchConnectivity';
const DeviceQuickActions = lazy(() => import('../components/DeviceQuickActions'));
const HandOffComponentListener = lazy(() => import('../components/HandOffComponentListener'));
import useDeviceQuickActions from '../hooks/useDeviceQuickActions';
import useHandoffListener from '../hooks/useHandoffListener';
const ClipboardContentType = Object.freeze({
BITCOIN: 'BITCOIN',
@ -40,12 +38,13 @@ const ClipboardContentType = Object.freeze({
const CompanionDelegates = () => {
const { wallets, addWallet, saveToDisk, fetchAndSaveWalletTransactions, refreshAllWalletTransactions, setSharedCosigner } = useStorage();
const appState = useRef<AppStateStatus>(AppState.currentState);
const { isHandOffUseEnabled, isQuickActionsEnabled } = useSettings();
const clipboardContent = useRef<undefined | string>();
useWatchConnectivity();
useWidgetCommunication();
useMenuElements();
useDeviceQuickActions();
useHandoffListener();
const processPushNotifications = useCallback(async () => {
await new Promise(resolve => setTimeout(resolve, 200));
@ -311,12 +310,7 @@ const CompanionDelegates = () => {
};
}, [addListeners]);
return (
<Suspense fallback={null}>
{isQuickActionsEnabled && <DeviceQuickActions />}
{isHandOffUseEnabled && <HandOffComponentListener />}
</Suspense>
);
return null;
};
export default CompanionDelegates;

View File

@ -6,7 +6,10 @@ import { clearUseURv1, isURv1Enabled, setUseURv1 } from '../../blue_modules/ur';
import { BlueApp } from '../../class';
import { saveLanguage, STORAGE_KEY } from '../../loc';
import { FiatUnit, TFiatUnit } from '../../models/fiatUnit';
import { getEnabled as getIsDeviceQuickActionsEnabled, setEnabled as setIsDeviceQuickActionsEnabled } from '../DeviceQuickActions';
import {
getEnabled as getIsDeviceQuickActionsEnabled,
setEnabled as setIsDeviceQuickActionsEnabled,
} from '../../hooks/useDeviceQuickActions';
import { getIsHandOffUseEnabled, setIsHandOffUseEnabled } from '../HandOffComponent';
import { useStorage } from '../../hooks/context/useStorage';
import { BitcoinUnit } from '../../models/bitcoinUnits';

View File

@ -1,21 +0,0 @@
import React from 'react';
export const DeviceQuickActionsStorageKey = 'DeviceQuickActionsEnabled';
interface DeviceQuickActionsFunctions {
popInitialAction: () => void;
}
export const setEnabled = (): void => {};
export const getEnabled = async (): Promise<boolean> => {
return false;
};
const DeviceQuickActions: React.FC & DeviceQuickActionsFunctions = () => {
return null;
};
DeviceQuickActions.popInitialAction = (): void => {};
export default DeviceQuickActions;

View File

@ -1,6 +1,6 @@
import React from 'react';
import DefaultPreference from 'react-native-default-preference';
// @ts-ignore: react-native-handoff is not in the type definition
// @ts-ignore: Handoff is not typed
import Handoff from 'react-native-handoff';
import { useSettings } from '../hooks/context/useSettings';
import { GROUP_IO_BLUEWALLET } from '../blue_modules/currency';
@ -9,32 +9,32 @@ import { HandOffComponentProps } from './types';
const HandOffComponent: React.FC<HandOffComponentProps> = props => {
const { isHandOffUseEnabled } = useSettings();
if (process.env.NODE_ENV === 'development') {
console.debug('HandOffComponent: render');
}
if (isHandOffUseEnabled) {
return <Handoff {...props} />;
}
return null;
console.debug('HandOffComponent is rendering.');
return isHandOffUseEnabled ? <Handoff {...props} /> : null;
};
const MemoizedHandOffComponent = React.memo(HandOffComponent);
export const setIsHandOffUseEnabled = async (value: boolean) => {
try {
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
await DefaultPreference.set(BlueApp.HANDOFF_STORAGE_KEY, value.toString());
console.debug('setIsHandOffUseEnabledAsyncStorage', value);
console.debug('setIsHandOffUseEnabled', value);
} catch (error) {
console.error('Error setting handoff enabled status:', error);
throw error; // Propagate error to caller
}
};
export const getIsHandOffUseEnabled = async (): Promise<boolean> => {
try {
await DefaultPreference.setName(GROUP_IO_BLUEWALLET);
const isEnabledValue = (await DefaultPreference.get(BlueApp.HANDOFF_STORAGE_KEY)) ?? false;
console.debug('getIsHandOffUseEnabled', isEnabledValue);
return isEnabledValue === 'true';
} catch (e) {
console.debug('getIsHandOffUseEnabled error', e);
const isEnabledValue = await DefaultPreference.get(BlueApp.HANDOFF_STORAGE_KEY);
const result = isEnabledValue === 'true';
console.debug('getIsHandOffUseEnabled', result);
return result;
} catch (error) {
console.error('Error getting handoff enabled status:', error);
return false;
}
};

View File

@ -1,73 +0,0 @@
import React, { useEffect, useCallback } from 'react';
import { NativeEventEmitter, NativeModules } from 'react-native';
import { useStorage } from '../hooks/context/useStorage';
import { useExtendedNavigation } from '../hooks/useExtendedNavigation';
import { HandOffActivityType } from './types';
interface UserActivityData {
activityType: HandOffActivityType;
userInfo: {
address?: string;
xpub?: string;
};
}
const { EventEmitter } = NativeModules;
const eventEmitter = new NativeEventEmitter(EventEmitter);
const HandOffComponentListener: React.FC = React.memo(() => {
const { walletsInitialized } = useStorage();
const { navigate } = useExtendedNavigation();
const onUserActivityOpen = useCallback((data: UserActivityData) => {
switch (data.activityType) {
case HandOffActivityType.ReceiveOnchain:
navigate('ReceiveDetailsRoot', {
screen: 'ReceiveDetails',
params: {
address: data.userInfo.address,
},
});
break;
case HandOffActivityType.Xpub:
navigate('WalletXpubRoot', {
screen: 'WalletXpub',
params: {
xpub: data.userInfo.xpub,
},
});
break;
default:
console.log(`Unhandled activity type: ${data.activityType}`);
break;
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => {
if (!walletsInitialized) {
return;
}
const addListeners = () => {
const activitySubscription = eventEmitter.addListener('onUserActivityOpen', onUserActivityOpen);
// Attempt to fetch the most recent user activity
EventEmitter.getMostRecentUserActivity?.()
.then(onUserActivityOpen)
.catch(() => console.log('No userActivity object sent'));
return { activitySubscription };
};
const subscriptions = addListeners();
return () => {
subscriptions.activitySubscription?.remove();
};
}, [walletsInitialized, onUserActivityOpen]);
return null;
});
export default HandOffComponentListener;

View File

@ -1,7 +0,0 @@
import React from 'react';
const HandOffComponentListener: React.FC = () => {
return null;
};
export default HandOffComponentListener;

View File

@ -1,8 +1,8 @@
import { useEffect } from 'react';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { CommonActions } from '@react-navigation/native';
import { useEffect } from 'react';
import { DeviceEventEmitter, Linking, Platform } from 'react-native';
import QuickActions from 'react-native-quick-actions';
import QuickActions, { ShortcutItem } from 'react-native-quick-actions';
import DeeplinkSchemaMatch from '../class/deeplink-schema-match';
import { TWallet } from '../class/wallets/types';
import useOnAppLaunch from '../hooks/useOnAppLaunch';
@ -30,16 +30,15 @@ export async function getEnabled(): Promise<boolean> {
}
}
function DeviceQuickActions() {
const useDeviceQuickActions = () => {
const { wallets, walletsInitialized, isStorageEncrypted, addWallet, saveToDisk, setSharedCosigner } = useStorage();
const { preferredFiatCurrency, isQuickActionsEnabled } = useSettings();
const { isViewAllWalletsEnabled, getSelectedDefaultWallet } = useOnAppLaunch();
useEffect(() => {
if (walletsInitialized) {
isStorageEncrypted()
.then((value: boolean | undefined | null) => {
.then(value => {
if (value) {
removeShortcuts();
} else {
@ -78,7 +77,7 @@ function DeviceQuickActions() {
const popInitialAction = async (data: any): Promise<void> => {
if (data) {
const wallet = wallets.find((w: { getID: () => any }) => w.getID() === data.userInfo.url.split('wallet/')[1]);
const wallet = wallets.find(w => w.getID() === data.userInfo.url.split('wallet/')[1]);
if (wallet) {
NavigationService.dispatch(
CommonActions.navigate({
@ -126,7 +125,7 @@ function DeviceQuickActions() {
};
const walletQuickActions = (data: any): void => {
const wallet = wallets.find((w: { getID: () => any }) => w.getID() === data.userInfo.url.split('wallet/')[1]);
const wallet = wallets.find(w => w.getID() === data.userInfo.url.split('wallet/')[1]);
if (wallet) {
NavigationService.dispatch(
CommonActions.navigate({
@ -153,22 +152,21 @@ function DeviceQuickActions() {
if (await getEnabled()) {
QuickActions.isSupported((error: null, _supported: any) => {
if (error === null) {
const shortcutItems = [];
for (const wallet of wallets.slice(0, 4)) {
shortcutItems.push({
type: 'Wallets', // Required
title: wallet.getLabel(), // Optional, if empty, `type` will be used instead
const shortcutItems: ShortcutItem[] = wallets.slice(0, 4).map((wallet, index) => ({
type: 'Wallets',
title: wallet.getLabel(),
subtitle:
wallet.hideBalance || wallet.getBalance() <= 0
? ''
: formatBalance(Number(wallet.getBalance()), wallet.getPreferredBalanceUnit(), true),
userInfo: {
url: `bluewallet://wallet/${wallet.getID()}`, // Provide any custom data like deep linking URL
url: `bluewallet://wallet/${wallet.getID()}`,
},
icon: Platform.select({ android: 'quickactions', ios: 'bookmark' }),
});
}
// @ts-ignore: Fix later
icon: Platform.select({
android: 'quickactions',
ios: index === 0 ? 'Favorite' : 'Bookmark',
}) || 'quickactions',
}));
QuickActions.setShortcutItems(shortcutItems);
}
});
@ -177,7 +175,7 @@ function DeviceQuickActions() {
}
};
return null;
return { popInitialAction };
}
export default DeviceQuickActions;
export default useDeviceQuickActions;

View File

@ -0,0 +1,17 @@
export const DeviceQuickActionsStorageKey = 'DeviceQuickActionsEnabled';
export const setEnabled = (): void => {};
export const getEnabled = async (): Promise<boolean> => {
return false;
};
const useDeviceQuickActions = () => {
const popInitialAction = (): void => {};
return { popInitialAction };
};
export default useDeviceQuickActions;

View File

@ -0,0 +1,63 @@
import { useEffect, useCallback } from 'react';
import { NativeEventEmitter, NativeModules } from 'react-native';
import { useStorage } from '../hooks/context/useStorage';
import { useExtendedNavigation } from '../hooks/useExtendedNavigation';
import { HandOffActivityType } from '../components/types';
import { useSettings } from './context/useSettings';
interface UserActivityData {
activityType: HandOffActivityType;
userInfo: {
address?: string;
xpub?: string;
};
}
const EventEmitter = NativeModules.EventEmitter;
const eventEmitter = EventEmitter ? new NativeEventEmitter(EventEmitter) : null;
const useHandoffListener = () => {
const { walletsInitialized } = useStorage();
const { isHandOffUseEnabled } = useSettings();
const { navigate } = useExtendedNavigation();
const handleUserActivity = useCallback(
(data: UserActivityData) => {
const { activityType, userInfo } = data;
try {
if (activityType === HandOffActivityType.ReceiveOnchain) {
navigate('ReceiveDetailsRoot', {
screen: 'ReceiveDetails',
params: { address: userInfo.address },
});
} else if (activityType === HandOffActivityType.Xpub) {
navigate('WalletXpubRoot', {
screen: 'WalletXpub',
params: { xpub: userInfo.xpub },
});
} else {
console.debug(`Unhandled activity type: ${activityType}`);
}
} catch (error) {
console.error('Error handling user activity:', error);
}
},
[navigate],
);
useEffect(() => {
if (!walletsInitialized || !isHandOffUseEnabled) return;
const activitySubscription = eventEmitter?.addListener('onUserActivityOpen', handleUserActivity);
EventEmitter.getMostRecentUserActivity?.()
.then(handleUserActivity)
.catch(() => console.debug('No userActivity object sent'));
return () => {
activitySubscription?.remove();
};
}, [walletsInitialized, isHandOffUseEnabled, handleUserActivity]);
};
export default useHandoffListener;

View File

@ -0,0 +1,3 @@
const useHandoffListener = () => {};
export default useHandoffListener;

24
package-lock.json generated
View File

@ -17,7 +17,7 @@
"@lodev09/react-native-true-sheet": "github:BlueWallet/react-native-true-sheet#839f2966cee77c0ad99d09609dadb61a338e7f54",
"@ngraveio/bc-ur": "1.1.13",
"@noble/secp256k1": "1.6.3",
"@react-native-async-storage/async-storage": "2.0.0",
"@react-native-async-storage/async-storage": "2.1.0",
"@react-native-clipboard/clipboard": "1.15.0",
"@react-native-community/push-notification-ios": "1.11.0",
"@react-native-menu/menu": "https://github.com/BlueWallet/menu.git#02592ae",
@ -46,7 +46,7 @@
"coinselect": "3.1.13",
"crypto-js": "4.2.0",
"dayjs": "1.11.13",
"detox": "20.27.6",
"detox": "20.28.0",
"ecpair": "2.0.1",
"ecurve": "1.0.6",
"electrum-client": "github:BlueWallet/rn-electrum-client#1bfe3cc",
@ -4507,9 +4507,9 @@
}
},
"node_modules/@react-native-async-storage/async-storage": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-2.0.0.tgz",
"integrity": "sha512-af6H9JjfL6G/PktBfUivvexoiFKQTJGQCtSWxMdivLzNIY94mu9DdiY0JqCSg/LyPCLGKhHPUlRQhNvpu3/KVA==",
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-2.1.0.tgz",
"integrity": "sha512-eAGQGPTAuFNEoIQSB5j2Jh1zm5NPyBRTfjRMfCN0W1OakC5WIB5vsDyIQhUweKN9XOE2/V07lqTMGsL0dGXNkA==",
"license": "MIT",
"dependencies": {
"merge-options": "^3.0.4"
@ -9731,9 +9731,9 @@
}
},
"node_modules/detox": {
"version": "20.27.6",
"resolved": "https://registry.npmjs.org/detox/-/detox-20.27.6.tgz",
"integrity": "sha512-eyVkBC7uFpxgUAuWjvbejwnPOjRHqUWSSE/P0FwsCxWVnrNOSq8IhBnSj82Ic5Dc76CAB+Xw5SWYsHnbhG26Bg==",
"version": "20.28.0",
"resolved": "https://registry.npmjs.org/detox/-/detox-20.28.0.tgz",
"integrity": "sha512-JeUkWNnYE7lqby3S9AeYJP3ttCBKH+qZWACjWXwvSbe3tm6JeXvecVUYkzSoNfC4IzTX5p+rWvG0IPsfOsZSFw==",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
@ -9743,7 +9743,7 @@
"caf": "^15.0.1",
"chalk": "^4.0.0",
"child-process-promise": "^2.2.0",
"detox-copilot": "^0.0.23",
"detox-copilot": "^0.0.24",
"execa": "^5.1.1",
"find-up": "^5.0.0",
"fs-extra": "^11.0.0",
@ -9790,9 +9790,9 @@
}
},
"node_modules/detox-copilot": {
"version": "0.0.23",
"resolved": "https://registry.npmjs.org/detox-copilot/-/detox-copilot-0.0.23.tgz",
"integrity": "sha512-qDSdLwgPUMVawpE0R3agNWd2U69ilTnhf+SodSqqrkmTI0oG67IfkACvwox+K9Slcc8ki6y0Bw6QVBi54MqpaA==",
"version": "0.0.24",
"resolved": "https://registry.npmjs.org/detox-copilot/-/detox-copilot-0.0.24.tgz",
"integrity": "sha512-42g0QyJS31URl28YRxc4hGozSXhbbB1sKwzxEjZR9WtLoSx6WYDsQkQD8+yP5t1NExiSCZAfvNmBw8PYQwDKwg==",
"license": "MIT"
},
"node_modules/detox/node_modules/ansi-styles": {

View File

@ -81,7 +81,7 @@
"@lodev09/react-native-true-sheet": "github:BlueWallet/react-native-true-sheet#839f2966cee77c0ad99d09609dadb61a338e7f54",
"@ngraveio/bc-ur": "1.1.13",
"@noble/secp256k1": "1.6.3",
"@react-native-async-storage/async-storage": "2.0.0",
"@react-native-async-storage/async-storage": "2.1.0",
"@react-native-clipboard/clipboard": "1.15.0",
"@react-native-community/push-notification-ios": "1.11.0",
"@react-native-menu/menu": "https://github.com/BlueWallet/menu.git#02592ae",
@ -110,7 +110,7 @@
"coinselect": "3.1.13",
"crypto-js": "4.2.0",
"dayjs": "1.11.13",
"detox": "20.27.6",
"detox": "20.28.0",
"ecpair": "2.0.1",
"ecurve": "1.0.6",
"electrum-client": "github:BlueWallet/rn-electrum-client#1bfe3cc",

View File

@ -207,8 +207,6 @@ const About: React.FC = () => {
<BlueTextCentered>
w, h = {width}, {height}
</BlueTextCentered>
{process.env.NODE_ENV !== 'development' && (
<>
<BlueTextCentered>Unique ID: {getUniqueIdSync()}</BlueTextCentered>
<View style={styles.copyToClipboard}>
<TouchableOpacity
@ -222,8 +220,6 @@ const About: React.FC = () => {
<Text style={styles.copyToClipboardText}>{loc.transactions.details_copy}</Text>
</TouchableOpacity>
</View>
</>
)}
<BlueSpacing20 />
<BlueSpacing20 />
</ScrollView>

View File

@ -13,7 +13,7 @@ import { AddWalletStackParamList } from '../../navigation/AddWalletStack';
type NavigationProp = NativeStackNavigationProp<AddWalletStackParamList, 'ImportSpeed'>;
const WalletsImportWallet = () => {
const ImportSpeed = () => {
const navigation = useNavigation<NavigationProp>();
const { colors } = useTheme();
const [loading, setLoading] = useState<boolean>(false);
@ -102,4 +102,4 @@ const WalletsImportWallet = () => {
);
};
export default WalletsImportWallet;
export default ImportSpeed;

View File

@ -197,7 +197,7 @@ const ImportWalletDiscovery: React.FC = () => {
) : (
<>
<BlueText style={styles.center}>{loc.wallets.import_discovery_no_wallets}</BlueText>
<BlueSpacing20 />{' '}
<BlueSpacing20 />
</>
)}
</View>

View File

@ -44,6 +44,8 @@ import assert from 'assert';
import useMenuElements from '../../hooks/useMenuElements';
import { useSettings } from '../../hooks/context/useSettings';
import { getClipboardContent } from '../../blue_modules/clipboard';
import HandOffComponent from '../../components/HandOffComponent';
import { HandOffActivityType } from '../../components/types';
const buttonFontSize =
PixelRatio.roundToNearestPixel(Dimensions.get('window').width / 26) > 22
@ -496,6 +498,13 @@ const WalletTransactions: React.FC<WalletTransactionsProps> = ({ route }) => {
/>
)}
</FContainer>
{wallet?.chain === Chain.ONCHAIN && wallet.type !== MultisigHDWallet.type && wallet.getXpub && wallet.getXpub() ? (
<HandOffComponent
title={wallet.getLabel()}
type={HandOffActivityType.Xpub}
url={`https://www.blockonomics.co/#/search?q=${wallet.getXpub()}`}
/>
) : null}
</View>
);
};

View File

@ -698,13 +698,14 @@ describe('BlueWallet UI Tests - no wallets', () => {
await element(by.id('DoImport')).tap();
await sleep(1000);
await element(by.text('OK')).tap();
await waitFor(element(by.id('Loading'))) // wait for discovery to be completed
.not.toExist()
.withTimeout(300 * 1000);
// wait for discovery to be completed
await waitFor(element(by.text("m/84'/0'/0'")))
.toBeVisible()
.withTimeout(300 * 1000);
await expect(element(by.text("m/44'/0'/1'"))).toBeVisible();
await expect(element(by.text("m/49'/0'/0'"))).toBeVisible();
await expect(element(by.text("m/84'/0'/0'"))).toBeVisible();
await expect(element(by.id('Loading'))).not.toBeVisible();
// open custom derivation path screen and import the wallet
await element(by.id('CustomDerivationPathButton')).tap();