-
Notifications
You must be signed in to change notification settings - Fork 652
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
fix: Estate fingerprint calculation #2047
Changes from 2 commits
a9647db
045299b
b35436c
7ee4117
e608708
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React, { useState, useCallback } from 'react' | ||
import { ethers } from 'ethers' | ||
import { Contract } from '@dcl/schemas' | ||
import { Contract, NFTCategory } from '@dcl/schemas' | ||
import { Header, Form, Field, Button } from 'decentraland-ui' | ||
import { t, T } from 'decentraland-dapps/dist/modules/translation/utils' | ||
import { withAuthorizedAction } from 'decentraland-dapps/dist/containers' | ||
|
@@ -28,6 +28,7 @@ import { ConfirmInputValueModal } from '../../ConfirmInputValueModal' | |
import { Mana } from '../../Mana' | ||
import { Props } from './BidModal.types' | ||
import './BidModal.css' | ||
import ErrorBanner from '../../ErrorBanner' | ||
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. Move up |
||
|
||
const BidModal = (props: Props) => { | ||
const { | ||
|
@@ -44,7 +45,7 @@ const BidModal = (props: Props) => { | |
const [price, setPrice] = useState('') | ||
const [expiresAt, setExpiresAt] = useState(getDefaultExpirationDate()) | ||
|
||
const [fingerprint, isLoading] = useFingerprint(nft) | ||
const [fingerprint, isLoading, contractFingerprint] = useFingerprint(nft) | ||
|
||
const [showConfirmationModal, setShowConfirmationModal] = useState(false) | ||
|
||
|
@@ -106,7 +107,9 @@ const BidModal = (props: Props) => { | |
isInvalidDate || | ||
hasInsufficientMANA || | ||
isLoading || | ||
isPlacingBid | ||
isPlacingBid || | ||
(!fingerprint && nft.category === NFTCategory.ESTATE) || | ||
contractFingerprint !== fingerprint | ||
|
||
return ( | ||
<AssetAction asset={nft}> | ||
|
@@ -161,6 +164,9 @@ const BidModal = (props: Props) => { | |
error={isInvalidDate} | ||
message={isInvalidDate ? t('bid_page.invalid_date') : undefined} | ||
/> | ||
{contractFingerprint !== fingerprint ? ( | ||
<ErrorBanner info={t('atlas_updated_warning.fingerprint_missmatch')} /> | ||
) : null} | ||
</div> | ||
<div className="buttons"> | ||
<Button | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ import { PartiallySupportedNetworkCard } from '../PartiallySupportedNetworkCard' | |
import { NotEnoughMana } from '../NotEnoughMana' | ||
import { PriceHasChanged } from '../PriceHasChanged' | ||
import { Props } from './BuyNFTModal.types' | ||
import ErrorBanner from '../../ErrorBanner' | ||
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. Move up |
||
|
||
const BuyNFTModal = (props: Props) => { | ||
const { | ||
|
@@ -51,7 +52,11 @@ const BuyNFTModal = (props: Props) => { | |
onClearOrderErrors | ||
} = props | ||
|
||
const [fingerprint, isFingerprintLoading] = useFingerprint(nft) | ||
const [ | ||
fingerprint, | ||
isFingerprintLoading, | ||
contractFingerprint | ||
] = useFingerprint(nft) | ||
const analytics = getAnalytics() | ||
|
||
const handleExecuteOrder = useCallback( | ||
|
@@ -121,7 +126,9 @@ const BuyNFTModal = (props: Props) => { | |
!order || | ||
isOwner || | ||
(hasInsufficientMANA && !isBuyWithCardPage) || | ||
(!fingerprint && nft.category === NFTCategory.ESTATE) | ||
(!fingerprint && nft.category === NFTCategory.ESTATE) || | ||
isFingerprintLoading || | ||
contractFingerprint !== fingerprint | ||
|
||
const name = <Name asset={nft} /> | ||
|
||
|
@@ -140,12 +147,6 @@ const BuyNFTModal = (props: Props) => { | |
subtitle = ( | ||
<T id={`${translationPageDescriptorId}.not_for_sale`} values={{ name }} /> | ||
) | ||
} else if ( | ||
!fingerprint && | ||
nft.category === NFTCategory.ESTATE && | ||
!isFingerprintLoading | ||
) { | ||
subtitle = <T id={`${translationPageDescriptorId}.no_fingerprint`} /> | ||
} else if (isOwner) { | ||
subtitle = ( | ||
<T id={`${translationPageDescriptorId}.is_owner`} values={{ name }} /> | ||
|
@@ -202,6 +203,9 @@ const BuyNFTModal = (props: Props) => { | |
<PriceTooLow chainId={nft.chainId} network={nft.network} /> | ||
) : null} | ||
<PartiallySupportedNetworkCard asset={nft} /> | ||
{contractFingerprint !== fingerprint ? ( | ||
<ErrorBanner info={t('atlas_updated_warning.fingerprint_missmatch')} /> | ||
) : null} | ||
<div | ||
className={classNames('buttons', isWearableOrEmote(nft) && 'with-mana')} | ||
> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.container { | ||
background: var(--dropdown); | ||
display: flex; | ||
padding: 20px; | ||
gap: 10px; | ||
} | ||
|
||
.icon { | ||
background: var(--oj-not-simpson); | ||
border-radius: 50%; | ||
min-width: 25px; | ||
height: 25px; | ||
text-align: center; | ||
margin: 0; | ||
} | ||
|
||
.icon :global(.icon) { | ||
position: relative; | ||
top: 2px; | ||
margin: 0; | ||
} | ||
|
||
.info { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 5px; | ||
text-align: left; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import classNames from 'classnames' | ||
import { Icon } from 'decentraland-ui' | ||
import { Props } from './ErrorBanner.types' | ||
import styles from './ErrorBanner.module.css' | ||
|
||
export default function ErrorBanner({ info, className }: Props) { | ||
return ( | ||
<div className={classNames(styles.container, className)}> | ||
<div className={styles.icon}> | ||
<Icon name="exclamation triangle" /> | ||
</div> | ||
<span className={styles.info}> | ||
{info} | ||
</span> | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type Props = { | ||
info: string; | ||
className?: string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import ErrorBanner from "./ErrorBanner"; | ||
export default ErrorBanner |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { | ||
getSigner, | ||
getConnectedProvider | ||
getConnectedProvider, | ||
getNetworkProvider | ||
} from 'decentraland-dapps/dist/lib/eth' | ||
import { EstateRegistry__factory } from '../../../contracts' | ||
import { Contract } from '../../vendor/services' | ||
import { NFT } from '../types' | ||
import { ethers } from 'ethers' | ||
|
||
export const getSelection = (estate: NFT['data']['estate']) => { | ||
return estate!.parcels.map(pair => ({ | ||
|
@@ -21,6 +23,55 @@ export const getCenter = (selection: { x: number; y: number }[]) => { | |
return [x, y] | ||
} | ||
|
||
export async function generateFingerprint( | ||
estateId: string, | ||
parcels: { x: number; y: number }[], | ||
landContract: Contract | ||
) { | ||
const provider = await getNetworkProvider(landContract.chainId) | ||
const contract = new ethers.Contract( | ||
landContract.address, | ||
[ | ||
{ | ||
constant: true, | ||
inputs: [ | ||
{ name: 'x', type: 'int256' }, | ||
{ name: 'y', type: 'int256' } | ||
], | ||
name: 'encodeTokenId', | ||
outputs: [{ name: '', type: 'uint256' }], | ||
payable: false, | ||
stateMutability: 'pure', | ||
type: 'function' | ||
} | ||
], | ||
new ethers.providers.Web3Provider(provider) | ||
) | ||
|
||
const estateTokenIds = [] | ||
|
||
for (const parcel of parcels) { | ||
estateTokenIds.push( | ||
(await contract.encodeTokenId(parcel.x, parcel.y)).toString() | ||
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. Is this toString necessary? |
||
) | ||
} | ||
|
||
let fingerprint = BigInt( | ||
ethers.utils.solidityKeccak256( | ||
['string', 'uint256'], | ||
['estateId', estateId] | ||
) | ||
) | ||
|
||
for (const tokenId of estateTokenIds) { | ||
fingerprint ^= BigInt( | ||
ethers.utils.solidityKeccak256(['uint256'], [tokenId]) | ||
) | ||
} | ||
|
||
return fingerprint.toString(16) | ||
} | ||
|
||
export async function getFingerprint( | ||
estateId: string, | ||
estateContract: Contract | ||
|
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.
Move up