Fixed wallet refresh
This commit is contained in:
@@ -14,7 +14,7 @@ CSiaApi::CSiaApi(const SiaHostConfig& hostConfig) :
|
|||||||
CSiaApi::~CSiaApi()
|
CSiaApi::~CSiaApi()
|
||||||
{
|
{
|
||||||
//TODO Make this an option to lock on exit
|
//TODO Make this an option to lock on exit
|
||||||
_wallet->Lock();
|
//_wallet->Lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
String CSiaApi::FormatToSiaPath(String path)
|
String CSiaApi::FormatToSiaPath(String path)
|
||||||
|
@@ -70,15 +70,15 @@
|
|||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: right">Available:</td>
|
<td style="text-align: right">Available:</td>
|
||||||
<td id="WalletBalanceConfirmed"></td>
|
<td id="ID_WalletConfirmedBalance"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: right">Pending:</td>
|
<td style="text-align: right">Pending:</td>
|
||||||
<td id="WalletBalanceUnconfirmed"></td>
|
<td id="ID_WalletBalanceUnconfirmed"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: right">Total:</td>
|
<td style="text-align: right">Total:</td>
|
||||||
<td id="WalletBalanceTotal"></td>
|
<td id="ID_WalletTotalBalance"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@@ -101,7 +101,7 @@
|
|||||||
<div id="unlock_wallet" style="display: none" class="fill">
|
<div id="unlock_wallet" style="display: none" class="fill">
|
||||||
<h3>Unlock Wallet</h3>
|
<h3>Unlock Wallet</h3>
|
||||||
<p>Enter wallet password and click 'Unlock' to continue.</p>
|
<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>
|
<button ID="UnlockWalletButton">Unlock</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@
|
|||||||
|
|
||||||
<div id="tab_view" style="display: none" class="fill">
|
<div id="tab_view" style="display: none" class="fill">
|
||||||
<h3>Receive Address</h3>
|
<h3>Receive Address</h3>
|
||||||
<label id="WalletAddress"></label><br/><br/>
|
<label id="ID_WalletReceiveAddress"></label><br/><br/>
|
||||||
<TABLE class="fill">
|
<TABLE class="fill">
|
||||||
<TR>
|
<TR>
|
||||||
<TD ALIGN=CENTER VALIGN=TOP>
|
<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 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' };
|
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;
|
std::set<std::string> avail;
|
||||||
for (size_t i = 0; i < alpha.size(); i++)
|
for (size_t i = 0; i < alpha.size(); i++)
|
||||||
@@ -96,12 +96,7 @@ CSiaDriveDlg::CSiaDriveDlg(CWnd* pParent /*=NULL*/)
|
|||||||
void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX)
|
void CSiaDriveDlg::DoDataExchange(CDataExchange* pDX)
|
||||||
{
|
{
|
||||||
CDHtmlDialog::DoDataExchange(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_ElementInnerText(pDX, _T("WalletCreatedSeed"), _walletCreatedSeed);
|
||||||
DDX_DHtml_ElementValue(pDX, _T("WalletUnlockPwd"), _unlockWalletPwd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN_MESSAGE_MAP(CSiaDriveDlg, CDHtmlDialog)
|
BEGIN_MESSAGE_MAP(CSiaDriveDlg, CDHtmlDialog)
|
||||||
@@ -238,6 +233,47 @@ BOOL CSiaDriveDlg::CallClientScript(LPCTSTR pStrFuncName, const json& json, CCom
|
|||||||
return CallClientScript(pStrFuncName, data, pOutVarRes);
|
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 system calls this function to obtain the cursor to display while the user drags
|
||||||
// the minimized window.
|
// the minimized window.
|
||||||
HCURSOR CSiaDriveDlg::OnQueryDragIcon()
|
HCURSOR CSiaDriveDlg::OnQueryDragIcon()
|
||||||
@@ -269,20 +305,16 @@ HRESULT CSiaDriveDlg::OnButtonConfirmSeed(IHTMLElement* /*pElement*/)
|
|||||||
|
|
||||||
HRESULT CSiaDriveDlg::OnButtonUnlockWallet(IHTMLElement* /*pElement*/)
|
HRESULT CSiaDriveDlg::OnButtonUnlockWallet(IHTMLElement* /*pElement*/)
|
||||||
{
|
{
|
||||||
UpdateData(TRUE);
|
if (API_SUCCESS(SiaApiError, _siaApi.GetWallet()->Unlock(GetWalletUnlockPassword())))
|
||||||
|
|
||||||
if (API_SUCCESS(SiaApiError, _siaApi.GetWallet()->Unlock(_unlockWalletPwd.GetBuffer())))
|
|
||||||
{
|
{
|
||||||
_unlockWalletPwd = L"";
|
SetWalletUnlockPassword(L"");
|
||||||
UpdateData(FALSE);
|
|
||||||
this->Navigate(this->m_strCurrentUrl);
|
this->Navigate(this->m_strCurrentUrl);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_unlockWalletPwd = L"";
|
SetWalletUnlockPassword(L"");
|
||||||
UpdateData(FALSE);
|
|
||||||
AfxMessageBox(L"Invalid password entered");
|
AfxMessageBox(L"Invalid password entered");
|
||||||
SetFocusToElement(L"WalletUnlockPwd");
|
SetFocusToElement(L"ID_WalletUnlockPwd");
|
||||||
}
|
}
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
@@ -321,16 +353,57 @@ void CSiaDriveDlg::SetServerVersion(const String& version)
|
|||||||
CallClientScript(L"setServerVersion", version, nullptr);
|
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)
|
void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
||||||
{
|
{
|
||||||
KillTimer(IDT_UPDATE);
|
KillTimer(IDT_UPDATE);
|
||||||
|
|
||||||
SetServerVersion(L"x.x.x.");
|
SetServerVersion(L"x.x.x.");
|
||||||
SetClientVersion(L"1.0.0");
|
SetClientVersion(L"1.0.0");
|
||||||
_walletBalanceConfirmed = L"";
|
SetWalletConfirmedBalance(L"");
|
||||||
_walletBalanceUnconfirmed = L"";
|
SetWalletUnconfirmedBalance(L"");
|
||||||
_walletBalanceTotal = L"";
|
SetWalletTotalBalance(L"");
|
||||||
_walletAddress = L"";
|
SetWalletReceiveAddress(L"");
|
||||||
|
|
||||||
SetTimer(IDT_UPDATE, 2000, nullptr);
|
SetTimer(IDT_UPDATE, 2000, nullptr);
|
||||||
|
|
||||||
@@ -338,10 +411,6 @@ void CSiaDriveDlg::OnDocumentComplete(LPDISPATCH, LPCTSTR)
|
|||||||
{
|
{
|
||||||
ConfigureWallet();
|
ConfigureWallet();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
UpdateData(FALSE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSiaDriveDlg::OnTimer(UINT_PTR nIDEvent)
|
void CSiaDriveDlg::OnTimer(UINT_PTR nIDEvent)
|
||||||
@@ -353,6 +422,9 @@ void CSiaDriveDlg::OnTimer(UINT_PTR nIDEvent)
|
|||||||
UpdateUi();
|
UpdateUi();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,17 +443,17 @@ bool CSiaDriveDlg::UpdateSiaInfo()
|
|||||||
{
|
{
|
||||||
SiaCurrency total = confirmed + unconfirmed;
|
SiaCurrency total = confirmed + unconfirmed;
|
||||||
|
|
||||||
_walletBalanceConfirmed = SiaCurrencyToString(confirmed).c_str();
|
SetServerVersion(serverVersion);
|
||||||
_walletBalanceUnconfirmed = SiaCurrencyToString(unconfirmed).c_str();
|
SetWalletConfirmedBalance(SiaCurrencyToString(confirmed));
|
||||||
_walletBalanceTotal = SiaCurrencyToString(total).c_str();
|
SetWalletUnconfirmedBalance(SiaCurrencyToString(unconfirmed));
|
||||||
|
SetWalletTotalBalance(SiaCurrencyToString(total));
|
||||||
|
|
||||||
if (!_walletAddress.GetLength())
|
if (GetWalletReceiveAddress().empty())
|
||||||
{
|
{
|
||||||
String address;
|
String address;
|
||||||
_siaApi.GetWallet()->GetAddress(address);
|
_siaApi.GetWallet()->GetAddress(address);
|
||||||
_walletAddress = address.c_str();
|
SetWalletReceiveAddress(address);
|
||||||
}
|
}
|
||||||
SetServerVersion(serverVersion);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -389,7 +461,10 @@ bool CSiaDriveDlg::UpdateSiaInfo()
|
|||||||
}
|
}
|
||||||
|
|
||||||
SetServerVersion(L"x.x.x");
|
SetServerVersion(L"x.x.x");
|
||||||
_walletAddress = _walletBalanceConfirmed = _walletBalanceUnconfirmed = _walletBalanceTotal = L"";
|
SetWalletConfirmedBalance(L"");
|
||||||
|
SetWalletUnconfirmedBalance(L"");
|
||||||
|
SetWalletTotalBalance(L"");
|
||||||
|
SetWalletReceiveAddress(L"");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -399,11 +474,7 @@ bool CSiaDriveDlg::UpdateUi(const bool& refresh)
|
|||||||
bool ret = UpdateSiaInfo();
|
bool ret = UpdateSiaInfo();
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
if (_connected)
|
if (!_connected && !_seedCreation)
|
||||||
{
|
|
||||||
UpdateData(FALSE);
|
|
||||||
}
|
|
||||||
else if (!_seedCreation)
|
|
||||||
{
|
{
|
||||||
KillTimer(IDT_UPDATE);
|
KillTimer(IDT_UPDATE);
|
||||||
this->Navigate(this->m_strCurrentUrl);
|
this->Navigate(this->m_strCurrentUrl);
|
||||||
@@ -502,7 +573,7 @@ void CSiaDriveDlg::DisplayUnlockWallet()
|
|||||||
{
|
{
|
||||||
KillTimer(IDT_UPDATE);
|
KillTimer(IDT_UPDATE);
|
||||||
SetMainWindow(L"unlock_wallet");
|
SetMainWindow(L"unlock_wallet");
|
||||||
SetFocusToElement(L"WalletUnlockPwd");
|
SetFocusToElement(L"ID_WalletUnlockPwd");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSiaDriveDlg::SetMainWindow(const String& name)
|
void CSiaDriveDlg::SetMainWindow(const String& name)
|
||||||
|
@@ -59,18 +59,22 @@ private:
|
|||||||
HRESULT GetDomNodeById(const String& id, CComPtr<IHTMLDOMNode>& node);
|
HRESULT GetDomNodeById(const String& id, CComPtr<IHTMLDOMNode>& node);
|
||||||
BOOL CallClientScript(LPCTSTR pStrFuncName, const json& json, CComVariant* pOutVarRes);
|
BOOL CallClientScript(LPCTSTR pStrFuncName, const json& json, CComVariant* pOutVarRes);
|
||||||
BOOL CallClientScript(LPCTSTR pStrFuncName, const String& string, CComVariant* pOutVarRes);
|
BOOL CallClientScript(LPCTSTR pStrFuncName, const String& string, CComVariant* pOutVarRes);
|
||||||
|
BOOL CallClientScript(LPCTSTR pStrFuncName, CComVariant* pOutVarRes);
|
||||||
|
|
||||||
void SetServerVersion(const String& version);
|
void SetServerVersion(const String& version);
|
||||||
void SetClientVersion(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:
|
private:
|
||||||
CSiaDriveConfig _siaConfig;
|
CSiaDriveConfig _siaConfig;
|
||||||
CSiaApi _siaApi;
|
CSiaApi _siaApi;
|
||||||
CString _walletBalanceConfirmed;
|
|
||||||
CString _walletBalanceTotal;
|
|
||||||
CString _walletBalanceUnconfirmed;
|
|
||||||
CString _walletCreatedSeed;
|
CString _walletCreatedSeed;
|
||||||
CString _walletAddress;
|
|
||||||
CString _unlockWalletPwd;
|
|
||||||
bool _connected = false;
|
bool _connected = false;
|
||||||
bool _seedCreation = false;
|
bool _seedCreation = false;
|
||||||
static const UINT IDT_UPDATE = 1;
|
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) {
|
function setInnerText(elementName, data) {
|
||||||
var elem = document.getElementById(elementName);
|
var elem = document.getElementById(elementName);
|
||||||
elem.innerText = data;
|
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) {
|
function setClientVersion(version) {
|
||||||
setInnerText("ID_ClientVersion", version);
|
setInnerText("ID_ClientVersion", version);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user