Skip to content

Commit

Permalink
fix: imporve transformHook typing inferring
Browse files Browse the repository at this point in the history
  • Loading branch information
swkatmask committed Nov 29, 2024
1 parent 20cf643 commit d276275
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
isNativeTokenAddress,
NETWORK_DESCRIPTORS,
SchemaType,
useRedPacketConstants,
useRedPacketConstant,
} from '@masknet/web3-shared-evm'
import { Box, ListItem, Typography } from '@mui/material'
import { useQuery } from '@tanstack/react-query'
Expand Down Expand Up @@ -186,10 +186,10 @@ export const RedPacketInHistoryList = memo(function RedPacketInHistoryList(props
const { data: tokenAddress } = useRedpacketToken(chainId, history.trans_hash, seen && token_symbol === 'MATIC')
const { data: token } = useFungibleToken(NetworkPluginID.PLUGIN_EVM, tokenAddress, undefined, { chainId })
const tokenSymbol = token?.symbol ?? token_symbol
const contractAddress = useRedPacketConstants(chainId).HAPPY_RED_PACKET_ADDRESS_V4
const contractAddress = useRedPacketConstant(chainId, 'HAPPY_RED_PACKET_ADDRESS_V4')
const { data: redpacketRecord } = useQuery({
queryKey: ['redpacket', 'by-tx-hash', history.trans_hash],
queryFn: async () => RedPacketRPC.getRedPacketRecord(history.trans_hash),
queryFn: () => RedPacketRPC.getRedPacketRecord(history.trans_hash),
})
const { data: createSuccessResult } = useCreateRedPacketReceipt(history.trans_hash, chainId)
const isViewStatus = redpacket_status === FireflyRedPacketAPI.RedPacketStatus.View
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-shared/base/src/helpers/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export function transformAllHook<ChainId extends number, T>(getConstants: (chain
}
}

export function transformHook<ChainId extends number, T, K extends keyof T>(
export function transformHook<ChainId extends number, const T, const K extends keyof T>(
getConstant: (chainId: ChainId) => Partial<T>,
) {
return function useConstant(chainId: ChainId = 1 as ChainId, key?: K, fallback?: T[K]) {
return function useConstant<F extends K>(chainId: ChainId = 1 as ChainId, key?: F, fallback?: T[F]) {
return useMemo(() => {
if (!key) return fallback
return getConstant(chainId)[key] ?? fallback
Expand Down

0 comments on commit d276275

Please sign in to comment.