11import { OrderComponents } from "@opensea/seaport-js/lib/types" ;
22import { Overrides , Signer } from "ethers" ;
3- import { GetOrderByHashResponse } from "../api/types" ;
3+ import { Offer , Listing } from "../api/types" ;
44import { OrderV2 } from "../orders/types" ;
55import { DEFAULT_SEAPORT_CONTRACT_ADDRESS } from "../orders/utils" ;
66import { Chain , EventType } from "../types" ;
@@ -64,7 +64,6 @@ export class CancellationManager {
6464 requireValidProtocol ( order . protocolAddress ) ;
6565 effectiveProtocolAddress = order . protocolAddress ;
6666 orderComponents = order . protocolData . parameters ;
67-
6867 this . context . dispatch ( EventType . CancelOrder , {
6968 orderV2 : order ,
7069 accountAddress,
@@ -80,6 +79,10 @@ export class CancellationManager {
8079 requireValidProtocol ( fetchedOrder . protocol_address ) ;
8180 effectiveProtocolAddress = fetchedOrder . protocol_address ;
8281 orderComponents = fetchedOrder . protocol_data . parameters ;
82+ this . context . dispatch ( EventType . CancelOrder , {
83+ order : fetchedOrder ,
84+ accountAddress,
85+ } ) ;
8386 } else {
8487 // Should never reach here due to earlier validation
8588 throw new Error ( "Invalid input" ) ;
@@ -161,17 +164,16 @@ export class CancellationManager {
161164
162165 let orderComponents : OrderComponents [ ] ;
163166 let effectiveProtocolAddress = protocolAddress ;
164- let firstOrderV2 : OrderV2 | undefined ;
165167
166168 if ( orders ) {
167169 // Extract OrderComponents from either OrderV2 objects or use OrderComponents directly
170+ let firstOrderV2 : OrderV2 | undefined ;
168171 orderComponents = orders . map ( ( order ) => {
169172 if ( "protocolData" in order ) {
170173 // It's an OrderV2 object
171174 const orderV2 = order as OrderV2 ;
172175 requireValidProtocol ( orderV2 . protocolAddress ) ;
173176 effectiveProtocolAddress = orderV2 . protocolAddress ;
174- // Save the first OrderV2 for event dispatching
175177 if ( ! firstOrderV2 ) {
176178 firstOrderV2 = orderV2 ;
177179 }
@@ -181,8 +183,7 @@ export class CancellationManager {
181183 return order as OrderComponents ;
182184 }
183185 } ) ;
184-
185- // Dispatch event for the first order if available (for backwards compatibility with cancelOrder)
186+ // Dispatch event for the first OrderV2 if available
186187 if ( firstOrderV2 ) {
187188 this . context . dispatch ( EventType . CancelOrder , {
188189 orderV2 : firstOrderV2 ,
@@ -191,22 +192,30 @@ export class CancellationManager {
191192 }
192193 } else if ( orderHashes ) {
193194 // Fetch orders from the API using order hashes
194- const fetchedOrders : GetOrderByHashResponse [ ] = [ ] ;
195- for ( const orderHash of orderHashes ) {
196- const order = await this . context . api . getOrderByHash (
197- orderHash ,
195+ const fetchedOrders : ( Offer | Listing ) [ ] = [ ] ;
196+ for ( const hash of orderHashes ) {
197+ const fetched = await this . context . api . getOrderByHash (
198+ hash ,
198199 protocolAddress ,
199200 this . context . chain ,
200201 ) ;
201- fetchedOrders . push ( order ) ;
202+ fetchedOrders . push ( fetched ) ;
202203 }
203204
204205 // Extract OrderComponents from the fetched orders
205- orderComponents = fetchedOrders . map ( ( order ) => {
206- requireValidProtocol ( order . protocol_address ) ;
207- effectiveProtocolAddress = order . protocol_address ;
208- return order . protocol_data . parameters ;
206+ orderComponents = fetchedOrders . map ( ( fetched ) => {
207+ requireValidProtocol ( fetched . protocol_address ) ;
208+ effectiveProtocolAddress = fetched . protocol_address ;
209+ return fetched . protocol_data . parameters ;
209210 } ) ;
211+
212+ // Dispatch event for the first fetched order
213+ if ( fetchedOrders . length > 0 ) {
214+ this . context . dispatch ( EventType . CancelOrder , {
215+ order : fetchedOrders [ 0 ] ,
216+ accountAddress,
217+ } ) ;
218+ }
210219 } else {
211220 // Should never reach here due to earlier validation
212221 throw new Error ( "Invalid input" ) ;
0 commit comments