Skip to content

Commit

Permalink
chore: up
Browse files Browse the repository at this point in the history
  • Loading branch information
iosh committed Oct 27, 2024
1 parent f88cbe4 commit 60488b8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
13 changes: 8 additions & 5 deletions src/actions/wallet/signTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import {
type AssertRequestErrorType,
assertRequest,
} from '../../utils/transaction/assertRequest.js'
import type { GetTransactionType } from '../../utils/transaction/getTransactionType.js'
import { type GetChainIdErrorType, getChainId } from '../public/getChainId.js'

type SignTransactionRequest<
export type SignTransactionRequest<
chain extends Chain | undefined = Chain | undefined,
> = UnionOmit<FormattedTransactionRequest<chain>, 'from'>

Expand All @@ -42,7 +42,10 @@ export type SignTransactionParameters<
account extends Account | undefined,
request extends SignTransactionRequest<chain> = SignTransactionRequest<chain>,
> = request & GetAccountParameter<account> & GetChainParameter<chain>
export type SignTransactionReturnType = TransactionSerialized

export type SignTransactionReturnType<
request extends SignTransactionRequest = SignTransactionRequest,
> = TransactionSerialized<GetTransactionType<request>>

export type SignTransactionErrorType =
| ParseAccountErrorType
Expand All @@ -61,7 +64,7 @@ export async function signTransaction<
>(
client: Client<Transport, chain, account>,
parameters: SignTransactionParameters<chain, account, request>,
): Promise<SignTransactionReturnType> {
): Promise<SignTransactionReturnType<request>> {
const {
account: account_ = client.account,
chain = client.chain,
Expand Down Expand Up @@ -97,7 +100,7 @@ export async function signTransaction<
chainId,
} as TransactionSerializable,
{ serializer: client.chain?.serializers?.transaction },
) as Promise<SignTransactionReturnType>
) as Promise<SignTransactionReturnType<request>>
}

return await client.request(
Expand Down
10 changes: 7 additions & 3 deletions src/clients/decorators/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {

import {
type SignTransactionParameters,
type SignTransactionRequest,
type SignTransactionReturnType,
signTransaction,
} from '../../actions/wallet/signTransaction.js'
Expand Down Expand Up @@ -135,9 +136,12 @@ export type WalletActions<
signMessage: (
args: SignMessageParameters<TAccount>,
) => Promise<SignMessageReturnType>
signTransaction: (
args: SignTransactionParameters<TChain, TAccount>,
) => Promise<SignTransactionReturnType>
signTransaction: <
const request extends
SignTransactionRequest<TChain> = SignTransactionRequest<TChain>,
>(
args: SignTransactionParameters<TChain, TAccount, request>,
) => Promise<SignTransactionReturnType<request>>
signTypedData: <
const TTypedData extends TypedData | { [key: string]: unknown },
TPrimaryType extends string,
Expand Down
14 changes: 9 additions & 5 deletions src/utils/abi/decodeEventLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,15 @@ export function decodeEventLog<
const [signature, ...argTopics] = topics
if (!signature) throw new AbiEventSignatureEmptyTopicsError({ docsPath })

const abiItem = abi.find(
(x) =>
x.type === 'event' &&
signature === toEventSelector(formatAbiItem(x) as EventDefinition),
)
const abiItem = (() => {
if (abi.length === 1) return abi[0]
return abi.find(
(x) =>
x.type === 'event' &&
signature === toEventSelector(formatAbiItem(x) as EventDefinition),
)
})()

if (!(abiItem && 'name' in abiItem) || abiItem.type !== 'event')
throw new AbiEventSignatureNotFoundError(signature, { docsPath })

Expand Down

0 comments on commit 60488b8

Please sign in to comment.