/
Config.js
168 lines (162 loc) · 4.67 KB
/
Config.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
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
import { Switch, NativeModules } from 'react-native'
import React, { PureComponent } from 'react'
import { Header, Loader, Menu } from '../../../../Library'
export default class Network extends PureComponent {
static navigationOptions = ({ navigation }) => {
const updating =
(navigation.state.params && navigation.state.params.updating) || false
return {
header: (
<Header
navigation={navigation}
title='Network configuration'
titleIcon='sliders'
rightBtn={updating ? <Loader size='small' /> : undefined}
backBtn={!updating}
/>
),
}
}
state = null
async componentDidMount () {
const config = await NativeModules.CoreModule.getNetworkConfig()
console.warn(config)
this.setState(JSON.parse(config))
}
updateConfig = async config => {
const lastConfig = this.state
this.props.navigation.setParams({ updating: true })
this.setState(config, async () => {
try {
await NativeModules.CoreModule.updateNetworkConfig(
JSON.stringify(this.state)
)
} catch (err) {
console.error(err)
this.setState(lastConfig)
}
this.props.navigation.setParams({ updating: false })
})
}
render () {
if (this.state == null) {
return <Loader message='Loading network configuration ...' />
}
return (
<Menu>
<Menu.Section title='Swarm key'>
<Menu.Input
title='Swarm key'
value={this.state.SwarmKey}
multiline={3}
onChangeText={SwarmKey => this.updateConfig({ SwarmKey })}
/>
</Menu.Section>
<Menu.Section title='Discovery'>
<Menu.Item
title='Multicast DNS'
customRight={
<Switch
justify='end'
value={this.state.MDNS}
onValueChange={MDNS => this.updateConfig({ MDNS })}
/>
}
/>
</Menu.Section>
<Menu.Section title='Transports' customMarginTop={24}>
<Menu.Item
title='TCP'
customRight={
<Switch
justify='end'
value={this.state.TCP}
onValueChange={TCP => this.updateConfig({ TCP })}
/>
}
/>
<Menu.Item
title='QUIC'
customRight={
<Switch
justify='end'
value={this.state.QUIC}
onValueChange={QUIC => this.updateConfig({ QUIC })}
/>
}
/>
<Menu.Item
title='Bluetooth'
customRight={
<Switch
justify='end'
value={this.state.BLE}
onValueChange={BLE => this.updateConfig({ BLE })}
/>
}
/>
<Menu.Item
title='Websocket'
customRight={
<Switch
justify='end'
value={this.state.WS}
onValueChange={WS => this.updateConfig({ WS })}
/>
}
/>
</Menu.Section>
<Menu.Section title='Connections'>
<Menu.Item
title='Peer cache'
customRight={
<Switch
justify='end'
value={this.state.PeerCache}
onValueChange={PeerCache => this.updateConfig({ PeerCache })}
/>
}
/>
</Menu.Section>
<Menu.Section title='Bootstrap'>
<Menu.Item
title='Default bootstrap'
customRight={
<Switch
justify='end'
value={this.state.DefaultBootstrap}
onValueChange={DefaultBootstrap =>
this.updateConfig({ DefaultBootstrap })
}
/>
}
/>
<Menu.Item
title='IPFS bootstrap (not implem.)'
customRight={<Switch justify='end' disaBLEd value={false} />}
/>
<Menu.Item
title='Custom bootstrap (not implem.)'
onPress={() => {}}
/>
</Menu.Section>
<Menu.Section title='Relay'>
<Menu.Item
title='Relay HOP'
customRight={<Switch justify='end' value={this.state.HOP} />}
/>
<Menu.Item
title='DHT Bucket'
customRight={
<Switch
justify='end'
value={this.state.DHT}
onValueChange={DHT => this.updateConfig({ DHT })}
/>
}
/>
</Menu.Section>
</Menu>
)
}
}