Skip to content

Commit e138a3e

Browse files
committed
fix: 🐛 Fixed "Invalid walletClient configuration" error
1 parent 9e7c235 commit e138a3e

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/shared/contracts.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,13 @@ export class ProtocolContracts<
108108
txSubject?: string,
109109
): Promise<TransactionReceipt> {
110110
try {
111-
if (!this.walletClient) {
112-
throw new Error(`Invalid walletClient configuration`);
111+
if (!walletClient && !this.walletClient) {
112+
throw new Error('Invalid walletClient configuration');
113113
}
114114

115-
const [account] = await this.walletClient.getAddresses();
115+
walletClient = walletClient ?? this.walletClient;
116+
117+
const [account] = await walletClient.getAddresses();
116118
const requestOptions = {
117119
address,
118120
abi,
@@ -125,11 +127,7 @@ export class ProtocolContracts<
125127

126128
const { request } = await this.publicClient.simulateContract(requestOptions);
127129

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);
133131

134132
if (txCallback) {
135133
txCallback(hash, txSubject);
@@ -187,21 +185,21 @@ export class ProtocolContracts<
187185
): Promise<TransactionReceipt> {
188186
const [, , , buyer] = await this.getDeal(offer);
189187

190-
if (buyer === zeroAddress) {
188+
if (buyer !== zeroAddress) {
191189
throw new Error(`Deal ${offer.payload.id} already created!`);
192190
}
193191

194192
// Extracting the proper payment method by Id
195193
// Will throw a error if invalid payment Id provided
196194
const paymentOption = getPaymentOption(offer.payment, paymentId);
197195

198-
if (!this.walletClient) {
196+
if (!walletClient && !this.walletClient) {
199197
throw new Error(`Invalid walletClient configuration`);
200198
}
201199

202200
// Asset must be allowed to Market in the proper amount
203201
// 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();
205203

206204
const allowance = await this.publicClient.readContract({
207205
address: paymentOption.asset,

0 commit comments

Comments
 (0)