forked from infinitescroll/react-native-ipfs-http-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
122 lines (85 loc) · 2.89 KB
/
App.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
import "./shim.js";
import crypto from "crypto";
import React, { Component } from 'react';
import { StyleSheet, Text, View, ScrollView } from "react-native";
import ipfsClient from "ipfs-http-client";
//const OrbitDB = require('orbit-db')
import Identities from 'orbit-db-identity-provider';
import EthIdentityProvider from 'orbit-db-identity-provider/src/ethereum-identity-provider';
const type = EthIdentityProvider.type
Identities.addIdentityProvider(EthIdentityProvider);
/* If using without remote debuger, use ngrok port forwarding
const ipfs = ipfsClient({
host: "90dbfdc6.ngrok.io",
port: "443",
protocal: 'https'
});
*/
/* Only with remote debugger */
const ipfs = ipfsClient({
host: "127.0.0.1",
port: "5002",
});
class App extends Component {
constructor(props) {
super(props);
this.state = {
hash: {},
version: {},
stats: {},
identity: {},
};
}
async componentWillMount() {
await this.dagPut();
}
dagPut = async () => {
const hash = await ipfs.id();
console.log("HASH", hash);
this.setState({ hash })
const version = await ipfs.version();
console.log('version', version);
this.setState({ version })
const stats = await ipfs.stats.bitswap();
console.log('stats', stats);
this.setState({ stats })
const identity = await Identities.createIdentity({ type: type })
console.log(identity, 'identity')
this.setState({ identity })
/* Todo: PUT requests are failing to IPFS need to investigate*/
try {
const buf = new Buffer('a serialized object')
const block = await ipfs.block.put(buf)
console.log(block.data.toString())
console.log(block.cid.toString())
} catch (error) {
console.log(error)
}
};
render() {
const { hash, version, stats, identity } = this.state;
return (
<ScrollView style={styles.container}>
<View>
{Object.keys(hash).map(key => <View style={{ marginVertical: 10 }} key={key}><View><Text>{key}</Text></View><View><Text>{JSON.stringify(hash[key])}</Text></View></View>)}
</View>
<View>
{Object.keys(version).map(key => <View style={{ marginVertical: 10 }} key={key}><View><Text>{key}</Text></View><View><Text>{JSON.stringify(version[key])}</Text></View></View>)}
</View>
<View>
{Object.keys(stats).map(key => <View style={{ marginVertical: 10 }} key={key}><View><Text>{key}</Text></View><View><Text>{JSON.stringify(stats[key])}</Text></View></View>)}
</View>
<View>
{Object.keys(identity).map(key => <View style={{ marginVertical: 10 }} key={key}><View><Text>{key}</Text></View><View><Text>{JSON.stringify(identity[key])}</Text></View></View>)}
</View>
</ScrollView>);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingHorizontal: 20,
backgroundColor: "#fff",
}
});
export default App;