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

Commit

Permalink
[CoW Subsidy] - connect real hook to other stuff (#2574)
Browse files Browse the repository at this point in the history
* connect actual (v)CoW balance hook to subsidy

* path fix

Co-authored-by: Leandro Boscariol <[email protected]>

Co-authored-by: Leandro Boscariol <[email protected]>
  • Loading branch information
W3stside and alfetopito authored Mar 23, 2022
1 parent 1e02a05 commit fde86c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/custom/components/CowSubsidyModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default function CowSubsidyModal({
}: Pick<ConfirmationModalProps, 'isOpen'> & Omit<ConfirmationModalContentProps, 'title' | 'topContent'>) {
const { account, chainId } = useActiveWeb3React()

// TODO: update with latest code
const { subsidy, balance } = useCowBalanceAndSubsidy()

const TopContent = useCallback(
Expand Down
22 changes: 7 additions & 15 deletions src/custom/hooks/useCowBalanceAndSubsidy.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import { useMemo } from 'react'
import { CurrencyAmount } from '@uniswap/sdk-core'
import { BigNumber } from 'bignumber.js'
import { parseUnits } from '@ethersproject/units'

import { getDiscountFromBalance } from 'components/CowSubsidyModal/utils'
import { SupportedChainId } from 'constants/chains'
import { V_COW } from 'constants/tokens'
import { useActiveWeb3React } from '.'
import { useVCowData } from 'state/claim/hooks'
import { COW_SUBSIDY_DATA } from 'components/CowSubsidyModal/constants'

// TODO: get real balance
const MOCK_BALANCE = CurrencyAmount.fromRawAmount(
V_COW[SupportedChainId.RINKEBY],
parseUnits('111100.97', V_COW[SupportedChainId.MAINNET].decimals).toString()
)
export default function useCowBalanceAndSubsidy() {
const { chainId } = useActiveWeb3React()
const ZERO_BALANCE_SUBSIDY = { subsidy: { tier: 0, discount: COW_SUBSIDY_DATA[0][1] }, balance: undefined }

// TODO: vcow and cow balance from @nenadV91
/* const vCow = */ chainId ? V_COW[chainId] : undefined
const balance = MOCK_BALANCE // useTotalCowBalance(account || undefined, vCow)
export default function useCowBalanceAndSubsidy() {
const { total: balance } = useVCowData()

return useMemo(() => {
if (!balance) return ZERO_BALANCE_SUBSIDY

const balanceBn = new BigNumber(balance.quotient.toString())
return { subsidy: getDiscountFromBalance(balanceBn), balance }
}, [balance])
Expand Down

0 comments on commit fde86c4

Please sign in to comment.