Skip to content

add export csv blockpit #262

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
56 changes: 51 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}`
},
BlockPit: (timestamp) => {
// Format: DD.MM.YYYY HH:MM:SS in UTC
const date = new Date(timestamp * 1000)

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

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

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

return `${dd}.${mm}.${yyyy} ${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,22 @@ export default function History({ queryAddress, selectedCurrency, setSelectedCur
{ label: 'Description (Optional)', key: 'memo' },
{ label: 'TxHash (Optional)', key: 'hash' }
]
},
{
platform: 'BlockPit',
headers: [
{ label: 'Date (UTC)', key: 'timestampExport' },
{ label: 'Integration Name', key: 'platform' },
{ label: 'Label', key: 'blockPitTxType' },
{ label: 'Outgoing Asset', key: 'sentCurrency' },
{ label: 'Outgoing Amount', key: 'sentAmount' },
{ label: 'Incoming Asset', key: 'receivedCurrency' },
{ label: 'Incoming Amount', key: 'receivedAmount' },
{ label: 'Fee Asset (optional)', key: 'txFeeCurrencyCode' },
{ label: 'Fee Amount (optional)', key: 'txFeeNumber' },
{ label: 'Comment (optional)', key: 'memo' },
{ label: 'Trx. ID (optional)', key: 'hash' }
]
}
],
[selectedCurrency]
Expand Down Expand Up @@ -324,10 +356,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 +372,14 @@ export default function History({ queryAddress, selectedCurrency, setSelectedCur

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

// For BlockPit platform
res.activities[i].blockPitTxType =
res.activities[i].amountNumber > 0
? 'Deposit'
: Math.abs(res.activities[i].amountNumber) <= res.activities[i].txFeeNumber
? 'Fee'
: 'Withdrawal'
}
setData(res) // last request data
if (options?.marker) {
Expand Down Expand Up @@ -524,7 +568,8 @@ export default function History({ queryAddress, selectedCurrency, setSelectedCur
setValue={setPlatformCSVExport}
optionsList={[
{ value: 'Koinly', label: 'Koinly' },
{ value: 'CoinLedger', label: 'CoinLedger' }
{ value: 'CoinLedger', label: 'CoinLedger' },
{ value: 'BlockPit', label: 'BlockPit' }
]}
/>
<button className="dropdown-btn" onClick={() => setSortMenuOpen(!sortMenuOpen)}>
Expand All @@ -541,6 +586,7 @@ export default function History({ queryAddress, selectedCurrency, setSelectedCur
}
filename={'export ' + new Date().toISOString() + '.csv'}
className={'button-action' + (!(activities?.length > 0) ? ' disabled' : '')}
uFEFF={platformCSVExport === 'BlockPit' ? false : undefined}
>
<DownloadIcon /> CSV for {platformCSVExport}
</CSVLink>
Expand Down