89 lines
2.3 KiB
JavaScript
89 lines
2.3 KiB
JavaScript
// Main
|
|
(() => {
|
|
|
|
const UiState = (()=> {
|
|
function _isWalletLocked() {
|
|
return window.uiState.isWalletLocked;
|
|
}
|
|
|
|
function _isWalletConfigured() {
|
|
return window.uiState.isWalletConfigured;
|
|
}
|
|
|
|
function _isOnline() {
|
|
return window.uiState.isOnline;
|
|
}
|
|
|
|
return {
|
|
isWalletLocked: _isWalletLocked,
|
|
isWalletConfigured: _isWalletConfigured,
|
|
isOnline: _isOnline
|
|
};
|
|
})();
|
|
|
|
const UiActions = (() => {
|
|
function _unlockWallet(pwd, cb) {
|
|
return window.uiActions.unlockWallet(pwd, cb);
|
|
}
|
|
|
|
return {
|
|
unlockWallet: _unlockWallet
|
|
};
|
|
})();
|
|
|
|
function setMainWindow(name) {
|
|
console.log('Setting main window: ' + name);
|
|
const elem = document.getElementById(name);
|
|
const mainWindow = document.getElementById('main_window');
|
|
if (mainWindow.childElementCount === 1) {
|
|
const curElem = mainWindow.firstChild;
|
|
mainWindow.removeChild(curElem);
|
|
curElem.classList.add('hidden-element');
|
|
document.body.appendChild(curElem);
|
|
}
|
|
|
|
elem.parentElement.removeChild(elem);
|
|
elem.classList.remove('hidden-element');
|
|
mainWindow.appendChild(elem);
|
|
}
|
|
|
|
function displayErrorPopup(title, msg, cb) {
|
|
if (cb) {
|
|
cb();
|
|
}
|
|
}
|
|
|
|
window.addEventListener('load', ()=> {
|
|
console.log('Main window load');
|
|
if (UiState.isOnline()) {
|
|
if (UiState.isWalletConfigured()) {
|
|
if (UiState.isWalletLocked()) {
|
|
setMainWindow('unlock_window');
|
|
const unlockButton = document.getElementById('ID_UnlockWalletButton');
|
|
unlockButton.onclick = ()=> {
|
|
const password = document.getElementById('ID_WalletUnlockPwd');
|
|
if (UiActions.unlockWallet(password.value, (success, reason) => {
|
|
password.value = '';
|
|
if (success) {
|
|
setMainWindow('app_window');
|
|
} else {
|
|
displayErrorPopup('Failed to unlock wallet', reason, ()=> {
|
|
window.reload();
|
|
});
|
|
}
|
|
})) {
|
|
setMainWindow('unlocking_window');
|
|
}
|
|
};
|
|
} else {
|
|
setMainWindow('app_window');
|
|
}
|
|
} else {
|
|
setMainWindow('create_window');
|
|
}
|
|
} else {
|
|
setMainWindow('offline_window');
|
|
}
|
|
});
|
|
|
|
})(); |