Skip to content

Commit e53c523

Browse files
committed
fix: 🐛 Fixed _sendHelper's local account error
1 parent 152df72 commit e53c523

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/shared/contracts.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
Address,
33
Hash,
44
Abi,
5+
Account,
56
InferFunctionName,
67
GetFunctionArgs,
78
SimulateContractParameters,
@@ -108,13 +109,19 @@ export class ProtocolContracts<
108109
txSubject?: string,
109110
): Promise<TransactionReceipt> {
110111
try {
111-
if (!walletClient && !this.walletClient) {
112+
walletClient = walletClient ?? this.walletClient;
113+
114+
if (!walletClient) {
112115
throw new Error('Invalid walletClient configuration');
113116
}
114117

115-
walletClient = walletClient ?? this.walletClient;
118+
let account = walletClient.account;
119+
120+
if (!account || account?.type !== 'local') {
121+
const [accountAddress] = await walletClient.getAddresses();
122+
account = accountAddress as unknown as Account;
123+
}
116124

117-
const [account] = await walletClient.getAddresses();
118125
const requestOptions = {
119126
address,
120127
abi,
@@ -129,12 +136,17 @@ export class ProtocolContracts<
129136

130137
const hash = await walletClient.writeContract(request);
131138

139+
logger.trace(`Tx: ${hash}, subject: "${txSubject ?? ''}"`);
140+
132141
if (txCallback) {
133142
txCallback(hash, txSubject);
134-
logger.trace(`Tx: ${hash}, subject: "${txSubject ?? ''}"`);
135143
}
136144

137-
return await this.publicClient.waitForTransactionReceipt({ hash });
145+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
146+
147+
logger.trace('Tx receipt:', receipt);
148+
149+
return receipt;
138150
} catch (error) {
139151
logger.error(error);
140152

@@ -193,13 +205,15 @@ export class ProtocolContracts<
193205
// Will throw a error if invalid payment Id provided
194206
const paymentOption = getPaymentOption(offer.payment, paymentId);
195207

196-
if (!walletClient && !this.walletClient) {
197-
throw new Error(`Invalid walletClient configuration`);
208+
walletClient = walletClient ?? this.walletClient;
209+
210+
if (!walletClient) {
211+
throw new Error('Invalid walletClient configuration');
198212
}
199213

200214
// Asset must be allowed to Market in the proper amount
201215
// This function will check allowance and send `approve` transaction if required
202-
const [owner] = await (walletClient ?? this.walletClient).getAddresses();
216+
const [owner] = await walletClient.getAddresses();
203217

204218
const allowance = await this.publicClient.readContract({
205219
address: paymentOption.asset,

0 commit comments

Comments
 (0)