@nimiq/fastspot-api
Advanced tools
Comparing version 1.1.0 to 1.1.1
import { RequestAsset, SwapAsset, PriceData, FastspotPrice, FastspotContract, FastspotPreSwap, FastspotSwap, FastspotLimits, Contract, PreSwap, Swap, Limits } from './types'; | ||
export declare function coinsToUnits(asset: SwapAsset, value: string | number): number; | ||
export declare function coinsToUnits(asset: SwapAsset, value: string | number, roundUp?: boolean): number; | ||
export declare function convertFromData(from: FastspotPrice): PriceData; | ||
@@ -4,0 +4,0 @@ export declare function convertToData(to: FastspotPrice): PriceData; |
import { SwapAsset, } from './types'; | ||
export function coinsToUnits(asset, value) { | ||
export function coinsToUnits(asset, value, roundUp = false) { | ||
let decimals; | ||
@@ -17,4 +17,8 @@ switch (asset) { | ||
const parts = value.toString().split('.'); | ||
parts[1] = (parts[1] || '').substr(0, decimals).padEnd(decimals, '0'); | ||
return parseInt(parts.join(''), 10); | ||
parts[1] = (parts[1] || '').substr(0, decimals + 1).padEnd(decimals + 1, '0'); | ||
const units = parseInt(parts.join(''), 10) / 10; | ||
if (roundUp) { | ||
return Math.ceil(units); | ||
} | ||
return Math.floor(units); | ||
} | ||
@@ -26,5 +30,5 @@ export function convertFromData(from) { | ||
amount: coinsToUnits(asset, from.amount), | ||
fee: coinsToUnits(asset, from.fundingNetworkFee.total), | ||
feePerUnit: coinsToUnits(asset, from.fundingNetworkFee.perUnit), | ||
serviceNetworkFee: coinsToUnits(asset, from.finalizeNetworkFee.total), | ||
fee: coinsToUnits(asset, from.fundingNetworkFee.total, true), | ||
feePerUnit: coinsToUnits(asset, from.fundingNetworkFee.perUnit, true), | ||
serviceNetworkFee: coinsToUnits(asset, from.finalizeNetworkFee.total, true), | ||
}; | ||
@@ -37,5 +41,5 @@ } | ||
amount: coinsToUnits(asset, to.amount), | ||
fee: coinsToUnits(asset, to.finalizeNetworkFee.total), | ||
feePerUnit: coinsToUnits(asset, to.finalizeNetworkFee.perUnit), | ||
serviceNetworkFee: coinsToUnits(asset, to.fundingNetworkFee.total), | ||
fee: coinsToUnits(asset, to.finalizeNetworkFee.total, true), | ||
feePerUnit: coinsToUnits(asset, to.finalizeNetworkFee.perUnit, true), | ||
serviceNetworkFee: coinsToUnits(asset, to.fundingNetworkFee.total, true), | ||
}; | ||
@@ -42,0 +46,0 @@ } |
{ | ||
"name": "@nimiq/fastspot-api", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Typescript library to interact with the Fastspot API", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:nimiq/fastspot-api.git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28153
485