@@ -108,11 +108,13 @@ export class ProtocolContracts<
108
108
txSubject ?: string ,
109
109
) : Promise < TransactionReceipt > {
110
110
try {
111
- if ( ! this . walletClient ) {
112
- throw new Error ( ` Invalid walletClient configuration` ) ;
111
+ if ( ! walletClient && ! this . walletClient ) {
112
+ throw new Error ( ' Invalid walletClient configuration' ) ;
113
113
}
114
114
115
- const [ account ] = await this . walletClient . getAddresses ( ) ;
115
+ walletClient = walletClient ?? this . walletClient ;
116
+
117
+ const [ account ] = await walletClient . getAddresses ( ) ;
116
118
const requestOptions = {
117
119
address,
118
120
abi,
@@ -125,11 +127,7 @@ export class ProtocolContracts<
125
127
126
128
const { request } = await this . publicClient . simulateContract ( requestOptions ) ;
127
129
128
- if ( ! walletClient && ! this . walletClient ) {
129
- throw new Error ( 'Invalid walletClient configuration' ) ;
130
- }
131
-
132
- const hash = await ( walletClient ?? this . walletClient ) . writeContract ( request ) ;
130
+ const hash = await walletClient . writeContract ( request ) ;
133
131
134
132
if ( txCallback ) {
135
133
txCallback ( hash , txSubject ) ;
@@ -187,21 +185,21 @@ export class ProtocolContracts<
187
185
) : Promise < TransactionReceipt > {
188
186
const [ , , , buyer ] = await this . getDeal ( offer ) ;
189
187
190
- if ( buyer = == zeroAddress ) {
188
+ if ( buyer ! == zeroAddress ) {
191
189
throw new Error ( `Deal ${ offer . payload . id } already created!` ) ;
192
190
}
193
191
194
192
// Extracting the proper payment method by Id
195
193
// Will throw a error if invalid payment Id provided
196
194
const paymentOption = getPaymentOption ( offer . payment , paymentId ) ;
197
195
198
- if ( ! this . walletClient ) {
196
+ if ( ! walletClient && ! this . walletClient ) {
199
197
throw new Error ( `Invalid walletClient configuration` ) ;
200
198
}
201
199
202
200
// Asset must be allowed to Market in the proper amount
203
201
// This function will check allowance and send `approve` transaction if required
204
- const [ owner ] = await this . walletClient . getAddresses ( ) ;
202
+ const [ owner ] = await ( walletClient ?? this . walletClient ) . getAddresses ( ) ;
205
203
206
204
const allowance = await this . publicClient . readContract ( {
207
205
address : paymentOption . asset ,
0 commit comments