Skip to content

create export csv for cryptotax #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 70 additions & 5 deletions pages/admin/pro/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ const dateFormatters = {
const ss = pad(date.getUTCSeconds())

return `${mm}/${dd}/${yyyy} ${hh}:${min}:${ss}`
},
CryptoTax: (timestamp) => {
// Format: YYYY-MM-DD HH:mm:ss
const date = new Date(timestamp * 1000)

const pad = (n) => n.toString().padStart(2, '0')

const yyyy = date.getUTCFullYear()
const mm = pad(date.getUTCMonth() + 1)
const dd = pad(date.getUTCDate())

const hh = pad(date.getUTCHours())
const min = pad(date.getUTCMinutes())
const ss = pad(date.getUTCSeconds())

return `${yyyy}-${mm}-${dd} ${hh}:${min}:${ss}`
}
}

Expand Down Expand Up @@ -118,9 +134,9 @@ export default function History({ queryAddress, selectedCurrency, setSelectedCur
headers: [
{ label: 'Date', key: 'timestampExport' },
{ label: 'Sent Amount', key: 'sentAmount' },
{ label: 'Sent Currency', key: 'sentCurrency' },
{ label: 'Sent Currency', key: 'koinlySentCurrency' },
{ label: 'Received Amount', key: 'receivedAmount' },
{ label: 'Received Currency', key: 'receivedCurrency' },
{ label: 'Received Currency', key: 'koinlyReceivedCurrency' },
{ label: 'Fee Amount', key: 'txFeeNumber' },
{ label: 'Fee Currency', key: 'txFeeCurrencyCode' },
{ label: 'Net Worth Amount', key: 'amountInFiats.' + selectedCurrency },
Expand All @@ -145,6 +161,26 @@ export default function History({ queryAddress, selectedCurrency, setSelectedCur
{ label: 'Description (Optional)', key: 'memo' },
{ label: 'TxHash (Optional)', key: 'hash' }
]
},
{
platform: 'CryptoTax',
headers: [
{ label: 'Timestamp (UTC)', key: 'timestampExport' },
{ label: 'Type', key: 'cryptoTaxTxType' },
{ label: 'Base Currency', key: 'baseCurrency' },
{ label: 'Base Amount', key: 'baseAmount' },
{ label: 'Quote Currency (Optional)', key: '' },
{ label: 'Quote Amount (Optional)', key: '' },
{ label: 'Fee Currency (Optional)', key: 'cryptoTaxFeeCurrencyCode' },
{ label: 'Fee Amount (Optional)', key: 'cryptoTaxFeeNumber' },
{ label: 'From (Optional)', key: '' },
{ label: 'To (Optional)', key: '' },
{ label: 'Blockchain (Optional)', key: '' },
{ label: 'ID (Optional)', key: 'hash' },
{ label: 'Description (Optional)', key: 'memo' },
{ label: 'Reference Price Per Unit (Optional)', key: '' },
{ label: 'Reference Price Currency (Optional)', key: '' }
]
}
],
[selectedCurrency]
Expand Down Expand Up @@ -324,10 +360,14 @@ export default function History({ queryAddress, selectedCurrency, setSelectedCur
res.activities[i].timestampExport = new Date(res.activities[i].timestamp * 1000).toISOString()

res.activities[i].sentAmount = sending ? res.activities[i].amountNumber : ''
res.activities[i].sentCurrency = sending ? scvCurrency : ''
res.activities[i].sentCurrency = sending ? currency : ''

res.activities[i].receivedAmount = !sending ? res.activities[i].amountNumber : ''
res.activities[i].receivedCurrency = !sending ? scvCurrency : ''
res.activities[i].receivedCurrency = !sending ? currency : ''

// For Koinly platform
res.activities[i].koinlySentCurrency = sending ? scvCurrency : ''
res.activities[i].koinlyReceivedCurrency = !sending ? scvCurrency : ''

res.activities[i].netWorthCurrency = selectedCurrency.toUpperCase()

Expand All @@ -336,6 +376,30 @@ export default function History({ queryAddress, selectedCurrency, setSelectedCur

// For CoinLedger platform
res.activities[i].coinLedgerTxType = res.activities[i].amountNumber > 0 ? 'Deposit' : 'Withdrawal'

// For CryptoTax platform
res.activities[i].cryptoTaxTxType =
res.activities[i].amountNumber > 0
? 'buy'
: Math.abs(res.activities[i].amountNumber) <= res.activities[i].txFeeNumber
? 'fee'
: 'sell'

res.activities[i].cryptoTaxFeeCurrencyCode = res.activities[i].txFeeCurrencyCode
res.activities[i].cryptoTaxFeeNumber = res.activities[i].txFeeNumber

if (res.activities[i].cryptoTaxTxType === 'buy') {
res.activities[i].baseCurrency = res.activities[i].receivedCurrency
res.activities[i].baseAmount = res.activities[i].receivedAmount
} else {
res.activities[i].baseCurrency = res.activities[i].sentCurrency
res.activities[i].baseAmount = res.activities[i].sentAmount
// don't include this fee amount in the fee column for type 'fee'
if (res.activities[i].cryptoTaxTxType === 'fee') {
res.activities[i].cryptoTaxFeeCurrencyCode = ''
res.activities[i].cryptoTaxFeeNumber = ''
}
}
}
setData(res) // last request data
if (options?.marker) {
Expand Down Expand Up @@ -524,7 +588,8 @@ export default function History({ queryAddress, selectedCurrency, setSelectedCur
setValue={setPlatformCSVExport}
optionsList={[
{ value: 'Koinly', label: 'Koinly' },
{ value: 'CoinLedger', label: 'CoinLedger' }
{ value: 'CoinLedger', label: 'CoinLedger' },
{ value: 'CryptoTax', label: 'CryptoTax' }
]}
/>
<button className="dropdown-btn" onClick={() => setSortMenuOpen(!sortMenuOpen)}>
Expand Down