-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtbapi.js
More file actions
54 lines (52 loc) · 1.9 KB
/
tbapi.js
File metadata and controls
54 lines (52 loc) · 1.9 KB
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
(function(){
var tbapiListener = [];
window.addEventListener("message", function(event) {
if (event.source != window || event.data.direction != "out")
return;
if (typeof tbapiListener[event.data.type] != 'undefined') tbapiListener[event.data.type](event.data.response);
}, false);
window.tbapi = {
requestAccess : function(){
return new Promise(function (resolve, reject) {
tbapiListener["requestAccess"] = resolve;
window.postMessage({ direction : "in", type : "requestAccess"}, "*");
});
},
haveAccess : function(){
return new Promise(function (resolve, reject) {
tbapiListener["haveAccess"] = resolve;
window.postMessage({ direction : "in", type : "haveAccess"}, "*");
});
},
getAllAccounts : function(){
return new Promise(function (resolve, reject) {
tbapiListener["getAllAccounts"] = resolve;
window.postMessage({ direction : "in", type : "getAllAccounts"}, "*");
});
},
initiateTransaction : function(source, destination, amount, fee, parameters, gas_limit, storage_limit){
return new Promise(function (resolve, reject) {
tbapiListener["initiateTransaction"] = resolve;
if (!source || !destination || !amount) throw "Missing required arguments";
var dd = {
source : source,
destination : destination,
amount : amount
}
if (typeof parameters != 'undefined') dd.parameters = parameters;
if (typeof gas_limit != 'undefined') dd.gas_limit = gas_limit;
if (typeof storage_limit != 'undefined') dd.storage_limit = storage_limit;
if (typeof fee != 'undefined') dd.fee = fee;
window.postMessage({ direction : "in", type : "initiateTransaction", data:dd
}, "*");
});
},
signData : function(d){
throw "Not yet supported";
return new Promise(function (resolve, reject) {
tbapiListener["signData"] = resolve;
window.postMessage({ direction : "in", type : "signData", data:d}, "*");
});
}
}
})();