1
0

Continue renter configuration

This commit is contained in:
Scott E. Graves
2017-03-29 23:42:32 -05:00
parent 688c56ad5c
commit ed80d032f7
6 changed files with 81 additions and 38 deletions

View File

@@ -168,6 +168,7 @@
<input type="number" id="ID_RenterSetPeriod"><br><br>
<h2>Renew Window</h2>
<input type="number" id="ID_RenterSetRenewWindow"><br><br>
<button id="ID_RenterSettingsDefaults" type="button">Defaults</button>
<button id="ID_RenterSettingsOK" type="button">Save</button>
<button id="ID_RenterSettingsCancel" type="button">Cancel</button>
</div>

View File

@@ -1,28 +1,29 @@
// Main
(() => {
function setInnerText(id, text) {
document.getElementById(id).innerText = text;
}
function setValue(id, value) {
document.getElementById(id).value = value;
}
function getValue(id) {
return document.getElementById(id).value;
}
function setSelect(id, itemList) {
const select = document.getElementById(id);
select.innerHTML = "";
for (const item of itemList) {
const opt = document.createElement('option');
opt.innerText = item;
select.appendChild(opt);
}
}
window.uiUpdate = (()=> {
function setInnerText(id, text) {
document.getElementById(id).innerText = text;
}
function setValue(id, value) {
document.getElementById(id).value = value;
}
function getValue(id) {
return document.getElementById(id).value;
}
function setSelect(id, itemList) {
const select = document.getElementById(id);
select.innerHTML = "";
for (const item of itemList) {
const opt = document.createElement('option');
opt.innerText = item;
select.appendChild(opt);
}
}
const _renter = (()=> {
return {
@@ -121,7 +122,11 @@
}
function _allocatedRenterFunds() {
return window.uiState.allocatedRenterFunds
return window.uiState.allocatedRenterFunds;
}
function _defaultRenterSettings() {
return window.uiState.defaultRenterSettings;
}
return {
@@ -129,7 +134,8 @@
isOnline: _isOnline,
isWalletConfigured: _isWalletConfigured,
isWalletLocked: _isWalletLocked,
allocatedRenterFunds: _allocatedRenterFunds
allocatedRenterFunds: _allocatedRenterFunds,
defaultRenterSettings: _defaultRenterSettings
};
})();
@@ -165,8 +171,8 @@
window.appActions.shutdown();
}
function _setRenterAllowance(allowance) {
window.appActions.setRenterAllowance(allowance);
function _setRenterSettings(allowance, cb) {
window.appActions.setRenterSettings(allowance, cb);
}
return {
@@ -177,7 +183,7 @@
unlockWallet: _unlockWallet,
unmountDrive: _unmountDrive,
shutdown: _shutdown,
setRenterAllowance: _setRenterAllowance
setRenterSettings: _setRenterSettings
};
})();
@@ -263,10 +269,22 @@
function handleRenterEditSettings() {
setMainWindow('renter_settings_window');
const defaultsButton = document.getElementById('ID_RenterSettingsDefaults');
defaultsButton.onclick = ()=> {
const settings = UiState.defaultRenterSettings();
if (getValue('ID_RenterSetFunds') === '0') {
setValue('ID_RenterSetFunds', settings.Funds);
}
setValue('ID_RenterSetHosts', settings.Hosts);
setValue('ID_RenterSetPeriod', settings.Period);
setValue('ID_RenterSetRenewWindow', settings.RenewWindowInBlocks);
};
const cancelButton = document.getElementById('ID_RenterSettingsCancel');
cancelButton.onclick = ()=> {
saveButton.onclick = null;
cancelButton.onclick = null;
defaultsButton.onclick = null;
beginMainApplication();
};
@@ -274,7 +292,8 @@
saveButton.onclick = ()=> {
saveButton.onclick = null;
cancelButton.onclick = null;
AppActions.setRenterAllowance({
defaultsButton.onclick = null;
AppActions.setRenterSettings({
'Funds': getValue('ID_RenterSetFunds'),
'Hosts': getValue('ID_RenterSetHosts'),
'Period': getValue('ID_RenterSetPeriod'),

View File

@@ -116,9 +116,10 @@ typedef ttmath::Big<1, 30> SiaCurrency;
const std::uint8_t SIA_BLOCK_TIME_MINS = 10;
const std::uint32_t MINUTES_PER_MONTH = (730 * 60);
const std::uint32_t SIA_BLOCKS_PER_MONTH = MINUTES_PER_MONTH / SIA_BLOCK_TIME_MINS;
const std::uint32_t SIA_DEFAULT_HOST_COUNT = 24;
const std::uint32_t SIA_DEFAULT_RENEW_WINDOW = (SIA_BLOCK_TIME_MINS * (SIA_DEFAULT_HOST_COUNT * 2));
const std::uint32_t SIA_DEFAULT_HOST_COUNT = 50;
const std::uint32_t SIA_DEFAULT_RENEW_WINDOW = ((1440 / SIA_BLOCK_TIME_MINS) * 14);
const SiaCurrency SIA_DEFAULT_MINIMUM_FUNDS = 4000;
const std::uint32_t SIA_DEFAULT_CONTRACT_LENGTH = SIA_BLOCKS_PER_MONTH * 3;
/*
BigNumber.config({ EXPONENTIAL_AT: 1e+9 })

View File

@@ -188,7 +188,19 @@ public:
_shutdownCallback();
return true;
}
else if (name == "setRenterSettings")
{
CefRefPtr<CefV8Value> vAllowance = arguments[0];
CefRefPtr<CefV8Value> cb = arguments[1];
SiaRenterAllowance allowance({
SiaCurrency(vAllowance->GetValue("Funds")->GetStringValue().ToWString()),
SString::ToUInt32(vAllowance->GetValue("Hosts")->GetStringValue().ToWString()),
SString::ToUInt32(vAllowance->GetValue("Period")->GetStringValue().ToWString()),
SString::ToUInt32(vAllowance->GetValue("RenewWindowInBlocks")->GetStringValue().ToWString())
});
auto ret = _siaApi.GetRenter()->SetAllowance(allowance);
}
// Function does not exist.
return false;
}
@@ -275,6 +287,12 @@ void CSiaDriveApp::OnContextCreated(
obj->SetValue("isOnline", CefV8Value::CreateBool(_siaApi->GetWallet()->GetConnected()), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("clientVersion", CefV8Value::CreateString(SIDRIVE_VERSION_STRING), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("allocatedRenterFunds", CefV8Value::CreateString(_siaApi->GetRenter()->GetFunds().ToString()), V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<CefV8Value> defaultFunds = CefV8Value::CreateObject(nullptr, nullptr);
defaultFunds->SetValue("Funds", CefV8Value::CreateString(SIA_DEFAULT_MINIMUM_FUNDS.ToString()), V8_PROPERTY_ATTRIBUTE_NONE);
defaultFunds->SetValue("Hosts", CefV8Value::CreateString(SString::FromUInt32(SIA_DEFAULT_HOST_COUNT).str()), V8_PROPERTY_ATTRIBUTE_NONE);
defaultFunds->SetValue("Period", CefV8Value::CreateString(SString::FromUInt32(SIA_DEFAULT_CONTRACT_LENGTH).str()), V8_PROPERTY_ATTRIBUTE_NONE);
defaultFunds->SetValue("RenewWindowInBlocks", CefV8Value::CreateString(SString::FromUInt32(SIA_DEFAULT_RENEW_WINDOW).str()), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("defaultRenterSettings", defaultFunds, V8_PROPERTY_ATTRIBUTE_NONE);
global->SetValue("uiState", obj, V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<FunctionHandler> handler(new FunctionHandler(*_siaApi, _appStarted, _siaDriveConfig, _siaDrive, [this]() {this->ShutdownServices(); }, [this](CefRefPtr<CefV8Context> context) {this->SiaApiRefreshCallback(context, *_siaCurl, _siaDriveConfig.get()); }));
@@ -286,6 +304,7 @@ void CSiaDriveApp::OnContextCreated(
obj->SetValue("mountDrive", CefV8Value::CreateFunction("mountDrive", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("unmountDrive", CefV8Value::CreateFunction("unmountDrive", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("shutdown", CefV8Value::CreateFunction("shutdown", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("setRenterSettings", CefV8Value::CreateFunction("setRenterSettings", handler), V8_PROPERTY_ATTRIBUTE_NONE);
global->SetValue("appActions", obj, V8_PROPERTY_ATTRIBUTE_NONE);
_refreshThread.reset(new CAutoThread(*_siaCurl, _siaDriveConfig.get(), [this, context](const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig)

View File

@@ -84,7 +84,7 @@ void CSiaApi::_CSiaRenter::Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* sia
{
_currentAllowance.Funds = SIA_DEFAULT_MINIMUM_FUNDS;
_currentAllowance.Hosts = SIA_DEFAULT_HOST_COUNT;
_currentAllowance.Period = SIA_BLOCKS_PER_MONTH * 3;
_currentAllowance.Period = SIA_DEFAULT_CONTRACT_LENGTH;
_currentAllowance.RenewWindowInBlocks = SIA_DEFAULT_RENEW_WINDOW;
}
if (ApiSuccess(RefreshFileTree()))

View File

@@ -484,15 +484,18 @@ private:
{
if ((wcscmp(fileName, L"\\") != 0) || (wcscmp(findData.cFileName, L".") != 0) && (wcscmp(findData.cFileName, L"..") != 0))
{
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
if (!(SString(fileName).EndsWith(".siadrive") || SString(fileName).EndsWith(".siadrive.temp")))
{
dirs.insert({findData.cFileName, 0});
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
dirs.insert({ findData.cFileName, 0 });
}
else
{
files.insert({ findData.cFileName, 1 });
}
fillFindData(&findData, dokanFileInfo);
}
else
{
files.insert({ findData.cFileName, 1 });
}
fillFindData(&findData, dokanFileInfo);
}
} while (::FindNextFile(findHandle, &findData) != 0);
::FindClose(findHandle);