mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-13 19:16:52 +01:00
wip
This commit is contained in:
parent
0b33af59f0
commit
4ff759b538
2 changed files with 138 additions and 137 deletions
|
@ -1,4 +1,4 @@
|
|||
import React, { useCallback, useMemo, forwardRef } from 'react';
|
||||
import React, { useCallback, useMemo } from 'react';
|
||||
import { Image, Keyboard, Platform, StyleSheet, Text } from 'react-native';
|
||||
import Clipboard from '@react-native-clipboard/clipboard';
|
||||
import ToolTipMenu from './TooltipMenu';
|
||||
|
@ -20,147 +20,150 @@ interface AddressInputScanButtonProps {
|
|||
beforePress?: () => Promise<void> | void;
|
||||
}
|
||||
|
||||
export const AddressInputScanButton = forwardRef<any, AddressInputScanButtonProps>(
|
||||
({ isLoading, onChangeText, type = 'default', testID = 'BlueAddressInputScanQrButton', beforePress }, ref) => {
|
||||
const { colors } = useTheme();
|
||||
const { isClipboardGetContentEnabled } = useSettings();
|
||||
export const AddressInputScanButton = ({
|
||||
isLoading,
|
||||
onChangeText,
|
||||
type = 'default',
|
||||
testID = 'BlueAddressInputScanQrButton',
|
||||
beforePress,
|
||||
}: AddressInputScanButtonProps) => {
|
||||
const { colors } = useTheme();
|
||||
const { isClipboardGetContentEnabled } = useSettings();
|
||||
|
||||
const navigation = useExtendedNavigation();
|
||||
const stylesHook = StyleSheet.create({
|
||||
scan: {
|
||||
backgroundColor: colors.scanLabel,
|
||||
},
|
||||
scanText: {
|
||||
color: colors.inverseForegroundColor,
|
||||
},
|
||||
const navigation = useExtendedNavigation();
|
||||
const stylesHook = StyleSheet.create({
|
||||
scan: {
|
||||
backgroundColor: colors.scanLabel,
|
||||
},
|
||||
scanText: {
|
||||
color: colors.inverseForegroundColor,
|
||||
},
|
||||
});
|
||||
|
||||
const toolTipOnPress = useCallback(async () => {
|
||||
if (beforePress) {
|
||||
await beforePress();
|
||||
}
|
||||
Keyboard.dismiss();
|
||||
navigation.navigate('ScanQRCode', {
|
||||
showFileImportButton: true,
|
||||
});
|
||||
}, [navigation, beforePress]);
|
||||
|
||||
const toolTipOnPress = useCallback(async () => {
|
||||
if (beforePress) {
|
||||
await beforePress();
|
||||
const actions = useMemo(() => {
|
||||
const availableActions = [
|
||||
CommonToolTipActions.ChoosePhoto,
|
||||
CommonToolTipActions.ImportFile,
|
||||
{
|
||||
...CommonToolTipActions.PasteFromClipboard,
|
||||
hidden: !isClipboardGetContentEnabled,
|
||||
},
|
||||
];
|
||||
|
||||
return availableActions;
|
||||
}, [isClipboardGetContentEnabled]);
|
||||
|
||||
const onMenuItemPressed = useCallback(
|
||||
async (action: string) => {
|
||||
switch (action) {
|
||||
case CommonToolTipActions.ScanQR.id:
|
||||
navigation.navigate('ScanQRCode', {
|
||||
showFileImportButton: true,
|
||||
});
|
||||
break;
|
||||
case CommonToolTipActions.PasteFromClipboard.id:
|
||||
try {
|
||||
let getImage: string | null = null;
|
||||
let hasImage = false;
|
||||
if (Platform.OS === 'android') {
|
||||
hasImage = true;
|
||||
} else {
|
||||
hasImage = await Clipboard.hasImage();
|
||||
}
|
||||
|
||||
if (hasImage) {
|
||||
getImage = await Clipboard.getImage();
|
||||
}
|
||||
|
||||
if (getImage) {
|
||||
try {
|
||||
const base64Data = getImage.replace(/^data:image\/(png|jpeg|jpg);base64,/, '');
|
||||
const values = await RNQRGenerator.detect({
|
||||
base64: base64Data,
|
||||
});
|
||||
|
||||
if (values && values.values.length > 0) {
|
||||
onChangeText(values.values[0]);
|
||||
} else {
|
||||
presentAlert({ message: loc.send.qr_error_no_qrcode });
|
||||
}
|
||||
} catch (error) {
|
||||
presentAlert({ message: (error as Error).message });
|
||||
}
|
||||
} else {
|
||||
const clipboardText = await Clipboard.getString();
|
||||
onChangeText(clipboardText);
|
||||
}
|
||||
} catch (error) {
|
||||
presentAlert({ message: (error as Error).message });
|
||||
}
|
||||
break;
|
||||
case CommonToolTipActions.ChoosePhoto.id:
|
||||
showImagePickerAndReadImage()
|
||||
.then(value => {
|
||||
if (value) {
|
||||
onChangeText(value);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
presentAlert({ message: error.message });
|
||||
});
|
||||
break;
|
||||
case CommonToolTipActions.ImportFile.id:
|
||||
showFilePickerAndReadFile()
|
||||
.then(value => {
|
||||
if (value.data) {
|
||||
onChangeText(value.data);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
presentAlert({ message: error.message });
|
||||
});
|
||||
break;
|
||||
}
|
||||
Keyboard.dismiss();
|
||||
navigation.navigate('ScanQRCode', {
|
||||
showFileImportButton: true,
|
||||
});
|
||||
}, [navigation, beforePress]);
|
||||
},
|
||||
[navigation, onChangeText],
|
||||
);
|
||||
|
||||
const actions = useMemo(() => {
|
||||
const availableActions = [
|
||||
CommonToolTipActions.ChoosePhoto,
|
||||
CommonToolTipActions.ImportFile,
|
||||
{
|
||||
...CommonToolTipActions.PasteFromClipboard,
|
||||
hidden: !isClipboardGetContentEnabled,
|
||||
},
|
||||
];
|
||||
const buttonStyle = useMemo(() => [styles.scan, stylesHook.scan], [stylesHook.scan]);
|
||||
|
||||
return availableActions;
|
||||
}, [isClipboardGetContentEnabled]);
|
||||
|
||||
const onMenuItemPressed = useCallback(
|
||||
async (action: string) => {
|
||||
switch (action) {
|
||||
case CommonToolTipActions.ScanQR.id:
|
||||
navigation.navigate('ScanQRCode', {
|
||||
showFileImportButton: true,
|
||||
});
|
||||
break;
|
||||
case CommonToolTipActions.PasteFromClipboard.id:
|
||||
try {
|
||||
let getImage: string | null = null;
|
||||
let hasImage = false;
|
||||
if (Platform.OS === 'android') {
|
||||
hasImage = true;
|
||||
} else {
|
||||
hasImage = await Clipboard.hasImage();
|
||||
}
|
||||
|
||||
if (hasImage) {
|
||||
getImage = await Clipboard.getImage();
|
||||
}
|
||||
|
||||
if (getImage) {
|
||||
try {
|
||||
const base64Data = getImage.replace(/^data:image\/(png|jpeg|jpg);base64,/, '');
|
||||
const values = await RNQRGenerator.detect({
|
||||
base64: base64Data,
|
||||
});
|
||||
|
||||
if (values && values.values.length > 0) {
|
||||
onChangeText(values.values[0]);
|
||||
} else {
|
||||
presentAlert({ message: loc.send.qr_error_no_qrcode });
|
||||
}
|
||||
} catch (error) {
|
||||
presentAlert({ message: (error as Error).message });
|
||||
}
|
||||
} else {
|
||||
const clipboardText = await Clipboard.getString();
|
||||
onChangeText(clipboardText);
|
||||
}
|
||||
} catch (error) {
|
||||
presentAlert({ message: (error as Error).message });
|
||||
}
|
||||
break;
|
||||
case CommonToolTipActions.ChoosePhoto.id:
|
||||
showImagePickerAndReadImage()
|
||||
.then(value => {
|
||||
if (value) {
|
||||
onChangeText(value);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
presentAlert({ message: error.message });
|
||||
});
|
||||
break;
|
||||
case CommonToolTipActions.ImportFile.id:
|
||||
showFilePickerAndReadFile()
|
||||
.then(value => {
|
||||
if (value.data) {
|
||||
onChangeText(value.data);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
presentAlert({ message: error.message });
|
||||
});
|
||||
break;
|
||||
}
|
||||
Keyboard.dismiss();
|
||||
},
|
||||
[navigation, onChangeText],
|
||||
);
|
||||
|
||||
const buttonStyle = useMemo(() => [styles.scan, stylesHook.scan], [stylesHook.scan]);
|
||||
|
||||
return (
|
||||
<ToolTipMenu
|
||||
ref={ref}
|
||||
actions={actions}
|
||||
isButton
|
||||
onPressMenuItem={onMenuItemPressed}
|
||||
testID={testID}
|
||||
disabled={isLoading}
|
||||
onPress={toolTipOnPress}
|
||||
isMenuPrimaryAction={isDesktop}
|
||||
buttonStyle={type === 'default' ? buttonStyle : undefined}
|
||||
accessibilityLabel={loc.send.details_scan}
|
||||
accessibilityHint={loc.send.details_scan_hint}
|
||||
>
|
||||
{type === 'default' ? (
|
||||
<>
|
||||
<Image source={require('../img/scan-white.png')} accessible={false} />
|
||||
<Text style={[styles.scanText, stylesHook.scanText]} accessible={false}>
|
||||
{loc.send.details_scan}
|
||||
</Text>
|
||||
</>
|
||||
) : (
|
||||
<Text style={[styles.linkText, { color: colors.foregroundColor }]}>{loc.wallets.import_scan_qr}</Text>
|
||||
)}
|
||||
</ToolTipMenu>
|
||||
);
|
||||
},
|
||||
);
|
||||
return (
|
||||
<ToolTipMenu
|
||||
actions={actions}
|
||||
isButton
|
||||
onPressMenuItem={onMenuItemPressed}
|
||||
testID={testID}
|
||||
disabled={isLoading}
|
||||
onPress={toolTipOnPress}
|
||||
isMenuPrimaryAction={isDesktop}
|
||||
buttonStyle={type === 'default' ? buttonStyle : undefined}
|
||||
accessibilityLabel={loc.send.details_scan}
|
||||
accessibilityHint={loc.send.details_scan_hint}
|
||||
>
|
||||
{type === 'default' ? (
|
||||
<>
|
||||
<Image source={require('../img/scan-white.png')} accessible={false} />
|
||||
<Text style={[styles.scanText, stylesHook.scanText]} accessible={false}>
|
||||
{loc.send.details_scan}
|
||||
</Text>
|
||||
</>
|
||||
) : (
|
||||
<Text style={[styles.linkText, { color: colors.foregroundColor }]}>{loc.wallets.import_scan_qr}</Text>
|
||||
)}
|
||||
</ToolTipMenu>
|
||||
);
|
||||
};
|
||||
|
||||
AddressInputScanButton.displayName = 'AddressInputScanButton';
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ const ViewEditMultisigCosigners: React.FC = () => {
|
|||
const { isBiometricUseCapableAndEnabled } = useBiometrics();
|
||||
const { isElectrumDisabled, isPrivacyBlurEnabled } = useSettings();
|
||||
const { dispatch, setParams, setOptions } = useExtendedNavigation<NavigationProp>();
|
||||
const openScannerButtonRef = useRef(null);
|
||||
const route = useRoute<RouteParams>();
|
||||
const { walletID } = route.params;
|
||||
const w = useRef(wallets.find(wallet => wallet.getID() === walletID));
|
||||
|
@ -562,7 +561,6 @@ const ViewEditMultisigCosigners: React.FC = () => {
|
|||
{!isLoading && (
|
||||
<>
|
||||
<AddressInputScanButton
|
||||
ref={openScannerButtonRef}
|
||||
beforePress={async () => {
|
||||
await provideMnemonicsModalRef.current?.dismiss();
|
||||
}}
|
||||
|
|
Loading…
Add table
Reference in a new issue