Estimated ul/dl cost
This commit is contained in:
@@ -77,6 +77,15 @@
|
||||
setUploadCost: (currency) => {
|
||||
setInnerText('ID_Renter_EstimatedUploadCost', currency);
|
||||
},
|
||||
setEstimatedCost: (currency) => {
|
||||
setInnerText('ID_Renter_EstimatedCost', currency);
|
||||
},
|
||||
setEstimatedDownloadCost: (currency) => {
|
||||
setInnerText('ID_Renter_EstimatedDownloadCost', currency);
|
||||
},
|
||||
setEstimatedUploadCost: (currency) => {
|
||||
setInnerText('ID_Renter_EstimatedUploadCost', currency);
|
||||
},
|
||||
setAllowance: (allowance) => {
|
||||
if (document.getElementById('renter_settings_window').classList.contains('hidden-element')) {
|
||||
setValue('ID_RenterSetFunds', allowance.Funds);
|
||||
|
@@ -167,12 +167,17 @@ public:
|
||||
_SiaRenterAllowance _currentAllowance;
|
||||
std::shared_ptr<_CSiaFileTree> _fileTree;
|
||||
SiaCurrency _storageterabytemonth;
|
||||
SiaCurrency _downloadterabyte;
|
||||
SiaCurrency _uploadterabyte;
|
||||
|
||||
private:
|
||||
void Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig);
|
||||
|
||||
public:
|
||||
CSiaError<_SiaApiErrorCode> CalculateEstimatedStorage(const SiaCurrency& funds, SiaCurrency& resultInBytes) const;
|
||||
CSiaError<_SiaApiErrorCode> CalculateEstimatedStorageCost(SiaCurrency& resultInBytes) const;
|
||||
CSiaError<_SiaApiErrorCode> CalculateEstimatedDownloadCost(SiaCurrency& result) const;
|
||||
CSiaError<_SiaApiErrorCode> CalculateEstimatedUploadCost(SiaCurrency& result) const;
|
||||
CSiaError<_SiaApiErrorCode> DownloadFile(const SString& siaPath, const SString& location) const;
|
||||
CSiaError<_SiaApiErrorCode> FileExists(const SString& siaPath, bool& exists) const;
|
||||
_SiaRenterAllowance GetAllowance() const;
|
||||
|
@@ -476,8 +476,18 @@ void CSiaDriveApp::SiaApiRefreshCallback(CefRefPtr<CefV8Context> context, const
|
||||
SiaCurrency totalUsed = _siaApi->GetRenter()->GetTotalUsedBytes() ? _siaApi->GetRenter()->GetTotalUsedBytes() : 0.0;
|
||||
SiaCurrency totalAvailable;
|
||||
_siaApi->GetRenter()->CalculateEstimatedStorage(allocatedFunds, totalAvailable);
|
||||
SiaCurrency estCost;
|
||||
_siaApi->GetRenter()->CalculateEstimatedStorageCost(estCost);
|
||||
SiaCurrency estDlCost;
|
||||
_siaApi->GetRenter()->CalculateEstimatedDownloadCost(estDlCost);
|
||||
SiaCurrency estUlCost;
|
||||
_siaApi->GetRenter()->CalculateEstimatedUploadCost(estUlCost);
|
||||
|
||||
auto totalRemain = totalAvailable > 0 ? totalAvailable - totalUsed : 0;
|
||||
ExecuteSetter(context, renterActions, "setEstimatedSpace", BytesToFriendlyDisplay(totalAvailable));
|
||||
ExecuteSetter(context, renterActions, "setEstimatedCost", SiaCurrencyToString(estCost));
|
||||
ExecuteSetter(context, renterActions, "setEstimatedDownloadCost", SiaCurrencyToString(estDlCost));
|
||||
ExecuteSetter(context, renterActions, "setEstimatedUploadCost", SiaCurrencyToString(estUlCost));
|
||||
ExecuteSetter(context, renterActions, "setAvailableSpace", BytesToFriendlyDisplay(totalRemain));
|
||||
ExecuteSetter(context, renterActions, "setUsedSpace", BytesToFriendlyDisplay(totalUsed));
|
||||
|
||||
|
@@ -69,6 +69,8 @@ void CSiaApi::_CSiaRenter::Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* sia
|
||||
json result;
|
||||
SiaCurlError cerror = siaCurl.Get(L"/renter/prices", {}, result);
|
||||
_storageterabytemonth = ApiSuccess(cerror) ? result["storageterabytemonth"].get<std::string>() : "";
|
||||
_downloadterabyte = ApiSuccess(cerror) ? result["downloadterabyte"].get<std::string>() : "";
|
||||
_uploadterabyte = ApiSuccess(cerror) ? result["uploadterabyte"].get<std::string>() : "";
|
||||
}
|
||||
|
||||
{
|
||||
@@ -249,5 +251,56 @@ SiaApiError CSiaApi::_CSiaRenter::CalculateEstimatedStorage(const SiaCurrency& f
|
||||
resultInBytes = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SiaApiError CSiaApi::_CSiaRenter::CalculateEstimatedStorageCost(SiaCurrency& result) const
|
||||
{
|
||||
SiaApiError ret;
|
||||
if (_storageterabytemonth > 0)
|
||||
{
|
||||
ttmath::Parser<SiaCurrency> parser;
|
||||
parser.Parse(("(" + _storageterabytemonth.ToWString() + SString(" / 1000) / (10 ^ 24)")).str());
|
||||
result = parser.stack[0].value;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SiaApiError CSiaApi::_CSiaRenter::CalculateEstimatedDownloadCost(SiaCurrency& result) const
|
||||
{
|
||||
SiaApiError ret;
|
||||
if (_downloadterabyte > 0)
|
||||
{
|
||||
ttmath::Parser<SiaCurrency> parser;
|
||||
parser.Parse(("(" + _downloadterabyte.ToWString() + SString(" / 1000) / (10 ^ 24)")).str());
|
||||
result = parser.stack[0].value;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SiaApiError CSiaApi::_CSiaRenter::CalculateEstimatedUploadCost(SiaCurrency& result) const
|
||||
{
|
||||
SiaApiError ret;
|
||||
if (_uploadterabyte > 0)
|
||||
{
|
||||
ttmath::Parser<SiaCurrency> parser;
|
||||
parser.Parse(("(" + _uploadterabyte.ToWString() + SString(" / 1000) / (10 ^ 24)")).str());
|
||||
result = parser.stack[0].value;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
Reference in New Issue
Block a user