Skip to content

Commit

Permalink
Add csv export
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino committed Jan 27, 2025
1 parent 552cca6 commit a3b243c
Show file tree
Hide file tree
Showing 21 changed files with 3,066 additions and 2 deletions.
2 changes: 2 additions & 0 deletions locale/cnr/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.
exportToCsv = "" # Export transactions
exportToCsvBody = "" # Do you want to export your transactions as CSV?

[ALERTS]
INTERNAL_ERROR = "Interna greška, molimo pokušajte ponovo kasnije" # Internal error, please try again later
Expand Down
2 changes: 2 additions & 0 deletions locale/de/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.
exportToCsv = "" # Export transactions
exportToCsvBody = "" # Do you want to export your transactions as CSV?

[ALERTS]
INTERNAL_ERROR = "Interner Fehler, bitte versuche es später erneut" # Internal error, please try again later
Expand Down
2 changes: 2 additions & 0 deletions locale/en/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ proposalOverBudget = "Over Budget" # Over Budget
badSaplingRoot = "There was an error while syncing. Resyncing from scratch (Bad sapling root)" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "Creating SHIELD transaction..." # Creating SHIELD transaction...
immatureRewards = "Part of your staked balance may be locked for 100 blocks as your reward matures." # Part of your staked balance may be locked for 100 blocks as your reward matures.
exportToCsv = "Export transactions" # Export transactions
exportToCsvBody = "Do you want to export your transactions as CSV?" # Do you want to export your transactions as CSV?

[ALERTS]
INTERNAL_ERROR = "Internal error, please try again later" # Internal error, please try again later
Expand Down
2 changes: 2 additions & 0 deletions locale/es-mx/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.
exportToCsv = "" # Export transactions
exportToCsvBody = "" # Do you want to export your transactions as CSV?

[ALERTS]
INTERNAL_ERROR = "Error interno, vuelve a intentarlo más tarde" # Internal error, please try again later
Expand Down
2 changes: 2 additions & 0 deletions locale/fr/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.
exportToCsv = "" # Export transactions
exportToCsvBody = "" # Do you want to export your transactions as CSV?

[ALERTS]
INTERNAL_ERROR = "Erreur interne, veuillez réessayer plus tard" # Internal error, please try again later
Expand Down
2 changes: 2 additions & 0 deletions locale/hi/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ cantShieldToExc = "यह एड्रेस शील्ड ट्रांस
badSaplingRoot = "सिंक करते समय एक त्रुटि हुई। रिसिंकिंग कर रहे हैं स्क्रैच से(खराब सैपलिंग रूट)" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "क्रिएटिंग शील्ड ट्रांजेक्शन..." # Creating SHIELD transaction...
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.
exportToCsv = "" # Export transactions
exportToCsvBody = "" # Do you want to export your transactions as CSV?

[ALERTS]
INTERNAL_ERROR = "आंतरिक त्रुटि, कृपया कुछ समय बाद पुनः प्रयास करें" # Internal error, please try again later
Expand Down
2 changes: 2 additions & 0 deletions locale/it/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.
exportToCsv = "" # Export transactions
exportToCsvBody = "" # Do you want to export your transactions as CSV?

[ALERTS]
INTERNAL_ERROR = "Errore interno, rirova più tardi" # Internal error, please try again later
Expand Down
2 changes: 2 additions & 0 deletions locale/nl/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.
exportToCsv = "" # Export transactions
exportToCsvBody = "" # Do you want to export your transactions as CSV?

[ALERTS]
INTERNAL_ERROR = "Interne fout, probeer het later opnieuw" # Internal error, please try again later
Expand Down
2 changes: 2 additions & 0 deletions locale/ph/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.
exportToCsv = "" # Export transactions
exportToCsvBody = "" # Do you want to export your transactions as CSV?

[ALERTS]
INTERNAL_ERROR = "Internal error, Pakiusap uliting muli" # Internal error, please try again later
Expand Down
2 changes: 2 additions & 0 deletions locale/pl/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.
exportToCsv = "" # Export transactions
exportToCsvBody = "" # Do you want to export your transactions as CSV?

