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

Commit

Permalink
Small claim fixes (#2153)
Browse files Browse the repository at this point in the history
* Rinkeby also deserves its own USDC claiming

* Work with native currency instead of their wrapped version

* Renoved unused constants

* Refactored out _sortTypes function from useUserEnhancedClaimData hook

* Fixing build...

* Using new object with USDC on every chain

Co-authored-by: Leandro <[email protected]>
  • Loading branch information
alfetopito and Leandro authored Jan 14, 2022
1 parent bd559e6 commit e492c21
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/custom/pages/Claim/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { UserClaimData } from 'state/claim/hooks'
import { Currency, CurrencyAmount, Price, Token } from '@uniswap/sdk-core'
import { SyntheticEvent } from 'react'
import { GpEther } from 'constants/tokens'

export type ClaimCommonTypes = {
account: string | null | undefined
Expand All @@ -11,7 +12,7 @@ export type ClaimCommonTypes = {

// Enhanced UserClaimData with useful additional properties
export type EnhancedUserClaimData = UserClaimData & {
currencyAmount: CurrencyAmount<Token> | undefined
currencyAmount: CurrencyAmount<Token | GpEther> | undefined
claimAmount: CurrencyAmount<Token> | undefined
price: Price<Currency, Currency> | undefined
cost: CurrencyAmount<Currency> | undefined
Expand Down
13 changes: 6 additions & 7 deletions src/custom/state/claim/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ export const NATIVE_TOKEN_PRICE: { [chain in SupportedChainId]: string } = {
export const GNO_PRICE = '375000000000000' // '0.000375' GNO (18 decimals) per vCOW, in atoms
export const USDC_PRICE = '150000' // '0.15' USDC (6 decimals) per vCOW, in atoms

export const GNO_SYMBOL = 'GNO'
export const USDC_SYMBOL = 'USDC'

// Constants regarding investment time windows
const TWO_WEEKS = ms`2 weeks`
const SIX_WEEKS = ms`6 weeks`
Expand Down Expand Up @@ -748,9 +745,7 @@ export function useUserEnhancedClaimData(account: Account): EnhancedUserClaimDat
const { available } = useClassifiedUserClaims(account)
const { chainId: preCheckChainId } = useActiveWeb3React()

const checkType = useCallback((type) => Number(FREE_CLAIM_TYPES.includes(type)), [])

const sorted = useMemo(() => available.sort((a, b) => checkType(b.type) - checkType(a.type)), [available, checkType])
const sorted = useMemo(() => available.sort(_sortTypes), [available])

return useMemo(() => {
const chainId = supportedChainId(preCheckChainId)
Expand All @@ -767,7 +762,7 @@ export function useUserEnhancedClaimData(account: Account): EnhancedUserClaimDat
}).invert()

// get the currency amount using the price base currency (remember price was inverted) and claim amount
const currencyAmount = CurrencyAmount.fromRawAmount(price.baseCurrency.wrapped, claim.amount)
const currencyAmount = CurrencyAmount.fromRawAmount(price.baseCurrency, claim.amount)
const claimAmount = CurrencyAmount.fromRawAmount(ONE_VCOW.currency, claim.amount)

// e.g 1000 vCow / 20 GNO = 50 GNO cost
Expand All @@ -786,3 +781,7 @@ export function useUserEnhancedClaimData(account: Account): EnhancedUserClaimDat
}, [])
}, [preCheckChainId, sorted])
}

function _sortTypes(a: UserClaimData, b: UserClaimData): number {
return Number(isFreeClaim(a.type)) - Number(isFreeClaim(b.type))
}
10 changes: 5 additions & 5 deletions src/custom/state/claim/hooks/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { CurrencyAmount, Token } from '@uniswap/sdk-core'

import { SupportedChainId } from 'constants/chains'
import { GNO, USDC, V_COW, WETH9_EXTENDED } from 'constants/tokens'
import { GNO, GpEther, USDC_BY_CHAIN, V_COW } from 'constants/tokens'

import {
CLAIMS_REPO,
ClaimType,
Expand Down Expand Up @@ -161,17 +163,15 @@ export type PaidClaimTypeToPriceMap = {

/**
* Helper function to get vCow price based on claim type and chainId
*
* @param type
*/
export function claimTypeToTokenAmount(type: ClaimType, chainId: SupportedChainId) {
switch (type) {
case ClaimType.GnoOption:
return { token: GNO[chainId], amount: GNO_PRICE }
case ClaimType.Investor:
return { token: USDC, amount: USDC_PRICE }
return { token: USDC_BY_CHAIN[chainId], amount: USDC_PRICE }
case ClaimType.UserOption:
return { token: WETH9_EXTENDED[chainId], amount: NATIVE_TOKEN_PRICE[chainId] }
return { token: GpEther.onChain(chainId), amount: NATIVE_TOKEN_PRICE[chainId] }
default:
return undefined
}
Expand Down

0 comments on commit e492c21

Please sign in to comment.