Files
xahau.js/src/api/ledger/parse/amount.js
2015-06-17 18:04:24 -07:00

24 lines
631 B
JavaScript

/* @flow */
'use strict';
const utils = require('./utils');
/*:: type Amount = string | {currency: string, issuer: string, value: string} */
/*:: type XRPAmount = {currency: string, value: string} */
/*:: type IOUAmount = {currency: string, value: string, counterparty: string} */
/*:: type Output = XRPAmount | IOUAmount */
function parseAmount(amount: Amount): Output {
if (typeof amount === 'string') {
return {
currency: 'XRP',
value: utils.dropsToXrp(amount)
};
}
return {
currency: amount.currency,
value: amount.value,
counterparty: amount.issuer
};
}
module.exports = parseAmount;