Files
pwap/shared/blockchain/endpoints.ts
T
pezkuwichain 9963a759d3 fix: fix Zagros endpoints, hide PEZ Rewards when pallet unavailable
- Remove Asset Hub and People Chain endpoints from Zagros/Development config (relay chain only)
- Default network now always mainnet
- PEZ Rewards card only renders when pallet is available on chain
- Dynamic grid layout when PEZ Rewards card is hidden
2026-02-13 18:11:24 +03:00

170 lines
4.8 KiB
TypeScript

/**
* Blockchain Network Endpoints Configuration
* Production, Testnet (Zagros), and Development environments
*/
export interface NetworkConfig {
name: string;
endpoint: string;
wsEndpoint: string;
assetHubEndpoint?: string;
peopleChainEndpoint?: string;
type: 'production' | 'testnet' | 'development';
description: string;
}
/**
* Production Network Endpoints
*/
export const NETWORK_ENDPOINTS: Record<string, NetworkConfig> = {
// Production Mainnet (Primary)
MAINNET: {
name: 'Pezkuwi Mainnet',
endpoint: 'https://rpc.pezkuwichain.io',
wsEndpoint: 'wss://rpc.pezkuwichain.io',
assetHubEndpoint: 'wss://asset-hub-rpc.pezkuwichain.io',
peopleChainEndpoint: 'wss://people-rpc.pezkuwichain.io',
type: 'production',
description: 'Main production network for Pezkuwi blockchain',
},
// Production alias using mainnet subdomain
PRODUCTION: {
name: 'Pezkuwi Mainnet',
endpoint: 'https://mainnet.pezkuwichain.io',
wsEndpoint: 'wss://mainnet.pezkuwichain.io',
assetHubEndpoint: 'wss://asset-hub-rpc.pezkuwichain.io',
peopleChainEndpoint: 'wss://people-rpc.pezkuwichain.io',
type: 'production',
description: 'Production mainnet (mainnet subdomain)',
},
// Zagros Testnet (Relay Chain only)
ZAGROS: {
name: 'Zagros Testnet',
endpoint: 'https://zagros-rpc.pezkuwichain.io',
wsEndpoint: 'wss://zagros-rpc.pezkuwichain.io',
type: 'testnet',
description: 'Zagros testnet - relay chain only',
},
// Testnet alias (maps to Zagros)
TESTNET: {
name: 'Zagros Testnet',
endpoint: 'https://zagros-rpc.pezkuwichain.io',
wsEndpoint: 'wss://zagros-rpc.pezkuwichain.io',
type: 'testnet',
description: 'Testnet environment (Zagros) - relay chain only',
},
// Local Development
LOCAL: {
name: 'Local Development',
endpoint: 'http://127.0.0.1:9944',
wsEndpoint: 'ws://127.0.0.1:9944',
assetHubEndpoint: 'ws://127.0.0.1:40944',
peopleChainEndpoint: 'ws://127.0.0.1:41944',
type: 'development',
description: 'Local development node',
},
// Development alias (maps to Zagros relay chain only)
DEVELOPMENT: {
name: 'Zagros Testnet',
endpoint: 'https://zagros-rpc.pezkuwichain.io',
wsEndpoint: 'wss://zagros-rpc.pezkuwichain.io',
type: 'development',
description: 'Development mode connecting to Zagros relay chain',
},
// Legacy: Beta (deprecated, maps to Mainnet)
BETA: {
name: 'Pezkuwi Mainnet',
endpoint: 'https://rpc.pezkuwichain.io',
wsEndpoint: 'wss://rpc.pezkuwichain.io',
assetHubEndpoint: 'wss://asset-hub-rpc.pezkuwichain.io',
peopleChainEndpoint: 'wss://people-rpc.pezkuwichain.io',
type: 'production',
description: 'Legacy beta config - now maps to mainnet',
},
};
/**
* Default network based on environment
*/
export const DEFAULT_NETWORK = NETWORK_ENDPOINTS.MAINNET;
/**
* Port Configuration
* - Relay Chain RPC: Port 9944
* - Asset Hub RPC: Port 40944
* - People Chain RPC: Port 41944
*/
export const PORTS = {
RELAY_CHAIN: 9944,
ASSET_HUB: 40944,
PEOPLE_CHAIN: 41944,
};
/**
* Frontend Deployments
*/
export const FRONTEND_URLS = {
PRODUCTION: 'https://app.pezkuwichain.io',
TESTNET: 'https://zagros.pezkuwichain.io',
EXPLORER: 'https://explorer.pezkuwichain.io',
EXTENSION: 'https://js.pezkuwichain.io',
};
/**
* Get network by name
*/
export function getNetwork(name: keyof typeof NETWORK_ENDPOINTS): NetworkConfig {
return NETWORK_ENDPOINTS[name];
}
/**
* Get all networks
*/
export function getAllNetworks(): NetworkConfig[] {
return Object.values(NETWORK_ENDPOINTS);
}
/**
* Get the current network configuration based on the VITE_NETWORK environment variable.
* This serves as the single source of truth for the application's network configuration.
* @returns {NetworkConfig} The active network configuration.
*/
export const getCurrentNetworkConfig = (): NetworkConfig => {
let networkName = 'LOCAL';
// Support both Vite (web) and React Native environments
if (typeof process !== 'undefined' && process.env?.EXPO_PUBLIC_NETWORK) {
networkName = process.env.EXPO_PUBLIC_NETWORK.toUpperCase();
} else if (typeof import.meta !== 'undefined' && (import.meta as any).env?.VITE_NETWORK) {
networkName = ((import.meta as any).env.VITE_NETWORK || 'local').toUpperCase();
}
const validNetworkKeys = Object.keys(NETWORK_ENDPOINTS);
if (validNetworkKeys.includes(networkName)) {
return NETWORK_ENDPOINTS[networkName as keyof typeof NETWORK_ENDPOINTS];
}
// Fallback to a default or local configuration if the name is invalid
return NETWORK_ENDPOINTS.LOCAL;
};
/**
* Check if endpoint is available
*/
export async function checkEndpoint(endpoint: string): Promise<boolean> {
try {
const response = await fetch(`${endpoint}/health`, { method: 'GET' });
return response.ok;
} catch {
return false;
}
}
export const NETWORKS = NETWORK_ENDPOINTS;