Sublings optimization

This commit is contained in:
Aleksandr Kraiz
2022-05-30 21:53:29 +04:00
parent 350e8d97e0
commit 3c2ee8e2a6
2 changed files with 8 additions and 22 deletions

View File

@@ -1,5 +1,4 @@
import { ethers } from 'ethers';
import getOrionUnitSiblings from '../getOrionUnitSiblings';
import { OrionAggregator } from '../services/OrionAggregator';
import OrionAnalytics from '../services/OrionAnalytics';
import { OrionBlockchain } from '../services/OrionBlockchain';
@@ -143,6 +142,13 @@ export default class OrionUnit {
}
get siblings() {
return getOrionUnitSiblings(this.chainId, this.env);
const envInfo = envs[this.env];
const envNetworks = envInfo?.networks;
const siblingsNetworks = Object
.keys(envNetworks)
.filter(isValidChainId)
.filter((chainId) => chainId !== this.chainId);
return siblingsNetworks.map((chainId) => new OrionUnit(chainId, this.env));
}
}

View File

@@ -1,20 +0,0 @@
import { SupportedChainId } from './types';
import { isValidChainId } from './utils';
import { envs } from './config';
import OrionUnit from './OrionUnit';
export default function getOrionUnitSiblings(siblingChain: SupportedChainId, env: string) {
if (!(env in envs)) throw new Error(`Env '${env}' not found. Available environments is: ${Object.keys(envs).join(', ')}`);
const envInfo = envs[env];
const envNetworks = envInfo?.networks;
if (!(siblingChain in envNetworks)) {
throw new Error(`Chain '${siblingChain}' not found. `
+ `Available chains in selected environment (${env}) is: ${Object.keys(envNetworks).join(', ')}`);
}
const siblingsNetworks = Object
.keys(envNetworks)
.filter(isValidChainId)
.filter((chainId) => chainId !== siblingChain);
return siblingsNetworks.map((chainId) => new OrionUnit(chainId, env));
}