-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet-dashboard): hook logic to staking overview (#459)
* feat(wallet-dashboard): hook stake logic and add StakeCard component * feat(wallet-dashboard): cleanup * feat(wallet-dasboard): add Stake interface * feat(wallet-dashboard): remove interface and add a type * feat(wallet-dashboard): add hook and updtae type * feat(wallet-dashboard): add props interface * feat(wallet-dashboard): cleanup code * feat(wallet-dashboard):remove headers * apply suggestion and use @iota * bring back List and better than before * feat(wallet-dashboard): remove List component * feat(wallet-dashboard): rename names, update types and rename file * feat(wallet-dashboard): rename constant * feat(wallet-dashboard): add stakedIotaId * feat(wallet-dashboard): remove unnecessary id * feat(wallet-dashboard): remove derbis * feat(wallet-dashboard): remove debris * feat(wallet-dashboard): add total hooks, format util and move hook to different folder * feat(wallet): update components to use new hooks * feat(wallet): cleanup * feat(core):cleanup * feat(explorer): cleanup * feat(wallet-dashboard): undo unnecessary change * feat(apps/core): move to stake folder * feat(wallet-dashboard): rename variables * feat(wallet-dashboard): rename type * feat(wallet-dashboard): fix build --------- Co-authored-by: Marc Espin <[email protected]> Co-authored-by: cpl121 <[email protected]> Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>
- Loading branch information
1 parent
aad5ff9
commit f8d666f
Showing
16 changed files
with
210 additions
and
170 deletions.
There are no files selected for viewing
File renamed without changes.
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,17 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useMemo } from 'react'; | ||
import { type ExtendedDelegatedStake } from '../../utils/stake/formatDelegatedStake'; | ||
|
||
export function useTotalDelegatedRewards(delegatedStake: ExtendedDelegatedStake[]) { | ||
return useMemo(() => { | ||
if (!delegatedStake) return 0n; | ||
return delegatedStake.reduce((acc, curr) => { | ||
if (curr.status === 'Active' && curr.estimatedReward) { | ||
return acc + BigInt(curr.estimatedReward); | ||
} | ||
return acc; | ||
}, 0n); | ||
}, [delegatedStake]); | ||
} |
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,12 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useMemo } from 'react'; | ||
import { type ExtendedDelegatedStake } from '../../utils/stake/formatDelegatedStake'; | ||
|
||
export function useTotalDelegatedStake(delegatedStake: ExtendedDelegatedStake[]) { | ||
return useMemo(() => { | ||
if (!delegatedStake) return 0n; | ||
return delegatedStake.reduce((acc, curr) => acc + BigInt(curr.principal), 0n); | ||
}, [delegatedStake]); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { DelegatedStake, StakeObject } from '@iota/iota.js/client'; | ||
|
||
export type ExtendedDelegatedStake = StakeObject & { | ||
validatorAddress: string; | ||
estimatedReward?: string; | ||
}; | ||
|
||
export function formatDelegatedStake( | ||
delegatedStakeData: DelegatedStake[], | ||
): ExtendedDelegatedStake[] { | ||
return delegatedStakeData.flatMap((delegatedStake) => { | ||
return delegatedStake.stakes.map((stake) => { | ||
return { | ||
validatorAddress: delegatedStake.validatorAddress, | ||
estimatedReward: stake.status === 'Active' ? stake.estimatedReward : '', | ||
stakeActiveEpoch: stake.stakeActiveEpoch, | ||
stakeRequestEpoch: stake.stakeRequestEpoch, | ||
status: stake.status, | ||
stakedIotaId: stake.stakedIotaId, | ||
principal: stake.principal, | ||
}; | ||
}); | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
import { Box, Button } from '@/components/index'; | ||
import { ExtendedDelegatedStake } from '@iota/core'; | ||
|
||
interface StakeCardProps { | ||
stake: ExtendedDelegatedStake; | ||
onDetailsClick: (stake: ExtendedDelegatedStake) => void; | ||
} | ||
|
||
function StakeCard({ stake, onDetailsClick }: StakeCardProps): JSX.Element { | ||
return ( | ||
<Box> | ||
<div>Validator: {stake.validatorAddress}</div> | ||
<div>Stake: {stake.principal}</div> | ||
{stake.status === 'Active' && <p>Estimated reward: {stake.estimatedReward}</p>} | ||
<div>Status: {stake.status}</div> | ||
<Button onClick={() => onDetailsClick(stake)}>Details</Button> | ||
</Box> | ||
); | ||
} | ||
|
||
export default StakeCard; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export { default as StakeCard } from './StakeCard'; | ||
export { default as AssetCard } from './AssetCard'; |
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
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
Oops, something went wrong.