UNPKG

x0-react-sdk

Version:

React SDK for X0Pay Hyperlane token bridging with MetaMask and Safe wallet integration

67 lines (59 loc) 2.04 kB
import type { WalletConnectConfig } from '../types/wallet'; // Helper function to create default WalletConnect configuration export function createDefaultWalletConnectConfig(projectId: string): WalletConnectConfig { return { projectId, chains: [1, 5, 137, 42161], // Mainnet, Goerli, Polygon, Arbitrum optionalChains: [1, 5, 137, 42161], // Required by WalletConnect v2 showQrModal: true, metadata: { name: 'X0 SDK', description: 'X0Pay Token bridging SDK', url: 'https://x0.com', icons: ['https://x0.com/icon.png'] } }; } // Validation function for WalletConnect config export function validateWalletConnectConfig(config: WalletConnectConfig): void { if (!config.projectId || config.projectId === 'YOUR_WALLETCONNECT_PROJECT_ID') { throw new Error( 'WalletConnect projectId is required. Please get your project ID from https://cloud.walletconnect.com' ); } if (!config.chains || config.chains.length === 0) { throw new Error('WalletConnect chains array is required and cannot be empty'); } if (!config.metadata) { throw new Error('WalletConnect metadata is required'); } } // Helper function to create WalletConnect config with validation export function createWalletConnectConfig( projectId: string, chains: number[], options?: Partial<WalletConnectConfig> ): WalletConnectConfig { const config: WalletConnectConfig = { ...createDefaultWalletConnectConfig(projectId), chains, ...options }; validateWalletConnectConfig(config); return config; } // Helper function to get chain-specific WalletConnect config export function getChainSpecificWalletConnectConfig( projectId: string, chainId: string ): WalletConnectConfig { const chainIdNumber = parseInt(chainId, 16); return createWalletConnectConfig(projectId, [chainIdNumber], { metadata: { name: 'X0 SDK', description: `X0Pay Token bridging on chain ${chainId}`, url: 'https://x0.com', icons: ['https://x0.com/icon.png'] } }); }