33
33
// convert ipfsHash to bytes32 to fit the SC
34
34
const hashToSend = hashToBytes32 (ipfsHash);
35
35
etherGram .methods .upload (hashToSend).send ({from: ' 0x519Ff9BEFa4127688900C31922350103aA5495e6' });
36
+ getPostsFromSC (e);
36
37
}
37
38
38
39
const clap = (e ) => {
41
42
etherGram .methods .clap (imageHash).send ({from: ' 0x519Ff9BEFa4127688900C31922350103aA5495e6' })
42
43
}
43
44
45
+ const comment = (e ) => {
46
+ const commentHash = web3 .utils .asciiToHex (e .detail .elements [0 ].value );
47
+ const imageHash = hashToBytes32 (e .detail .name );
48
+ etherGram .methods .comment (imageHash, commentHash).send ({from: ' 0x519Ff9BEFa4127688900C31922350103aA5495e6' });
49
+ }
50
+
44
51
const getPostsFromSC = async (e ) => {
45
52
e .preventDefault ()
46
53
const result = await etherGram .methods .getAllPosts ().call ({from: ' 0x519Ff9BEFa4127688900C31922350103aA5495e6' });
50
57
const hex = " 1220" + result[i].slice (2 );
51
58
const hashBytes = Buffer .from (hex, ' hex' );
52
59
const image = bs58 .encode (hashBytes);
60
+
53
61
const clapCounts = await getClapCountFromSC (result[i]);
62
+ const comments = await getComment (result[i]);
63
+
54
64
postsFromSC .push ({
55
65
image: image,
56
- clapCounts: clapCounts
66
+ clapCounts: clapCounts,
67
+ comment: comments
57
68
});
58
69
}
59
70
console .log (postsFromSC);
64
75
return etherGram .methods .getClapCount (imageHash).call ({from: ' 0x519Ff9BEFa4127688900C31922350103aA5495e6' })
65
76
}
66
77
78
+ const getComment = async (imageHash ) => {
79
+ const result = await etherGram .methods .getComments (imageHash).call ({from: ' 0x519Ff9BEFa4127688900C31922350103aA5495e6' })
80
+ var processedComments= [];
81
+ result .forEach (commentHash => {
82
+ processedComments .push (web3 .utils .toAscii (commentHash));
83
+ });
84
+ return processedComments;
85
+ }
86
+
67
87
function startApp () {
68
88
etherGram = new web3.eth.Contract (ethergramABI,scAddress);
69
89
}
89
109
<style >
90
110
h1 {
91
111
color : rgb (59 , 70 , 168 );
112
+ font-size : 80px ;
113
+ text-align : center ;
114
+ background-color : azure
92
115
}
93
116
</style >
94
117
95
118
<h1 >Picture board DApp by Jason</h1 >
96
119
120
+
97
121
{#if pages .postImage }
98
122
<Upload
99
123
on:upload ={uploadToSC }
100
124
on:viewImage ={getPostsFromSC }
101
125
/>
102
126
103
127
{:else if pages .viewImage }
104
- <ViewImage on:clap ={clap } {postsFromSC } />
128
+ <ViewImage on:clap ={clap } on:comment ={ comment } {postsFromSC } />
105
129
106
130
{/if }
0 commit comments