Skip to content

Commit

Permalink
refactor(sdk-coin-hbar): add recovery for hbar tokens
Browse files Browse the repository at this point in the history
TICKET: WIN-4342
  • Loading branch information
abhishekagrawal080 committed Jan 31, 2025
1 parent 725c495 commit 1380cc2
Show file tree
Hide file tree
Showing 3 changed files with 459 additions and 12 deletions.
14 changes: 11 additions & 3 deletions modules/sdk-coin-hbar/src/hbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ export interface RecoveryOptions {
maxFee?: string;
nodeId?: string;
startTime?: string;
tokenName?: string;
}

interface RecoveryInfo {
export interface RecoveryInfo {
id: string;
tx: string;
coin: string;
Expand Down Expand Up @@ -391,12 +392,19 @@ export class Hbar extends BaseCoin {

const spendableAmount = new BigNumber(nativeBalance).minus(fee).toString();

const txBuilder = this.getBuilderFactory().getTransferBuilder();
const txBuilder = params.tokenName
? this.getBuilderFactory().getTokenTransferBuilder()
: this.getBuilderFactory().getTransferBuilder();

txBuilder.node({ nodeId });
txBuilder.fee({ fee });
txBuilder.source({ address: params.rootAddress });
txBuilder.send({ address: destinationAddress, amount: spendableAmount });
txBuilder.validDuration(180);
if (params.tokenName) {
txBuilder.send({ address: destinationAddress, amount: spendableAmount, tokenName: params.tokenName });
} else {
txBuilder.send({ address: destinationAddress, amount: spendableAmount });
}

if (memoId) {
txBuilder.memo(memoId);
Expand Down
Loading

0 comments on commit 1380cc2

Please sign in to comment.