Skip to content

Commit

Permalink
Change reward withdrawals in CSV to send
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidTranDucVL committed Nov 4, 2020
1 parent dc0eea3 commit c19e1af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
19 changes: 10 additions & 9 deletions app/frontend/components/pages/txHistory/transactionHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {ADALITE_CONFIG} from '../../../config'
import actions from '../../../actions'
import {connect} from '../../../libs/unistore/preact'
import toLocalDate from '../../../helpers/toLocalDate'
import {StakingHistoryItemType} from '../delegations/stakingHistoryPage'
import {RewardWithdrawal, StakingHistoryItemType} from '../delegations/stakingHistoryPage'
import moment = require('moment')

const FormattedAmount = ({amount}: {amount: Lovelace}) => {
Expand Down Expand Up @@ -76,11 +76,12 @@ interface Props {
}

const ExportCSV = ({transactionHistory, stakingHistory}) => {
const withdrawalHistoryTxHashes = new Set(
stakingHistory
.filter((item) => item.type === StakingHistoryItemType.RewardWithdrawal)
.map((withdrawal) => withdrawal.txHash)
)
const withdrawalHistory = stakingHistory
.filter((item) => item.type === StakingHistoryItemType.RewardWithdrawal)
.reduce((acc, withdrawal: RewardWithdrawal) => {
acc[withdrawal.txHash] = withdrawal.amount
return acc
}, {})

const stakingRewards = stakingHistory.filter(
(item) => item.type === StakingHistoryItemType.StakingReward
Expand All @@ -107,7 +108,6 @@ const ExportCSV = ({transactionHistory, stakingHistory}) => {
received: 'Received',
sent: 'Sent',
rewardAwarded: 'Reward awarded',
rewardWithdrawal: 'Reward withdrawal',
}

const transactionsEntries = transactionHistory.map((transaction) => {
Expand All @@ -116,10 +116,11 @@ const ExportCSV = ({transactionHistory, stakingHistory}) => {
dateTime: moment.utc(new Date(transaction.ctbTimeIssued * 1000)),
}

if (withdrawalHistoryTxHashes.has(transaction.ctbId)) {
if (withdrawalHistory.hasOwnProperty(transaction.ctbId)) {
return {
...common,
type: transactionTypes.rewardWithdrawal,
type: transactionTypes.sent,
sent: Math.abs(transaction.effect - withdrawalHistory[transaction.ctbId]) - transaction.fee,
fee: transaction.fee,
}
} else if (transaction.effect > 0) {
Expand Down
5 changes: 3 additions & 2 deletions app/frontend/wallet/blockchain-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../components/pages/delegations/stakingHistoryPage'
import distinct from '../helpers/distinct'
import {UNKNOWN_POOL_NAME} from './constants'
import {Lovelace} from '../state'

const cacheResults = (maxAge: number, cache_obj: Object = {}) => <T extends Function>(fn: T): T => {
const wrapped = (...args) => {
Expand Down Expand Up @@ -271,7 +272,7 @@ const blockchainExplorer = (ADALITE_CONFIG) => {
epoch: reward.epochNo,
dateTime: new Date(reward.time),
forEpoch: reward.forDelegationInEpoch,
reward: reward.amount,
reward: parseInt(reward.amount, 10) as Lovelace,
stakePool: parseStakePool(reward),
}

Expand All @@ -285,7 +286,7 @@ const blockchainExplorer = (ADALITE_CONFIG) => {
txHash: withdrawal.txHash,
epoch: withdrawal.epochNo,
dateTime: new Date(withdrawal.time),
amount: withdrawal.amount,
amount: parseInt(withdrawal.amount, 10) as Lovelace,
}

return rewardWithdrawal
Expand Down

0 comments on commit c19e1af

Please sign in to comment.