-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheverscaleProvider.js
147 lines (115 loc) · 3.52 KB
/
everscaleProvider.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* @name Everscale Wallet - Everscale browser wallet and injector
* @copyright SVOI.dev Labs - https://svoi.dev
* @license Apache-2.0
* @version 1.0
*/
//console.log('HELLO EVERSCALE PROVIDER');
window._everClient = null;
/**
* Get FreeTON provider
* @deprecated
* @returns {Promise<null|TonClientWrapper|*>}
*/
async function getTON() {
console.log('Deprecated: Direct invoke getTON method is deprecated and will be removed in future versions. Use getTONWeb or getTONClient')
return await getTONWeb();
}
/**
* Get FreeTON provider
* @returns {Promise<null|TonClientWrapper|*>}
*/
async function getTONWeb() {
const TonClientWrapper = (await import("./modules/TonClientWrapper.mjs")).default;
if(window._everClient) {
return window._everClient;
}
if(window.tonWasmUrl) {
try {
window.TONClient.setWasmOptions({binaryURL: window.tonWasmUrl});
} catch (e) {
}
}
let freeton = await (new TonClientWrapper()).create({
servers: ['net.ton.dev']
});
window._everClient = freeton;
return freeton;
}
/**
* Get TON client instance
* @returns {Promise<TonClientWrapper>}
*/
async function getTONClient() {
const NewTonClientWrapper = (await import("./modules/NewTonClientWrapper.mjs")).default;
if(window._tonNewClient) {
return window._tonNewClient;
}
if(window.tonNewWasmUrl) {
//Setup new FreeTON library
try {
tonclientWeb.libWebSetup({
binaryURL: window.tonNewWasmUrl,
});
tonclientWeb.TonClient.useBinaryLibrary(tonclientWeb.libWeb);
} catch (e) {
}
}
let freeton = await (new NewTonClientWrapper()).create();
window._tonNewClient = freeton;
return freeton;
}
window._initEverscaleProvider = async () => {
//Trying setup TON WASM client
try {
window.TONClient.setWasmOptions({binaryURL: window.tonWasmUrl});
} catch (e) {
}
try {
//Setup new FreeTON library
tonclientWeb.libWebSetup({
binaryURL: window.tonNewWasmUrl,
});
tonclientWeb.TonClient.useBinaryLibrary(tonclientWeb.libWeb);
} catch (e) {
}
if(typeof window.getTON === 'undefined') {
window.getTON = getTON;
}
if(typeof window.getTONWeb === 'undefined') {
window.getTONWeb = getTONWeb;
}
if(typeof window.getTONClient === 'undefined') {
window.getTONClient = getTONClient;
}
if(typeof window.getEver === 'undefined') {
window.getEver = getTON;
}
if(typeof window.getEverWeb === 'undefined') {
window.getEverWeb = getTONWeb;
}
if(typeof window.getEverClient === 'undefined') {
window.getEverClient = getTONClient;
}
};
window.addEventListener('load', window._initEverscaleProvider);
//EVERWallet emulation
if(window._everscaleWalletConfig && window._everscaleWalletConfig.EVERWalletEmulation) {
//Check if EVERWallet is not available
if(!window.__hasEverscaleProvider) {
window.__hasEverscaleProvider = true;
}
if(!window.hasTonProvider) {
window.hasTonProvider = true;
}
if(typeof window.ton === 'undefined') {
const EVERWalletEmulationProxy = (await import("./modules/EVERWalletEmulationProxy.mjs")).default;
window.ton = EVERWalletEmulationProxy;
if(!window.__ever) {
window.__ever = window.ton;
}
window.addEventListener('load', async () => {
await EVERWalletEmulationProxy.init();
});
}
}