Fixed wallet refresh
This commit is contained in:
@@ -14,7 +14,7 @@ CSiaApi::CSiaApi(const SiaHostConfig& hostConfig) :
|
||||
CSiaApi::~CSiaApi()
|
||||
{
|
||||
//TODO Make this an option to lock on exit
|
||||
_wallet->Lock();
|
||||
//_wallet->Lock();
|
||||
}
|
||||
|
||||
String CSiaApi::FormatToSiaPath(String path)
|
||||
|
@@ -70,15 +70,15 @@
|
||||
<table>
|
||||
<tr>
|
||||
<td style="text-align: right">Available:</td>
|
||||
<td id="WalletBalanceConfirmed"></td>
|
||||
<td id="ID_WalletConfirmedBalance"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align: right">Pending:</td>
|
||||
<td id="WalletBalanceUnconfirmed"></td>
|
||||
<td id="ID_WalletBalanceUnconfirmed"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align: right">Total:</td>
|
||||
<td id="WalletBalanceTotal"></td>
|
||||
<td id="ID_WalletTotalBalance"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@@ -101,7 +101,7 @@
|
||||
<div id="unlock_wallet" style="display: none" class="fill">
|
||||
<h3>Unlock Wallet</h3>
|
||||
<p>Enter wallet password and click 'Unlock' to continue.</p>
|
||||
<input type="password" id="WalletUnlockPwd" style="width: inherit"/><br/><br/>
|
||||
<input type="password" id="ID_WalletUnlockPwd" style="width: inherit"/><br/><br/>
|
||||
<button ID="UnlockWalletButton">Unlock</button>
|
||||
</div>
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
|
||||
<div id="tab_view" style="display: none" class="fill">
|
||||
<h3>Receive Address</h3>
|
||||
<label id="WalletAddress"></label><br/><br/>
|
||||
<label id="ID_WalletReceiveAddress"></label><br/><br/>
|
||||
<TABLE class="fill">
|
||||
<TR>
|
||||
<TD ALIGN=CENTER VALIGN=TOP>
|
||||
|
@@ -27,7 +27,7 @@ ornament alkaline gasp pepper upkeep ablaze number sizes toyed sawmill looking b
|
||||
static std::set<std::string> GetAvailableDrives()
|
||||
{
|
||||
static const std::vector<char> alpha = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
|
||||
std::bitset<sizeof(DWORD) * 8> drives(~GetLogicalDrives());
|
||||
std::bitset<26> drives(~GetLogicalDrives() & 0xFFFFFFFF);
|
||||
|
||||
std::set<std::string> avail;
|
||||
for (size_t i = 0; i < alpha.size(); i++)
|
||||
@@ -96,12 +96,7 @@ CSiaDriveDlg::CSiaDriveDlg(CWnd* pParent /*=NULL*/)
|
||||
void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDHtmlDialog::DoDataExchange(pDX);
|
||||
DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceTotal"), _walletBalanceTotal);
|
||||
DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceConfirmed"), _walletBalanceConfirmed);
|
||||
DDX_DHtml_ElementInnerText(pDX, _T("WalletBalanceUnconfirmed"), _walletBalanceUnconfirmed);
|
||||
DDX_DHtml_ElementInnerText(pDX, _T("WalletAddress"), _walletAddress);
|
||||
DDX_DHtml_ElementInnerText(pDX, _T("WalletCreatedSeed"), _walletCreatedSeed);
|
||||
DDX_DHtml_ElementValue(pDX, _T("WalletUnlockPwd"), _unlockWalletPwd);
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(CSiaDriveDlg, CDHtmlDialog)
|
||||
@@ -238,6 +233,47 @@ 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
|
||||
if (SUCCEEDED(spScript->Invoke(dispid, IID_NULL, 0, DISPATCH_METHOD, &dispparams, &vaResult, &excepInfo, &nArgErr)))
|
||||
{
|
||||
//Done!
|
||||
bRes = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pOutVarRes)
|
||||
*pOutVarRes = vaResult;
|
||||
|
||||
return bRes;
|
||||
}
|
||||
|
||||
// The system calls this function to obtain the cursor to display while the user drags
|
||||
// the minimized window.
|
||||
HCURSOR CSiaDriveDlg::OnQueryDragIcon()
|
||||
@@ -269,20 +305,16 @@ HRESULT CSiaDriveDlg::OnButtonConfirmSeed(IHTMLElement* /*pElement*/)
|
||||
|
||||
HRESULT CSiaDriveDlg::OnButtonUnlockWallet(IHTMLElement* /*pElement*/)
|
||||
{
|
||||
UpdateData(TRUE);
|
||||
|
||||
if (API_SUCCESS(SiaApiError, _siaApi.GetWallet()->Unlock(_unlockWalletPwd.GetBuffer())))
|
||||
if (API_SUCCESS(SiaApiError, _siaApi.GetWallet()->Unlock(GetWalletUnlockPassword())))
|
||||
{
|
||||
_unlockWalletPwd = L"";
|
||||
UpdateData(FALSE);
|
||||
SetWalletUnlockPassword(L"");
|
||||
this->Navigate(this->m_strCurrentUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
_unlockWalletPwd = L"";
|
||||
UpdateData(FALSE);
|
||||
SetWalletUnlockPassword(L"");
|
||||
AfxMessageBox(L"Invalid password entered");
|
||||
SetFocusToElement(L"WalletUnlockPwd");
|
||||
SetFocusToElement(L"ID_WalletUnlockPwd");
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
@@ -321,16 +353,57 @@ 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)
|
||||
{
|
||||
CallClientScript(L"setWalletReceiveAddress", address, 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::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
||||
{
|
||||
KillTimer(IDT_UPDATE);
|
||||
|
||||
SetServerVersion(L"x.x.x.");
|
||||
SetClientVersion(L"1.0.0");
|
||||
_walletBalanceConfirmed = L"";
|
||||
_walletBalanceUnconfirmed = L"";
|
||||
_walletBalanceTotal = L"";
|
||||
_walletAddress = L"";
|
||||
SetWalletConfirmedBalance(L"");
|
||||
SetWalletUnconfirmedBalance(L"");
|
||||
SetWalletTotalBalance(L"");
|
||||
SetWalletReceiveAddress(L"");
|
||||
|
||||
SetTimer(IDT_UPDATE, 2000, nullptr);
|
||||
|
||||
@@ -338,10 +411,6 @@ void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
||||
{
|
||||
ConfigureWallet();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateData(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::OnTimer(UINT_PTR nIDEvent)
|
||||
@@ -353,6 +422,9 @@ void CSiaDriveDlg::OnTimer(UINT_PTR nIDEvent)
|
||||
UpdateUi();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,17 +443,17 @@ bool CSiaDriveDlg::UpdateSiaInfo()
|
||||
{
|
||||
SiaCurrency total = confirmed + unconfirmed;
|
||||
|
||||
_walletBalanceConfirmed = SiaCurrencyToString(confirmed).c_str();
|
||||
_walletBalanceUnconfirmed = SiaCurrencyToString(unconfirmed).c_str();
|
||||
_walletBalanceTotal = SiaCurrencyToString(total).c_str();
|
||||
SetServerVersion(serverVersion);
|
||||
SetWalletConfirmedBalance(SiaCurrencyToString(confirmed));
|
||||
SetWalletUnconfirmedBalance(SiaCurrencyToString(unconfirmed));
|
||||
SetWalletTotalBalance(SiaCurrencyToString(total));
|
||||
|
||||
if (!_walletAddress.GetLength())
|
||||
if (GetWalletReceiveAddress().empty())
|
||||
{
|
||||
String address;
|
||||
_siaApi.GetWallet()->GetAddress(address);
|
||||
_walletAddress = address.c_str();
|
||||
SetWalletReceiveAddress(address);
|
||||
}
|
||||
SetServerVersion(serverVersion);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -389,7 +461,10 @@ bool CSiaDriveDlg::UpdateSiaInfo()
|
||||
}
|
||||
|
||||
SetServerVersion(L"x.x.x");
|
||||
_walletAddress = _walletBalanceConfirmed = _walletBalanceUnconfirmed = _walletBalanceTotal = L"";
|
||||
SetWalletConfirmedBalance(L"");
|
||||
SetWalletUnconfirmedBalance(L"");
|
||||
SetWalletTotalBalance(L"");
|
||||
SetWalletReceiveAddress(L"");
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -399,11 +474,7 @@ bool CSiaDriveDlg::UpdateUi(const bool& refresh)
|
||||
bool ret = UpdateSiaInfo();
|
||||
if (ret)
|
||||
{
|
||||
if (_connected)
|
||||
{
|
||||
UpdateData(FALSE);
|
||||
}
|
||||
else if (!_seedCreation)
|
||||
if (!_connected && !_seedCreation)
|
||||
{
|
||||
KillTimer(IDT_UPDATE);
|
||||
this->Navigate(this->m_strCurrentUrl);
|
||||
@@ -502,7 +573,7 @@ void CSiaDriveDlg::DisplayUnlockWallet()
|
||||
{
|
||||
KillTimer(IDT_UPDATE);
|
||||
SetMainWindow(L"unlock_wallet");
|
||||
SetFocusToElement(L"WalletUnlockPwd");
|
||||
SetFocusToElement(L"ID_WalletUnlockPwd");
|
||||
}
|
||||
|
||||
void CSiaDriveDlg::SetMainWindow(const String& name)
|
||||
|
@@ -59,18 +59,22 @@ private:
|
||||
HRESULT GetDomNodeById(const String& id, CComPtr<IHTMLDOMNode>& node);
|
||||
BOOL CallClientScript(LPCTSTR pStrFuncName, const json& json, CComVariant* pOutVarRes);
|
||||
BOOL CallClientScript(LPCTSTR pStrFuncName, const String& string, CComVariant* pOutVarRes);
|
||||
BOOL CallClientScript(LPCTSTR pStrFuncName, CComVariant* pOutVarRes);
|
||||
|
||||
void SetServerVersion(const String& version);
|
||||
void SetClientVersion(const String& version);
|
||||
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);
|
||||
|
||||
private:
|
||||
CSiaDriveConfig _siaConfig;
|
||||
CSiaApi _siaApi;
|
||||
CString _walletBalanceConfirmed;
|
||||
CString _walletBalanceTotal;
|
||||
CString _walletBalanceUnconfirmed;
|
||||
CString _walletCreatedSeed;
|
||||
CString _walletAddress;
|
||||
CString _unlockWalletPwd;
|
||||
bool _connected = false;
|
||||
bool _seedCreation = false;
|
||||
static const UINT IDT_UPDATE = 1;
|
||||
|
@@ -1,10 +1,53 @@
|
||||
|
||||
|
||||
function setValue(elementName, data) {
|
||||
var elem = document.getElementById(elementName);
|
||||
elem.value = data;
|
||||
}
|
||||
|
||||
function setInnerText(elementName, data) {
|
||||
var elem = document.getElementById(elementName);
|
||||
elem.innerText = data;
|
||||
}
|
||||
|
||||
function getInnerText(elementName) {
|
||||
var elem = document.getElementById(elementName);
|
||||
return elem.innerText;
|
||||
}
|
||||
|
||||
function getValue(elementName) {
|
||||
var elem = document.getElementById(elementName);
|
||||
return elem.value;
|
||||
}
|
||||
|
||||
function setWalletUnlockPassword(pwd) {
|
||||
setValue("ID_WalletUnlockPwd", pwd);
|
||||
}
|
||||
|
||||
function getWalletUnlockPassword() {
|
||||
return getValue("ID_WalletUnlockPwd");
|
||||
}
|
||||
|
||||
function setWalletReceiveAddress(address) {
|
||||
setInnerText("ID_WalletReceiveAddress", address);
|
||||
}
|
||||
|
||||
function getWalletReceiveAddress() {
|
||||
return getInnerText("ID_WalletReceiveAddress");
|
||||
}
|
||||
|
||||
function setWalletTotalBalance(balance) {
|
||||
setInnerText("ID_WalletTotalBalance", balance);
|
||||
}
|
||||
|
||||
function setWalletConfirmedBalance(balance) {
|
||||
setInnerText("ID_WalletConfirmedBalance", balance);
|
||||
}
|
||||
|
||||
function setWalletUnconfirmedBalance(balance) {
|
||||
setInnerText("ID_WalletBalanceUnconfirmed", balance);
|
||||
}
|
||||
|
||||
function setClientVersion(version) {
|
||||
setInnerText("ID_ClientVersion", version);
|
||||
}
|
||||
|
Reference in New Issue
Block a user