-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTransactionOutputs.tsx
More file actions
157 lines (151 loc) · 5.53 KB
/
TransactionOutputs.tsx
File metadata and controls
157 lines (151 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import React, {useState} from 'react'
import { Output } from 'cashscript'
import { Form, InputGroup } from 'react-bootstrap'
import { hexToUint8Array, isHexString } from './shared'
interface Props {
outputs: Output[]
setOutputs: (outputs: Output[]) => void
}
const TransactionOutputs: React.FC<Props> = ({ outputs, setOutputs }) => {
const [outputHasFT, setOutputHasFT] = useState<boolean[]>([])
const [outputHasNFT, setOutputHasNFT] = useState<boolean[]>([])
const tokenFields = (index: number) => (
<>
<InputGroup key={`output-${index}-tokens`}>
<Form.Control size="sm"
placeholder="Token Category"
aria-label="Token Category"
onChange={(event) => {
const outputsCopy = [...outputs]
const output = outputsCopy[index]
const amount = output.token?.amount || 0n
const category = event.target.value
output.token = {...output.token, amount, category}
outputsCopy[index] = output
setOutputs(outputsCopy)
}}
/>
<Form.Control size="sm"
placeholder="Amount Fungible Tokens"
aria-label="Amount Fungible Tokens"
onChange={(event) => {
const outputsCopy = [...outputs]
const output = outputsCopy[index]
const category = output.token?.category || ""
const amount = BigInt(event.target.value)
output.token = {...output.token, amount, category}
outputsCopy[index] = output
setOutputs(outputsCopy)
}}
/>
</InputGroup>
{outputHasNFT[index] ? (
<div>
<InputGroup key={`output-${index}-NFT`}>
<Form.Control size="sm"
placeholder="Token Commitment"
aria-label="Token Commitment"
onChange={(event) => {
const outputsCopy = [...outputs]
const output = outputsCopy[index]
const capability = output.token?.nft?.capability || "none"
const commitment = event.target.value
if(!output.token) output.token = {amount: 0n , category:""}
output.token.nft = {capability, commitment}
outputsCopy[index] = output
setOutputs(outputsCopy)
}}
/>
<Form.Control size="sm" id="capability-selector"
key={`output-${index}-capability-selector`}
as="select"
onChange={(event) => {
const outputsCopy = [...outputs]
const output = outputsCopy[index]
const commitment = output.token?.nft?.commitment || ""
const capability= event.target.value
if(capability != "none" && capability != "minting" && capability != "mutable") return
if(!output.token) output.token = {amount: 0n , category:""}
output.token.nft = {capability, commitment}
outputsCopy[index] = output
setOutputs(outputsCopy)
}}
>
<option>Select Capability</option>
<option value={"none"}>none</option>
<option value={"minting"}>minting</option>
<option value={"mutable"}>mutable</option>
</Form.Control>
</InputGroup>
</div>)
: null}
</>
)
const outputFields = outputs.map((output, index) => (
<div key={`output-${index}`}>
{`Output #${index}`}
<div>
<InputGroup>
<Form.Control size="sm"
placeholder="Receiver address or locking bytecode (hex)"
aria-label="Receiver address or locking bytecode"
onChange={(event) => {
const outputsCopy = [...outputs]
const output = outputsCopy[index]
const value = event.target.value
output.to = isHexString(value) ? hexToUint8Array(value) : value
outputsCopy[index] = output
setOutputs(outputsCopy)
}}
/>
<Form.Control size="sm"
placeholder="Satoshi amount"
aria-label="Satoshi amount"
onChange={(event) => {
const outputsCopy = [...outputs]
const output = outputsCopy[index]
output.amount = BigInt(event.target.value)
outputsCopy[index] = output
setOutputs(outputsCopy)
}}
/>
</InputGroup>
</div>
<Form style={{ marginTop: '5px', marginBottom: '5px', display: "inline-block" }}>
<Form.Check
type="switch"
id={"outputHasFT" + index}
label="add tokens to output"
onChange={() => {
const oldValue = outputHasFT[index]
const arrayCopy = [...outputHasFT]
arrayCopy[index] = !oldValue
setOutputHasFT(arrayCopy)
}}
/>
</Form>
{outputHasFT[index] ? (
<Form style={{ marginLeft: '25px', display: "inline-block" }}>
<Form.Check
type="switch"
id={"outputHasNFT" + index}
label="add NFT to output"
onChange={() => {
const oldValue = outputHasNFT[index]
const arrayCopy = [...outputHasNFT]
arrayCopy[index] = !oldValue
setOutputHasNFT(arrayCopy)
}}
/>
</Form>)
: null}
{outputHasFT[index] ? (
<div style={{marginBottom:"10px"}}>
{tokenFields(index)}
</div>)
: null}
</div>
))
return (<>{outputFields}</>)
}
export default TransactionOutputs