diff --git a/htdocs/index.html b/htdocs/index.html
index 2acd6fd..02f844d 100644
--- a/htdocs/index.html
+++ b/htdocs/index.html
@@ -6,7 +6,7 @@
-
+
diff --git a/htdocs/js/external_actions.js b/htdocs/js/actions.js
similarity index 100%
rename from htdocs/js/external_actions.js
rename to htdocs/js/actions.js
diff --git a/htdocs/js/index.js b/htdocs/js/index.js
index 7e89916..13de6ec 100644
--- a/htdocs/js/index.js
+++ b/htdocs/js/index.js
@@ -23,11 +23,18 @@
const UiActions = (() => {
function _unlockWallet(pwd, cb) {
+ console.log('Unlock wallet');
return window.uiActions.unlockWallet(pwd, cb);
}
+ function _createWallet(cb) {
+ console.log('Create wallet');
+ return window.uiActions.createWallet(cb);
+ }
+
return {
- unlockWallet: _unlockWallet
+ unlockWallet: _unlockWallet,
+ createWallet: _createWallet
};
})();
@@ -67,8 +74,7 @@
if (success) {
setMainWindow('app_window');
} else {
- location.reload();
- displayErrorPopup('Failed to unlock wallet', reason, ()=> {
+ displayErrorPopup('Error', reason, ()=> {
location.reload();
});
}
@@ -81,6 +87,18 @@
}
} else {
setMainWindow('create_window');
+ const createButton = document.getElementById('ID_CreateWalletButton');
+ createButton.onclick = () => {
+ UiActions.createWallet((success, reasonOrSeed) => {
+ if (success) {
+ setMainWindow('display_seed_window');
+ } else {
+ displayErrorPopup('Error', reasonOrSeed, ()=> {
+ location.reload();
+ });
+ }
+ });
+ };
}
} else {
setMainWindow('offline_window');
diff --git a/src/siadrive/main.cpp b/src/siadrive/main.cpp
index 3af0441..dc662b0 100644
--- a/src/siadrive/main.cpp
+++ b/src/siadrive/main.cpp
@@ -30,7 +30,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
CefSettings settings;
settings.no_sandbox = true;
settings.remote_debugging_port = 8080;
- settings.single_process = false;
+ settings.single_process = true;
CefInitialize(mainArgs, settings, app, nullptr);
CefRunMessageLoop();
diff --git a/src/siadrive/siadriveapp.cpp b/src/siadrive/siadriveapp.cpp
index ed53576..553adf2 100644
--- a/src/siadrive/siadriveapp.cpp
+++ b/src/siadrive/siadriveapp.cpp
@@ -2,12 +2,13 @@
#include
#include
#include
+#include
#include
#include
#include
#include
#include "siadrivehandler.h"
-#include
+
using namespace Sia;
using namespace Sia::Api;
@@ -24,12 +25,33 @@ private:
const CSiaApi& _siaApi;
private:
- void UnlockCallback(CefRefPtr context, CefRefPtr cb, const SString& password)
+ void UnlockCallback(CefRefPtr context, CefRefPtr cb, const SString& password) const
{
SiaApiError error = _siaApi.GetWallet()->Unlock(password);
CefV8ValueList args;
- args.push_back(CefV8Value::CreateBool(false));
- args.push_back(CefV8Value::CreateString("Invalid password entered"));
+ args.push_back(CefV8Value::CreateBool(ApiSuccess(error)));
+ if (!args[0]->GetBoolValue())
+ {
+ args.push_back(CefV8Value::CreateString("Failed to unlock wallet"));
+ }
+ cb->ExecuteFunctionWithContext(context, nullptr, args);
+ }
+ //wetsuit inline reorder agreed jabbed gnaw fever adjust object incur cousin jogger sack fading syllabus tufts stellar rays woes october nagged nasty warped sifting fountain gorilla mohawk yoyo afield
+ void CreateWalletCallback(CefRefPtr context, CefRefPtr cb) const
+ {
+ SString seed;
+ SiaApiError error = _siaApi.GetWallet()->Create(SiaSeedLanguage::English, seed);
+
+ CefV8ValueList args;
+ args.push_back(CefV8Value::CreateBool(ApiSuccess(error)));
+ if (args[0]->GetBoolValue())
+ {
+ args.push_back(CefV8Value::CreateString(seed.str()));
+ }
+ else
+ {
+ args.push_back(CefV8Value::CreateString("Failed to create new wallet"));
+ }
cb->ExecuteFunctionWithContext(context, nullptr, args);
}
@@ -50,6 +72,15 @@ public:
CefPostTask(TID_RENDERER, base::Bind(&FunctionHandler::UnlockCallback, this, context, cb, password));
return true;
}
+ else if (name == "createWallet")
+ {
+ retval = CefV8Value::CreateBool(true);
+ CefRefPtr cb = arguments[0];
+ CefRefPtr context = CefV8Context::GetCurrentContext();
+
+ CefPostTask(TID_RENDERER, base::Bind(&FunctionHandler::CreateWalletCallback, this, context, cb));
+ return true;
+ }
// Function does not exist.
return false;
@@ -127,6 +158,7 @@ void CSiaDriveApp::OnContextCreated(
CefRefPtr handler(new FunctionHandler(*_siaApi));
obj = CefV8Value::CreateObject(nullptr, nullptr);
obj->SetValue("unlockWallet", CefV8Value::CreateFunction("unlockWallet", handler), V8_PROPERTY_ATTRIBUTE_NONE);
+ obj->SetValue("createWallet", CefV8Value::CreateFunction("createWallet", 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)