*Move code to plugin

This commit is contained in:
Derrick Hammer 2022-08-28 22:34:48 -04:00
parent 6283e8c1b1
commit 744ab44af8
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 0 additions and 39 deletions

View File

@ -1,42 +1,3 @@
let chainNetworks: networks;
dynImport("@lumeweb/pokt-rpc-endpoints").then(
(module) => (chainNetworks = module as any)
);
type networks = { [net: string]: string };
export function maybeMapChainId(chain: string): string | boolean {
if (chain in chainNetworks) {
return chainNetworks[chain];
}
if (
[parseInt(chain, 16).toString(), parseInt(chain, 10).toString()].includes(
chain.toLowerCase()
)
) {
return chain;
}
return false;
}
export function reverseMapChainId(chainId: string): string | boolean {
let vals = Object.values(chainNetworks);
if (!vals.includes(chainId)) {
return false;
}
return Object.keys(chainNetworks)[vals.indexOf(chainId)];
}
export function isIp(ip: string) {
return /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(
ip
);
}
export function dynImport(module: string) {
return Function(`return import("${module}")`)() as Promise<any>;
}