mirror of
https://github.com/Xahau/xahau.js.git
synced 2026-04-29 15:37:50 +00:00
24 lines
631 B
JavaScript
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;
|