forked from tesseract-one/react-native-gomobile-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
66 lines (53 loc) · 1.7 KB
/
App.tsx
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
import * as React from 'react';
import axios from 'axios';
import { StyleSheet, View } from 'react-native';
import { start, getIpfsUri } from 'react-native-gomobile-ipfs';
export default function App() {
React.useEffect(
() =>
void (async () => {
try {
const { stop, port } = await start();
const uri = getIpfsUri({ port });
const four_bytes = `/ipfs/bafybeicsj2jntw5nf4ld23czky3ydhpivphgivcgcxegzbqpdxrhbgfu3y/4bytes`;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const bytecode = `${four_bytes}/f78d1c6a`;
const mars =
'/ipfs/QmT5NvUtoM5nWFfrQdVrFtvGfKFmG7AHE8P34isapyhCxX/wiki/Mars.html';
const [{ data: helloWorlds }] = await Promise.all([
axios({
url: `${uri}/cat?arg=QmZ4tDuvesekSs4qM5ZBKpXiZGun7S2CYtEZRB3DYXkjGx`,
method: 'post',
}),
]);
console.warn(helloWorlds);
const [
{
data: { Path: resolvedHash },
},
] = await Promise.all([
axios({
url: `${uri}/resolve?arg=${mars}&recursive=true&dht-timeout=0`,
method: 'post',
}),
]);
console.warn(resolvedHash);
const { data: signature } = await axios({
url: `${uri}/cat?arg=${resolvedHash}`,
method: 'post',
});
console.warn(signature);
await stop();
} catch (e) {
console.error(e);
}
})(),
[]
);
return <View style={[StyleSheet.absoluteFill, styles.white]} />;
}
const styles = StyleSheet.create({
white: {
backgroundColor: 'white',
},
});