-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add golos/donate service, update golos/wallet (add Qiwi method for YM…
…RUB deposit)
- Loading branch information
1 parent
6750d01
commit ad1ffef
Showing
10 changed files
with
268 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"title": "Golos | Донат", | ||
"description": "Сервис донатов пользователей Голоса", | ||
"in_menu": "Донат", | ||
"category": "tools" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php if (!defined('NOTLOAD')) exit('No direct script access allowed'); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.