Refactor to make quality adjustment for XRP more clear

This commit is contained in:
Chris Clark
2015-07-08 12:51:49 -07:00
parent 38b254e7f0
commit fb8eefd00d

View File

@@ -8,8 +8,11 @@ const BigNumber = require('bignumber.js');
function adjustQualityForXRP(quality: string, takerGetsCurrency: string,
takerPaysCurrency: string) {
const shift = (takerGetsCurrency === 'XRP' ? 6 : 0)
- (takerPaysCurrency === 'XRP' ? 6 : 0);
// quality = takerPays.value/takerGets.value
// using drops (1e-6 XRP) for XRP values
const numeratorShift = (takerPaysCurrency === 'XRP' ? -6 : 0);
const denominatorShift = (takerGetsCurrency === 'XRP' ? -6 : 0);
const shift = numeratorShift - denominatorShift;
return shift === 0 ? quality :
(new BigNumber(quality)).shift(shift).toString();
}