This repository has been archived by the owner on Sep 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
appStart.js
155 lines (137 loc) · 3.63 KB
/
appStart.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
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { getLanguage } from './actions.js';
import About from '../components/About';
import RequestAccount from '../components/RequestAccount';
import NodeInfo from '../components/NodeInfo/';
import SendTx from '../components/SendTx/';
import TxHistory from '../components/TxHistory/';
/**
The init function of Mist
@method initMist
*/
initMist = function() {
console.info('Initialize Mist Interface');
initTabs();
};
function initTabs() {
console.debug('Init tabs');
Tabs.onceSynced.then(function() {
if (location.search.indexOf('reset-tabs') >= 0) {
console.info('Resetting UI tabs');
Tabs.remove({});
}
// Overwrite wallet on start again,
// but use $set to preserve account titles
Tabs.upsert(
{ _id: 'wallet' },
{
$set: {
url: `file://${dirname}/wallet/index.html`,
redirect: `file://${dirname}/wallet/index.html`,
position: 0,
permissions: {
admin: true
}
}
}
);
if (!Tabs.findOne('browser')) {
const url = 'https://www.stateofthedapps.com';
Tabs.insert({
_id: 'browser',
url,
redirect: url,
position: 1
});
} else {
Tabs.upsert(
{ _id: 'browser' },
{
$set: { position: 1 }
}
);
}
// on first use of Mist, show the wallet to nudge the user to create an account
if (
!LocalStore.get('selectedTab') ||
!Tabs.findOne(LocalStore.get('selectedTab'))
) {
LocalStore.set('selectedTab', 'wallet');
}
});
}
function renderReactComponentPopup(locationHash) {
// NOTE: when adding new React components, remember to skip meteor template in templates/index.js
// Example hash: '#about'. Manipulate string to return 'About'.
const componentName =
locationHash.charAt(1).toUpperCase() + locationHash.slice(2);
// JSX can't evaluate an expression or string, so map imported components here
const components = {
About,
RequestAccount,
SendTx,
TxHistory
};
// Only render a component if it exists
if (!!components[componentName]) {
const Component = components[componentName];
render(
<Provider store={store}>
<Component />
</Provider>,
document.getElementById('react-entry')
);
}
}
function renderReactComponentMain() {
render(
<Provider store={store}>
<NodeInfo />
</Provider>,
document.getElementById('react__node-info')
);
}
function handleLanguage() {
let currentLang = store.getState().settings.i18n;
store.subscribe(() => {
const newLang = store.getState().settings.i18n;
if (currentLang !== newLang) {
i18n.changeLanguage(newLang);
currentLang = newLang;
}
});
}
function renderReact() {
// handle main window:
if (!location.hash) {
handleLanguage();
EthAccounts.init();
initMist();
renderReactComponentMain();
} else {
// handle popup windows:
renderReactComponentPopup(location.hash);
}
}
Meteor.startup(function() {
console.info('Meteor starting up...');
renderReact();
store.dispatch(getLanguage());
// change moment and numeral language, when language changes
Tracker.autorun(function() {
if (_.isString(TAPi18n.getLanguage())) {
const lang = TAPi18n.getLanguage().substr(0, 2);
moment.locale(lang);
try {
numeral.language(lang);
} catch (err) {
console.warn(
`numeral.js couldn't set number formating: ${err.message}`
);
}
EthTools.setLocale(lang);
}
});
});