Skip to content

Instantly share code, notes, and snippets.

@brandonbevans
Created November 21, 2019 22:39
Show Gist options
  • Save brandonbevans/2abb3e4ba58c08c378c9e02a7b14ec47 to your computer and use it in GitHub Desktop.
Save brandonbevans/2abb3e4ba58c08c378c9e02a7b14ec47 to your computer and use it in GitHub Desktop.
Vue component for generating tax reports from Baker rewards
<template>
<v-card color="grey darken-2" id="rewards">
<v-container grid-list-md text-xs-center>
<v-layout align-center>
<v-flex xs12>
<h2 class="headline">Report Generator</h2>
<div>Enter your KT address to generate a CSV with all of your received rewards:</div>
<input v-model="address" placeholder="address"><v-btn @click="generateReport">Generate</v-btn>
</v-flex>
</v-layout>
</v-container>
</v-card>
</template>
<script>
import axios from 'axios'
export default {
name: "ReportGenerator",
data: function() {
return {
address: "",
txData: [],
rows: []
}
},
methods: {
generateReport: function() {
axios
.get("https://api.tzstats.com/tables/flow?address=" + this.address + "&operation=transaction&category=balance", {
crossdomain: true
})
.then(response => {
if (response.status === 200) {
this.txData = response.data.filter(tx =>
tx[19] === "BAKER_ADDRESS_HERE"
)
this.convertToCsv(this.txData)
} else {
//generate error
}
})
},
convertToCsv: function(txs) {
let rows = txs.map(tx => ({
timestamp: tx[3],
amount: tx[9],
destination: tx[18],
sender: tx[19]
})).filter(x => x.amount > 0)
// rows.forEach(row => {
// row.amount = row.amount / 1000000
// })
let csvContent = "data:text/csv;charset=utf-8,";
let headers = ["Transaction Type", "Buy Amount", "Buy Currency", "Date"]
csvContent += headers.join(",") + "\r\n"
rows.forEach(rowObject => {
let row =
"Income" + "," +
rowObject.amount + "," +
"XTZ" + "," + new Date(rowObject.timestamp).toISOString()
csvContent += row + "\r\n";
})
let encodedUri = encodeURI(csvContent);
let link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "delegator_rewards.csv");
document.body.appendChild(link);
link.click()
}
}
}
</script>
<style scoped>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment