forked from taylorjdawson/eth-chains
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Small (breaking) compatibility changes and bump version to v23.0.0
- Loading branch information
Showing
3 changed files
with
11 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
export { | ||
default as chains, | ||
getChain, | ||
getChainById, | ||
getChainByName, | ||
allChains, | ||
Chain, | ||
ChainId, | ||
ChainName, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,35 @@ | ||
import { Chain, Chains } from './types' | ||
import { chains } from './chains' | ||
import { ChainId } from './enums' | ||
export { NativeCurrency, Explorer, Parent } from './types' | ||
export { ChainName, ChainId } from './enums' | ||
export { chains, Chain, Chains } | ||
export { Chain, Chains } | ||
|
||
/** | ||
* Get a chain by its `id`. | ||
* @param id - The `id` of the chain | ||
* @returns The `Chain` object associated with the chain `id` | ||
*/ | ||
const getById = (id: number): Chain | undefined => chains[id] | ||
export const getChainById = (id: number): Chain | undefined => chains[id] | ||
|
||
/** | ||
* Get a chain by its `name`. | ||
* @param name - The `name` of the chain | ||
* @returns The `Chain` object associated with the chain `name` | ||
*/ | ||
const getByName = (name: string): Chain | undefined => | ||
export const getChainByName = (name: string): Chain | undefined => | ||
Object.values(chains).find(chain => chain.name === name) || {} | ||
|
||
/** | ||
* Get a chain by its `id` or by its `name`. | ||
* @param idOrName - The name or id of the chain | ||
* @returns The `Chain` object associated with the `id` or `name` | ||
*/ | ||
const get = (idOrName: string | number): Chain | undefined => | ||
typeof idOrName === 'number' ? getById(idOrName) : getByName(idOrName) | ||
export const getChain = (idOrName: string | number): Chain | undefined => | ||
typeof idOrName === 'number' ? getChainById(idOrName) : getChainByName(idOrName) | ||
|
||
/** | ||
* Gets the entire `chains` object | ||
* @returns An object containing all chains | ||
*/ | ||
const all = (): Chains => chains | ||
export const allChains = (): Chains => chains | ||
|
||
export default { getById, getByName, get, all } |