Skip to content

Commit

Permalink
feat(sdk-coin-xrp): add tokenTransferBuilder
Browse files Browse the repository at this point in the history
TICKET: WIN-3610
  • Loading branch information
nvrakesh06 committed Oct 17, 2024
1 parent 8d4a245 commit fc79381
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions modules/sdk-coin-xrp/src/lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ export class Transaction extends BaseTransaction {
return true;
}

private isIssuedCurrencyAmount(amount: Amount): amount is IssuedCurrencyAmount {
return (
!_.isString(amount) &&
_.isObjectLike(amount) &&
_.isString(amount.currency) &&
_.isString(amount.issuer) &&
_.isString(amount.value)
);
}

toJson(): TxData {
if (!this._xrpTransaction) {
throw new InvalidTransactionError('Empty transaction');
Expand All @@ -87,6 +77,16 @@ export class Transaction extends BaseTransaction {
txData.isMultiSig = false;
}

function isIssuedCurrencyAmount(amount: Amount): amount is IssuedCurrencyAmount {
return (
!_.isString(amount) &&
_.isObjectLike(amount) &&
_.isString(amount.currency) &&
_.isString(amount.issuer) &&
_.isString(amount.value)
);
}

switch (this._xrpTransaction.TransactionType) {
case XrpTransactionType.Payment:
txData.destination = this._xrpTransaction.Destination;
Expand All @@ -95,6 +95,8 @@ export class Transaction extends BaseTransaction {
txData.amount = this._xrpTransaction.Amount;
} else if (this.isIssuedCurrencyAmount(this._xrpTransaction.Amount)) {
txData.amount = this._xrpTransaction.Amount;
} else if (isIssuedCurrencyAmount(this._xrpTransaction.Amount)) {
txData.amount = this._xrpTransaction.Amount;
} else {
throw new InvalidTransactionError('Invalid amount');
}
Expand Down

0 comments on commit fc79381

Please sign in to comment.