Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Fix free claims #2160

Merged
merged 4 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/custom/pages/Claim/ClaimsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ const ClaimsTableRow = ({
Ends in: <b>28 days, 10h, 50m</b>
</span>
</td>
<td>{type === ClaimType.Airdrop ? 'No' : '4 years (linear)'}</td>
<td>28 days, 10h, 50m</td>
</ClaimTr>
)
}
Expand Down
8 changes: 4 additions & 4 deletions src/custom/pages/Claim/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export type ClaimCommonTypes = {

// Enhanced UserClaimData with useful additional properties
export type EnhancedUserClaimData = UserClaimData & {
currencyAmount: CurrencyAmount<Token | GpEther> | undefined
claimAmount: CurrencyAmount<Token> | undefined
price: Price<Currency, Currency> | undefined
cost: CurrencyAmount<Currency> | undefined
currencyAmount?: CurrencyAmount<Token | GpEther> | undefined
claimAmount?: CurrencyAmount<Token> | undefined
alfetopito marked this conversation as resolved.
Show resolved Hide resolved
price?: Price<Currency, Currency> | undefined
cost?: CurrencyAmount<Currency> | undefined
isFree: boolean
}
43 changes: 21 additions & 22 deletions src/custom/state/claim/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,37 +749,36 @@ export function useUserEnhancedClaimData(account: Account): EnhancedUserClaimDat
const chainId = supportedChainId(preCheckChainId)
if (!chainId) return []

return sorted.reduce<EnhancedUserClaimData[]>((acc, claim) => {
const tokenAndAmount = claimTypeToTokenAmount(claim.type, chainId)

if (!tokenAndAmount) return acc

const price = new Price({
baseAmount: ONE_VCOW,
quoteAmount: CurrencyAmount.fromRawAmount(tokenAndAmount.token, tokenAndAmount.amount),
}).invert()

// get the currency amount using the price base currency (remember price was inverted) and claim amount
const currencyAmount = CurrencyAmount.fromRawAmount(price.baseCurrency, claim.amount)
return sorted.map<EnhancedUserClaimData>((claim) => {
const claimAmount = CurrencyAmount.fromRawAmount(ONE_VCOW.currency, claim.amount)
alfetopito marked this conversation as resolved.
Show resolved Hide resolved

// e.g 1000 vCow / 20 GNO = 50 GNO cost
const cost = currencyAmount.divide(price)
const tokenAndAmount = claimTypeToTokenAmount(claim.type, chainId)

acc.push({
const data: EnhancedUserClaimData = {
...claim,
isFree: isFreeClaim(claim.type),
currencyAmount,
claimAmount,
price,
cost,
})
}

if (!tokenAndAmount) {
return data
} else {
data.price = new Price({
baseAmount: ONE_VCOW,
quoteAmount: CurrencyAmount.fromRawAmount(tokenAndAmount.token, tokenAndAmount.amount),
}).invert()
// get the currency amount using the price base currency (remember price was inverted) and claim amount
data.currencyAmount = CurrencyAmount.fromRawAmount(data.price.baseCurrency, claim.amount)

return acc
}, [])
// e.g 1000 vCow / 20 GNO = 50 GNO cost
data.cost = data.currencyAmount.divide(data.price)

return data
}
})
}, [preCheckChainId, sorted])
}

function _sortTypes(a: UserClaimData, b: UserClaimData): number {
return Number(isFreeClaim(a.type)) - Number(isFreeClaim(b.type))
return Number(isFreeClaim(b.type)) - Number(isFreeClaim(a.type))
}