Skip to content

Commit

Permalink
fix: add missing fingerprint in estate orders (#2340)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo authored Dec 17, 2024
1 parent 94391bf commit 50b0157
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const mapState = (state: RootState): MapStateProps => {
}

const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => ({
onCreateOrder: (nft, price, expiresAt) => dispatch(createOrderRequest(nft, price, expiresAt)),
onCreateOrder: (nft, price, expiresAt, fingerprint) => dispatch(createOrderRequest(nft, price, expiresAt, fingerprint)),
onFetchAuthorizations: (authorizations: Authorization[]) => dispatch(fetchAuthorizationsRequest(authorizations)),
onUpsertContracts: (contracts: Contract[]) => dispatch(upsertContracts(contracts)),
onCancelOrder: (order, nft, skipRedirection = false) => dispatch(cancelOrderRequest(order, nft, skipRedirection))
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/components/Modals/SellModal/SellModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Button, Field, Loader, Mana, Message, ModalNavigation } from 'decentral
import { useAuthorization } from '../../../lib/authorization'
import { formatWeiMANA, parseMANANumber } from '../../../lib/mana'
import { getAssetName, isOwnedBy } from '../../../modules/asset/utils'
import { useFingerprint } from '../../../modules/nft/hooks'
import { getDefaultExpirationDate, INPUT_FORMAT } from '../../../modules/order/utils'
import { locations } from '../../../modules/routing/locations'
import { getContractNames, VendorFactory } from '../../../modules/vendor'
Expand Down Expand Up @@ -104,6 +105,7 @@ const SellModal = ({
}

const [isLoadingAuthorizations, isAuthorized] = useAuthorization(authorization, onFetchAuthorizations)
const [fingerprint] = useFingerprint(nft)

if (!wallet) {
return null
Expand All @@ -125,7 +127,7 @@ const SellModal = ({
}
}

const handleCreateOrder = () => onCreateOrder(nft, parseMANANumber(price), new Date(`${expiresAt} 00:00:00`).getTime())
const handleCreateOrder = () => onCreateOrder(nft, parseMANANumber(price), new Date(`${expiresAt} 00:00:00`).getTime(), fingerprint)

const isInvalidDate = new Date(`${expiresAt} 00:00:00`).getTime() < Date.now()
const isInvalidPrice = parseMANANumber(price) <= 0 || parseFloat(price) !== parseMANANumber(price)
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/components/SellPage/SellModal/SellModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ERC721ABI from '../../../contracts/ERC721.json'
import { parseMANANumber } from '../../../lib/mana'
import { getAssetName, isOwnedBy } from '../../../modules/asset/utils'
import { isStubMaticCollectionContract } from '../../../modules/contract/utils'
import { useFingerprint } from '../../../modules/nft/hooks'
import { getSellItemStatus, getError } from '../../../modules/order/selectors'
import { INPUT_FORMAT, getDefaultExpirationDate } from '../../../modules/order/utils'
import { getContractNames } from '../../../modules/vendor'
Expand Down Expand Up @@ -49,6 +50,7 @@ const SellModal = (props: Props) => {
const isUpdate = order !== null
const shouldRemoveListing = order?.tradeId
const [price, setPrice] = useState<string>(isUpdate ? ethers.utils.formatEther(order.price) : '')
const [fingerprint] = useFingerprint(nft)

const [expiresAt, setExpiresAt] = useState(() => {
let exp = order?.expiresAt
Expand Down Expand Up @@ -113,7 +115,7 @@ const SellModal = (props: Props) => {
? getDecentralandContract(ContractName.OffChainMarketplace, nft.chainId)
: null

const handleCreateOrder = () => onCreateOrder(nft, parseMANANumber(price), new Date(`${expiresAt} 00:00:00`).getTime())
const handleCreateOrder = () => onCreateOrder(nft, parseMANANumber(price), new Date(`${expiresAt} 00:00:00`).getTime(), fingerprint)

const handleCancelTrade = () => order && onCancelOrder(order, nft)

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/SellPage/SellPage.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const mapState = (state: RootState): MapStateProps => ({
})

const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => ({
onCreateOrder: (nft, price, expiresAt) => dispatch(createOrderRequest(nft, price, expiresAt)),
onCreateOrder: (nft, price, expiresAt, fingerprint) => dispatch(createOrderRequest(nft, price, expiresAt, fingerprint)),
onClearOrderErrors: () => dispatch(clearOrderErrors()),
onCancelOrder: (order: Order, nft: NFT) => dispatch(cancelOrderRequest(order, nft, true))
})
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export const CREATE_ORDER_REQUEST = '[Request] Create Order'
export const CREATE_ORDER_SUCCESS = '[Success] Create Order'
export const CREATE_ORDER_FAILURE = '[Failure] Create Order'

export const createOrderRequest = (nft: NFT, price: number, expiresAt: number) => action(CREATE_ORDER_REQUEST, { nft, price, expiresAt })
export const createOrderRequest = (nft: NFT, price: number, expiresAt: number, fingerprint?: string) =>
action(CREATE_ORDER_REQUEST, { nft, price, expiresAt, fingerprint })
export const createOrderSuccess = (nft: NFT, price: number, expiresAt: number, txHash?: string) =>
action(CREATE_ORDER_SUCCESS, {
nft,
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/modules/order/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ export function* orderSaga(tradeService: TradeService) {
}

function* handleCreateOrderRequest(action: CreateOrderRequestAction) {
const { nft, price, expiresAt } = action.payload
const { nft, price, expiresAt, fingerprint } = action.payload
try {
const isOffchainPublicNFTOrdersEnabled: boolean = yield select(getIsOffchainPublicNFTOrdersEnabled)
if (isOffchainPublicNFTOrdersEnabled) {
const history: History = yield getContext('history')
const trade: TradeCreation = yield call([orderUtils, 'createPublicNFTOrderTrade'], nft, price, expiresAt)
const trade: TradeCreation = yield call([orderUtils, 'createPublicNFTOrderTrade'], nft, price, expiresAt, fingerprint)
yield call([tradeService, 'addTrade'], trade)
yield put(createOrderSuccess(nft, price, expiresAt))
yield put(fetchNFTRequest(nft.contractAddress, nft.tokenId)) // fetch the NFT again to get the new order with the tradeId
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/modules/order/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function getSubgraphOrdersQuery(filters: OrderFilters) {
}`
}

export async function createPublicNFTOrderTrade(nft: NFT, price: number, expiresAt: number) {
export async function createPublicNFTOrderTrade(nft: NFT, price: number, expiresAt: number, fingerprint?: string) {
const signer = await getSigner()
const address = await signer.getAddress()
const marketplaceContract = await getOffChainMarketplaceContract(nft.chainId)
Expand Down Expand Up @@ -106,7 +106,7 @@ export async function createPublicNFTOrderTrade(nft: NFT, price: number, expires
assetType: TradeAssetType.ERC721,
contractAddress: nft.contractAddress,
tokenId: nft.tokenId,
extra: ''
extra: fingerprint || ''
}
],
received: [
Expand Down

0 comments on commit 50b0157

Please sign in to comment.