@exodus/assets
Advanced tools
Comparing version 8.0.94 to 8.0.95
426
lib/index.js
@@ -6,47 +6,161 @@ "use strict"; | ||
}); | ||
var _exportNames = { | ||
combinedAssets: true, | ||
coerceTokenProps: true, | ||
assetsListToObject: true, | ||
connectAssetsList: true, | ||
connectAsset: true, | ||
connectAssets: true, | ||
connectCombinedAssets: true, | ||
addToken: true, | ||
updateToken: true, | ||
addNetwork: true, | ||
addCombinedAsset: true, | ||
updateCombinedAsset: true | ||
}; | ||
exports.addCombinedAsset = addCombinedAsset; | ||
exports.addNetwork = addNetwork; | ||
exports.addToken = addToken; | ||
exports.assetsListToObject = assetsListToObject; | ||
exports.coerceTokenProps = coerceTokenProps; | ||
Object.defineProperty(exports, "CT_ALL_STATUSES", { | ||
enumerable: true, | ||
get: function () { | ||
return _constants.CT_ALL_STATUSES; | ||
} | ||
}); | ||
Object.defineProperty(exports, "CT_DEFAULT_SERVER", { | ||
enumerable: true, | ||
get: function () { | ||
return _constants.CT_DEFAULT_SERVER; | ||
} | ||
}); | ||
Object.defineProperty(exports, "CT_STATUS", { | ||
enumerable: true, | ||
get: function () { | ||
return _constants.CT_STATUS; | ||
} | ||
}); | ||
Object.defineProperty(exports, "CT_UPDATEABLE_PROPERTIES", { | ||
enumerable: true, | ||
get: function () { | ||
return _constants.CT_UPDATEABLE_PROPERTIES; | ||
} | ||
}); | ||
Object.defineProperty(exports, "addCombinedAsset", { | ||
enumerable: true, | ||
get: function () { | ||
return _connectAssets.addCombinedAsset; | ||
} | ||
}); | ||
Object.defineProperty(exports, "addNetwork", { | ||
enumerable: true, | ||
get: function () { | ||
return _connectAssets.addNetwork; | ||
} | ||
}); | ||
Object.defineProperty(exports, "addToken", { | ||
enumerable: true, | ||
get: function () { | ||
return _connectAssets.addToken; | ||
} | ||
}); | ||
Object.defineProperty(exports, "assert", { | ||
enumerable: true, | ||
get: function () { | ||
return _validateAsset.assert; | ||
} | ||
}); | ||
Object.defineProperty(exports, "assertNotAnObjectPrototypeProperty", { | ||
enumerable: true, | ||
get: function () { | ||
return _validateAsset.assertNotAnObjectPrototypeProperty; | ||
} | ||
}); | ||
Object.defineProperty(exports, "assetsListToObject", { | ||
enumerable: true, | ||
get: function () { | ||
return _connectAssets.assetsListToObject; | ||
} | ||
}); | ||
Object.defineProperty(exports, "coerceTokenProps", { | ||
enumerable: true, | ||
get: function () { | ||
return _connectAssets.coerceTokenProps; | ||
} | ||
}); | ||
exports.combinedAssets = void 0; | ||
exports.connectAsset = connectAsset; | ||
exports.connectAssets = connectAssets; | ||
exports.connectAssetsList = connectAssetsList; | ||
exports.connectCombinedAssets = connectCombinedAssets; | ||
Object.defineProperty(exports, "connectAsset", { | ||
enumerable: true, | ||
get: function () { | ||
return _connectAssets.connectAsset; | ||
} | ||
}); | ||
Object.defineProperty(exports, "connectAssets", { | ||
enumerable: true, | ||
get: function () { | ||
return _connectAssets.connectAssets; | ||
} | ||
}); | ||
Object.defineProperty(exports, "connectAssetsList", { | ||
enumerable: true, | ||
get: function () { | ||
return _connectAssets.connectAssetsList; | ||
} | ||
}); | ||
Object.defineProperty(exports, "connectCombinedAssets", { | ||
enumerable: true, | ||
get: function () { | ||
return _connectAssets.connectCombinedAssets; | ||
} | ||
}); | ||
Object.defineProperty(exports, "createAssetRegistry", { | ||
enumerable: true, | ||
get: function () { | ||
return _createAssetsRegistry.default; | ||
} | ||
}); | ||
exports.default = void 0; | ||
exports.updateCombinedAsset = updateCombinedAsset; | ||
exports.updateToken = updateToken; | ||
Object.defineProperty(exports, "updateCombinedAsset", { | ||
enumerable: true, | ||
get: function () { | ||
return _connectAssets.updateCombinedAsset; | ||
} | ||
}); | ||
Object.defineProperty(exports, "updateToken", { | ||
enumerable: true, | ||
get: function () { | ||
return _connectAssets.updateToken; | ||
} | ||
}); | ||
Object.defineProperty(exports, "validateAsset", { | ||
enumerable: true, | ||
get: function () { | ||
return _validateAsset.validateAsset; | ||
} | ||
}); | ||
Object.defineProperty(exports, "validateBaseAsset", { | ||
enumerable: true, | ||
get: function () { | ||
return _validateAsset.validateBaseAsset; | ||
} | ||
}); | ||
Object.defineProperty(exports, "validateBaseAssetDef", { | ||
enumerable: true, | ||
get: function () { | ||
return _validateAsset.validateBaseAssetDef; | ||
} | ||
}); | ||
Object.defineProperty(exports, "validateCombinedAsset", { | ||
enumerable: true, | ||
get: function () { | ||
return _validateAsset.validateCombinedAsset; | ||
} | ||
}); | ||
Object.defineProperty(exports, "validateCombinedAssetDef", { | ||
enumerable: true, | ||
get: function () { | ||
return _validateAsset.validateCombinedAssetDef; | ||
} | ||
}); | ||
Object.defineProperty(exports, "validateToken", { | ||
enumerable: true, | ||
get: function () { | ||
return _validateAsset.validateToken; | ||
} | ||
}); | ||
Object.defineProperty(exports, "validateTokenDef", { | ||
enumerable: true, | ||
get: function () { | ||
return _validateAsset.validateTokenDef; | ||
} | ||
}); | ||
var _basicUtils = require("@exodus/basic-utils"); | ||
var _assetsBase = _interopRequireDefault(require("@exodus/assets-base")); | ||
var _combinedAssetsMeta = _interopRequireWildcard(require("@exodus/combined-assets-meta")); | ||
var _currency = require("@exodus/currency"); | ||
var _combinedAssetsMeta = _interopRequireDefault(require("@exodus/combined-assets-meta")); | ||
var _connectAssets = require("./connect-assets"); | ||
var _validateAsset = require("./validate-asset"); | ||
Object.keys(_validateAsset).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
if (key in exports && exports[key] === _validateAsset[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _validateAsset[key]; | ||
} | ||
}); | ||
}); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var _constants = require("./constants"); | ||
var _createAssetsRegistry = _interopRequireDefault(require("./create-assets-registry")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -57,233 +171,3 @@ const combinedAssets = (0, _basicUtils.keyBy)(_combinedAssetsMeta.default, ({ | ||
exports.combinedAssets = combinedAssets; | ||
const connectProp = (asset, prop, value) => { | ||
if (asset[prop] === undefined && value !== undefined) asset[prop] = value; | ||
}; | ||
const defineAssetProps = ({ | ||
assets, | ||
asset | ||
}) => { | ||
Object.defineProperties(asset, { | ||
baseAsset: { | ||
get() { | ||
return assets[asset.baseAssetName || asset.name]; | ||
}, | ||
enumerable: true | ||
}, | ||
feeAsset: { | ||
get() { | ||
return assets[asset.feeAssetName || asset.baseAssetName || asset.name]; | ||
}, | ||
enumerable: true | ||
} | ||
}); | ||
if (asset.isCombined) { | ||
const combinedAssetNames = asset.combinedAssetNames.filter(assetName => assets[assetName]); | ||
Object.defineProperties(asset, { | ||
combinedAssetNames: { | ||
get() { | ||
return combinedAssetNames; | ||
}, | ||
enumerable: true | ||
} | ||
}); | ||
Object.defineProperties(asset, { | ||
combinedAssets: { | ||
get() { | ||
return combinedAssetNames.map(assetName => assets[assetName]); | ||
}, | ||
enumerable: true | ||
} | ||
}); | ||
} | ||
asset.isBuiltIn = !!(_assetsBase.default[asset.name] || combinedAssets[asset.name]); | ||
if (!asset.isBuiltIn || ['bcashclaim', 'bgoldclaim', 'bitcoinsvclaim'].includes(asset.name)) { | ||
coerceTokenProps(asset, asset.baseAsset); | ||
} | ||
}; | ||
function coerceTokenProps(asset, baseAsset) { | ||
const { | ||
units, | ||
properName, | ||
properTicker, | ||
displayName, | ||
displayTicker, | ||
ticker, | ||
color | ||
} = asset; | ||
connectProp(asset, 'currency', _currency.UnitType.create(units)); | ||
connectProp(asset, 'displayName', properName); | ||
connectProp(asset, 'displayTicker', properTicker); | ||
connectProp(asset, 'properName', displayName); | ||
connectProp(asset, 'properTicker', displayTicker || ticker); | ||
connectProp(asset, 'primaryColor', color || '#FFFFFF'); | ||
connectProp(asset, 'chainBadgeColors', baseAsset.chainBadgeColors); | ||
connectProp(asset, 'displayNetworkName', baseAsset.displayNetworkName || baseAsset.displayName); | ||
connectProp(asset, 'displayNetworkTicker', baseAsset.displayNetworkTicker || baseAsset.displayTicker); | ||
connectProp(asset, 'blockExplorer', baseAsset.blockExplorer); | ||
connectProp(asset, 'gradientCoords', { | ||
x1: '0%', | ||
y1: '0%', | ||
x2: '100%', | ||
y2: '100%' | ||
}); | ||
connectProp(asset, 'gradientColors', ['#EAEAEA', '#FFF']); | ||
return asset; | ||
} | ||
function assetsListToObject(assetsList) { | ||
return (0, _basicUtils.keyBy)(assetsList, ({ | ||
name | ||
}) => name); | ||
} | ||
function connectAssetsList(assetsList) { | ||
return connectAssets(assetsListToObject(assetsList)); | ||
} | ||
function connectAsset(asset) { | ||
return connectAssets({ | ||
[asset.name]: asset | ||
})[asset.name]; | ||
} | ||
function connectAssets(assets) { | ||
const _assets = (0, _basicUtils.mapValues)(assets, v => ({ | ||
...v | ||
})); | ||
Object.values(_assets).forEach(asset => defineAssetProps({ | ||
assets: _assets, | ||
asset | ||
})); | ||
return _assets; | ||
} | ||
function connectCombinedAssets({ | ||
combinedAssets, | ||
assets | ||
}) { | ||
const _combinedAssets = (0, _basicUtils.mapValues)(combinedAssets, v => ({ | ||
...v | ||
})); | ||
const _assets = { | ||
..._combinedAssets, | ||
...assets | ||
}; | ||
Object.values(_combinedAssets).forEach(asset => defineAssetProps({ | ||
assets: _assets, | ||
asset | ||
})); | ||
return _combinedAssets; | ||
} | ||
function addToken(assets, assetDef) { | ||
const { | ||
name, | ||
baseAssetName, | ||
info = {} | ||
} = assetDef; | ||
(0, _validateAsset.assertNotAnObjectPrototypeProperty)(name); | ||
(0, _validateAsset.assert)(name && !assets[name], `token ${name} already in registry`); | ||
(0, _validateAsset.assertNotAnObjectPrototypeProperty)(baseAssetName); | ||
(0, _validateAsset.assert)(baseAssetName && assets[baseAssetName], `base asset ${baseAssetName} not found for token ${name}`); | ||
(0, _validateAsset.assert)(name !== baseAssetName, `token ${name} must be distinct from base asset`); | ||
const asset = { | ||
...assetDef, | ||
toString: () => name, | ||
info | ||
}; | ||
(0, _validateAsset.validateTokenDef)(asset); | ||
defineAssetProps({ | ||
assets, | ||
asset | ||
}); | ||
assets[name] = asset; | ||
return asset; | ||
} | ||
function updateToken(assets, assetUpdate, updateableProps) { | ||
const { | ||
name | ||
} = assetUpdate; | ||
(0, _validateAsset.assertNotAnObjectPrototypeProperty)(name); | ||
(0, _validateAsset.assert)(name && assets[name], `token ${name} not in the registry`); | ||
(0, _validateAsset.assert)(name !== assets[name].baseAssetName, `token ${name} must be distinct from base asset`); | ||
(0, _validateAsset.assert)(updateableProps, 'expected `updateableProps`'); | ||
const asset = { | ||
...assets[name], | ||
...(0, _basicUtils.pick)(assetUpdate, updateableProps) | ||
}; | ||
(0, _validateAsset.validateTokenDef)(asset); | ||
assets[name] = asset; | ||
return asset; | ||
} | ||
function addNetwork(assets, baseAssetDef, tokenDefs = []) { | ||
const { | ||
name, | ||
info = {} | ||
} = baseAssetDef; | ||
(0, _validateAsset.assert)(!assets[name], `asset ${name} already exists`); | ||
const asset = { | ||
...baseAssetDef, | ||
toString: () => name, | ||
info | ||
}; | ||
(0, _validateAsset.validateBaseAssetDef)(asset); | ||
try { | ||
assets[name] = asset; | ||
defineAssetProps({ | ||
assets, | ||
asset | ||
}); | ||
} catch (e) { | ||
delete assets[name]; | ||
throw e; | ||
} | ||
tokenDefs.forEach(token => addToken(assets, token)); | ||
} | ||
function addCombinedAsset(assets, assetDef) { | ||
const { | ||
name, | ||
baseAssetName | ||
} = assetDef; | ||
(0, _validateAsset.assertNotAnObjectPrototypeProperty)(name); | ||
(0, _validateAsset.assert)(name && !assets[name], `combined asset ${name} already in registry`); | ||
(0, _validateAsset.assertNotAnObjectPrototypeProperty)(baseAssetName); | ||
(0, _validateAsset.assert)(baseAssetName && name === baseAssetName, `combined asset ${name} invalid`); | ||
const asset = (0, _combinedAssetsMeta.createCombined)(assetDef, assets); | ||
try { | ||
assets[name] = asset; | ||
defineAssetProps({ | ||
assets, | ||
asset | ||
}); | ||
(0, _validateAsset.validateCombinedAsset)(asset); | ||
} catch (e) { | ||
delete assets[name]; | ||
throw e; | ||
} | ||
return asset; | ||
} | ||
function updateCombinedAsset(assets, combinedAsset, { | ||
newMemberAsset | ||
} = {}) { | ||
const { | ||
name, | ||
isCombined | ||
} = combinedAsset; | ||
(0, _validateAsset.assert)(isCombined, `asset ${name} must be a combined asset`); | ||
(0, _validateAsset.assertNotAnObjectPrototypeProperty)(name); | ||
(0, _validateAsset.assert)(assets[name], `combined asset ${name} does not exist`); | ||
(0, _validateAsset.assert)(assets[newMemberAsset.name], `asset ${newMemberAsset.name} does not exist`); | ||
(0, _validateAsset.assert)(!newMemberAsset.isCombined, `asset ${newMemberAsset.name} must not be a combined asset`); | ||
const assetDef = (0, _basicUtils.omit)(combinedAsset, ['baseAsset', 'feeAsset', 'combinedAssets']); | ||
assetDef.combinedAssetNames.push(newMemberAsset.name); | ||
const asset = (0, _combinedAssetsMeta.createCombined)(assetDef, assets); | ||
const orig = assets[name]; | ||
try { | ||
assets[name] = asset; | ||
defineAssetProps({ | ||
assets, | ||
asset | ||
}); | ||
(0, _validateAsset.validateCombinedAsset)(asset); | ||
} catch (e) { | ||
assets[name] = orig; | ||
throw e; | ||
} | ||
return asset; | ||
} | ||
var _default = connectAssets({ | ||
var _default = (0, _connectAssets.connectAssets)({ | ||
...combinedAssets, | ||
@@ -290,0 +174,0 @@ ..._assetsBase.default |
{ | ||
"name": "@exodus/assets", | ||
"version": "8.0.94", | ||
"version": "8.0.95", | ||
"description": "Exodus assets", | ||
@@ -36,3 +36,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "d33d238f9283e240a71b1fa40e3bbdf66832f436" | ||
"gitHead": "fd8431e0450689dd0a9370172bdcb61fb2160e1f" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20946
7
570
1