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

Show real vCow and Cow data on profile page #2568

Merged
merged 6 commits into from
Mar 23, 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
22 changes: 22 additions & 0 deletions src/custom/abis/types/VCow.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PopulatedTransaction,
BaseContract,
ContractTransaction,
Overrides,
PayableOverrides,
CallOverrides,
} from "ethers";
Expand All @@ -31,6 +32,7 @@ interface VCowInterface extends ethers.utils.Interface {
"nativeTokenPrice()": FunctionFragment;
"swappableBalanceOf(address)": FunctionFragment;
"balanceOf(address)": FunctionFragment;
"swapAll()": FunctionFragment;
};

encodeFunctionData(
Expand Down Expand Up @@ -79,6 +81,7 @@ interface VCowInterface extends ethers.utils.Interface {
values: [string]
): string;
encodeFunctionData(functionFragment: "balanceOf", values: [string]): string;
encodeFunctionData(functionFragment: "swapAll", values?: undefined): string;

decodeFunctionResult(functionFragment: "claim", data: BytesLike): Result;
decodeFunctionResult(functionFragment: "claimMany", data: BytesLike): Result;
Expand All @@ -99,6 +102,7 @@ interface VCowInterface extends ethers.utils.Interface {
data: BytesLike
): Result;
decodeFunctionResult(functionFragment: "balanceOf", data: BytesLike): Result;
decodeFunctionResult(functionFragment: "swapAll", data: BytesLike): Result;

events: {
"Claimed(uint256,uint8,address,uint256,uint256)": EventFragment;
Expand Down Expand Up @@ -203,6 +207,10 @@ export class VCow extends BaseContract {
): Promise<[BigNumber]>;

balanceOf(user: string, overrides?: CallOverrides): Promise<[BigNumber]>;

swapAll(
overrides?: Overrides & { from?: string | Promise<string> }
): Promise<ContractTransaction>;
};

claim(
Expand Down Expand Up @@ -245,6 +253,10 @@ export class VCow extends BaseContract {

balanceOf(user: string, overrides?: CallOverrides): Promise<BigNumber>;

swapAll(
overrides?: Overrides & { from?: string | Promise<string> }
): Promise<ContractTransaction>;

callStatic: {
claim(
index: BigNumberish,
Expand Down Expand Up @@ -285,6 +297,8 @@ export class VCow extends BaseContract {
): Promise<BigNumber>;

balanceOf(user: string, overrides?: CallOverrides): Promise<BigNumber>;

swapAll(overrides?: CallOverrides): Promise<BigNumber>;
};

filters: {
Expand Down Expand Up @@ -366,6 +380,10 @@ export class VCow extends BaseContract {
): Promise<BigNumber>;

balanceOf(user: string, overrides?: CallOverrides): Promise<BigNumber>;

swapAll(
overrides?: Overrides & { from?: string | Promise<string> }
): Promise<BigNumber>;
};

populateTransaction: {
Expand Down Expand Up @@ -416,5 +434,9 @@ export class VCow extends BaseContract {
user: string,
overrides?: CallOverrides
): Promise<PopulatedTransaction>;

swapAll(
overrides?: Overrides & { from?: string | Promise<string> }
): Promise<PopulatedTransaction>;
};
}
13 changes: 13 additions & 0 deletions src/custom/abis/types/factories/VCow__factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ const _abi = [
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "swapAll",
outputs: [
{
internalType: "uint256",
name: "swappedBalance",
type: "uint256",
},
],
stateMutability: "nonpayable",
type: "function",
},
];

export class VCow__factory {
Expand Down
13 changes: 13 additions & 0 deletions src/custom/abis/vCow.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,18 @@
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "swapAll",
"outputs": [
{
"internalType": "uint256",
"name": "swappedBalance",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
4 changes: 2 additions & 2 deletions src/custom/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ export const GP_VAULT_RELAYER: Partial<Record<number, string>> = {
export const V_COW_CONTRACT_ADDRESS: Record<number, string> = {
[ChainId.MAINNET]: '0xd057b63f5e69cf1b929b356b579cba08d7688048',
[ChainId.XDAI]: '0xc20C9C13E853fc64d054b73fF21d3636B2d97eaB',
[ChainId.RINKEBY]: '0x5Bf4d1f8d1cB35E0aeA69B220beb97b8807504eA',
[ChainId.RINKEBY]: '0x9386177e95A853070076Df2403b9D547D653126D', // <- TODO: change these at some point after testing is done
}

export const COW_CONTRACT_ADDRESS: Record<number, string> = {
[ChainId.MAINNET]: '0xDEf1CA1fb7FBcDC777520aa7f396b4E015F497aB',
[ChainId.XDAI]: '0x177127622c4A00F3d409B75571e12cB3c8973d3c',
[ChainId.RINKEBY]: '0x263D0C7a63D25564cFDc299C97Fd92A61B5fc7d1',
[ChainId.RINKEBY]: '0xbdf1e19f8c78A77fb741b44EbA5e4c0C8DBAeF91', // <- TODO: change these at some point after testing is done
}

// See https://github.com/gnosis/gp-v2-contracts/commit/821b5a8da213297b0f7f1d8b17c893c5627020af#diff-12bbbe13cd5cf42d639e34a39d8795021ba40d3ee1e1a8282df652eb161a11d6R13
Expand Down
48 changes: 21 additions & 27 deletions src/custom/pages/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import { RefreshCcw } from 'react-feather'
import Web3Status from 'components/Web3Status'
import useReferralLink from 'hooks/useReferralLink'
import useFetchProfile from 'hooks/useFetchProfile'
import {
// formatSmartLocaleAware,
numberFormatter,
} from 'utils/format'
import { formatSmartLocaleAware, numberFormatter } from 'utils/format'
import { getExplorerAddressLink } from 'utils/explorer'
import useTimeAgo from 'hooks/useTimeAgo'
import { MouseoverTooltipContent } from 'components/Tooltip'
Expand All @@ -43,10 +40,10 @@ import SVG from 'react-inlinesvg'
import ArrowIcon from 'assets/cow-swap/arrow.svg'
import CowImage from 'assets/cow-swap/cow_v2.svg'
import CowProtocolImage from 'assets/cow-swap/cowprotocol.svg'
// import { useTokenBalance } from 'state/wallet/hooks'
// import { useVCowData } from 'state/claim/hooks'
// import { V_COW, COW } from 'constants/tokens'
// import { isPr, isLocal } from 'utils/environments'
import { useTokenBalance } from 'state/wallet/hooks'
import { useVCowData } from 'state/claim/hooks'
import { AMOUNT_PRECISION } from 'constants/index'
import { COW } from 'constants/tokens'

export default function Profile() {
const referralLink = useReferralLink()
Expand All @@ -56,31 +53,28 @@ export default function Profile() {
const isTradesTooltipVisible = account && chainId == 1 && !!profileData?.totalTrades
const hasOrders = useHasOrders(account)

// const vCowBalance = useTokenBalance(account || undefined, chainId ? V_COW[chainId] : undefined)
const vCowBalance = '10,240,800.32'
// const cowBalance = useTokenBalance(account || undefined, chainId ? COW[chainId] : undefined)
const cowBalance = '0'
// Cow balance
const cow = useTokenBalance(account || undefined, chainId ? COW[chainId] : undefined)

// vCow balance values
const { unvested, vested, total } = useVCowData()

// const { vested, total, unvested } = useVCowData()
const unvested = '9,240,800.32'
const vested = '1,240,800.32'
const cowBalance = formatSmartLocaleAware(cow, AMOUNT_PRECISION) || '0'
const vCowBalanceVested = formatSmartLocaleAware(vested, AMOUNT_PRECISION) || '0'
const vCowBalanceUnvested = formatSmartLocaleAware(unvested, AMOUNT_PRECISION) || '0'
const vCowBalance = formatSmartLocaleAware(total, AMOUNT_PRECISION) || '0'

// TODO: remove once this is not needed anymore
// if (isPr || isLocal) {
// console.force.log('vested', formatSmartLocaleAware(vested, vested?.currency.decimals))
// console.force.log('total', formatSmartLocaleAware(total, total?.currency.decimals))
// console.force.log('unvested', formatSmartLocaleAware(unvested, unvested?.currency.decimals))
// console.force.log('cowBalance', formatSmartLocaleAware(cowBalance, cowBalance?.currency.decimals))
// }
const hasCowBalance = cow && !cow.equalTo(0)
W3stside marked this conversation as resolved.
Show resolved Hide resolved
const hasVCowBalance = total && !total.equalTo(0)
W3stside marked this conversation as resolved.
Show resolved Hide resolved

const tooltipText = {
balanceBreakdown: (
<VestingBreakdown>
<span>
<i>Unvested</i> <p>{unvested} vCOW</p>
<i>Unvested</i> <p>{vCowBalanceUnvested} vCOW</p>
</span>
<span>
<i>Vested</i> <p>{vested} vCOW</p>
<i>Vested</i> <p>{vCowBalanceVested} vCOW</p>
</span>
</VestingBreakdown>
),
Expand Down Expand Up @@ -119,7 +113,7 @@ export default function Profile() {
<Title>Profile</Title>

<CardsWrapper>
{vCowBalance && (
{hasVCowBalance && (
<Card>
<BalanceDisplay hAlign="left">
<img src={vCOWImage} alt="vCOW token" width="56" height="56" />
Expand All @@ -141,7 +135,7 @@ export default function Profile() {
<HelpCircle size={14} />
</MouseoverTooltipContent>
</i>
<b>{vested}</b>
<b>{vCowBalanceVested}</b>
</BalanceDisplay>
<ButtonPrimary>
Convert to COW <SVG src={ArrowIcon} />
Expand All @@ -150,7 +144,7 @@ export default function Profile() {
</Card>
)}

{cowBalance && (
{hasCowBalance && (
<Card>
<BalanceDisplay titleSize={26}>
<img src={CowImage} alt="Cow Balance" height="80" width="80" />
Expand Down
1 change: 1 addition & 0 deletions src/custom/pages/Profile/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export const BannerCard = styled(BannerExplainer)`
padding: 0 100px 0 24px;
flex: 1;
overflow: hidden;
height: auto;

${({ theme }) => theme.mediaWidth.upToSmall`
text-align: center;
Expand Down
4 changes: 3 additions & 1 deletion src/custom/state/claim/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ import useIsMounted from 'hooks/useIsMounted'
import { ChainId } from '@uniswap/sdk'
import { ClaimInfo } from 'state/claim/reducer'

const CLAIMS_REPO_BRANCH = 'gip-13'
// TODO: Change back this to commented line before it goes to production
// const CLAIMS_REPO_BRANCH = 'gip-13'
nenadV91 marked this conversation as resolved.
Show resolved Hide resolved
const CLAIMS_REPO_BRANCH = '2022-02-15_Rinkeby-full'
export const CLAIMS_REPO = `https://github.com/gnosis/cow-merkle-drop/${CLAIMS_REPO_BRANCH}/`

// Base amount = 1 VCOW
Expand Down