Skip to content

Commit

Permalink
refactor: unwrap TX on L2 use runWithTransactionLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
solidovic committed Oct 1, 2024
1 parent bd0d7d9 commit 9b0b4ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
17 changes: 13 additions & 4 deletions features/wsteth/unwrap/hooks/use-unwrap-form-processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,23 @@ export const useUnwrapFormProcessor = ({

let txHash: string;
if (isSDKSupportedL2Chain(chainId as CHAINS)) {
// TODO: remove without runWithTransactionLogger
// txHash = (
// await sdk.l2.wrapWstethToSteth({
// value: amount.toBigInt(),
// })
// ).hash;
txHash = (
await sdk.l2.wrapWstethToSteth({
value: amount.toBigInt(),
})
await runWithTransactionLogger('Unwrap signing on L2', () =>
// The operation 'wstETH to stETH' on L2 is 'wrap'
sdk.l2.wrapWstethToSteth({
value: amount.toBigInt(),
}),
)
).hash;
} else {
txHash = await runWithTransactionLogger(
'Unwrap signing',
'Unwrap signing on L1',
async () => {
const tx =
await wstethContractWeb3.populateTransaction.unwrap(amount);
Expand Down
15 changes: 12 additions & 3 deletions features/wsteth/unwrap/hooks/use-unwrap-tx-on-l2-approve.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMemo, useState, useEffect, useCallback } from 'react';
import type { BigNumber } from 'ethers';

import { runWithTransactionLogger } from 'utils';
import { useLidoSDK } from 'providers/lido-sdk';

type UseUnwrapTxApproveArgs = {
Expand Down Expand Up @@ -30,10 +31,18 @@ export const useUnwrapTxOnL2Approve = ({ amount }: UseUnwrapTxApproveArgs) => {
const processApproveTx = useCallback(
async ({ onTxSent }) => {
try {
// TODO: remove without runWithTransactionLogger
// const approveTxHash = (
// await sdk.l2.approveWstethForWrap({
// value: amount.toBigInt(),
// })
// ).hash;
const approveTxHash = (
await sdk.l2.approveWstethForWrap({
value: amount.toBigInt(),
})
await runWithTransactionLogger('Approve signing on L2', () =>
sdk.l2.approveWstethForWrap({
value: amount.toBigInt(),
}),
)
).hash;

await onTxSent?.(approveTxHash);
Expand Down
2 changes: 1 addition & 1 deletion shared/hooks/useApproveOnL1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const useApproveOnL1 = (
};

const approveTxHash = await runWithTransactionLogger(
'Approve signing',
'Approve signing on L1',
processApproveTx,
);
await onTxSent?.(approveTxHash);
Expand Down

0 comments on commit 9b0b4ee

Please sign in to comment.