Browse Source

FIX: Don't display send modal if address belongs to self #573

psbt
Marcos Rodriguez 5 years ago
parent
commit
59c9905ae8
  1. 10
      App.js
  2. 4
      class/lightning-custodian-wallet.js
  3. 5
      screen/receive/details.js

10
App.js

@ -9,6 +9,7 @@ import { BlueTextCentered, BlueButton } from './BlueComponents';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import url from 'url';
import { AppStorage, LightningCustodianWallet } from './class';
import { Chain } from './models/bitcoinUnits';
const bitcoin = require('bitcoinjs-lib');
const bitcoinModalString = 'Bitcoin address';
const lightningModalString = 'Lightning Invoice';
@ -47,7 +48,14 @@ export default class App extends React.Component {
if (BlueApp.getWallets().length > 0) {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
const clipboard = await Clipboard.getString();
if (this.state.clipboardContent !== clipboard && (this.isBitcoinAddress(clipboard) || this.isLightningInvoice(clipboard))) {
const isAddressFromStoredWallet = BlueApp.getWallets().some(wallet =>
wallet.chain === Chain.ONCHAIN ? wallet._address === clipboard : wallet.isInvoiceGeneratedByWallet(clipboard),
);
if (
this.state.clipboardContent !== clipboard &&
!isAddressFromStoredWallet &&
(this.isBitcoinAddress(clipboard) || this.isLightningInvoice(clipboard))
) {
this.setState({ isClipboardContentModalVisible: true });
}
this.setState({ clipboardContent: clipboard });

4
class/lightning-custodian-wallet.js

@ -199,6 +199,10 @@ export class LightningCustodianWallet extends LegacyWallet {
await this.getUserInvoices();
}
isInvoiceGeneratedByWallet(paymentRequest) {
return this.user_invoices_raw.some(invoice => invoice.payment_request === paymentRequest);
}
async addInvoice(amt, memo) {
let response = await this._api.post('/addinvoice', {
body: { amt: amt + '', memo: memo },

5
screen/receive/details.js

@ -56,14 +56,15 @@ export default class ReceiveDetails extends Component {
if (wallet.getAddressAsync) {
try {
address = await Promise.race([wallet.getAddressAsync(), BlueApp.sleep(1000)]);
wallet._address = address;
} catch (_) {}
if (!address) {
// either sleep expired or getAddressAsync threw an exception
console.warn('either sleep expired or getAddressAsync threw an exception');
address = wallet._getExternalAddressByIndex(wallet.next_free_address_index);
} else {
BlueApp.saveToDisk(); // caching whatever getAddressAsync() generated internally
wallet._address = address;
}
BlueApp.saveToDisk(); // caching whatever getAddressAsync() generated internally
}
this.setState({
address: address,

Loading…
Cancel
Save