@alexkeating/common-utilities
Version:
Our **Common Utilities** package is a set of helper tools and utilities that are used throughout our libraries and apps. This includes things like our constants, types that are commonly shared across packages, and various utilities and helper functions.
50 lines • 1.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addKeychain = exports.getNetworkName = exports.getNetwork = exports.NETWORK_DATA = exports.isValidNetwork = exports.VALID_NETWORKS = void 0;
const utils_1 = require("../utils");
exports.VALID_NETWORKS = {
'0x1': true,
'0x5': true,
'0x64': true,
'0xa': true,
'0x89': true,
'0xa4b1': true,
'0xa4ec': true,
};
const isValidNetwork = (str, networks) => (0, utils_1.isString)(str) && networks
? networks[str] !== undefined
: exports.VALID_NETWORKS[str] !== undefined;
exports.isValidNetwork = isValidNetwork;
exports.NETWORK_DATA = {
'0x5': {
chainId: '0x5',
networkId: 5,
name: 'Goerli',
symbol: 'ETH',
tokenDecimals: 18,
},
};
const getNetwork = (chainId) => {
if (!(0, exports.isValidNetwork)(chainId)) {
return null;
}
return exports.NETWORK_DATA[chainId];
};
exports.getNetwork = getNetwork;
const getNetworkName = (chainId) => {
var _a;
return ((_a = (0, exports.getNetwork)(chainId)) === null || _a === void 0 ? void 0 : _a.name) || null;
};
exports.getNetworkName = getNetworkName;
const addKeychain = (keychain, property, networkList = exports.NETWORK_DATA) => {
return Object.values(networkList).reduce((acc, networkObj) => {
const { chainId } = networkObj;
if (!(0, exports.isValidNetwork)(chainId)) {
console.warn(`Invalid network: ${chainId}`);
return acc;
}
return Object.assign(Object.assign({}, acc), { [chainId]: Object.assign(Object.assign({}, networkObj), { [property]: keychain[chainId] }) });
}, {});
};
exports.addKeychain = addKeychain;
//# sourceMappingURL=chainData.js.map