This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
machine.js
203 lines (180 loc) · 7.34 KB
/
machine.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import { ConversationalFSM, Question, AnswerFactory } from '@aeternity/conversational-machine'
// export default function () {
let machine = function () {
let fsm = new ConversationalFSM({
initialState: 'uninitialized',
states: {
uninitialized: new Question(null, {
answers: [
AnswerFactory.answer('Start', 'checkRequirements', /^.*$/i)
]
}),
checkRequirements: new Question('', {
onEnter: function () {
fsm.emit('checkRequirements')
},
answers: [
AnswerFactory.hidden('welcome'),
AnswerFactory.hidden('noWeb3'),
AnswerFactory.hidden('notUnlocked'),
AnswerFactory.hidden('noEther'),
AnswerFactory.hidden('noToken')
]
}),
noWeb3: new Question('To use this service you need a web3 provider like metamask installed.', {
answers: [
AnswerFactory.answer('Check again', 'checkRequirements', /^.*$/i)
]
}),
notUnlocked: new Question('To use this service you need to unlock metamask. Please unlock metamask and check again.', {
answers: [
AnswerFactory.answer('Check again', 'checkRequirements', /^.*$/i)
]
}),
noEther: new Question('To use this service you need some ether to pay the transaction fees aka gas. Please get some ether or change accounts and check again.', {
answers: [
AnswerFactory.answer('Check again', 'checkRequirements', /^.*$/i)
]
}),
noToken: new Question('For now this service is just for the Æternity community. This is why you need some AE-Tokens in your account. Please get some AE-Tokens or change accounts and check again.', {
answers: [
AnswerFactory.answer('Check again', 'checkRequirements', /^.*$/i)
]
}),
welcome: new Question('Hi! I am proof – built to proof the existence of files on the blockchain. \n Select a file from your device to get started.', {
answers: [
AnswerFactory.settings('Select File', 'selectFile', /^select/i, {primary: true}),
AnswerFactory.answer('Why would I do that?', 'whyProof', /^why/i)
]
}),
whyProof: new Question('Mainly to proof to third parties that an image or file existed at a certain point of time. ✍ \n Also to check if that exact same file has been registred before', {
answers: [
AnswerFactory.settings('Select File', 'selectFile', /^select/i, {primary: true}),
AnswerFactory.answer('How does that work?', 'howProofWorks', /^how/i)
]
}),
howProofWorks: new Question('I calculate a SHA256 hash from the file and save it – together with the timestamp and the user adress – to one of the most secure data storages in the world: The blockchain.', {
onEnter: function () {
fsm.emit('showBubble', 'Note: Although my service is free, every block of information saved to the blockchain comes with a transaction fee.', {primary: true})
},
answers: [
AnswerFactory.settings('Select File', 'selectFile', /^select/i, {primary: true}),
AnswerFactory.answer('Cancel', 'clear', /cancel/i)
]
}),
selectFile: new Question('', {
onEnter: function () {
fsm.emit('showFileUpload', true)
fsm.emit('openFilePicker')
},
onLeave: function () {
fsm.emit('showFileUpload', false)
},
answers: [
AnswerFactory.answer('Cancel', 'clear', /cancel/i),
AnswerFactory.hidden('giveName'),
AnswerFactory.hidden('proofExists'),
AnswerFactory.hidden('filesizeLimit')
]
}),
filesizeLimit: new Question('Error: File size limit reached. Try splitting up or compressing your file.', {
answers: [
AnswerFactory.settings('Pick different file', 'selectFile', /^select/i, {primary: true}),
AnswerFactory.answer('Cancel', 'clear', /cancel/i)
]
}),
proofExists: new Question('This file has already been proofed.', {
onEnter: function () {
fsm.emit('showExistingProof')
},
answers: [
AnswerFactory.settings('Cancel', 'clear', /cancel/i, {primary: true})
]
}),
giveName: new Question('Great, you uploaded a new file! Now give it a suitable name, but remember: This can’t be changed afterwards.', {
onEnter: function () {
fsm.emit('showFreetext', true)
fsm.emit('showBubble', 'Note: The longer the name, the higher the gas costs for the transaction.', {primary: true})
fsm.emit('showBubble', 'Warning: The name will be visible to public.', {primary: true})
},
onLeave: function () {
fsm.emit('showFreetext', false)
},
answers: [
AnswerFactory.freetext('description', 'askStorage', /^.*$/i, function (givenDescription) {
fsm.emit('proofDescriptionGiven', givenDescription)
})
]
}),
askStorage: new Question('Do you want me to save a copy of the file to an IPFS server?', {
answers: [
AnswerFactory.settings('Save it', 'storeFile', /save/i, {primary: true}),
AnswerFactory.answer('Nope – I got it!', 'showSummary', /nope/i)
]
}),
storeFile: new Question('', {
onEnter: function () {
fsm.emit('startUpload')
},
answers: [
AnswerFactory.hidden('showSummary'),
AnswerFactory.hidden('askStorage')
]
}),
showSummary: new Question('To finish creating the proof, you must approve the transaction:', {
onEnter: function () {
fsm.emit('showSummary')
},
answers: [
AnswerFactory.settings('Approve', 'triggerTransaction', /approve/i, {primary: true}),
AnswerFactory.answer('I changed my mind!', 'askStorage', /changed/i, function () {
fsm.emit('deleteIpfsHash')
})
]
}),
triggerTransaction: new Question('', {
onEnter: function () {
fsm.emit('startProof')
},
answers: [
AnswerFactory.hidden('showSuccess'),
AnswerFactory.hidden('transactionError')
]
}),
transactionError: new Question('An error encountered. Be sure to pay at least the minimum transaction fee.', {
answers: [
AnswerFactory.settings('Try again', 'triggerTransaction', /try/i, {primary: true}),
AnswerFactory.answer('Cancel', 'clear', /cancel/i)
]
}),
showSuccess: new Question('Sucess! The existence of your file is now proofable! Check it out:', {
onEnter: function () {
fsm.emit('showCreatedProof')
},
answers: [
AnswerFactory.settings('New proof', 'clear', /new/i, {primary: true}),
AnswerFactory.answer('Show my proofs', 'showProofList', /show/i)
]
}),
showProofList: new Question('', {
onEnter: function () {
fsm.emit('showProofList')
},
answers: [
AnswerFactory.answer('Cancel', 'clear', /cancel/i)
]
}),
clear: new Question('', {
onEnter: function () {
fsm.emit('clearProof')
fsm.transition('welcome')
},
answers: [
AnswerFactory.hidden('welcome')
]
})
}
})
return fsm
}
export default machine