From a8f0f64fd9625cf1602915e1d0bbbcabb6abcec7 Mon Sep 17 00:00:00 2001 From: Andrei Date: Tue, 12 Sep 2023 00:24:21 +0700 Subject: [PATCH] fix: fix errorHandler --- .../sdk/src/common/decorators/ErrorHandler.ts | 2 +- packages/sdk/src/staking/staking.ts | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/sdk/src/common/decorators/ErrorHandler.ts b/packages/sdk/src/common/decorators/ErrorHandler.ts index 6f0b3f96..26f3038f 100644 --- a/packages/sdk/src/common/decorators/ErrorHandler.ts +++ b/packages/sdk/src/common/decorators/ErrorHandler.ts @@ -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); diff --git a/packages/sdk/src/staking/staking.ts b/packages/sdk/src/staking/staking.ts index 71ec7d79..129a71e1 100644 --- a/packages/sdk/src/staking/staking.ts +++ b/packages/sdk/src/staking/staking.ts @@ -89,26 +89,21 @@ export class LidoSDKStaking { @Logger('LOG:') private async stakeEOA(props: StakeProps): Promise { - 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], { @@ -119,7 +114,7 @@ export class LidoSDKStaking { account, }); - callback({ + callback?.({ stage: TransactionCallbackStage.RECEIPT, payload: transaction, }); @@ -129,7 +124,7 @@ export class LidoSDKStaking { hash: transaction, }); - callback({ + callback?.({ stage: TransactionCallbackStage.CONFIRMATION, payload: transactionReceipt, }); @@ -139,7 +134,7 @@ export class LidoSDKStaking { hash: transactionReceipt.transactionHash, }); - callback({ + callback?.({ stage: TransactionCallbackStage.DONE, payload: confirmations, });