mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-22 15:04:50 +01:00
REF: Start not using merge for navigations params
This commit is contained in:
parent
dcf178453d
commit
7b4dc84822
4 changed files with 68 additions and 27 deletions
|
@ -9,21 +9,33 @@ import { navigationRef } from '../NavigationService';
|
|||
* @param showFileImportButton {boolean}
|
||||
*
|
||||
* @param onDismiss {function} - if camera is closed via X button it gets triggered
|
||||
* @param useMerge {boolean} - if true, will merge the new screen with the current screen, otherwise will replace the current screen
|
||||
* @return {Promise<string>}
|
||||
*/
|
||||
function scanQrHelper(currentScreenName: string, showFileImportButton = true, onDismiss?: () => void): Promise<string | null> {
|
||||
function scanQrHelper(
|
||||
currentScreenName: string,
|
||||
showFileImportButton = true,
|
||||
onDismiss?: () => void,
|
||||
useMerge = true,
|
||||
): Promise<string | null> {
|
||||
return requestCameraAuthorization().then(() => {
|
||||
return new Promise(resolve => {
|
||||
const params = {
|
||||
showFileImportButton: Boolean(showFileImportButton),
|
||||
onBarScanned: (data: any) => {},
|
||||
onDismiss,
|
||||
};
|
||||
let params = {};
|
||||
|
||||
params.onBarScanned = function (data: any) {
|
||||
setTimeout(() => resolve(data.data || data), 1);
|
||||
navigationRef.navigate({ name: currentScreenName, params: {}, merge: true });
|
||||
};
|
||||
if (useMerge) {
|
||||
const onBarScanned = function (data: any) {
|
||||
setTimeout(() => resolve(data.data || data), 1);
|
||||
navigationRef.navigate({ name: currentScreenName, params: {}, merge: true });
|
||||
};
|
||||
|
||||
params = {
|
||||
showFileImportButton: Boolean(showFileImportButton),
|
||||
onDismiss,
|
||||
onBarScanned,
|
||||
};
|
||||
} else {
|
||||
params = { launchedBy: currentScreenName, showFileImportButton: Boolean(showFileImportButton) };
|
||||
}
|
||||
|
||||
navigationRef.navigate('ScanQRCodeRoot', {
|
||||
screen: 'ScanQRCode',
|
||||
|
|
|
@ -3,7 +3,7 @@ import { SendDetailsParams } from './SendDetailsStackParamList';
|
|||
|
||||
export type DetailViewStackParamList = {
|
||||
UnlockWithScreen: undefined;
|
||||
WalletsList: undefined;
|
||||
WalletsList: { scannedData?: string };
|
||||
WalletTransactions: { walletID: string; walletType: string };
|
||||
LDKOpenChannelRoot: undefined;
|
||||
LdkInfo: undefined;
|
||||
|
|
|
@ -127,9 +127,13 @@ const ScanQRCode = () => {
|
|||
const data = decoder.toString();
|
||||
decoder = false; // nullify for future use (?)
|
||||
if (launchedBy) {
|
||||
navigation.navigate({ name: launchedBy, params: {}, merge: true });
|
||||
let merge = true;
|
||||
if (typeof onBarScanned !== 'function') {
|
||||
merge = false;
|
||||
}
|
||||
navigation.navigate({ name: launchedBy, params: { scannedData: data }, merge });
|
||||
}
|
||||
onBarScanned({ data });
|
||||
onBarScanned && onBarScanned({ data });
|
||||
} else {
|
||||
setUrTotal(100);
|
||||
setUrHave(Math.floor(decoder.estimatedPercentComplete() * 100));
|
||||
|
@ -176,9 +180,13 @@ const ScanQRCode = () => {
|
|||
data = Buffer.from(payload, 'hex').toString();
|
||||
}
|
||||
if (launchedBy) {
|
||||
navigation.navigate({ name: launchedBy, params: {}, merge: true });
|
||||
let merge = true;
|
||||
if (typeof onBarScanned !== 'function') {
|
||||
merge = false;
|
||||
}
|
||||
navigation.navigate({ name: launchedBy, params: { scannedData: data }, merge });
|
||||
}
|
||||
onBarScanned({ data });
|
||||
onBarScanned && onBarScanned({ data });
|
||||
} else {
|
||||
setAnimatedQRCodeData(animatedQRCodeData);
|
||||
}
|
||||
|
@ -237,11 +245,15 @@ const ScanQRCode = () => {
|
|||
try {
|
||||
const hex = Base43.decode(ret.data);
|
||||
bitcoin.Psbt.fromHex(hex); // if it doesnt throw - all good
|
||||
|
||||
const data = Buffer.from(hex, 'hex').toString('base64');
|
||||
if (launchedBy) {
|
||||
navigation.navigate({ name: launchedBy, params: {}, merge: true });
|
||||
let merge = true;
|
||||
if (typeof onBarScanned !== 'function') {
|
||||
merge = false;
|
||||
}
|
||||
navigation.navigate({ name: launchedBy, params: { scannedData: data }, merge });
|
||||
}
|
||||
onBarScanned({ data: Buffer.from(hex, 'hex').toString('base64') });
|
||||
onBarScanned && onBarScanned({ data });
|
||||
return;
|
||||
} catch (_) {}
|
||||
|
||||
|
@ -249,9 +261,13 @@ const ScanQRCode = () => {
|
|||
setIsLoading(true);
|
||||
try {
|
||||
if (launchedBy) {
|
||||
navigation.navigate({ name: launchedBy, params: {}, merge: true });
|
||||
let merge = true;
|
||||
if (typeof onBarScanned !== 'function') {
|
||||
merge = false;
|
||||
}
|
||||
navigation.navigate({ name: launchedBy, params: { scannedData: ret.data }, merge });
|
||||
}
|
||||
onBarScanned(ret.data);
|
||||
onBarScanned && onBarScanned(ret.data);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
@ -304,7 +320,11 @@ const ScanQRCode = () => {
|
|||
|
||||
const dismiss = () => {
|
||||
if (launchedBy) {
|
||||
navigation.navigate({ name: launchedBy, params: {}, merge: true });
|
||||
let merge = true;
|
||||
if (typeof onBarScanned !== 'function') {
|
||||
merge = false;
|
||||
}
|
||||
navigation.navigate({ name: launchedBy, params: {}, merge });
|
||||
} else {
|
||||
navigation.goBack();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React, { useCallback, useEffect, useReducer, useRef } from 'react';
|
||||
import { useFocusEffect, useIsFocused, useRoute } from '@react-navigation/native';
|
||||
import { useFocusEffect, useIsFocused, useRoute, RouteProp } from '@react-navigation/native';
|
||||
import { findNodeHandle, Image, InteractionManager, SectionList, StyleSheet, Text, useWindowDimensions, View } from 'react-native';
|
||||
import A from '../../blue_modules/analytics';
|
||||
import BlueClipboard from '../../blue_modules/clipboard';
|
||||
|
@ -88,6 +88,7 @@ function reducer(state: WalletListState, action: WalletListAction) {
|
|||
}
|
||||
|
||||
type NavigationProps = NativeStackNavigationProp<DetailViewStackParamList, 'WalletsList'>;
|
||||
type RouteProps = RouteProp<DetailViewStackParamList, 'WalletsList'>;
|
||||
|
||||
const WalletsList: React.FC = () => {
|
||||
const [state, dispatch] = useReducer<React.Reducer<WalletListState, WalletListAction>>(reducer, initialState);
|
||||
|
@ -108,7 +109,8 @@ const WalletsList: React.FC = () => {
|
|||
const { colors, scanImage } = useTheme();
|
||||
const { navigate } = useExtendedNavigation<NavigationProps>();
|
||||
const isFocused = useIsFocused();
|
||||
const routeName = useRoute().name;
|
||||
const route = useRoute<RouteProps>();
|
||||
const routeName = route.name;
|
||||
const dataSource = getTransactions(undefined, 10);
|
||||
const walletsCount = useRef<number>(wallets.length);
|
||||
const walletActionButtonsRef = useRef<any>();
|
||||
|
@ -149,6 +151,14 @@ const WalletsList: React.FC = () => {
|
|||
walletsCount.current = wallets.length;
|
||||
}, [wallets]);
|
||||
|
||||
useEffect(() => {
|
||||
const scannedData = route.params?.scannedData;
|
||||
if (scannedData) {
|
||||
onBarScanned(scannedData);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [route.params?.scannedData]);
|
||||
|
||||
const verifyBalance = useCallback(() => {
|
||||
if (getBalance() !== 0) {
|
||||
A(A.ENUM.GOT_NONZERO_BALANCE);
|
||||
|
@ -332,9 +342,8 @@ const WalletsList: React.FC = () => {
|
|||
};
|
||||
|
||||
const onScanButtonPressed = useCallback(() => {
|
||||
scanQrHelper(routeName).then(onBarScanned);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
scanQrHelper(routeName, true, undefined, false);
|
||||
}, [routeName]);
|
||||
|
||||
const onBarScanned = useCallback(
|
||||
(value: any) => {
|
||||
|
@ -381,7 +390,7 @@ const WalletsList: React.FC = () => {
|
|||
});
|
||||
break;
|
||||
case 2:
|
||||
scanQrHelper(routeName, true).then(data => onBarScanned(data));
|
||||
scanQrHelper(routeName, true, undefined, false);
|
||||
break;
|
||||
case 3:
|
||||
if (!isClipboardEmpty) {
|
||||
|
|
Loading…
Add table
Reference in a new issue