Skip to content

Commit

Permalink
Update types again
Browse files Browse the repository at this point in the history
  • Loading branch information
yivlad committed Aug 21, 2023
1 parent 88ff4e0 commit 13958db
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 118 deletions.
1 change: 0 additions & 1 deletion packages/core/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './useBlockMeta'
export * from './useBlockNumber'
export * from './useBlockNumbers'
export * from './useChainCalls'
export * from './useConfig'
export * from './useDebounce'
export * from './useDebouncePair'
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/hooks/useCallResilency.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ describe.skip('useCall Resilency tests', () => {
},
pollingInterval: 200,
multicallAddresses: {
[1337]: multicall0.address,
[31337]: multicall1.address,
[1337]: multicall0.target as string,
[31337]: multicall1.target as string,
},
}
})
Expand Down
68 changes: 0 additions & 68 deletions packages/core/src/hooks/useChainCall.test.tsx

This file was deleted.

28 changes: 0 additions & 28 deletions packages/core/src/hooks/useChainCalls.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/hooks/useContractFunction.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('useContractFunction', () => {

it('transfer amount with just mnemonic phrase', async () => {
const { result, waitForCurrent, waitForNextUpdate } = await renderDAppHook(
() => useContractFunction(token, 'transfer', { chainId: 1, mnemonicPhrase: wallet1.mnemonic?.phrase }),
() => useContractFunction(token, 'transfer', { chainId: 1, mnemonicPhrase: wallet1.mnemonic?.phrase as string }),
{
config,
}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/hooks/useContractFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function useContractFunction<T extends BaseContract, FN extends ContractF
? opts.gasLimit
: (await estimateContractFunctionGasLimit(
contractWithSigner,
functionName,
functionName as string,
args,
gasLimitBufferPercentage
)) ?? null
Expand All @@ -110,11 +110,11 @@ export function useContractFunction<T extends BaseContract, FN extends ContractF
}
const modifiedArgs = hasOpts ? args.slice(0, args.length - 1) : args

const receipt = await promiseTransaction(contractWithSigner[functionName](...modifiedArgs, modifiedOpts), {
const receipt = await promiseTransaction(contractWithSigner[functionName as string](...modifiedArgs, modifiedOpts), {
safeTransaction: {
to: contract.target,
to: contract.target as string,
value: opts?.value,
data: contract.interface.encodeFunctionData(functionName, modifiedArgs),
data: contract.interface.encodeFunctionData(functionName as string, modifiedArgs),
safeTxGas: gasLimit ?? undefined,
},
})
Expand All @@ -130,7 +130,7 @@ export function useContractFunction<T extends BaseContract, FN extends ContractF
}, [] as LogDescription[])
setEvents(events)
}
return receipt
return receipt ?? undefined
}
},
[contract, functionName, options, provider, library, gasLimitBufferPercentage, promiseTransaction]
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/hooks/useGnosisSafeContract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useRef } from 'react'
import type { Signer, providers } from 'ethers'
import type { Provider, Signer } from 'ethers'
import { Contract } from 'ethers'
import { GNOSIS_SAFE_ABI } from '../helpers/gnosisSafeUtils'

Expand All @@ -8,7 +8,7 @@ import { GNOSIS_SAFE_ABI } from '../helpers/gnosisSafeUtils'
*/
export const useGnosisSafeContract = (
account: string | undefined,
provider: Signer | providers.Provider | undefined
provider: Signer | Provider | undefined
) => {
const safeContract = useRef<Contract | undefined>(undefined)

Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/hooks/useLogs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from 'react'
import { Contract } from 'ethers'
import { ContractEventNames, Falsy, EventParams, TypedContract } from '../model/types'
import { BaseContract } from 'ethers'
import { ContractEventNames, Falsy, EventParams } from '../model/types'
import { useRawLogs } from './useRawLogs'
import { decodeLogs, encodeFilterData } from '../helpers'
import { LogQueryParams } from '../constants/type/QueryParams'
Expand All @@ -18,7 +18,7 @@ import { LogQueryParams } from '../constants/type/QueryParams'
* }
*/
export interface TypedFilter<
T extends TypedContract = Contract,
T extends BaseContract = BaseContract,
EN extends ContractEventNames<T> = ContractEventNames<T>
> {
contract: T
Expand All @@ -35,7 +35,7 @@ export interface TypedFilter<
* @returns an array of decoded logs (see {@link LogsResult})
* @public
*/
export function useLogs<T extends Contract = Contract, EN extends ContractEventNames<T> = ContractEventNames<T>>(
export function useLogs<T extends BaseContract = BaseContract, EN extends ContractEventNames<T> = ContractEventNames<T>>(
filter: TypedFilter<T, EN> | Falsy,
queryParams: LogQueryParams = {}
) {
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ export {
useCalls,
useConfig,
useUpdateConfig,
useChainCall,
useChainCalls,
useChainMeta,
useChainState,
useContractFunction,
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { BaseContract, ContractTransaction } from "ethers"

export type Falsy = false | 0 | '' | null | undefined

type ReplaceNever<T, R = string> = [T] extends [never] ? R : T;
type ReplaceNever<T, R = any> = [T] extends [never] ? R : T;

export type ContractFunctionNames<T extends BaseContract> = ReplaceNever<keyof { [K in Parameters<T['interface']['getFunction']>[0] as ReturnType<K extends keyof T ? T[K] extends (...args: any) => any ? T[K] : never : never> extends Promise<ContractTransaction> ? K : never]: void }>

export type ContractMethodNames<T extends BaseContract> = ReplaceNever<keyof { [K in Parameters<T['interface']['getFunction']>[0] as ReturnType<K extends keyof T ? T[K] extends (...args: any) => any ? T[K] : never : never> extends Promise<ContractTransaction> ? never : K]: void }>

export type ContractEventNames<T extends BaseContract> = ReplaceNever<keyof { [K in keyof T['filters']]: void }>
export type ContractEventNames<T extends BaseContract> = keyof { [K in Exclude<keyof T['filters'], number | symbol>]: void }

export type Params<T extends BaseContract, FN extends ContractFunctionNames<T> | ContractMethodNames<T>> = ReplaceNever<Parameters<FN extends keyof T ? T[FN] extends (...args: any) => any ? T[FN] : never : never>, any[]>
export type Params<T extends BaseContract, FN extends ContractFunctionNames<T> | ContractMethodNames<T>> = ReplaceNever<Parameters<FN extends keyof T ? T[FN] extends (...args: any) => any ? T[FN] : never : never>>

export type Results<T extends BaseContract, FN extends ContractMethodNames<T>> = ReplaceNever<Awaited<ReturnType<FN extends keyof T ? T[FN] extends (...args: any) => any ? T[FN] : never : never>>, any[]>
export type Results<T extends BaseContract, FN extends ContractMethodNames<T>> = ReplaceNever<Awaited<ReturnType<FN extends keyof T ? T[FN] extends (...args: any) => any ? T[FN] : never : never>>>

export type EventParams<T extends BaseContract, EN extends ContractEventNames<T>> = ReplaceNever<Parameters<T['filters'][EN]>, any[]>
export type EventParams<T extends BaseContract, EN extends ContractEventNames<T>> = ReplaceNever<Parameters<T['filters'][EN]>>

export type EventRecord<T extends BaseContract, EN extends ContractEventNames<T>> = { [P in keyof EventParams<T, EN> as string]: any }

Expand Down

0 comments on commit 13958db

Please sign in to comment.