Skip to content

Commit 6679b40

Browse files
committed
Added an optional waitForTransactionOptions parameter to the useTransact hook and waitForTransationResponse parameter to its onSuccess handler. Updated docs accordingly. Updated some dependencies. Incremented project version.
1 parent 0bf0e39 commit 6679b40

File tree

7 files changed

+1216
-940
lines changed

7 files changed

+1216
-940
lines changed

apps/docs/package.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
"deploy:firebase": "firebase deploy --only hosting"
1414
},
1515
"dependencies": {
16-
"@mysten/dapp-kit": "^0.14.47",
17-
"@mysten/sui": "^1.20.0",
16+
"@mysten/dapp-kit": "^0.14.48",
17+
"@mysten/sui": "^1.21.0",
1818
"@mysten/suins": "^0.4.2",
19-
"@mysten/wallet-standard": "^0.13.23",
20-
"@radix-ui/react-select": "^2.1.4",
19+
"@mysten/wallet-standard": "^0.13.24",
20+
"@radix-ui/react-select": "^2.1.5",
2121
"@radix-ui/react-toggle": "^1.1.1",
22-
"@radix-ui/themes": "^3.1.6",
22+
"@radix-ui/themes": "^3.2.0",
2323
"@suiware/kit": "workspace:*",
2424
"@tanstack/react-query": "^5.64.2",
2525
"bignumber.js": "^9.1.2",
@@ -31,24 +31,24 @@
3131
"react-use": "^17.6.0"
3232
},
3333
"devDependencies": {
34-
"@types/node": "^22.10.7",
35-
"@types/react": "^19.0.7",
34+
"@types/node": "^22.10.10",
35+
"@types/react": "^19.0.8",
3636
"@types/react-dom": "^19.0.3",
37-
"@typescript-eslint/eslint-plugin": "^8.20.0",
38-
"@typescript-eslint/parser": "^8.20.0",
37+
"@typescript-eslint/eslint-plugin": "^8.21.0",
38+
"@typescript-eslint/parser": "^8.21.0",
3939
"@vitejs/plugin-react-swc": "^3.7.2",
4040
"autoprefixer": "^10.4.20",
4141
"env-file-rw": "^1.0.0",
42-
"eslint": "^9.18.0",
42+
"eslint": "^9.19.0",
4343
"eslint-config-prettier": "^9.1.0",
4444
"eslint-plugin-react-hooks": "^5.1.0",
4545
"eslint-plugin-react-refresh": "^0.4.18",
4646
"postcss": "^8.5.1",
4747
"prettier": "^3.4.2",
48-
"prettier-plugin-tailwindcss": "^0.6.10",
48+
"prettier-plugin-tailwindcss": "^0.6.11",
4949
"tailwindcss": "^3.4.17",
5050
"typescript": "^5.7.3",
51-
"vite": "^6.0.9",
51+
"vite": "^6.0.11",
5252
"vite-tsconfig-paths": "^5.1.4"
5353
}
5454
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"docs:deploy": "pnpm --filter=docs deploy:firebase"
1414
},
1515
"devDependencies": {
16-
"@changesets/cli": "^2.27.11",
16+
"@changesets/cli": "^2.27.12",
1717
"prettier": "^3.4.2",
18-
"turbo": "^2.3.3"
18+
"turbo": "^2.3.4"
1919
},
2020
"packageManager": "pnpm@9.15.0",
2121
"name": "suiware-kit-monorepo"

