Skip to content

Commit a214a33

Browse files
committed
ADDS getOrderHash fn for v4
1 parent 6d8c02f commit a214a33

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

src/sdk/v4/NftSwapV4.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ import {
3434
import type {
3535
AddressesForChainV4,
3636
ApprovalOverrides,
37+
ERC1155OrderStruct,
38+
ERC1155OrderStructSerialized,
39+
ERC721OrderStruct,
40+
ERC721OrderStructSerialized,
3741
FillOrderOverrides,
3842
NftOrderV4,
3943
NftOrderV4Serialized,
@@ -265,16 +269,31 @@ class NftSwapV4 implements INftSwapV4 {
265269
nonce: BigNumberish,
266270
orderType: 'ERC721' | 'ERC1155'
267271
): Promise<ContractTransaction> => {
268-
if (orderType === 'ERC1155') {
269-
return this.exchangeProxy.cancelERC1155Order(nonce);
270-
}
271272
if (orderType === 'ERC721') {
272273
return this.exchangeProxy.cancelERC721Order(nonce);
273274
}
275+
if (orderType === 'ERC1155') {
276+
return this.exchangeProxy.cancelERC1155Order(nonce);
277+
}
274278
console.log('unsupported order', orderType);
275279
throw new Error('unsupport order');
276280
};
277281

282+
/**
283+
* Derives order hash from order (currently requires a provider to derive)
284+
* @param order A 0x v4 order (signed or unsigned)
285+
* @returns Order hash
286+
*/
287+
getOrderHash = (order: NftOrderV4Serialized): Promise<string> => {
288+
if ('erc721Token' in order) {
289+
return this.exchangeProxy.getERC721OrderHash(order);
290+
}
291+
if ('erc1155Token' in order) {
292+
return this.exchangeProxy.getERC1155OrderHash(order);
293+
}
294+
throw new Error('unsupport order');
295+
};
296+
278297
/**
279298
* Looks up the order status for a given 0x v4 order.
280299
* (Available states for an order are 'filled', 'expired', )
@@ -287,6 +306,12 @@ class NftSwapV4 implements INftSwapV4 {
287306
* Expired = 3,
288307
*/
289308
getOrderStatus = async (order: NftOrderV4): Promise<number> => {
309+
if ('erc721Token' in order) {
310+
const erc721OrderStatus = await this.exchangeProxy.getERC721OrderStatus(
311+
order
312+
);
313+
return erc721OrderStatus;
314+
}
290315
if ('erc1155Token' in order) {
291316
const [
292317
_erc1155OrderHash,
@@ -296,12 +321,6 @@ class NftSwapV4 implements INftSwapV4 {
296321
] = await this.exchangeProxy.getERC1155OrderInfo(order);
297322
return erc1155OrderStatus;
298323
}
299-
if ('erc721Token' in order) {
300-
const erc721OrderStatus = await this.exchangeProxy.getERC721OrderStatus(
301-
order
302-
);
303-
return erc721OrderStatus;
304-
}
305324
console.log('unsupported order', order);
306325
throw new Error('unsupport order');
307326
};

0 commit comments

Comments
 (0)