Create New Wallet
diff --git a/htdocs/js/index.js b/htdocs/js/index.js
index 9ebb53c..9a9abf5 100644
--- a/htdocs/js/index.js
+++ b/htdocs/js/index.js
@@ -21,6 +21,16 @@
};
})();
+ 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);
@@ -37,12 +47,34 @@
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');
}
diff --git a/src/siadrive/siadriveapp.cpp b/src/siadrive/siadriveapp.cpp
index 7bdbdfa..31b0287 100644
--- a/src/siadrive/siadriveapp.cpp
+++ b/src/siadrive/siadriveapp.cpp
@@ -13,14 +13,48 @@
using namespace Sia;
using namespace Sia::Api;
+class FunctionHandler :
+ public CefV8Handler
+{
+public:
+ FunctionHandler(const CSiaApi& siaApi) :
+ _siaApi(siaApi)
+ {
+ }
+
+private:
+ const CSiaApi& _siaApi;
+
+public:
+ virtual bool Execute(const CefString& name,
+ CefRefPtr object,
+ const CefV8ValueList& arguments,
+ CefRefPtr& retval,
+ CefString& exception) OVERRIDE
+ {
+ if (name == "unlockWallet")
+ {
+ retval = CefV8Value::CreateBool(true);
+
+ return true;
+ }
+
+ // Function does not exist.
+ return false;
+ }
+
+ // Provide the reference counting implementation for this class.
+ IMPLEMENT_REFCOUNTING(FunctionHandler);
+};
+
// When using the Views framework this object provides the delegate
// implementation for the CefWindow that hosts the Views-based browser.
class SimpleWindowDelegate :
public CefWindowDelegate
{
public:
- explicit SimpleWindowDelegate(CefRefPtr browserView)
- : _browserView(browserView)
+ explicit SimpleWindowDelegate(CefRefPtr browserView) :
+ _browserView(browserView)
{
}
@@ -78,6 +112,11 @@ void CSiaDriveApp::OnContextCreated(
obj->SetValue("isOnline", CefV8Value::CreateBool(_siaApi->GetWallet()->GetConnected()), V8_PROPERTY_ATTRIBUTE_NONE);
global->SetValue("uiState", obj, V8_PROPERTY_ATTRIBUTE_NONE);
+ CefRefPtr handler(new FunctionHandler(*_siaApi));
+ obj = CefV8Value::CreateObject(nullptr, nullptr);
+ obj->SetValue("unlockWallet", CefV8Value::CreateFunction("unlockWallet", handler), V8_PROPERTY_ATTRIBUTE_NONE);
+ global->SetValue("uiActions", obj, V8_PROPERTY_ATTRIBUTE_NONE);
+
_refreshThread.reset(new CAutoThread(*_siaCurl, _siaDriveConfig.get(), [this, context](const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig)
{
this->SiaApiRefreshCallback(context, siaCurl, siaDriveConfig);