mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-26 08:55:56 +01:00
REF: Moved AddressInput tooltips to types
This commit is contained in:
parent
cebdea6d25
commit
2a1ab931bd
4 changed files with 75 additions and 61 deletions
|
@ -1,10 +1,17 @@
|
|||
import React, { useCallback, useMemo } from 'react';
|
||||
import { Image, Keyboard, Platform, StyleSheet, Text, TextInput, View } from 'react-native';
|
||||
import { Image, Keyboard, StyleSheet, Text, TextInput, View } from 'react-native';
|
||||
|
||||
import { scanQrHelper } from '../helpers/scan-qr';
|
||||
import loc from '../loc';
|
||||
import presentAlert from './Alert';
|
||||
import ToolTipMenu from './TooltipMenu';
|
||||
import { CommonToolTipActions } from '../typings/CommonToolTipActions';
|
||||
import Clipboard from '@react-native-clipboard/clipboard';
|
||||
import { showFilePickerAndReadFile, showImagePickerAndReadImage } from '../blue_modules/fs';
|
||||
import { useTheme } from './themes';
|
||||
import { useSettings } from '../hooks/context/useSettings';
|
||||
import DeeplinkSchemaMatch from '../class/deeplink-schema-match';
|
||||
import triggerHapticFeedback, { HapticFeedbackTypes } from '../blue_modules/hapticFeedback';
|
||||
|
||||
interface AddressInputProps {
|
||||
isLoading?: boolean;
|
||||
|
@ -47,6 +54,7 @@ const AddressInput = ({
|
|||
keyboardType = 'default',
|
||||
}: AddressInputProps) => {
|
||||
const { colors } = useTheme();
|
||||
const { isClipboardGetContentEnabled } = useSettings();
|
||||
const stylesHook = StyleSheet.create({
|
||||
root: {
|
||||
borderColor: colors.formBorder,
|
||||
|
@ -62,10 +70,24 @@ const AddressInput = ({
|
|||
});
|
||||
|
||||
const onBlurEditing = () => {
|
||||
if (DeeplinkSchemaMatch.isBitcoinAddress(address) || DeeplinkSchemaMatch.isLightningInvoice(address)) {
|
||||
triggerHapticFeedback(HapticFeedbackTypes.NotificationSuccess);
|
||||
} else {
|
||||
triggerHapticFeedback(HapticFeedbackTypes.NotificationError);
|
||||
}
|
||||
onBlur();
|
||||
Keyboard.dismiss();
|
||||
};
|
||||
|
||||
const actions = useMemo(() => {
|
||||
const availableActions = [CommonToolTipActions.ScanQR, CommonToolTipActions.ChoosePhoto, CommonToolTipActions.ImportFile];
|
||||
const clipboardAction = CommonToolTipActions.CopyFromClipboard;
|
||||
clipboardAction.hidden = !isClipboardGetContentEnabled;
|
||||
availableActions.push(clipboardAction);
|
||||
|
||||
return availableActions;
|
||||
}, [isClipboardGetContentEnabled]);
|
||||
|
||||
const toolTipOnPress = useCallback(async () => {
|
||||
await scanButtonTapped();
|
||||
Keyboard.dismiss();
|
||||
|
@ -76,7 +98,7 @@ const AddressInput = ({
|
|||
(action: string) => {
|
||||
if (onBarScanned === undefined) throw new Error('onBarScanned is required');
|
||||
switch (action) {
|
||||
case actionKeys.ScanQR:
|
||||
case CommonToolTipActions.ScanQR.id:
|
||||
scanButtonTapped();
|
||||
if (launchedBy) {
|
||||
scanQrHelper(launchedBy)
|
||||
|
@ -87,14 +109,14 @@ const AddressInput = ({
|
|||
}
|
||||
|
||||
break;
|
||||
case actionKeys.CopyFromClipboard:
|
||||
case CommonToolTipActions.CopyFromClipboard.id:
|
||||
Clipboard.getString()
|
||||
.then(onChangeText)
|
||||
.catch(error => {
|
||||
presentAlert({ message: error.message });
|
||||
});
|
||||
break;
|
||||
case actionKeys.ChoosePhoto:
|
||||
case CommonToolTipActions.ChoosePhoto.id:
|
||||
showImagePickerAndReadImage()
|
||||
.then(value => {
|
||||
if (value) {
|
||||
|
@ -105,7 +127,7 @@ const AddressInput = ({
|
|||
presentAlert({ message: error.message });
|
||||
});
|
||||
break;
|
||||
case actionKeys.ImportFile:
|
||||
case CommonToolTipActions.ImportFile.id:
|
||||
showFilePickerAndReadFile()
|
||||
.then(value => {
|
||||
if (value.data) {
|
||||
|
@ -140,6 +162,7 @@ const AddressInput = ({
|
|||
onBlur={onBlurEditing}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
readOnly={!editable}
|
||||
keyboardType={keyboardType}
|
||||
/>
|
||||
{editable ? (
|
||||
|
@ -197,49 +220,4 @@ const styles = StyleSheet.create({
|
|||
},
|
||||
});
|
||||
|
||||
const actionKeys = {
|
||||
ScanQR: 'scan_qr',
|
||||
CopyFromClipboard: 'copy_from_clipboard',
|
||||
ChoosePhoto: 'choose_photo',
|
||||
ImportFile: 'import_file',
|
||||
};
|
||||
|
||||
const actionIcons = {
|
||||
ScanQR: {
|
||||
iconValue: Platform.OS === 'ios' ? 'qrcode' : 'ic_menu_camera',
|
||||
},
|
||||
ImportFile: {
|
||||
iconValue: 'doc',
|
||||
},
|
||||
ChoosePhoto: {
|
||||
iconValue: Platform.OS === 'ios' ? 'photo' : 'ic_menu_gallery',
|
||||
},
|
||||
Clipboard: {
|
||||
iconValue: Platform.OS === 'ios' ? 'doc' : 'ic_menu_file',
|
||||
},
|
||||
};
|
||||
|
||||
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;
|
||||
|
|
|
@ -340,7 +340,11 @@ const Confirm: React.FC = () => {
|
|||
{state.isLoading ? (
|
||||
<ActivityIndicator />
|
||||
) : (
|
||||
<Button disabled={isElectrumDisabled || state.isButtonDisabled} onPress={handleSendTransaction} title={loc.send.confirm_sendNow} />
|
||||
<Button
|
||||
disabled={isElectrumDisabled || state.isButtonDisabled}
|
||||
onPress={handleSendTransaction}
|
||||
title={loc.send.confirm_sendNow}
|
||||
/>
|
||||
)}
|
||||
</BlueCard>
|
||||
</View>
|
||||
|
@ -444,4 +448,4 @@ const styles = StyleSheet.create({
|
|||
fontSize: 15,
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import { Platform, Pressable, ScrollView, StyleSheet, Text, TouchableWithoutFeedback, View } from 'react-native';
|
||||
import { Platform, ScrollView, StyleSheet, Text, TouchableWithoutFeedback, View } from 'react-native';
|
||||
import { openSettings } from 'react-native-permissions';
|
||||
import A from '../../blue_modules/analytics';
|
||||
import { Header } from '../../components/Header';
|
||||
|
@ -127,11 +127,7 @@ const SettingsPrivacy: React.FC = () => {
|
|||
disabled: isLoading === SettingsPrivacySection.All,
|
||||
testID: 'ClipboardSwitch',
|
||||
}}
|
||||
subtitle={
|
||||
<Pressable accessibilityRole="button">
|
||||
<Text style={styles.subtitleText}>{loc.settings.privacy_clipboard_explanation}</Text>
|
||||
</Pressable>
|
||||
}
|
||||
subtitle={loc.settings.privacy_clipboard_explanation}
|
||||
/>
|
||||
|
||||
<ListItem
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { Platform } from 'react-native';
|
||||
import loc from '../loc';
|
||||
|
||||
const keys = {
|
||||
|
@ -22,6 +23,10 @@ const keys = {
|
|||
RemoveAllRecipients: 'RemoveAllRecipients',
|
||||
AddRecipient: 'AddRecipient',
|
||||
RemoveRecipient: 'RemoveRecipient',
|
||||
ScanQR: 'scan_qr',
|
||||
CopyFromClipboard: 'copy_from_clipboard',
|
||||
ChoosePhoto: 'choose_photo',
|
||||
ImportFile: 'import_file',
|
||||
};
|
||||
|
||||
const icons = {
|
||||
|
@ -31,9 +36,6 @@ const icons = {
|
|||
EyeSlash: {
|
||||
iconValue: 'eye.slash',
|
||||
},
|
||||
Clipboard: {
|
||||
iconValue: 'doc.on.doc',
|
||||
},
|
||||
Link: {
|
||||
iconValue: 'link',
|
||||
},
|
||||
|
@ -73,6 +75,18 @@ const icons = {
|
|||
RemoveAllRecipients: { iconValue: 'person.2.slash' },
|
||||
AddRecipient: { iconValue: 'person.badge.plus' },
|
||||
RemoveRecipient: { iconValue: 'person.badge.minus' },
|
||||
ScanQR: {
|
||||
iconValue: Platform.OS === 'ios' ? 'qrcode' : 'ic_menu_camera',
|
||||
},
|
||||
ImportFile: {
|
||||
iconValue: 'doc',
|
||||
},
|
||||
ChoosePhoto: {
|
||||
iconValue: Platform.OS === 'ios' ? 'photo' : 'ic_menu_gallery',
|
||||
},
|
||||
Clipboard: {
|
||||
iconValue: Platform.OS === 'ios' ? 'doc.on.doc' : 'ic_menu_file',
|
||||
},
|
||||
};
|
||||
|
||||
export const CommonToolTipActions = {
|
||||
|
@ -185,4 +199,26 @@ export const CommonToolTipActions = {
|
|||
icon: icons.PaymentsCode,
|
||||
menuState: false,
|
||||
},
|
||||
ScanQR: {
|
||||
id: keys.ScanQR,
|
||||
text: loc.wallets.list_long_scan,
|
||||
icon: icons.ScanQR,
|
||||
},
|
||||
CopyFromClipboard: {
|
||||
id: keys.CopyFromClipboard,
|
||||
text: loc.wallets.list_long_clipboard,
|
||||
icon: icons.Clipboard,
|
||||
subtitle: '',
|
||||
hidden: false,
|
||||
},
|
||||
ChoosePhoto: {
|
||||
id: keys.ChoosePhoto,
|
||||
text: loc.wallets.list_long_choose,
|
||||
icon: icons.ChoosePhoto,
|
||||
},
|
||||
ImportFile: {
|
||||
id: keys.ImportFile,
|
||||
text: loc.wallets.import_file,
|
||||
icon: icons.ImportFile,
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue