UNPKG

@funded-labs/plug-controller

Version:

Internet Computer Plug wallet's controller

48 lines (47 loc) 2.43 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMultipleCanisterInfo = exports.getCanisterInfo = void 0; const dab_js_1 = require("@funded-labs/dab-js"); const agent_1 = require("@dfinity/agent"); const principal_1 = require("@dfinity/principal"); const constants_1 = require("./dfx/constants"); const wrappedFetch_1 = require("./dfx/wrappedFetch"); const getCanisterInfo = (canisterId, agent, fetch) => __awaiter(void 0, void 0, void 0, function* () { const finalAgent = agent || new agent_1.HttpAgent({ host: constants_1.PLUG_PROXY_HOST, fetch: fetch ? (0, wrappedFetch_1.wrappedFetch)(fetch) : (0, wrappedFetch_1.wrappedFetch)(), }); const result = yield (0, dab_js_1.getCanisterInfo)({ canisterId, agent: finalAgent, }); if (result) return Object.assign(Object.assign({}, result), { icon: result.logo_url }); return undefined; }); exports.getCanisterInfo = getCanisterInfo; const getMultipleCanisterInfo = (canisterIds, agent, fetch) => __awaiter(void 0, void 0, void 0, function* () { const finalAgent = agent || new agent_1.HttpAgent({ host: constants_1.PLUG_PROXY_HOST, fetch: fetch ? (0, wrappedFetch_1.wrappedFetch)(fetch) : (0, wrappedFetch_1.wrappedFetch)(), }); const result = yield (0, dab_js_1.getMultipleCanisterInfo)({ canisterIds: canisterIds.map(id => principal_1.Principal.from(id)), agent: finalAgent, }); if (!result) return []; return result.map(canisterMetadata => (Object.assign(Object.assign({}, canisterMetadata), { icon: canisterMetadata.logo_url }))); }); exports.getMultipleCanisterInfo = getMultipleCanisterInfo;