forked from JSKitty/scc-web3
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
3,066 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<script setup> | ||
import { useWallet } from '../composables/use_wallet'; | ||
import Modal from '../Modal.vue'; | ||
import { KoinlyExport } from '../tx_export/koinly_export.js'; | ||
import { ref } from 'vue'; | ||
import { translation } from '../i18n.js'; | ||
const wallet = useWallet(); | ||
const showConfirmationModal = ref(false); | ||
function exportToCsv() { | ||
console.log(JSON.stringify(wallet.getHistoricalTxs())); | ||
const koinlyExport = new KoinlyExport(wallet.getHistoricalTxs()); | ||
const csvBlob = new Blob([koinlyExport.getCsv()], { type: 'text/csv' }); | ||
const csvURL = URL.createObjectURL(csvBlob); | ||
const downloadLink = document.createElement('a'); | ||
downloadLink.href = csvURL; | ||
downloadLink.download = 'MPW-transactions.csv'; | ||
document.body.appendChild(downloadLink); | ||
downloadLink.click(); | ||
document.body.removeChild(downloadLink); | ||
showConfirmationModal.value = false; | ||
} | ||
</script> | ||
|
||
<template> | ||
<i class="fa-solid fa-file-csv" @click="showConfirmationModal = true"></i> | ||
<Teleport to="body"> | ||
<Modal :show="showConfirmationModal"> | ||
<template #header> | ||
<h3 | ||
class="modal-title" | ||
style="text-align: center; width: 100%; color: #8e21ff" | ||
> | ||
{{ translation.exportToCsv }} | ||
</h3> | ||
</template> | ||
|
||
<template #body> | ||
{{ translation.exportToCsvBody }} | ||
</template> | ||
<template #footer> | ||
<button | ||
data-i18n="popupConfirm" | ||
type="button" | ||
class="pivx-button-big" | ||
style="float: right" | ||
@click="exportToCsv()" | ||
> | ||
Confirm | ||
</button> | ||
<button | ||
type="button" | ||
class="pivx-button-big-cancel" | ||
style="float: right" | ||
@click="showConfirmationModal = false" | ||
> | ||
{{ translation.popupCancel }} | ||
</button> | ||
</template> | ||
</Modal> | ||
</Teleport> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { TxExport } from './tx_export.js'; | ||
import { HistoricalTxType } from '../historical_tx.js'; | ||
|
||
export class KoinlyExport extends TxExport { | ||
getCsv() { | ||
const res = [['Koinly Date', 'Amount', 'Currency', 'Label', 'TxHash']]; | ||
this.transactions.forEach((t) => { | ||
const type = this.getLabel(t.type); | ||
if (type !== 'SKIP') | ||
res.push([ | ||
this.convertToUTCDateTime(t.time * 1000), | ||
t.amount, | ||
'PIVX', | ||
this.getLabel(t.type), | ||
t.id, | ||
]); | ||
}); | ||
return this.arrayToCsv(res); | ||
} | ||
|
||
getLabel(type) { | ||
switch (type) { | ||
case HistoricalTxType.STAKE: | ||
return 'REWARD'; | ||
case HistoricalTxType.DELEGATION: | ||
case HistoricalTxType.UNDELEGATION: | ||
return 'SKIP'; | ||
case HistoricalTxType.SENT: | ||
case HistoricalTxType.PROPOSAL_FEE: | ||
return 'Send'; | ||
case HistoricalTxType.RECEIVED: | ||
return 'Income'; | ||
case HistoricalTxType.UNKNOWN: | ||
default: | ||
return 'UNKNOWN'; | ||
} | ||
} | ||
|
||
convertToUTCDateTime(time) { | ||
const date = new Date(time); | ||
const year = date.getUTCFullYear(); | ||
const month = String(date.getUTCMonth() + 1).padStart(2, '0'); | ||
const day = String(date.getUTCDate()).padStart(2, '0'); | ||
const hours = String(date.getUTCHours()).padStart(2, '0'); | ||
const minutes = String(date.getUTCMinutes()).padStart(2, '0'); | ||
return `${year}-${month}-${day} ${hours}:${minutes} UTC`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Abstract class for exporting Txs | ||
*/ | ||
export class TxExport { | ||
/** | ||
* @type{import('../historical_tx.js').HistoricalTx[]} transactions | ||
*/ | ||
transactions = []; | ||
|
||
/** | ||
* @param{import('../historical_tx.js').HistoricalTx[]} transactions | ||
*/ | ||
constructor(transactions) { | ||
if (new.target === TxExport) { | ||
throw new Error('Cannot instantiate an abstract class'); | ||
} | ||
this.transactions = transactions; | ||
} | ||
|
||
/** | ||
* @param {string[][]} array | ||
*/ | ||
arrayToCsv(array) { | ||
return array.map((a) => a.join(',')).join('\n'); | ||
} | ||
|
||
/** | ||
* @returns {string} csv encoded export | ||
*/ | ||
getCsv() { | ||
throw new Error('getCsv not implemented'); | ||
} | ||
} |
Oops, something went wrong.