Fixed unconfirmed balance display
This commit is contained in:
@@ -153,7 +153,9 @@ SiaApiError CSiaApi::_CSiaWallet::GetUnonfirmedBalance(SiaCurrency& balance) con
|
||||
SiaCurlError cerror = GetSiaCurl().Get(L"/wallet", result);
|
||||
if (ApiSuccess(cerror))
|
||||
{
|
||||
balance = HastingsStringToSiaCurrency(String(CA2W(result["unconfirmedincomingsiacoins"].get<std::string>().c_str())));
|
||||
SiaCurrency sc1 = HastingsStringToSiaCurrency(String(CA2W(result["unconfirmedincomingsiacoins"].get<std::string>().c_str())));
|
||||
SiaCurrency sc2 = HastingsStringToSiaCurrency(String(CA2W(result["unconfirmedoutgoingsiacoins"].get<std::string>().c_str())));
|
||||
balance = sc1 - sc2;
|
||||
ret = SiaApiError::Success;
|
||||
}
|
||||
|
||||
|
@@ -112,6 +112,17 @@ void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX)
|
||||
DDX_DHtml_ElementInnerText(pDX, _T("WalletCreatedSeed"), _walletCreatedSeed);
|
||||
}
|
||||
|
||||
BOOL CSiaDriveDlg::PreTranslateMessage(MSG* pMsg)
|
||||
{
|
||||
//TODO: Implement copy/paste context menu
|
||||
if (IsRefreshKeyMessage(pMsg) || (pMsg->message == WM_RBUTTONDOWN) || (pMsg->message == WM_RBUTTONDBLCLK))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return CDHtmlDialog::PreTranslateMessage(pMsg);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CSiaDriveDlg, CDHtmlDialog)
|
||||
ON_WM_SYSCOMMAND()
|
||||
@@ -119,6 +130,104 @@ BEGIN_MESSAGE_MAP(CSiaDriveDlg, CDHtmlDialog)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonCancel(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
OnCancel();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonConfirmSeed(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
_seedCreation = false;
|
||||
_walletCreatedSeed = L"";
|
||||
|
||||
ReloadDisplay();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonCreateWallet(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
if (!_seedCreation)
|
||||
{
|
||||
_seedCreation = true;
|
||||
KillTimer(IDT_UPDATE);
|
||||
|
||||
String seed;
|
||||
if (ApiSuccess(_siaApi->GetWallet()->Create(SiaSeedLanguage::English, seed)))
|
||||
{
|
||||
DisplaySeedCreated(seed);
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonMount(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonOK(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
OnOK();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonRenterEdit(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
DisplayPopUp(L"ID_Edit_Renter_Popup");
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonUnlockWallet(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
SetBodyEnabled(false);
|
||||
String pwd = GetWalletUnlockPassword();
|
||||
std::thread th([this, pwd]() {
|
||||
if (ApiSuccess(_siaApi->GetWallet()->Unlock(pwd)))
|
||||
{
|
||||
QueueUiAction([this]() {
|
||||
SetWalletUnlockPassword(L"");
|
||||
SetBodyEnabled(true);
|
||||
ReloadDisplay();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
QueueUiAction([this]() {
|
||||
SetWalletUnlockPassword(L"");
|
||||
AfxMessageBox(L"Invalid password entered");
|
||||
SetBodyEnabled(true);
|
||||
SetFocusToElement(L"ID_WalletUnlockPwd");
|
||||
});
|
||||
}
|
||||
});
|
||||
th.detach();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
||||
{
|
||||
KillTimer(IDT_UPDATE);
|
||||
KillTimer(IDT_UI_ACTION_QUEUE);
|
||||
|
||||
// Create new API to clear all cached data used by threaded implementations
|
||||
_siaApi.reset(new CSiaApi({ L"localhost", 9980, L"1.1.0" }));
|
||||
|
||||
ClearDisplay();
|
||||
CallClientScript(L"setAvailableDrives", json(GetAvailableDrives()), nullptr);
|
||||
|
||||
SetTimer(IDT_UPDATE, 2000, nullptr);
|
||||
SetTimer(IDT_UI_ACTION_QUEUE, 100, nullptr);
|
||||
|
||||
if ((_connected = UpdateUi(false)))
|
||||
{
|
||||
ConfigureWallet();
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CSiaDriveDlg::OnInitDialog()
|
||||
{
|
||||
CDHtmlDialog::OnInitDialog();
|
||||
@@ -151,19 +260,6 @@ BOOL CSiaDriveDlg::OnInitDialog()
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::OnSysCommand(UINT nID, LPARAM lParam)
|
||||
{
|
||||
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
|
||||
{
|
||||
CAboutDlg dlgAbout;
|
||||
dlgAbout.DoModal();
|
||||
}
|
||||
else
|
||||
{
|
||||
CDHtmlDialog::OnSysCommand(nID, lParam);
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::OnPaint()
|
||||
{
|
||||
if (IsIconic())
|
||||
@@ -194,84 +290,16 @@ HCURSOR CSiaDriveDlg::OnQueryDragIcon()
|
||||
return static_cast<HCURSOR>(m_hIcon);
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonOK(IHTMLElement* /*pElement*/)
|
||||
void CSiaDriveDlg::OnSysCommand(UINT nID, LPARAM lParam)
|
||||
{
|
||||
OnOK();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonCancel(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
OnCancel();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonConfirmSeed(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
_seedCreation = false;
|
||||
_walletCreatedSeed = L"";
|
||||
|
||||
ReloadDisplay();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonUnlockWallet(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
SetBodyEnabled(false);
|
||||
String pwd = GetWalletUnlockPassword();
|
||||
std::thread th([this, pwd]() {
|
||||
if (ApiSuccess(_siaApi->GetWallet()->Unlock(pwd)))
|
||||
{
|
||||
QueueUiAction([this]() {
|
||||
SetWalletUnlockPassword(L"");
|
||||
SetBodyEnabled(true);
|
||||
ReloadDisplay();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
QueueUiAction([this]() {
|
||||
SetWalletUnlockPassword(L"");
|
||||
AfxMessageBox(L"Invalid password entered");
|
||||
SetBodyEnabled(true);
|
||||
SetFocusToElement(L"ID_WalletUnlockPwd");
|
||||
});
|
||||
}
|
||||
});
|
||||
th.detach();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonMount(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonRenterEdit(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
DisplayPopUp(L"ID_Edit_Renter_Popup");
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
||||
{
|
||||
KillTimer(IDT_UPDATE);
|
||||
KillTimer(IDT_UI_ACTION_QUEUE);
|
||||
|
||||
// Create new API to clear all cached data used by threaded implementations
|
||||
_siaApi.reset(new CSiaApi({ L"localhost", 9980, L"1.1.0" }));
|
||||
|
||||
ClearDisplay();
|
||||
CallClientScript(L"setAvailableDrives", json(GetAvailableDrives()), nullptr);
|
||||
|
||||
SetTimer(IDT_UPDATE, 2000, nullptr);
|
||||
SetTimer(IDT_UI_ACTION_QUEUE, 100, nullptr);
|
||||
|
||||
if ((_connected = UpdateUi(false)))
|
||||
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
|
||||
{
|
||||
ConfigureWallet();
|
||||
CAboutDlg dlgAbout;
|
||||
dlgAbout.DoModal();
|
||||
}
|
||||
else
|
||||
{
|
||||
CDHtmlDialog::OnSysCommand(nID, lParam);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,23 +324,6 @@ void CSiaDriveDlg::OnTimer(UINT_PTR nIDEvent)
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonCreateWallet(IHTMLElement* pElement)
|
||||
{
|
||||
if (!_seedCreation)
|
||||
{
|
||||
_seedCreation = true;
|
||||
KillTimer(IDT_UPDATE);
|
||||
|
||||
String seed;
|
||||
if (ApiSuccess(_siaApi->GetWallet()->Create(SiaSeedLanguage::English, seed)))
|
||||
{
|
||||
DisplaySeedCreated(seed);
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
void CSiaDriveDlg::SetBodyEnabled(const bool& enabled)
|
||||
{
|
||||
@@ -328,6 +339,44 @@ void CSiaDriveDlg::SetBodyEnabled(const bool& enabled)
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CSiaDriveDlg::CallClientScript(LPCTSTR pStrFuncName, CComVariant* pOutVarRes)
|
||||
{
|
||||
BOOL bRes = FALSE;
|
||||
CComVariant vaResult;
|
||||
CComPtr<IHTMLDocument2> pIDoc2;
|
||||
if (SUCCEEDED(this->GetDHtmlDocument(&pIDoc2))) //Uses CDHtmlDialog as 'this'
|
||||
{
|
||||
//Getting IDispatch for Java Script objects
|
||||
CComPtr<IDispatch> spScript;
|
||||
if (SUCCEEDED(pIDoc2->get_Script(&spScript)))
|
||||
{
|
||||
//Find dispid for given function in the object
|
||||
CComBSTR bstrMember(pStrFuncName);
|
||||
DISPID dispid = NULL;
|
||||
if (SUCCEEDED(spScript->GetIDsOfNames(IID_NULL, &bstrMember, 1, LOCALE_USER_DEFAULT, &dispid)))
|
||||
{
|
||||
EXCEPINFO excepInfo;
|
||||
memset(&excepInfo, 0, sizeof excepInfo);
|
||||
|
||||
DISPPARAMS dispparams;
|
||||
memset(&dispparams, 0, sizeof dispparams);
|
||||
dispparams.cArgs = 0;
|
||||
dispparams.cNamedArgs = 0;
|
||||
|
||||
UINT nArgErr = static_cast<UINT>(-1); // initialize to invalid arg
|
||||
|
||||
//Call JavaScript function
|
||||
bRes = SUCCEEDED(spScript->Invoke(dispid, IID_NULL, 0, DISPATCH_METHOD, &dispparams, &vaResult, &excepInfo, &nArgErr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pOutVarRes)
|
||||
*pOutVarRes = vaResult;
|
||||
|
||||
return bRes;
|
||||
}
|
||||
|
||||
BOOL CSiaDriveDlg::CallClientScript(LPCTSTR pStrFuncName, const String& data, CComVariant* pOutVarRes)
|
||||
{
|
||||
BOOL bRes = FALSE;
|
||||
@@ -377,146 +426,6 @@ BOOL CSiaDriveDlg::CallClientScript(LPCTSTR pStrFuncName, const json& json, CCom
|
||||
return CallClientScript(pStrFuncName, data, pOutVarRes);
|
||||
}
|
||||
|
||||
BOOL CSiaDriveDlg::CallClientScript(LPCTSTR pStrFuncName, CComVariant* pOutVarRes)
|
||||
{
|
||||
BOOL bRes = FALSE;
|
||||
CComVariant vaResult;
|
||||
CComPtr<IHTMLDocument2> pIDoc2;
|
||||
if (SUCCEEDED(this->GetDHtmlDocument(&pIDoc2))) //Uses CDHtmlDialog as 'this'
|
||||
{
|
||||
//Getting IDispatch for Java Script objects
|
||||
CComPtr<IDispatch> spScript;
|
||||
if (SUCCEEDED(pIDoc2->get_Script(&spScript)))
|
||||
{
|
||||
//Find dispid for given function in the object
|
||||
CComBSTR bstrMember(pStrFuncName);
|
||||
DISPID dispid = NULL;
|
||||
if (SUCCEEDED(spScript->GetIDsOfNames(IID_NULL, &bstrMember, 1, LOCALE_USER_DEFAULT, &dispid)))
|
||||
{
|
||||
EXCEPINFO excepInfo;
|
||||
memset(&excepInfo, 0, sizeof excepInfo);
|
||||
|
||||
DISPPARAMS dispparams;
|
||||
memset(&dispparams, 0, sizeof dispparams);
|
||||
dispparams.cArgs = 0;
|
||||
dispparams.cNamedArgs = 0;
|
||||
|
||||
UINT nArgErr = static_cast<UINT>(-1); // initialize to invalid arg
|
||||
|
||||
//Call JavaScript function
|
||||
bRes = SUCCEEDED(spScript->Invoke(dispid, IID_NULL, 0, DISPATCH_METHOD, &dispparams, &vaResult, &excepInfo, &nArgErr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pOutVarRes)
|
||||
*pOutVarRes = vaResult;
|
||||
|
||||
return bRes;
|
||||
}
|
||||
|
||||
// The system calls this function to obtain the cursor to display while the user drags
|
||||
// the minimized window.
|
||||
|
||||
void CSiaDriveDlg::DisplayPopUp(const String& name)
|
||||
{
|
||||
CallClientScript(L"displayPopUp", name, nullptr);
|
||||
}
|
||||
|
||||
BOOL CSiaDriveDlg::PreTranslateMessage(MSG* pMsg)
|
||||
{
|
||||
//TODO: Implement copy/paste context menu
|
||||
if (IsRefreshKeyMessage(pMsg) || (pMsg->message == WM_RBUTTONDOWN) || (pMsg->message == WM_RBUTTONDBLCLK))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return CDHtmlDialog::PreTranslateMessage(pMsg);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetClientVersion(const String& version)
|
||||
{
|
||||
CallClientScript(L"setClientVersion", version, nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetServerVersion(const String& version)
|
||||
{
|
||||
CallClientScript(L"setServerVersion", version, nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetWalletConfirmedBalance(const String& balance)
|
||||
{
|
||||
CallClientScript(L"setWalletConfirmedBalance", balance, nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetWalletUnconfirmedBalance(const String& balance)
|
||||
{
|
||||
CallClientScript(L"setWalletUnconfirmedBalance", balance, nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetWalletTotalBalance(const String& balance)
|
||||
{
|
||||
CallClientScript(L"setWalletTotalBalance", balance, nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetWalletReceiveAddress(const String& address)
|
||||
{
|
||||
_receiveAddress = address;
|
||||
CallClientScript(L"setWalletReceiveAddress", address, nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetConsensusHeight(const std::uint64_t& height)
|
||||
{
|
||||
CallClientScript(L"setConsensusHeight", height ? std::to_wstring(height) : L"...", nullptr);
|
||||
}
|
||||
|
||||
String CSiaDriveDlg::GetWalletReceiveAddress()
|
||||
{
|
||||
CComVariant result;
|
||||
CallClientScript(L"getWalletReceiveAddress", &result);
|
||||
|
||||
return result.bstrVal ? result.bstrVal : L"";
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetWalletUnlockPassword(const String& password)
|
||||
{
|
||||
CallClientScript(L"setWalletUnlockPassword", password, nullptr);
|
||||
}
|
||||
|
||||
String CSiaDriveDlg::GetWalletUnlockPassword()
|
||||
{
|
||||
CComVariant result;
|
||||
CallClientScript(L"getWalletUnlockPassword", &result);
|
||||
|
||||
return result.bstrVal ? result.bstrVal : L"";
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetRenterAllocatedFunds(const SiaCurrency& currency)
|
||||
{
|
||||
CallClientScript(L"setRenterAllocatedFunds", SiaCurrencyToString(currency), nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetRenterHosts(const std::uint64_t& hosts)
|
||||
{
|
||||
CallClientScript(L"setRenterHosts", std::to_wstring(hosts), nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetRenterAvailableFunds(const SiaCurrency& currency)
|
||||
{
|
||||
CallClientScript(L"setRenterAvailableFunds", SiaCurrencyToString(currency), nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetRenterUsedFunds(const SiaCurrency& currency)
|
||||
{
|
||||
CallClientScript(L"setRenterUsedFunds", SiaCurrencyToString(currency), nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetRenterTotalUsed(const std::uint64_t& bytes)
|
||||
{
|
||||
double total = bytes ? bytes / (1024.0 * 1024.0 * 1024.0) : 0.0;
|
||||
CallClientScript(L"setRenterTotalUsedGb", std::to_wstring(total), nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::ClearDisplay()
|
||||
{
|
||||
SetServerVersion(L"...");
|
||||
@@ -536,153 +445,6 @@ void CSiaDriveDlg::ClearDisplay()
|
||||
SetConsensusHeight(0);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::QueueUiAction(std::function<void()> fn)
|
||||
{
|
||||
if (GetCurrentThreadId() == _uiThreadId)
|
||||
{
|
||||
fn();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_uiActionQueueMutex);
|
||||
_uiActionQueue.push_back(fn);
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::ProcessUiActionQueue()
|
||||
{
|
||||
std::deque<std::function<void()>> items;
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_uiActionQueueMutex);
|
||||
items = _uiActionQueue;
|
||||
_uiActionQueue.clear();
|
||||
}
|
||||
|
||||
while (items.size())
|
||||
{
|
||||
items.front()();
|
||||
items.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
bool CSiaDriveDlg::UpdateSiaInfo()
|
||||
{
|
||||
const String serverVersion = _siaApi->GetServerVersion();
|
||||
if (serverVersion.length())
|
||||
{
|
||||
if (_siaApi->GetWallet()->Refresh())
|
||||
{
|
||||
SiaCurrency confirmed;
|
||||
if (ApiSuccess(_siaApi->GetWallet()->GetConfirmedBalance(confirmed)))
|
||||
{
|
||||
SiaCurrency unconfirmed;
|
||||
if (ApiSuccess(_siaApi->GetWallet()->GetUnonfirmedBalance(unconfirmed)))
|
||||
{
|
||||
SiaCurrency total = confirmed + unconfirmed;
|
||||
|
||||
SetServerVersion(serverVersion);
|
||||
SetWalletConfirmedBalance(SiaCurrencyToString(confirmed));
|
||||
SetWalletUnconfirmedBalance(SiaCurrencyToString(unconfirmed));
|
||||
SetWalletTotalBalance(SiaCurrencyToString(total));
|
||||
if (_receiveAddress.empty())
|
||||
{
|
||||
String receiveAddress;
|
||||
_siaApi->GetWallet()->GetAddress(receiveAddress);
|
||||
SetWalletReceiveAddress(receiveAddress);
|
||||
}
|
||||
|
||||
SiaCurrency allocatedFunds = _siaApi->GetRenter()->GetFunds();
|
||||
SiaCurrency unspentFunds = _siaApi->GetRenter()->GetUnspent();
|
||||
SetRenterAllocatedFunds(allocatedFunds);
|
||||
SetRenterAvailableFunds(unspentFunds);
|
||||
SetRenterUsedFunds(allocatedFunds - unspentFunds);
|
||||
SetRenterHosts(_siaApi->GetRenter()->GetHosts());
|
||||
SetRenterTotalUsed(_siaApi->GetRenter()->GetTotalUsedBytes());
|
||||
|
||||
SetConsensusHeight(_siaApi->GetConsensus()->GetHeight());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ClearDisplay();
|
||||
return false;
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::ReloadDisplay()
|
||||
{
|
||||
KillTimer(IDT_UPDATE);
|
||||
ClearDisplay();
|
||||
this->Navigate(this->m_strCurrentUrl);
|
||||
}
|
||||
|
||||
bool CSiaDriveDlg::UpdateUi(const bool& refresh)
|
||||
{
|
||||
bool ret = UpdateSiaInfo();
|
||||
if (ret)
|
||||
{
|
||||
if (!_connected && !_seedCreation)
|
||||
{
|
||||
ReloadDisplay();
|
||||
}
|
||||
}
|
||||
else if (refresh && !_seedCreation)
|
||||
{
|
||||
_connected = false;
|
||||
ReloadDisplay();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::GetDomNodeById(const String& id, CComPtr<IHTMLDOMNode>& node)
|
||||
{
|
||||
CComPtr<IHTMLElement> elem;
|
||||
return GetDomNodeAndElementById(id, node, elem);
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::GetDomNodeAndElementById(const String& id, CComPtr<IHTMLDOMNode>& node, CComPtr<IHTMLElement>& elem)
|
||||
{
|
||||
HRESULT hr;
|
||||
if (SUCCEEDED((hr = GetElement(id.c_str(), &elem))))
|
||||
{
|
||||
hr = elem->QueryInterface(IID_IHTMLDOMNode, reinterpret_cast<void**>(&node));
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::RemoveDomNodeById(const String& id)
|
||||
{
|
||||
CComPtr<IHTMLDOMNode> element;
|
||||
if (SUCCEEDED(GetDomNodeById(id.c_str(), element)))
|
||||
{
|
||||
CComPtr<IHTMLDOMNode> parent;
|
||||
if (SUCCEEDED(element->get_parentNode(&parent)))
|
||||
{
|
||||
CComPtr<IHTMLDOMNode> removed;
|
||||
parent->removeChild(element, &removed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::RemoveCreateWalletItems()
|
||||
{
|
||||
RemoveDomNodeById(L"create_wallet");
|
||||
RemoveDomNodeById(L"disp_wallet_seed");
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::DisplayCreateWallet()
|
||||
{
|
||||
SetMainWindow(L"create_wallet");
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::DisplayRenterTab()
|
||||
{
|
||||
SetTabWindow(L"ID_Tab_Renter");
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::ConfigureWallet()
|
||||
{
|
||||
if (_siaApi->GetWallet()->GetCreated())
|
||||
@@ -715,6 +477,21 @@ void CSiaDriveDlg::ConfigureWallet()
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::DisplayCreateWallet()
|
||||
{
|
||||
SetMainWindow(L"create_wallet");
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::DisplayPopUp(const String& name)
|
||||
{
|
||||
CallClientScript(L"displayPopUp", name, nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::DisplayRenterTab()
|
||||
{
|
||||
SetTabWindow(L"ID_Tab_Renter");
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::DisplaySeedCreated(const String& seed)
|
||||
{
|
||||
SetMainWindow(L"disp_wallet_seed");
|
||||
@@ -728,6 +505,87 @@ void CSiaDriveDlg::DisplayUnlockWallet()
|
||||
SetFocusToElement(L"ID_WalletUnlockPwd");
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::GetDomNodeAndElementById(const String& id, CComPtr<IHTMLDOMNode>& node, CComPtr<IHTMLElement>& elem)
|
||||
{
|
||||
HRESULT hr;
|
||||
if (SUCCEEDED((hr = GetElement(id.c_str(), &elem))))
|
||||
{
|
||||
hr = elem->QueryInterface(IID_IHTMLDOMNode, reinterpret_cast<void**>(&node));
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT CSiaDriveDlg::GetDomNodeById(const String& id, CComPtr<IHTMLDOMNode>& node)
|
||||
{
|
||||
CComPtr<IHTMLElement> elem;
|
||||
return GetDomNodeAndElementById(id, node, elem);
|
||||
}
|
||||
|
||||
String CSiaDriveDlg::GetWalletUnlockPassword()
|
||||
{
|
||||
CComVariant result;
|
||||
CallClientScript(L"getWalletUnlockPassword", &result);
|
||||
|
||||
return result.bstrVal ? result.bstrVal : L"";
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::ProcessUiActionQueue()
|
||||
{
|
||||
std::deque<std::function<void()>> items;
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_uiActionQueueMutex);
|
||||
items = _uiActionQueue;
|
||||
_uiActionQueue.clear();
|
||||
}
|
||||
|
||||
while (items.size())
|
||||
{
|
||||
items.front()();
|
||||
items.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::QueueUiAction(std::function<void()> fn)
|
||||
{
|
||||
if (GetCurrentThreadId() == _uiThreadId)
|
||||
{
|
||||
fn();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_uiActionQueueMutex);
|
||||
_uiActionQueue.push_back(fn);
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::ReloadDisplay()
|
||||
{
|
||||
KillTimer(IDT_UPDATE);
|
||||
ClearDisplay();
|
||||
this->Navigate(this->m_strCurrentUrl);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::RemoveCreateWalletItems()
|
||||
{
|
||||
RemoveDomNodeById(L"create_wallet");
|
||||
RemoveDomNodeById(L"disp_wallet_seed");
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::RemoveDomNodeById(const String& id)
|
||||
{
|
||||
CComPtr<IHTMLDOMNode> element;
|
||||
if (SUCCEEDED(GetDomNodeById(id.c_str(), element)))
|
||||
{
|
||||
CComPtr<IHTMLDOMNode> parent;
|
||||
if (SUCCEEDED(element->get_parentNode(&parent)))
|
||||
{
|
||||
CComPtr<IHTMLDOMNode> removed;
|
||||
parent->removeChild(element, &removed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetChildWindow(const String& parentName, const String& name)
|
||||
{
|
||||
CComPtr<IHTMLDOMNode> mainNode;
|
||||
@@ -786,12 +644,143 @@ void CSiaDriveDlg::SetChildWindow(const String& parentName, const String& name)
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetClientVersion(const String& version)
|
||||
{
|
||||
CallClientScript(L"setClientVersion", version, nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetConsensusHeight(const std::uint64_t& height)
|
||||
{
|
||||
CallClientScript(L"setConsensusHeight", height ? std::to_wstring(height) : L"...", nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetMainWindow(const String& name)
|
||||
{
|
||||
SetChildWindow(L"main_window", name);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetRenterAllocatedFunds(const SiaCurrency& currency)
|
||||
{
|
||||
CallClientScript(L"setRenterAllocatedFunds", SiaCurrencyToString(currency), nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetRenterAvailableFunds(const SiaCurrency& currency)
|
||||
{
|
||||
CallClientScript(L"setRenterAvailableFunds", SiaCurrencyToString(currency), nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetRenterHosts(const std::uint64_t& hosts)
|
||||
{
|
||||
CallClientScript(L"setRenterHosts", std::to_wstring(hosts), nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetRenterTotalUsed(const std::uint64_t& bytes)
|
||||
{
|
||||
double total = bytes ? bytes / (1024.0 * 1024.0 * 1024.0) : 0.0;
|
||||
CallClientScript(L"setRenterTotalUsedGb", std::to_wstring(total), nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetRenterUsedFunds(const SiaCurrency& currency)
|
||||
{
|
||||
CallClientScript(L"setRenterUsedFunds", SiaCurrencyToString(currency), nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetServerVersion(const String& version)
|
||||
{
|
||||
CallClientScript(L"setServerVersion", version, nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetTabWindow(const String& name)
|
||||
{
|
||||
SetChildWindow(L"ID_ActiveTab", name);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetWalletConfirmedBalance(const String& balance)
|
||||
{
|
||||
CallClientScript(L"setWalletConfirmedBalance", balance, nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetWalletReceiveAddress(const String& address)
|
||||
{
|
||||
_receiveAddress = address;
|
||||
CallClientScript(L"setWalletReceiveAddress", address, nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetWalletTotalBalance(const String& balance)
|
||||
{
|
||||
CallClientScript(L"setWalletTotalBalance", balance, nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetWalletUnconfirmedBalance(const String& balance)
|
||||
{
|
||||
CallClientScript(L"setWalletUnconfirmedBalance", balance, nullptr);
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetWalletUnlockPassword(const String& password)
|
||||
{
|
||||
CallClientScript(L"setWalletUnlockPassword", password, nullptr);
|
||||
}
|
||||
|
||||
bool CSiaDriveDlg::UpdateSiaInfo()
|
||||
{
|
||||
const String serverVersion = _siaApi->GetServerVersion();
|
||||
if (serverVersion.length())
|
||||
{
|
||||
if (_siaApi->GetWallet()->Refresh())
|
||||
{
|
||||
SiaCurrency confirmed;
|
||||
if (ApiSuccess(_siaApi->GetWallet()->GetConfirmedBalance(confirmed)))
|
||||
{
|
||||
SiaCurrency unconfirmed;
|
||||
if (ApiSuccess(_siaApi->GetWallet()->GetUnonfirmedBalance(unconfirmed)))
|
||||
{
|
||||
SiaCurrency total = confirmed + unconfirmed;
|
||||
|
||||
SetServerVersion(serverVersion);
|
||||
SetWalletConfirmedBalance(SiaCurrencyToString(confirmed));
|
||||
SetWalletUnconfirmedBalance(SiaCurrencyToString(unconfirmed));
|
||||
SetWalletTotalBalance(SiaCurrencyToString(total));
|
||||
if (_receiveAddress.empty())
|
||||
{
|
||||
String receiveAddress;
|
||||
_siaApi->GetWallet()->GetAddress(receiveAddress);
|
||||
SetWalletReceiveAddress(receiveAddress);
|
||||
}
|
||||
|
||||
SiaCurrency allocatedFunds = _siaApi->GetRenter()->GetFunds();
|
||||
SiaCurrency unspentFunds = _siaApi->GetRenter()->GetUnspent();
|
||||
SetRenterAllocatedFunds(allocatedFunds);
|
||||
SetRenterAvailableFunds(unspentFunds);
|
||||
SetRenterUsedFunds(allocatedFunds - unspentFunds);
|
||||
SetRenterHosts(_siaApi->GetRenter()->GetHosts());
|
||||
SetRenterTotalUsed(_siaApi->GetRenter()->GetTotalUsedBytes());
|
||||
|
||||
SetConsensusHeight(_siaApi->GetConsensus()->GetHeight());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ClearDisplay();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSiaDriveDlg::UpdateUi(const bool& refresh)
|
||||
{
|
||||
bool ret = UpdateSiaInfo();
|
||||
if (ret)
|
||||
{
|
||||
if (!_connected && !_seedCreation)
|
||||
{
|
||||
ReloadDisplay();
|
||||
}
|
||||
}
|
||||
else if (refresh && !_seedCreation)
|
||||
{
|
||||
_connected = false;
|
||||
ReloadDisplay();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
@@ -74,7 +74,6 @@ private:
|
||||
void SetWalletConfirmedBalance(const String& balance);
|
||||
void SetWalletUnconfirmedBalance(const String& balance);
|
||||
void SetWalletTotalBalance(const String& balance);
|
||||
String GetWalletReceiveAddress();
|
||||
void SetWalletReceiveAddress(const String& address);
|
||||
String GetWalletUnlockPassword();
|
||||
void SetWalletUnlockPassword(const String& address);
|
||||
|
Reference in New Issue
Block a user