diff --git a/CHANGELOG.md b/CHANGELOG.md index b93f973cf7..c904c00341 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [4.1.7] - 2023.10.15 +### Changed +- `TatumUtils` chainId <-> `Network` mappings always return usable value or throw error for ease of use. + ## [4.1.6] - 2023.10.15 ### Added - `TatumUtils` added with access to chainId <-> `Network` mapping diff --git a/package.json b/package.json index 4f1df886e7..0e38a0cdca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tatumio/tatum", - "version": "4.1.6", + "version": "4.1.7", "description": "Tatum JS SDK", "author": "Tatum", "repository": "https://github.com/tatumio/tatum-js", diff --git a/src/e2e/tatum.spec.ts b/src/e2e/tatum.spec.ts index 6aca730b3f..f77c8b337e 100644 --- a/src/e2e/tatum.spec.ts +++ b/src/e2e/tatum.spec.ts @@ -51,7 +51,7 @@ describe('Network to chainId mapping check', () => { const chainId = TatumUtils.getChainId(network) expect(chainId).toBeGreaterThan(0) - expect(TatumUtils.getNetwork(chainId as number)).toBe(network) + expect(TatumUtils.getNetwork(chainId)).toBe(network) }) } }) diff --git a/src/util/tatum.utils.ts b/src/util/tatum.utils.ts index 231c8ab52d..1f5e40b3ed 100644 --- a/src/util/tatum.utils.ts +++ b/src/util/tatum.utils.ts @@ -2,17 +2,21 @@ import { Network } from '../dto' import { Constant } from './constant' export const TatumUtils = { - getChainId: (network: Network): number | undefined => { + getChainId: (network: Network): number => { if (network in Constant.NETWORK.ChainId) { return Constant.NETWORK.ChainId[network as keyof typeof Constant.NETWORK.ChainId] } - return undefined + throw new Error(`Tatum Network to ChainId for network ${network} does not exist`) }, - getNetwork: (chainId: number): keyof typeof Constant.NETWORK.ChainId | undefined => { + getNetwork: (chainId: number): Network => { if (Object.keys(chainIdToNetworkCache).length === 0) { buildChainIdToNetworkCache() } - return chainIdToNetworkCache[chainId] || undefined + const network = chainIdToNetworkCache[chainId] + if (!network) { + throw new Error(`ChainId to Tatum Network for chainId ${chainId} does not exist`) + } + return network }, }