Skip to content

Commit 2d82c4e

Browse files
committed
fix: decoding logic to differentiate b/w stake and unstake batch
TICKET: SC-2173
1 parent 19c049d commit 2d82c4e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

modules/sdk-coin-polyx/src/lib/iface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export interface NominateArgs extends Args {
4545
}
4646

4747
export interface BatchCallObject {
48-
method: string;
48+
method?: string;
49+
callIndex?: string;
4950
args: Record<string, unknown>;
5051
}
5152

modules/sdk-coin-polyx/src/lib/transactionBuilderFactory.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { BatchUnstakingBuilder } from './batchUnstakingBuilder';
99
import { WithdrawUnbondedBuilder } from './withdrawUnbondedBuilder';
1010
import utils from './utils';
1111
import { Interface, SingletonRegistry, TransactionBuilder } from './';
12-
import { TxMethod } from './iface';
12+
import { TxMethod, BatchCallObject } from './iface';
1313
import { Transaction as BaseTransaction } from '@bitgo/abstract-substrate';
1414
import { Transaction as PolyxTransaction } from './transaction';
1515

@@ -77,15 +77,19 @@ export class TransactionBuilderFactory extends BaseTransactionBuilderFactory {
7777
} else if (methodName === 'bondExtra') {
7878
return this.getBondExtraBuilder();
7979
} else if (methodName === 'batchAll') {
80-
const args = decodedTxn.method.args as { calls?: { method: string; args: Record<string, unknown> }[] };
80+
const args = decodedTxn.method.args as { calls?: BatchCallObject[] };
8181

8282
if (args.calls && args.calls.length === 2) {
83+
// Decode method names from the calls using utils.decodeMethodName
84+
const firstCallMethod = utils.decodeMethodName(args.calls[0], registry);
85+
const secondCallMethod = utils.decodeMethodName(args.calls[1], registry);
86+
8387
// Check for batch staking pattern: bond + nominate
84-
if (args.calls[0].method === 'bond' && args.calls[1].method === 'nominate') {
88+
if (firstCallMethod === 'bond' && secondCallMethod === 'nominate') {
8589
return this.getBatchBuilder();
8690
}
8791
// Check for batch unstaking pattern: chill + unbond
88-
if (args.calls[0].method === 'chill' && args.calls[1].method === 'unbond') {
92+
if (firstCallMethod === 'chill' && secondCallMethod === 'unbond') {
8993
return this.getBatchUnstakingBuilder();
9094
}
9195
}

0 commit comments

Comments
 (0)