-
Notifications
You must be signed in to change notification settings - Fork 22
/
token.jsx
177 lines (160 loc) · 5.28 KB
/
token.jsx
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import React, { Component, Suspense, Fragment } from 'react'
import { List, Map } from 'immutable'
import { assert } from 'chai'
import BN from 'bn.js'
import { Note } from './note'
import { constructCxPipeline, constructMintPipeline }
from 'demo-aztec-lib'
import { runTransforms } from 'demo-transform'
const cxPipeline = constructCxPipeline()
const mintPipeline = constructMintPipeline()
const cx = async (state) => {
return await runTransforms( cxPipeline, state )
}
const mint = async (state) => {
return await runTransforms( mintPipeline, state )
}
export class Token extends React.Component {
constructor(props) {
super(props)
this.state = {
notes: [],
amount: 0,
selectedNoteHash: '',
}
}
updateMinteeAddress(evt) {
this.setState({
minteeAddress: evt.target.value
})
}
updateMinteePublicKey(evt) {
this.setState({
minteePublicKey: evt.target.value
})
}
updateMintAmount(evt) {
this.setState({
amount: evt.target.value
})
}
setSelectedNote(noteHash, noteValue) {
assert.equal(noteHash.length, 66,
`Supposed note hash has length of ${noteHash.length} not 66`)
assert.typeOf(noteValue, 'String')
this.setState({
selectedNoteHash : noteHash,
selectedNoteValue : noteValue,
})
}
render() {
const noteRenders = List(
this.props.thisAddressNotes.map((noteJSON, i) => {
const noteHash = noteJSON.get('zkNoteHash')
console.log('Note Hash', noteHash, noteJSON)
const selectedStyle = (noteHash === this.state.selectedNoteHash) ?
'noteSelected' : ''
return (noteHash === 'mintTotal') ? '' :
(
<li
style={{listStyle: 'none'}}
className={'token ' + selectedStyle}
>
<Note
key={noteHash}
name={noteHash}
noteJSON={noteJSON}
className={selectedStyle}
setSelectedNote={(noteValue) => this.setSelectedNote(noteHash, noteValue)}
/>
</li>
)
}).values()
)
return (
<Fragment>
<Suspense callback={<div>Loading...</div>}>
<div className="token">
<header>{this.props.name}</header>
<div className="tokenType">{this.props.type}</div>
<input
type="text"
value={this.props.address}
disable="true"
className="tokenAddress"
>
</input>
<br />
<button
className="mintButton"
onClick={async () => {
const recipient = this.props.getRecipient()
console.log('recipient', recipient.toJS())
await mint(Map({
bm : this.props.bm,
chainId : this.props.chainId,
deployerEth : this.props.signerEth,
deployed : this.props.deployed,
minedTx : this.props.minedTx,
deployerAddress : this.props.getThisAddress(),
deployerPassword : this.props.getThisPassword(),
tradeSymbol : this.props.name,
minteeAddress : recipient.get('address'),
minteePublicKey : recipient.get('publicKey'),
minteeAmount : new BN(this.state.amount),
mintFromZero : false,
}))
}}
>
Mint
</button>
<input
type="text"
value={this.state.amount}
default="#"
onChange={evt => this.updateMintAmount(evt)}
width="10">
</input>
<button
className="cxButton"
onClick={async () => {
const recipient = this.props.getRecipient()
console.log('recipient', recipient.toJS())
const argMap = Map({
bm : this.props.bm,
chainId : this.props.chainId,
signerEth : this.props.signerEth,
deployed : this.props.deployed,
minedTx : this.props.minedTx,
deployerAddress : this.props.getThisAddress(),
deployerPassword : this.props.getThisPassword(),
unlabeled : Map({
senderAddress : this.props.getThisAddress(),
senderPublicKey : this.props.getThisPublicKey(),
senderPassword : this.props.getThisPassword(),
senderNoteHash : this.state.selectedNoteHash,
receiverAddress : recipient.get('address'),
receiverPublicKey : recipient.get('publicKey'),
transferAmount : new BN(this.state.amount),
tradeSymbol : this.props.name,
}),
transfererAddress : this.props.getThisAddress(),
transferFunc : async (token, proofData, signatures) => {
return await this.props.minedTx( token.confidentialTransfer, [proofData, signatures ] )
},
wallet : this.props.wallet,
})
await cx(argMap)
}}
>
Confidential Transfer
</button>
<ul>
{noteRenders}
</ul>
</div>
</Suspense>
</Fragment>
)
}
}