@mysten/create-dapp 0.0.0-experimental-20231012175001

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE +201 -0
  3. package/README.md +33 -0
  4. package/bin/index.js +4 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +95 -0
  7. package/dist/index.js.map +1 -0
  8. package/package.json +49 -0
  9. package/src/index.ts +120 -0
  10. package/templates/react-client-dapp/CHANGELOG.md +14 -0
  11. package/templates/react-client-dapp/README.md +35 -0
  12. package/templates/react-client-dapp/index.html +59 -0
  13. package/templates/react-client-dapp/node_modules/.bin/eslint +17 -0
  14. package/templates/react-client-dapp/node_modules/.bin/prettier +17 -0
  15. package/templates/react-client-dapp/node_modules/.bin/tsc +17 -0
  16. package/templates/react-client-dapp/node_modules/.bin/tsserver +17 -0
  17. package/templates/react-client-dapp/node_modules/.bin/vite +17 -0
  18. package/templates/react-client-dapp/package.json +35 -0
  19. package/templates/react-client-dapp/prettier.config.cjs +4 -0
  20. package/templates/react-client-dapp/src/App.tsx +39 -0
  21. package/templates/react-client-dapp/src/OwnedObjects.tsx +42 -0
  22. package/templates/react-client-dapp/src/WalletStatus.tsx +23 -0
  23. package/templates/react-client-dapp/src/main.tsx +32 -0
  24. package/templates/react-client-dapp/src/vite-env.d.ts +1 -0
  25. package/templates/react-client-dapp/tsconfig.json +25 -0
  26. package/templates/react-client-dapp/tsconfig.node.json +10 -0
  27. package/templates/react-client-dapp/vite.config.ts +7 -0
  28. package/templates/react-e2e-counter/CHANGELOG.md +14 -0
  29. package/templates/react-e2e-counter/README.md +99 -0
  30. package/templates/react-e2e-counter/index.html +59 -0
  31. package/templates/react-e2e-counter/move/counter/Move.toml +9 -0
  32. package/templates/react-e2e-counter/move/counter/sources/counter.move +53 -0
  33. package/templates/react-e2e-counter/node_modules/.bin/eslint +17 -0
  34. package/templates/react-e2e-counter/node_modules/.bin/prettier +17 -0
  35. package/templates/react-e2e-counter/node_modules/.bin/tsc +17 -0
  36. package/templates/react-e2e-counter/node_modules/.bin/tsserver +17 -0
  37. package/templates/react-e2e-counter/node_modules/.bin/vite +17 -0
  38. package/templates/react-e2e-counter/package.json +35 -0
  39. package/templates/react-e2e-counter/prettier.config.cjs +4 -0
  40. package/templates/react-e2e-counter/src/App.tsx +61 -0
  41. package/templates/react-e2e-counter/src/Counter.tsx +90 -0
  42. package/templates/react-e2e-counter/src/CreateCounter.tsx +63 -0
  43. package/templates/react-e2e-counter/src/constants.ts +2 -0
  44. package/templates/react-e2e-counter/src/main.tsx +32 -0
  45. package/templates/react-e2e-counter/src/vite-env.d.ts +1 -0
  46. package/templates/react-e2e-counter/tsconfig.json +25 -0
  47. package/templates/react-e2e-counter/tsconfig.node.json +10 -0
  48. package/templates/react-e2e-counter/vite.config.ts +7 -0
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@mysten/template-react-e2e-coinflip",
3
+ "private": true,
4
+ "version": "0.0.0-experimental-20231012175001",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc && vite build",
9
+ "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
10
+ "preview": "vite preview"
11
+ },
12
+ "dependencies": {
13
+ "@mysten/dapp-kit": "workspace:*",
14
+ "@mysten/sui.js": "workspace:*",
15
+ "@radix-ui/colors": "^3.0.0",
16
+ "@radix-ui/react-icons": "^1.3.0",
17
+ "@radix-ui/themes": "^2.0.0",
18
+ "@tanstack/react-query": "^4.29.25",
19
+ "react": "^18.2.0",
20
+ "react-dom": "^18.2.0"
21
+ },
22
+ "devDependencies": {
23
+ "@types/react": "^18.2.15",
24
+ "@types/react-dom": "^18.2.7",
25
+ "@typescript-eslint/eslint-plugin": "^6.1.0",
26
+ "@typescript-eslint/parser": "^6.1.0",
27
+ "@vitejs/plugin-react-swc": "^3.3.2",
28
+ "eslint": "^8.45.0",
29
+ "eslint-plugin-react-hooks": "^4.6.0",
30
+ "eslint-plugin-react-refresh": "^0.4.3",
31
+ "prettier": "^3.0.0",
32
+ "typescript": "^5.1.6",
33
+ "vite": "^4.4.4"
34
+ }
35
+ }
@@ -0,0 +1,4 @@
1
+ // eslint-disable-next-line no-undef
2
+ module.exports = {
3
+ proseWrap: "always",
4
+ };
@@ -0,0 +1,61 @@
1
+ import { ConnectButton, useCurrentAccount } from "@mysten/dapp-kit";
2
+ import { isValidSuiObjectId } from "@mysten/sui.js/utils";
3
+ import { Box, Container, Flex, Heading } from "@radix-ui/themes";
4
+ import { useState } from "react";
5
+ import { Counter } from "./Counter";
6
+ import { CreateCounter } from "./CreateCounter";
7
+
8
+ function App() {
9
+ const currentAccount = useCurrentAccount();
10
+ const [counterId, setCounter] = useState(() => {
11
+ const hash = window.location.hash.slice(1);
12
+ return isValidSuiObjectId(hash) ? hash : null;
13
+ });
14
+
15
+ return (
16
+ <>
17
+ <Flex
18
+ position="sticky"
19
+ px="4"
20
+ py="2"
21
+ justify="between"
22
+ style={{
23
+ borderBottom: "1px solid var(--gray-a2)",
24
+ }}
25
+ >
26
+ <Box>
27
+ <Heading>dApp Starter Template</Heading>
28
+ </Box>
29
+
30
+ <Box>
31
+ <ConnectButton />
32
+ </Box>
33
+ </Flex>
34
+ <Container>
35
+ <Container
36
+ mt="5"
37
+ pt="2"
38
+ px="4"
39
+ style={{ background: "var(--gray-a2)", minHeight: 500 }}
40
+ >
41
+ {currentAccount ? (
42
+ counterId ? (
43
+ <Counter id={counterId} />
44
+ ) : (
45
+ <CreateCounter
46
+ onCreated={(id) => {
47
+ window.location.hash = id;
48
+ setCounter(id);
49
+ }}
50
+ />
51
+ )
52
+ ) : (
53
+ <Heading>Please connect your wallet</Heading>
54
+ )}
55
+ </Container>
56
+ </Container>
57
+ </>
58
+ );
59
+ }
60
+
61
+ export default App;
@@ -0,0 +1,90 @@
1
+ import {
2
+ useCurrentAccount,
3
+ useSignAndExecuteTransactionBlock,
4
+ useSuiClient,
5
+ useSuiClientQuery,
6
+ } from "@mysten/dapp-kit";
7
+ import { SuiObjectData } from "@mysten/sui.js/client";
8
+ import { TransactionBlock } from "@mysten/sui.js/transactions";
9
+ import { Button, Flex, Heading, Text } from "@radix-ui/themes";
10
+ import { PACKAGE_ID } from "./constants";
11
+
12
+ export function Counter({ id }: { id: string }) {
13
+ const client = useSuiClient();
14
+ const currentAccount = useCurrentAccount();
15
+ const { mutate: signAndExecute } = useSignAndExecuteTransactionBlock();
16
+ const { data, isLoading, error, refetch } = useSuiClientQuery("getObject", {
17
+ id,
18
+ options: {
19
+ showContent: true,
20
+ showOwner: true,
21
+ },
22
+ });
23
+
24
+ const executeMoveCall = (method: "increment" | "reset") => {
25
+ const txb = new TransactionBlock();
26
+
27
+ if (method === "reset") {
28
+ txb.moveCall({
29
+ arguments: [txb.object(id), txb.pure.u64(0)],
30
+ target: `${PACKAGE_ID}::counter::set_value`,
31
+ });
32
+ } else {
33
+ txb.moveCall({
34
+ arguments: [txb.object(id)],
35
+ target: `${PACKAGE_ID}::counter::increment`,
36
+ });
37
+ }
38
+
39
+ signAndExecute(
40
+ {
41
+ transactionBlock: txb,
42
+ options: {
43
+ showEffects: true,
44
+ showObjectChanges: true,
45
+ },
46
+ },
47
+ {
48
+ onSuccess: (tx) => {
49
+ client.waitForTransactionBlock({ digest: tx.digest }).then(() => {
50
+ refetch();
51
+ });
52
+ },
53
+ },
54
+ );
55
+ };
56
+
57
+ if (isLoading) return <Text>Loading...</Text>;
58
+
59
+ if (error) return <Text>Error: {error.message}</Text>;
60
+
61
+ if (!data.data) return <Text>Not found</Text>;
62
+
63
+ const ownedByCurrentAccount =
64
+ getCounterFields(data.data)?.owner === currentAccount?.address;
65
+
66
+ return (
67
+ <>
68
+ <Heading size="3">Counter {id}</Heading>
69
+
70
+ <Flex direction="column" gap="2">
71
+ <Text>Count: {getCounterFields(data.data)?.value}</Text>
72
+ <Flex direction="row" gap="2">
73
+ <Button onClick={() => executeMoveCall("increment")}>
74
+ Increment
75
+ </Button>
76
+ {ownedByCurrentAccount ? (
77
+ <Button onClick={() => executeMoveCall("reset")}>Reset</Button>
78
+ ) : null}
79
+ </Flex>
80
+ </Flex>
81
+ </>
82
+ );
83
+ }
84
+ function getCounterFields(data: SuiObjectData) {
85
+ if (data.content?.dataType !== "moveObject") {
86
+ return null;
87
+ }
88
+
89
+ return data.content.fields as { value: number; owner: string };
90
+ }
@@ -0,0 +1,63 @@
1
+ import { TransactionBlock } from "@mysten/sui.js/transactions";
2
+ import { Button, Container } from "@radix-ui/themes";
3
+ import { PACKAGE_ID } from "./constants";
4
+ import {
5
+ useSignAndExecuteTransactionBlock,
6
+ useSuiClient,
7
+ } from "@mysten/dapp-kit";
8
+
9
+ export function CreateCounter({
10
+ onCreated,
11
+ }: {
12
+ onCreated: (id: string) => void;
13
+ }) {
14
+ const client = useSuiClient();
15
+ const { mutate: signAndExecute } = useSignAndExecuteTransactionBlock();
16
+
17
+ return (
18
+ <Container>
19
+ <Button
20
+ size="3"
21
+ onClick={() => {
22
+ create();
23
+ }}
24
+ >
25
+ Create Counter
26
+ </Button>
27
+ </Container>
28
+ );
29
+
30
+ function create() {
31
+ const txb = new TransactionBlock();
32
+
33
+ txb.moveCall({
34
+ arguments: [],
35
+ target: `${PACKAGE_ID}::counter::create`,
36
+ });
37
+
38
+ signAndExecute(
39
+ {
40
+ transactionBlock: txb,
41
+ options: {
42
+ showEffects: true,
43
+ showObjectChanges: true,
44
+ },
45
+ },
46
+ {
47
+ onSuccess: (tx) => {
48
+ client
49
+ .waitForTransactionBlock({
50
+ digest: tx.digest,
51
+ })
52
+ .then(() => {
53
+ const objectId = tx.effects?.created?.[0]?.reference?.objectId;
54
+
55
+ if (objectId) {
56
+ onCreated(objectId);
57
+ }
58
+ });
59
+ },
60
+ },
61
+ );
62
+ }
63
+ }
@@ -0,0 +1,2 @@
1
+ export const PACKAGE_ID =
2
+ "0x224f49ba0ca915646c3e40bab06259ce1c27516f2873a01e560b43e3e2543ed2";
@@ -0,0 +1,32 @@
1
+ import React from "react";
2
+ import ReactDOM from "react-dom/client";
3
+ import "@mysten/dapp-kit/dist/index.css";
4
+ import "@radix-ui/themes/styles.css";
5
+
6
+ import { getFullnodeUrl } from "@mysten/sui.js/client";
7
+ import { SuiClientProvider, WalletProvider } from "@mysten/dapp-kit";
8
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
9
+ import { Theme } from "@radix-ui/themes";
10
+ import App from "./App.tsx";
11
+
12
+ const queryClient = new QueryClient();
13
+ const networks = {
14
+ localnet: { url: getFullnodeUrl("localnet") },
15
+ devnet: { url: getFullnodeUrl("devnet") },
16
+ testnet: { url: getFullnodeUrl("testnet") },
17
+ mainnet: { url: getFullnodeUrl("mainnet") },
18
+ };
19
+
20
+ ReactDOM.createRoot(document.getElementById("root")!).render(
21
+ <React.StrictMode>
22
+ <Theme appearance="dark">
23
+ <QueryClientProvider client={queryClient}>
24
+ <SuiClientProvider networks={networks} defaultNetwork="devnet">
25
+ <WalletProvider autoConnect>
26
+ <App />
27
+ </WalletProvider>
28
+ </SuiClientProvider>
29
+ </QueryClientProvider>
30
+ </Theme>
31
+ </React.StrictMode>,
32
+ );
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "noEmit": true,
15
+ "jsx": "react-jsx",
16
+
17
+ /* Linting */
18
+ "strict": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "noFallthroughCasesInSwitch": true
22
+ },
23
+ "include": ["src"],
24
+ "references": [{ "path": "./tsconfig.node.json" }]
25
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true
8
+ },
9
+ "include": ["vite.config.ts"]
10
+ }
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from "vite";
2
+ import react from "@vitejs/plugin-react-swc";
3
+
4
+ // https://vitejs.dev/config/
5
+ export default defineConfig({
6
+ plugins: [react()],
7
+ });