-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
226 lines (187 loc) · 6.53 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Export Stellar Transactions</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.21.0/moment.js"></script>
<style>
* {
text-align: center;
padding: 2px;
font-size: 1.1em;
}
.content {
width: 90%;
margin: auto
}
input[type="text"],
input[type="button"],
select {
display: block;
width: 50%;
margin: 10px auto;
padding: 10px;
border: 1ps solid lightgrey;
-ms-box-sizing: content-box;
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
}
input[type="button"] {
background: #08b5e5;
border-radius: 5px;
color: white;
padding: 10px;
border: 1px solid #08b5e5;
}
input[type="button"]:disabled {
background: #5a5a5a;
border: 1px solid #5a5a5a;
}
select {
background: transparent;
}
table {
margin: 0 auto;
text-align: left;
border-spacing: 0;
font-size: .8em;
}
td {
padding: 5px;
border-left: 1px solid gray;
border-spacing: 0;
}
td:last-child {
border-right: 1px solid gray;
}
</style>
</head>
<body>
<div class="content">
<div>DO NOT USE TO DO YOUR TAXES</div>
<div class="note">This will export the payments sent from Source Address (theirs) to Destination Address (yours).</div>
<div class="note">Proof of concept, does not export all transactions</div>
<div>By using this you accept the attached
<a href="https://github.com/ZanderAdam/StellarTransactionExport/blob/master/LICENSE">
license</a>
</div>
<div>Use Debug Console (F12) to look for info</div>
<a href="https://github.com/ZanderAdam/StellarTransactionExport">Fork the code</a>
<hr>
<div>Sample Data: inflation pool payout to some random address</div>
<div>Destination Address: GD67AOC2P4U22NUPPJFC32WN4INSVA6GLTVIZY3ORYVRXV2HUF6FGTBR</div>
<div>Source Address: GA3FUYFOPWZ25YXTCA73RK2UGONHCO27OHQRSGV3VCE67UEPEFEDCOPA</div>
<input type="text" value="GD67AOC2P4U22NUPPJFC32WN4INSVA6GLTVIZY3ORYVRXV2HUF6FGTBR" id="destinationAddress" placeholder="Destination Address">
<input type="text" value="GA3FUYFOPWZ25YXTCA73RK2UGONHCO27OHQRSGV3VCE67UEPEFEDCOPA" id="sourceAddress" placeholder="Source Address">
<select id="timeframe">
<option value="30days">Last 30 Days</option>
<option value="year">Last 1 Year</option>
<option value="prevYear">Previous Year</option>
</select>
<input type="button" value="Load Payments" id="get">
<input type="button" value="Export CSV" id="export" disabled>
<table>
<thead>
<td>Date</td>
<td>Amount</td>
</thead>
<tbody id="data">
</tbody>
</table>
</div>
<script>
var loadedPayments = [];
document.getElementById("get").onclick = function () {
sourceAddress = document.getElementById('sourceAddress').value;
destinationAddress = document.getElementById('destinationAddress').value;
if (!sourceAddress || !destinationAddress) {
console.error("Source Address and/or Destination Address missing");
return;
}
var timeFrameValue = document.getElementById("timeframe").value;
endDate = moment();
startDate = moment().subtract(30, 'days').startOf('day');
switch (timeFrameValue) {
case 'year':
startDate = moment().subtract(1, 'year').startOf('day');
break;
case 'prevYear':
endDate = moment().startOf('year');
timeFrameValue
startDate = moment().startOf('year').subtract(1, 'year');
break;
}
var url = 'https://horizon.stellar.org/accounts/' + destinationAddress + '/payments?limit=200&order=desc'
getData(url, sourceAddress, startDate, endDate, function (payments) {
loadedPayments = payments;
var dataTable = document.getElementById("data");
dataTable.innerHTML = '';
payments.forEach(function (payment) {
dataTable.innerHTML += `<tr><td>${payment.date.format()}</td><td>${payment.amount}</td></tr>`;
});
document.getElementById("export").disabled = false;
});
}
document.getElementById("export").onclick = function () {
var timeFrameValue = document.getElementById("timeframe").value;
var sourceAddress = document.getElementById('sourceAddress').value;
//create csv
var csvFile = 'Date,Amount(XLM)';
loadedPayments.forEach(function (payment) {
csvFile += '\n' + payment.date.format() + ',' + payment.amount;
})
//download as file
var a = document.createElement('a');
var file = new Blob([csvFile], {
type: 'csv'
});
a.href = URL.createObjectURL(file);
a.download = `${sourceAddress.substring(0,5)}_${timeFrameValue}_PaymentsExport.csv`;
a.click();
}
function getData(url, sourceAddress, startDate, endDate, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
var payments = JSON.parse(xmlHttp.responseText);
processPayments(payments, sourceAddress, startDate, endDate, callback);
} else if (xmlHttp.status == 404) {
callback([]);
}
}
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function processPayments(payments, sourceAddress, startDate, endDate, callback) {
var paymentsOfInterest = [];
var lastPaymentDate;
var records = payments['_embedded'].records;
if (records.length == 0) {
callback(paymentsOfInterest);
return;
}
records.forEach(function (payment) {
lastPaymentDate = moment(payment['created_at']);
if (!lastPaymentDate.isBetween(startDate, endDate)) {
return;
}
if (payment['source_account'] == sourceAddress) {
paymentsOfInterest.push({
date: lastPaymentDate,
amount: payment.amount
});
}
});
if (lastPaymentDate.isAfter(startDate))
getData(payments['_links'].prev.href, sourceAddress, startDate, endDate, function (newPayments) {
callback(paymentsOfInterest.concat(newPayments));
});
else
callback(paymentsOfInterest);
}
</script>
</body>
</html>