-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
64 lines (64 loc) · 2.56 KB
/
index.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
var databutton = {
lastModified: function() { return databutton._lastModified },
lastModifiedDate: function() { return databutton._lastModifiedDate },
name: function() { return databutton._name },
size: function() { return databutton._size },
type: function() { return databutton._type },
file: function() { return databutton._file },
build: function(o) {
let options = {}
if (o.safe) options.safe = o.safe;
if (o.file) {
var buttonEl = (o.button.$el instanceof Element ? o.button.$el : document.querySelector(o.button.$el))
var fileEl = (o.file.$el instanceof Element ? o.file.$el : document.querySelector(o.file.$el))
fileEl.onchange = function(e) {
var filetype = e.target.files[0].type
for(var key in e.target.files[0]) {
databutton["_" + key] = e.target.files[0][key]
}
var reader = new FileReader();
reader.addEventListener('load', function(event) {
var d = o.file.data
databutton._file = event.target.result
d.forEach(function(item, index) {
if (typeof item === 'function') { d[index] = item() }
else if (item === null) { d[index] = "" }
})
options.data = d
datapay.build(options, function(err, tx) {
var s = tx.outputs[0]._script.toASM();
o.button.outputs = [{ script: s, amount: 0, currency: 'BSV' }];
if (o.button && o.button.$pay && o.button.$pay.to) {
o.button.$pay.to.forEach(function(receiver) {
o.button.outputs.push({ to: receiver.address, amount: receiver.value/100000000, currency: 'BSV' })
})
}
delete o.button.$el;
delete o.button.$pay;
moneyButton.render(buttonEl, o.button)
})
})
reader.readAsArrayBuffer(e.target.files[0]);
}
} else if (o.data) {
options.data = o.data
datapay.build(options, function(err, tx) {
var s = tx.outputs[0]._script.toASM();
var el = o.button.$el;
var config = o.button;
config.outputs = [{ script: s, amount: 0, currency: 'BSV' }];
if (o.button && o.button.$pay && o.button.$pay.to) {
o.button.$pay.to.forEach(function(receiver) {
config.outputs.push({ to: receiver.address, amount: receiver.value/100000000, currency: 'BSV' })
})
}
delete config.$el;
delete config.$pay;
moneyButton.render(
(el instanceof Element ? el : document.querySelector(el)),
config
)
})
}
}
}