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

@requestnetwork/currency

Package Overview
Dependencies
Maintainers
6
Versions
605
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@requestnetwork/currency - npm Package Compare versions

Comparing version 0.5.1-next.1424 to 0.5.1-next.1425

4

dist/currency.d.ts

@@ -38,2 +38,6 @@ import { RequestLogicTypes } from '@requestnetwork/types';

/**
* Returns the number of decimals
*/
getDecimals(): number;
/**
* @returns e.g.: 'ETH', 'ETH-rinkeby', 'FAU-rinkeby' etc.

@@ -40,0 +44,0 @@ */

@@ -11,2 +11,3 @@ "use strict";

const iso4217_1 = __importDefault(require("./iso4217"));
const others_1 = __importDefault(require("./others"));
/**

@@ -37,3 +38,3 @@ * @class Currency implements ICurrency with helpers

const erc20Currencies = erc20_1.getSupportedERC20Currencies();
const currencyFromAddress = erc20Currencies.find((c) => c.value === symbolOrAddress);
const currencyFromAddress = erc20Currencies.find((c) => c.value.toLowerCase() === symbolOrAddress.toLowerCase());
if (!currencyFromAddress) {

@@ -87,2 +88,25 @@ throw new Error(`The currency ${symbolOrAddress} does not exist or is not supported`);

/**
* Returns the number of decimals
*/
getDecimals() {
// Return decimals if currency is an ERC20
if (this.type === types_1.RequestLogicTypes.CURRENCY.ERC20) {
return erc20_1.getErc20Decimals(this);
}
// Return the number of decimals for ISO-4217 currencies
if (this.type === types_1.RequestLogicTypes.CURRENCY.ISO4217) {
const iso = iso4217_1.default.find((i) => i.code === this.value);
if (!iso) {
throw new Error(`Unsupported ISO currency ${this.value}`);
}
return iso.digits;
}
// other currencies
const otherCurrency = others_1.default[this.type];
if (!otherCurrency) {
throw new Error(`Currency ${this.type} not implemented`);
}
return otherCurrency.decimals;
}
/**
* @returns e.g.: 'ETH', 'ETH-rinkeby', 'FAU-rinkeby' etc.

@@ -89,0 +113,0 @@ */

@@ -25,2 +25,3 @@ import { RequestLogicTypes } from '@requestnetwork/types';

* @param currency The currency
* @deprecated Use new Currency().getDecimals() instead
* @returns The number of decimals

@@ -27,0 +28,0 @@ */

20

dist/index.js

@@ -58,23 +58,7 @@ "use strict";

* @param currency The currency
* @deprecated Use new Currency().getDecimals() instead
* @returns The number of decimals
*/
function getDecimalsForCurrency(currency) {
// Return decimals if currency is an ERC20
if (currency.type === types_1.RequestLogicTypes.CURRENCY.ERC20) {
return erc20_1.getErc20Decimals(currency);
}
// Return the number of decimals for ISO-4217 currencies
if (currency.type === types_1.RequestLogicTypes.CURRENCY.ISO4217) {
const iso = iso4217_1.default.find((i) => i.code === currency.value);
if (!iso) {
throw new Error(`Unsupported ISO currency ${currency.value}`);
}
return iso.digits;
}
// other currencies
const otherCurrency = others_1.default[currency.type];
if (!otherCurrency) {
throw new Error(`Currency ${currency.type} not implemented`);
}
return otherCurrency.decimals;
return new currency_1.Currency(currency).getDecimals();
}

@@ -81,0 +65,0 @@ exports.getDecimalsForCurrency = getDecimalsForCurrency;

@@ -16,2 +16,6 @@ import { RequestLogicTypes } from '@requestnetwork/types';

/**
* Override for efficiency
*/
getSymbol(): string;
/**
* Same result as Currency.toString() but with a faster implementation because symbol is known

@@ -18,0 +22,0 @@ */

@@ -27,3 +27,3 @@ "use strict";

const erc20Currencies = erc20_1.getSupportedERC20Tokens();
const currencyFromAddress = erc20Currencies.find((c) => c.address === symbolOrAddress);
const currencyFromAddress = erc20Currencies.find((c) => c.address.toLowerCase() === symbolOrAddress.toLowerCase());
if (!currencyFromAddress) {

@@ -36,2 +36,8 @@ throw new Error(`The currency ${symbolOrAddress} does not exist or is not supported`);

/**
* Override for efficiency
*/
getSymbol() {
return this.symbol;
}
/**
* Same result as Currency.toString() but with a faster implementation because symbol is known

@@ -38,0 +44,0 @@ */

{
"name": "@requestnetwork/currency",
"version": "0.5.1-next.1424+7d55b33f",
"version": "0.5.1-next.1425+77f4fe20",
"publishConfig": {

@@ -44,4 +44,4 @@ "access": "public"

"@metamask/contract-metadata": "1.23.0",
"@requestnetwork/types": "0.32.1-next.1424+7d55b33f",
"@requestnetwork/utils": "0.32.1-next.1424+7d55b33f",
"@requestnetwork/types": "0.32.1-next.1425+77f4fe20",
"@requestnetwork/utils": "0.32.1-next.1425+77f4fe20",
"node-dijkstra": "2.5.0"

@@ -60,3 +60,3 @@ },

},
"gitHead": "7d55b33f905c9107b75c28aa363bd7d3dcc85a36"
"gitHead": "77f4fe2084be0d5dfdfeabb5c267cb45fef80c9f"
}

@@ -16,15 +16,15 @@ # @requestnetwork/currency

import { RequestLogicTypes } from '@requestnetwork/types';
import { getDecimalsForCurrency, getCurrencyHash, Currency, Token } from '@requestnetwork/currency';
import { Currency, Token } from '@requestnetwork/currency';
const decimals = getDecimalsForCurrency({
const decimals = new Currency({
type: RequestLogicTypes.CURRENCY.ETH,
value: 'ETH',
});
}).getDecimals();
console.log(decimals); // 18
const ETHHash = getCurrencyHash({
const ETHHash = new Currency({
type: RequestLogicTypes.CURRENCY.ETH,
value: 'ETH',
});
}).getHash();

@@ -31,0 +31,0 @@ console.log(ETHHash); // 0xF5AF88e117747e87fC5929F2ff87221B1447652E

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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