Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(types): Make DepositPreauth easier to guard #2355

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/xrpl/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr
* Add type for NFToken object that is stored on a `NFTokenPage`.
* Add type for `account_info`'s `account_flags` property.

### Changed
* `DeposityPreauth` has a new type definition that will not allow `Authorize` and `Unauthorize` on the same instance. This provides better guard support.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `DeposityPreauth` has a new type definition that will not allow `Authorize` and `Unauthorize` on the same instance. This provides better guard support.
* `DepositPreauth` has a new type definition that will not allow `Authorize` and `Unauthorize` on the same instance. This provides better guard support.


## 2.8.0 (2023-06-13)

### Added
Expand Down
31 changes: 21 additions & 10 deletions packages/xrpl/src/models/transactions/depositPreauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,34 @@ import { ValidationError } from '../../errors'

import { BaseTransaction, validateBaseTransaction } from './common'

export interface DepositPreauthBase extends BaseTransaction {
TransactionType: 'DepositPreauth'
}

export interface DepositPreauthWithAuthorize extends DepositPreauthBase {
/** The XRP Ledger address of the sender to preauthorize. */
Authorize: string
Unauthorize: never
}

export interface DepositPreauthWithUnauthorize extends DepositPreauthBase {
Authorize: never
/** The XRP Ledger address of a sender whose preauthorization should be revoked. */
Unauthorize: string
}

/**
* A DepositPreauth transaction gives another account pre-approval to deliver
* payments to the sender of this transaction. This is only useful if the sender
* of this transaction is using (or plans to use) Deposit Authorization.
*
* @category Transaction Models
*
* @interface
*/
export interface DepositPreauth extends BaseTransaction {
TransactionType: 'DepositPreauth'
/** The XRP Ledger address of the sender to preauthorize. */
Authorize?: string
/**
* The XRP Ledger address of a sender whose preauthorization should be.
* revoked.
*/
Unauthorize?: string
}
export type DepositPreauth =
| DepositPreauthWithAuthorize
| DepositPreauthWithUnauthorize

/**
* Verify the form and type of a DepositPreauth at runtime.
Expand Down
6 changes: 5 additions & 1 deletion packages/xrpl/src/models/transactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export { AccountDelete } from './accountDelete'
export { CheckCancel } from './checkCancel'
export { CheckCash } from './checkCash'
export { CheckCreate } from './checkCreate'
export { DepositPreauth } from './depositPreauth'
export {
DepositPreauth,
DepositPreauthWithAuthorize,
DepositPreauthWithUnauthorize,
Comment on lines +16 to +17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these two need to be exported?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes if people want to type guard.

} from './depositPreauth'
export { EscrowCancel } from './escrowCancel'
export { EscrowCreate } from './escrowCreate'
export { EscrowFinish } from './escrowFinish'
Expand Down