proper rounding for amount operations
This commit is contained in:
parent
63914ab53b
commit
b47522c11b
@ -1312,7 +1312,7 @@ export namespace Amounts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
value = value + x.value + Math.floor((fraction + x.fraction) / fractionalBase);
|
value = value + x.value + Math.floor((fraction + x.fraction) / fractionalBase);
|
||||||
fraction = (fraction + x.fraction) % fractionalBase;
|
fraction = Math.floor((fraction + x.fraction) % fractionalBase);
|
||||||
if (value > Number.MAX_SAFE_INTEGER) {
|
if (value > Number.MAX_SAFE_INTEGER) {
|
||||||
return { amount: getMaxAmount(currency), saturated: true };
|
return { amount: getMaxAmount(currency), saturated: true };
|
||||||
}
|
}
|
||||||
@ -1440,7 +1440,7 @@ export namespace Amounts {
|
|||||||
export function fromFloat(floatVal: number, currency: string) {
|
export function fromFloat(floatVal: number, currency: string) {
|
||||||
return {
|
return {
|
||||||
currency,
|
currency,
|
||||||
fraction: (floatVal - Math.floor(floatVal)) * fractionalBase,
|
fraction: Math.floor((floatVal - Math.floor(floatVal)) * fractionalBase),
|
||||||
value: Math.floor(floatVal),
|
value: Math.floor(floatVal),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -413,6 +413,8 @@ export function selectPayCoins(cds: CoinWithDenom[], paymentAmount: AmountJson,
|
|||||||
denom.feeDeposit).amount) >= 0;
|
denom.feeDeposit).amount) >= 0;
|
||||||
isBelowFee = Amounts.cmp(accFee, depositFeeLimit) <= 0;
|
isBelowFee = Amounts.cmp(accFee, depositFeeLimit) <= 0;
|
||||||
|
|
||||||
|
console.log("coin selection", { coversAmount, isBelowFee, accFee, accAmount, paymentAmount });
|
||||||
|
|
||||||
if ((coversAmount && isBelowFee) || coversAmountWithFee) {
|
if ((coversAmount && isBelowFee) || coversAmountWithFee) {
|
||||||
return cdsResult;
|
return cdsResult;
|
||||||
}
|
}
|
||||||
@ -759,6 +761,8 @@ export class Wallet {
|
|||||||
cds.push({coin, denom});
|
cds.push({coin, denom});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("coin return: selecting from possible coins", { cds, amount } );
|
||||||
|
|
||||||
return selectPayCoins(cds, amount, amount);
|
return selectPayCoins(cds, amount, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user