Fix Payment source & destination types (#870)

Payment `source` and `destination` are defined as intersection types, `Adjustment & MaxAdjustment` and  `Adjustment & MinAdjustment` respectively. But they should be union types instead. This problem was introduced during js to ts conversion.

Fixes #866
This commit is contained in:
darkmemo
2018-03-20 21:26:41 +03:00
committed by Elliot Lee
parent 71a0c16fec
commit a72041a321

View File

@@ -10,8 +10,8 @@ import {Amount, Adjustment, MaxAdjustment,
export type Payment = {
source: Adjustment & MaxAdjustment,
destination: Adjustment & MinAdjustment,
source: Adjustment | MaxAdjustment,
destination: Adjustment | MinAdjustment,
paths?: string,
memos?: Array<Memo>,
// A 256-bit hash that can be used to identify a particular payment
@@ -74,8 +74,8 @@ function createPaymentTransaction(address: string, paymentArgument: Payment
throw new ValidationError('address must match payment.source.address')
}
if ((payment.source.maxAmount && payment.destination.minAmount) ||
(payment.source.amount && payment.destination.amount)) {
if (((<MaxAdjustment>payment.source).maxAmount && (<MinAdjustment>payment.destination).minAmount) ||
((<Adjustment>payment.source).amount && (<Adjustment>payment.destination).amount)) {
throw new ValidationError('payment must specify either (source.maxAmount '
+ 'and destination.amount) or (source.amount and destination.minAmount)')
}
@@ -86,9 +86,9 @@ function createPaymentTransaction(address: string, paymentArgument: Payment
// send the whole source amount, so we set the destination amount to the
// maximum possible amount. otherwise it's possible that the destination
// cap could be hit before the source cap.
const amount = payment.destination.minAmount && !isXRPToXRPPayment(payment) ?
createMaximalAmount(payment.destination.minAmount) :
(payment.destination.amount || payment.destination.minAmount)
const amount = (<MinAdjustment>payment.destination).minAmount && !isXRPToXRPPayment(payment) ?
createMaximalAmount((<MinAdjustment>payment.destination).minAmount) :
((<Adjustment>payment.destination).amount || (<MinAdjustment>payment.destination).minAmount)
const txJSON: any = {
TransactionType: 'Payment',
@@ -122,15 +122,15 @@ function createPaymentTransaction(address: string, paymentArgument: Payment
// https://github.com/ripple/rippled/commit/
// c522ffa6db2648f1d8a987843e7feabf1a0b7de8/
if (payment.allowPartialPayment === true
|| payment.destination.minAmount !== undefined) {
|| (<MinAdjustment>payment.destination).minAmount !== undefined) {
txJSON.Flags |= paymentFlags.PartialPayment
}
txJSON.SendMax = toRippledAmount(
payment.source.maxAmount || payment.source.amount)
(<MaxAdjustment>payment.source).maxAmount || (<Adjustment>payment.source).amount)
if (payment.destination.minAmount !== undefined) {
txJSON.DeliverMin = toRippledAmount(payment.destination.minAmount)
if ((<MinAdjustment>payment.destination).minAmount !== undefined) {
txJSON.DeliverMin = toRippledAmount((<MinAdjustment>payment.destination).minAmount)
}
if (payment.paths !== undefined) {