Browse Source

v1.0 release

tags/v1.0^0
Jaryl Chng 7 months ago
commit
611e76a012
Signed by: jarylc GPG Key ID: A7174FB4C337FA37
17 changed files with 8818 additions and 0 deletions
  1. +1
    -0
      .gitattributes
  2. +21
    -0
      .gitignore
  3. +20
    -0
      .gitlab-ci.yml
  4. +21
    -0
      LICENSE.md
  5. +28
    -0
      README.md
  6. +5
    -0
      babel.config.js
  7. +43
    -0
      package.json
  8. BIN
      public/favicon.ico
  9. +17
    -0
      public/index.html
  10. +68
    -0
      src/App.vue
  11. +126
    -0
      src/components/Import.vue
  12. +124
    -0
      src/components/Process.vue
  13. +12
    -0
      src/main.js
  14. +98
    -0
      src/models/transaction.js
  15. +43
    -0
      src/resources/strings.js
  16. +3
    -0
      vue.config.js
  17. +8188
    -0
      yarn.lock

+ 1
- 0
.gitattributes View File

@@ -0,0 +1 @@
.ico filter=lfs diff=lfs merge=lfs -text

+ 21
- 0
.gitignore View File

@@ -0,0 +1,21 @@
.DS_Store
node_modules
/dist

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

+ 20
- 0
.gitlab-ci.yml View File

@@ -0,0 +1,20 @@
image: node:latest

