Files
xahau.js/src/ledger/parse/payment.ts
Fred K. Schott 8204f6c648 Convert from Flow to Typescript (#816)
* convert to typescript
* add docs for custom node typing
* update webpack, gulpfile
2017-12-24 00:39:18 -08:00

49 lines
1.3 KiB
TypeScript

import * as _ from 'lodash'
import * as assert from 'assert'
import * as utils from './utils'
import {txFlags, removeUndefined} from '../../common'
import parseAmount from './amount'
function isNoDirectRipple(tx) {
return (tx.Flags & txFlags.Payment.NoRippleDirect) !== 0
}
function isQualityLimited(tx) {
return (tx.Flags & txFlags.Payment.LimitQuality) !== 0
}
function removeGenericCounterparty(amount, address) {
return amount.counterparty === address ?
_.omit(amount, 'counterparty') : amount
}
function parsePayment(tx: any): Object {
assert(tx.TransactionType === 'Payment')
const source = {
address: tx.Account,
maxAmount: removeGenericCounterparty(
parseAmount(tx.SendMax || tx.Amount), tx.Account),
tag: tx.SourceTag
}
const destination = {
address: tx.Destination,
amount: removeGenericCounterparty(parseAmount(tx.Amount), tx.Destination),
tag: tx.DestinationTag
}
return removeUndefined({
source: removeUndefined(source),
destination: removeUndefined(destination),
memos: utils.parseMemos(tx),
invoiceID: tx.InvoiceID,
paths: tx.Paths ? JSON.stringify(tx.Paths) : undefined,
allowPartialPayment: utils.isPartialPayment(tx) || undefined,
noDirectRipple: isNoDirectRipple(tx) || undefined,
limitQuality: isQualityLimited(tx) || undefined
})
}
export default parsePayment