Browse Source

add csv export of a xpub tx history

umbrel
kenshin-samourai 4 years ago
parent
commit
5392bfa6a1
  1. 11
      static/admin/css/style.css
  2. 14
      static/admin/dmt/xpubs-tools/xpubs-tools.html
  3. 44
      static/admin/dmt/xpubs-tools/xpubs-tools.js

11
static/admin/css/style.css

@ -551,6 +551,17 @@ button {
display: inline-block;
}
#xpubs-export-actions span {
display: inline;
}
#xpubs-export-actions select {
width: 220px;
margin-left: 5px;
margin-right: 5px;
display: inline-block;
}
#xpubs-tool-details #xpub-value {
overflow: hidden;
}

14
static/admin/dmt/xpubs-tools/xpubs-tools.html

@ -62,6 +62,7 @@
<button id="btn-xpub-details-rescan" class="btn btn-success" type="button">RESCAN</button>
<button id="btn-xpub-details-retype" class="btn btn-success" type="button">RETYPE</button>
<button id="btn-xpub-details-delete" class="btn btn-success" type="button">DELETE</button>
<button id="btn-xpub-details-export" class="btn btn-success" type="button">CSV EXPORT</button>
<button id="btn-xpub-details-reset" class="btn btn-success" type="button">SEARCH ANOTHER XPUB</button>
</div>
</div>
@ -86,6 +87,19 @@
</div>
</div>
<div id="xpubs-export-actions" class="row box-main">
<div class="center">
<span>Do you want to export a list of </span>
<select id="export-type" type="select" value="full">
<option value="full" selected>all the transactions</option>
<option value="notNull">the transactions modifying the balance</option>
</select>
<span> of this XPUB?</span>
<button id="btn-xpub-export-go" class="btn btn-success" type="button">EXPORT</button>
<button id="btn-xpub-export-cancel" class="btn btn-success" type="button">CANCEL</button>
</div>
</div>
<div id="xpubs-tool-details-row1" class="row box-main">
<!-- GENERAL INFO -->
<div id="box-general" class="halfwidth-left box">

44
static/admin/dmt/xpubs-tools/xpubs-tools.js

@ -12,10 +12,13 @@ const screenXpubsToolsScript = {
$('#btn-xpub-details-reset').click(() => {this.showSearchForm()})
$('#btn-xpub-details-rescan').click(() => {this.showRescanForm()})
$('#btn-xpub-details-delete').click(() => {this.showDeletionForm()})
$('#btn-xpub-details-export').click(() => {this.showExportForm()})
$('#btn-xpub-rescan-go').click(() => {this.rescanXpub()})
$('#btn-xpub-rescan-cancel').click(() => {this.hideRescanForm()})
$('#btn-xpub-delete-go').click(() => {this.deleteXpub()})
$('#btn-xpub-delete-cancel').click(() => {this.hideDeletionForm()})
$('#btn-xpub-export-go').click(() => {this.exportXpubHistory()})
$('#btn-xpub-export-cancel').click(() => {this.hideExportForm()})
$('#btn-xpub-import-go').click(() => {this.importXpub()})
$('#btn-xpub-details-retype').click(() => {this.showImportForm(true)})
$('#btn-xpub-import-cancel').click(() => {this.hideImportForm(this.isReimport)})
@ -33,6 +36,7 @@ const screenXpubsToolsScript = {
this.hideRescanForm()
this.hideDeletionForm()
this.hideExportForm()
this.showSearchForm()
$("#xpub").focus()
},
@ -148,6 +152,35 @@ const screenXpubsToolsScript = {
})
},
exportXpubHistory: function() {
lib_msg.displayMessage('Exporting the transactional history of this xpub. Please wait...')
const args = {
'active': this.currentXpub,
'page': 0,
'count': 1000000000
}
if ($('#export-type').val() == 'notNull')
args['excludeNullXfer'] = 1
return lib_api.getTransactions(args)
.then(result => {
if (result['txs'] && result['txs'].length > 0) {
let content = 'data:text/csv;charset=utf-8,'
content += 'height,txid,date,flow\n'
for (let tx of result['txs'])
content += `${tx['block_height']},${tx['hash']},${new Date(tx['time']*1000).toString()},${tx['result']/100000000}\n`
const encodedURI = encodeURI(content)
window.open(encodedURI)
}
this.hideExportForm()
lib_msg.displayInfo('Transactional history successfully exported.')
}).catch(e => {
lib_errors.processError(e)
})
},
checkRescanStatus: function(callback) {
this.rescanStatusTimerId = setTimeout(() => {
lib_api.getXpubRescanStatus(this.currentXpub)
@ -312,6 +345,17 @@ const screenXpubsToolsScript = {
$('#xpubs-tool-actions').show()
},
showExportForm: function() {
$('#xpubs-tool-actions').hide()
$('#xpubs-export-actions').show()
lib_msg.cleanMessagesUi()
},
hideExportForm: function() {
$('#xpubs-export-actions').hide()
$('#xpubs-tool-actions').show()
},
}
screenScripts.set('#screen-xpubs-tools', screenXpubsToolsScript)

Loading…
Cancel
Save