diff --git a/website/static/js/validate-btc.js b/website/static/js/validate-btc.js index 6fdf6d97c..4e264bf55 100644 --- a/website/static/js/validate-btc.js +++ b/website/static/js/validate-btc.js @@ -28,7 +28,7 @@ function validateBCH(address) { * Params: BCH Address * ***/ if (address == null || address == "" || address == " ") { - return false; + return "empty"; } if (address.startsWith("bitcoincash:")) { address = address.slice(12); @@ -50,7 +50,7 @@ function validateEthereum(address) { let regex = new RegExp(/^(0x)?[0-9a-fA-F]{40}$/); if (address == null || address == "" || address == " ") { - return false; + return "empty"; } else if (regex.test(address) == true) { return true; } else { @@ -65,13 +65,53 @@ function validateBitCoin(address) { * ***/ let regex = new RegExp(/^(bc1|[13])[a-km-zA-HJ-NP-Z1-9]{25,34}$/); if (address == null || address == "" || address == " ") { - return false; + return "empty"; } else if (regex.test(address) == true) { return true; } else { return false; } } + +async function CryptoEditForm(crypto, selected_c) { + if(selected_c == "BTC"){ + selected_c = "Bitcoin" + var isValidAddress = validateBitCoin(crypto); + }else if(selected_c == "BCH"){ + selected_c = "BitcoinCash" + var isValidAddress = validateBCH(crypto); + }else if(selected_c == "ETH"){ + selected_c = "Ethereum" + var isValidAddress = validateEthereum(crypto); + }else{ + $.notify("Please select a Crypto Address", { + style: "custom", + className: "danger" + }); + return; + } + if(isValidAddress == true){ + const data = { + selected_crypto: selected_c, + new_address: crypto + }; + const request = await fetch("/update_bch_address/", { + method: 'POST', + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify(data), + }); + if(request.status == 200){ + window.location.reload(); + } + }else{ + $.notify("Please enter a valid Crypto Address", { + style: "custom", + className: "danger" + }); + } +} // TEST THE VALIDATORS // BitCoin VALIDATOR // Uncomment the below code diff --git a/website/templates/includes/crypto_donation.html b/website/templates/includes/crypto_donation.html index 34272423d..da15c7fed 100644 --- a/website/templates/includes/crypto_donation.html +++ b/website/templates/includes/crypto_donation.html @@ -8,27 +8,27 @@ width="32px" height="32px">
- {% if object.user.userprofile.btc_address %} - {% include "./tiny-cards.html" with insideIFCondition=True left="BTC" right=object.user.userprofile.btc_address lessWidth=True %} + {% if user.userprofile.btc_address %} + {% include "./tiny-cards.html" with insideIFCondition=True left="BTC" right=user.userprofile.btc_address|slice:":40" lessWidth=True editCrypto=True %} {% endif %} - {% if object.user.userprofile.bch_address %} - {% include "./tiny-cards.html" with insideIFCondition=True left="BCH" right=object.user.userprofile.bch_address lessWidth=True %} + {% if user.userprofile.bch_address %} + {% include "./tiny-cards.html" with insideIFCondition=True left="BCH" right=user.userprofile.bch_address|slice:":40" lessWidth=True editCrypto=True %} {% endif %} - {% if object.user.userprofile.eth_address %} - {% include "./tiny-cards.html" with insideIFCondition=True left="ETH" right=object.user.userprofile.eth_address lessWidth=True %} + {% if user.userprofile.eth_address %} + {% include "./tiny-cards.html" with insideIFCondition=True left="ETH" right=user.userprofile.eth_address|slice:":40" lessWidth=True editCrypto=True %} {% endif %}
- + {% endblock content %} diff --git a/website/views.py b/website/views.py index 4ca8f53c9..20e7369e3 100644 --- a/website/views.py +++ b/website/views.py @@ -4231,7 +4231,6 @@ def get_context_data(self, **kwargs): context["bookmarked"] = self.request.user.userprofile.issue_saved.filter( pk=self.object.id ).exists() - context["screenshots"] = IssueScreenshot.objects.filter(issue=self.object).all() context["status"] = Issue.objects.filter(id=self.object.id).get().status context["github_issues_url"] = ( @@ -4540,10 +4539,12 @@ def trademark_detailview(request, slug): # headers=headers, # ) # mail.logout() +@csrf_exempt def update_bch_address(request): if request.method == "POST": - selected_crypto = request.POST.get("selected_crypto") - new_address = request.POST.get("new_address") + data = json.loads(request.body) + selected_crypto = data.get("selected_crypto") + new_address = data.get("new_address") if selected_crypto and new_address: try: user_profile = request.user.userprofile