@reef-defi/api-derive
Version:
Additional polkadot.js derives for Reef Chain
65 lines (52 loc) • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.allCurrencyIds = allCurrencyIds;
exports.allNonNativeCurrencyIds = allNonNativeCurrencyIds;
exports.nativeCurrencyId = nativeCurrencyId;
var _util = require("@polkadot/api-derive/util");
var _rxjs = require("rxjs");
var _operators = require("rxjs/operators");
function getNativeCurrencyId(api) {
return api.rpc.system.properties().pipe((0, _operators.switchMap)(properties => {
const nativeTokenSymbol = properties.tokenSymbol.unwrapOrDefault()[0].toString();
return (0, _rxjs.of)(api.registry.createType('CurrencyId', api.registry.createType('TokenSymbol', nativeTokenSymbol)));
}));
}
/**
* @name nativeCurrencyId
* @returns native currencyId
*/
function nativeCurrencyId(instanceId, api) {
return (0, _util.memo)(instanceId, () => {
return getNativeCurrencyId(api);
});
}
/**
* @name stakingCurrencyId
* @returns staking currencyId in staking pool
*/
function getAllNonNativeCurrencyIds(api) {
return api.consts.transactionPayment.allNonNativeCurrencyIds;
}
/**
* @name allNonNativeCurrencyIds
* @returns all nonnative currencyIds
*/
function allNonNativeCurrencyIds(instanceId, api) {
return (0, _util.memo)(instanceId, () => {
return (0, _rxjs.of)(getAllNonNativeCurrencyIds(api));
});
}
/**
* @name allCurrencyIds
* @returns all currencyIds includes stable curerncyId and all nonnative currencyIds
*/
function allCurrencyIds(instanceId, api) {
return (0, _util.memo)(instanceId, () => {
return getNativeCurrencyId(api).pipe((0, _operators.switchMap)(nativeCurrencyId => {
return (0, _rxjs.of)([nativeCurrencyId, ...getAllNonNativeCurrencyIds(api).slice()]);
}));
});
}