From 5fa4c977fc0e0353955a624dd244ce8747be6b53 Mon Sep 17 00:00:00 2001 From: joeuhren <46763106+joeuhren@users.noreply.github.com> Date: Sat, 26 Dec 2020 22:01:36 -0700 Subject: [PATCH] More claim address feature updates -Lots of changes to the claim address page: now supports the ability to enter a wallet address instead of always being read-only; no longer displays address information summary; updated alert text and display with better icons; initial info alert denotes current claim status when viewing an existing address; you can now show/hide claim instructions which are defaulted to hidden; Submit button changed to Claim button; Updated page text and verbiage -Added new setting, "claim_address_header_menu" which shows/hides a new "Claim Address" header menu item -Claim url changed from /address/{hash}/claim to /claim and /claim/{hash} -Added additional error handling for successfully verifying a wallet address that is now known to the explorer -Added a new locale string for the "Claim Address" header menu --- app.js | 14 +++-- lib/database.js | 7 ++- lib/locale.js | 3 +- lib/settings.js | 1 + locale/en.json | 1 + routes/index.js | 26 ++++++--- settings.json.template | 2 + views/address.pug | 2 +- views/claim_address.pug | 125 ++++++++++++++++------------------------ views/layout.pug | 5 ++ 10 files changed, 94 insertions(+), 92 deletions(-) diff --git a/app.js b/app.js index 03bc8cc..df3ad31 100644 --- a/app.js +++ b/app.js @@ -279,7 +279,7 @@ app.use('/ext/getaddresstxs/:address/:start/:length', function(req,res) { }); }); -app.post('/address/:hash/claim', function(req, res) { +app.post('/claim', function(req, res) { // initialize the bad-words filter var bad_word_lib = require('bad-words'); var bad_word_filter = new bad_word_lib(); @@ -294,11 +294,17 @@ app.post('/address/:hash/claim', function(req, res) { if (body == false) { res.json({'status': 'failed', 'error': true, 'message': 'Invalid signature'}); } else if (body == true) { - db.update_label(req.body.address, req.body.message, function() { - res.json({'status': 'success'}); + db.update_label(req.body.address, req.body.message, function(val) { + // check if the update was successful + if (val == '') + res.json({'status': 'success'}); + else if (val == 'no_address') + res.json({'status': 'failed', 'error': true, 'message': 'Wallet address ' + req.body.address + ' is not valid or does not have any transactions'}); + else + res.json({'status': 'failed', 'error': true, 'message': 'Wallet address or signature is invalid'}); }); } else - res.json({'status': 'failed', 'error': true, 'message': 'There was an error. Check your console'}); + res.json({'status': 'failed', 'error': true, 'message': 'Wallet address or signature is invalid'}); }); } else { // message was filtered which would change the signature diff --git a/lib/database.js b/lib/database.js index a5764e3..84207be 100644 --- a/lib/database.js +++ b/lib/database.js @@ -287,14 +287,17 @@ module.exports = { balance: richlist.balance }, function() { // finished updating the claim label - return cb(); + return cb(''); }); } else { // finished updating the claim label - return cb(); + return cb(''); } }); }); + } else { + // address is not valid or does not have any transactions + return cb('no_address'); } }); }, diff --git a/lib/locale.js b/lib/locale.js index 3806e80..70cacff 100644 --- a/lib/locale.js +++ b/lib/locale.js @@ -14,7 +14,8 @@ exports.menu_richlist = "Rich List", exports.menu_reward = "Reward", exports.menu_movement = "Movement", exports.menu_node = "Nodes", -exports.menu_network = "Network" +exports.menu_network = "Network", +exports.menu_claim_address = "Claim Address", exports.ex_title = "Block Explorer", exports.ex_search_title = "Search", diff --git a/lib/settings.js b/lib/settings.js index 2c9030f..77ba604 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -91,6 +91,7 @@ exports.display = { "movement": true, "network": true, "claim_address": true, + "claim_address_header_menu": true, "page_header_bgcolor": "", "page_footer_bgcolor": "", "table_header_bgcolor": "", diff --git a/locale/en.json b/locale/en.json index c39f8d2..1c5cc0c 100644 --- a/locale/en.json +++ b/locale/en.json @@ -11,6 +11,7 @@ "menu_movement": "Movement", "menu_node": "Nodes", "menu_network": "Network", + "menu_claim_address": "Claim Address", // explorer view "ex_title": "Block Explorer", diff --git a/routes/index.js b/routes/index.js index 9abc5d1..4e8908f 100644 --- a/routes/index.js +++ b/routes/index.js @@ -166,15 +166,19 @@ function route_get_address(res, hash, count) { function route_get_claim_form(res, hash) { // check if claiming addresses is enabled if (settings.display.claim_address) { - db.get_address(hash, false, function(address) { - if (address) - res.render("claim_address", { active: "address", address: address, showSync: db.check_show_sync_message()}); - else - route_get_index(res, hash + ' not found'); - }); - } else { + // check if a hash was passed in + if (hash == null || hash == '') { + // no hash so just load the claim page without an address + res.render("claim_address", { active: "claim-address", hash: hash, claim_name: '', showSync: db.check_show_sync_message()}); + } else { + // lookup hash in the address collection + db.get_address(hash, false, function(address) { + // load the claim page regardless of whether the address exists or not + res.render("claim_address", { active: "claim-address", hash: hash, claim_name: (address == null || address.name == null ? '' : address.name), showSync: db.check_show_sync_message()}); + }); + } + } else route_get_address(res, hash, settings.txcount); - } } /* GET home page. */ @@ -287,7 +291,11 @@ router.get('/block/:hash', function(req, res) { route_get_block(res, req.params.hash); }); -router.get('/address/:hash/claim', function(req,res){ +router.get('/claim', function(req, res) { + route_get_claim_form(res, ''); +}); + +router.get('/claim/:hash', function(req, res) { route_get_claim_form(res, req.params.hash); }); diff --git a/settings.json.template b/settings.json.template index 9a52de3..a747f98 100644 --- a/settings.json.template +++ b/settings.json.template @@ -113,6 +113,8 @@ "network": true, // Enable/disable the ability for users to claim a wallet address. NOTE: Disabling this feature after addresses have already been claimed will effectively hide the claimed values and restore the original wallet addresses again "claim_address": true, + // Show/hide the "Claim Address" header menu item. NOTE: "claim_address" setting must also be enabled or else the header item will automatically be hidden as well + "claim_address_header_menu": true, // page_header_bgcolor: change the background color of the page header // page_footer_bgcolor: change the background color of the page footer // valid options: light, dark, primary, secondary, success, info, warning, danger or leave blank ( "" ) for default colors diff --git a/views/address.pug b/views/address.pug index ca253dc..fc7c0be 100644 --- a/views/address.pug +++ b/views/address.pug @@ -32,7 +32,7 @@ block content strong #{address.name} include ./includes/rl_labels.pug if !settings.labels[address.a_id] && settings.display.claim_address == true - a.badge.badge-pill.float-right.d-none.d-sm-block(href="/address/"+ address.a_id +"/claim" style="font-size:smaller;padding-bottom:0;") + a.badge.badge-pill.float-right.d-none.d-sm-block(href='/claim/' + address.a_id, style='font-size:smaller;padding-bottom:0;') if address.name == null || address.name == '' =" Is this yours? Claim it now for free!" else diff --git a/views/claim_address.pug b/views/claim_address.pug index c49b353..06bcbef 100644 --- a/views/claim_address.pug +++ b/views/claim_address.pug @@ -3,25 +3,47 @@ extends layout block content script. $(function () { + function generateAlertHTML(alertClass, allowDismiss, headerText, msgText) { + return '' + + (msgText == null || msgText == '' ? '' : '' + msgText + '') + + ''; + } function displayAsText(str) { return str.replace(//g, '>'); } function showClaimAlert(claimClass, warnMsg, removedClaim) { if ($('#claimAlert').length == 0) $('
').insertBefore('#claimForm'); - $('#claimAlert').html('
' + (claimClass == 'success' ? (removedClaim ? 'Address claim removed successfully' : 'Address claimed successfully') : (claimClass == 'danger' ? 'Failed to claim address' : 'Required field missing')) + '
' + (claimClass == 'success' ? 'This address will now be referred to as ' + (removedClaim ? $('input#address').val() : displayAsText($('#message').val())) + ' throughout the website' : warnMsg) + '.
'); + $('#claimAlert').html(generateAlertHTML(claimClass, true, (claimClass == 'success' ? (removedClaim ? 'Address claim removed successfully' : 'Address claimed successfully') : (claimClass == 'danger' ? 'Failed to claim address' : 'Required field missing')), (claimClass == 'success' ? '' + $('input#address').val() + ' will now be referred to as ' + (removedClaim ? $('input#address').val() : displayAsText($('#message').val())) + ' throughout the website' : warnMsg) + '.')); + fixFooterHeightAndPosition(); } - + $('#claimInstructions').on('show.bs.collapse', function () { + $('#showClaimInstructions').html('Hide claim instructions'); + }).on('hide.bs.collapse', function () { + $('#showClaimInstructions').html('Show claim instructions'); + }).on('shown.bs.collapse', function () { + fixFooterHeightAndPosition(); + }).on('hidden.bs.collapse', function () { + fixFooterHeightAndPosition(); + }); $('#claimForm').on('submit', function (e) { e.preventDefault(); var address = $('input#address').val(); var message = $('input#message').val(); var signature = $('input#signature').val(); - var url = '/address/'+address+'/claim'; + var url = '/claim'; - if (signature == null || signature.trim().length == 0) { + if (address == null || address.trim().length == 0) { + showClaimAlert('warning', 'Please enter the wallet address you wish to claim', false); + $('input#address').focus(); + } else if (signature == null || signature.trim().length == 0) { showClaimAlert('warning', 'Please enter the signature value from your wallet software', false); - $('input#signature').focus(); + $('input#signature').focus(); } else { $.ajax({ type: 'post', @@ -37,85 +59,35 @@ block content }); } }); + if ('!{hash}' != 'null' && '!{hash}' != '') { + $('
').insertBefore('#claimForm'); + $('#claimAlert').html(generateAlertHTML('info', true, ('!{claim_name}' == '' ? 'Unc' : 'C') + 'laimed address', '!{hash} is currently ' + ('!{claim_name}' == '' ? 'un' : '') + 'claimed' + ('!{claim_name}' == '' ? '' : ' as ' + displayAsText('!{claim_name}') + '.'))); + } }); - - var balance = Number((address.received - address.sent) / 100000000).toLocaleString('en',{'minimumFractionDigits':2,'maximumFractionDigits':8,'useGrouping':true}); - - var balanceParts = balance.split('.'); - - var sent = Number(address.sent /100000000).toLocaleString('en',{'minimumFractionDigits':2,'maximumFractionDigits':8,'useGrouping':true}); - - var sentParts = sent.split('.'); - - var received = Number(address.received / 100000000).toLocaleString('en',{'minimumFractionDigits':2,'maximumFractionDigits':8,'useGrouping':true}); - - var receivedParts = received.split('.'); - if address.a_id !== 'coinbase' || settings.show_sent_received == true - script. - $(document).ready(function() { - $('.summary-table').dataTable({ - info: false, - paging: false, - searching: false, - ordering: false, - responsive: true, - scrollX: true, - fnDrawCallback: function(settings) { - fixDataTableColumns(); - } - }) - }); - .col-xs-12.col-md-12.cardSpacer - if address.a_id !== 'coinbase' || settings.show_sent_received == true - .card.card-default.border-0.card-address-summary.cardSpacer - .card-header(style='position:relative;') - if typeof address.name == null || address.name == '' - strong #{address.a_id} - else - strong #{address.name} - include ./includes/rl_labels.pug - table.table.table-bordered.table-striped.summary-table.mobile-border-right(style='border-top:0;margin-top:0 !important;') - - var theadClasses = []; - if settings.display.table_header_bgcolor != null && settings.display.table_header_bgcolor != '' - - theadClasses.push('thead-' + settings.display.table_header_bgcolor); - thead(class=theadClasses) - tr - if address.a_id !== 'coinbase' - th.text-center #{settings.locale.rl_balance} - span.small (#{settings.symbol}) - if settings.show_sent_received == true - th.text-center #{settings.locale.total_sent} - span.small (#{settings.symbol}) - if address.a_id !== 'coinbase' && settings.show_sent_received == true - th.text-center #{settings.locale.total_received} - span.small (#{settings.symbol}) - if address.a_id !== 'coinbase' - th.text-center #{settings.locale.a_qr} - tbody - tr - if address.a_id !== 'coinbase' - td.text-center.addr-summary #{balanceParts[0]}. - span.decimal #{balanceParts[1]} - if settings.show_sent_received == true - td.text-center.addr-summary #{sentParts[0]}. - span.decimal #{sentParts[1]} - if address.a_id !== 'coinbase' && settings.show_sent_received == true - td.text-center.addr-summary #{receivedParts[0]}. - span.decimal #{receivedParts[1]} - if address.a_id !== 'coinbase' - td.text-center.addr-summary - img.qrcode(src='/qr/' + address.a_id) + .col-xs-12.col-md-12 .card.card-default.border-0.cardSpacer .card-header - strong Claim this Address + strong Claim Wallet Address .card-body - div.alert.alert-primary + a#showClaimInstructions.badge.badge-info(href='#claimInstructions', style='font-size:100%;margin-bottom:15px;', data-toggle='collapse' role='button' aria-expanded='false' aria-controls='claimInstructions') + i.fas.fa-angle-up(style='margin-right:5px;') + span Show claim instructions + div#claimInstructions.alert.alert-primary.collapse div - span You can use the + span Use the span.font-weight-bold Sign Message span feature from your span.font-weight-bold #{settings.coin} - span wallet to verify ownership of this address. + span wallet to verify ownership of a wallet address that belongs to you. br div Enter the following data into the wallet software: br div span.font-weight-bold Address: - span #{address.a_id} + if hash == null || hash == '' + span=' ' + else + span #{hash} div span.font-weight-bold Message: span=' ' @@ -125,11 +97,11 @@ block content span.font-weight-bold Sign Message span button in the wallet, and copy/paste the resulting span.font-weight-bold Signature - span in the form below. + span at the bottom of this form. br div span Finally, click the - span.font-weight-bold Submit + span.font-weight-bold Claim span button below to claim your address, which will display your custom display name instead of the default wallet address on this site. br div @@ -139,7 +111,10 @@ block content .form-group fieldset.entryField label(for='address') Wallet Address - input#address.form-control(type='text' value=address.a_id readonly="") + if hash == null || hash == '' + input#address.form-control(type='text', maxlength='70') + else + input#address.form-control(type='text', value=hash, readonly='readonly', maxlength='70') .form-group fieldset.entryField label(for='message') Display Name @@ -148,4 +123,4 @@ block content fieldset.entryField label(for='signature') Signature input#signature.form-control(type='text', placeholder='Signature', maxlength='100') - button.btn.btn-primary(type='submit') Submit \ No newline at end of file + button.btn.btn-success(type='submit') Claim \ No newline at end of file diff --git a/views/layout.pug b/views/layout.pug index 316c5ef..68dfa39 100644 --- a/views/layout.pug +++ b/views/layout.pug @@ -345,6 +345,11 @@ html(lang='en') a.nav-link(href='/info') span.fa.fa-info-circle span.margin-left-5 #{settings.locale.menu_api} + if settings.display.claim_address_header_menu == true && settings.display.claim_address == true + li#claim-address + a.nav-link.loading(href='/claim') + span.far.fa-address-card + span.margin-left-5 #{settings.locale.menu_claim_address} div#body-container(style='margin-top:' + (settings.sticky_header == true ? '80px;' : '20px')) if showSync != null && showSync == true .col-lg-12