Add BTC conversion utils
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
export function floatToBtc(number) {
|
||||
return Number(number.toFixed(8))
|
||||
}
|
||||
|
||||
export function btcToSats(btc) {
|
||||
return Math.round(btc * 100_000_000);
|
||||
}
|
||||
|
||||
export function satsToBtc(sats) {
|
||||
return Math.round((sats / 100_000_000) * 100_000_000) / 100_000_000;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { floatToBtc, btcToSats, satsToBtc } from 'kredits-web/utils/btc-conversions';
|
||||
import { module, test } from 'qunit';
|
||||
|
||||
module('Unit | Utility | btc-conversions', function() {
|
||||
test('floatToBtc', function(assert) {
|
||||
assert.equal(floatToBtc(0.001429007), 0.00142901);
|
||||
});
|
||||
|
||||
test('btcToSats', function(assert) {
|
||||
assert.equal(btcToSats(0.001429007), 142901);
|
||||
});
|
||||
|
||||
test('satsToBtc', function(assert) {
|
||||
assert.equal(satsToBtc(142901), 0.00142901);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user