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 4 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
53 changes: 51 additions & 2 deletions pages/admin/pro/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ const dateFormatters = {
// Format: dd.mm.yyyy HH:MM:SS in UTC
const { dd, mm, yyyy, hh, min, ss } = timePieces(timestamp)
return `${dd}.${mm}.${yyyy} ${hh}:${min}:${ss}`
},
CryptoTax: (timestamp) => {
// Format: YYYY-MM-DD HH:mm:ss
const { yyyy, mm, dd, hh, min, ss } = timePieces(timestamp)
return `${yyyy}-${mm}-${dd} ${hh}:${min}:${ss}`
}
}

Expand Down Expand Up @@ -116,6 +121,12 @@ const processDataForExport = (activities, platform) => {
: Math.abs(activity.amountNumber) <= activity.txFeeNumber
? 'Other Fee'
: 'Deposit'
} else if (platform === 'CryptoTax') {
processedActivity.cryptoTaxTxType = !sending
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be here processedActivity.type instead of processedActivity.cryptoTaxTxType?

because below you use type in headers
And that would also be good for consistency

? 'buy'
: Math.abs(activity.amountNumber) <= activity.txFeeNumber
? 'fee'
: 'sell'
}

return processedActivity
Expand Down Expand Up @@ -200,6 +211,26 @@ export default function History({ queryAddress, selectedCurrency, setSelectedCur
{ label: 'Sell Value in Account Currency', key: '' },
{ label: 'Liquidity pool', key: '' }
]
},
{
platform: 'CryptoTax',
headers: [
{ label: 'Timestamp (UTC)', key: 'timestampExport' },
{ label: 'Type', key: 'type' },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's type here

{ 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: 'counterparty' },
{ label: 'To (Optional)', key: 'address' },
{ 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 @@ -375,6 +406,23 @@ export default function History({ queryAddress, selectedCurrency, setSelectedCur

//sanitize memos for CSV
res.activities[i].memo = res.activities[i].memo?.replace(/"/g, "'") || ''

// For CryptoTax platform
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's specific for a platform, we shouldn't do it for everyone.
The code needs to be moved into the processDataForExport function

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 @@ -564,7 +612,8 @@ export default function History({ queryAddress, selectedCurrency, setSelectedCur
optionsList={[
{ value: 'Koinly', label: 'Koinly' },
{ value: 'CoinLedger', label: 'CoinLedger' },
{ value: 'CoinTracking', label: 'CoinTracking' }
{ value: 'CoinTracking', label: 'CoinTracking' },
{ value: 'CryptoTax', label: 'CryptoTax' }
]}
/>
<button className="dropdown-btn" onClick={() => setSortMenuOpen(!sortMenuOpen)}>
Expand Down Expand Up @@ -720,4 +769,4 @@ export default function History({ queryAddress, selectedCurrency, setSelectedCur
</div>
</>
)
}
}