-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
388 additions
and
144 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
frontend/src/app/(routes)/(overview)/overview-components/Asset.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { formatAmount, formatCoin, formatDollarAmount } from '@/utils/util'; | ||
import Link from 'next/link'; | ||
import React from 'react'; | ||
import Image from 'next/image'; | ||
import { useAppDispatch, useAppSelector } from '@/custom-hooks/StateHooks'; | ||
import { txWithdrawAllRewards } from '@/store/features/distribution/distributionSlice'; | ||
import useGetTxInputs from '@/custom-hooks/useGetTxInputs'; | ||
import { TxStatus } from '@/types/enums'; | ||
import { txRestake } from '@/store/features/staking/stakeSlice'; | ||
import { RootState } from '@/store/store'; | ||
|
||
const Asset = ({ | ||
asset, | ||
showChainName, | ||
}: { | ||
asset: ParsedAsset; | ||
showChainName: boolean; | ||
}) => { | ||
const txClaimStatus = useAppSelector( | ||
(state: RootState) => state.distribution.chains[asset.chainID].tx.status | ||
); | ||
const txRestakeStatus = useAppSelector( | ||
(state: RootState) => state.staking.chains[asset.chainID].reStakeTxStatus | ||
); | ||
|
||
const dispatch = useAppDispatch(); | ||
const { txWithdrawAllRewardsInputs, txRestakeInputs } = useGetTxInputs(); | ||
|
||
const claim = (chainID: string) => { | ||
if (txClaimStatus === TxStatus.PENDING) { | ||
alert('A claim transaction is already in pending...'); | ||
return; | ||
} | ||
const txInputs = txWithdrawAllRewardsInputs(chainID); | ||
if (txInputs.msgs.length) dispatch(txWithdrawAllRewards(txInputs)); | ||
else alert('no delegations'); | ||
}; | ||
|
||
const claimAndStake = (chainID: string) => { | ||
if (txRestakeStatus === TxStatus.PENDING) { | ||
alert('A restake transaction is already pending...'); | ||
return; | ||
} | ||
const txInputs = txRestakeInputs(chainID); | ||
if (txInputs.msgs.length) dispatch(txRestake(txInputs)); | ||
else alert('no rewards'); | ||
}; | ||
|
||
return ( | ||
<tr key={asset.chainID + asset.denom}> | ||
<td> | ||
<div>{formatCoin(asset.balance, asset.displayDenom)}</div> | ||
{showChainName && ( | ||
<div className="text-xs text-[#a7a2b5] font-thin leading-[normal]"> | ||
on{' '} | ||
<Link href={`/overview/${asset.chainName}`}>{asset.chainName}</Link> | ||
</div> | ||
)} | ||
</td> | ||
<td> | ||
{asset.type === 'native' | ||
? formatCoin(asset.staked, asset.displayDenom) | ||
: '-'} | ||
</td> | ||
<td> | ||
{asset.type === 'native' | ||
? formatCoin(asset.rewards, asset.displayDenom) | ||
: '-'} | ||
</td> | ||
<td> | ||
<div className="flex gap-2" style={{ alignItems: 'flex-end' }}> | ||
<div>{formatDollarAmount(asset.usdPrice)}</div> | ||
<div className="flex"> | ||
<Image | ||
src={`/${ | ||
asset.inflation >= 0 ? 'up' : 'down' | ||
}-arrow-filled-icon.svg`} | ||
height={16} | ||
width={16} | ||
alt="inflation change" | ||
/> | ||
<div className="text-[#E57575] text-[12px]"> | ||
{formatAmount(Math.abs(asset.inflation))}% | ||
</div> | ||
</div> | ||
</div> | ||
</td> | ||
<td> | ||
<div className="flex justify-between gap-1"> | ||
<div className="asset-action" onClick={() => claim(asset.chainID)}> | ||
<Image src="/claim-icon.svg" height={16} width={16} alt="Claim" /> | ||
</div> | ||
<div | ||
className="asset-action" | ||
onClick={() => claimAndStake(asset.chainID)} | ||
> | ||
<Image | ||
src="/claim-stake-icon.svg" | ||
height={16} | ||
width={16} | ||
alt="Claim and Stake" | ||
/> | ||
</div> | ||
</div> | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
export default Asset; | ||
function txWithdrawAllRewardsInputs(chainID: string) { | ||
throw new Error('Function not implemented.'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.