Skip to content

Commit

Permalink
add golos/donate service, update golos/wallet (add Qiwi method for YM…
Browse files Browse the repository at this point in the history
…RUB deposit)
  • Loading branch information
denis-skripnik committed Jan 18, 2021
1 parent 6750d01 commit ad1ffef
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 14 deletions.
6 changes: 6 additions & 0 deletions blockchains/golos/apps/donate/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"title": "Golos | Донат",
"description": "Сервис донатов пользователей Голоса",
"in_menu": "Донат",
"category": "tools"
}
57 changes: 57 additions & 0 deletions blockchains/golos/apps/donate/content.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php if (!defined('NOTLOAD')) exit('No direct script access allowed');
global $conf;
$url = pageUrl();
$content = '<h2>Донат<span class="token"></span></h2>
<form action="/" method="post">
<input type="hidden" name="chain" value="golos">
<input type="hidden" name="service" value="donate">';
if (isset($url[2])) {
$content .= '<input type="hidden" name="user" value="'.$url[2].'">';
$data['title'] .= ' пользователю '.$url[2];
} else {
$content .= '<p><label for="user">Кому: <br>
<input type="text" name="user" value="" placeholder="Получатель доната"></label></p>';
}
if (isset($url[3])) {
$content .= '<input type="hidden" name="token" value="'.$url[3].'">';
} else {
$content .= '<p><label for="token">Способ доната: <br>
<select name="token"></select></label></p>';
}
if (isset($url[4])) {
$content .= '<p><label for="amount">Сумма: <br>
<input type="text" name="amount" value="'.$url[4].'" placeholder="Сумма доната"></label></p>';
$data['title'] .= ' на '.$url[4].' '.$url[3];
} else {
$content .= '<p><label for="amount">Сумма: <br>
<input type="text" name="amount" value="" placeholder="Сумма доната"></label></p>';
}
$content .= '<p></strong><input type="submit" value="Отправить"></strong></p>
</form>';
if (isset($url[4])) {
$content .= '<hr>
<p><a href="'.$conf['siteUrl'].'golos/donate/'.$url[2].'">К выбору токена</a></p>
<div id="deposit_without_golos" style="display: none;"><hr>
<h2>Донат без авторизации</h2>
<ul><li>Кому: '.$url[2].'</li>
<li>сумма: '.$url[4].' <span class="token"></li></ul>
<div id="uia_diposit_data"></div>
<hr></div>
<div id="auth_msg" style="display: none;"><hr>
<p>Если вы хотите отправить донат при помощи Golos blockchain, необходимо авторизоваться <a href="'.$conf['siteUrl'].'golos/accounts" target="_blank">здесь</a></p></div>
<div id="posting_page">
<h2>Донат при помощи Golos blockchain</h2>
<ul><li>Кому: '.$url[2].'</li>
<li>сумма: '.$url[4].' '.$url[3].'</li>
<li>TIP-баланс: <span id="tip_balance"></span></li></ul>
<p><strong><button type="button" id="donate_action">Отправить донат</button></strong></p>
</div>';
}
$content .= '<hr>
<h2>Ссылка на страницу</h2>
<p>Вы можете её использовать на сайте:</p>
<p><textarea readonly id="this_page_url"><a href="'.((!empty($_SERVER['HTTPS'])) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'].'" target="_blank">Донат на '.$url[4].' '.$url[3].'</a></textarea>
<input type="button" onclick="copyText(`this_page_url`)" value="Копировать в буфер обмена"></p>
';
return $content;
?>
2 changes: 2 additions & 0 deletions blockchains/golos/apps/donate/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php if (!defined('NOTLOAD')) exit('No direct script access allowed');
?>
147 changes: 147 additions & 0 deletions blockchains/golos/apps/donate/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
var url = document.location.pathname.slice(1).split('/');
var gates = {};
gates.YMRUB = {};
gates.YMPZM = {};
gates.YMRUB.deposit = {
vars: [
{ // Qiwi
address: {
name: "Никнейм в Qiwi",
value: `RICHE387`,
},
memo: {
name: "Примечание",
value: "golos:" + url[2]
}
}, // end Qiwi method
{ // Advcash
address: {
name: "Адрес кошелька в Advcash",
value: `R 9085 0398 0645`,
},
memo: {
name: "Примечание к платежу",
value: "golos:" + url[2]
}
}, // end Advcash method
{ // Payeer
address: {
name: "Адрес кошелька в Payeer",
value: `P9741574`,
},
memo: {
name: "Примечание к платежу",
value: "golos:" + url[2]
}
}
]
};

