Skip to content

Commit 7b2d09d

Browse files
committed
solang cnft example
1 parent 90080ff commit 7b2d09d

31 files changed

+1502
-0
lines changed

compression/cnft-solang/.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
.anchor
3+
.DS_Store
4+
target
5+
**/*.rs.bk
6+
node_modules
7+
test-ledger
8+
.yarn
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
.anchor
3+
.DS_Store
4+
target
5+
node_modules
6+
dist
7+
build
8+
test-ledger

compression/cnft-solang/Anchor.toml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[features]
2+
seeds = false
3+
skip-lint = false
4+
[programs.devnet]
5+
compressed_nft = "BhDH6TLEnf4dLq9hLn2gLwm5rJdj8Cbdc9ZrsjUpL7kB"
6+
7+
[registry]
8+
url = "https://api.apr.dev"
9+
10+
[provider]
11+
cluster = "devnet"
12+
wallet = "~/.config/solana/id.json"
13+
14+
[scripts]
15+
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
16+
17+
[test.validator]
18+
url = "https://api.mainnet-beta.solana.com"
19+
20+
[[test.validator.clone]]
21+
address = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
22+
23+
[[test.validator.clone]]
24+
address = "BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY"
25+
26+
[[test.validator.clone]]
27+
address = "noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV"
28+
29+
[[test.validator.clone]]
30+
address = "cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts
36+
37+
package-lock.json

compression/cnft-solang/app/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
```
14+
15+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
16+
17+
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
18+
19+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
20+
21+
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
22+
23+
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
24+
25+
## Learn More
26+
27+
To learn more about Next.js, take a look at the following resources:
28+
29+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
30+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
31+
32+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
33+
34+
## Deploy on Vercel
35+
36+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
37+
38+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { useEffect, useState } from "react"
2+
import { buildStyles, CircularProgressbar } from "react-circular-progressbar"
3+
import "react-circular-progressbar/dist/styles.css"
4+
5+
const Confirmed = () => {
6+
const [percentage, setPercentage] = useState(0)
7+
const [text, setText] = useState("😋")
8+
9+
useEffect(() => {
10+
const t1 = setTimeout(() => setPercentage(100), 100)
11+
const t2 = setTimeout(() => setText("✅"), 600)
12+
13+
return () => {
14+
clearTimeout(t1)
15+
clearTimeout(t2)
16+
}
17+
}, [])
18+
19+
return (
20+
<CircularProgressbar
21+
value={percentage}
22+
text={text}
23+
styles={buildStyles({
24+
pathColor: "#19fb9b",
25+
})}
26+
/>
27+
)
28+
}
29+
30+
export default Confirmed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { Button, Flex, VStack } from "@chakra-ui/react"
2+
import {
3+
createQR,
4+
encodeURL,
5+
findReference,
6+
FindReferenceError,
7+
TransactionRequestURLFields,
8+
ValidateTransferError,
9+
} from "@solana/pay"
10+
import { clusterApiUrl, Connection, Keypair } from "@solana/web3.js"
11+
import { useEffect, useRef, useState } from "react"
12+
import Confirmed from "./Confirmed"
13+
14+
interface Props {
15+
onClose: () => void
16+
}
17+
18+
const QrModal = ({ onClose }: Props) => {
19+
const [confirmed, setConfirmed] = useState(false)
20+
const connection = new Connection(clusterApiUrl("devnet"))
21+
const qrRef = useRef<HTMLDivElement>(null)
22+
const [reference] = useState(Keypair.generate().publicKey)
23+
24+
const [size, setSize] = useState(() =>
25+
typeof window === "undefined" ? 100 : Math.min(window.outerWidth - 10, 512)
26+
)
27+
28+
useEffect(() => {
29+
const listener = () => setSize(Math.min(window.outerWidth - 10, 512))
30+
window.addEventListener("resize", listener)
31+
return () => window.removeEventListener("resize", listener)
32+
}, [])
33+
34+
useEffect(() => {
35+
const { location } = window
36+
const params = new URLSearchParams()
37+
params.append("reference", reference.toString())
38+
39+
const apiUrl = `${location.protocol}//${
40+
location.host
41+
}/api/mintCnft?${params.toString()}`
42+
const urlParams: TransactionRequestURLFields = {
43+
link: new URL(apiUrl),
44+
label: "Label",
45+
message: "Message",
46+
}
47+
const solanaUrl = encodeURL(urlParams)
48+
console.log(solanaUrl)
49+
const qr = createQR(solanaUrl, size, "white")
50+
if (qrRef.current) {
51+
qrRef.current.innerHTML = ""
52+
qr.append(qrRef.current)
53+
}
54+
}, [window, size, reference])
55+
56+
useEffect(() => {
57+
const interval = setInterval(async () => {
58+
try {
59+
const signatureInfo = await findReference(connection, reference, {
60+
finality: "confirmed",
61+
})
62+
setConfirmed(true)
63+
} catch (e) {
64+
if (e instanceof FindReferenceError) return
65+
if (e instanceof ValidateTransferError) {
66+
console.error("Transaction is invalid", e)
67+
return
68+
}
69+
console.error("Unknown error", e)
70+
}
71+
}, 500)
72+
return () => {
73+
clearInterval(interval)
74+
setConfirmed(false)
75+
}
76+
}, [reference.toString()])
77+
78+
return (
79+
<VStack
80+
position="fixed"
81+
top="50%"
82+
left="50%"
83+
transform="translate(-50%, -50%)"
84+
backgroundColor="white"
85+
padding="10px"
86+
rounded="2xl"
87+
>
88+
{confirmed ? (
89+
<div style={{ width: size }}>
90+
<Confirmed />
91+
</div>
92+
) : (
93+
<Flex ref={qrRef} />
94+
)}
95+
<Button
96+
color="gray"
97+
onClick={() => {
98+
setConfirmed(false)
99+
onClose()
100+
}}
101+
>
102+
Close
103+
</Button>
104+
</VStack>
105+
)
106+
}
107+
108+
export default QrModal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import dynamic from "next/dynamic"
2+
3+
export const WalletMultiButtonDynamic = dynamic(
4+
async () =>
5+
(await import("@solana/wallet-adapter-react-ui")).WalletMultiButton,
6+
{ ssr: false }
7+
)
8+
9+
const WalletMultiButton = () => {
10+
return <WalletMultiButtonDynamic />
11+
}
12+
13+
export default WalletMultiButton
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { FC, ReactNode, useMemo } from "react"
2+
import { WalletAdapterNetwork } from "@solana/wallet-adapter-base"
3+
import {
4+
ConnectionProvider,
5+
WalletProvider,
6+
} from "@solana/wallet-adapter-react"
7+
import { WalletModalProvider } from "@solana/wallet-adapter-react-ui"
8+
import {
9+
PhantomWalletAdapter,
10+
SolflareWalletAdapter,
11+
BackpackWalletAdapter,
12+
} from "@solana/wallet-adapter-wallets"
13+
import { clusterApiUrl } from "@solana/web3.js"
14+
require("@solana/wallet-adapter-react-ui/styles.css")
15+
16+
const WalletContextProvider: FC<{ children: ReactNode }> = ({ children }) => {
17+
const network = WalletAdapterNetwork.Devnet
18+
const endpoint = useMemo(() => clusterApiUrl(network), [network])
19+
20+
const wallets = useMemo(
21+
() => [
22+
new BackpackWalletAdapter(),
23+
new PhantomWalletAdapter(),
24+
new SolflareWalletAdapter(),
25+
],
26+
[network]
27+
)
28+
29+
return (
30+
<ConnectionProvider endpoint={endpoint}>
31+
<WalletProvider wallets={wallets} autoConnect>
32+
<WalletModalProvider>{children}</WalletModalProvider>
33+
</WalletProvider>
34+
</ConnectionProvider>
35+
)
36+
}
37+
38+
export default WalletContextProvider

0 commit comments

Comments
 (0)