[ALERTS]
INTERNAL_ERROR = "Błąd wewnętrzny, spróbuj ponownie później" # Internal error, please try again later
Expand Down
2 changes: 2 additions & 0 deletions locale/pt-br/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.
exportToCsv = "" # Export transactions
exportToCsvBody = "" # Do you want to export your transactions as CSV?

[ALERTS]
STAKE_ADDR_SET = "<b>Endereço de Cold Staking definido!</b><br>Ao fazer Stake no futuro este endereço irá ser usado." # <b>Cold Address set!</b><br>Future stakes will use this address.
Expand Down
2 changes: 2 additions & 0 deletions locale/pt-pt/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.
exportToCsv = "" # Export transactions
exportToCsvBody = "" # Do you want to export your transactions as CSV?

[ALERTS]
STAKE_ADDR_SET = "<b>Endereço de Cold Staking definido!</b><br>Ao fazer Stake no futuro irá ser usado este endereço." # <b>Cold Address set!</b><br>Future stakes will use this address.
Expand Down
2 changes: 2 additions & 0 deletions locale/template/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ cantShieldToExc = "This address does not support shield transfers"
badSaplingRoot = "There was an error while syncing. Resyncing from scratch (Bad sapling root)"
creatingShieldTransaction = "Creating SHIELD transaction..."
immatureRewards = "Part of your staked balance may be locked for 100 blocks as your reward matures."
exportToCsv = "Export transactions"
exportToCsvBody = "Do you want to export your transactions as CSV?"

[ALERTS]
INTERNAL_ERROR = "Internal error, please try again later"
Expand Down
2 changes: 2 additions & 0 deletions locale/uwu/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ proposalOverBudget = "Over Budgey" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...
immatureRewards = "" # Part of your staked balance may be locked for 100 blocks as your reward matures.
exportToCsv = "" # Export transactions
exportToCsvBody = "" # Do you want to export your transactions as CSV?

[ALERTS]
INTERNAL_ERROR = "Internal error, pwease try again later" # Internal error, please try again later
Expand Down
2 changes: 2 additions & 0 deletions scripts/composables/use_wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export const useWallet = defineStore('wallet', () => {
const getPath = (script) => wallet.getPath(script);
const lockCoin = (out) => wallet.lockCoin(out);
const unlockCoin = (out) => wallet.unlockCoin(out);
const getHistoricalTxs = () => wallet.getHistoricalTxs();

getEventEmitter().on('toggle-network', async () => {
isEncrypted.value = await hasEncryptedWallet();
Expand Down Expand Up @@ -205,5 +206,6 @@ export const useWallet = defineStore('wallet', () => {
blockCount,
lockCoin,
unlockCoin,
getHistoricalTxs,
};
});
7 changes: 5 additions & 2 deletions scripts/dashboard/Activity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { translation } from '../i18n.js';
import { Database } from '../database.js';
import { HistoricalTx, HistoricalTxType } from '../historical_tx.js';
import { getNameOrAddress } from '../contacts-book.js';
import { getEventEmitter } from '../event_bus';
import iCheck from '../../assets/icons/icon-check.svg';
import iHourglass from '../../assets/icons/icon-hourglass.svg';
import { blockCount } from '../global.js';
import { beautifyNumber } from '../misc.js';
import TxExport from './TxExport.vue';
const props = defineProps({
title: String,
Expand All @@ -29,6 +29,7 @@ const network = useNetwork();
function getActivityUrl(tx) {
return network.explorerUrl + '/tx/' + tx.id;
}
const txMap = computed(() => {
return {
[HistoricalTxType.STAKE]: {
Expand Down Expand Up @@ -353,7 +354,9 @@ defineExpose({ update, reset, getTxCount, updateReward });
<th scope="col" class="tx3">
{{ translation.amount }}
</th>
<th scope="col" class="tx4 text-right"></th>
<th scope="col" class="tx4 text-right">
<TxExport />
</th>
</tr>
</thead>
<tbody>
Expand Down
66 changes: 66 additions & 0 deletions scripts/dashboard/TxExport.vue
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>
48 changes: 48 additions & 0 deletions scripts/tx_export/koinly_export.js
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`;
}
}
33 changes: 33 additions & 0 deletions scripts/tx_export/tx_export.js
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');
}
}
Loading

0 comments on commit a3b243c

Please sign in to comment.