gates.YMPZM.deposit = {
vars: [
{
address: {
name: "Адрес кошелька в Prizm",
value: `PRIZM-5UER-N986-BU24-AXJRL`,
},
memo: {
name: "Примечание к платежу",
value: "golos:" + url[2]
}
}
]
};

async function donateAction(to, amount, token, precision) {
var q = window.confirm('Вы действительно хотите отправить донат?');
if (q == true) {
try {
let result = await golos.broadcast.donateAsync(posting_key, golos_login, to, `${parseFloat(amount).toFixed(precision)} ${token}`, {app: 'dpos-space', version: 1, comment: `Донат со страницы https://dpos.space${window.location.pathname}`, target: {type: 'personal_donate'}}, []);
window.alert('Вы отблагодарили пользователя ' + to + ' на ' + amount + ' ' + token + '.');
await main();
} catch(e) {
window.alert('Ошибка: ' + e);
}

}
}

async function getTipBalance(token) {
let balances = (await golos.api.getAccountsBalancesAsync([golos_login]))[0];
if (balances && balances[token]) {
return parseFloat(balances[token].tip_balance);
} else if (balances && !balances[token] || !balances) {
let tip_balance = parseFloat((await golos.api.getAccountsAsync([golos_login]))[0].tip_balance);
if (tip_balance) {
return tip_balance;
}
}
}

async function main() {
let assets = await golos.api.getAssetsAsync('');
let precision = 3;
if (assets && assets.length > 0) {
let tokens = '<option value="GOLOS">GOLOS (только при помощи блокчейна Golos)</option>';
for (let asset of assets) {
let name = asset.max_supply.split(' ')[1];
if (name === url[3]) precision = asset.precision;
if (parseFloat(asset.supply) > 0) {
let add_str = '';
if (!gates[name]) {
add_str = ' (только при помощи блокчейна Golos)';
}
if (name.indexOf('YM') > -1) {
view_name = name.slice(2);
} else {
view_name = name;
}
tokens += `<option value="${name}">${view_name}${add_str}</option>`;
}
}
$('[name=token]').html(tokens);
}

if (url[3]) {
let view_token = ` ${url[3]}`;
if (url[3].indexOf('YM') > -1) view_token = url[3].slice(2);
$('.token').html(` ${view_token}`);
}

if (url[3] && gates[url[3]] && url[4]) {
$('#deposit_without_golos').css('display', 'block');
let deposit = gates[url[3]].deposit;
let res = `<p>Для доната следуйте инструкции ниже.</p>
`;
let vars = deposit.vars;
for (let method of vars) {
res += '<ul>';
for (let el in method) {
res += `<li>${method[el].name}: ${method[el].value} (<input type="button" value="копировать" onclick="navigator.clipboard.writeText('${method[el].value.replace(/<[^>]*>/g, "")}').then(() => {console.log('Successfully copied to clipboard');}).catch(() => {console.log('Copy error');});">)</li>`;
}
res += `</ul>`;
}
$('#uia_diposit_data').html(res);
}

if (url[4]) {
let tip = await getTipBalance(url[3]);
if (!tip) tip = 0;
$('#tip_balance').html(`${tip} ${url[3]}`);
if (tip < parseFloat(url[4])) {
$('#donate_action').attr('disabled', true);
$('#donate_action').html('TIP баланс < суммы доната. <a href="/golos/wallet" target="_blank">В кошелёк</a>');
} else {
$('#donate_action').attr('disabled', false);
}
}
return {precision}
}

$(document).ready(async function() {
let data = await main();

$('#donate_action').click(async function() {
await donateAction(url[2], url[4], url[3], data.precision);
});
});
10 changes: 10 additions & 0 deletions blockchains/golos/apps/wallet/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ login: "ecurrex-ru",

gates.YMRUB.deposit = {
vars: [
{ // Qiwi
address: {
name: "Никнейм в Qiwi",
value: `RICHE387`,
},
memo: {
name: "Примечание",
value: "golos:" + golos_login
}
}, // end Qiwi method
{ // Advcash
address: {
name: "Адрес кошелька в Advcash",
Expand Down
8 changes: 7 additions & 1 deletion blockchains/golos/js/blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,10 @@ var ajax_options = {};
ajax_options[data[0]] = data[1];
}
getLoad(url, 'ajax_modal_content', 'Следующие 10', 'Предыдущие 10')(START_MODE);
});
});

