mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-23 23:27:26 +01:00
Merge pull request #3410 from BlueWallet/fix-tor-lnurl-withdraw
FIX: support lnurl-withdraw via Tor (closes #3086)
This commit is contained in:
commit
d8b2a0ce74
2 changed files with 33 additions and 13 deletions
|
@ -73,7 +73,7 @@ export class LightningCustodianWallet extends LegacyWallet {
|
|||
baseURI: this.baseURI,
|
||||
});
|
||||
|
||||
if (isTorCapable && this.baseURI?.indexOf('.onion') !== -1) {
|
||||
if (isTorCapable && this.baseURI && this.baseURI?.indexOf('.onion') !== -1) {
|
||||
this._api = new torrific.Torsbee({
|
||||
baseURI: this.baseURI,
|
||||
});
|
||||
|
|
|
@ -29,7 +29,9 @@ import loc, { formatBalanceWithoutSuffix, formatBalancePlain } from '../../loc';
|
|||
import Lnurl from '../../class/lnurl';
|
||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||
import Notifications from '../../blue_modules/notifications';
|
||||
import { isTorCapable } from '../../blue_modules/environment';
|
||||
const currency = require('../../blue_modules/currency');
|
||||
const torrific = require('../../blue_modules/torrific');
|
||||
|
||||
const LNDCreateInvoice = () => {
|
||||
const { wallets, saveToDisk, setSelectedWallet } = useContext(BlueStorageContext);
|
||||
|
@ -176,12 +178,22 @@ const LNDCreateInvoice = () => {
|
|||
if (lnurlParams) {
|
||||
const { callback, k1 } = lnurlParams;
|
||||
const callbackUrl = callback + (callback.indexOf('?') !== -1 ? '&' : '?') + 'k1=' + k1 + '&pr=' + invoiceRequest;
|
||||
const resp = await fetch(callbackUrl, { method: 'GET' });
|
||||
if (resp.status >= 300) {
|
||||
const text = await resp.text();
|
||||
throw new Error(text);
|
||||
|
||||
let reply;
|
||||
if (isTorCapable && callbackUrl.includes('.onion')) {
|
||||
const api = new torrific.Torsbee();
|
||||
const torResponse = await api.get(callbackUrl);
|
||||
reply = torResponse.body;
|
||||
if (reply && typeof reply === 'string') reply = JSON.parse(reply);
|
||||
} else {
|
||||
const resp = await fetch(callbackUrl, { method: 'GET' });
|
||||
if (resp.status >= 300) {
|
||||
const text = await resp.text();
|
||||
throw new Error(text);
|
||||
}
|
||||
reply = await resp.json();
|
||||
}
|
||||
const reply = await resp.json();
|
||||
|
||||
if (reply.status === 'ERROR') {
|
||||
throw new Error('Reply from server: ' + reply.reason);
|
||||
}
|
||||
|
@ -217,14 +229,22 @@ const LNDCreateInvoice = () => {
|
|||
const url = Lnurl.getUrlFromLnurl(data);
|
||||
|
||||
// calling the url
|
||||
let reply;
|
||||
try {
|
||||
const resp = await fetch(url, { method: 'GET' });
|
||||
if (resp.status >= 300) {
|
||||
throw new Error('Bad response from server');
|
||||
}
|
||||
const reply = await resp.json();
|
||||
if (reply.status === 'ERROR') {
|
||||
throw new Error('Reply from server: ' + reply.reason);
|
||||
if (isTorCapable && url.includes('.onion')) {
|
||||
const api = new torrific.Torsbee();
|
||||
const torResponse = await api.get(url);
|
||||
reply = torResponse.body;
|
||||
if (reply && typeof reply === 'string') reply = JSON.parse(reply);
|
||||
} else {
|
||||
const resp = await fetch(url, { method: 'GET' });
|
||||
if (resp.status >= 300) {
|
||||
throw new Error('Bad response from server');
|
||||
}
|
||||
reply = await resp.json();
|
||||
if (reply.status === 'ERROR') {
|
||||
throw new Error('Reply from server: ' + reply.reason);
|
||||
}
|
||||
}
|
||||
|
||||
if (reply.tag === Lnurl.TAG_PAY_REQUEST) {
|
||||
|
|
Loading…
Add table
Reference in a new issue