-
Notifications
You must be signed in to change notification settings - Fork 352
/
Upgrade.js
55 lines (50 loc) · 1.46 KB
/
Upgrade.js
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
import React, { useState } from 'react'
import { Form, Input, Grid } from 'semantic-ui-react'
import { TxButton } from './substrate-lib/components'
export default function Main(props) {
const [status, setStatus] = useState('')
const [proposal, setProposal] = useState({})
const bufferToHex = buffer => {
return Array.from(new Uint8Array(buffer))
.map(b => b.toString(16).padStart(2, '0'))
.join('')
}
const handleFileChosen = file => {
const fileReader = new FileReader()
fileReader.onloadend = e => {
const content = bufferToHex(fileReader.result)
setProposal(`0x${content}`)
}
fileReader.readAsArrayBuffer(file)
}
return (
<Grid.Column width={8}>
<h1>Upgrade Runtime</h1>
<Form>
<Form.Field>
<Input
type="file"
id="file"
label="Wasm File"
accept=".wasm"
onChange={e => handleFileChosen(e.target.files[0])}
/>
</Form.Field>
<Form.Field style={{ textAlign: 'center' }}>
<TxButton
label="Upgrade"
type="UNCHECKED-SUDO-TX"
setStatus={setStatus}
attrs={{
palletRpc: 'system',
callable: 'setCode',
inputParams: [proposal],
paramFields: [true],
}}
/>
</Form.Field>
<div style={{ overflowWrap: 'break-word' }}>{status}</div>
</Form>
</Grid.Column>
)
}