Skip to content

Commit

Permalink
Fix viem adapter to call onMined callback.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangoree committed Nov 4, 2024
1 parent e3b44c5 commit 25a1e75
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/drift-viem/src/ViemReadWriteAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import type {
FunctionReturn,
ReadWriteAdapter,
} from "@delvtech/drift";
import { ViemReadAdapter, type ViemReadAdapterParams } from "src/ViemReadAdapter";
import {
ViemReadAdapter,
type ViemReadAdapterParams,
} from "src/ViemReadAdapter";
import { createSimulateContractParameters } from "src/utils/createSimulateContractParameters";
import { outputToFriendly } from "src/utils/outputToFriendly";
import type { Abi, WalletClient, WriteContractParameters } from "viem";
Expand Down Expand Up @@ -57,7 +60,7 @@ export class ViemReadWriteAdapter
>(
params: AdapterWriteParams<TAbi, TFunctionName>,
) => {
return this.getSignerAddress().then((from) => {
const writePromise = this.getSignerAddress().then((from) => {
const viemParams = createSimulateContractParameters(
Object.assign({}, params, { from }),
);
Expand All @@ -67,5 +70,14 @@ export class ViemReadWriteAdapter
this.walletClient.writeContract(request as WriteContractParameters),
);
});

if (params.onMined) {
writePromise.then((hash) => {
this.waitForTransaction({ hash }).then(params.onMined);
return hash;
});
}

return writePromise;
};
}

0 comments on commit 25a1e75

Please sign in to comment.