"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { WalletManagerPlugin: () => WalletManagerPlugin, useWallet: () => useWallet }); module.exports = __toCommonJS(src_exports); __reExport(src_exports, require("avm-wallet"), module.exports); // src/walletManagerPlugin.ts var import_avm_wallet = require("avm-wallet"); var import_vue = require("vue"); var WalletManagerPlugin = { install(app, options) { const manager = new import_avm_wallet.WalletManager(options); const avmAlgodClient = (0, import_vue.ref)(manager.avmAlgodClient); const setAVMAlgodClient = (client) => { avmAlgodClient.value = client; manager.avmAlgodClient = client; }; app.provide("avmWalletManager", manager); app.provide("avmAlgodClient", avmAlgodClient); app.provide("setAVMAlgodClient", setAVMAlgodClient); manager.resumeSessions().catch((error) => { console.error("Error resuming sessions:", error); }); } }; // src/useWallet.ts var import_vue_store = require("@tanstack/vue-store"); var import_avm_wallet2 = require("avm-wallet"); var import_algosdk = __toESM(require("algosdk"), 1); var import_vue2 = require("vue"); function useWallet() { const manager = (0, import_vue2.inject)("avmWalletManager"); const avmAlgodClient = (0, import_vue2.inject)("avmAlgodClient"); const setAVMAlgodClient = (0, import_vue2.inject)("setAVMAlgodClient"); if (!manager) { throw new Error("WalletManager plugin is not properly installed"); } if (!avmAlgodClient || !setAVMAlgodClient) { throw new Error("Algod client or setter not properly installed"); } const activeNetwork = (0, import_vue_store.useStore)(manager.store, (state) => state.activeNetwork); const setActiveNetwork = async (networkId) => { if (networkId === activeNetwork.value) { return; } console.info(`[Vue] Creating Algodv2 client for ${networkId}...`); const { token, baseServer, port, headers } = manager.networkConfig[networkId]; const newClient = new import_algosdk.default.Algodv2(token, baseServer, port, headers); setAVMAlgodClient(newClient); manager.store.setState((state) => ({ ...state, activeNetwork: networkId })); console.info(`[Vue] \u2705 Active network set to ${networkId}.`); }; const walletAVMStateMap = (0, import_vue_store.useStore)(manager.store, (state) => state.wallets); const avmActiveWalletId = (0, import_vue_store.useStore)(manager.store, (state) => state.avmActiveWallet); const wallets = (0, import_vue2.computed)(() => { return [...manager.wallets.values()].map((wallet) => { const walletAVMState = walletAVMStateMap.value[wallet.id]; return { id: wallet.id, metadata: wallet.metadata, accounts: walletAVMState?.accounts ?? [], activeAccount: walletAVMState?.activeAccount ?? null, isConnected: !!walletAVMState, isActive: wallet.id === avmActiveWalletId.value, connect: (args) => wallet.connect(args), disconnect: () => wallet.disconnect(), setActive: () => wallet.setActive(), setActiveAccount: (addr) => wallet.setActiveAccount(addr) }; }); }); const avmActiveWallet = (0, import_vue2.computed)(() => { return avmActiveWalletId.value ? manager.getWallet(avmActiveWalletId.value) || null : null; }); const avmActiveWalletAVMState = (0, import_vue2.computed)(() => { const wallet = avmActiveWallet.value; return wallet ? walletAVMStateMap.value[wallet.id] || null : null; }); const avmActiveWalletAccounts = (0, import_vue2.computed)(() => { return avmActiveWalletAVMState.value?.accounts ?? null; }); const avmActiveWalletAddresses = (0, import_vue2.computed)(() => { return avmActiveWalletAccounts.value?.map((account) => account.address) ?? null; }); const activeAccount = (0, import_vue2.computed)(() => { return avmActiveWalletAVMState.value?.activeAccount ?? null; }); const activeAddress = (0, import_vue2.computed)(() => { return activeAccount.value?.address ?? null; }); const signTransactions = (txnGroup, indexesToSign) => { if (!avmActiveWallet.value) { throw new Error("No active wallet"); } return avmActiveWallet.value.signTransactions(txnGroup, indexesToSign); }; const transactionSigner = (txnGroup, indexesToSign) => { if (!avmActiveWallet.value) { throw new Error("No active wallet"); } return avmActiveWallet.value.transactionSigner(txnGroup, indexesToSign); }; return { wallets, avmAlgodClient: (0, import_vue2.computed)(() => { if (!avmAlgodClient.value) { throw new Error("Algod client is undefined"); } return avmAlgodClient.value; }), activeNetwork, avmActiveWallet, avmActiveWalletAccounts, avmActiveWalletAddresses, activeAccount, activeAddress, setActiveNetwork, setAVMAlgodClient, signTransactions, transactionSigner }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { WalletManagerPlugin, useWallet, ...require("avm-wallet") }); //# sourceMappingURL=index.cjs.map