ADD: Scan tooltip

This commit is contained in:
Marcos Rodriguez Velez 2024-05-25 13:13:29 -04:00
parent cb3aea1e54
commit 90172d1e67
No known key found for this signature in database
GPG Key ID: 6030B2F48CCE86D7
3 changed files with 123 additions and 20 deletions

View File

@ -121,7 +121,7 @@ const _readPsbtFileIntoBase64 = async function (uri: string): Promise<string> {
}
};
export const showImagePickerAndReadImage = () => {
export const showImagePickerAndReadImage = (): Promise<string | undefined> => {
return new Promise((resolve, reject) =>
launchImageLibrary(
{

View File

@ -5,6 +5,10 @@ import { Image, Keyboard, StyleSheet, Text, TextInput, TouchableOpacity, View }
import { scanQrHelper } from '../helpers/scan-qr';
import loc from '../loc';
import { useTheme } from './themes';
import ToolTipMenu from './TooltipMenu';
import { showFilePickerAndReadFile, showImagePickerAndReadImage } from '../blue_modules/fs';
import Clipboard from '@react-native-clipboard/clipboard';
import presentAlert from './Alert';
interface AddressInputProps {
isLoading?: boolean;
@ -67,6 +71,53 @@ const AddressInput = ({
Keyboard.dismiss();
};
const onMenuItemPressed = (action: string) => {
if (onBarScanned === undefined) throw new Error('onBarScanned is required');
switch (action) {
case actionKeys.ScanQR:
scanButtonTapped();
if (launchedBy) {
scanQrHelper(navigate, launchedBy ?? undefined)
.then(value => onBarScanned({ data: value }))
.catch(error => {
presentAlert({ message: error.message });
});
}
break;
case actionKeys.CopyFromClipboard:
Clipboard.getString()
.then(onChangeText)
.catch(error => {
presentAlert({ message: error.message });
});
break;
case actionKeys.ChoosePhoto:
showImagePickerAndReadImage()
.then(value => {
if (value) {
onChangeText(value);
}
})
.catch(error => {
presentAlert({ message: error.message });
});
break;
case actionKeys.ImportFile:
showFilePickerAndReadFile()
.then(value => {
if (value.data) {
onChangeText(value.data);
}
})
.catch(error => {
presentAlert({ message: error.message });
});
break;
}
Keyboard.dismiss();
};
return (
<View style={[styles.root, stylesHook.root]}>
<TextInput
@ -86,25 +137,27 @@ const AddressInput = ({
keyboardType={keyboardType}
/>
{editable ? (
<TouchableOpacity
testID="BlueAddressInputScanQrButton"
disabled={isLoading}
onPress={async () => {
await scanButtonTapped();
Keyboard.dismiss();
// @ts-ignore: Fix later
scanQrHelper(navigate, launchedBy).then(onBarScanned);
}}
accessibilityRole="button"
style={[styles.scan, stylesHook.scan]}
accessibilityLabel={loc.send.details_scan}
accessibilityHint={loc.send.details_scan_hint}
>
<Image source={require('../img/scan-white.png')} accessible={false} />
<Text style={[styles.scanText, stylesHook.scanText]} accessible={false}>
{loc.send.details_scan}
</Text>
</TouchableOpacity>
<ToolTipMenu actions={actions} isButton onPressMenuItem={onMenuItemPressed}>
<TouchableOpacity
testID="BlueAddressInputScanQrButton"
disabled={isLoading}
onPress={async () => {
await scanButtonTapped();
Keyboard.dismiss();
// @ts-ignore: Fix later
scanQrHelper(navigate, launchedBy).then(onBarScanned);
}}
accessibilityRole="button"
style={[styles.scan, stylesHook.scan]}
accessibilityLabel={loc.send.details_scan}
accessibilityHint={loc.send.details_scan_hint}
>
<Image source={require('../img/scan-white.png')} accessible={false} />
<Text style={[styles.scanText, stylesHook.scanText]} accessible={false}>
{loc.send.details_scan}
</Text>
</TouchableOpacity>
</ToolTipMenu>
) : null}
</View>
);
@ -143,4 +196,53 @@ const styles = StyleSheet.create({
},
});
const actionKeys = {
ScanQR: 'scan_qr',
CopyFromClipboard: 'copy_from_clipboard',
ChoosePhoto: 'choose_photo',
ImportFile: 'import_file',
};
const actionIcons = {
ScanQR: {
iconType: 'SYSTEM',
iconValue: 'qrcode',
},
ImportFile: {
iconType: 'SYSTEM',
iconValue: 'doc',
},
ChoosePhoto: {
iconType: 'SYSTEM',
iconValue: 'photo',
},
Clipboard: {
iconType: 'SYSTEM',
iconValue: 'doc.on.doc',
},
};
const actions = [
{
id: actionKeys.ScanQR,
text: loc.wallets.list_long_scan,
icon: actionIcons.ScanQR,
},
{
id: actionKeys.CopyFromClipboard,
text: loc.wallets.list_long_clipboard,
icon: actionIcons.Clipboard,
},
{
id: actionKeys.ChoosePhoto,
text: loc.wallets.list_long_choose,
icon: actionIcons.ChoosePhoto,
},
{
id: actionKeys.ImportFile,
text: loc.wallets.import_file,
icon: actionIcons.ImportFile,
},
];
export default AddressInput;

View File

@ -455,6 +455,7 @@
"list_latest_transaction": "Latest Transaction",
"list_long_choose": "Choose Photo",
"list_long_clipboard": "Copy from Clipboard",
"import_file": "Import File",
"list_long_scan": "Scan QR Code",
"list_title": "Wallets",
"list_tryagain": "Try again",