@iota/create-dapp 0.3.10 → 0.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @iota/create-dapp
2
2
 
3
+ ## 0.3.11
4
+
5
+ ### Patch Changes
6
+
7
+ - d8e3086: Fixes issue regarding refetching object data too soon after executing transactions
8
+ - Updated dependencies [40576ed]
9
+ - Updated dependencies [61b0944]
10
+ - Updated dependencies [966f83c]
11
+ - Updated dependencies [f008db3]
12
+ - Updated dependencies [733df30]
13
+ - Updated dependencies [13ca264]
14
+ - Updated dependencies [5bbafa8]
15
+ - Updated dependencies [28ce666]
16
+ - Updated dependencies [c855f8c]
17
+ - Updated dependencies [f008db3]
18
+ - Updated dependencies [464c15a]
19
+ - Updated dependencies [75554e6]
20
+ - @iota/iota-sdk@1.5.0
21
+ - @iota/dapp-kit@0.5.1
22
+
3
23
  ## 0.3.10
4
24
 
5
25
  ### Patch Changes
package/README.md CHANGED
@@ -29,7 +29,7 @@ you including:
29
29
  - [Vite](https://vitejs.dev/)
30
30
  - [Radix UI](https://www.radix-ui.com/)
31
31
  - [ESLint](https://eslint.org/)
32
- - [`@iota/dapp-kit`](https://docs.iota.org/ts-sdk/dapp-kit)
32
+ - [`@iota/dapp-kit`](https://docs.iota.org/developer/ts-sdk/dapp-kit)
33
33
 
34
34
  These templates are still new, and would love to get feedback and suggestions for improvements or
35
35
  future templates. Please open an issue on GitHub if you have any feedback.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "IOTA Foundation <info@iota.org>",
4
4
  "description": "A CLI for creating new IOTA dApps",
5
5
  "homepage": "https://docs.iota.org/ts-sdk/typescript/",
6
- "version": "0.3.10",
6
+ "version": "0.3.11",
7
7
  "license": "Apache-2.0",
8
8
  "files": [
9
9
  "CHANGELOG.md",
@@ -27,8 +27,8 @@
27
27
  "dependencies": {
28
28
  "@types/node": "^20.14.10",
29
29
  "enquirer": "^2.4.1",
30
- "@iota/iota-sdk": "1.4.0",
31
- "@iota/dapp-kit": "0.5.0"
30
+ "@iota/dapp-kit": "0.5.1",
31
+ "@iota/iota-sdk": "1.5.0"
32
32
  },
33
33
  "sideEffects": false,
34
34
  "bin": "./bin/index.js",
@@ -8,7 +8,7 @@ Client dApp using the following tools:
8
8
  - [Vite](https://vitejs.dev/) for build tooling
9
9
  - [Radix UI](https://www.radix-ui.com/) for pre-built UI components
10
10
  - [ESLint](https://eslint.org/)
11
- - [`@iota/dapp-kit`](https://docs.iota.org/ts-sdk/dapp-kit) for
11
+ - [`@iota/dapp-kit`](https://docs.iota.org/developer/ts-sdk/dapp-kit) for
12
12
  connecting to wallets and loading data
13
13
  - [pnpm](https://pnpm.io/) for package management
14
14
 
@@ -8,7 +8,7 @@ Client dApp using the following tools:
8
8
  - [Vite](https://vitejs.dev/) for build tooling
9
9
  - [Radix UI](https://www.radix-ui.com/) for pre-built UI components
10
10
  - [ESLint](https://eslint.org/) for linting
11
- - [`@iota/dapp-kit`](https://docs.iota.org/ts-sdk/dapp-kit) for
11
+ - [`@iota/dapp-kit`](https://docs.iota.org/developer/ts-sdk/dapp-kit) for
12
12
  connecting to wallets and loading data
13
13
  - [pnpm](https://pnpm.io/) for package management
14
14
 
@@ -16,7 +16,8 @@
16
16
  "@radix-ui/themes": "^3.1.1",
17
17
  "@tanstack/react-query": "^5.50.1",
18
18
  "react": "^18.3.1",
19
- "react-dom": "^18.3.1"
19
+ "react-dom": "^18.3.1",
20
+ "react-spinners": "^0.14.1"
20
21
  },
21
22
  "devDependencies": {
22
23
  "@eslint/js": "^9.17.0",
@@ -8,23 +8,14 @@ import type { IotaObjectData } from "@iota/iota-sdk/client";
8
8
  import { Transaction } from "@iota/iota-sdk/transactions";
9
9
  import { Button, Flex, Heading, Text } from "@radix-ui/themes";
10
10
  import { useNetworkVariable } from "./networkConfig";
11
+ import { useState } from "react";
12
+ import ClipLoader from "react-spinners/ClipLoader";
11
13
 
12
14
  export function Counter({ id }: { id: string }) {
13
15
  const counterPackageId = useNetworkVariable("counterPackageId");
14
16
  const iotaClient = useIotaClient();
15
17
  const currentAccount = useCurrentAccount();
16
- const { mutate: signAndExecute } = useSignAndExecuteTransaction({
17
- execute: async ({ bytes, signature }) =>
18
- await iotaClient.executeTransactionBlock({
19
- transactionBlock: bytes,
20
- signature,
21
- options: {
22
- // Raw effects are required so the effects can be reported back to the wallet
23
- showRawEffects: true,
24
- showEffects: true,
25
- },
26
- }),
27
- });
18
+ const { mutate: signAndExecute } = useSignAndExecuteTransaction();
28
19
  const { data, isPending, error, refetch } = useIotaClientQuery("getObject", {
29
20
  id,
30
21
  options: {
@@ -33,7 +24,11 @@ export function Counter({ id }: { id: string }) {
33
24
  },
34
25
  });
35
26
 
27
+ const [waitingForTxn, setWaitingForTxn] = useState("");
28
+
36
29
  const executeMoveCall = (method: "increment" | "reset") => {
30
+ setWaitingForTxn(method);
31
+
37
32
  const tx = new Transaction();
38
33
 
39
34
  if (method === "reset") {
@@ -53,8 +48,13 @@ export function Counter({ id }: { id: string }) {
53
48
  transaction: tx,
54
49
  },
55
50
  {
56
- onSuccess: async () => {
57
- await refetch();
51
+ onSuccess: (tx) => {
52
+ iotaClient
53
+ .waitForTransaction({ digest: tx.digest })
54
+ .then(async () => {
55
+ await refetch();
56
+ setWaitingForTxn("");
57
+ });
58
58
  },
59
59
  },
60
60
  );
@@ -76,11 +76,23 @@ export function Counter({ id }: { id: string }) {
76
76
  <Flex direction="column" gap="2">
77
77
  <Text>Count: {getCounterFields(data.data)?.value}</Text>
78
78
  <Flex direction="row" gap="2">
79
- <Button onClick={() => executeMoveCall("increment")}>
80
- Increment
79
+ <Button
80
+ onClick={() => executeMoveCall("increment")}
81
+ disabled={waitingForTxn !== ""}
82
+ >
83
+ {waitingForTxn === "increment" ? (
84
+ <ClipLoader size={20} />
85
+ ) : (
86
+ "Increment"
87
+ )}
81
88
  </Button>
82
89
  {ownedByCurrentAccount ? (
83
- <Button onClick={() => executeMoveCall("reset")}>Reset</Button>
90
+ <Button
91
+ onClick={() => executeMoveCall("reset")}
92
+ disabled={waitingForTxn !== ""}
93
+ >
94
+ {waitingForTxn === "reset" ? <ClipLoader size={20} /> : "Reset"}
95
+ </Button>
84
96
  ) : null}
85
97
  </Flex>
86
98
  </Flex>
@@ -2,6 +2,7 @@ import { Transaction } from "@iota/iota-sdk/transactions";
2
2
  import { Button, Container } from "@radix-ui/themes";
3
3
  import { useSignAndExecuteTransaction, useIotaClient } from "@iota/dapp-kit";
4
4
  import { useNetworkVariable } from "./networkConfig";
5
+ import ClipLoader from "react-spinners/ClipLoader";
5
6
 
6
7
  export function CreateCounter({
7
8
  onCreated,
@@ -10,31 +11,11 @@ export function CreateCounter({
10
11
  }) {
11
12
  const counterPackageId = useNetworkVariable("counterPackageId");
12
13
  const iotaClient = useIotaClient();
13
- const { mutate: signAndExecute } = useSignAndExecuteTransaction({
14
- execute: async ({ bytes, signature }) =>
15
- await iotaClient.executeTransactionBlock({
16
- transactionBlock: bytes,
17
- signature,
18
- options: {
19
- // Raw effects are required so the effects can be reported back to the wallet
20
- showRawEffects: true,
21
- showEffects: true,
22
- },
23
- }),
24
- });
25
-
26
- return (
27
- <Container>
28
- <Button
29
- size="3"
30
- onClick={() => {
31
- create();
32
- }}
33
- >
34
- Create Counter
35
- </Button>
36
- </Container>
37
- );
14
+ const {
15
+ mutate: signAndExecute,
16
+ isSuccess,
17
+ isPending,
18
+ } = useSignAndExecuteTransaction();
38
19
 
39
20
  function create() {
40
21
  const tx = new Transaction();
@@ -49,13 +30,36 @@ export function CreateCounter({
49
30
  transaction: tx,
50
31
  },
51
32
  {
52
- onSuccess: (result) => {
53
- const objectId = result.effects?.created?.[0]?.reference?.objectId;
33
+ onSuccess: async ({ digest }) => {
34
+ const { effects } = await iotaClient.waitForTransaction({
35
+ digest: digest,
36
+ options: {
37
+ showEffects: true,
38
+ },
39
+ });
40
+
41
+ const objectId = effects?.created?.[0]?.reference?.objectId;
54
42
  if (objectId) {
55
43
  onCreated(objectId);
44
+ } else {
45
+ console.error("Failed to get objectId from transaction effects");
56
46
  }
57
47
  },
58
48
  },
59
49
  );
60
50
  }
51
+
52
+ return (
53
+ <Container>
54
+ <Button
55
+ size="3"
56
+ onClick={() => {
57
+ create();
58
+ }}
59
+ disabled={isSuccess || isPending}
60
+ >
61
+ {isSuccess || isPending ? <ClipLoader size={20} /> : "Create Counter"}
62
+ </Button>
63
+ </Container>
64
+ );
61
65
  }