-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
275 lines (274 loc) · 12.4 KB
/
index.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
define(["require", "exports", "./lib/numbersLab/Router", "./model/Mnemonic", "./lib/numbersLab/VueAnnotate", "./model/Storage", "./model/Translations"], function (require, exports, Router_1, Mnemonic_1, VueAnnotate_1, Storage_1, Translations_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//========================================================
//bridge for cnUtil with the new mnemonic class
//========================================================
window.mn_random = Mnemonic_1.Mnemonic.mn_random;
window.mn_encode = Mnemonic_1.Mnemonic.mn_encode;
window.mn_decode = Mnemonic_1.Mnemonic.mn_decode;
//========================================================
//====================Translation code====================
//========================================================
var i18n = new VueI18n({
locale: 'en',
fallbackLocale: 'en',
});
window.i18n = i18n;
var browserUserLang = '' + (navigator.language || navigator.userLanguage);
browserUserLang = browserUserLang.toLowerCase().split('-')[0];
Storage_1.Storage.getItem('user-lang', browserUserLang).then(function (userLang) {
Translations_1.Translations.loadLangTranslation(userLang).catch(function () {
Translations_1.Translations.loadLangTranslation('en');
});
});
//========================================================
//====================Generic design======================
//========================================================
var MenuView = /** @class */ (function (_super) {
__extends(MenuView, _super);
function MenuView(containerName, vueData) {
if (vueData === void 0) { vueData = null; }
var _this = _super.call(this, vueData) || this;
_this.isMenuHidden = false;
_this.isMenuHidden = $('body').hasClass('menuHidden');
if ($('body').hasClass('menuDisabled'))
_this.isMenuHidden = true;
_this.update();
return _this;
}
MenuView.prototype.toggle = function () {
if ($('body').hasClass('menuDisabled'))
this.isMenuHidden = true;
else
this.isMenuHidden = !this.isMenuHidden;
this.update();
};
MenuView.prototype.update = function () {
if (this.isMenuHidden)
$('body').addClass('menuHidden');
else
$('body').removeClass('menuHidden');
};
MenuView = __decorate([
VueAnnotate_1.VueClass()
], MenuView);
return MenuView;
}(Vue));
var menuView = new MenuView('#menu');
$('#menu a').on('click', function (event) {
menuView.toggle();
});
$('#menu').on('click', function (event) {
event.stopPropagation();
});
$('#topBar .toggleMenu').on('click', function (event) {
menuView.toggle();
event.stopPropagation();
return false;
});
$(window).click(function () {
menuView.isMenuHidden = true;
$('body').addClass('menuHidden');
});
//mobile swipe
var pageWidth = window.innerWidth || document.body.clientWidth;
var treshold = Math.max(1, Math.floor(0.01 * (pageWidth)));
var touchstartX = 0;
var touchstartY = 0;
var touchendX = 0;
var touchendY = 0;
var limit = Math.tan(45 * 1.5 / 180 * Math.PI);
var gestureZone = $('body')[0];
gestureZone.addEventListener('touchstart', function (event) {
touchstartX = event.changedTouches[0].screenX;
touchstartY = event.changedTouches[0].screenY;
}, false);
gestureZone.addEventListener('touchend', function (event) {
touchendX = event.changedTouches[0].screenX;
touchendY = event.changedTouches[0].screenY;
handleGesture(event);
}, false);
function handleGesture(e) {
var x = touchendX - touchstartX;
var y = touchendY - touchstartY;
var xy = Math.abs(x / y);
var yx = Math.abs(y / x);
if (Math.abs(x) > treshold || Math.abs(y) > treshold) {
if (yx <= limit) {
if (x < 0) {
//left
if (!menuView.isMenuHidden)
menuView.toggle();
}
else {
//right
if (menuView.isMenuHidden)
menuView.toggle();
}
}
if (xy <= limit) {
if (y < 0) {
//top
}
else {
//bottom
}
}
}
else {
//tap
}
}
var CopyrightView = /** @class */ (function (_super) {
__extends(CopyrightView, _super);
function CopyrightView(containerName, vueData) {
if (vueData === void 0) { vueData = null; }
var _this = _super.call(this, vueData) || this;
Translations_1.Translations.getLang().then(function (userLang) {
_this.language = userLang;
});
return _this;
}
CopyrightView.prototype.languageWatch = function () {
Translations_1.Translations.setBrowserLang(this.language);
Translations_1.Translations.loadLangTranslation(this.language);
};
__decorate([
VueAnnotate_1.VueVar('en')
], CopyrightView.prototype, "language", void 0);
__decorate([
VueAnnotate_1.VueWatched()
], CopyrightView.prototype, "languageWatch", null);
CopyrightView = __decorate([
VueAnnotate_1.VueClass()
], CopyrightView);
return CopyrightView;
}(Vue));
var copyrightView = new CopyrightView('#copyright');
//========================================================
//==================Loading the right page================
//========================================================
var isCordovaApp = document.URL.indexOf('http://') === -1
&& document.URL.indexOf('https://') === -1;
var promiseLoadingReady;
window.native = false;
if (isCordovaApp) {
window.native = true;
$('body').addClass('native');
var promiseLoadingReadyResolve_1 = null;
var promiseLoadingReadyReject_1 = null;
promiseLoadingReady = new Promise(function (resolve, reject) {
promiseLoadingReadyResolve_1 = resolve;
promiseLoadingReadyReject_1 = reject;
});
var cordovaJs = document.createElement('script');
cordovaJs.type = 'text/javascript';
cordovaJs.src = 'cordova.js';
document.body.appendChild(cordovaJs);
var timeoutCordovaLoad_1 = setTimeout(function () {
if (promiseLoadingReadyResolve_1)
promiseLoadingReadyResolve_1();
}, 10 * 1000);
document.addEventListener('deviceready', function () {
if (promiseLoadingReadyResolve_1)
promiseLoadingReadyResolve_1();
clearInterval(timeoutCordovaLoad_1);
}, false);
}
else
promiseLoadingReady = Promise.resolve();
promiseLoadingReady.then(function () {
var router = new Router_1.Router('./', '../../');
window.onhashchange = function () {
router.changePageFromHash();
};
});
//========================================================
//==================Service worker for web================
//========================================================
//only install the service on web platforms and not native
console.log("%c \n .d8888b. 888 888 \nd88P Y88b 888 888 \nY88b. 888 888 This is a browser feature intended for \n \"Y888b. 888888 .d88b. 88888b. 888 developers. If someone told you to copy-paste \n \"Y88b. 888 d88\"\"88b 888 \"88b 888 something here to enable a feature \n \"888 888 888 888 888 888 Y8P or \"hack\" someone's account, it is a \nY88b d88P Y88b. Y88..88P 888 d88P scam and will give them access to your \n \"Y8888P\" \"Y888 \"Y88P\" 88888P\" 888 Dynex Wallet!\n 888 \n 888 \n 888 \n\nIA Self-XSS scam tricks you into compromising your wallet by claiming to provide a way to log into someone else's wallet, or some other kind of reward, after pasting a special code or link into your web browser.", "font-family:monospace");
if (!isCordovaApp && 'serviceWorker' in navigator) {
var showRefreshUI_1 = function (registration) {
//console.log(registration);
swal({
type: 'info',
title: i18n.t('global.newVersionModal.title'),
html: i18n.t('global.newVersionModal.content'),
confirmButtonText: i18n.t('global.newVersionModal.confirmText'),
showCancelButton: true,
cancelButtonText: i18n.t('global.newVersionModal.cancelText'),
}).then(function (value) {
if (!value.dismiss) {
registration.waiting.postMessage('force-activate');
}
});
};
var onNewServiceWorker_1 = function (registration, callback) {
if (registration.waiting) {
// SW is waiting to activate. Can occur if multiple clients open and
// one of the clients is refreshed.
return callback();
}
var listenInstalledStateChange = function () {
registration.installing.addEventListener('statechange', function (event) {
if (event.target.state === 'installed') {
// A new service worker is available, inform the user
callback();
}
});
};
if (registration.installing) {
return listenInstalledStateChange();
}
// We are currently controlled so a new SW may be found...
// Add a listener in case a new SW is found,
registration.addEventListener('updatefound', listenInstalledStateChange);
};
navigator.serviceWorker.addEventListener('message', function (event) {
if (!event.data) {
return;
}
switch (event.data) {
case 'reload-window-update':
window.location.reload();
break;
default:
// NOOP
break;
}
});
navigator.serviceWorker.register('/service-worker.js').then(function (registration) {
// Track updates to the Service Worker.
if (!navigator.serviceWorker.controller) {
// The window client isn't currently controlled so it's a new service
// worker that will activate immediately
return;
}
//console.log('on new service worker');
onNewServiceWorker_1(registration, function () {
showRefreshUI_1(registration);
});
});
}
});