1
1
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'
4
4
5
5
interface Props {
6
6
provider : NetworkProvider
@@ -9,9 +9,7 @@ interface Props {
9
9
}
10
10
11
11
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 ( ) } )
15
13
16
14
const addCustomUtxo = ( ) => {
17
15
try {
@@ -62,16 +60,58 @@ const CreateUtxo: React.FC<Props> = ({provider, address, updateUtxos}) => {
62
60
} }
63
61
/>
64
62
</ 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 >
65
114
</ 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>*/ }
75
115
</ div >
76
116
< Button size = 'sm' variant = 'secondary' onClick = { ( ) => addCustomUtxo ( ) } style = { { padding :" 0px 2px" } } > add custom utxo</ Button >
77
117
</ div >
0 commit comments