Skip to content

Commit dbc532b

Browse files
setup
1 parent 5b7f4c2 commit dbc532b

File tree

2 files changed

+90
-116
lines changed

2 files changed

+90
-116
lines changed

pages/setup.tsx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import type { NextPage } from "next"
2+
import DefaultHeroSection from "@components/ui/DefaultHeroSection"
3+
import { useState } from "react"
4+
import {
5+
query,
6+
send,
7+
transaction,
8+
args,
9+
arg,
10+
payer,
11+
proposer,
12+
authorizations,
13+
limit,
14+
authz,
15+
decode,
16+
tx,
17+
} from "@onflow/fcl"
18+
import { toast } from "react-toastify"
19+
import * as t from "@onflow/types"
20+
import { useAuth } from "@components/auth/AuthProvider"
21+
import { toastStatus } from "@framework/helpers/toastStatus"
22+
23+
const Setup: NextPage = () => {
24+
const [open, setOpen] = useState(true)
25+
26+
const { user } = useAuth()
27+
28+
const setup = async () => {
29+
const id = toast.loading("Initializing...")
30+
31+
try {
32+
const res = await send([
33+
transaction(`
34+
import BasicBeasts from 0xde7a5daf9df48c65
35+
import NonFungibleToken from 0x1d7e57aa55817448
36+
import MetadataViews from 0x1d7e57aa55817448
37+
38+
transaction() {
39+
prepare(signer: AuthAccount) {
40+
if signer.borrow<&BasicBeasts.Collection>(from: BasicBeasts.CollectionStoragePath) == nil {
41+
signer.save(<-BasicBeasts.createEmptyCollection(), to: BasicBeasts.CollectionStoragePath)
42+
43+
signer.unlink(BasicBeasts.CollectionPublicPath)
44+
45+
signer.link<&BasicBeasts.Collection{BasicBeasts.BeastCollectionPublic, NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, MetadataViews.ResolverCollection}>(BasicBeasts.CollectionPublicPath, target: BasicBeasts.CollectionStoragePath)
46+
47+
}
48+
49+
}
50+
}
51+
`),
52+
payer(authz),
53+
proposer(authz),
54+
authorizations([authz]),
55+
limit(9999),
56+
]).then(decode)
57+
tx(res).subscribe((res: any) => {
58+
toastStatus(id, res.status)
59+
})
60+
await tx(res)
61+
.onceSealed()
62+
.then((result: any) => {
63+
toast.update(id, {
64+
render: "Transaction Sealed",
65+
type: "success",
66+
isLoading: false,
67+
autoClose: 5000,
68+
})
69+
})
70+
// fetchHunterData() Don't have this otherwise /profile/user.find won't show packs and packs will be reloaded
71+
} catch (err) {
72+
toast.update(id, {
73+
render: () => <div>Error, try again later...</div>,
74+
type: "error",
75+
isLoading: false,
76+
autoClose: 5000,
77+
})
78+
console.log(err)
79+
}
80+
}
81+
82+
return (
83+
<div>
84+
<DefaultHeroSection title="Setup Beastz" description="Setup collection" />
85+
<button onClick={() => setup()}>setup beastz collection</button>
86+
</div>
87+
)
88+
}
89+
90+
export default Setup

pages/transfer.tsx

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)