UNPKG

@broxus/js-core

Version:

MobX-based JavaScript Core library

45 lines (44 loc) 1.68 kB
/* eslint-disable max-len */ import { ProviderRpcClient } from 'everscale-inpage-provider'; import { StandaloneClientAdapter } from '../adapters'; const connections = new Map(); export function getTvmConnection(networks, chainId, network) { networks.forEach(value => { if (!connections.has(value.chainId.toString())) { connections.set(value.chainId, new ProviderRpcClient({ provider: new StandaloneClientAdapter({ connection: value.connectionProperties || { data: { endpoint: value.rpcUrl, }, id: Number(value.chainId), type: process.env.NODE_ENV === 'production' ? 'proto' : 'jrpc', }, }), })); } }); if (connections.has(chainId)) { const connection = connections.get(chainId); if (!connection) { throw new Error('Cannot get TVM connection'); } return connection; } if (network?.rpcUrl) { const connection = new ProviderRpcClient({ provider: new StandaloneClientAdapter({ connection: network.connectionProperties || { data: { endpoint: network.rpcUrl, }, id: Number(network.chainId), type: process.env.NODE_ENV === 'production' ? 'proto' : 'jrpc', }, }), }); connections.set(network.chainId, connection); return connection; } throw new Error('Cannot get TVM connection'); }