Handle fallback for component already initialized

This commit is contained in:
austinkelsay 2025-03-28 10:34:59 -05:00
parent c9ae2ac436
commit 7d176decfc
No known key found for this signature in database
GPG Key ID: 5A763922E5BA08EE

View File

@ -12,13 +12,24 @@ let initialized = false;
export async function initializeBitcoinConnect() { export async function initializeBitcoinConnect() {
if (!initialized) { if (!initialized) {
const { init } = await import('@getalby/bitcoin-connect-react'); try {
init({ const { init } = await import('@getalby/bitcoin-connect-react');
appName: "PlebDevs", // Check if custom elements are already registered
filters: ["nwc"], if (!customElements.get('bc-balance')) {
showBalance: false init({
}); appName: "PlebDevs",
initialized = true; filters: ["nwc"],
showBalance: false
});
initialized = true;
}
} catch (error) {
// If the error is about custom element already being defined, we can ignore it
// as it means the component is already initialized
if (!error.message?.includes('has already been defined as a custom element')) {
console.error('Error initializing Bitcoin Connect:', error);
}
}
} }
} }