mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-22 06:52:41 +01:00
ADD: Deeplinking for LND invoices
This commit is contained in:
parent
054b92d7f7
commit
4aa9c47fda
5 changed files with 37 additions and 15 deletions
10
App.js
10
App.js
|
@ -36,6 +36,16 @@ export default class App extends React.Component {
|
|||
},
|
||||
}),
|
||||
);
|
||||
} else if (event.url.indexOf('lightning:') === 0 || event.url.indexOf('LIGHTNING:') === 0) {
|
||||
this.navigator &&
|
||||
this.navigator.dispatch(
|
||||
NavigationActions.navigate({
|
||||
routeName: 'ScanLndInvoice',
|
||||
params: {
|
||||
uri: event.url,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -25,11 +25,10 @@
|
|||
<dict>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
<key>CFBundleURLName</key>
|
||||
<string>bitcoin</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>bitcoin</string>
|
||||
<string>lightning</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
|
@ -57,7 +56,7 @@
|
|||
<key>NSCalendarsUsageDescription</key>
|
||||
<string>This alert should not show up as we do not require this data</string>
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>In order to quickly scan the recipient's address, we need your permission to use the camera to scan their QR Code.</string>
|
||||
<string>In order to quickly scan the recipient's address, we need your permission to use the camera to scan their QR Code.</string>
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string>This alert should not show up as we do not require this data</string>
|
||||
<key>NSMotionUsageDescription</key>
|
||||
|
|
|
@ -4,6 +4,7 @@ import { Text, Dimensions, ActivityIndicator, View, TouchableOpacity, TouchableW
|
|||
import { Icon } from 'react-native-elements';
|
||||
import PropTypes from 'prop-types';
|
||||
import { BlueSpacing20, BlueButton, SafeBlueArea, BlueCard, BlueHeaderDefaultSub } from '../../BlueComponents';
|
||||
import { LightningCustodianWallet } from '../../class/lightning-custodian-wallet';
|
||||
/** @type {AppStorage} */
|
||||
let BlueApp = require('../../BlueApp');
|
||||
let currency = require('../../currency');
|
||||
|
@ -28,6 +29,13 @@ export default class ScanLndInvoice extends React.Component {
|
|||
if (props.navigation.state.params.fromSecret) fromSecret = props.navigation.state.params.fromSecret;
|
||||
let fromWallet = {};
|
||||
|
||||
if (!fromSecret) {
|
||||
const lightningWallets = BlueApp.getWallets().filter(item => item.type === new LightningCustodianWallet().type);
|
||||
if (lightningWallets.length > 0) {
|
||||
fromSecret = lightningWallets[0].getSecret();
|
||||
}
|
||||
}
|
||||
|
||||
for (let w of BlueApp.getWallets()) {
|
||||
if (w.getSecret() === fromSecret) {
|
||||
fromWallet = w;
|
||||
|
@ -49,6 +57,10 @@ export default class ScanLndInvoice extends React.Component {
|
|||
},
|
||||
true,
|
||||
);
|
||||
|
||||
if (this.props.navigation.state.params.uri) {
|
||||
this.processTextForInvoice(this.props.navigation.getParam('uri'));
|
||||
}
|
||||
}
|
||||
|
||||
async processInvoice(data) {
|
||||
|
@ -128,6 +140,14 @@ export default class ScanLndInvoice extends React.Component {
|
|||
this.props.navigation.goBack();
|
||||
}
|
||||
|
||||
processTextForInvoice = text => {
|
||||
if (text.toLowerCase().startsWith('lnb') || text.toLowerCase().startsWith('lightning:lnb')) {
|
||||
this.processInvoice(text);
|
||||
} else {
|
||||
this.setState({ decoded: undefined, expiresIn: undefined });
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
|
||||
|
@ -162,13 +182,7 @@ export default class ScanLndInvoice extends React.Component {
|
|||
}}
|
||||
>
|
||||
<TextInput
|
||||
onChangeText={text => {
|
||||
if (text.toLowerCase().startsWith('lnb') || text.toLowerCase().startsWith('lntb')) {
|
||||
this.processInvoice(text);
|
||||
} else {
|
||||
this.setState({ decoded: undefined, expiresIn: undefined });
|
||||
}
|
||||
}}
|
||||
onChangeText={this.processTextForInvoice}
|
||||
placeholder={loc.wallets.details.destination}
|
||||
numberOfLines={1}
|
||||
value={this.state.hasOwnProperty('decoded') && this.state.decoded !== undefined ? this.state.decoded.destination : ''}
|
||||
|
@ -263,8 +277,10 @@ ScanLndInvoice.propTypes = {
|
|||
navigation: PropTypes.shape({
|
||||
goBack: PropTypes.function,
|
||||
navigate: PropTypes.function,
|
||||
getParam: PropTypes.function,
|
||||
state: PropTypes.shape({
|
||||
params: PropTypes.shape({
|
||||
uri: PropTypes.string,
|
||||
fromSecret: PropTypes.string,
|
||||
}),
|
||||
}),
|
||||
|
|
|
@ -146,7 +146,6 @@ export default class SendDetails extends Component {
|
|||
let memo = '';
|
||||
|
||||
parsedBitcoinUri = bip21.decode(this.props.navigation.state.params.uri);
|
||||
console.warn(parsedBitcoinUri);
|
||||
address = parsedBitcoinUri.address || address;
|
||||
amount = parsedBitcoinUri.options.amount.toString() || amount;
|
||||
memo = parsedBitcoinUri.options.label || memo;
|
||||
|
|
|
@ -58,9 +58,7 @@ export default class WalletsImport extends Component {
|
|||
await BlueApp.saveToDisk();
|
||||
EV(EV.enum.WALLETS_COUNT_CHANGED);
|
||||
A(A.ENUM.CREATED_WALLET);
|
||||
setTimeout(() => {
|
||||
this.props.navigation.popToTop();
|
||||
});
|
||||
this.props.navigation.dismiss();
|
||||
}
|
||||
|
||||
async importMnemonic(text) {
|
||||
|
@ -261,7 +259,7 @@ export default class WalletsImport extends Component {
|
|||
WalletsImport.propTypes = {
|
||||
navigation: PropTypes.shape({
|
||||
navigate: PropTypes.func,
|
||||
popToTop: PropTypes.func,
|
||||
dismiss: PropTypes.func,
|
||||
goBack: PropTypes.func,
|
||||
}),
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue