Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: async callback #175

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/sdk/src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export default class LidoSDKCore extends LidoSDKCacheable {
nonce: 1,
};
} else {
callback({ stage: TransactionCallbackStage.GAS_LIMIT });
await callback({ stage: TransactionCallbackStage.GAS_LIMIT });
const feeData = await this.getFeeData();
overrides.maxFeePerGas = feeData.maxFeePerGas;
overrides.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
Expand All @@ -541,7 +541,7 @@ export default class LidoSDKCore extends LidoSDKCacheable {
}
}

const customGas = callback({
const customGas = await callback({
stage: TransactionCallbackStage.SIGN,
payload: overrides.gas,
});
Expand All @@ -556,11 +556,11 @@ export default class LidoSDKCore extends LidoSDKCacheable {
);

if (isContract) {
callback({ stage: TransactionCallbackStage.MULTISIG_DONE });
await callback({ stage: TransactionCallbackStage.MULTISIG_DONE });
return { hash };
}

callback({
await callback({
stage: TransactionCallbackStage.RECEIPT,
payload: hash,
});
Expand All @@ -574,7 +574,7 @@ export default class LidoSDKCore extends LidoSDKCacheable {
ERROR_CODE.TRANSACTION_ERROR,
);

callback({
await callback({
stage: TransactionCallbackStage.CONFIRMATION,
payload: receipt,
});
Expand All @@ -585,7 +585,7 @@ export default class LidoSDKCore extends LidoSDKCacheable {

const result = await decodeResult?.(receipt);

callback({
await callback({
stage: TransactionCallbackStage.DONE,
payload: confirmations,
});
Expand Down
8 changes: 7 additions & 1 deletion packages/sdk/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,18 @@ export type TransactionCallbackProps =
| { stage: TransactionCallbackStage.MULTISIG_DONE; payload?: undefined }
| { stage: TransactionCallbackStage.ERROR; payload: SDKError };

export type TransactionCallbackResult<TProps> = TProps extends {
// callback return type based on stage
type TransactionCallbackReturn<TProps> = TProps extends {
stage: TransactionCallbackStage.SIGN;
}
? bigint | undefined
: void;

// support both async and non async callbacks
export type TransactionCallbackResult<TProps> =
| TransactionCallbackReturn<TProps>
| Promise<TransactionCallbackReturn<TProps>>;

export type TransactionCallback = (
props: TransactionCallbackProps,
) => TransactionCallbackResult<TransactionCallbackProps>;
Expand Down
Loading