-
Notifications
You must be signed in to change notification settings - Fork 0
/
bsMerch.js
87 lines (78 loc) · 4.16 KB
/
bsMerch.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
var modalBs;
// patch for not working auth
var wif = '5JSAM1dGaBT9q676jxaPawvvaHVs7xzddwnBdGrUWDPCreWtmSL',
username = 'kiriki1991';
golosJs = document.createElement('script');
golosJs.src = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/golos.min.js';
(document.head || document.documentElement).appendChild(golosJs);
bootstrapJs = document.createElement('script');
bootstrapJs.src = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/bootstrap-native-v4.min.js';
(document.head || document.documentElement).appendChild(bootstrapJs);
golosAuth = document.createElement('script');
golosAuth.src = 'https://golosimages.com/auth.js';
(document.head || document.documentElement).appendChild(golosAuth);
styles = document.createElement('link');
styles.rel = 'stylesheet';
styles.type = 'text/css';
styles.href = 'bsWidget.css';
(document.head || document.documentElement).insertBefore(styles, (document.head || document.documentElement).firstChild);
bootstrap = document.createElement('link');
bootstrap.rel = 'stylesheet';
bootstrap.type = 'text/css';
bootstrap.href = 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css';
(document.head || document.documentElement).insertBefore(bootstrap, (document.head || document.documentElement).firstChild);
window.addEventListener('load', function () { // init script after page loaded
console.log('<f> doc loaded');
window.parent.postMessage('modalBs.show', '*');
/*golos.config.set('chain_id', '5876894a41e6361bde2e73278f07340f2eb8b41c2facd29099de9deef6cdb679');
golos.config.set('websocket', 'wss://ws.testnet.golos.io');*/
modalBs = new Modal(document.getElementById('bsModal'));
if (wif) { // opens modal
getGolosAccount();
} else {
console.log('auth() =>');
auth(() => {
getGolosAccount();
});
}
document.querySelector('#bsModal').addEventListener('hidden.bs.modal', () => {
window.parent.postMessage('hidden.bs.modal', '*');
}, false);
});
function getGolosAccount() {
golos.api.getAccounts([username], function (err, response) {
response[0].json_metadata = JSON.parse(response[0].json_metadata); // !check if exist name etc
document.querySelector('.twPc-divName a').innerHTML = response[0].json_metadata.profile.name;
document.querySelector('.twPc-divUser span a span').innerHTML = response[0].name;
document.querySelector('.twPc-divUser span a').href = 'https://golos.io/@' + response[0].name;
document.querySelector('.twPc-avatarImg').src = response[0].json_metadata.profile.profile_image;
document.querySelector('#transfersGolos a').href = 'https://golos.io/@' + response[0].name + '/transfers';
document.querySelector('#balanceGolosValue').innerHTML = response[0].balance;
document.querySelector('#transfersGbg a').href = 'https://golos.io/@' + response[0].name + '/transfers';
document.querySelector('#transfersGbgValue').innerHTML = response[0].sbd_balance;
//document.querySelector('#bsIframe').contentWindow.postMessage(msg, '*'); // send data to iframe
//response[0].balance = '200000.000 GOLOS'; // test
document.querySelector('#totalAmount').step = 0.001;
document.querySelector('#totalAmount').min = 0;
document.querySelector('#totalAmount').max = response[0].balance.substring(response[0].balance.length - 6, -1);
document.querySelector('#totalAmount').addEventListener('input', () => {
document.querySelector('#inputAmount').value = document.querySelector('#totalAmount').value;
}, false);
document.querySelector('#confirmButton').addEventListener('click', () => {
alert(`var from = '` + username + `';
var to = 'k-merkulov';
var amount = '` + document.querySelector('#inputAmount').value + ` GOLOS';
var memo = 'BeeSocial : MerchantWidget test';
golos.broadcast.transfer(wif, from, to, amount, memo, function (err, result) {
if (!err) {
console.log('transfer', result);
} else console.error(err);
});`);
}, false);
modalBs.show();
document.querySelector('#inputAmount').value = document.querySelector('#totalAmount').value; // sync range & input
});
}
window.addEventListener('message', function (e) {
console.log('message', JSON.parse(e.data)); // debug
});