Socket
Socket
Sign inDemoInstall

@xchainjs/xchain-util

Package Overview
Dependencies
Maintainers
0
Versions
39
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 1.0.2 to 1.0.3

17

lib/asset.d.ts

@@ -160,19 +160,2 @@ import BigNumber from 'bignumber.js';

export declare const isTokenAsset: (asset: AnyAsset) => asset is TokenAsset;
/**
* Creates an `Asset` by a given string
*
* This helper function expects a string with following naming convention:
* `AAA.BBB-CCC`
* where
* chain: `AAA`
* ticker (optional): `BBB`
* symbol: `BBB-CCC` or `CCC` (if no ticker available)
*
* @see https://docs.thorchain.org/developers/transaction-memos#asset-notation
*
* If the naming convention fails, it returns null
*
* @param {string} s The given string.
* @returns {Asset|null} The asset from the given string.
*/
export declare const assetFromString: (s: string) => AnyAsset | null;

@@ -179,0 +162,0 @@ /**

37

lib/index.esm.js

@@ -344,6 +344,14 @@ import BigNumber from 'bignumber.js';

*/
const assetConfigs = new Map([
['KUJI.USK', { chain: 'KUJI', symbol: 'USK', ticker: 'USK', type: AssetType.TOKEN }],
['MAYA.MAYA', { chain: 'MAYA', symbol: 'MAYA', ticker: 'MAYA', type: AssetType.TOKEN }],
]);
const createAsset = (chain, symbol, ticker, type) => {
return { chain, symbol, ticker, type };
};
const assetFromString = (s) => {
var _a, _b;
if (s === 'KUJI.USK')
return { chain: 'KUJI', symbol: 'USK', ticker: 'USK', type: AssetType.TOKEN }; // TODO: Find a better way to avoid hardcoding
var _a;
const directAsset = assetConfigs.get(s);
if (directAsset)
return directAsset;
const isSynth = s.includes(SYNTH_ASSET_DELIMITER);

@@ -353,21 +361,12 @@ const isTrade = s.includes(TRADE_ASSET_DELIMITER);

const data = s.split(delimiter);
if (data.length <= 1 || ((_a = data[1]) === null || _a === void 0 ? void 0 : _a.length) < 1) {
if (data.length <= 1 || !data[1])
return null;
}
const chain = data[0];
// filter out not supported string of chains
if (!chain)
return null;
const symbol = data[1];
const chain = data[0].trim();
const symbol = data[1].trim();
const ticker = symbol.split('-')[0];
const isToken = ((_b = symbol.split('-')[1]) === null || _b === void 0 ? void 0 : _b.length) > 1;
if (!symbol)
const isToken = ((_a = symbol.split('-')[1]) === null || _a === void 0 ? void 0 : _a.length) > 1;
if (!symbol || !chain)
return null;
if (isSynth)
return { chain, symbol, ticker, type: AssetType.SYNTH };
if (isTrade)
return { chain, symbol, ticker, type: AssetType.TRADE };
if (isToken)
return { chain, symbol, ticker, type: AssetType.TOKEN };
return { chain, symbol, ticker, type: AssetType.NATIVE };
const type = isSynth ? AssetType.SYNTH : isTrade ? AssetType.TRADE : isToken ? AssetType.TOKEN : AssetType.NATIVE;
return createAsset(chain, symbol, ticker, type);
};

@@ -374,0 +373,0 @@ /**

@@ -352,6 +352,14 @@ 'use strict';

*/
const assetConfigs = new Map([
['KUJI.USK', { chain: 'KUJI', symbol: 'USK', ticker: 'USK', type: exports.AssetType.TOKEN }],
['MAYA.MAYA', { chain: 'MAYA', symbol: 'MAYA', ticker: 'MAYA', type: exports.AssetType.TOKEN }],
]);
const createAsset = (chain, symbol, ticker, type) => {
return { chain, symbol, ticker, type };
};
const assetFromString = (s) => {
var _a, _b;
if (s === 'KUJI.USK')
return { chain: 'KUJI', symbol: 'USK', ticker: 'USK', type: exports.AssetType.TOKEN }; // TODO: Find a better way to avoid hardcoding
var _a;
const directAsset = assetConfigs.get(s);
if (directAsset)
return directAsset;
const isSynth = s.includes(SYNTH_ASSET_DELIMITER);

@@ -361,21 +369,12 @@ const isTrade = s.includes(TRADE_ASSET_DELIMITER);

const data = s.split(delimiter);
if (data.length <= 1 || ((_a = data[1]) === null || _a === void 0 ? void 0 : _a.length) < 1) {
if (data.length <= 1 || !data[1])
return null;
}
const chain = data[0];
// filter out not supported string of chains
if (!chain)
return null;
const symbol = data[1];
const chain = data[0].trim();
const symbol = data[1].trim();
const ticker = symbol.split('-')[0];
const isToken = ((_b = symbol.split('-')[1]) === null || _b === void 0 ? void 0 : _b.length) > 1;
if (!symbol)
const isToken = ((_a = symbol.split('-')[1]) === null || _a === void 0 ? void 0 : _a.length) > 1;
if (!symbol || !chain)
return null;
if (isSynth)
return { chain, symbol, ticker, type: exports.AssetType.SYNTH };
if (isTrade)
return { chain, symbol, ticker, type: exports.AssetType.TRADE };
if (isToken)
return { chain, symbol, ticker, type: exports.AssetType.TOKEN };
return { chain, symbol, ticker, type: exports.AssetType.NATIVE };
const type = isSynth ? exports.AssetType.SYNTH : isTrade ? exports.AssetType.TRADE : isToken ? exports.AssetType.TOKEN : exports.AssetType.NATIVE;
return createAsset(chain, symbol, ticker, type);
};

@@ -382,0 +381,0 @@ /**

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

@@ -5,0 +5,0 @@ "keywords": [

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