Skip to content

Commit 86f875f

Browse files
authored
Add isGuarded prop (#433)
1 parent 60125ff commit 86f875f

File tree

9 files changed

+203
-66
lines changed

9 files changed

+203
-66
lines changed

pnpm-lock.yaml

Lines changed: 166 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages/Dashboard/widgets/BatchTransactions/BatchTransactions.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { useState } from 'react';
21
import {
32
faArrowsRotate,
43
faPaperPlane,
54
IconDefinition
65
} from '@fortawesome/free-solid-svg-icons';
76
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
7+
import { useState } from 'react';
88
import { OutputContainer } from 'components/OutputContainer';
99
import { TransactionsOutput } from 'components/OutputContainer/components';
1010
import { MvxButton, useGetPendingTransactionsSessions } from 'lib';
@@ -35,7 +35,7 @@ interface BatchTransactionsButtonsType {
3535
}
3636

3737
export const BatchTransactions = () => {
38-
const { address, nonce } = useGetAccount();
38+
const { address, nonce, isGuarded } = useGetAccount();
3939
const { network } = useGetNetworkConfig();
4040
const [currentSessionId, setCurrentSessionId] = useState('');
4141
const pendingSession = useGetPendingTransactionsSessions();
@@ -47,6 +47,7 @@ export const BatchTransactions = () => {
4747

4848
const executeSignAndAutoSendBatchTransactions = async () => {
4949
const sessionId = await signAndAutoSendBatchTransactions({
50+
isGuarded,
5051
address,
5152
nonce,
5253
chainID: network.chainId,
@@ -63,6 +64,7 @@ export const BatchTransactions = () => {
6364

6465
const executeWrapMultiTransferTransactions = async () => {
6566
const sessionId = await wrapAndMultiTransferTransactions({
67+
isGuarded,
6668
address,
6769
nonce,
6870
chainID: network.chainId,
@@ -79,6 +81,7 @@ export const BatchTransactions = () => {
7981

8082
const executeSwapAndLockTokens = async () => {
8183
const sessionId = await swapAndLockTokens({
84+
isGuarded,
8285
address,
8386
nonce,
8487
chainID: network.chainId,

src/pages/Dashboard/widgets/BatchTransactions/helpers/getBatchTransactions.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const NUMBER_OF_TRANSACTIONS = 5;
1111

1212
export const getBatchTransactions = async ({
1313
address,
14-
chainID
14+
chainID,
15+
isGuarded
1516
}: TransactionProps): Promise<Transaction[]> => {
1617
const transactions = Array.from(Array(NUMBER_OF_TRANSACTIONS).keys());
1718

@@ -35,6 +36,10 @@ export const getBatchTransactions = async ({
3536
}
3637
);
3738

39+
if (isGuarded) {
40+
tokenTransfer.gasLimit = tokenTransfer.gasLimit + BigInt(50_000);
41+
}
42+
3843
return tokenTransfer;
3944
})
4045
);

src/pages/Dashboard/widgets/BatchTransactions/helpers/getSwapAndLockTransactions.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import { Address, GAS_PRICE, Transaction, VERSION } from 'lib';
33
import { TransactionProps } from 'types';
44

55
export const getSwapAndLockTransactions = ({
6+
isGuarded,
67
address,
78
chainID,
89
nonce
910
}: TransactionProps): Transaction[] => {
10-
return [
11+
const transcations = [
1112
new Transaction({
1213
chainID,
1314
gasLimit: BigInt(4200000),
@@ -57,4 +58,12 @@ export const getSwapAndLockTransactions = ({
5758
data: Uint8Array.from(Buffer.from(BATCH_TRANSACTIONS_SC.lock_MEX.data))
5859
})
5960
];
61+
62+
if (isGuarded) {
63+
transcations.forEach((tx) => {
64+
tx.gasLimit = tx.gasLimit + BigInt(50_000);
65+
});
66+
}
67+
68+
return transcations;
6069
};

src/pages/Dashboard/widgets/BatchTransactions/helpers/getWrapAndMultiTransferTransactions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Address } from 'lib';
1313
import { TransactionProps } from 'types';
1414

1515
export const getWrapAndMultiTransferTransactions = async ({
16+
isGuarded,
1617
address,
1718
chainID
1819
}: TransactionProps) => {
@@ -68,5 +69,13 @@ export const getWrapAndMultiTransferTransactions = async ({
6869
]
6970
});
7071

72+
if (isGuarded) {
73+
wrapOneEgld.gasLimit = wrapOneEgld.gasLimit + BigInt(50_000);
74+
swapHalfWEgldToUsdc.gasLimit =
75+
swapHalfWEgldToUsdc.gasLimit + BigInt(50_000);
76+
multiTransferOneUsdcHalfWEgld.gasLimit =
77+
multiTransferOneUsdcHalfWEgld.gasLimit + BigInt(50_000);
78+
}
79+
7180
return { wrapOneEgld, swapHalfWEgldToUsdc, multiTransferOneUsdcHalfWEgld };
7281
};

src/pages/Dashboard/widgets/BatchTransactions/helpers/signAndAutoSendBatchTransactions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getBatchTransactions } from './getBatchTransactions';
44
import { sendAndTrackTransactions } from './sendAndTrackTransactions';
55

66
export const signAndAutoSendBatchTransactions = async ({
7+
isGuarded,
78
address,
89
nonce,
910
chainID,
@@ -18,6 +19,7 @@ export const signAndAutoSendBatchTransactions = async ({
1819
const provider = getAccountProvider();
1920

2021
const transactions = await getBatchTransactions({
22+
isGuarded,
2123
address,
2224
nonce,
2325
chainID

src/pages/Dashboard/widgets/BatchTransactions/helpers/swapAndLockTokens.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getSwapAndLockTransactions } from './getSwapAndLockTransactions';
1010
import { sendAndTrackTransactions } from './sendAndTrackTransactions';
1111

1212
export const swapAndLockTokens = async ({
13+
isGuarded,
1314
address,
1415
nonce,
1516
chainID,
@@ -24,6 +25,7 @@ export const swapAndLockTokens = async ({
2425
const provider = getAccountProvider();
2526

2627
const transactionsToSign = getSwapAndLockTransactions({
28+
isGuarded,
2729
address,
2830
chainID,
2931
nonce

src/pages/Dashboard/widgets/BatchTransactions/helpers/wrapAndMultiTransferTransactions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ interface WrapAndMultiTransferTransactionsType extends TransactionProps {
1414
export const wrapAndMultiTransferTransactions = async (
1515
props: WrapAndMultiTransferTransactionsType
1616
) => {
17-
const { address, nonce, chainID, transactionsDisplayInfo } = props;
17+
const { address, nonce, chainID, transactionsDisplayInfo, isGuarded } = props;
1818

1919
const provider = getAccountProvider();
2020

2121
const transactionsToSign = await getWrapAndMultiTransferTransactions({
22+
isGuarded,
2223
address,
2324
chainID,
2425
nonce

src/types/transaction.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export type TransactionProps = {
2+
isGuarded?: boolean;
23
address: string;
34
nonce: number;
45
chainID: string;

0 commit comments

Comments
 (0)