-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(registry) feat: Next epoch reward estimates are also visible on comp…
…onent and agent Registry pages (#59) * feat: init - add next epoch rewards row * feat: create new library for common contract functions * chore: minor improvements * refactor: Update DetailsSubInfo component to use custom hook for tokenomics unit type * refactor: Update RewardsSection to fetch and display pending incentives * refactor: Update RewardsSection to fetch and display pending incentives * chore: format document autonolas-registry/common-util/Contracts * feat: move tokenomics.js to tokenomics.ts add export TOKENOMICS to util-contracts library * chore: declare module for tokenomics.js in util-contracts * refractor: convert rewards.js to rewards.ts * refractor: move claimable rewards to hooks (using useReadContract) * feat: add useClaimableRewards, try to move other rewards to hooks * refactor: Update RewardsSection to fetch and display pending incentives * refractor: udpate configs * fix: broken tests for agent * test: add test for component details reward section * refactor: skip test for common-utils/addresses * refractor: cleanup rewards.ts and add fetch to useRewards * refractor: remove getMapUnitIncentivesRequest from tokenomics and use from common-contract-functions * refactor: update test for common-utils/addresses (skip for 2 test-cases as of now) * refractor: minor improvement * , * refactor: Fix typo in error message for notifications * cd '/Users/mohandas/work/open-source-valory/autonolas-frontend-mono' * test: rewards util * refactor: Improve getMapUnitIncentivesRequest function in rewards.ts by using only biginit * refactor: Improve getMapUnitIncentivesRequest function in rewards.ts * style: review changes by Roman
- Loading branch information
1 parent
0ed9251
commit 9373860
Showing
37 changed files
with
708 additions
and
365 deletions.
There are no files selected for viewing
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
111 changes: 83 additions & 28 deletions
111
apps/autonolas-registry/common-util/Details/DetailsSubInfo/RewardsSection.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 |
---|---|---|
@@ -1,42 +1,97 @@ | ||
import { Col, Flex, Row } from 'antd'; | ||
import { FC, memo } from 'react'; | ||
import { formatEther } from 'viem'; | ||
import { FC, useEffect, useState } from 'react'; | ||
import { Address } from 'viem'; | ||
|
||
import { getPendingIncentives, useClaimableIncentives } from 'libs/common-contract-functions/src'; | ||
import { UNICODE_SYMBOLS } from 'libs/util-constants/src/lib/symbols'; | ||
import { TOKENOMICS } from 'libs/util-contracts/src'; | ||
|
||
import { getEthersProviderForEthereum, getTokenomicsEthersContract } from 'common-util/Contracts'; | ||
|
||
import { RewardsStatistic } from '../styles'; | ||
import { useTokenomicsUnitType } from './hooks'; | ||
|
||
/** | ||
* Formats reward values to required decimal places | ||
*/ | ||
const rewardsFormatter = (reward: bigint, dp: number) => | ||
parseFloat(formatEther(reward)).toLocaleString('en', { | ||
maximumFractionDigits: dp, | ||
minimumFractionDigits: dp, | ||
}); | ||
type RewardsColumnProps = { title: string; statistic: null | string; loading?: boolean }; | ||
|
||
const RewardColumn = ({ title, statistic }: { title: string; statistic: string }) => ( | ||
const RewardColumn = ({ title, statistic, loading }: RewardsColumnProps) => ( | ||
<Col span={24} xl={12}> | ||
<RewardsStatistic title={title} value={statistic} /> | ||
<RewardsStatistic title={title} value={statistic || '--'} loading={!!loading} /> | ||
</Col> | ||
); | ||
|
||
type RewardsSectionProps = { reward: bigint; topUp: bigint }; | ||
export const RewardsSection: FC<RewardsSectionProps> = memo(function RewardsSection({ | ||
reward, | ||
topUp, | ||
}) { | ||
type RewardsSectionProps = { | ||
ownerAddress: Address; | ||
id: string; | ||
type: string; | ||
dataTestId: string; | ||
}; | ||
|
||
export const RewardsSection: FC<RewardsSectionProps> = ({ ownerAddress, id, type, dataTestId }) => { | ||
const [isPendingIncentivesLoading, setIsPendingIncentivesLoading] = useState<boolean>(true); | ||
const [pendingIncentives, setPendingIncentives] = useState<{ | ||
reward: string; | ||
topUp: string; | ||
} | null>(null); | ||
|
||
const tokenomicsUnitType = useTokenomicsUnitType(type); | ||
const { | ||
isFetching, | ||
reward: claimableReward, | ||
topUp: claimableTopup, | ||
} = useClaimableIncentives( | ||
TOKENOMICS.addresses[1], | ||
TOKENOMICS.abi, | ||
ownerAddress, | ||
id, | ||
tokenomicsUnitType, | ||
); | ||
|
||
useEffect(() => { | ||
const provider = getEthersProviderForEthereum(); | ||
const contract = getTokenomicsEthersContract(TOKENOMICS.addresses[1]); | ||
|
||
getPendingIncentives(provider, contract, `${tokenomicsUnitType}`, id) | ||
.then((data) => setPendingIncentives(data)) | ||
.catch((error) => console.error(error)) | ||
.finally(() => setIsPendingIncentivesLoading(false)); | ||
}, [ownerAddress, id, tokenomicsUnitType]); | ||
|
||
return ( | ||
<Flex vertical gap={4}> | ||
<Row> | ||
<RewardColumn title={'Claimable Reward'} statistic={`${rewardsFormatter(reward, 4)} ETH`} /> | ||
<RewardColumn title={'Claimable Top-Up'} statistic={`${rewardsFormatter(topUp, 2)} OLAS`} /> | ||
</Row> | ||
<Row> | ||
<a href="https://tokenomics.olas.network/donate"> | ||
Make donation {UNICODE_SYMBOLS.EXTERNAL_LINK} | ||
</a> | ||
</Row> | ||
<Flex gap={16} vertical className="mt-12" data-testid={dataTestId}> | ||
<Flex vertical gap={4}> | ||
<Row> | ||
<RewardColumn | ||
title="Claimable Reward" | ||
statistic={claimableReward ? `${claimableReward} ETH` : null} | ||
loading={isFetching} | ||
/> | ||
<RewardColumn | ||
title="Claimable Top Up" | ||
statistic={claimableTopup ? `${claimableTopup} OLAS` : null} | ||
/> | ||
</Row> | ||
</Flex> | ||
|
||
<Flex vertical gap={12}> | ||
<Row> | ||
<RewardColumn | ||
title="Pending Reward" | ||
statistic={pendingIncentives ? `${pendingIncentives?.reward} ETH` : null} | ||
loading={isPendingIncentivesLoading} | ||
/> | ||
<RewardColumn | ||
title="Pending Top Up" | ||
statistic={pendingIncentives ? `${pendingIncentives?.topUp} OLAS` : null} | ||
loading={isPendingIncentivesLoading} | ||
/> | ||
</Row> | ||
|
||
<Row> | ||
<a href="https://tokenomics.olas.network/donate"> | ||
Make donation {UNICODE_SYMBOLS.EXTERNAL_LINK} | ||
</a> | ||
</Row> | ||
</Flex> | ||
</Flex> | ||
); | ||
}); | ||
}; |
7 changes: 7 additions & 0 deletions
7
apps/autonolas-registry/common-util/Details/DetailsSubInfo/hooks.ts
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,7 @@ | ||
import { NAV_TYPES, TOKENOMICS_UNIT_TYPES } from '../../../util/constants'; | ||
|
||
export const useTokenomicsUnitType = (type?: string) => { | ||
if (type === NAV_TYPES.COMPONENT) return TOKENOMICS_UNIT_TYPES.COMPONENT; | ||
if (type === NAV_TYPES.AGENT) return TOKENOMICS_UNIT_TYPES.AGENT; | ||
return; | ||
}; |
Oops, something went wrong.