NFC finetuning (#4822)

This commit is contained in:
d11n
2023-03-28 12:36:32 +02:00
committed by GitHub
parent 8b6c7a6061
commit 22657b66d7
3 changed files with 13 additions and 17 deletions

View File

@@ -71,7 +71,6 @@ namespace BTCPayServer.Tests
Assert.Equal(address, copyAddress);
Assert.Equal($"bitcoin:{address.ToUpperInvariant()}", qrValue);
s.Driver.ElementDoesNotExist(By.Id("Lightning_BTC"));
s.Driver.ElementDoesNotExist(By.Id("PayByLNURL"));
// Details should show exchange rate
s.Driver.ToggleCollapse("PaymentDetails");
@@ -89,7 +88,6 @@ namespace BTCPayServer.Tests
Assert.StartsWith("lightning:lnurl", payUrl);
Assert.StartsWith("lnurl", s.Driver.WaitForElement(By.Id("Lightning_BTC")).GetAttribute("value"));
s.Driver.ElementDoesNotExist(By.Id("Address_BTC"));
s.Driver.FindElement(By.Id("PayByLNURL"));
});
// Default payment method
@@ -108,7 +106,6 @@ namespace BTCPayServer.Tests
Assert.Equal(address, copyAddress);
Assert.Equal($"lightning:{address.ToUpperInvariant()}", qrValue);
s.Driver.ElementDoesNotExist(By.Id("Address_BTC"));
s.Driver.FindElement(By.Id("PayByLNURL"));
// Lightning amount in sats
Assert.Contains("BTC", s.Driver.FindElement(By.Id("AmountDue")).Text);
@@ -247,7 +244,6 @@ namespace BTCPayServer.Tests
Assert.StartsWith("lnbcrt", copyAddressLightning);
Assert.StartsWith($"bitcoin:{address.ToUpperInvariant()}?amount=", qrValue);
Assert.Contains("&lightning=LNBCRT", qrValue);
s.Driver.FindElement(By.Id("PayByLNURL"));
// Check details
s.Driver.ToggleCollapse("PaymentDetails");
@@ -284,7 +280,6 @@ namespace BTCPayServer.Tests
payUrl = s.Driver.FindElement(By.Id("PayInWallet")).GetAttribute("href");
Assert.StartsWith("bitcoin:", payUrl);
Assert.Contains("&lightning=lnbcrt", payUrl);
s.Driver.FindElement(By.Id("PayByLNURL"));
// Check details
s.Driver.ToggleCollapse("PaymentDetails");
@@ -317,7 +312,6 @@ namespace BTCPayServer.Tests
Assert.Equal(address, copyAddressOnchain);
Assert.StartsWith("lnurl", copyAddressLightning);
Assert.StartsWith($"bitcoin:{address.ToUpperInvariant()}?lightning=LNURL", qrValue);
s.Driver.FindElement(By.Id("PayByLNURL"));
// Check details
s.Driver.ToggleCollapse("PaymentDetails");
@@ -384,7 +378,6 @@ namespace BTCPayServer.Tests
payUrl = s.Driver.FindElement(By.Id("PayInWallet")).GetAttribute("href");
Assert.StartsWith("bitcoin:", payUrl);
Assert.Contains("&lightning=lnbcrt", payUrl);
s.Driver.FindElement(By.Id("PayByLNURL"));
// Language Switch
var languageSelect = new SelectElement(s.Driver.FindElement(By.Id("DefaultLang")));

View File

@@ -6,13 +6,11 @@
<p id="CheatSuccessMessage" class="alert alert-success text-break" v-if="successMessage" v-text="successMessage"></p>
<p id="CheatErrorMessage" class="alert alert-danger text-break" v-if="errorMessage" v-text="errorMessage"></p>
<template v-if="isV2">
<button class="btn btn-secondary rounded-pill w-100" type="button"
:disabled="scanning || submitting" v-on:click="handleClick" :id="btnId"
:class="{ 'text-secondary': !supported }">{{btnText}}</button>
<button class="btn btn-secondary rounded-pill w-100" type="button" id="PayByNFC"
:disabled="scanning || submitting" v-on:click="handleClick">{{btnText}}</button>
</template>
<bp-loading-button v-else>
<button class="action-button" style="margin: 0 45px;width:calc(100% - 90px) !important"
:disabled="scanning || submitting" v-on:click="startScan" :id="btnId"
<button class="action-button" style="margin: 0 45px;width:calc(100% - 90px) !important" :disabled="scanning || submitting" v-on:click="handleClick" id="PayByNFC"
:class="{ 'loading': scanning || submitting, 'action-button': supported, 'btn btn-text w-100': !supported }">
<span class="button-text">{{btnText}}</span>
<div class="loader-wrapper">
@@ -44,14 +42,15 @@ Vue.component("lnurl-withdraw-checkout", {
!!availablePaymentMethods.find(pm => ['BTC_LNURLPAY', 'BTC_LightningLike'].includes(pm.paymentMethodId)) ||
// Or the BIP21 payment URL flags Lightning support
!!paymentUrl.match(/lightning=ln/i)
return activePaymentMethodId === 'BTC_LNURLPAY' || (
const isAvailable = activePaymentMethodId === 'BTC_LNURLPAY' || (
// Unified QR/BIP21 case
(activePaymentMethodId === 'BTC' && isUnified && lnurlwAvailable) ||
// Lightning with LNURL available
(activePaymentMethodId === 'BTC_LightningLike' && lnurlwAvailable))
return isAvailable && (this.supported || this.testFallback)
},
btnId () {
return this.supported ? 'PayByNFC' : 'PayByLNURL'
testFallback () {
return !this.supported && window.location.search.match('lnurlwtest=(1|true)')
},
btnText () {
if (this.supported) {
@@ -89,6 +88,11 @@ Vue.component("lnurl-withdraw-checkout", {
this.startScan()
}
},
beforeDestroy () {
if (this.readerAbortController) {
this.readerAbortController.abort()
}
},
methods: {
async handleClick () {
if (this.supported) {
@@ -140,7 +144,6 @@ Vue.component("lnurl-withdraw-checkout", {
ndef.onreadingerror = () => {
this.errorMessage = "Could not read NFC tag";
this.readerAbortController.abort()
}
ndef.onreading = async ({ message, serialNumber }) => {

View File

@@ -137,7 +137,7 @@
<vc:icon symbol="caret-down" />
</button>
<p class="text-center mt-3" v-t="'payment_sent_body'"></p>
<p class="text-center" v-if="srvModel.receivedConfirmations !== null && srvModel.requiredConfirmations != null" v-t="{ path: 'payment_sent_confirmations', args: { cryptoCode: realCryptoCode, receivedConfirmations: srvModel.receivedConfirmations, requiredConfirmations: srvModel.requiredConfirmations } }"></p>
<p class="text-center" v-if="srvModel.receivedConfirmations !== null && srvModel.requiredConfirmations" v-t="{ path: 'payment_sent_confirmations', args: { cryptoCode: realCryptoCode, receivedConfirmations: srvModel.receivedConfirmations, requiredConfirmations: srvModel.requiredConfirmations } }"></p>
</div>
</div>
<div v-if="isSettled" id="settled" key="settled">