Skip to content

Commit

Permalink
Add staking rewards to staking history
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidTranDucVL committed Nov 3, 2020
1 parent e38171e commit 6a5b5f0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
47 changes: 27 additions & 20 deletions app/frontend/components/pages/delegations/stakingHistoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface StakePool {
export interface StakeDelegation extends StakingHistoryObject {
newStakePool: StakePool
oldStakePool?: StakePool
txid: string
txHash: string
}

const StakeDelegationItem = ({stakeDelegation}: {stakeDelegation: StakeDelegation}) => {
Expand All @@ -51,7 +51,7 @@ const StakeDelegationItem = ({stakeDelegation}: {stakeDelegation: StakeDelegatio
''
)}
<ViewOnCardanoScan
txid={stakeDelegation.txid}
txHash={stakeDelegation.txHash}
suffix="?tab=delegations"
className="margin-top"
/>
Expand All @@ -60,33 +60,40 @@ const StakeDelegationItem = ({stakeDelegation}: {stakeDelegation: StakeDelegatio
}

export interface StakingReward extends StakingHistoryObject {
forEpoch: number
reward: Lovelace
stakePool: StakePool
}

const StakingRewardItem = ({stakingReward}: {stakingReward: StakingReward}) => {
return (
<li className="staking-history-item">
<div>
<div className="label">Staking reward</div>
<div className="margin-bottom">
<EpochDateTime epoch={stakingReward.epoch} dateTime={stakingReward.dateTime} />
<div className="space-between">
<div>
<div>
<div className="label">Reward for epoch {stakingReward.forEpoch}</div>
<div className="margin-bottom">
<EpochDateTime epoch={stakingReward.epoch} dateTime={stakingReward.dateTime} />
</div>
</div>
<div>
<div className="grey">
{stakingReward.stakePool.name}
<CopyPoolId value={stakingReward.stakePool.id} />
</div>
</div>
</div>
</div>
<div>
<div>Reward: {printAda(stakingReward.reward)}</div>
<div className="grey">
{stakingReward.stakePool.name}
<CopyPoolId value={stakingReward.stakePool.id} />
<div>
<div className="transaction-amount credit">{printAda(stakingReward.reward)}</div>
</div>
</div>
</li>
)
}

export interface RewardWithdrawal extends StakingHistoryObject {
credit: Lovelace
txid: string
amount: Lovelace
txHash: string
}

const RewardWithdrawalItem = ({rewardWithdrawal}: {rewardWithdrawal: RewardWithdrawal}) => {
Expand All @@ -100,18 +107,18 @@ const RewardWithdrawalItem = ({rewardWithdrawal}: {rewardWithdrawal: RewardWithd
</div>
</div>
<div>
<div className="transaction-amount credit">{printAda(rewardWithdrawal.credit)}</div>
<div className="transaction-amount debit">{printAda(rewardWithdrawal.amount)}</div>
</div>
</div>
<ViewOnCardanoScan txid={rewardWithdrawal.txid} suffix="?tab=withdrawals" />
<ViewOnCardanoScan txHash={rewardWithdrawal.txHash} suffix="?tab=withdrawals" />
</li>
)
}

export interface StakingKeyRegistration extends StakingHistoryObject {
action: string
stakingKey: string
txid: string
txHash: string
}

const formatStakingKey = (str: string, n: number) =>
Expand Down Expand Up @@ -143,22 +150,22 @@ const StakingKeyRegistrationItem = ({
</CopyOnClick>
</div>
<ViewOnCardanoScan
txid={stakingKeyRegistration.txid}
txHash={stakingKeyRegistration.txHash}
suffix="?tab=stakecertificates"
className="margin-top"
/>
</li>
)
}

const ViewOnCardanoScan = ({txid, suffix, className = ''}) => {
const ViewOnCardanoScan = ({txHash, suffix, className = ''}) => {
return (
<div className={`blockexplorer-link ${className}`}>
<span>View on </span>
<span>
<a
className="transaction-address"
href={`https://cardanoscan.io/transaction/${txid}${suffix}`}
href={`https://cardanoscan.io/transaction/${txHash}${suffix}`}
target="_blank"
rel="noopener"
>
Expand Down
20 changes: 10 additions & 10 deletions app/frontend/wallet/blockchain-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,23 +202,22 @@ const blockchainExplorer = (ADALITE_CONFIG) => {
const delegationsUrl = `${
ADALITE_CONFIG.ADALITE_BLOCKCHAIN_EXPLORER_URL
}/api/account/delegationHistory/${accountPubkeyHex}`
// const rewardsUrl = `${
// ADALITE_CONFIG.ADALITE_BLOCKCHAIN_EXPLORER_URL
// }/api/account/rewardHistory/${accountPubkeyHex}`
const rewardsUrl = `${
ADALITE_CONFIG.ADALITE_BLOCKCHAIN_EXPLORER_URL
}/api/account/rewardHistory/${accountPubkeyHex}`
const withdrawalsUrl = `${
ADALITE_CONFIG.ADALITE_BLOCKCHAIN_EXPLORER_URL
}/api/account/withdrawalHistory/${accountPubkeyHex}`
const stakingKeyRegistrationUrl = `${
ADALITE_CONFIG.ADALITE_BLOCKCHAIN_EXPLORER_URL
}/api/account/stakeRegistrationHistory/${accountPubkeyHex}`

const [delegations, /*rewards,*/ withdrawals, stakingKeyRegistrations] = await Promise.all([
const [delegations, rewards, withdrawals, stakingKeyRegistrations] = await Promise.all([
request(delegationsUrl).catch(() => []),
// request(rewardsUrl).catch(()=>[]),
request(rewardsUrl).catch(() => []),
request(withdrawalsUrl).catch(() => []),
request(stakingKeyRegistrationUrl).catch(() => []),
])
const rewards = []

const extractUrl = (poolHash) =>
validStakepools[poolHash] ? validStakepools[poolHash].url : null
Expand Down Expand Up @@ -253,7 +252,7 @@ const blockchainExplorer = (ADALITE_CONFIG) => {
const stakePool: StakePool = parseStakePool(delegation)
const stakeDelegation: StakeDelegation = {
type: StakingHistoryItemType.StakeDelegation,
txid: delegation.txHash,
txHash: delegation.txHash,
epoch: delegation.epochNo,
dateTime: new Date(delegation.time),
newStakePool: stakePool,
Expand All @@ -271,6 +270,7 @@ const blockchainExplorer = (ADALITE_CONFIG) => {
type: StakingHistoryItemType.StakingReward,
epoch: reward.epochNo,
dateTime: new Date(reward.time),
forEpoch: reward.forDelegationInEpoch,
reward: reward.amount,
stakePool: parseStakePool(reward),
}
Expand All @@ -282,10 +282,10 @@ const blockchainExplorer = (ADALITE_CONFIG) => {
const parsedWithdrawals = withdrawals.map((withdrawal) => {
const rewardWithdrawal: RewardWithdrawal = {
type: StakingHistoryItemType.RewardWithdrawal,
txid: withdrawal.txHash,
txHash: withdrawal.txHash,
epoch: withdrawal.epochNo,
dateTime: new Date(withdrawal.time),
credit: withdrawal.amount,
amount: withdrawal.amount,
}

return rewardWithdrawal
Expand All @@ -295,7 +295,7 @@ const blockchainExplorer = (ADALITE_CONFIG) => {
const parsedStakingKeyRegistrations = stakingKeyRegistrations.map((registration) => {
const stakingKeyRegistration: StakingKeyRegistration = {
type: StakingHistoryItemType.StakingKeyRegistration,
txid: registration.txHash,
txHash: registration.txHash,
epoch: registration.epochNo,
dateTime: new Date(registration.time),
action: registration.action,
Expand Down

0 comments on commit 6a5b5f0

Please sign in to comment.