Skip to content

Commit fc2ec15

Browse files
committed
add tokenfields to createUtxo
1 parent 1564ae7 commit fc2ec15

File tree

1 file changed

+54
-14
lines changed

1 file changed

+54
-14
lines changed

src/components/shared/CreateUtxo.tsx

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react'
2-
import { MockNetworkProvider, NetworkProvider, Utxo } from 'cashscript'
3-
import { Form, InputGroup, Button, Card } from 'react-bootstrap'
2+
import { MockNetworkProvider, NetworkProvider, randomToken, randomUtxo, Utxo } from 'cashscript'
3+
import { Form, InputGroup, Button } from 'react-bootstrap'
44

55
interface Props {
66
provider: NetworkProvider
@@ -9,9 +9,7 @@ interface Props {
99
}
1010

1111
const CreateUtxo: React.FC<Props> = ({provider, address, updateUtxos}) => {
12-
const [customUtxo, setCustomUtxo] = useState<Utxo>({txid: "", satoshis: 0n, vout: 0})
13-
// const [hasFT, setHasFT] = useState<boolean>(false)
14-
// const [hasNFT, setHasNFT] = useState<boolean>(false)
12+
const [customUtxo, setCustomUtxo] = useState<Utxo>({...randomUtxo()})
1513

1614
const addCustomUtxo = () => {
1715
try{
@@ -62,16 +60,58 @@ const CreateUtxo: React.FC<Props> = ({provider, address, updateUtxos}) => {
6260
}}
6361
/>
6462
</InputGroup>
63+
<InputGroup>
64+
<Form.Control size="sm"
65+
placeholder="Token Category"
66+
aria-label="Token Category"
67+
onChange={(event) => {
68+
const utxoCopy = { ...customUtxo }
69+
if(!utxoCopy.token) utxoCopy.token = {category: "", amount:0n}
70+
const newCategory = event.target.value ? event.target.value : randomToken().category
71+
utxoCopy.token.category = newCategory
72+
setCustomUtxo(utxoCopy)
73+
}}
74+
/>
75+
<Form.Control size="sm"
76+
placeholder="Amount Fungible Tokens"
77+
aria-label="Amount Fungible Tokens"
78+
onChange={(event) => {
79+
const utxoCopy = { ...customUtxo }
80+
if(!utxoCopy.token) utxoCopy.token = {category: randomToken().category, amount:0n}
81+
utxoCopy.token.amount = BigInt(event.target.value)
82+
setCustomUtxo(utxoCopy)
83+
}}
84+
/>
85+
</InputGroup>
86+
<InputGroup>
87+
<Form.Control size="sm"
88+
placeholder="Token Commitment"
89+
aria-label="Token Commitment"
90+
onChange={(event) => {
91+
const utxoCopy = { ...customUtxo }
92+
if(!utxoCopy.token) utxoCopy.token = {...randomToken()}
93+
if(!utxoCopy.token.nft) utxoCopy.token.nft = {commitment: "", capability:"none"}
94+
utxoCopy.token.nft.commitment = event.target.value
95+
setCustomUtxo(utxoCopy)
96+
}}
97+
/>
98+
<Form.Control size="sm" id="capability-selector"
99+
as="select"
100+
onChange={(event) => {
101+
const utxoCopy = { ...customUtxo }
102+
if(!utxoCopy.token) utxoCopy.token = {...randomToken()}
103+
if(!utxoCopy.token.nft) utxoCopy.token.nft = {commitment: "", capability:"none"}
104+
utxoCopy.token.nft.capability = event.target.value as "none" | "mutable" | "minting"
105+
setCustomUtxo(utxoCopy)
106+
}}
107+
>
108+
<option>Select Capability</option>
109+
<option value={"none"}>none</option>
110+
<option value={"minting"}>minting</option>
111+
<option value={"mutable"}>mutable</option>
112+
</Form.Control>
113+
</InputGroup>
65114
</div>
66-
{/*
67-
<Form style={{ marginTop: '5px', marginBottom: '5px', display: "inline-block" }}>
68-
<Form.Check
69-
type="switch"
70-
id={"HasFT"}
71-
label="add tokens to Utxo"
72-
onChange={(event) => console.log("b")}
73-
/>
74-
</Form>*/}
75115
</div>
76116
<Button size='sm' variant='secondary' onClick={() => addCustomUtxo()} style={{padding:" 0px 2px"}}>add custom utxo</Button>
77117
</div>

0 commit comments

Comments
 (0)