Skip to content

Commit

Permalink
Merge pull request #24 from lidofinance/fix/fix_error_handler
Browse files Browse the repository at this point in the history
fix: fix errorHandler
  • Loading branch information
DiRaiks committed Sep 12, 2023
2 parents bd2dd1f + a8f0f64 commit e8f93f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/src/common/decorators/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const ErrorHandler = function (headMessage: HeadMessage = 'Error:') {
) {
const methodName = String(context.name);
const replacementMethod = function (this: This, ...args: Args): Return {
const callback = args[0].callback;
const callback = args[0]?.callback;

try {
const result = originalMethod.call(this, ...args);
Expand Down
17 changes: 6 additions & 11 deletions packages/sdk/src/staking/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,21 @@ export class LidoSDKStaking {

@Logger('LOG:')
private async stakeEOA(props: StakeProps): Promise<StakeResult> {
const {
value,
callback = () => {},
referralAddress = zeroAddress,
account,
} = props;
const { value, callback, referralAddress = zeroAddress, account } = props;

invariant(this.core.rpcProvider, 'RPC provider is not defined');
invariant(this.core.web3Provider, 'Web3 provider is not defined');
// Checking the daily protocol staking limit
await this.validateStakeLimit(value);

callback({ stage: TransactionCallbackStage.GAS_LIMIT });
callback?.({ stage: TransactionCallbackStage.GAS_LIMIT });
const { gasLimit, overrides } = await this.submitGasLimit(
account,
value,
referralAddress,
);

callback({ stage: TransactionCallbackStage.SIGN, payload: gasLimit });
callback?.({ stage: TransactionCallbackStage.SIGN, payload: gasLimit });

const contract = await this.getContractStETH();
const transaction = await contract.write.submit([referralAddress], {
Expand All @@ -119,7 +114,7 @@ export class LidoSDKStaking {
account,
});

callback({
callback?.({
stage: TransactionCallbackStage.RECEIPT,
payload: transaction,
});
Expand All @@ -129,7 +124,7 @@ export class LidoSDKStaking {
hash: transaction,
});

callback({
callback?.({
stage: TransactionCallbackStage.CONFIRMATION,
payload: transactionReceipt,
});
Expand All @@ -139,7 +134,7 @@ export class LidoSDKStaking {
hash: transactionReceipt.transactionHash,
});

callback({
callback?.({
stage: TransactionCallbackStage.DONE,
payload: confirmations,
});
Expand Down

0 comments on commit e8f93f3

Please sign in to comment.