Skip to content

Commit

Permalink
update transaction response type
Browse files Browse the repository at this point in the history
  • Loading branch information
alissacrane-cb committed Aug 5, 2024
1 parent 9038ebe commit 466ec1f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
13 changes: 11 additions & 2 deletions site/docs/pages/transaction/types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type TransactionProviderReact = {
children: ReactNode; // The child components to be rendered within the provider component.
contracts: ContractFunctionParameters[]; // An array of contract function parameters provided to the child components.
onError?: (e: TransactionError) => void; // An optional callback function that handles errors within the provider.
onSuccess?: (response: TransactionReceipt | TransactionReceipt[]) => void; // An optional callback function that exposes transaction hash
onSuccess?: (response: TransactionResponse) => void; // An optional callback function that exposes the transaction receipts
};
```

Expand All @@ -67,10 +67,19 @@ type TransactionReact = {
className?: string; // An optional CSS class name for styling the component.
contracts: ContractFunctionParameters[]; // An array of contract function parameters for the transaction.
onError?: (e: TransactionError) => void; // An optional callback function that handles transaction errors.
onSuccess?: (response: TransactionReceipt | TransactionReceipt[]) => void; // An optional callback function that exposes transaction hash
onSuccess?: (response: TransactionResponse) => void; // An optional callback function that exposes the transaction receipts
};
```

## `TransactionResponse`

```ts
type TransactionResponse = {
transactionReceipts: TransactionReceipt[];
};

```

## `TransactionSponsorReact`

```ts
Expand Down
6 changes: 3 additions & 3 deletions src/transaction/components/TransactionProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ export function TransactionProvider({
}, [chainId, executeContracts, handleSubmitErrors, switchChain]);

useEffect(() => {
if (receiptArray?.length > 1) {
onSuccess?.(receiptArray);
if (receiptArray?.length) {
onSuccess?.({ transactionReceipts: receiptArray });
} else if (receipt) {
onSuccess?.(receipt);
onSuccess?.({ transactionReceipts: [receipt] });
}
}, [onSuccess, receipt, receiptArray]);

Expand Down
11 changes: 9 additions & 2 deletions src/transaction/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export type TransactionProviderReact = {
children: ReactNode; // The child components to be rendered within the provider component.
contracts: ContractFunctionParameters[]; // An array of contract function parameters provided to the child components.
onError?: (e: TransactionError) => void; // An optional callback function that handles errors within the provider.
onSuccess?: (response: TransactionReceipt | TransactionReceipt[]) => void; // An optional callback function that exposes transaction hash
onSuccess?: (response: TransactionResponse) => void; // An optional callback function that exposes the transaction receipts
};

/**
Expand All @@ -76,7 +76,14 @@ export type TransactionReact = {
className?: string; // An optional CSS class name for styling the component.
contracts: ContractFunctionParameters[]; // An array of contract function parameters for the transaction.
onError?: (e: TransactionError) => void; // An optional callback function that handles transaction errors.
onSuccess?: (response: TransactionReceipt | TransactionReceipt[]) => void; // An optional callback function that exposes transaction hash
onSuccess?: (response: TransactionResponse) => void; // An optional callback function that exposes the transaction receipts
};

/**
* Note: exported as public Type
*/
export type TransactionResponse = {
transactionReceipts: TransactionReceipt[];
};

/**
Expand Down

0 comments on commit 466ec1f

Please sign in to comment.