mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-26 08:55:56 +01:00
FIX: some cases of lnurl-withdraw
This commit is contained in:
parent
3e3b5fc5da
commit
be0c44669c
5 changed files with 34 additions and 12 deletions
class
loc
screen/lnd
tests/unit
|
@ -9,7 +9,7 @@ const createHash = require('create-hash');
|
|||
*/
|
||||
export default class Lnurl {
|
||||
static TAG_PAY_REQUEST = 'payRequest'; // type of LNURL
|
||||
static TAG_WITHDRAW_REQUEST = "withdrawRequest"; // type of LNURL
|
||||
static TAG_WITHDRAW_REQUEST = 'withdrawRequest'; // type of LNURL
|
||||
|
||||
constructor(url, AsyncStorage) {
|
||||
this._lnurl = url;
|
||||
|
@ -31,12 +31,12 @@ export default class Lnurl {
|
|||
const found = Lnurl.findlnurl(lnurlExample);
|
||||
if (!found) return false;
|
||||
|
||||
const decoded = bech32.decode(lnurlExample, 10000);
|
||||
const decoded = bech32.decode(found, 10000);
|
||||
return Buffer.from(bech32.fromWords(decoded.words)).toString();
|
||||
}
|
||||
|
||||
static isLnurl(url) {
|
||||
return Lnurl.findlnurl(url) !== null
|
||||
return Lnurl.findlnurl(url) !== null;
|
||||
}
|
||||
|
||||
async fetchGet(url) {
|
||||
|
|
|
@ -405,6 +405,7 @@
|
|||
"xpub_copiedToClipboard": "Copied to clipboard.",
|
||||
"pull_to_refresh": "Pull to Refresh",
|
||||
"warning_do_not_disclose": "Warning! Do not disclose",
|
||||
"add_ln_wallet_first": "You must first add a Lightning wallet.",
|
||||
"xpub_title": "Wallet XPUB"
|
||||
},
|
||||
"multisig": {
|
||||
|
|
|
@ -42,7 +42,7 @@ const LNDCreateInvoice = () => {
|
|||
const { name } = useRoute();
|
||||
const { colors } = useTheme();
|
||||
const { navigate, dangerouslyGetParent, goBack, pop, setParams } = useNavigation();
|
||||
const [unit, setUnit] = useState(wallet.current.getPreferredBalanceUnit());
|
||||
const [unit, setUnit] = useState(wallet.current?.getPreferredBalanceUnit() || BitcoinUnit.BTC);
|
||||
const [amount, setAmount] = useState();
|
||||
const [renderWalletSelectionButtonHidden, setRenderWalletSelectionButtonHidden] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
@ -131,6 +131,10 @@ const LNDCreateInvoice = () => {
|
|||
},
|
||||
});
|
||||
}
|
||||
} else {
|
||||
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
||||
alert(loc.wallets.add_ln_wallet_first);
|
||||
goBack();
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [wallet]),
|
||||
|
@ -194,7 +198,7 @@ const LNDCreateInvoice = () => {
|
|||
|
||||
navigate('LNDViewInvoice', {
|
||||
invoice: invoiceRequest,
|
||||
walletID,
|
||||
walletID: wallet.current.getID(),
|
||||
isModal: true,
|
||||
});
|
||||
} catch (Err) {
|
||||
|
@ -206,11 +210,6 @@ const LNDCreateInvoice = () => {
|
|||
|
||||
const processLnurl = async data => {
|
||||
setIsLoading(true);
|
||||
if (!wallet) {
|
||||
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
||||
alert('Before paying a Lightning invoice, you must first add a Lightning wallet.');
|
||||
return goBack();
|
||||
}
|
||||
|
||||
// decoding the lnurl
|
||||
const url = Lnurl.getUrlFromLnurl(data);
|
||||
|
@ -233,7 +232,7 @@ const LNDCreateInvoice = () => {
|
|||
screen: 'LnurlPay',
|
||||
params: {
|
||||
lnurl: data,
|
||||
fromWalletID: walletID || wallet.current.getID(),
|
||||
fromWalletID: wallet.current.getID(),
|
||||
},
|
||||
});
|
||||
return;
|
||||
|
@ -342,7 +341,7 @@ const LNDCreateInvoice = () => {
|
|||
pop();
|
||||
};
|
||||
|
||||
if (wallet.current === undefined || !walletID) {
|
||||
if (!wallet.current) {
|
||||
return (
|
||||
<View style={[styles.root, styleHooks.root]}>
|
||||
<StatusBar barStyle="light-content" />
|
||||
|
|
|
@ -165,6 +165,22 @@ describe('unit - DeepLinkSchemaMatch', function () {
|
|||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
argument: {
|
||||
url:
|
||||
'https://lnbits.com/?lightning=LNURL1DP68GURN8GHJ7MRWVF5HGUEWVDHK6TMHD96XSERJV9MJ7CTSDYHHVVF0D3H82UNV9UM9JDENFPN5SMMK2359J5RKWVMKZ5ZVWAV4VJD63TM',
|
||||
},
|
||||
expected: [
|
||||
'LNDCreateInvoiceRoot',
|
||||
{
|
||||
screen: 'LNDCreateInvoice',
|
||||
params: {
|
||||
uri:
|
||||
'https://lnbits.com/?lightning=LNURL1DP68GURN8GHJ7MRWVF5HGUEWVDHK6TMHD96XSERJV9MJ7CTSDYHHVVF0D3H82UNV9UM9JDENFPN5SMMK2359J5RKWVMKZ5ZVWAV4VJD63TM',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const asyncNavigationRouteFor = async function (event) {
|
||||
|
|
|
@ -21,6 +21,12 @@ describe('LNURL', function () {
|
|||
Lnurl.getUrlFromLnurl('LNURL1DP68GURN8GHJ7MRWW3UXYMM59E3XJEMNW4HZU7RE0GHKCMN4WFKZ7URP0YLH2UM9WF5KG0FHXYCNV9G9W58'),
|
||||
'https://lntxbot.bigsun.xyz/lnurl/pay?userid=7116',
|
||||
);
|
||||
assert.strictEqual(
|
||||
Lnurl.getUrlFromLnurl(
|
||||
'https://lnbits.com/?lightning=LNURL1DP68GURN8GHJ7MRWVF5HGUEWVDHK6TMHD96XSERJV9MJ7CTSDYHHVVF0D3H82UNV9UM9JDENFPN5SMMK2359J5RKWVMKZ5ZVWAV4VJD63TM',
|
||||
),
|
||||
'https://lnbits.com/withdraw/api/v1/lnurl/6Y73HgHovThYPvs7aPLwYV',
|
||||
);
|
||||
assert.strictEqual(Lnurl.getUrlFromLnurl('bs'), false);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue