Skip to content

Commit f18bff0

Browse files
authored
refactor: Receive any argumentss on execute method from useTransaction (#276)
* Receive any argumentss on execute method from useTransaction * Create strong-suns-sort.md
1 parent b01ff1e commit f18bff0

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

.changeset/strong-suns-sort.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@web3-ui/hooks": minor
3+
---
4+
5+
You can now pass in args to the exec fn in useTransaction just like you would with ethers. You don't need to pass it all inside an array anymore.
6+
7+
```tsx
8+
execute(['Hello', { value: '10' }]);
9+
10+
// is now
11+
execute('Hello', { value: '10' });
12+
```

packages/hooks/README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,9 @@ import { useTransaction, useWriteContract } from '@web3-ui/hooks';
175175
const greeterContract = useWriteContract('CONTRACT_ADDRESS', 'CONTRACT_ABI');
176176
const [execute, loading, error] = useTransaction(greeter.setGreeting);
177177

178-
await execute([
179-
'Hello, world!',
180-
{
181-
value: ethers.utils.parseEther('0.1'), // you can also use this for payable transactions
182-
},
183-
]); // will execute the transaction
178+
await execute('Hello, world!', {
179+
value: ethers.utils.parseEther('0.1'), // you can also use this for payable transactions
180+
}); // will execute the transaction
184181
```
185182

186183
---

packages/hooks/src/hooks/useTransaction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react';
44
* @dev Hook to get the loading status, error, and data of a function call.
55
* @param method The contract function you want to call
66
* @returns {
7-
* execute: (args: any[]) => Promise<any>,
7+
* execute: (args: any) => Promise<any>,
88
* loading: boolean,
99
* error: null | Error,
1010
* } {
@@ -16,11 +16,11 @@ import React from 'react';
1616

1717
export function useTransaction(
1818
method
19-
): [(args: any[]) => Promise<any>, boolean, any] {
19+
): [(args: any) => Promise<any>, boolean, any] {
2020
const [loading, setLoading] = React.useState<boolean>(false);
2121
const [error, setError] = React.useState<any>(null);
2222

23-
const execute = async (args: any[]) => {
23+
const execute = async (...args: any) => {
2424
setLoading(true);
2525
setError(null);
2626
try {

packages/hooks/src/stories/UseTransaction.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const UsingUseWriteContract = () => {
9797
<Button
9898
type="submit"
9999
isLoading={loading}
100-
onClick={() => setGreeting([value])}
100+
onClick={() => setGreeting(value)}
101101
>
102102
Set Greeting
103103
</Button>

0 commit comments

Comments
 (0)