1
0

Wallet send

This commit is contained in:
Scott E. Graves
2017-05-05 11:31:59 -05:00
parent c5eaa64c13
commit 278ff2b778
5 changed files with 54 additions and 3 deletions

View File

@@ -208,6 +208,8 @@
</div>
<div class="hidden-element" id="send_window">
<div class="box">
<h1>Available</h1>
<label id="ID_Send_Balance" class="amount"></label><br><br>
<h1>Send to Address</h1>
<input type="text" id="ID_Send_Address" style="width: 100%;"><br><br>
<h1>Send Amount <a href="javascript:void(0)" id="ID_SendMaxAmount">max</a></h1>

View File

@@ -125,6 +125,7 @@
return {
setConfirmedBalance: (balance) => {
setInnerText('ID_WalletConfirmedBalance', balance);
setInnerText('ID_Send_Balance', balance);
},
setUnconfirmedBalance: (balance) => {
setInnerText('ID_WalletBalanceUnconfirmed', balance);
@@ -267,6 +268,10 @@
window.appActions.autoMountDrive();
}
function _walletSend(address, amount, cb) {
window.appActions.walletSend(address, amount, cb);
}
return {
createWallet: _createWallet,
mountDrive: _mountDrive,
@@ -277,7 +282,8 @@
setRenterSettings: _setRenterSettings,
calculateEstimatedStorage: _calculateEstimatedStorage,
setSiaSettings: _setSiaSettings,
autoMountDrive: _autoMountDrive
autoMountDrive: _autoMountDrive,
walletSend: _walletSend
};
})();
@@ -386,7 +392,14 @@
saveButton.onclick = () => {
cancelButton.onclick = null;
saveButton.onclick = null;
beginMainApplication(false);
const address = getValue('ID_Send_Address');
const amount = getValue('ID_Send_Amount');
AppActions.walletSend(address, amount, (success, reason) => {
if (!success) {
displayErrorPopup('Send Failed', reason);
}
beginMainApplication(false);
});
};
setMainWindow('send_window');
}

View File

@@ -132,7 +132,8 @@ public:
CSiaError<_SiaApiErrorCode> Create(const _SiaSeedLanguage& seedLanguage, SString& seed);
CSiaError<_SiaApiErrorCode> Restore(const SString& seed);
CSiaError<_SiaApiErrorCode> Lock();
CSiaError<_SiaApiErrorCode> Unlock(const SString& password);
CSiaError<_SiaApiErrorCode> Unlock(const SString& password);
CSiaError<_SiaApiErrorCode> Send(const SString& address, const SiaCurrency& amount);
};
class SIADRIVE_EXPORTABLE _CSiaRenter :

View File

@@ -148,6 +148,22 @@ public:
}
return true;
}
else if (name == "walletSend")
{
SString address = arguments[0]->GetStringValue().ToWString();
SString amount = arguments[1]->GetStringValue().ToWString();
CefRefPtr<CefV8Value> cb = arguments[2];
SiaCurrency currency(amount.str());
auto ret = _siaApi.GetWallet()->Send(address, currency);
CefV8ValueList args;
args.push_back(CefV8Value::CreateBool(ApiSuccess(ret)));
args.push_back(CefV8Value::CreateString(ret.GetReason().str()));
cb->ExecuteFunctionWithContext(context, nullptr, args);
return true;
}
else if (name == "unlockWallet")
{
retval = CefV8Value::CreateBool(true);
@@ -394,6 +410,7 @@ void CSiaDriveApp::OnContextCreated(
global->SetValue("uiState", obj, V8_PROPERTY_ATTRIBUTE_NONE);
obj = CefV8Value::CreateObject(nullptr, nullptr);
obj->SetValue("walletSend", CefV8Value::CreateFunction("walletSend", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("autoMountDrive", CefV8Value::CreateFunction("autoMountDrive", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("autoUnlockWallet", CefV8Value::CreateFunction("autoUnlockWallet", handler), V8_PROPERTY_ATTRIBUTE_NONE);
obj->SetValue("unlockWallet", CefV8Value::CreateFunction("unlockWallet", handler), V8_PROPERTY_ATTRIBUTE_NONE);

View File

@@ -154,5 +154,23 @@ SiaApiError CSiaApi::_CSiaWallet::Unlock(const SString& password)
}
}
return error;
}
SiaApiError CSiaApi::_CSiaWallet::Send(const SString& address, const SiaCurrency& amount)
{
SiaApiError error = SiaApiErrorCode::Success;
const SString hast = SiaCurrencyToHastingsString(amount);
json result;
SiaCurlError cerror = GetSiaCurl().Post(L"/wallet/siacoins", { {L"destination", address}, { L"amount", hast} }, result);
if (ApiSuccess(cerror))
{
error = SiaApiErrorCode::Success;
}
else
{
error = { SiaApiErrorCode::RequestError, cerror.GetReason() };
}
return error;
}