Skip to content

Commit e49235f

Browse files
committed
fix: claim and stake gas estimation
1 parent c987dca commit e49235f

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

apps/namadillo/src/App/Staking/StakingRewards.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const StakingRewards = (): JSX.Element => {
7070
} = useTransaction({
7171
createTxAtom: claimAndStakeRewardsAtom,
7272
params: rewardsToClaim,
73-
eventType: "ClaimRewards",
73+
eventType: ["ClaimRewards", "Bond"],
7474
parsePendingTxNotification: () => ({
7575
title: "Claim rewards transaction is in progress",
7676
description: (

apps/namadillo/src/hooks/useTransaction.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export type UseTransactionProps<T> = {
4343
params: T[];
4444
createTxAtom: AtomType<T>;
4545
useDisposableSigner?: boolean;
46-
eventType: TransactionEventsClasses;
46+
eventType: TransactionEventsClasses | TransactionEventsClasses[];
4747
parsePendingTxNotification?: (tx: TransactionPair<T>) => PartialNotification;
4848
parseErrorTxNotification?: () => PartialNotification;
4949
} & UseTransactionPropsEvents<T>;
@@ -80,12 +80,22 @@ export const useTransaction = <T,>({
8080
const dispatchNotification = useSetAtom(dispatchToastNotificationAtom);
8181
const { mutateAsync: performBuildTx } = useAtomValue(createTxAtom);
8282

83-
// We don't want to display zeroed value when params are not set yet.
84-
const txKinds = new Array(Math.max(1, params.length)).fill(eventType);
83+
// Claim & Stake is the only array of tx kinds. The rest are single tx kinds.
84+
const arr = new Array(Math.max(1, params.length));
85+
const kinds =
86+
Array.isArray(eventType) ?
87+
// **IMPORTANT**
88+
// If eventType is an array, we set kinds by multiplying each kind by params length
89+
// i.e. (["ClaimRewards", "Bond"] AND params.length == 2) => ["ClaimRewards", "Bond", "ClaimRewards", "Bond"]
90+
arr.fill(eventType).flat()
91+
: arr.fill(eventType); // Don't display zeroed value when params are not set yet.
92+
8593
const feeProps = useTransactionFee(
86-
txKinds,
87-
["ShieldedTransfer", "UnshieldingTransfer"].includes(eventType)
94+
kinds,
95+
kinds.some((k) => ["ShieldedTransfer", "UnshieldingTransfer"].includes(k))
8896
);
97+
const broadcastEventType =
98+
!Array.isArray(eventType) ? eventType : "ClaimRewards";
8999

90100
const dispatchPendingTxNotification = (
91101
tx: TransactionPair<T>,
@@ -192,7 +202,7 @@ export const useTransaction = <T,>({
192202
transactionPair.encodedTxData,
193203
transactionPair.signedTxs,
194204
transactionPair.encodedTxData.meta?.props,
195-
eventType
205+
broadcastEventType
196206
);
197207
onBroadcasted?.(transactionPair);
198208
} catch (error) {

0 commit comments

Comments
 (0)