Skip to content

Commit 6295f1a

Browse files
committed
refactor(sdk-coin-hbar): improve variable naming and typing
- Replace single-letter variable 't' with descriptive 'instructionType' in validateAssociateInstructionOnly method - Replace 'any' type with proper HederaRecipient type in validateNoTransfers method - Export Recipient type from lib/index.ts as HederaRecipient to avoid naming conflicts Ticket: WP-5746
1 parent 6eb45c0 commit 6295f1a

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

modules/sdk-coin-hbar/src/hbar.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
import { BigNumber } from 'bignumber.js';
2929
import * as stellar from 'stellar-sdk';
3030
import { SeedValidator } from './seedValidator';
31-
import { KeyPair as HbarKeyPair, TransactionBuilderFactory, Transaction } from './lib';
31+
import { KeyPair as HbarKeyPair, TransactionBuilderFactory, Transaction, Recipient as HederaRecipient } from './lib';
3232
import * as Utils from './lib/utils';
3333
import * as _ from 'lodash';
3434
import {
@@ -303,7 +303,7 @@ export class Hbar extends BaseCoin {
303303
private validateNoTransfers(raw: HederaRawTransactionData): void {
304304
if (raw.instructionsData?.params?.recipients?.length && raw.instructionsData.params.recipients.length > 0) {
305305
const hasNonZeroTransfers = raw.instructionsData.params.recipients.some(
306-
(recipient: any) => recipient.amount && recipient.amount !== '0'
306+
(recipient: HederaRecipient) => recipient.amount && recipient.amount !== '0'
307307
);
308308
if (hasNonZeroTransfers) {
309309
throw new Error('Transaction contains transfers; not a pure token enablement.');
@@ -422,15 +422,22 @@ export class Hbar extends BaseCoin {
422422
}
423423

424424
private validateAssociateInstructionOnly(raw: HederaRawTransactionData): void {
425-
const t = String(raw.instructionsData?.type || '').toLowerCase();
425+
const instructionType = String(raw.instructionsData?.type || '').toLowerCase();
426426

427-
if (t === 'contractexecute' || t === 'contractcall' || t === 'precompile') {
428-
throw new Error(`Contract-based token association not allowed for blind enablement; got ${t}`);
427+
if (
428+
instructionType === 'contractexecute' ||
429+
instructionType === 'contractcall' ||
430+
instructionType === 'precompile'
431+
) {
432+
throw new Error(`Contract-based token association not allowed for blind enablement; got ${instructionType}`);
429433
}
430434

431-
const isNativeAssociate = t === 'tokenassociate' || t === 'associate' || t === 'associate_token';
435+
const isNativeAssociate =
436+
instructionType === 'tokenassociate' || instructionType === 'associate' || instructionType === 'associate_token';
432437
if (!isNativeAssociate) {
433-
throw new Error(`Only native TokenAssociate is allowed for blind enablement; got ${t || 'unknown'}`);
438+
throw new Error(
439+
`Only native TokenAssociate is allowed for blind enablement; got ${instructionType || 'unknown'}`
440+
);
434441
}
435442
}
436443

modules/sdk-coin-hbar/src/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export { TransferBuilder } from './transferBuilder';
77
export { CoinTransferBuilder } from './coinTransferBuilder';
88
export { TokenTransferBuilder } from './tokenTransferBuilder';
99
export { TokenAssociateBuilder } from './tokenAssociateBuilder';
10+
export { Recipient } from './iface';
1011
export { Utils };

0 commit comments

Comments
 (0)