function copyText(id) {
let text = document.getElementById(id);
text.select();
document.execCommand("copy");
}
5 changes: 4 additions & 1 deletion blockchains/steem/apps/wallet/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@
<p><input type="button" id="action_vesting_delegate_start" value="делегировать"></p>
</form></div>
</div>
<div><p>Делегировали другие пользователи вам <span class="received_vesting_shares_result"></span></p>
<div id="claim" style="display: none;"><hr>
<p>К получению: <span id="claim_balances"></span></p>
<p><strong><input type="button" id="claim_action" value="Получить"></strong></p><hr></div>
<div><p>Делегировали другие пользователи вам <span class="received_vesting_shares_result"></span></p>
<p>Делегировано другим пользователям (Без учёта отменённого) <a data-fancybox data-src="#modal_delegated_vesting_shares" href="javascript:;"><span class="delegated_vesting_shares_result"></span></a></p>
<div style="display: none;" id="modal_delegated_vesting_shares">
<h4 class="modal-title">Список аккаунтов, которым вы делегировали Steem Power</h4>
Expand Down
41 changes: 30 additions & 11 deletions blockchains/steem/apps/wallet/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ function date_str(timestamp,add_time,add_seconds,remove_today=false){
return datetime_str;
}

function load_balance(account, active_key) {
steem.api.getAccounts([account], function(err, result){
function load_balance() {
steem.api.getAccounts([steem_login], function(err, result){
if (!err) {
result.forEach(function(acc) {
steem.api.getDynamicGlobalProperties(function(error, res) {
Expand All @@ -94,8 +94,27 @@ $(".steem_balance").html(new Number(parseFloat(acc.balance)).toFixed(3));
$(".received_vesting_shares_result").html(received_sp);
$(".delegated_vesting_shares_result").html(delegated_sp);

let claim_data = [];
if (acc.reward_steem_balance !== '0.000 STEEM') claim_data.push(acc.reward_steem_balance);
if (acc.reward_sbd_balance !== '0.000 SBD') claim_data.push(acc.reward_sbd_balance);
if (acc.reward_vesting_balance !== '0.000000 VESTS') claim_data.push(parseFloat(acc.reward_vesting_steem) + ' SP');
if (claim_data.length > 0) {
$('#claim').css('display', 'block');
$('#claim_balances').html(claim_data.join(', '));
}

$('#claim_action').click(function() {
steem.broadcast.claimRewardBalance(posting_key, steem_login, acc.reward_steem_balance, acc.reward_sbd_balance, acc.reward_vesting_balance, function(err, data) {
if (!err) {
window.alert('Балансы получены');
$('#claim').css('display', 'none');
load_balance();
}
});
});

const timezoneOffset = (new Date()).getTimezoneOffset() * 60000;
steem.api.getVestingDelegations(account, '', 100, function(err, res) {
steem.api.getVestingDelegations(steem_login, '', 100, function(err, res) {
//console.log(err, res);
if ( ! err) {
var vesting_shares_amount = '';
Expand All @@ -109,7 +128,7 @@ let min_delegation_datetime = date_str(min_delegation_time - timezoneOffset, tru
body_delegated_vesting_shares = '<tr id="delegated_vesting_shares_' + item.delegatee + '"><td><a href="/steem/profiles/' + item.delegatee + '" target="_blank">@' + item.delegatee + '</a></td><td>' + vesting_shares_amount + '</td><td>' + min_delegation_datetime + '</td><td><input type="button" id="cancel_delegated_vesting_shares_' + item.delegatee + '" value="Отменить делегирование"></td></tr>';
jQuery("#body_delegated_vesting_shares").append(body_delegated_vesting_shares);
$('#cancel_delegated_vesting_shares_' + item.delegatee).click(function(){
steem.broadcast.delegateVestingShares(active_key, account, item.delegatee, '0.000000 VESTS', function(err, result) {
steem.broadcast.delegateVestingShares(active_key, steem_login, item.delegatee, '0.000000 VESTS', function(err, result) {
if (!err) {
window.alert('Делегирование пользователю ' + item.delegatee + ' отменено.');
$('#delegated_vesting_shares_' + item.delegatee).css("display", "none");
Expand All @@ -127,7 +146,7 @@ var full_vesting = (sp - delegated_sp + received_sp).toFixed(6);
$("#full_vesting").html(full_vesting);

$("#cancel_vesting_withdraw").click(function(){
steem.broadcast.withdrawVesting(active_key, account, '0.000000 VESTS', function(err, result) {
steem.broadcast.withdrawVesting(active_key, steem_login, '0.000000 VESTS', function(err, result) {
if (!err) {
window.alert('Вывод отменён.');
$('#info_vesting_withdraw').css('display', 'none');
Expand Down Expand Up @@ -161,7 +180,7 @@ $("#max_vesting_withdraw_result").html(new Number(parseFloat(max_vesting_withdra
var action_vesting_withdraw_amount = parseFloat($('#action_vesting_withdraw_amount').val());
let withdraw_vests = action_vesting_withdraw_amount * 1000000 / steem_per_vests;
withdraw_vests = withdraw_vests.toFixed(6) + ' VESTS';
steem.broadcast.withdrawVesting(active_key, account, withdraw_vests, function(err, result) {
steem.broadcast.withdrawVesting(active_key, steem_login, withdraw_vests, function(err, result) {
if (!err) {
window.alert('Вывод на ' + action_vesting_withdraw_amount + ' начат.');
location.reload();
Expand All @@ -184,7 +203,7 @@ window.alert('Ошибка: ' + err);
var transfer_to_vesting = document.getElementById('transfer_to_vesting');

if (transfer_to_vesting.checked) {
steem.broadcast.transferToVesting(active_key, account, action_steem_transfer_to, action_steem_transfer_amount, function(err, result) {
steem.broadcast.transferToVesting(active_key, steem_login, action_steem_transfer_to, action_steem_transfer_amount, function(err, result) {
if (!err) {
window.alert('Вы перевели ' + action_steem_transfer_amount + ' пользователю ' + action_steem_transfer_to + ' в SP.');
location.reload();
Expand All @@ -193,7 +212,7 @@ window.alert('Ошибка: ' + err);
}
});
} else {
steem.broadcast.transfer(active_key, account, action_steem_transfer_to, action_steem_transfer_amount, action_steem_transfer_memo, function(err, result) {
steem.broadcast.transfer(active_key, steem_login, action_steem_transfer_to, action_steem_transfer_amount, action_steem_transfer_memo, function(err, result) {
if (!err) {
window.alert('Вы перевели ' + action_steem_transfer_amount + ' пользователю ' + action_steem_transfer_to + '.');
location.reload();
Expand All @@ -209,7 +228,7 @@ window.alert('Ошибка: ' + err);
$("#action_to_shares_transfer_start").click(function(){
var action_to_shares_transfer_amount = parseFloat($('#action_to_shares_transfer_amount').val());
action_to_shares_transfer_amount = action_to_shares_transfer_amount.toFixed(3) + ' STEEM';
steem.broadcast.transferToVesting(active_key, account, account, action_to_shares_transfer_amount, function(err, result) {
steem.broadcast.transferToVesting(active_key, steem_login, steem_login, action_to_shares_transfer_amount, function(err, result) {
if (!err) {
window.alert('Вы успешно перевели ' + action_to_shares_transfer_amount + ' steem в SP своего аккаунта.');
location.reload();
Expand All @@ -230,7 +249,7 @@ $("#max_vesting_deligate").html(max_vesting_deligate);
var action_vesting_delegate_amount = parseFloat($('#action_vesting_delegate_amount').val());
let delegate_vests = action_vesting_delegate_amount * 1000000 / steem_per_vests;
delegate_vests = delegate_vests.toFixed(6) + ' VESTS';
steem.broadcast.delegateVestingShares(active_key, account, action_vesting_delegate_to, delegate_vests, function(err, result) {
steem.broadcast.delegateVestingShares(active_key, steem_login, action_vesting_delegate_to, delegate_vests, function(err, result) {
if (!err) {
window.alert('Вы делегировали ' + action_vesting_delegate_amount + '.');
location.reload();
Expand Down Expand Up @@ -316,7 +335,7 @@ const walletDataSettings = {
async function walletData() {
if (active_key) {
jQuery("#main_wallet_info").css("display", "block");
load_balance(steem_login, active_key);
load_balance();

// История переводов:
jQuery("#wallet_transfer_history").css("display", "block");
Expand Down
Loading

0 comments on commit ad1ffef

Please sign in to comment.