packages/eslint-config/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"devDependencies": {
1111
"@vercel/style-guide": "^6.0.0",
12-
"eslint-config-turbo": "^2.3.3",
12+
"eslint-config-turbo": "^2.3.4",
1313
"eslint-plugin-mdx": "^3.1.5",
1414
"eslint-plugin-only-warn": "^1.1.0",
1515
"eslint-plugin-storybook": "^0.8.0"

packages/kit/docs/useTransact.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ function MyComponent() {
1717
const { transact } = useTransact({
1818
onBeforeStart: () => console.log('Transaction starting...'),
1919
onSuccess: (data) => console.log('Transaction succeeded:', data),
20-
onError: (e) => console.error('Transaction failed:', e)
20+
onError: (e) => console.error('Transaction failed:', e),
21+
waitForTransactionOptions: {
22+
showEffects: true,
23+
},
2124
})
2225

2326
const handleTransaction = () => {
@@ -41,8 +44,9 @@ The hook accepts an options object with the following properties:
4144
| Parameter | Type | Description |
4245
| --- | --- | --- |
4346
| onBeforeStart | () => void | (Optional) Callback executed when user triggers a transaction |
44-
| onSuccess | (data: SuiSignAndExecuteTransactionOutput) => void | (Optional) Callback executed after successful transaction completion |
47+
| onSuccess | (data: SuiSignAndExecuteTransactionOutput, waitForTransactionResponse: SuiTransactionBlockResponse) => void | (Optional) Callback executed when transaction succeeds |
4548
| onError | (e: Error) => void | (Optional) Callback executed if transaction fails |
49+
| waitForTransactionOptions | SuiTransactionBlockResponseOptions | (Optional) Options for waitForTransaction call |
4650

4751
## Return Value
4852

packages/kit/package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@suiware/kit",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"sideEffects": false,
55
"license": "MIT",
66
"type": "commonjs",
@@ -131,30 +131,30 @@
131131
"styles": "tailwindcss -c ./tailwind.config.mjs -i ./src/styles/main.css -o ./dist/main.css --minify"
132132
},
133133
"devDependencies": {
134-
"@mysten/dapp-kit": "^0.14.47",
135-
"@mysten/sui": "^1.20.0",
134+
"@mysten/dapp-kit": "^0.14.48",
135+
"@mysten/sui": "^1.21.0",
136136
"@mysten/suins": "^0.4.2",
137-
"@mysten/wallet-standard": "^0.13.23",
137+
"@mysten/wallet-standard": "^0.13.24",
138138
"@radix-ui/colors": "^3.0.0",
139139
"@repo/eslint-config": "workspace:*",
140140
"@repo/typescript-config": "workspace:*",
141141
"@tanstack/react-query": "^5.64.2",
142142
"@types/lodash.debounce": "^4.0.9",
143-
"@types/node": "^22.10.7",
144-
"@types/react": "^19.0.7",
143+
"@types/node": "^22.10.10",
144+
"@types/react": "^19.0.8",
145145
"@types/react-dom": "^19.0.3",
146146
"autoprefixer": "^10.4.20",
147147
"eslint": "^8.57.1",
148148
"postcss": "^8.5.1",
149149
"prettier": "^3.4.2",
150-
"prettier-plugin-tailwindcss": "^0.6.10",
150+
"prettier-plugin-tailwindcss": "^0.6.11",
151151
"react": "^19.0.0",
152152
"tailwindcss": "^3.4.17",
153-
"tsup": "^8.3.5",
153+
"tsup": "^8.3.6",
154154
"typescript": "^5.7.3"
155155
},
156156
"dependencies": {
157-
"@radix-ui/themes": "^3.1.6",
157+
"@radix-ui/themes": "^3.2.0",
158158
"bignumber.js": "^9.1.2",
159159
"lodash.debounce": "^4.0.8",
160160
"lucide-react": "^0.469.0"

packages/kit/src/hooks/useTransact.tsx

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
import { useSignAndExecuteTransaction, useSuiClient } from '@mysten/dapp-kit'
2+
import { SuiTransactionBlockResponse, SuiTransactionBlockResponseOptions } from '@mysten/sui/client'
23
import { Transaction } from '@mysten/sui/transactions'
34
import type { SuiSignAndExecuteTransactionOutput } from '@mysten/wallet-standard'
45

56
export interface IUseTransactParams {
6-
/**
7+
/**
78
* (Optional) Is executed when user triggers a transaction.
89
*/
910
onBeforeStart?: () => void
1011
/**
1112
* (Optional) React on success, e.g. refetch dependent queries.
1213
*
1314
* @param {SuiSignAndExecuteTransactionOutput} data The transaction output.
15+
* @param {SuiTransactionBlockResponse} waitForTransactionResponse The transaction response.
1416
*/
15-
onSuccess?: (data: SuiSignAndExecuteTransactionOutput) => void
17+
onSuccess?: (data: SuiSignAndExecuteTransactionOutput, waitForTransactionResponse: SuiTransactionBlockResponse) => void
1618
/**
1719
* (Optional) React on error.
1820
*
1921
* @param {Error} e The error.
2022
*/
2123
onError?: (e: Error) => void
24+
25+
/**
26+
* (Optional) Options for waitForTransaction call.
27+
*/
28+
waitForTransactionOptions?: SuiTransactionBlockResponseOptions
2229
}
2330

2431
export interface IUseTransactResponse {
@@ -33,18 +40,13 @@ export interface IUseTransactResponse {
3340
/**
3441
* The useTransact() hook lets you perform a transaction on the Sui network.
3542
*
36-
* When user triggers a transaction, we display a notification to confirm that transaction in their wallet.
37-
* Once user confirmed or rejected the transaction, we convert that notification to a success message or error message.
38-
* The success message will have a link to a Sui Explorer depending on the active network.
39-
* In case of error, we additionally print full error message in the browser console.
40-
*
4143
* Usage:
4244
* ```ts
4345
* import type { SuiSignAndExecuteTransactionOutput } from '@mysten/wallet-standard'
4446
* import { Transaction } from '@mysten/sui/transactions'
4547
* const { transact: greet } = useTransact({
4648
* onBeforeStart: () => {},
47-
* onSuccess: (data: SuiSignAndExecuteTransactionOutput) => {},
49+
* onSuccess: (data: SuiSignAndExecuteTransactionOutput, waitForTransactionResponse: SuiTransactionBlockResponse) => {},
4850
* onError: (e: Error) => {}
4951
* })
5052
*
@@ -67,6 +69,7 @@ const useTransact = ({
6769
onBeforeStart,
6870
onSuccess,
6971
onError,
72+
waitForTransactionOptions,
7073
}: IUseTransactParams = {}): IUseTransactResponse => {
7174
const client = useSuiClient()
7275
const { mutate: signAndExecute } = useSignAndExecuteTransaction()
@@ -90,10 +93,11 @@ const useTransact = ({
9093
client
9194
.waitForTransaction({
9295
digest: data.digest,
96+
options: waitForTransactionOptions,
9397
})
94-
.then(() => {
98+
.then((response: SuiTransactionBlockResponse) => {
9599
if (onSuccess != null) {
96-
onSuccess(data)
100+
onSuccess(data, response)
97101
}
98102
})
99103
.catch((e) => {

0 commit comments

Comments
 (0)