Files
pwap/shared/blockchain/polkadot.ts
T
pezkuwichain f4a7a56c75 fix: Configure WebSocket endpoint from environment variables
## Problem
Frontend was showing 'connecting network' message on production (pezkuwichain.io) because:
1. WebSocket endpoint was hardcoded to localhost in App.tsx
2. DEFAULT_ENDPOINT in polkadot.ts was not reading environment variables

## Solution

### shared/blockchain/polkadot.ts
- Added getWebSocketEndpoint() function to read VITE_NETWORK and corresponding VITE_WS_ENDPOINT_* env vars
- Changed DEFAULT_ENDPOINT from hardcoded value to call getWebSocketEndpoint()
- Now correctly uses wss://ws.pezkuwichain.io in production

### web/src/App.tsx
- Removed hardcoded endpoint="ws://127.0.0.1:9944" prop from PolkadotProvider
- Now uses DEFAULT_ENDPOINT which reads from environment

### web/vite.config.ts
- Minor formatting improvements (no functional changes)

### CLAUDE_README_KRITIK.md (New file)
- Critical documentation for future Claude instances
- Documents VPS validator setup, bootnode configuration
- Strict warnings not to modify working blockchain
- Troubleshooting commands and procedures
- Frontend deployment steps

## Result
- Production site now correctly connects to wss://ws.pezkuwichain.io
- Environment-based configuration working as expected
- Local dev still uses ws://127.0.0.1:9944

## Files Changed
- shared/blockchain/polkadot.ts: Dynamic endpoint selection
- web/src/App.tsx: Remove hardcoded endpoint
- CLAUDE_README_KRITIK.md: Critical documentation (new)
2025-11-17 00:08:14 +03:00

56 lines
1.4 KiB
TypeScript

/**
* Polkadot/Substrate blockchain utilities
*/
import type { BlockchainNetwork } from '../types/blockchain';
/**
* Pezkuwi blockchain network configuration
*/
export const PEZKUWI_NETWORK: BlockchainNetwork = {
name: 'Pezkuwi',
endpoint: 'wss://beta-rpc.pezkuwi.art',
chainId: 'pezkuwi',
};
/**
* Common blockchain endpoints
*/
export const BLOCKCHAIN_ENDPOINTS = {
mainnet: 'wss://mainnet.pezkuwichain.io',
testnet: 'wss://ws.pezkuwichain.io',
local: 'ws://127.0.0.1:9944',
} as const;
/**
* Get the appropriate WebSocket endpoint based on environment
*/
function getWebSocketEndpoint(): string {
const network = import.meta.env.VITE_NETWORK || 'local';
switch (network) {
case 'mainnet':
return import.meta.env.VITE_WS_ENDPOINT_MAINNET || BLOCKCHAIN_ENDPOINTS.mainnet;
case 'testnet':
return import.meta.env.VITE_WS_ENDPOINT_TESTNET || BLOCKCHAIN_ENDPOINTS.testnet;
case 'local':
default:
return import.meta.env.VITE_WS_ENDPOINT_LOCAL || BLOCKCHAIN_ENDPOINTS.local;
}
}
/**
* Default endpoint (reads from environment variables)
*/
export const DEFAULT_ENDPOINT = getWebSocketEndpoint();
/**
* Get block explorer URL for a transaction
* @param txHash - Transaction hash
* @returns Block explorer URL
*/
export function getExplorerUrl(txHash: string): string {
// Update with your actual block explorer URL
return `https://explorer.pezkuwichain.app/tx/${txHash}`;
}