pages:
stage: deploy
script:
- yarn
- yarn build
- rm -rf public
- mkdir public
- cp -r dist/* public
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
artifacts:
expire_in: 1 day
paths:
- public
only:
- master

+ 21
- 0
LICENSE.md View File

@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Jaryl Chng

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

+ 28
- 0
README.md View File

@@ -0,0 +1,28 @@
# Crypto.com to Delta CSV Converter

## Description
An open source CSV converter application that converts a Crypto.com exported CSV to a format that is able to be imported into the Delta crypto-currency portfolio application.

This project is coded in HTML, CSS, Javascript with the help of Bootstrap and VueJS framework.

## Development instructions
### Required dependencies
```
yarn
```
### Project setup and build
```
yarn install
```
#### Compiles and hot-reloads for development
```
yarn serve
```
#### Compiles and minifies for production
```
yarn build
```
#### Lints and fixes files
```
yarn lint
```

+ 5
- 0
babel.config.js View File

@@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
};

+ 43
- 0
package.json View File

@@ -0,0 +1,43 @@
{
"name": "js-vue-cdc-to-delta",
"version": "1.0.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"bootstrap": "^4.4.1",
"core-js": "^3.6.4",
"csv-parse": "^4.8.5",
"vue": "^2.6.11"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.2.0",
"@vue/cli-plugin-eslint": "~4.2.0",
"@vue/cli-service": "~4.2.0",
"babel-eslint": "^10.0.3",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.1.2",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}

BIN
public/favicon.ico View File

Before After

+ 17
- 0
public/index.html View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="./favicon.ico">
<title>Crypto.com CSV ⇄ Delta CSV</title>
</head>
<body>
<noscript>
<strong>JavaScript is required to run this application which is disabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

+ 68
- 0
src/App.vue View File

@@ -0,0 +1,68 @@
<template>
<div id="app" class="container-fluid">
<div class="row">
<h1 class="m-auto pb-2">Crypto.com CSV ⇄ Delta CSV</h1>
</div>
<Import v-if="!processed.length" @submit="imported"/>
<Process v-cloak v-else v-bind:processed="processed" @retry="retry" @generate="generate"/>
<footer class="small text-center">
<strong>{{strings.data_collection}}</strong><br/>
<span v-html="strings.affiliation"></span><br/>
{{strings.risk}}<br/>
<br/>
<a href="https://gitlab.com/jarylc/javascript-vue-cdc-to-delta-csv-converter" target="_blank"
rel="noopener noreferrer">{{strings.source_codes}}</a><br/>
<a href="https://billing.usonyx.net/aff.php?aff=8400187" target="_blank" rel="noopener noreferrer"><strong>{{strings.hosted}}</strong></a><br/>
<br/>
<a href="https://jarylchng.com" target="_blank" rel="noopener noreferrer"><strong>Jaryl Chng</strong></a>
</footer>
</div>
</template>

<script>
import Import from "./components/Import";
import Process from "./components/Process";
import {Strings} from "./resources/strings";

export default {
name: 'App',
components: {
Process,
Import
},
data: function () {
return {
strings: Strings.default(),
processed: []
}
},
methods: {
imported: function (processed) {
this.processed = processed;
},
retry: function () {
this.processed = [];
},
generate: function () {
let output = "Date,Type,Exchange,Base amount,Base currency,Quote amount,Quote currency,Fee,Fee currency,Costs/Proceeds,Costs/Proceeds currency,Sync Holdings,Sent/Received from,Sent to,Notes\n";
this.processed.forEach((transaction) => {
output += transaction.toString();
});

let element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(output));
element.setAttribute('download', 'delta_' + Date.now() + '.csv');
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
}
}
</script>

<style>
[v-cloak] {
display: none;
}
</style>

+ 126
- 0
src/components/Import.vue View File

@@ -0,0 +1,126 @@
<template>
<div class="row ml-lg-5 mr-lg-5 mb-2" @drop.prevent="dropHandler" @dragover.prevent>
<label class="h2 m-auto font-weight-normal" for="csv">{{strings.cdc_instruction}}</label>
<input class="m-3 text-center vw-100" type="file" @change="file"/>
<textarea id="csv" class="vw-100" :placeholder="strings.drag_and_drop_possible" v-model="csv"/>
<div v-if="error !== ''" class="text-danger m-auto">{{error}}</div>
<button class="btn btn-block btn-primary mt-2" @click="submit">{{strings.submit}}</button>
</div>
</template>

<script>
const parse = require('csv-parse');
import {Strings} from "../resources/strings";
import {Transaction} from "../models/transaction";

export default {
name: 'Import',
data: function () {
return {
strings: Strings.default(),
csv: "",
error: ""
}
},
methods: {
processFile: function (file) {
let _this = this;
if (file.name.includes('.csv') || file.type === "text/csv") {
let reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = function (evt) {
_this.csv = evt.target.result;
_this.error = "";
};
reader.onerror = function () {
_this.error = Strings.default().error_reading_file;
}
} else {
_this.error = Strings.default().invalid_file_type + ' (' + file.type + ')';
}
},
file: function (e) {
let file = e.target.files[0];
this.processFile(file);
},
dropHandler: function (e) {
if (e.dataTransfer.files.length > 0) {
let file = e.dataTransfer.files[0];
this.processFile(file);
}
},
submit: function () {
const _this = this;
parse(this.csv, {}, function (err, output) {
if (err) {
_this.error = Strings.default().invalid_csv + " - " + err.message;
return;
}

if (JSON.stringify(output[0]) === '["Timestamp (UTC)","Transaction Description","Currency","Amount","To Currency","To Amount","Native Currency","Native Amount","Native Amount (in USD)"]') {
let data = [];

output.forEach((row, index) => {
if (index === 0)
return;

let date = row[0];
let type = row[1];
let currency = row[2];
let quantity = row[3];
let currencyTo = row[4];
let quantityTo = row[5];
let currencyNative = row[6];
let quantityNative = row[7];

let transaction = new Transaction();
if (type.includes("Unlocked") || type === "Crypto Earn" || type === "MCO Stake Rewards" || type.includes("Referral Bonus") || type === "Card Cashback" || type.includes("Card Rebate:")) {
transaction.deposit(date, quantity, currency);
transaction.notes = type;
} else if (type.includes("Buy") || (type.includes("Deposit") && !type.includes("Earn"))) {
transaction.trade(date, quantity, currency, quantityNative, currencyNative);
} else if (type.includes("->")) {
if (quantityTo !== "")
transaction.trade(date, quantityTo, currencyTo, quantity, currency);
else
transaction.trade(date, quantityNative, currencyNative, quantity, currency);
} else if (type.includes("Withdraw") && !type.includes("Earn")) {
transaction.withdraw(date, quantity, currency);
} else if (type.includes("Reversal")) {
transaction.withdraw(date, quantity, currency);
transaction.notes = type;
}

if (transaction.type !== "")
data.push(transaction);
});

_this.$emit('submit', data)
} else {
_this.error = Strings.default().invalid_header;
}
})
}
}
}
</script>

<style scoped>
label {
font-weight: bolder;
}

textarea {
height: 25vh;
}
@media (min-width: 767px) {
textarea {
height: 40vh;
}
}
@media (min-width: 991px) {
textarea {
height: 60vh;
}
}
</style>

+ 124
- 0
src/components/Process.vue View File

@@ -0,0 +1,124 @@
<template>
<div class="row ml-lg-5 mr-lg-5 mb-2">
<button class="btn btn-block btn-success mt-2" @click="submit">{{strings.download}}</button>
<button class="btn btn-block btn-danger mt-2" @click="retry">{{strings.retry}}</button>
<h2 id="summary" class="m-auto pt-2 pb-2">{{strings.summary}}</h2>
<div class="table-responsive text-center">
<table aria-describedby="summary" class="table table-striped">
<thead class="thead-light">
<tr>
<th scope="row">{{strings.currency}}</th>
<th scope="row">{{strings.total}}</th>
</tr>
</thead>
<tbody>
<tr v-for="(amount, currency, index) in getTotals" v-bind:key="index">
<td>{{currency}}</td>
<td>{{parseFloat(amount).toFixed(8)}}</td>
</tr>
</tbody>
</table>
</div>
<h2 id="breakdown" class="m-auto pb-1">{{strings.breakdown}} ({{processed.length}})</h2>
<div class="table-responsive text-center">
<table aria-describedby="breakdown" class="table table-striped">
<thead class="thead-light">
<tr>
<th scope="row">#</th>
<th scope="row">{{strings.timestamp}}</th>
<th scope="row">{{strings.type}}</th>
<th scope="row">{{strings.base_amount}}</th>
<th scope="row">{{strings.base_currency}}</th>
<th scope="row">{{strings.quote_amount}}</th>
<th scope="row">{{strings.quote_currency}}</th>
<th scope="row">{{strings.sent_received}}</th>
<th scope="row">{{strings.sent_to}}</th>
<th id="notes">{{strings.notes}}</th>
</tr>
</thead>
<tbody>
<tr v-for="(transaction, index) in processed" v-bind:key="index">
<td>{{index+1}}</td>
<td>{{transaction.date}}</td>
<td>{{transaction.type}}</td>
<td>{{transaction.baseAmount}}</td>
<td>{{transaction.baseCurrency}}</td>
<td>{{transaction.quoteAmount}}</td>
<td>{{transaction.quoteCurrency}}</td>
<td>{{transaction.from}}</td>
<td>{{transaction.to}}</td>
<td><input aria-label="notes" type="text" v-model="transaction.notes"/></td>
</tr>
</tbody>
</table>
</div>
<button class="btn btn-block btn-danger mt-2" @click="retry">{{strings.retry}}</button>
<button class="btn btn-block btn-success mt-2" @click="submit">{{strings.download}}</button>
</div>
</template>

<script>
import {Strings} from "../resources/strings";

export default {
name: 'Process',
props: {
processed: []
},
data: function () {
return {
strings: Strings.default()
}
},
created: function () {
window.scrollTo(0, 0);
},
computed: {
getTotals: function () {
let totals = {};
this.processed.forEach((transaction) => {
if (!(transaction.baseCurrency in totals))
totals[transaction.baseCurrency] = 0.0;

if (isNaN(totals[transaction.baseCurrency])) {
console.log(transaction.date);
console.log(totals[transaction.baseCurrency])
}

switch (transaction.type) {
case "BUY":
if (transaction.sync === "1") {
if (!(transaction.quoteCurrency in totals))
totals[transaction.quoteCurrency] = 0.0;
totals[transaction.quoteCurrency] = totals[transaction.quoteCurrency] - parseFloat(transaction.quoteAmount);
}
// falls through
case "DEPOSIT":
totals[transaction.baseCurrency] = totals[transaction.baseCurrency] + parseFloat(transaction.baseAmount);
break;
case "SELL":
if (transaction.sync === "1") {
if (!(transaction.quoteCurrency in totals))
totals[transaction.quoteCurrency] = 0.0;
totals[transaction.quoteCurrency] = totals[transaction.quoteCurrency] + parseFloat(transaction.quoteAmount);
}
// falls through
case "WITHDRAW":
totals[transaction.baseCurrency] = totals[transaction.baseCurrency] - parseFloat(transaction.baseAmount);
break;
}
});

return totals;
}
},
methods: {
retry: function () {
this.$emit('retry')
},
submit: function () {
this.$emit('generate')
}
}
}
</script>

+ 12
- 0
src/main.js View File

@@ -0,0 +1,12 @@
import Vue from 'vue'
import App from './App.vue'

import 'bootstrap/dist/css/bootstrap.min.css';

Vue.config.productionTip = false;

new Vue({
render: h => h(App),
}).$mount('#app');

console.log('This application was created by Jaryl Chng (https://jarylchng.com)');

+ 98
- 0
src/models/transaction.js View File

@@ -0,0 +1,98 @@
export class Transaction {
static fiats = [
"USD", "USDM", "EUR", "AUD", "BGN",
"CAD", "HRK", "CZK", "DKK", "HKD",
"HUF", "ILS", "JPY", "NZD", "NOK",
"PLN", "RON", "SGD", "SAR", "SEK",
"CHF", "GBP"
];

// some of the cryptocurrency require a name change to map correctly, I may not know all and do raise an issue if you find one
static convert = {
USDM: "USD",
FET: "FET*",
COS: "COS*"
};

date = "";
type = "";
exchange = "";
baseAmount = "";
baseCurrency = "";
quoteAmount = "";
quoteCurrency = "";
sync = "1";
from = "";
to = "";
notes = "";

trade(date, baseAmount, baseCurrency, quoteAmount, quoteCurrency) {
this.date = date;

let isBaseFiat = Transaction.fiats.includes(baseCurrency);
let isQuoteFiat = Transaction.fiats.includes(quoteCurrency);

if (isBaseFiat && isQuoteFiat) {
// this.type = "DEPOSIT";
// this.exchange = "OKEX";
// this.baseAmount = Math.abs(baseAmount);
// this.baseCurrency = baseCurrency;
return;
}

if (isBaseFiat) {
this.type = "SELL";
this.baseAmount = Math.abs(quoteAmount);
this.baseCurrency = quoteCurrency;
this.quoteAmount = Math.abs(baseAmount);
this.quoteCurrency = baseCurrency;
this.sync = "0";
} else {
this.type = "BUY";
this.baseAmount = Math.abs(baseAmount);
this.baseCurrency = baseCurrency;
this.quoteAmount = Math.abs(quoteAmount);
this.quoteCurrency = quoteCurrency;
if (isQuoteFiat)
this.sync = "0";
}

if (this.baseCurrency in Transaction.convert)
this.baseCurrency = Transaction.convert[this.baseCurrency];
if (this.quoteCurrency in Transaction.convert)
this.quoteCurrency = Transaction.convert[this.quoteCurrency];
}

deposit(date, baseAmount, baseCurrency) {
this.type = "DEPOSIT";
this.date = date;
this.baseAmount = baseAmount;
this.baseCurrency = baseCurrency;
this.from = "OTHER";
this.to = "MY_WALLET";
}

withdraw(date, baseAmount, baseCurrency) {
this.type = "WITHDRAW";
this.date = date;
this.baseAmount = Math.abs(baseAmount);
this.baseCurrency = baseCurrency;
this.from = "MY_WALLET";
this.to = "OTHER";
}

toString() {
return this.date + ','
+ this.type + ','
+ this.exchange + ','
+ this.baseAmount + ','
+ this.baseCurrency + ','
+ this.quoteAmount + ','
+ this.quoteCurrency + ','
+ ",,,,"
+ this.sync + ','
+ this.from + ','
+ this.to + ','
+ this.notes + '\n';
}
}

+ 43
- 0
src/resources/strings.js View File

@@ -0,0 +1,43 @@
export const Strings = {
en: {
// footer
data_collection: 'No data will be collected nor transmitted, it is processed entirely by your browser',
affiliation: 'This application is not affiliated with <a href="https://crypto.com/" target="_blank" rel="noopener noreferrer">Crypto.com</a> and <a href="https://delta.app" target="_blank" rel="noopener noreferrer">Delta</a>',
risk: 'Use at your own risk',
source_codes: 'Source codes',
hosted: '☁ Hosted on Usonyx ☁',
// import
cdc_instruction: 'Import Crypto.com exported CSV',
drag_and_drop_possible: 'You can also drag and drop the CSV file here',
invalid_file_type: 'Invalid file type',
error_reading_file: 'Error reading file, try manually pasting CSV above',
invalid_header: 'Invalid Crypto.com CSV header',
invalid_csv: 'CSV failed to parse',
// process
process_instruction: 'Process converted data',
summary: 'Summary',
breakdown: 'Breakdown',
currency: 'Currency',
total: 'Total',
timestamp: 'Timestamp (UTC)',
type: 'Type',
exchange: 'Exchange',
base_amount: 'Base amount',
base_currency: 'Base currency',
quote_amount: 'Quote amount',
quote_currency: 'Quote currency',
sync: 'Sync',
sent_received: 'Sent/Received',
sent_to: 'Sent to',
notes: 'Notes',
// misc
submit: 'Submit',
retry: 'Retry',
download: 'Download'
},
default: function () {
if (document.documentElement.lang)
return this[document.documentElement.lang];
return this.en;
}
};

+ 3
- 0
vue.config.js View File

@@ -0,0 +1,3 @@
module.exports = {
publicPath: './'
};

+ 8188
- 0
yarn.lock
File diff suppressed because it is too large
View File


Loading…
Cancel
Save