Skip to content

Commit b41e701

Browse files
feat: add filter to get chain by network name
* Update getChainsByNetwork to allow input of both the chain symbol and the network name v1.8.0
1 parent efc25e2 commit b41e701

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hyperbitjs/chains",
3-
"version": "1.7.2",
3+
"version": "1.8.0",
44
"license": "MIT",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",

src/utils.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ export function findNetworkById(id: string): Network | undefined {
6969
return undefined;
7070
}
7171

72-
export function getChainIds(network: string): string[] {
72+
export function getChainIds(symbol: string): string[] {
7373
return Object.keys(chains).reduce<string[]>((acc: string[], key: string) => {
74-
const n = chains[key][network];
74+
const n = chains[key][symbol];
7575
if (n) {
7676
return [...acc, n.id];
7777
}
@@ -86,11 +86,23 @@ export function getChainNames(): string[] {
8686
}, []);
8787
}
8888

89-
export function getChainsByNetwork(network: string): Network[] {
89+
/**
90+
* Return Networks by the blockchain symbol. If network is provided, return only the network with the given network.
91+
* @param symbol e.g. btc
92+
* @param network e.g. mainnet
93+
* @returns Network[]
94+
*/
95+
export function getChainsByNetwork(symbol: string, network?: string): Network[] {
9096
return Object.keys(chains).reduce<Network[]>(
9197
(acc: Network[], key: string) => {
92-
const n = chains[key][network];
98+
const n = chains[key][symbol];
9399
if (n) {
100+
if (network) {
101+
if (n.network === network) {
102+
return [...acc, n];
103+
}
104+
return acc;
105+
}
94106
return [...acc, n];
95107
}
96108
return acc;

0 commit comments

Comments
 (0)