@dynamic-labs/sdk-react-core
Version:
A React SDK for implementing wallet web3 authentication and authorization to your website.
49 lines (44 loc) • 1.9 kB
JavaScript
'use client'
;
Object.defineProperty(exports, '__esModule', { value: true });
var _tslib = require('../../../../_virtual/_tslib.cjs');
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
var openPopup = require('./openPopup/openPopup.cjs');
const ONRAMP_POPUP_CONFIG = {
height: 600,
width: 500,
};
/**
* Opens an onramp popup and sets up event listeners to handle popup closure
* @param url The base URL to open in the popup
* @param wallet The user's wallet (optional)
* @param setShowOnramp Callback to update the UI state when popup is closed
* @param provider The onramp provider ID
* @returns A promise that resolves when the popup is opened
* @throws Error if there are issues with URL, wallet compatibility, etc.
*/
const openOnrampPopup = (url_1, wallet_1, setShowOnramp_1, ...args_1) => _tslib.__awaiter(void 0, [url_1, wallet_1, setShowOnramp_1, ...args_1], void 0, function* (url, wallet, setShowOnramp, provider = sdkApiCore.OnrampProviders.CoinbaseOnramp) {
try {
// Safety check: don't open popup with empty URL
if (!url) {
throw new Error('Cannot open onramp popup: Empty URL');
}
// Open the popup - errors will propagate to the caller
yield openPopup.openPopup(url, ONRAMP_POPUP_CONFIG.width, ONRAMP_POPUP_CONFIG.height, () => {
// When the popup is closed (by user or programmatically), update the UI
setShowOnramp(false);
});
}
catch (error) {
// Always set showOnramp to false on any error
setShowOnramp(false);
// Re-throw any error
if (error instanceof Error) {
throw error;
}
// For non-Error objects, wrap in a generic Error
throw new Error('Error opening onramp popup');
}
});
exports.ONRAMP_POPUP_CONFIG = ONRAMP_POPUP_CONFIG;
exports.openOnrampPopup = openOnrampPopup;