import QRCode from "qrcode";
import { EventBus } from "../../../utils/EventBus";
import { WalletConnectEventsEnum } from "./wallet-connect-modal.types";
export class WalletConnectBase {
    constructor(data) {
        this.data = data;
        this.eventBus = new EventBus();
    }
    getEventBus() {
        return this.eventBus;
    }
    async generateSVG(wcURI) {
        try {
            const svg = await QRCode.toString(wcURI, {
                type: 'svg',
            });
            return svg;
        }
        catch (error) {
            console.error('Error generating QR Code:', error);
            return '';
        }
    }
    subscribeEventBus({ closeFn, forceUpdateFn }) {
        this.eventBus.subscribe(WalletConnectEventsEnum.DATA_UPDATE, (payload) => this.dataUpdate({ payload, closeFn, forceUpdateFn }));
    }
    unsubscribeEventBus({ closeFn, forceUpdateFn }) {
        this.eventBus.unsubscribe(WalletConnectEventsEnum.DATA_UPDATE, (payload) => this.dataUpdate({ payload, closeFn, forceUpdateFn }));
    }
    dataUpdate({ payload, closeFn, forceUpdateFn }) {
        if (payload.shouldClose) {
            return closeFn();
        }
        this.data = Object.assign({}, payload);
        forceUpdateFn();
    }
}
//# sourceMappingURL=WalletConnectBase.js.map
