mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 09:50:15 +01:00
ADD: Shortcuts on Scan button long press
This commit is contained in:
parent
44033b473d
commit
c243ea405b
@ -1,5 +1,17 @@
|
||||
/* global alert */
|
||||
import React, { Component } from 'react';
|
||||
import { View, TouchableOpacity, Text, StyleSheet, InteractionManager, RefreshControl, SectionList, Alert, Platform } from 'react-native';
|
||||
import {
|
||||
View,
|
||||
TouchableOpacity,
|
||||
Clipboard,
|
||||
Text,
|
||||
StyleSheet,
|
||||
InteractionManager,
|
||||
RefreshControl,
|
||||
SectionList,
|
||||
Alert,
|
||||
Platform,
|
||||
} from 'react-native';
|
||||
import { BlueScanButton, WalletsCarousel, BlueHeaderDefaultMain, BlueTransactionListItem } from '../../BlueComponents';
|
||||
import { Icon } from 'react-native-elements';
|
||||
import { NavigationEvents } from 'react-navigation';
|
||||
@ -8,11 +20,14 @@ import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
||||
import PropTypes from 'prop-types';
|
||||
import { PlaceholderWallet } from '../../class';
|
||||
import WalletImport from '../../class/walletImport';
|
||||
import ActionSheet from '../ActionSheet';
|
||||
import ImagePicker from 'react-native-image-picker';
|
||||
let EV = require('../../events');
|
||||
let A = require('../../analytics');
|
||||
/** @type {AppStorage} */
|
||||
let BlueApp = require('../../BlueApp');
|
||||
let loc = require('../../loc');
|
||||
const LocalQRCode = require('@remobile/react-native-qrcode-local-image');
|
||||
let BlueElectrum = require('../../BlueElectrum');
|
||||
|
||||
const WalletsListSections = { CAROUSEL: 'CAROUSEL', LOCALTRADER: 'LOCALTRADER', TRANSACTIONS: 'TRANSACTIONS' };
|
||||
@ -432,7 +447,7 @@ export default class WalletsList extends Component {
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
<BlueScanButton onPress={this.onScanButtonPressed} />
|
||||
<BlueScanButton onPress={this.onScanButtonPressed} onLongPress={this.sendButtonLongPress} />
|
||||
</View>
|
||||
);
|
||||
} else {
|
||||
@ -459,6 +474,87 @@ export default class WalletsList extends Component {
|
||||
});
|
||||
};
|
||||
|
||||
choosePhoto = () => {
|
||||
ImagePicker.launchImageLibrary(
|
||||
{
|
||||
title: null,
|
||||
mediaType: 'photo',
|
||||
takePhotoButtonTitle: null,
|
||||
},
|
||||
response => {
|
||||
if (response.uri) {
|
||||
const uri = Platform.OS === 'ios' ? response.uri.toString().replace('file://', '') : response.path.toString();
|
||||
LocalQRCode.decode(uri, (error, result) => {
|
||||
if (!error) {
|
||||
this.onBarScanned({ data: result });
|
||||
} else {
|
||||
alert('The selected image does not contain a QR Code.');
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
copyFromClipbard = async () => {
|
||||
this.onBarScanned(await Clipboard.getString());
|
||||
};
|
||||
|
||||
sendButtonLongPress = async () => {
|
||||
const isClipboardEmpty = (await Clipboard.getString()).replace(' ', '').length === 0;
|
||||
if (Platform.OS === 'ios') {
|
||||
let options = [loc.send.details.cancel, 'Choose Photo', 'Scan QR Code'];
|
||||
if (!isClipboardEmpty) {
|
||||
options.push('Copy from Clipboard');
|
||||
}
|
||||
ActionSheet.showActionSheetWithOptions({ options, cancelButtonIndex: 0 }, buttonIndex => {
|
||||
if (buttonIndex === 1) {
|
||||
this.choosePhoto();
|
||||
} else if (buttonIndex === 2) {
|
||||
this.props.navigation.navigate('ScanQRCode', {
|
||||
launchedBy: this.props.navigation.state.routeName,
|
||||
onBarScanned: this.onBarCodeRead,
|
||||
showFileImportButton: false,
|
||||
});
|
||||
} else if (buttonIndex === 3) {
|
||||
this.copyFromClipbard();
|
||||
}
|
||||
});
|
||||
} else if (Platform.OS === 'android') {
|
||||
let buttons = [
|
||||
{
|
||||
text: loc.send.details.cancel,
|
||||
onPress: () => {},
|
||||
style: 'cancel',
|
||||
},
|
||||
{
|
||||
text: 'Choose Photo',
|
||||
onPress: this.choosePhoto,
|
||||
},
|
||||
{
|
||||
text: 'Scan QR Code',
|
||||
onPress: () =>
|
||||
this.props.navigation.navigate('ScanQRCode', {
|
||||
launchedBy: this.props.navigation.state.routeName,
|
||||
onBarScanned: this.onBarCodeRead,
|
||||
showFileImportButton: false,
|
||||
}),
|
||||
},
|
||||
];
|
||||
if (!isClipboardEmpty) {
|
||||
buttons.push({
|
||||
text: 'Copy From Clipboard',
|
||||
onPress: this.copyFromClipbard,
|
||||
});
|
||||
}
|
||||
ActionSheet.showActionSheetWithOptions({
|
||||
title: '',
|
||||
message: '',
|
||||
buttons,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={{ flex: 1 }}>
|
||||
|
@ -521,52 +521,57 @@ export default class WalletTransactions extends Component {
|
||||
this.onBarCodeRead({ data: await Clipboard.getString() });
|
||||
};
|
||||
|
||||
sendButtonLongPress = () => {
|
||||
sendButtonLongPress = async () => {
|
||||
const isClipboardEmpty = (await Clipboard.getString()).replace(' ', '').length === 0;
|
||||
if (Platform.OS === 'ios') {
|
||||
ActionSheet.showActionSheetWithOptions(
|
||||
{ options: [loc.send.details.cancel, 'Choose Photo', 'Scan QR Code', 'Copy from Clipboard'], cancelButtonIndex: 0 },
|
||||
buttonIndex => {
|
||||
if (buttonIndex === 1) {
|
||||
this.choosePhoto();
|
||||
} else if (buttonIndex === 2) {
|
||||
let options = [loc.send.details.cancel, 'Choose Photo', 'Scan QR Code'];
|
||||
if (!isClipboardEmpty) {
|
||||
options.push('Copy from Clipboard');
|
||||
}
|
||||
ActionSheet.showActionSheetWithOptions({ options, cancelButtonIndex: 0 }, buttonIndex => {
|
||||
if (buttonIndex === 1) {
|
||||
this.choosePhoto();
|
||||
} else if (buttonIndex === 2) {
|
||||
this.props.navigation.navigate('ScanQRCode', {
|
||||
launchedBy: this.props.navigation.state.routeName,
|
||||
onBarScanned: this.onBarCodeRead,
|
||||
showFileImportButton: false,
|
||||
});
|
||||
} else if (buttonIndex === 3) {
|
||||
this.copyFromClipbard();
|
||||
}
|
||||
});
|
||||
} else if (Platform.OS === 'android') {
|
||||
let buttons = [
|
||||
{
|
||||
text: loc.send.details.cancel,
|
||||
onPress: () => {},
|
||||
style: 'cancel',
|
||||
},
|
||||
{
|
||||
text: 'Choose Photo',
|
||||
onPress: this.choosePhoto,
|
||||
},
|
||||
{
|
||||
text: 'Scan QR Code',
|
||||
onPress: () =>
|
||||
this.props.navigation.navigate('ScanQRCode', {
|
||||
launchedBy: this.props.navigation.state.routeName,
|
||||
onBarScanned: this.onBarCodeRead,
|
||||
showFileImportButton: false,
|
||||
});
|
||||
} else if (buttonIndex === 3) {
|
||||
this.copyFromClipbard();
|
||||
}
|
||||
}),
|
||||
},
|
||||
);
|
||||
} else if (Platform.OS === 'android') {
|
||||
];
|
||||
if (!isClipboardEmpty) {
|
||||
buttons.push({
|
||||
text: 'Copy From Clipboard',
|
||||
onPress: this.copyFromClipbard,
|
||||
});
|
||||
}
|
||||
ActionSheet.showActionSheetWithOptions({
|
||||
title: '',
|
||||
message: '',
|
||||
buttons: [
|
||||
{
|
||||
text: loc.send.details.cancel,
|
||||
onPress: () => {},
|
||||
style: 'cancel',
|
||||
},
|
||||
{
|
||||
text: 'Choose Photo',
|
||||
onPress: this.choosePhoto,
|
||||
},
|
||||
{
|
||||
text: 'Scan QR Code',
|
||||
onPress: () =>
|
||||
this.props.navigation.navigate('ScanQRCode', {
|
||||
launchedBy: this.props.navigation.state.routeName,
|
||||
onBarScanned: this.onBarCodeRead,
|
||||
showFileImportButton: false,
|
||||
}),
|
||||
},
|
||||
{
|
||||
text: 'Copy From Clipboard',
|
||||
onPress: this.copyFromClipbard,
|
||||
},
|
||||
],
|
||||
buttons,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user