Refactoring
This commit is contained in:
@@ -7,7 +7,8 @@ CSiaApi::_CSiaConsensus::_CSiaConsensus(const CSiaCurl& siaCurl) :
|
|||||||
CSiaBase(siaCurl),
|
CSiaBase(siaCurl),
|
||||||
CAutoThread(siaCurl),
|
CAutoThread(siaCurl),
|
||||||
_Height(0),
|
_Height(0),
|
||||||
_Synced(false)
|
_Synced(false),
|
||||||
|
_CurrentBlock(L"")
|
||||||
{
|
{
|
||||||
StartAutoThread();
|
StartAutoThread();
|
||||||
}
|
}
|
||||||
|
@@ -47,7 +47,11 @@ using namespace Sia::Api;
|
|||||||
}*/
|
}*/
|
||||||
CSiaApi::_CSiaRenter::_CSiaRenter(const CSiaCurl& siaCurl) :
|
CSiaApi::_CSiaRenter::_CSiaRenter(const CSiaCurl& siaCurl) :
|
||||||
CSiaBase(siaCurl),
|
CSiaBase(siaCurl),
|
||||||
CAutoThread(siaCurl)
|
CAutoThread(siaCurl),
|
||||||
|
_Funds(0),
|
||||||
|
_Hosts(0),
|
||||||
|
_Unspent(0),
|
||||||
|
_TotalUsedBytes(0)
|
||||||
{
|
{
|
||||||
StartAutoThread();
|
StartAutoThread();
|
||||||
}
|
}
|
||||||
|
@@ -198,20 +198,20 @@
|
|||||||
<h3>Receive Address</h3>
|
<h3>Receive Address</h3>
|
||||||
<label id="ID_WalletReceiveAddress"></label>
|
<label id="ID_WalletReceiveAddress"></label>
|
||||||
<div id="ID_ActiveTab"></div>
|
<div id="ID_ActiveTab"></div>
|
||||||
|
<div class="fill" style="padding: 0; margin: 0;">
|
||||||
|
<h3>Mounting</h3>
|
||||||
|
<p>Choose an available drive letter and click 'Mount'</p>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td style="text-align: left; vertical-align: top">
|
||||||
|
<select id="ID_MountDrives"></select>
|
||||||
|
<input id="ID_MountButton" type="button" value="Mount" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="fill">
|
|
||||||
<h3>Mounting</h3>
|
|
||||||
<p>Choose an available drive letter and click 'Mount'</p>
|
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<td style="text-align: left; vertical-align: top">
|
|
||||||
<select id="ID_MountDrives"></select>
|
|
||||||
<input id="ID_MountButton" type="button" value="Mount" />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<table class="fill">
|
<table class="fill">
|
||||||
|
@@ -90,8 +90,8 @@ END_DHTML_EVENT_MAP()
|
|||||||
|
|
||||||
CSiaDriveDlg::CSiaDriveDlg(CWnd* pParent /*=NULL*/)
|
CSiaDriveDlg::CSiaDriveDlg(CWnd* pParent /*=NULL*/)
|
||||||
: CDHtmlDialog(IDD_SIADRIVE_DIALOG, IDR_HTML_SIADRIVE_DIALOG, pParent),
|
: CDHtmlDialog(IDD_SIADRIVE_DIALOG, IDR_HTML_SIADRIVE_DIALOG, pParent),
|
||||||
_uiThreadId(GetCurrentThreadId()),
|
_uiThreadId(GetCurrentThreadId())
|
||||||
_siaApi({L"localhost", 9980, L"1.1.0"})
|
|
||||||
{
|
{
|
||||||
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
||||||
}
|
}
|
||||||
@@ -308,8 +308,8 @@ HRESULT CSiaDriveDlg::OnButtonConfirmSeed(IHTMLElement* /*pElement*/)
|
|||||||
{
|
{
|
||||||
_seedCreation = false;
|
_seedCreation = false;
|
||||||
_walletCreatedSeed = L"";
|
_walletCreatedSeed = L"";
|
||||||
UpdateData(FALSE);
|
|
||||||
this->Navigate(this->m_strCurrentUrl);
|
ReloadDisplay();
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
@@ -319,12 +319,12 @@ HRESULT CSiaDriveDlg::OnButtonUnlockWallet(IHTMLElement* /*pElement*/)
|
|||||||
SetBodyEnabled(false);
|
SetBodyEnabled(false);
|
||||||
String pwd = GetWalletUnlockPassword();
|
String pwd = GetWalletUnlockPassword();
|
||||||
std::thread th([this, pwd]() {
|
std::thread th([this, pwd]() {
|
||||||
if (ApiSuccess(_siaApi.GetWallet()->Unlock(pwd)))
|
if (ApiSuccess(_siaApi->GetWallet()->Unlock(pwd)))
|
||||||
{
|
{
|
||||||
QueueUiAction([this]() {
|
QueueUiAction([this]() {
|
||||||
SetWalletUnlockPassword(L"");
|
SetWalletUnlockPassword(L"");
|
||||||
SetBodyEnabled(true);
|
SetBodyEnabled(true);
|
||||||
this->Navigate(this->m_strCurrentUrl);
|
ReloadDisplay();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -403,6 +403,7 @@ void CSiaDriveDlg::SetWalletTotalBalance(const String& balance)
|
|||||||
|
|
||||||
void CSiaDriveDlg::SetWalletReceiveAddress(const String& address)
|
void CSiaDriveDlg::SetWalletReceiveAddress(const String& address)
|
||||||
{
|
{
|
||||||
|
_receiveAddress = address;
|
||||||
CallClientScript(L"setWalletReceiveAddress", address, nullptr);
|
CallClientScript(L"setWalletReceiveAddress", address, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,17 +459,14 @@ void CSiaDriveDlg::SetRenterTotalUsed(const std::uint64_t& bytes)
|
|||||||
CallClientScript(L"setRenterTotalUsedGb", std::to_wstring(total), nullptr);
|
CallClientScript(L"setRenterTotalUsedGb", std::to_wstring(total), nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
void CSiaDriveDlg::ClearDisplay()
|
||||||
{
|
{
|
||||||
KillTimer(IDT_UPDATE);
|
SetServerVersion(L"...");
|
||||||
KillTimer(IDT_UI_ACTION_QUEUE);
|
|
||||||
|
|
||||||
SetServerVersion(L"x.x.x.");
|
|
||||||
SetClientVersion(L"1.0.0");
|
SetClientVersion(L"1.0.0");
|
||||||
|
|
||||||
SetWalletConfirmedBalance(L"");
|
SetWalletConfirmedBalance(L"...");
|
||||||
SetWalletUnconfirmedBalance(L"");
|
SetWalletUnconfirmedBalance(L"...");
|
||||||
SetWalletTotalBalance(L"");
|
SetWalletTotalBalance(L"...");
|
||||||
SetWalletReceiveAddress(L"");
|
SetWalletReceiveAddress(L"");
|
||||||
|
|
||||||
SetRenterAllocatedFunds(0);
|
SetRenterAllocatedFunds(0);
|
||||||
@@ -478,6 +476,19 @@ void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
|||||||
SetRenterTotalUsed(0);
|
SetRenterTotalUsed(0);
|
||||||
|
|
||||||
SetConsensusHeight(0);
|
SetConsensusHeight(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
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_UPDATE, 2000, nullptr);
|
||||||
SetTimer(IDT_UI_ACTION_QUEUE, 100, nullptr);
|
SetTimer(IDT_UI_ACTION_QUEUE, 100, nullptr);
|
||||||
@@ -540,16 +551,16 @@ void CSiaDriveDlg::ProcessUiActionQueue()
|
|||||||
|
|
||||||
bool CSiaDriveDlg::UpdateSiaInfo()
|
bool CSiaDriveDlg::UpdateSiaInfo()
|
||||||
{
|
{
|
||||||
const String serverVersion = _siaApi.GetServerVersion();
|
const String serverVersion = _siaApi->GetServerVersion();
|
||||||
if (serverVersion.length())
|
if (serverVersion.length())
|
||||||
{
|
{
|
||||||
if (_siaApi.GetWallet()->Refresh())
|
if (_siaApi->GetWallet()->Refresh())
|
||||||
{
|
{
|
||||||
SiaCurrency confirmed;
|
SiaCurrency confirmed;
|
||||||
if (ApiSuccess(_siaApi.GetWallet()->GetConfirmedBalance(confirmed)))
|
if (ApiSuccess(_siaApi->GetWallet()->GetConfirmedBalance(confirmed)))
|
||||||
{
|
{
|
||||||
SiaCurrency unconfirmed;
|
SiaCurrency unconfirmed;
|
||||||
if (ApiSuccess(_siaApi.GetWallet()->GetUnonfirmedBalance(unconfirmed)))
|
if (ApiSuccess(_siaApi->GetWallet()->GetUnonfirmedBalance(unconfirmed)))
|
||||||
{
|
{
|
||||||
SiaCurrency total = confirmed + unconfirmed;
|
SiaCurrency total = confirmed + unconfirmed;
|
||||||
|
|
||||||
@@ -557,44 +568,39 @@ bool CSiaDriveDlg::UpdateSiaInfo()
|
|||||||
SetWalletConfirmedBalance(SiaCurrencyToString(confirmed));
|
SetWalletConfirmedBalance(SiaCurrencyToString(confirmed));
|
||||||
SetWalletUnconfirmedBalance(SiaCurrencyToString(unconfirmed));
|
SetWalletUnconfirmedBalance(SiaCurrencyToString(unconfirmed));
|
||||||
SetWalletTotalBalance(SiaCurrencyToString(total));
|
SetWalletTotalBalance(SiaCurrencyToString(total));
|
||||||
if (GetWalletReceiveAddress().empty())
|
if (_receiveAddress.empty())
|
||||||
{
|
{
|
||||||
String address;
|
String receiveAddress;
|
||||||
_siaApi.GetWallet()->GetAddress(address);
|
_siaApi->GetWallet()->GetAddress(receiveAddress);
|
||||||
SetWalletReceiveAddress(address);
|
SetWalletReceiveAddress(receiveAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
SiaCurrency allocatedFunds = _siaApi.GetRenter()->GetFunds();
|
SiaCurrency allocatedFunds = _siaApi->GetRenter()->GetFunds();
|
||||||
SiaCurrency unspentFunds = _siaApi.GetRenter()->GetUnspent();
|
SiaCurrency unspentFunds = _siaApi->GetRenter()->GetUnspent();
|
||||||
SetRenterAllocatedFunds(allocatedFunds);
|
SetRenterAllocatedFunds(allocatedFunds);
|
||||||
SetRenterAvailableFunds(unspentFunds);
|
SetRenterAvailableFunds(unspentFunds);
|
||||||
SetRenterUsedFunds(allocatedFunds - unspentFunds);
|
SetRenterUsedFunds(allocatedFunds - unspentFunds);
|
||||||
SetRenterHosts(_siaApi.GetRenter()->GetHosts());
|
SetRenterHosts(_siaApi->GetRenter()->GetHosts());
|
||||||
SetRenterTotalUsed(_siaApi.GetRenter()->GetTotalUsedBytes());
|
SetRenterTotalUsed(_siaApi->GetRenter()->GetTotalUsedBytes());
|
||||||
|
|
||||||
SetConsensusHeight(_siaApi.GetConsensus()->GetHeight());
|
SetConsensusHeight(_siaApi->GetConsensus()->GetHeight());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetServerVersion(L"x.x.x");
|
ClearDisplay();
|
||||||
SetWalletConfirmedBalance(L"");
|
|
||||||
SetWalletUnconfirmedBalance(L"");
|
|
||||||
SetWalletTotalBalance(L"");
|
|
||||||
SetWalletReceiveAddress(L"");
|
|
||||||
|
|
||||||
SetRenterAllocatedFunds(0);
|
|
||||||
SetRenterAvailableFunds(0);
|
|
||||||
SetRenterUsedFunds(0);
|
|
||||||
SetRenterHosts(0);
|
|
||||||
SetRenterTotalUsed(0);
|
|
||||||
|
|
||||||
SetConsensusHeight(0);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSiaDriveDlg::ReloadDisplay()
|
||||||
|
{
|
||||||
|
KillTimer(IDT_UPDATE);
|
||||||
|
ClearDisplay();
|
||||||
|
this->Navigate(this->m_strCurrentUrl);
|
||||||
|
}
|
||||||
|
|
||||||
bool CSiaDriveDlg::UpdateUi(const bool& refresh)
|
bool CSiaDriveDlg::UpdateUi(const bool& refresh)
|
||||||
{
|
{
|
||||||
bool ret = UpdateSiaInfo();
|
bool ret = UpdateSiaInfo();
|
||||||
@@ -602,15 +608,13 @@ bool CSiaDriveDlg::UpdateUi(const bool& refresh)
|
|||||||
{
|
{
|
||||||
if (!_connected && !_seedCreation)
|
if (!_connected && !_seedCreation)
|
||||||
{
|
{
|
||||||
KillTimer(IDT_UPDATE);
|
ReloadDisplay();
|
||||||
this->Navigate(this->m_strCurrentUrl);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (refresh && !_seedCreation)
|
else if (refresh && !_seedCreation)
|
||||||
{
|
{
|
||||||
_connected = false;
|
_connected = false;
|
||||||
KillTimer(IDT_UPDATE);
|
ReloadDisplay();
|
||||||
this->Navigate(this->m_strCurrentUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -665,16 +669,15 @@ void CSiaDriveDlg::DisplayRenterTab()
|
|||||||
|
|
||||||
void CSiaDriveDlg::ConfigureWallet()
|
void CSiaDriveDlg::ConfigureWallet()
|
||||||
{
|
{
|
||||||
if (_siaApi.GetWallet()->GetCreated())
|
if (_siaApi->GetWallet()->GetCreated())
|
||||||
{
|
{
|
||||||
RemoveCreateWalletItems();
|
RemoveCreateWalletItems();
|
||||||
if (_siaApi.GetWallet()->GetLocked())
|
if (_siaApi->GetWallet()->GetLocked())
|
||||||
{
|
{
|
||||||
DisplayUnlockWallet();
|
DisplayUnlockWallet();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CallClientScript(L"setAvailableDrives", json(GetAvailableDrives()), nullptr);
|
|
||||||
SetMainWindow(L"ID_TabWindow");
|
SetMainWindow(L"ID_TabWindow");
|
||||||
|
|
||||||
switch (_siaConfig.GetUI_Main_TabIndex())
|
switch (_siaConfig.GetUI_Main_TabIndex())
|
||||||
@@ -782,7 +785,7 @@ HRESULT CSiaDriveDlg::OnButtonCreateWallet(IHTMLElement* pElement)
|
|||||||
KillTimer(IDT_UPDATE);
|
KillTimer(IDT_UPDATE);
|
||||||
|
|
||||||
String seed;
|
String seed;
|
||||||
if (ApiSuccess(_siaApi.GetWallet()->Create(SiaSeedLanguage::English, seed)))
|
if (ApiSuccess(_siaApi->GetWallet()->Create(SiaSeedLanguage::English, seed)))
|
||||||
{
|
{
|
||||||
DisplaySeedCreated(seed);
|
DisplaySeedCreated(seed);
|
||||||
}
|
}
|
||||||
|
@@ -53,6 +53,7 @@ private:
|
|||||||
void DisplayRenterTab();
|
void DisplayRenterTab();
|
||||||
void DisplaySeedCreated(const String& seed);
|
void DisplaySeedCreated(const String& seed);
|
||||||
bool UpdateSiaInfo();
|
bool UpdateSiaInfo();
|
||||||
|
void ReloadDisplay();
|
||||||
void DisplayUnlockWallet();
|
void DisplayUnlockWallet();
|
||||||
void ConfigureWallet();
|
void ConfigureWallet();
|
||||||
void RemoveCreateWalletItems();
|
void RemoveCreateWalletItems();
|
||||||
@@ -85,12 +86,14 @@ private:
|
|||||||
void SetRenterTotalUsed(const std::uint64_t& bytes);
|
void SetRenterTotalUsed(const std::uint64_t& bytes);
|
||||||
void QueueUiAction(std::function<void()> action);
|
void QueueUiAction(std::function<void()> action);
|
||||||
void ProcessUiActionQueue();
|
void ProcessUiActionQueue();
|
||||||
|
void ClearDisplay();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const DWORD _uiThreadId;
|
const DWORD _uiThreadId;
|
||||||
CSiaDriveConfig _siaConfig;
|
CSiaDriveConfig _siaConfig;
|
||||||
CSiaApi _siaApi;
|
std::unique_ptr<CSiaApi> _siaApi;
|
||||||
CString _walletCreatedSeed;
|
CString _walletCreatedSeed;
|
||||||
|
String _receiveAddress;
|
||||||
std::mutex _uiActionQueueMutex;
|
std::mutex _uiActionQueueMutex;
|
||||||
std::deque<std::function<void()>> _uiActionQueue;
|
std::deque<std::function<void()>> _uiActionQueue;
|
||||||
bool _connected = false;
|
bool _connected = false;
|
||||||
|
Reference in New Issue
Block a user