Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ckeshava committed Jun 6, 2024
1 parent 21c683e commit defdd4e
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions packages/xrpl/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ class Client extends EventEmitter<EventTypes> {
* Only used for multisigned transactions.
* @returns The autofilled transaction.
*/
/* eslint-disable max-len -- Long linter directives are needed to perform type-erasure in this function */
// eslint-disable-next-line max-lines-per-function, complexity -- handling v2 Payment transaction API requires more logic
public async autofill<T extends SubmittableTransaction>(
transaction: T,
Expand Down Expand Up @@ -668,57 +669,44 @@ class Client extends EventEmitter<EventTypes> {
}

// further manipulation of tx_ uses non-SubmittableTransaction types, hence we need a typecast to any
// eslint-disable-next-line max-len -- elaborate comment
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/consistent-type-assertions -- `any` type is required to perform non-protocol modifications to the JSON object
const tx_ = tx as any

// eslint-disable-next-line max-len -- elaborate comment
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A transaction JSON must contain TransactionType field
if (tx_.TransactionType === 'Payment') {
// eslint-disable-next-line max-len -- elaborate comment
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- A Payment transaction JSON must contain Amount field
if (tx_.Amount == null) {
if (tx_.Amount == null && tx_.DeliverMax != null) {
// If only DeliverMax is provided, use it to populate the Amount field
// eslint-disable-next-line max-len -- elaborate comment
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, max-depth -- A Payment transaction JSON might contain Amount field
if (tx_.DeliverMax != null) {
// eslint-disable-next-line max-len -- elaborate comment
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access -- ensure that the aliased fields are identical
tx_.Amount = tx_.DeliverMax
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access -- ensure that the aliased fields are identical
tx_.Amount = tx_.DeliverMax
}

// If Amount is not identical to DeliverMax, throw an error
if (
// eslint-disable-next-line max-len -- elaborate comment
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields
tx_.DeliverMax != null &&
// eslint-disable-next-line max-len -- elaborate comment
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields
tx_.Amount != null &&
// eslint-disable-next-line max-len -- elaborate comment
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction JSON could contain these fields
tx_.Amount !== tx_.DeliverMax
) {
throw new ValidationError(
'PaymentTransaction: Amount and DeliverMax fields must be identical',
'PaymentTransaction: Amount and DeliverMax fields must be identical when both are provided',
)
}

// remove the DeliverMax field
// eslint-disable-next-line max-len -- elaborate comment
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction could contain DeliverMax field
if (tx_.DeliverMax != null) {
// eslint-disable-next-line max-len -- elaborate comment
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- v2 rippled Payment-transaction could contain DeliverMax field
delete tx_.DeliverMax
}
}

// eslint-disable-next-line max-len -- elaborate comment
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/promise-function-async -- Please ensure that tx_ is a serializable transaction
return Promise.all(promises).then(() => tx_)
}
/* eslint-enable max-len */

/**
* Submits a signed/unsigned transaction.
Expand Down

0 comments on commit defdd4e

Please sign in to comment.