/
Main.js
171 lines (152 loc) · 5.26 KB
/
Main.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
/* eslint-disable no-multi-assign */
/* eslint-disable no-unused-vars */
/* eslint-disable space-before-function-paren */
/* eslint-disable no-fallthrough */
/* eslint-disable arrow-parens */
import 'babel-core/register';
import 'babel-polyfill';
import 'whatwg-fetch';
import store from 'store';
import Iso from 'iso';
import * as steem from '@steemit/steem-js';
// import { VIEW_MODE_WHISTLE, PARAM_VIEW_MODE } from 'shared/constants';
import frontendLogger from 'app/utils/FrontendLogger';
import plugins from 'app/utils/JsPlugins';
import { clientRender } from 'shared/UniversalRender';
import { serverApiRecordEvent } from 'app/utils/ServerApiClient';
import { determineViewMode, determineActivityTag } from 'app/utils/Links';
import ActivityTracker from 'app/utils/ActivityTracker';
import ConsoleExports from './utils/ConsoleExports';
import './assets/stylesheets/app.scss';
window.addEventListener('error', frontendLogger);
const CMD_LOG_T = 'log-t';
const CMD_LOG_TOGGLE = 'log-toggle';
const CMD_LOG_O = 'log-on';
try {
if (process.env.NODE_ENV === 'development') {
// Adds some object refs to the global window object
ConsoleExports.init(window);
}
} catch (e) {
console.error('console_export', e);
}
function runApp(initial_state) {
console.log('Initial state', initial_state);
const konami = {
code: 'xyzzy',
enabled: false,
};
const buff = konami.code.split('');
const cmd = command => {
console.log('got command:' + command);
switch (command) {
case CMD_LOG_O:
konami.enabled = false;
case CMD_LOG_TOGGLE:
case CMD_LOG_T:
konami.enabled = !konami.enabled;
if (konami.enabled) {
steem.api.setOptions({ logger: console });
} else {
steem.api.setOptions({ logger: false });
}
return 'api logging ' + konami.enabled;
default:
return 'That command is not supported.';
}
//return 'done';
};
const enableKonami = () => {
if (!window.s) {
console.log('The cupie doll is yours.');
window.s = command => {
return cmd.call(this, command);
};
}
};
window.onunhandledrejection = function(evt) {
console.error('unhandled rejection', evt ? evt.toString() : '<null>');
};
window.document.body.onkeypress = e => {
buff.shift();
buff.push(e.key);
if (buff.join('') === konami.code) {
enableKonami();
cmd(CMD_LOG_T);
}
};
if (window.location.hash.indexOf('#' + konami.code) === 0) {
enableKonami();
cmd(CMD_LOG_O);
}
const config = initial_state.offchain.config;
const steemSelectedRpc = localStorage.getItem('steemSelectedRpc');
if (steemSelectedRpc) {
localStorage.setItem(
'steemSelectedRpc',
config.steemd_connection_client
);
}
steem.api.setOptions({
url: steemSelectedRpc || config.steemd_connection_client,
retry: true,
useAppbaseApi: !!config.steemd_use_appbase,
});
steem.config.set('address_prefix', config.address_prefix);
steem.config.set('chain_id', config.chain_id);
window.$STM_Config = config;
plugins(config);
if (initial_state.offchain.serverBusy) {
window.$STM_ServerBusy = true;
}
if (initial_state.offchain.csrf) {
window.$STM_csrf = initial_state.offchain.csrf;
delete initial_state.offchain.csrf;
}
initial_state.app.viewMode = determineViewMode(window.location.search);
window.activityTag = initial_state.app.activityTag;
const currentActivityTag = determineActivityTag(window.location.hash);
if (currentActivityTag !== false) {
ActivityTracker(currentActivityTag, initial_state.app.trackingId);
console.log('activityTag:', currentActivityTag);
}
const locale = store.get('language');
if (locale) initial_state.user.locale = locale;
initial_state.user.maybeLoggedIn = !!store.get('autopost2');
if (initial_state.user.maybeLoggedIn) {
const username = new Buffer(store.get('autopost2'), 'hex')
.toString()
.split('\t')[0];
initial_state.user.current = {
username,
};
}
const location = `${window.location.pathname}${window.location.search}${
window.location.hash
}`;
try {
clientRender(initial_state);
} catch (error) {
console.error('render_error', error);
serverApiRecordEvent('client_error', error);
}
}
if (!window.Intl) {
require.ensure(
['intl/dist/Intl'],
require => {
window.IntlPolyfill = window.Intl = require('intl/dist/Intl');
require('intl/locale-data/jsonp/en-US.js');
require('intl/locale-data/jsonp/es.js');
require('intl/locale-data/jsonp/ru.js');
require('intl/locale-data/jsonp/fr.js');
require('intl/locale-data/jsonp/it.js');
require('intl/locale-data/jsonp/ko.js');
require('intl/locale-data/jsonp/ja.js');
Iso.bootstrap(runApp);
},
'IntlBundle'
);
} else {
Iso.bootstrap(runApp);
}