Skip to content

Commit

Permalink
Merge pull request #178 from autonomys/feat/improve-network-types
Browse files Browse the repository at this point in the history
Improve network types
  • Loading branch information
marc-aurele-besner authored Nov 27, 2024
2 parents 10955d9 + c368f8d commit dc475c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions examples/next/src/hooks/useNetwork.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { networks } from '@autonomys/auto-utils'
import { NetworkId, networks } from '@autonomys/auto-utils'
import { useParams } from 'next/navigation'
import { useCallback, useEffect, useMemo, useState } from 'react'

Expand All @@ -17,7 +17,7 @@ export const useNetwork = () => {
const listOfNetworks = useMemo(() => networks.map((network) => network.id), [])

const handleNetworkChange = useCallback(
(networkId: string) => {
(networkId: NetworkId) => {
if (!listOfNetworks.includes(networkId)) {
throw new Error(`Network ${networkId} not found`)
}
Expand All @@ -29,7 +29,7 @@ export const useNetwork = () => {

useEffect(() => {
if (networkName && config.networkId !== networkName && Array.isArray(networkName) === false)
handleNetworkChange(networkName)
handleNetworkChange(networkName as NetworkId)
}, [networkName])

return { config, handleNetworkChange }
Expand Down
5 changes: 3 additions & 2 deletions packages/auto-utils/src/types/network.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// file: src/types/network.ts
import type { ApiOptions } from '@polkadot/api/types'
import { NetworkId, NetworkName } from '../constants/network'
import type { NetworkDomains } from './domain'
import { Token } from './token'

Expand All @@ -9,8 +10,8 @@ export type Explorer = {
}

export type Network = {
id: string
name: string
id: NetworkId
name: NetworkName
rpcUrls: string[]
explorer: Explorer[]
domains: NetworkDomains[]
Expand Down

0 comments on commit dc475c9

Please sign in to comment.