UNPKG

@pushchain/ui-kit

Version:

Push Chain is a true universal L1 that is 100% EVM compatible. It allows developers to deploy once and make their apps instantly compatible with users from all other L1s (Ethereum, Solana, etc) with zero on-chain code change.

60 lines 3.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.openPhantomMobileBrowser = exports.buildPhantomMobileBrowseUrl = exports.consumePhantomMobileConnectRequest = exports.hasPhantomMobileConnectRequest = exports.shouldOpenPhantomMobileBrowser = exports.hasPhantomSolanaProvider = exports.isMobileDevice = exports.PHANTOM_MOBILE_CONNECT_PARAM = exports.PHANTOM_PROVIDER_NAME = void 0; const wallet_types_1 = require("../../../types/wallet.types"); const PHANTOM_BROWSE_BASE_URL = 'https://phantom.app/ul/browse'; exports.PHANTOM_PROVIDER_NAME = 'Phantom'; exports.PHANTOM_MOBILE_CONNECT_PARAM = 'pua_phantom_mobile_connect'; const isMobileDevice = () => { if (typeof navigator === 'undefined') return false; const userAgent = navigator.userAgent || ''; const isIOS = /iPad|iPhone|iPod/i.test(userAgent); const isAndroid = /Android/i.test(userAgent); const isTouchMac = /Macintosh/i.test(userAgent) && navigator.maxTouchPoints > 1; return isIOS || isAndroid || isTouchMac; }; exports.isMobileDevice = isMobileDevice; const hasPhantomSolanaProvider = () => { return typeof window !== 'undefined' && !!window.phantom?.solana; }; exports.hasPhantomSolanaProvider = hasPhantomSolanaProvider; const shouldOpenPhantomMobileBrowser = (chainType) => { const targetChain = chainType || wallet_types_1.ChainType.SOLANA; return (targetChain === wallet_types_1.ChainType.SOLANA && (0, exports.isMobileDevice)() && !(0, exports.hasPhantomSolanaProvider)()); }; exports.shouldOpenPhantomMobileBrowser = shouldOpenPhantomMobileBrowser; const hasPhantomMobileConnectRequest = () => { if (typeof window === 'undefined') return false; return new URL(window.location.href).searchParams.has(exports.PHANTOM_MOBILE_CONNECT_PARAM); }; exports.hasPhantomMobileConnectRequest = hasPhantomMobileConnectRequest; const consumePhantomMobileConnectRequest = () => { if (typeof window === 'undefined') return null; const url = new URL(window.location.href); const requestedChain = url.searchParams.get(exports.PHANTOM_MOBILE_CONNECT_PARAM); if (!requestedChain) return null; url.searchParams.delete(exports.PHANTOM_MOBILE_CONNECT_PARAM); window.history.replaceState(window.history.state, document.title, `${url.pathname}${url.search}${url.hash}`); return requestedChain === wallet_types_1.ChainType.SOLANA ? wallet_types_1.ChainType.SOLANA : null; }; exports.consumePhantomMobileConnectRequest = consumePhantomMobileConnectRequest; const buildPhantomMobileBrowseUrl = (chainType = wallet_types_1.ChainType.SOLANA) => { if (typeof window === 'undefined') { throw new Error('Phantom mobile browser can only be opened in a browser'); } const targetUrl = new URL(window.location.href); targetUrl.searchParams.set(exports.PHANTOM_MOBILE_CONNECT_PARAM, chainType); return `${PHANTOM_BROWSE_BASE_URL}/${encodeURIComponent(targetUrl.toString())}?ref=${encodeURIComponent(window.location.origin)}`; }; exports.buildPhantomMobileBrowseUrl = buildPhantomMobileBrowseUrl; const openPhantomMobileBrowser = (chainType = wallet_types_1.ChainType.SOLANA) => { window.location.assign((0, exports.buildPhantomMobileBrowseUrl)(chainType)); }; exports.openPhantomMobileBrowser = openPhantomMobileBrowser; //# sourceMappingURL=phantomMobile.js.map