Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Aug 9, 2023
1 parent 148d26a commit dd74ecf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
11 changes: 6 additions & 5 deletions src/types/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import type { IsUndefined, Prettify } from './utils.js'

export type Chain<
formatters extends ChainFormatters | undefined = ChainFormatters | undefined,
serializers extends ChainSerializers<formatters> | undefined =
| ChainSerializers<formatters>
| undefined,
> = import('@wagmi/chains').Chain & {
> = import('@wagmi/chains').Chain & ChainConfig<formatters>

export type ChainConfig<
formatters extends ChainFormatters | undefined = ChainFormatters | undefined,
> = {
formatters?: formatters | undefined
serializers?: serializers | undefined
serializers?: ChainSerializers<formatters> | undefined
fees?: ChainFees<formatters> | undefined
}

Expand Down
25 changes: 18 additions & 7 deletions src/utils/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import {
ChainMismatchError,
ChainNotFoundError,
} from '../errors/chain.js'
import type { Chain, ChainContract, ChainFormatters } from '../types/chain.js'
import type {
Chain,
ChainConfig,
ChainContract,
ChainFormatters,
} from '../types/chain.js'
import type { Assign } from '../types/utils.js'

export type AssertCurrentChainParameters = {
chain?: Chain
Expand All @@ -24,14 +30,19 @@ export function defineChain<
formatters extends ChainFormatters,
>(
chain: chain,
config?: Pick<Chain<formatters>, 'fees' | 'formatters' | 'serializers'>,
) {
config?: ChainConfig<formatters>,
): Assign<chain, ChainConfig<formatters>> {
const {
fees = chain.fees,
formatters = chain.formatters,
serializers = chain.serializers,
} = config || {}
return {
...chain,
fees: config?.fees,
formatters: config?.formatters,
serializers: config?.serializers,
}
fees,
formatters,
serializers,
} as unknown as Assign<chain, ChainConfig<formatters>>
}

export function getChainContractAddress({
Expand Down

0 comments on commit dd74ecf

Please sign in to comment.