Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@makerdao/currency

Package Overview
Dependencies
Maintainers
18
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@makerdao/currency - npm Package Compare versions

Comparing version 0.9.6 to 0.9.7

test/getCurrency.spec.js

2

dist/Currency.js

@@ -134,3 +134,3 @@ 'use strict';

var mathFunctions = [['plus'], ['minus'], ['times', 'multipliedBy'], ['div', 'dividedBy'], ['shiftedBy']];
var mathFunctions = [['plus', 'add'], ['minus', 'sub'], ['times', 'multipliedBy', 'mul'], ['div', 'dividedBy'], ['shiftedBy']];

@@ -137,0 +137,0 @@ var booleanFunctions = [['isLessThan', 'lt'], ['isLessThanOrEqualTo', 'lte'], ['isGreaterThan', 'gt'], ['isGreaterThanOrEqualTo', 'gte'], ['eq']];

{
"name": "@makerdao/currency",
"description": "Utilities for working with currency amounts",
"version": "0.9.6",
"version": "0.9.7",
"license": "MIT",

@@ -6,0 +6,0 @@ "main": "dist/index.js",

@@ -71,5 +71,5 @@ import BigNumber from 'bignumber.js';

const mathFunctions = [
['plus'],
['minus'],
['times', 'multipliedBy'],
['plus', 'add'],
['minus', 'sub'],
['times', 'multipliedBy', 'mul'],
['div', 'dividedBy'],

@@ -76,0 +76,0 @@ ['shiftedBy']

@@ -1,7 +0,2 @@

import {
Currency,
createCurrency,
createCurrencyRatio,
createGetCurrency
} from '../src';
import { Currency, createCurrency, createCurrencyRatio } from '../src';

@@ -120,2 +115,7 @@ const DAI = createCurrency('DAI');

test('dividing by 0 = Infinity', () => {
expect(USD(10).div(0)).toEqual(USD(Infinity));
expect(USD(10).div(DAI(0))).toEqual(USD_DAI(Infinity));
});
test('creating a ratio from division', () => {

@@ -149,66 +149,1 @@ const value1 = USD(4);

});
describe('getCurrency', () => {
let getCurrency;
beforeAll(() => {
getCurrency = createGetCurrency({ DAI, MKR, ETH, PETH, WETH, USD });
});
test('passes through Currency instance', () => {
const val = ETH(5);
expect(getCurrency(val)).toEqual(val);
});
test('parses an amount and currency symbol', () => {
expect(getCurrency(1, 'dai').toString()).toBe('1.00 DAI');
expect(getCurrency(1, 'mkr').toString()).toBe('1.00 MKR');
expect(getCurrency(1, 'weth').toString()).toBe('1.00 WETH');
expect(getCurrency(1, 'peth').toString()).toBe('1.00 PETH');
expect(getCurrency(1, 'eth').toString()).toBe('1.00 ETH');
});
test('parses an amount + currency class', () => {
expect(getCurrency(1, ETH).toString()).toBe('1.00 ETH');
expect(getCurrency(1, PETH).toString()).toBe('1.00 PETH');
expect(getCurrency(1, WETH).toString()).toBe('1.00 WETH');
expect(getCurrency(1, DAI).toString()).toBe('1.00 DAI');
expect(getCurrency(1, MKR).toString()).toBe('1.00 MKR');
});
test('parses an amount + currency as wei', () => {
const val = 10000000000000000;
expect(getCurrency(val, ETH.wei).toString()).toBe('0.01 ETH');
expect(getCurrency(val, PETH.wei).toString()).toBe('0.01 PETH');
expect(getCurrency(val, WETH.wei).toString()).toBe('0.01 WETH');
expect(getCurrency(val, DAI.wei).toString()).toBe('0.01 DAI');
expect(getCurrency(val, MKR.wei).toString()).toBe('0.01 MKR');
});
test('parses an amount + currency as ray', () => {
const val = 10000000000000000000000000;
expect(getCurrency(val, ETH.ray).toString()).toBe('0.01 ETH');
expect(getCurrency(val, PETH.ray).toString()).toBe('0.01 PETH');
expect(getCurrency(val, WETH.ray).toString()).toBe('0.01 WETH');
expect(getCurrency(val, DAI.ray).toString()).toBe('0.01 DAI');
expect(getCurrency(val, MKR.ray).toString()).toBe('0.01 MKR');
});
test('throws an error if there is no unit', () => {
expect(() => {
getCurrency(1);
}).toThrowError('Amount is not a Currency');
});
test('throws an error if amount is negative', () => {
expect(() => {
getCurrency('-1', 'eth');
}).toThrowError('amount cannot be negative');
});
test('throws an error if symbol is unrecognized', () => {
expect(() => {
getCurrency(1, 'foo');
}).toThrowError('Couldn\'t find currency for "FOO"');
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc