Skip to content

Commit

Permalink
Merge branch 'main' into fix-dev-env
Browse files Browse the repository at this point in the history
  • Loading branch information
sophialittlejohn authored Jan 19, 2024
2 parents 1f4a74c + bdc842a commit b521b79
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 67 deletions.
80 changes: 41 additions & 39 deletions centrifuge-app/src/components/ExpiringCFGRewardsBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const ExpiringCFGRewardsBanner = () => {
const [isOpen, setIsOpen] = React.useState(true)
const { data } = useUserRewards()

const hasUnclaimedRewards = data?.links.some((link) => (link.claimable ? !link.claimable?.isZero() : false))
const hasLinkedRewards = data?.links.some((link) => (link.claimable?.isZero() === true ? false : true))
const hasUnlinkedRewards = data?.unlinkedRewards?.isZero() === false ? true : false

const expirationDate = new Date('2024-01-29T15:01')
const currentDateCET = new Date().toLocaleString('en-US', { timeZone: 'CET' })
const currentDateCETMillis = new Date(currentDateCET).getTime()
Expand All @@ -17,44 +19,44 @@ export const ExpiringCFGRewardsBanner = () => {
year: 'numeric',
})} at ${expirationDate.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true }).toLowerCase()}`

if (!hasUnclaimedRewards || isExpired) {
return null
if ((hasLinkedRewards || hasUnlinkedRewards) && !isExpired) {
return (
<Banner
isOpen={isOpen}
onClose={() => setIsOpen(false)}
title={
<Text as="h3" color="textInverted" variant="heading5">
Claim your Tinlake Rewards before it is too late. Rewards will expire on {formattedExpirationDate} CET.
After the deadline, users will not be able to claim their CFG rewards. Check{' '}
<Text
target="_blank"
as="a"
href="https://legacy.tinlake.centrifuge.io/rewards"
color="textInverted"
variant="heading5"
display="inline"
textDecoration="underline"
>
here
</Text>{' '}
if you have unclaimed rewards. Read more about the community vote{' '}
<Text
target="_blank"
as="a"
href="https://gov.centrifuge.io/t/cp81-unclaimed-tinlake-rewards/5885/4"
color="textInverted"
variant="heading5"
display="inline"
textDecoration="underline"
>
here
</Text>
.
</Text>
}
/>
)
}

return (
<Banner
isOpen={isOpen}
onClose={() => setIsOpen(false)}
title={
<Text as="h3" color="textInverted" variant="heading5">
Claim your Tinlake Rewards before it is too late. Rewards will expire on {formattedExpirationDate} CET. After
the deadline, users will not be able to claim their CFG rewards. Check{' '}
<Text
target="_blank"
as="a"
href="https://legacy.tinlake.centrifuge.io/rewards"
color="textInverted"
variant="heading5"
display="inline"
textDecoration="underline"
>
here
</Text>{' '}
if you have unclaimed rewards. Read more about the community vote{' '}
<Text
target="_blank"
as="a"
href="https://gov.centrifuge.io/t/cp81-unclaimed-tinlake-rewards/5885/4"
color="textInverted"
variant="heading5"
display="inline"
textDecoration="underline"
>
here
</Text>
.
</Text>
}
/>
)
return null
}
51 changes: 23 additions & 28 deletions centrifuge-app/src/utils/tinlake/useTinlakeRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import Decimal from 'decimal.js-light'
import { useQuery } from 'react-query'
import { combineLatest, map } from 'rxjs'
import { useAddress } from '../../utils/useAddress'
import { isEvmAddress } from '../address'
import { RewardBalance, RewardClaim, RewardDayTotals, RewardsData, UserRewardsData } from './types'

async function getTinlakeUserRewards(ethAddr: string) {
let rewardBalances: RewardBalance[] = []

const response = await fetch(
'https://api.goldsky.com/api/public/project_clhi43ef5g4rw49zwftsvd2ks/subgraphs/main/prod/gn',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `
const response = await fetch(import.meta.env.REACT_APP_TINLAKE_SUBGRAPH_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `
query GetRewardBalances($address: String!) {
rewardBalances(where: {id: $address}) {
links {
Expand All @@ -30,12 +29,11 @@ async function getTinlakeUserRewards(ethAddr: string) {
}
}
`,
variables: {
address: ethAddr.toLowerCase(),
},
}),
}
)
variables: {
address: ethAddr.toLowerCase(),
},
}),
})

if (response?.ok) {
const { data } = await response.json()
Expand Down Expand Up @@ -69,22 +67,20 @@ async function getTinlakeUserRewards(ethAddr: string) {

export function useTinlakeUserRewards(ethAddr?: string | null) {
return useQuery(['getTinlakeUserRewards', ethAddr], () => getTinlakeUserRewards(ethAddr!), {
enabled: !!ethAddr,
enabled: !!ethAddr && isEvmAddress(ethAddr),
})
}

async function getTinlakeRewards(): Promise<RewardsData | null> {
let rewardDayTotals: RewardDayTotals[] = []

const response = await fetch(
'https://api.goldsky.com/api/public/project_clhi43ef5g4rw49zwftsvd2ks/subgraphs/main/prod/gn',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `
const response = await fetch(import.meta.env.REACT_APP_TINLAKE_SUBGRAPH_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `
query GetRewardDayTotals {
rewardDayTotals(first: 1, skip: 1, orderBy: id, orderDirection: desc) {
dropRewardRate
Expand All @@ -95,9 +91,8 @@ async function getTinlakeRewards(): Promise<RewardsData | null> {
}
}
`,
}),
}
)
}),
})

if (response?.ok) {
const { data } = await response.json()
Expand Down

0 comments on commit b521b79

Please sign in to comment.