mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-21 14:34:55 +01:00
FIX: Listen to lnd invoice changes
This commit is contained in:
parent
301bf499ce
commit
a46c79ac63
3 changed files with 48 additions and 52 deletions
|
@ -2076,7 +2076,7 @@ export class BlueAddressInput extends Component {
|
|||
value={this.props.address}
|
||||
style={{ flex: 1, marginHorizontal: 8, minHeight: 33 }}
|
||||
editable={!this.props.isLoading}
|
||||
onSubmitEditing={() => Keyboard.dismiss()}
|
||||
onSubmitEditing={Keyboard.dismiss}
|
||||
{...this.props}
|
||||
/>
|
||||
<TouchableOpacity
|
||||
|
|
|
@ -39,7 +39,6 @@ class DeeplinkSchemaMatch {
|
|||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
console.warn(isBothBitcoinAndLightning)
|
||||
if (isBothBitcoinAndLightning) {
|
||||
completionHandler({
|
||||
routeName: 'HandleOffchainAndOnChain',
|
||||
|
|
|
@ -80,10 +80,51 @@ export default class ScanLndInvoice extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.navigation.state.params.uri) {
|
||||
this.processTextForInvoice(this.props.navigation.getParam('uri'));
|
||||
static getDerivedStateFromProps(props, state) {
|
||||
if (props.navigation.state.params.uri) {
|
||||
let data = props.navigation.state.params.uri;
|
||||
// handling BIP21 w/BOLT11 support
|
||||
let ind = data.indexOf('lightning=');
|
||||
if (ind !== -1) {
|
||||
data = data.substring(ind + 10).split('&')[0];
|
||||
}
|
||||
|
||||
data = data.replace('LIGHTNING:', '').replace('lightning:', '');
|
||||
console.log(data);
|
||||
|
||||
/**
|
||||
* @type {LightningCustodianWallet}
|
||||
*/
|
||||
let w = state.fromWallet;
|
||||
let decoded;
|
||||
try {
|
||||
decoded = w.decodeInvoice(data);
|
||||
|
||||
let expiresIn = (decoded.timestamp * 1 + decoded.expiry * 1) * 1000; // ms
|
||||
if (+new Date() > expiresIn) {
|
||||
expiresIn = 'expired';
|
||||
} else {
|
||||
expiresIn = Math.round((expiresIn - +new Date()) / (60 * 1000)) + ' min';
|
||||
}
|
||||
Keyboard.dismiss();
|
||||
props.navigation.setParams({ uri: undefined });
|
||||
return {
|
||||
invoice: data,
|
||||
decoded,
|
||||
expiresIn,
|
||||
destination: data,
|
||||
isAmountInitiallyEmpty: decoded.num_satoshis === '0',
|
||||
isLoading: false,
|
||||
};
|
||||
} catch (Err) {
|
||||
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
||||
Keyboard.dismiss();
|
||||
props.navigation.setParams({ uri: undefined });
|
||||
setTimeout(() => alert(Err.message), 10);
|
||||
return { ...state, isLoading: false };
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
@ -100,52 +141,7 @@ export default class ScanLndInvoice extends React.Component {
|
|||
};
|
||||
|
||||
processInvoice = data => {
|
||||
this.setState({ isLoading: true }, async () => {
|
||||
if (!this.state.fromWallet) {
|
||||
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
||||
alert('Before paying a Lightning invoice, you must first add a Lightning wallet.');
|
||||
return this.props.navigation.goBack();
|
||||
}
|
||||
|
||||
// handling BIP21 w/BOLT11 support
|
||||
let ind = data.indexOf('lightning=');
|
||||
if (ind !== -1) {
|
||||
data = data.substring(ind + 10).split('&')[0];
|
||||
}
|
||||
|
||||
data = data.replace('LIGHTNING:', '').replace('lightning:', '');
|
||||
console.log(data);
|
||||
|
||||
/**
|
||||
* @type {LightningCustodianWallet}
|
||||
*/
|
||||
let w = this.state.fromWallet;
|
||||
let decoded;
|
||||
try {
|
||||
decoded = w.decodeInvoice(data);
|
||||
|
||||
let expiresIn = (decoded.timestamp * 1 + decoded.expiry * 1) * 1000; // ms
|
||||
if (+new Date() > expiresIn) {
|
||||
expiresIn = 'expired';
|
||||
} else {
|
||||
expiresIn = Math.round((expiresIn - +new Date()) / (60 * 1000)) + ' min';
|
||||
}
|
||||
Keyboard.dismiss();
|
||||
this.setState({
|
||||
invoice: data,
|
||||
decoded,
|
||||
expiresIn,
|
||||
destination: data,
|
||||
isAmountInitiallyEmpty: decoded.num_satoshis === '0',
|
||||
isLoading: false,
|
||||
});
|
||||
} catch (Err) {
|
||||
Keyboard.dismiss();
|
||||
this.setState({ isLoading: false });
|
||||
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
||||
alert(Err.message);
|
||||
}
|
||||
});
|
||||
this.props.navigation.setParams({ uri: data });
|
||||
};
|
||||
|
||||
async pay() {
|
||||
|
@ -295,7 +291,7 @@ export default class ScanLndInvoice extends React.Component {
|
|||
<BlueCard>
|
||||
<BlueAddressInput
|
||||
onChangeText={text => {
|
||||
this.setState({ destination: text });
|
||||
text = text.trim();
|
||||
this.processTextForInvoice(text);
|
||||
}}
|
||||
onBarScanned={this.processInvoice}
|
||||
|
@ -355,6 +351,7 @@ ScanLndInvoice.propTypes = {
|
|||
navigate: PropTypes.func,
|
||||
pop: PropTypes.func,
|
||||
getParam: PropTypes.func,
|
||||
setParams: PropTypes.func,
|
||||
dismiss: PropTypes.func,
|
||||
state: PropTypes.shape({
|
||||
routeName: PropTypes.string,
|
||||
|
|
Loading…
Add table
Reference in a new issue