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

@xchainjs/xchain-util

Package Overview
Dependencies
Maintainers
10
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xchainjs/xchain-util - npm Package Compare versions

Comparing version 0.13.2 to 0.13.3

5

lib/asset.d.ts

@@ -163,3 +163,6 @@ import BigNumber from 'bignumber.js';

ETH = "\u039E",
USD = "$"
USD = "$",
DASH = "\u0110",
LTC = "\u0141",
DOGE = "\u00D0"
}

@@ -166,0 +169,0 @@ /**

@@ -0,1 +1,4 @@

/**
* Utility class for caching stable data
*/
export declare class CachedValue<T> {

@@ -7,5 +10,18 @@ private cachedValue;

private refreshPromise;
/**
* @constructor
* @param refreshData function that refresh and return the data
* @param {number|undefined} cacheMaxAge time in millisecond to expire cache
*/
constructor(refreshData: (params?: any) => Promise<T>, cacheMaxAge?: number);
/**
* @private
* Validates if internal cache is valid or expired
*/
private isCacheValid;
/**
* Returns cached data if valid or request fresh data if cache is invalid
* @param params use this params to request data if cache is expired
*/
getValue(params?: any): Promise<T>;
}

41

lib/index.esm.js

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

AssetCurrencySymbol["USD"] = "$";
AssetCurrencySymbol["DASH"] = "\u0110";
AssetCurrencySymbol["LTC"] = "\u0141";
AssetCurrencySymbol["DOGE"] = "\u00D0";
})(AssetCurrencySymbol || (AssetCurrencySymbol = {}));

@@ -378,3 +381,9 @@ /**

return AssetCurrencySymbol.ETH;
case ticker.includes('USD') || ticker.includes('UST'):
case ticker === 'DASH':
return AssetCurrencySymbol.DASH;
case ticker === 'LTC':
return AssetCurrencySymbol.LTC;
case ticker === 'DOGE':
return AssetCurrencySymbol.DOGE;
case ticker.includes('USD'):
return AssetCurrencySymbol.USD;

@@ -411,3 +420,3 @@ default:

let regex = new RegExp(AssetBTC.ticker, 'i');
if (ticker.match(new RegExp(AssetBTC.ticker, 'i'))) {
if (ticker.match(regex)) {
const base = assetToBase(amount);

@@ -424,2 +433,14 @@ // format all < ₿ 0.01 in statoshi

return `${AssetCurrencySymbol.ETH} ${amountFormatted}`;
// LTC
regex = new RegExp('LTC', 'i');
if (ticker.match(regex))
return `${AssetCurrencySymbol.LTC} ${amountFormatted}`;
// DASH
regex = new RegExp('DASH', 'i');
if (ticker.match(regex))
return `${AssetCurrencySymbol.DASH} ${amountFormatted}`;
// DOGE
regex = new RegExp('DOGE', 'i');
if (ticker.match(regex))
return `${AssetCurrencySymbol.DOGE} ${amountFormatted}`;
// USD

@@ -618,3 +639,11 @@ regex = new RegExp('USD', 'i');

/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Utility class for caching stable data
*/
class CachedValue {
/**
* @constructor
* @param refreshData function that refresh and return the data
* @param {number|undefined} cacheMaxAge time in millisecond to expire cache
*/
constructor(refreshData, cacheMaxAge) {

@@ -625,5 +654,13 @@ this.refreshPromise = null;

}
/**
* @private
* Validates if internal cache is valid or expired
*/
isCacheValid() {
return Boolean(this.cacheTimestamp && new Date().getTime() - this.cacheTimestamp.getTime() < this.cacheMaxAge);
}
/**
* Returns cached data if valid or request fresh data if cache is invalid
* @param params use this params to request data if cache is expired
*/
getValue(params) {

@@ -630,0 +667,0 @@ return __awaiter(this, void 0, void 0, function* () {

@@ -370,2 +370,5 @@ 'use strict';

AssetCurrencySymbol["USD"] = "$";
AssetCurrencySymbol["DASH"] = "\u0110";
AssetCurrencySymbol["LTC"] = "\u0141";
AssetCurrencySymbol["DOGE"] = "\u00D0";
})(exports.AssetCurrencySymbol || (exports.AssetCurrencySymbol = {}));

@@ -386,3 +389,9 @@ /**

return exports.AssetCurrencySymbol.ETH;
case ticker.includes('USD') || ticker.includes('UST'):
case ticker === 'DASH':
return exports.AssetCurrencySymbol.DASH;
case ticker === 'LTC':
return exports.AssetCurrencySymbol.LTC;
case ticker === 'DOGE':
return exports.AssetCurrencySymbol.DOGE;
case ticker.includes('USD'):
return exports.AssetCurrencySymbol.USD;

@@ -419,3 +428,3 @@ default:

let regex = new RegExp(AssetBTC.ticker, 'i');
if (ticker.match(new RegExp(AssetBTC.ticker, 'i'))) {
if (ticker.match(regex)) {
const base = assetToBase(amount);

@@ -432,2 +441,14 @@ // format all < ₿ 0.01 in statoshi

return `${exports.AssetCurrencySymbol.ETH} ${amountFormatted}`;
// LTC
regex = new RegExp('LTC', 'i');
if (ticker.match(regex))
return `${exports.AssetCurrencySymbol.LTC} ${amountFormatted}`;
// DASH
regex = new RegExp('DASH', 'i');
if (ticker.match(regex))
return `${exports.AssetCurrencySymbol.DASH} ${amountFormatted}`;
// DOGE
regex = new RegExp('DOGE', 'i');
if (ticker.match(regex))
return `${exports.AssetCurrencySymbol.DOGE} ${amountFormatted}`;
// USD

@@ -626,3 +647,11 @@ regex = new RegExp('USD', 'i');

/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Utility class for caching stable data
*/
class CachedValue {
/**
* @constructor
* @param refreshData function that refresh and return the data
* @param {number|undefined} cacheMaxAge time in millisecond to expire cache
*/
constructor(refreshData, cacheMaxAge) {

@@ -633,5 +662,13 @@ this.refreshPromise = null;

}
/**
* @private
* Validates if internal cache is valid or expired
*/
isCacheValid() {
return Boolean(this.cacheTimestamp && new Date().getTime() - this.cacheTimestamp.getTime() < this.cacheMaxAge);
}
/**
* Returns cached data if valid or request fresh data if cache is invalid
* @param params use this params to request data if cache is expired
*/
getValue(params) {

@@ -638,0 +675,0 @@ return __awaiter(this, void 0, void 0, function* () {

{
"name": "@xchainjs/xchain-util",
"version": "0.13.2",
"version": "0.13.3",
"description": "Helper utilities for XChain clients",

@@ -27,3 +27,3 @@ "keywords": [

"scripts": {
"clean": "rimraf lib/**",
"clean": "rimraf --glob ./lib/**",
"build": "yarn clean && rollup -c",

@@ -43,2 +43,2 @@ "test": "jest",

}
}
}

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