-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from AudiusProject/jowlee-rewards
Add estimated reward
- Loading branch information
Showing
26 changed files
with
779 additions
and
13 deletions.
There are no files selected for viewing
Empty file.
26 changes: 26 additions & 0 deletions
26
packages/protocol-dashboard/src/components/EstimatedAnnualStat/EstimatedAnnualStat.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,26 @@ | ||
import React from 'react' | ||
|
||
import RewardStat from 'components/RewardStat' | ||
import { useAnnualRewardRate } from 'hooks/useRewardRate' | ||
import { Status } from 'types' | ||
|
||
const messages = { | ||
label: `ESTIMATED ANNUAL REWARD RATE` | ||
} | ||
|
||
interface EstimatedAnnualStatProps { | ||
className?: string | ||
} | ||
|
||
const EstimatedAnnualStat: React.FC<EstimatedAnnualStatProps> = ({ | ||
className | ||
}) => { | ||
const claimRate = useAnnualRewardRate() | ||
const value = | ||
claimRate.status === Status.Success | ||
? `${claimRate.rate!.toFixed(0)}%` | ||
: null | ||
return <RewardStat label={messages.label} stat={value} /> | ||
} | ||
|
||
export default EstimatedAnnualStat |
1 change: 1 addition & 0 deletions
1
packages/protocol-dashboard/src/components/EstimatedAnnualStat/index.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 @@ | ||
export { default } from './EstimatedAnnualStat' |
28 changes: 28 additions & 0 deletions
28
packages/protocol-dashboard/src/components/EstimatedWeeklyStat/EstimatedWeeklyStat.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,28 @@ | ||
import React from 'react' | ||
|
||
import RewardStat from 'components/RewardStat' | ||
import { Status } from 'types' | ||
import { useWeeklyRewardRate } from 'hooks/useRewardRate' | ||
|
||
const messages = { | ||
label: `ESTIMATED WEEKLY REWARD RATE` | ||
} | ||
|
||
interface EstimatedWeeklyStatProps { | ||
className?: string | ||
} | ||
|
||
const EstimatedWeeklyStat: React.FC<EstimatedWeeklyStatProps> = ({ | ||
className | ||
}) => { | ||
const claimRate = useWeeklyRewardRate() | ||
const value = | ||
claimRate.status === Status.Success | ||
? `${claimRate.rate!.toFixed(3)}%` | ||
: null | ||
return ( | ||
<RewardStat className={className} label={messages.label} stat={value} /> | ||
) | ||
} | ||
|
||
export default EstimatedWeeklyStat |
1 change: 1 addition & 0 deletions
1
packages/protocol-dashboard/src/components/EstimatedWeeklyStat/index.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 @@ | ||
export { default } from './EstimatedWeeklyStat' |
33 changes: 33 additions & 0 deletions
33
packages/protocol-dashboard/src/components/MyEstimatedRewards/MyEstimatedRewards.module.css
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,33 @@ | ||
.container { | ||
display: inline-flex; | ||
flex-direction: column; | ||
align-items: center; | ||
padding: 0px; | ||
width: 300px; | ||
min-width: 300px; | ||
} | ||
|
||
.rowContainer { | ||
display: inline-flex; | ||
width: 100%; | ||
justify-content: space-between; | ||
margin-bottom: 2px; | ||
} | ||
|
||
.label { | ||
font-weight: var(--font-bold); | ||
font-size: var(--font-m); | ||
letter-spacing: 0.01em; | ||
text-transform: uppercase; | ||
color: var(--neutral-light-4); | ||
} | ||
|
||
.value { | ||
font-weight: var(--font-bold); | ||
font-size: var(--font-m); | ||
|
||
text-align: right; | ||
letter-spacing: 0.01em; | ||
text-transform: uppercase; | ||
color: var(--neutral); | ||
} |
71 changes: 71 additions & 0 deletions
71
packages/protocol-dashboard/src/components/MyEstimatedRewards/MyEstimatedRewards.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,71 @@ | ||
import React, { ReactNode } from 'react' | ||
|
||
import Paper from 'components/Paper' | ||
import styles from './MyEstimatedRewards.module.css' | ||
import { TICKER } from 'utils/consts' | ||
import { Address, Status } from 'types' | ||
import { | ||
useUserAnnualRewardRate, | ||
useUserWeeklyRewards | ||
} from 'store/cache/rewards/hooks' | ||
import Loading from 'components/Loading' | ||
import DisplayAudio from 'components/DisplayAudio' | ||
|
||
const messages = { | ||
staked: `Staked ${TICKER}`, | ||
estAnnualRewards: 'Est. Annual Reward', | ||
estWeeklyRewards: 'Est. Weekly Reward' | ||
} | ||
|
||
type RowStatProps = { | ||
label: string | ||
value: ReactNode | ||
} | ||
const RowStat: React.FC<RowStatProps> = ({ label, value }) => { | ||
return ( | ||
<div className={styles.rowContainer}> | ||
<div className={styles.label}>{label}</div> | ||
<div className={styles.value}>{value}</div> | ||
</div> | ||
) | ||
} | ||
|
||
type OwnProps = { | ||
wallet: Address | ||
} | ||
|
||
type MyEstimatedRewardsProps = OwnProps | ||
|
||
/** | ||
* Shows stats about staking. Lives on the SP page | ||
*/ | ||
const MyEstimatedRewards: React.FC<MyEstimatedRewardsProps> = ({ wallet }) => { | ||
const weeklyRewards = useUserWeeklyRewards({ wallet }) | ||
const annualRewards = useUserAnnualRewardRate({ wallet }) | ||
const isLoading = | ||
weeklyRewards.status === Status.Loading || | ||
annualRewards.status === Status.Loading | ||
const annual = annualRewards.reward ? ( | ||
<DisplayAudio amount={annualRewards.reward} /> | ||
) : null | ||
|
||
const weekly = | ||
'reward' in weeklyRewards ? ( | ||
<DisplayAudio amount={weeklyRewards.reward} /> | ||
) : null | ||
|
||
return ( | ||
<Paper className={styles.container}> | ||
{isLoading ? ( | ||
<Loading /> | ||
) : ( | ||
<> | ||
<RowStat label={messages.estAnnualRewards} value={annual} /> | ||
<RowStat label={messages.estWeeklyRewards} value={weekly} /> | ||
</> | ||
)} | ||
</Paper> | ||
) | ||
} | ||
|
||
export default MyEstimatedRewards |
1 change: 1 addition & 0 deletions
1
packages/protocol-dashboard/src/components/MyEstimatedRewards/index.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 @@ | ||
export { default } from './MyEstimatedRewards' |
43 changes: 43 additions & 0 deletions
43
packages/protocol-dashboard/src/components/RewardStat/RewardStat.module.css
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,43 @@ | ||
/* Stats Container */ | ||
|
||
.container { | ||
padding: 0px 16px; | ||
display: inline-flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
min-width: 228px; | ||
min-height: 150px; | ||
box-sizing: border-box; | ||
align-items: center; | ||
} | ||
|
||
.stat { | ||
font-family: var(--font-family); | ||
font-weight: 900; | ||
font-size: 64px; | ||
height: 76px; | ||
text-align: center; | ||
display: inline; | ||
background: -webkit-linear-gradient(315deg, #7652CC 2.04%, #B05CE6 100%); | ||
-webkit-background-clip: text; | ||
-webkit-text-fill-color: transparent; | ||
} | ||
|
||
.label, | ||
.description { | ||
font-family: var(--font-family); | ||
font-weight: var(--font-bold); | ||
font-size: var(--font-l); | ||
line-height: 22px; | ||
text-align: center; | ||
letter-spacing: 0.04em; | ||
text-transform: uppercase; | ||
color: #BEC5E0; | ||
user-select: none; | ||
} | ||
|
||
.loadingContainer { | ||
height: 62px; | ||
display: flex; | ||
align-items: center; | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/protocol-dashboard/src/components/RewardStat/RewardStat.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,42 @@ | ||
import React, { ReactNode } from 'react' | ||
|
||
import Paper from 'components/Paper' | ||
import styles from './RewardStat.module.css' | ||
import Loading from 'components/Loading' | ||
import Error from 'components/Error' | ||
import clsx from 'clsx' | ||
|
||
type OwnProps = { | ||
className?: string | ||
stat: ReactNode | ||
label: string | ||
error?: boolean | ||
} | ||
|
||
type RewardStatProps = OwnProps | ||
|
||
const RewardStat: React.FC<RewardStatProps> = ({ | ||
className, | ||
stat, | ||
label, | ||
error | ||
}) => { | ||
return ( | ||
<Paper className={clsx(styles.container, { [className!]: className })}> | ||
{error ? ( | ||
<div className={styles.stat}> | ||
<Error /> | ||
</div> | ||
) : stat !== null ? ( | ||
<div className={styles.stat}>{stat}</div> | ||
) : ( | ||
<div className={styles.loadingContainer}> | ||
<Loading className={styles.loading} /> | ||
</div> | ||
)} | ||
<div className={styles.label}>{label}</div> | ||
</Paper> | ||
) | ||
} | ||
|
||
export default RewardStat |
1 change: 1 addition & 0 deletions
1
packages/protocol-dashboard/src/components/RewardStat/index.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 @@ | ||
export { default } from './RewardStat' |
3 changes: 2 additions & 1 deletion
3
packages/protocol-dashboard/src/components/StatsChip/StatsChip.module.css
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 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,31 @@ | ||
import AudiusClient from 'services/Audius' | ||
import useTotalStaked from './useTotalStaked' | ||
import { useFundsPerRound } from 'store/cache/claims/hooks' | ||
import { Status } from 'types' | ||
|
||
export const useWeeklyRewardRate = () => { | ||
const fundsPerRound = useFundsPerRound() | ||
const totalActiveStake = useTotalStaked() | ||
if ( | ||
fundsPerRound.status === Status.Success && | ||
totalActiveStake.status === Status.Success | ||
) { | ||
const percentage = | ||
AudiusClient.getBNPercentage( | ||
fundsPerRound.amount!, | ||
totalActiveStake.total!, | ||
4 | ||
) * 100 | ||
return { status: Status.Success, rate: percentage } | ||
} | ||
return { status: Status.Loading } | ||
} | ||
|
||
export const useAnnualRewardRate = () => { | ||
const weeklyClaim = useWeeklyRewardRate() | ||
if (weeklyClaim.status === Status.Success) { | ||
const rate = weeklyClaim.rate! * 52 | ||
return { status: Status.Success, rate } | ||
} | ||
return { status: Status.Loading } | ||
} |
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.