@@ -91,19 +91,32 @@ class AcpJob {
9191 return this . acpContractClient . config . baseFare ;
9292 }
9393
94- public get rejectionReason ( ) {
95- const requestMemo = this . memos . find (
94+ public get rejectionReason ( ) : {
95+ rejectedBy : Address ,
96+ reason : string | undefined
97+ } | undefined {
98+ const rejectedMemo : AcpMemo | undefined = this . memos . find (
9699 ( m ) =>
97- m . nextPhase === AcpJobPhases . NEGOTIATION &&
98100 m . status === AcpMemoStatus . REJECTED
99101 ) ;
100102
101- if ( requestMemo ) {
102- return requestMemo . signedReason ;
103+ if ( rejectedMemo ) {
104+ const rejectedBy : Address = rejectedMemo . senderAddress === this . clientAddress ? this . providerAddress : this . clientAddress ;
105+ return {
106+ rejectedBy : rejectedBy ,
107+ reason : rejectedMemo . signedReason
108+ } ;
103109 }
104110
105- return this . memos . find ( ( m ) => m . nextPhase === AcpJobPhases . REJECTED )
106- ?. content ;
111+ const rejectJobMemo : AcpMemo | undefined = this . memos . find ( ( m ) => m . nextPhase === AcpJobPhases . REJECTED ) ;
112+ if ( rejectJobMemo ) {
113+ return {
114+ rejectedBy : rejectJobMemo . senderAddress ,
115+ reason : rejectJobMemo . content ,
116+ } ;
117+ }
118+
119+ return undefined ;
107120 }
108121
109122 public get providerAgent ( ) {
@@ -396,14 +409,31 @@ class AcpJob {
396409 async reject ( reason ?: string ) {
397410 const memoContent = `Job ${ this . id } rejected. ${ reason || "" } ` ;
398411
399- if ( this . phase === AcpJobPhases . REQUEST ) {
412+ const isProviderRequestPhase : boolean = (
413+ this . providerAddress === this . acpClient . walletAddress &&
414+ this . phase === AcpJobPhases . REQUEST
415+ ) ;
416+ const isClientPaymentPhase : boolean = (
417+ this . clientAddress === this . acpClient . walletAddress &&
418+ this . phase === AcpJobPhases . NEGOTIATION
419+ ) ;
420+
421+ if ( isProviderRequestPhase ) {
400422 const latestMemo = this . latestMemo ;
401423 if ( latestMemo ?. nextPhase !== AcpJobPhases . NEGOTIATION ) {
402424 throw new AcpError ( "No request memo found" ) ;
403425 }
404426 return await latestMemo . sign ( false , memoContent ) ;
405427 }
406428
429+ if ( isClientPaymentPhase ) {
430+ const latestMemo = this . latestMemo ;
431+ if ( latestMemo ?. nextPhase !== AcpJobPhases . TRANSACTION ) {
432+ throw new AcpError ( "No payment memo found" ) ;
433+ }
434+ return await latestMemo . sign ( false , memoContent ) ;
435+ }
436+
407437 const operations : OperationPayload [ ] = [ ] ;
408438 operations . push (
409439 this . acpContractClient . createMemo (
0 commit comments