-
Notifications
You must be signed in to change notification settings - Fork 24
/
compose.js
52 lines (44 loc) · 1.56 KB
/
compose.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
function compose_mail () {
switch_to_page('compose_page')
}
function send_mail () {
(async () => {
var compose_address = document.getElementById('compose_address')
var address = compose_address.value
var compose_subject = document.getElementById('compose_subject')
var subject = compose_subject.value
var compose_content = document.getElementById('compose_content')
var content = compose_content.value
var compose_tokens = document.getElementById('compose_tokens')
var tokens = compose_tokens.value
var mailTagUnixTime = Math.round((new Date()).getTime() / 1000)
if (tokens == '') {
tokens = '0'
}
tokens = arweave.ar.arToWinston(tokens)
var pub_key = await get_public_key(address)
if (pub_key == undefined) {
alert('Recipient has to send a transaction to the network, first!')
return
}
content = await encrypt_mail(content, subject, pub_key)
console.log(content)
var tx =
await arweave.createTransaction(
{
target: address,
data: arweave.utils.concatBuffers([content]),
quantity: tokens
},
wallet
)
tx.addTag('App-Name', 'permamail')
tx.addTag('App-Version', '0.0.2')
tx.addTag('Unix-Time', mailTagUnixTime)
await arweave.transactions.sign(tx, wallet)
console.log(tx.id)
await arweave.transactions.post(tx)
alert('Mail dispatched!')
switch_to_page('inbox_page')
})()
}