UNPKG

cosmic-lib

Version:

A JavaScript implementation of the CosmicLink protocol for Stellar

97 lines (80 loc) 2.67 kB
"use strict"; /** * Library-wide configuration. * * @borrows module:aliases.all as aliases * @borrows module:aliases.set as addAliases * @borrows module:aliases.remove as removeAliases * * @borrows module:event.defaultClickHandlers as clickHandlers * @borrows module:event.setClickHandler as setClickHandler * @borrows module:event.clearClickHandler as clearClickHandler * * @exports config */ var config = exports; var aliases = require("@cosmic-plus/base/es5/aliases"); var env = require("@cosmic-plus/jsutils/es5/env"); var StellarSdk = require("@cosmic-plus/base/es5/stellar-sdk"); var event = env.isBrowser && require("./event"); /** * The base URI to build cosmic links. * @default 'https://cosmic.link/' */ config.page = "https://cosmic.link/"; /** * The default fallback network. * @default 'public' */ config.network = "public"; /** * The default fallback source address. * @default undefined */ config.source = undefined; /** * Networks setup. * * @private */ config.current = { passphrase: {}, horizon: {}, server: {} }; /** * Set default **passphrase** and **horizon** URL for network **name**. * * Adding custom network this way will enable the use of their name in cosmic * queries (as in `&network=name`). However, please remind that this feature * will works only on your side and could break compatibility with other * services. * * @example * cosmicLib.config.setupNetwork('public', 'https://my-own-horizon-instance.example.org') * cosmicLib.config.setupNetwork('custom', 'https://custom-horizon.example.org', 'My Custom Passphrase') * * @param {string} name Network name (like 'public', 'test') * @param {string} horizon Horizon URL * @param {string} [passphrase] Network passphrase */ config.setupNetwork = function (name, horizon, passphrase) { if (passphrase) config.current.passphrase[name] = passphrase;else passphrase = config.current.passphrase[name]; config.current.horizon[passphrase] = horizon; }; config.setupNetwork("public", "https://horizon.stellar.org", StellarSdk.Networks.PUBLIC); config.setupNetwork("test", "https://horizon-testnet.stellar.org", StellarSdk.Networks.TESTNET); config.aliases = aliases.all; config.addAliases = function (definitions) { return aliases.set(config, definitions); }; config.removeAliases = function (array) { return aliases.remove(config, array); }; config.clickHandlers = event.defaultClickHandlers; config.setClickHandler = function (fieldType, callback) { return event.setClickHandler(config, fieldType, callback); }; config.clearClickHandler = function (fieldType) { return event.clearClickHandler(config, fieldType); };