mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
* major types cleanup, more formatted api methods onto new request method - getPaymentChannel() now uses this.request() - getSettings() now uses this.request() - getLedger() now uses this.request() - transaction types cleaned up a bit, but still some work left to do
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import * as assert from 'assert'
|
|
import {parseTimestamp} from './utils'
|
|
import parseAmount from './amount'
|
|
import {removeUndefined, txFlags} from '../../common'
|
|
import {
|
|
FormattedOrderSpecification,
|
|
OfferCreateTransaction
|
|
} from '../../common/types/objects/index'
|
|
|
|
const flags = txFlags.OfferCreate
|
|
|
|
function parseOrder(tx: OfferCreateTransaction): FormattedOrderSpecification {
|
|
assert(tx.TransactionType === 'OfferCreate')
|
|
|
|
const direction = (tx.Flags & flags.Sell) === 0 ? 'buy' : 'sell'
|
|
const takerGetsAmount = parseAmount(tx.TakerGets)
|
|
const takerPaysAmount = parseAmount(tx.TakerPays)
|
|
const quantity = (direction === 'buy') ? takerPaysAmount : takerGetsAmount
|
|
const totalPrice = (direction === 'buy') ? takerGetsAmount : takerPaysAmount
|
|
|
|
return removeUndefined({
|
|
direction: direction,
|
|
quantity: quantity,
|
|
totalPrice: totalPrice,
|
|
passive: ((tx.Flags & flags.Passive) !== 0) || undefined,
|
|
immediateOrCancel: ((tx.Flags & flags.ImmediateOrCancel) !== 0)
|
|
|| undefined,
|
|
fillOrKill: ((tx.Flags & flags.FillOrKill) !== 0) || undefined,
|
|
expirationTime: parseTimestamp(tx.Expiration)
|
|
})
|
|
}
|
|
|
|
export default parseOrder
|