From c412df84aa5748f1e19236e9bcfbe949a0d41619 Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 19 Nov 2024 23:24:58 +0800 Subject: [PATCH] feat: add spore demo --- .changeset/real-geckos-fry.md | 5 + packages/demo/package.json | 1 - .../connected/(tools)/CreateCluster/page.tsx | 198 ++++++++++++++++++ .../app/connected/(tools)/MintSpore/page.tsx | 101 +++++++++ .../(tools)/TransferCluster/page.tsx | 100 +++++++++ .../connected/(tools)/TransferSpore/page.tsx | 136 ++++++++++++ packages/demo/src/app/connected/page.tsx | 14 ++ packages/spore/src/cluster/index.ts | 53 +++-- packages/spore/src/spore/index.ts | 70 ++++--- pnpm-lock.yaml | 3 - 10 files changed, 630 insertions(+), 51 deletions(-) create mode 100644 .changeset/real-geckos-fry.md create mode 100644 packages/demo/src/app/connected/(tools)/CreateCluster/page.tsx create mode 100644 packages/demo/src/app/connected/(tools)/MintSpore/page.tsx create mode 100644 packages/demo/src/app/connected/(tools)/TransferCluster/page.tsx create mode 100644 packages/demo/src/app/connected/(tools)/TransferSpore/page.tsx diff --git a/.changeset/real-geckos-fry.md b/.changeset/real-geckos-fry.md new file mode 100644 index 00000000..2e6dfe41 --- /dev/null +++ b/.changeset/real-geckos-fry.md @@ -0,0 +1,5 @@ +--- +"@ckb-ccc/spore": patch +--- + +refactor(spore): unified findSpore(s) interface diff --git a/packages/demo/package.json b/packages/demo/package.json index 6afbc559..ed50074f 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -24,7 +24,6 @@ "devDependencies": { "@ckb-ccc/connector-react": "workspace:*", "@ckb-ccc/lumos-patches": "workspace:*", - "@ckb-ccc/udt": "workspace:*", "@ckb-lumos/ckb-indexer": "^0.24.0-next.1", "@ckb-lumos/common-scripts": "^0.24.0-next.1", "@ckb-lumos/config-manager": "^0.24.0-next.1", diff --git a/packages/demo/src/app/connected/(tools)/CreateCluster/page.tsx b/packages/demo/src/app/connected/(tools)/CreateCluster/page.tsx new file mode 100644 index 00000000..3b565d37 --- /dev/null +++ b/packages/demo/src/app/connected/(tools)/CreateCluster/page.tsx @@ -0,0 +1,198 @@ +"use client"; + +import React, { useEffect, useState } from "react"; +import { TextInput } from "@/src/components/Input"; +import { Button } from "@/src/components/Button"; +import { useGetExplorerLink } from "@/src/utils"; +import { useApp } from "@/src/context"; +import { ButtonsPanel } from "@/src/components/ButtonsPanel"; +import { ccc, spore } from "@ckb-ccc/connector-react"; +import { Textarea } from "@/src/components/Textarea"; + +function generateClusterDescriptionUnderDobProtocol( + client: ccc.Client, +): string { + /** + * Generation example for DOB0 + */ + const clusterDescription = "My First DOB Cluster"; + const dob0Pattern: spore.dob.PatternElementDob0[] = [ + { + traitName: "BackgroundColor", + dobType: "String", + dnaOffset: 0, + dnaLength: 1, + patternType: "options", + traitArgs: ["red", "blue", "green", "black", "white"], + }, + { + traitName: "FontSize", + dobType: "Number", + dnaOffset: 1, + dnaLength: 1, + patternType: "range", + traitArgs: [10, 50], + }, + { + traitName: "FontFamily", + dobType: "String", + dnaOffset: 2, + dnaLength: 1, + patternType: "options", + traitArgs: ["Arial", "Helvetica", "Times New Roman", "Courier New"], + }, + { + traitName: "Timestamp", + dobType: "Number", + dnaOffset: 3, + dnaLength: 4, + patternType: "rawNumber", + }, + { + traitName: "ConsoleLog", + dobType: "String", + dnaOffset: 7, + dnaLength: 13, + patternType: "utf8", + }, + ]; + + /** + * Generation example for DOB1 + */ + const dob1Pattern: spore.dob.PatternElementDob1[] = [ + { + imageName: "IMAGE.0", + svgFields: "attributes", + traitName: "", + patternType: "raw", + traitArgs: "xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 200'", + }, + { + imageName: "IMAGE.0", + svgFields: "elements", + traitName: "Timestamp", + patternType: "options", + traitArgs: [ + [ + [0, 1000000], + "", + ], + [ + ["*"], + "", + ], + ], + }, + { + imageName: "IMAGE.0", + svgFields: "elements", + traitName: "BackgroundColor", + patternType: "options", + traitArgs: [ + ["red", ""], + ["blud", ""], + ["green", ""], + [["*"], ""], + ], + }, + { + imageName: "IMAGE.0", + svgFields: "elements", + traitName: "ConsoleLog", + patternType: "options", + traitArgs: [ + [ + "hello, world!", + "", + ], + [ + ["*"], + "", + ], + ], + }, + ]; + const dob1: spore.dob.Dob1 = { + description: clusterDescription, + dob: { + ver: 1, + decoders: [ + { + decoder: spore.dob.getDecoder(client, "dob0"), + pattern: dob0Pattern, + }, + { + decoder: spore.dob.getDecoder(client, "dob1"), + pattern: dob1Pattern, + }, + ], + }, + }; + return spore.dob.encodeClusterDescriptionForDob1(dob1); +} +export default function CreateCluster() { + const { signer, createSender } = useApp(); + const { client } = ccc.useCcc(); + const { log } = createSender("Create Cluster"); + + const { explorerTransaction } = useGetExplorerLink(); + + const [name, SetName] = useState(""); + const [description, setDescription] = useState(""); + + useEffect(() => { + setDescription( + JSON.stringify( + JSON.parse(generateClusterDescriptionUnderDobProtocol(client)), + undefined, + 2, + ), + ); + }, [client]); + + return ( +
+ +