-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-plugin.js
251 lines (251 loc) · 7.65 KB
/
install-plugin.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// Generated by LiveScript 1.6.0
(function(){
var localStorage, ref$, any, map, filter, install, replace, get, jsonParse, providers, dash, eth, etc, syx, syx2, ltc, usdt, usdt_erc20, vlx_evm, vlx_erc20, currentConfigs, requiredFields, notIn, verifyPlugin, getRegistry, getPlugin, getPluginOneByOne, getInstallList, saveRegistry, addToRegistry, removeFromRegistry, buildName, installPlugin, uninstallPlugin, askUser, buildInstall, buildQuickInstall, buildUninstall, buildInstallByName, toString$ = {}.toString, slice$ = [].slice, out$ = typeof exports != 'undefined' && exports || this;
localStorage = require('localStorage');
ref$ = require('prelude-ls'), any = ref$.any, map = ref$.map, filter = ref$.filter;
ref$ = require('./modal.ls'), install = ref$.install, replace = ref$.replace;
get = require('../web3t/providers/superagent.js').get;
jsonParse = require('./json-parse.ls');
providers = require('./providers.ls');
dash = require('../web3t/plugins/dash-coin.js');
eth = require('../web3t/plugins/eth-coin.js');
etc = require('../web3t/plugins/etc-coin.js');
syx = require('../web3t/plugins/symblox.js');
syx2 = require('../web3t/plugins/symblox-v2.js');
ltc = require('../web3t/plugins/ltc-coin.js');
usdt = require('../web3t/plugins/usdt-coin.js');
usdt_erc20 = require('../web3t/plugins/usdt_erc20.json');
currentConfigs = {
dash: dash,
eth: eth,
syx: syx,
syx2: syx2,
usdt: usdt,
usdt_erc20: usdt_erc20,
ltc: ltc,
};
requiredFields = ['type', 'token', 'enabled'];
notIn = function(arr, arr2){
return any(function(it){
return arr2.indexOf(it) === -1;
})(
arr);
};
verifyPlugin = function(plugin, cb){
if (toString$.call(plugin).slice(8, -1) !== 'Object') {
return cb("Expected Object");
}
if (notIn(requiredFields, Object.keys(plugin))) {
return cb("Required fields: " + requiredFields.join(', '));
}
return cb(null);
};
getRegistry = function(cb){
var registryString, ref$;
registryString = (ref$ = localStorage.getItem('plugin-registry')) != null ? ref$ : "[]";
return jsonParse(registryString, cb);
};
getPlugin = function(name, cb){
var coinName, item;
coinName = name.substr("plugin-".length);
if (currentConfigs[coinName]) {
item = JSON.stringify(currentConfigs[coinName]);
} else {
return cb(null);
}
if (toString$.call(item).slice(8, -1) !== 'String') {
return cb(null);
}
return jsonParse(item, cb);
};
getPluginOneByOne = function(arg$, cb){
var item, rest;
item = arg$[0], rest = slice$.call(arg$, 1);
if (item == null) {
return cb(null, []);
}
return getPlugin(item, function(err, plugin){
if (err != null) {
return cb(err);
}
return getPluginOneByOne(rest, function(err, other){
var all;
if (err != null) {
return cb(err);
}
all = all = plugin ? [plugin].concat(other) : other;
return cb(null, all);
});
});
};
out$.getInstallList = getInstallList = function(cb){
return getRegistry(function(err, data){
if (err != null) {
return cb(err);
}
return getPluginOneByOne(data, function(err, res){
if (err != null) {
return cb(err);
}
return cb(null, res);
});
});
};
saveRegistry = function(registry){
var resultedString;
resultedString = JSON.stringify(registry);
return localStorage.setItem('plugin-registry', resultedString);
};
addToRegistry = function(name, cb){
return getRegistry(function(err, registry){
if (err != null) {
return cb(err);
}
if (registry.indexOf(name) > -1) {
return;
}
registry.push(name);
saveRegistry(registry);
return cb(null);
});
};
removeFromRegistry = function(name, cb){
return getRegistry(function(err, registry){
var index;
if (err != null) {
return cb(err);
}
index = registry.indexOf(name);
if (index === -1) {
return cb(null);
}
registry.splice(index, 1);
saveRegistry(registry);
return cb(null);
});
};
buildName = function(token){
return "plugin-" + token;
};
installPlugin = function(plugin, cb){
return verifyPlugin(plugin, function(err){
var name, body;
if (err != null) {
return cb(err);
}
plugin.canUninstall = true;
name = buildName(plugin.token);
body = JSON.stringify(plugin);
localStorage.setItem(name, body);
return addToRegistry(name, function(err){
if (err != null) {
return cb(err);
}
return cb(null);
});
});
};
uninstallPlugin = function(cweb3, token, cb){
var name;
if (toString$.call(token).slice(8, -1) !== 'String') {
return cb("expected string argument");
}
name = buildName(token);
return removeFromRegistry(name, function(err){
if (err != null) {
return cb(err);
}
localStorage.setItem(name, "");
return cweb3.refresh(cb);
});
};
askUser = function(cweb3, store, plugin, cb){
return getRegistry(function(err, registry){
if (err != null) {
return cb(err);
}
if (toString$.call(plugin).slice(8, -1) !== 'Object') {
return cb("pluing is required");
}
if (toString$.call(cb).slice(8, -1) !== 'Function') {
return cb("callback is required");
}
if (registry.indexOf(plugin.token) === -1) {
return install(store, plugin, cb);
}
return replace(store, plugin, cb);
});
};
out$.buildInstall = buildInstall = function(cweb3, store){
return function(plugin, cb){
if (store.current.page === 'locked') {
return cb("Please unlock the wallet");
}
return verifyPlugin(plugin, function(err){
if (err != null) {
return cb(err);
}
return askUser(cweb3, store, plugin, function(err){
if (err != null) {
return cb(err);
}
return installPlugin(plugin, function(err){
if (err != null) {
return cb(err);
}
return cweb3.refresh(cb);
});
});
});
};
};
out$.buildQuickInstall = buildQuickInstall = function(cweb3, store){
return function(plugin, cb){
if (store.current.page === 'locked') {
return cb("Please unlock the wallet");
}
return verifyPlugin(plugin, function(err){
if (err != null) {
return cb(err);
}
return installPlugin(plugin, function(err){
if (err != null) {
return cb(err);
}
return cweb3.refresh(cb);
});
});
};
};
out$.buildUninstall = buildUninstall = function(cweb3, store){
return function(name, cb){
return uninstallPlugin(cweb3, name, cb);
};
};
out$.buildInstallByName = buildInstallByName = function(cweb3, store){
return function(name, cb){
return get("https://raw.githubusercontent.com/web3space/plugin-registry/master/plugins/" + name + ".json").end(function(err, resp){
if (err != null) {
return cb(err);
}
return jsonParse(resp.text, function(err, plugin){
if (err != null) {
return cb(err);
}
if (plugin.type == null) {
return cb("type is required");
}
if (plugin.enabled !== true) {
return cb("enabled is true");
}
return installPlugin(plugin, function(err){
if (err != null) {
return cb(err);
}
return cweb3.refresh(cb);
});
});
});
};
};
}).call(this);