mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-25 16:04:17 +01:00
ADD: subscripbe to push notifications about mined tx
This commit is contained in:
parent
f0b9366ced
commit
1d8cbcf4b2
9 changed files with 22 additions and 10 deletions
|
@ -56,7 +56,7 @@ export default class WatchConnectivity {
|
|||
// lets decode payreq and subscribe groundcontrol so we can receive push notification when our invoice is paid
|
||||
const decoded = await wallet.decodeInvoice(invoiceRequest);
|
||||
await notifications.tryToObtainPermissions();
|
||||
notifications.majorTomToGroundControl([], [decoded.payment_hash]);
|
||||
notifications.majorTomToGroundControl([], [decoded.payment_hash], []);
|
||||
return invoiceRequest;
|
||||
} catch (error) {
|
||||
return error;
|
||||
|
|
|
@ -148,10 +148,12 @@ function _getHeaders() {
|
|||
*
|
||||
* @param addresses {string[]}
|
||||
* @param hashes {string[]}
|
||||
* @param txids {string[]}
|
||||
* @returns {Promise<object>} Response object from API rest call
|
||||
*/
|
||||
const majorTomToGroundControl = async function (addresses, hashes) {
|
||||
if (!Array.isArray(addresses) || !Array.isArray(hashes)) throw new Error('no addresses or hashes provided');
|
||||
const majorTomToGroundControl = async function (addresses, hashes, txids) {
|
||||
if (!Array.isArray(addresses) || !Array.isArray(hashes) || !Array.isArray(txids))
|
||||
throw new Error('no addresses or hashes or txids provided');
|
||||
const pushToken = await _getPushToken();
|
||||
if (!pushToken || !pushToken.token || !pushToken.os) return;
|
||||
|
||||
|
@ -163,6 +165,7 @@ const majorTomToGroundControl = async function (addresses, hashes) {
|
|||
body: {
|
||||
addresses,
|
||||
hashes,
|
||||
txids,
|
||||
token: pushToken.token,
|
||||
os: pushToken.os,
|
||||
},
|
||||
|
|
|
@ -397,7 +397,7 @@ export default class Browser extends Component {
|
|||
// lets decode payreq and subscribe groundcontrol so we can receive push notification when our invoice is paid
|
||||
const decoded = await fromWallet.decodeInvoice(payreq);
|
||||
await notifications.tryToObtainPermissions();
|
||||
notifications.majorTomToGroundControl([], [decoded.payment_hash]);
|
||||
notifications.majorTomToGroundControl([], [decoded.payment_hash], []);
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
@ -229,7 +229,7 @@ export default class LNDCreateInvoice extends Component {
|
|||
const fromWallet = this.state.fromWallet;
|
||||
const decoded = await fromWallet.decodeInvoice(invoiceRequest);
|
||||
await notifications.tryToObtainPermissions();
|
||||
notifications.majorTomToGroundControl([], [decoded.payment_hash]);
|
||||
notifications.majorTomToGroundControl([], [decoded.payment_hash], []);
|
||||
|
||||
// send to lnurl-withdraw callback url if that exists
|
||||
if (this.state.lnurlParams) {
|
||||
|
|
|
@ -207,11 +207,11 @@ const ReceiveDetails = () => {
|
|||
}
|
||||
setAddressBIP21Encoded(address);
|
||||
await notifications.tryToObtainPermissions();
|
||||
notifications.majorTomToGroundControl([address], []);
|
||||
notifications.majorTomToGroundControl([address], [], []);
|
||||
} else if (wallet.getAddress) {
|
||||
setAddressBIP21Encoded(wallet.getAddress());
|
||||
await notifications.tryToObtainPermissions();
|
||||
notifications.majorTomToGroundControl([wallet.getAddress()], []);
|
||||
notifications.majorTomToGroundControl([wallet.getAddress()], [], []);
|
||||
}
|
||||
}, [wallet]);
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ import React, { useState } from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
import { ActivityIndicator, Linking, StyleSheet, View, KeyboardAvoidingView, Platform, Text, TextInput } from 'react-native';
|
||||
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
||||
|
||||
import loc from '../../loc';
|
||||
import { HDSegwitBech32Wallet } from '../../class';
|
||||
import {
|
||||
|
@ -19,6 +18,7 @@ import {
|
|||
import { BlueCurrentTheme } from '../../components/themes';
|
||||
import BlueElectrum from '../../blue_modules/BlueElectrum';
|
||||
const bitcoin = require('bitcoinjs-lib');
|
||||
const notifications = require('../../blue_modules/notifications');
|
||||
|
||||
const BROADCAST_RESULT = Object.freeze({
|
||||
none: 'Input transaction hash',
|
||||
|
@ -44,6 +44,7 @@ const Broadcast = () => {
|
|||
const txid = tx.getId();
|
||||
setTx(txid);
|
||||
setBroadcastResult(BROADCAST_RESULT.success);
|
||||
notifications.majorTomToGroundControl([], [], [txid]);
|
||||
} else {
|
||||
setBroadcastResult(BROADCAST_RESULT.error);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ const EV = require('../../blue_modules/events');
|
|||
const currency = require('../../blue_modules/currency');
|
||||
const BlueElectrum = require('../../blue_modules/BlueElectrum');
|
||||
const Bignumber = require('bignumber.js');
|
||||
const bitcoin = require('bitcoinjs-lib');
|
||||
const notifications = require('../../blue_modules/notifications');
|
||||
|
||||
export default class Confirm extends Component {
|
||||
constructor(props) {
|
||||
|
@ -65,6 +67,8 @@ export default class Confirm extends Component {
|
|||
if (!result) {
|
||||
throw new Error(loc.errors.broadcast);
|
||||
} else {
|
||||
const txid = bitcoin.Transaction.fromHex(this.state.tx).getId();
|
||||
notifications.majorTomToGroundControl([], [], [txid]);
|
||||
EV(EV.enum.REMOTE_TRANSACTIONS_COUNT_CHANGED); // someone should fetch txs
|
||||
let amount = 0;
|
||||
const recipients = this.state.recipients;
|
||||
|
|
|
@ -42,6 +42,7 @@ const BlueElectrum = require('../../blue_modules/BlueElectrum');
|
|||
/** @type {AppStorage} */
|
||||
const BlueApp = require('../../BlueApp');
|
||||
const bitcoin = require('bitcoinjs-lib');
|
||||
const notifications = require('../../blue_modules/notifications');
|
||||
const { height, width } = Dimensions.get('window');
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
|
@ -251,9 +252,10 @@ export default class PsbtWithHardwareWallet extends Component {
|
|||
if (result) {
|
||||
EV(EV.enum.REMOTE_TRANSACTIONS_COUNT_CHANGED); // someone should fetch txs
|
||||
this.setState({ success: true, isLoading: false });
|
||||
const txDecoded = bitcoin.Transaction.fromHex(this.state.txhex);
|
||||
const txid = txDecoded.getId();
|
||||
notifications.majorTomToGroundControl([], [], [txid]);
|
||||
if (this.state.memo) {
|
||||
const txDecoded = bitcoin.Transaction.fromHex(this.state.txhex);
|
||||
const txid = txDecoded.getId();
|
||||
BlueApp.tx_metadata[txid] = { memo: this.state.memo };
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -22,6 +22,7 @@ const EV = require('../../blue_modules/events');
|
|||
const BlueElectrum = require('../../blue_modules/BlueElectrum');
|
||||
/** @type {AppStorage} */
|
||||
const BlueApp = require('../../BlueApp');
|
||||
const notifications = require('../../blue_modules/notifications');
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
root: {
|
||||
|
@ -118,6 +119,7 @@ export default class CPFP extends Component {
|
|||
|
||||
onSuccessBroadcast() {
|
||||
BlueApp.tx_metadata[this.state.newTxid] = { memo: 'Child pays for parent (CPFP)' };
|
||||
notifications.majorTomToGroundControl([], [], [this.state.newTxid]);
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
|
|
Loading…
Add table
Reference in a new issue