-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Profile: Add COW to Metamask: Waterfall PR[3] #378
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,20 +45,21 @@ 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, useSwapVCowCallback, useSetSwapVCowStatus, useSwapVCowStatus } from 'state/cowToken/hooks' | ||
import { COW_CONTRACT_ADDRESS, AMOUNT_PRECISION } from 'constants/index' | ||
import { V_COW_CONTRACT_ADDRESS, COW_CONTRACT_ADDRESS, AMOUNT_PRECISION } from 'constants/index' | ||
import { COW } from 'constants/tokens' | ||
import { useErrorModal } from 'hooks/useErrorMessageAndModal' | ||
import { OperationType } from 'components/TransactionConfirmationModal' | ||
import useTransactionConfirmationModal from 'hooks/useTransactionConfirmationModal' | ||
import { SwapVCowStatus } from 'state/cowToken/actions' | ||
import MetamaskIcon from 'assets/images/metamask.png' | ||
import {} from 'constants/index' | ||
import AddToMetamask from 'components/AddToMetamask' | ||
import { Link } from 'react-router-dom' | ||
import CopyHelper from 'components/Copy' | ||
|
||
const COW_DECIMALS = COW[ChainId.MAINNET].decimals | ||
|
||
export default function Profile() { | ||
const referralLink = useReferralLink() | ||
const { account, chainId } = useActiveWeb3React() | ||
const { account, chainId = ChainId.MAINNET, library } = useActiveWeb3React() | ||
const { profileData, isLoading, error } = useFetchProfile() | ||
const lastUpdated = useTimeAgo(profileData?.lastUpdated) | ||
const isTradesTooltipVisible = account && chainId == 1 && !!profileData?.totalTrades | ||
|
@@ -161,6 +162,8 @@ export default function Profile() { | |
</> | ||
) | ||
|
||
const currencyCOW = COW[chainId] | ||
|
||
return ( | ||
<Container> | ||
<TransactionConfirmationModal /> | ||
|
@@ -204,6 +207,15 @@ export default function Profile() { | |
)} | ||
</ButtonPrimary> | ||
</ConvertWrapper> | ||
|
||
<CardActions> | ||
<ExtLink href={getBlockExplorerUrl(chainId, V_COW_CONTRACT_ADDRESS[chainId], 'address')}> | ||
Contract ↗ | ||
</ExtLink> | ||
<CopyHelper toCopy={V_COW_CONTRACT_ADDRESS[chainId]}> | ||
<div title="Click to copy token contract address">Copy contract</div> | ||
</CopyHelper> | ||
</CardActions> | ||
</Card> | ||
)} | ||
|
||
|
@@ -216,13 +228,22 @@ export default function Profile() { | |
</span> | ||
</BalanceDisplay> | ||
<CardActions> | ||
<ExtLink href={getBlockExplorerUrl(chainId || 1, COW_CONTRACT_ADDRESS[chainId || 1], 'address')}> | ||
{chainId === ChainId.XDAI ? 'Blockscout' : 'Etherscan'} ↗ | ||
<ExtLink | ||
title="View contract" | ||
href={getBlockExplorerUrl(chainId, COW_CONTRACT_ADDRESS[chainId], 'address')} | ||
> | ||
Contract ↗ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More than contract, could be View Token and send you to Etherscan Token page? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that might be a better destination. Agree |
||
</ExtLink> | ||
<ExtLink href={'#'}> | ||
<img src={MetamaskIcon} alt="MetaMask" width="15" height="14" /> Add to MetaMask | ||
</ExtLink> | ||
<ExtLink href={'#'}>Buy COW ↗</ExtLink> | ||
|
||
{library?.provider?.isMetaMask && <AddToMetamask shortLabel currency={currencyCOW} />} | ||
|
||
{!library?.provider?.isMetaMask && ( | ||
<CopyHelper toCopy={COW_CONTRACT_ADDRESS[chainId]}> | ||
<div title="Click to copy token contract address">Copy contract</div> | ||
</CopyHelper> | ||
)} | ||
|
||
<Link to={`/swap?outputCurrency=${COW_CONTRACT_ADDRESS[chainId]}`}>Buy COW</Link> | ||
</CardActions> | ||
</Card> | ||
|
||
|
@@ -266,7 +287,7 @@ export default function Profile() { | |
)} | ||
</Txt> | ||
{hasOrders && ( | ||
<ExtLink href={getExplorerAddressLink(chainId || 1, account)}> | ||
<ExtLink href={getExplorerAddressLink(chainId, account)}> | ||
<Txt secondary>View all orders ↗</Txt> | ||
</ExtLink> | ||
)} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we prefer to copy the contract address over sending the user to Etherscan?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case it was not added as a preference per se: You've got both options there (View Contract and Copy Contract).
Rather it was a ported action from the COW balance card, where if you are not connected with MetaMask we show you 'Copy Contract' instead of 'Add Token' as a fall back.
Discussed with @elena-zh that it might not make sense to have 'Add Token' (to MetaMask) for vCOW (given it's non transferable anyway..) but might be OK to have the 'Copy contract' action.
Let me know your thoughts.