-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/staging' into feat/simple-ota
- Loading branch information
Showing
17 changed files
with
202 additions
and
49 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
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
80 changes: 80 additions & 0 deletions
80
frontend/components/MainPage/sections/RewardsSection/StakingRewardsThisEpoch.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,80 @@ | ||
import { InfoCircleOutlined } from '@ant-design/icons'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { Popover, Typography } from 'antd'; | ||
import { gql, request } from 'graphql-request'; | ||
import { z } from 'zod'; | ||
|
||
import { SUBGRAPH_URL } from '@/constants/urls'; | ||
import { POPOVER_WIDTH_MEDIUM } from '@/constants/width'; | ||
import { useStakingProgram } from '@/hooks/useStakingProgram'; | ||
import { formatToTime } from '@/utils/time'; | ||
|
||
const { Text } = Typography; | ||
|
||
const EpochTimeResponseSchema = z.object({ | ||
epochLength: z.string(), | ||
blockTimestamp: z.string(), | ||
}); | ||
type EpochTimeResponse = z.infer<typeof EpochTimeResponseSchema>; | ||
|
||
const useEpochEndTime = () => { | ||
const { activeStakingProgramAddress } = useStakingProgram(); | ||
const latestEpochTimeQuery = gql` | ||
query { | ||
checkpoints( | ||
orderBy: epoch | ||
orderDirection: desc | ||
first: 1 | ||
where: { | ||
contractAddress: "${activeStakingProgramAddress}" | ||
} | ||
) { | ||
epochLength | ||
blockTimestamp | ||
} | ||
} | ||
`; | ||
|
||
const { data, isLoading } = useQuery({ | ||
queryKey: ['latestEpochTime'], | ||
queryFn: async () => { | ||
const response = (await request(SUBGRAPH_URL, latestEpochTimeQuery)) as { | ||
checkpoints: EpochTimeResponse[]; | ||
}; | ||
return EpochTimeResponseSchema.parse(response.checkpoints[0]); | ||
}, | ||
select: (data) => { | ||
// last epoch end time + epoch length | ||
return Number(data.blockTimestamp) + Number(data.epochLength); | ||
}, | ||
enabled: !!activeStakingProgramAddress, | ||
}); | ||
|
||
return { data, isLoading }; | ||
}; | ||
|
||
export const StakingRewardsThisEpoch = () => { | ||
const { data: epochEndTimeInMs } = useEpochEndTime(); | ||
const { activeStakingProgramMeta } = useStakingProgram(); | ||
|
||
return ( | ||
<Text type="secondary"> | ||
Staking rewards this epoch | ||
<Popover | ||
arrow={false} | ||
content={ | ||
<div style={{ maxWidth: POPOVER_WIDTH_MEDIUM }}> | ||
The epoch for {activeStakingProgramMeta?.name} ends each day at ~{' '} | ||
<Text className="text-sm" strong> | ||
{epochEndTimeInMs | ||
? `${formatToTime(epochEndTimeInMs * 1000)} (UTC)` | ||
: '--'} | ||
</Text> | ||
</div> | ||
} | ||
> | ||
<InfoCircleOutlined /> | ||
</Popover> | ||
</Text> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const CONTENT_TYPE_JSON_UTF8 = { | ||
'Content-Type': 'application/json; charset=utf-8', | ||
}; | ||
} as const; |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export const MODAL_WIDTH = 412; | ||
|
||
export const POPOVER_WIDTH_MEDIUM = 260; |
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
Oops, something went wrong.