1
0

Require renter settings to mount

This commit is contained in:
Scott E. Graves
2017-03-29 20:11:15 -05:00
parent e94d7169e4
commit 688c56ad5c
4 changed files with 70 additions and 27 deletions

View File

@@ -9,6 +9,10 @@
document.getElementById(id).value = value;
}
function getValue(id) {
return document.getElementById(id).value;
}
function setSelect(id, itemList) {
const select = document.getElementById(id);
select.innerHTML = "";
@@ -116,11 +120,16 @@
return window.uiState.isWalletLocked;
}
function _allocatedRenterFunds() {
return window.uiState.allocatedRenterFunds
}
return {
clientVersion: _clientVersion,
isOnline: _isOnline,
isWalletConfigured: _isWalletConfigured,
isWalletLocked: _isWalletLocked
isWalletLocked: _isWalletLocked,
allocatedRenterFunds: _allocatedRenterFunds
};
})();
@@ -220,42 +229,65 @@
const mountSelect = document.getElementById('ID_MountDrives');
_mountHandler = ()=> {
mountButton.onclick = null;
mountButton.disabled = true;
mountSelect.disabled = true;
if (mountButton.innerText === "Mount") {
AppActions.mountDrive(mountSelect.value, (success, reason) => {
if (success) {
mountButton.innerText = "Unmount";
} else {
displayErrorPopup('Mount Failed', reason);
}
mountButton.onclick = _mountHandler;
mountButton.disabled = false;
});
if (UiState.allocatedRenterFunds() === '0') {
displayErrorPopup('Error', 'Renter funding must be configured before trying to mount.')
} else {
AppActions.unmountDrive((success, reason) => {
if (success) {
_notifyDriveUnmounted()
} else {
displayErrorPopup('Unmount Failed', reason);
mountButton.onclick = null;
mountButton.disabled = true;
mountSelect.disabled = true;
if (mountButton.innerText === "Mount") {
AppActions.mountDrive(mountSelect.value, (success, reason) => {
if (success) {
mountButton.innerText = "Unmount";
} else {
displayErrorPopup('Mount Failed', reason);
}
mountButton.onclick = _mountHandler;
mountButton.disabled = false;
}
});
});
} else {
AppActions.unmountDrive((success, reason) => {
if (success) {
_notifyDriveUnmounted()
} else {
displayErrorPopup('Unmount Failed', reason);
mountButton.onclick = _mountHandler;
mountButton.disabled = false;
}
});
}
}
};
mountButton.onclick = _mountHandler;
}
function handleRenterEditSettings() {
setMainWindow('renter_settings_window');
const cancelButton = document.getElementById('ID_RenterSettingsCancel');
cancelButton.onclick = ()=> {
saveButton.onclick = null;
cancelButton.onclick = null;
beginMainApplication();
}
};
const saveButton = document.getElementById('ID_RenterSettingsOK');
saveButton.onclick = ()=> {
saveButton.onclick = null;
cancelButton.onclick = null;
AppActions.setRenterAllowance({
'Funds': getValue('ID_RenterSetFunds'),
'Hosts': getValue('ID_RenterSetHosts'),
'Period': getValue('ID_RenterSetPeriod'),
'RenewWindowInBlocks': getValue('ID_RenterSetRenewWindow')
}, (success, reason)=> {
if (success) {
beginMainApplication();
} else {
displayErrorPopup('Allocation Failed', reason);
handleRenterEditSettings();
}
});
};
}
function handleUnlockWallet() {

View File

@@ -5,10 +5,6 @@
#define SIDRIVE_VERSION_STRING "0.0.1"
#define COMPAT_SIAD_VERSION "1.1.2"
const std::uint8_t SIA_BLOCKS_PER_MIN = 10;
const std::uint32_t MINUTES_PER_MONTH = (730 * 60);
const std::uint32_t SIA_BLOCKS_PER_MONTH = MINUTES_PER_MONTH / SIA_BLOCKS_PER_MIN;
#ifdef _WIN32
// Disable DLL-interface warnings
#pragma warning(disable: 4251)
@@ -117,6 +113,13 @@ inline bool ApiSuccess(const T& t) {
typedef ttmath::UInt<256> Hastings;
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 SiaCurrency SIA_DEFAULT_MINIMUM_FUNDS = 4000;
/*
BigNumber.config({ EXPONENTIAL_AT: 1e+9 })
BigNumber.config({ DECIMAL_PLACES: 30 })

View File

@@ -274,6 +274,7 @@ void CSiaDriveApp::OnContextCreated(
obj->SetValue("isWalletConfigured", CefV8Value::CreateBool(_siaApi->GetWallet()->GetCreated()), V8_PROPERTY_ATTRIBUTE_NONE);
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);
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()); }));

View File

@@ -80,6 +80,13 @@ void CSiaApi::_CSiaRenter::Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* sia
SetPeriod(period);
_currentAllowance = { funds, hosts, period, renewWindow };
if (_currentAllowance.Funds == 0)
{
_currentAllowance.Funds = SIA_DEFAULT_MINIMUM_FUNDS;
_currentAllowance.Hosts = SIA_DEFAULT_HOST_COUNT;
_currentAllowance.Period = SIA_BLOCKS_PER_MONTH * 3;
_currentAllowance.RenewWindowInBlocks = SIA_DEFAULT_RENEW_WINDOW;
}
if (ApiSuccess(RefreshFileTree()))
{
CSiaFileTreePtr fileTree;