From 2693dacae6b080933e76f8c052b91071554302d1 Mon Sep 17 00:00:00 2001 From: Kukks Date: Thu, 26 Mar 2020 11:59:28 +0100 Subject: [PATCH 1/5] Scan address/bip21 with camera --- BTCPayServer/BTCPayServer.csproj | 1 + BTCPayServer/Controllers/WalletsController.cs | 23 ++++-- .../Views/Wallets/WalletCameraScanner.cshtml | 50 ++++++++++++ BTCPayServer/Views/Wallets/WalletSend.cshtml | 14 ++-- BTCPayServer/bundleconfig.json | 13 ++-- .../wwwroot/js/{ => wallet}/WalletSend.js | 0 .../js/wallet/wallet-camera-scanner.js | 77 +++++++++++++++++++ .../vue-qrcode-reader.browser.js | 1 + .../vue-qrcode-reader/vue-qrcode-reader.css | 1 + 9 files changed, 165 insertions(+), 15 deletions(-) create mode 100644 BTCPayServer/Views/Wallets/WalletCameraScanner.cshtml rename BTCPayServer/wwwroot/js/{ => wallet}/WalletSend.js (100%) create mode 100644 BTCPayServer/wwwroot/js/wallet/wallet-camera-scanner.js create mode 100644 BTCPayServer/wwwroot/vendor/vue-qrcode-reader/vue-qrcode-reader.browser.js create mode 100644 BTCPayServer/wwwroot/vendor/vue-qrcode-reader/vue-qrcode-reader.css diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 655414b04..10b6c4fdc 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -120,6 +120,7 @@ + diff --git a/BTCPayServer/Controllers/WalletsController.cs b/BTCPayServer/Controllers/WalletsController.cs index 7c15f77a8..77622cacd 100644 --- a/BTCPayServer/Controllers/WalletsController.cs +++ b/BTCPayServer/Controllers/WalletsController.cs @@ -662,13 +662,26 @@ namespace BTCPayServer.Controllers uriBuilder.UnknowParameters.TryGetValue("bpu", out var vmPayJoinEndpointUrl); vm.PayJoinEndpointUrl = vmPayJoinEndpointUrl; } - catch (Exception) + catch { - TempData.SetStatusMessageModel(new StatusMessageModel() + try { - Severity = StatusMessageModel.StatusSeverity.Error, - Message = "The provided BIP21 payment URI was malformed" - }); + vm.Outputs = new List() + { + new WalletSendModel.TransactionOutput() + { + DestinationAddress = BitcoinAddress.Create(bip21, network.NBitcoinNetwork).ToString() + } + }; + } + catch + { + TempData.SetStatusMessageModel(new StatusMessageModel() + { + Severity = StatusMessageModel.StatusSeverity.Error, + Message = "The provided BIP21 payment URI was malformed" + }); + } } ModelState.Clear(); diff --git a/BTCPayServer/Views/Wallets/WalletCameraScanner.cshtml b/BTCPayServer/Views/Wallets/WalletCameraScanner.cshtml new file mode 100644 index 000000000..ac11ab5ee --- /dev/null +++ b/BTCPayServer/Views/Wallets/WalletCameraScanner.cshtml @@ -0,0 +1,50 @@ +@model WalletSendModel + + +
+ +
+ diff --git a/BTCPayServer/Views/Wallets/WalletSend.cshtml b/BTCPayServer/Views/Wallets/WalletSend.cshtml index 2530d2f20..9c62838d8 100644 --- a/BTCPayServer/Views/Wallets/WalletSend.cshtml +++ b/BTCPayServer/Views/Wallets/WalletSend.cshtml @@ -1,4 +1,5 @@ -@using Microsoft.AspNetCore.Mvc.ModelBinding +@addTagHelper *, BundlerMinifier.TagHelpers +@using Microsoft.AspNetCore.Mvc.ModelBinding @model WalletSendModel @{ Layout = "../Shared/_NavLayout.cshtml"; @@ -13,7 +14,9 @@ } +
+
@@ -198,16 +201,17 @@ }
- - + + + -@section Scripts +@section HeadScripts { - + diff --git a/BTCPayServer/wwwroot/js/wallet/wallet-camera-scanner.js b/BTCPayServer/wwwroot/js/wallet/wallet-camera-scanner.js index 783c0e8e7..73cace4ab 100644 --- a/BTCPayServer/wwwroot/js/wallet/wallet-camera-scanner.js +++ b/BTCPayServer/wwwroot/js/wallet/wallet-camera-scanner.js @@ -20,6 +20,13 @@ $(function () { }, methods: { retry: function () { + if (!this.data) { + this.close(); + this.$nextTick(function () { + this.loaded = true; + }); + return; + } this.data = ""; }, close: function () { @@ -29,7 +36,6 @@ $(function () { }, onDecode(content) { this.data = decodeURIComponent(content); - }, submitData: function () { $("#BIP21").val(this.data); From 1debbc3cdb918b53610f910c6acfccb95520d9ae Mon Sep 17 00:00:00 2001 From: Kukks Date: Fri, 27 Mar 2020 10:18:11 +0100 Subject: [PATCH 3/5] Change error messages --- BTCPayServer/wwwroot/js/wallet/wallet-camera-scanner.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BTCPayServer/wwwroot/js/wallet/wallet-camera-scanner.js b/BTCPayServer/wwwroot/js/wallet/wallet-camera-scanner.js index 73cace4ab..fbea564da 100644 --- a/BTCPayServer/wwwroot/js/wallet/wallet-camera-scanner.js +++ b/BTCPayServer/wwwroot/js/wallet/wallet-camera-scanner.js @@ -64,15 +64,15 @@ $(function () { if (error.name === 'StreamApiNotSupportedError') { self.noStreamApiSupport = true; } else if (error.name === 'NotAllowedError') { - self.errorMessage = 'Hey! I need access to your camera' + self.errorMessage = 'A permission to the camera is needed to scan the QR code.' } else if (error.name === 'NotFoundError') { - self.errorMessage = 'Do you even have a camera on your device?' + self.errorMessage = 'A camera was not detected on your device.' } else if (error.name === 'NotSupportedError') { - self.errorMessage = 'Seems like this page is served in non-secure context (HTTPS, localhost or file://)' + self.errorMessage = 'This page is served in non-secure context (HTTPS, localhost or file://)' } else if (error.name === 'NotReadableError') { self.errorMessage = 'Couldn\'t access your camera. Is it already in use?' } else if (error.name === 'OverconstrainedError') { - self.errorMessage = 'Constraints don\'t match any installed camera. Did you asked for the front camera although there is none?' + self.errorMessage = 'Constraints don\'t match any installed camera.' } else { self.errorMessage = 'UNKNOWN ERROR: ' + error.message } From 8278926e4228d83f4a11752ea8333520115063aa Mon Sep 17 00:00:00 2001 From: Kukks Date: Fri, 27 Mar 2020 10:18:20 +0100 Subject: [PATCH 4/5] change wallet send buttons --- BTCPayServer/Views/Wallets/WalletSend.cshtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BTCPayServer/Views/Wallets/WalletSend.cshtml b/BTCPayServer/Views/Wallets/WalletSend.cshtml index 9c62838d8..808c1e33f 100644 --- a/BTCPayServer/Views/Wallets/WalletSend.cshtml +++ b/BTCPayServer/Views/Wallets/WalletSend.cshtml @@ -201,8 +201,8 @@ } - - + + From 16e35e8b5533b433f45ad9648e9e5ade02b60812 Mon Sep 17 00:00:00 2001 From: Kukks Date: Fri, 27 Mar 2020 10:18:38 +0100 Subject: [PATCH 5/5] update html styles --- BTCPayServer/Views/Wallets/WalletCameraScanner.cshtml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BTCPayServer/Views/Wallets/WalletCameraScanner.cshtml b/BTCPayServer/Views/Wallets/WalletCameraScanner.cshtml index ee4fd3a7c..5081c8d0f 100644 --- a/BTCPayServer/Views/Wallets/WalletCameraScanner.cshtml +++ b/BTCPayServer/Views/Wallets/WalletCameraScanner.cshtml @@ -7,19 +7,20 @@