Coin: Add dialog with QR-code and requisites + tweak config

This commit is contained in:
veselcraft 2022-05-07 15:42:25 +03:00
parent cc6771ea70
commit 04ab845382
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E
6 changed files with 66 additions and 15 deletions

View file

@ -78,17 +78,13 @@ class FetchToncoinTransactions extends Command
foreach($response["result"] as $transfer) foreach($response["result"] as $transfer)
{ {
$output_array; $output_array;
preg_match('/ovk=([0-9]+)/', $transfer["in_msg"]["message"], $output_array); preg_match('/' . OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["regex"] . '/', $transfer["in_msg"]["message"], $output_array);
$userid = ctype_digit($output_array[1]) ? intval($output_array[1]) : null; $userid = ctype_digit($output_array[1]) ? intval($output_array[1]) : NULL;
if($userid === null) if($userid === NULL) {
{
$header->writeln(["Well, that's a donation. Thanks! XD"]); $header->writeln(["Well, that's a donation. Thanks! XD"]);
} } else {
else
{
$user = (new Users)->get($userid); $user = (new Users)->get($userid);
if(!$user) if(!$user) {
{
$header->writeln(["Well, that's a donation. Thanks! XD"]); $header->writeln(["Well, that's a donation. Thanks! XD"]);
} else { } else {
$value = ($transfer["in_msg"]["value"] / NANOTON) / OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["rate"]; $value = ($transfer["in_msg"]["value"] / NANOTON) / OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["rate"];
@ -97,7 +93,7 @@ class FetchToncoinTransactions extends Command
(new CoinsTransferNotification($user, (new Users)->get(OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["adminAccount"]), 0, "Via TON cryptocurrency"))->emit(); (new CoinsTransferNotification($user, (new Users)->get(OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["adminAccount"]), 0, "Via TON cryptocurrency"))->emit();
$header->writeln([$value . " coins are added to " . $user->getId() . " user id"]); $header->writeln([$value . " coins are added to " . $user->getId() . " user id"]);
$this->transactions->insert([ $this->transactions->insert([
"id" => null, "id" => NULL,
"hash" => $transfer["transaction_id"]["hash"], "hash" => $transfer["transaction_id"]["hash"],
"lt" => $transfer["transaction_id"]["lt"] "lt" => $transfer["transaction_id"]["lt"]
]); ]);

View file

@ -449,6 +449,18 @@ final class UserPresenter extends OpenVKPresenter
"main", "privacy", "finance", "finance.top-up", "interface" "main", "privacy", "finance", "finance.top-up", "interface"
]) ? $this->queryParam("act") ]) ? $this->queryParam("act")
: "main"; : "main";
if($this->template->mode == "finance") {
$address = OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["address"];
$text = str_replace("$1", $this->user->identity->getId(), OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["hint"]);
$qrCode = explode("base64,", (new QRCode(new QROptions([
"imageTransparent" => false
])))->render("ton://transfer/$address?text=$text"));
$this->template->qrCodeType = substr($qrCode[0], 5);
$this->template->qrCodeData = $qrCode[1];
}
$this->template->user = $user; $this->template->user = $user;
$this->template->themes = Themepacks::i()->getThemeList(); $this->template->themes = Themepacks::i()->getThemeList();
} }

View file

@ -383,7 +383,10 @@
{_on_your_account} {_on_your_account}
<div style="width: 100%; height: 60px; font-weight: 100;" id="balance">{$thisUser->getCoins()}</div> <div style="width: 100%; height: 60px; font-weight: 100;" id="balance">{$thisUser->getCoins()}</div>
{_points_count}<br/> {_points_count}<br/>
<small><a href="?act=finance.top-up">[{_have_voucher}?]</a></small> <small><a href="?act=finance.top-up">[{_have_voucher}?]</a></small><br>
<small n:if="OPENVK_ROOT_CONF['openvk']['preferences']['ton']['enabled']">
<a href="javascript:showCoinsTopUpTroughTon()">[{_transfer_trough_ton}]</a>
</small>
</p> </p>
</div> </div>
@ -393,6 +396,28 @@
balance.style.width = Math.ceil(balance.parentNode.getBoundingClientRect().width) + "px"; balance.style.width = Math.ceil(balance.parentNode.getBoundingClientRect().width) + "px";
textFit(balance, { alignVert: true }); textFit(balance, { alignVert: true });
function convertCurrency(coin) {
var currencyTON = {php echo OPENVK_ROOT_CONF['openvk']['preferences']['ton']['rate']};
u('.coins_dialog_conv').nodes[0].innerHTML = tr("transfer_ton_currency_per_ton", coin * currencyTON);
}
function showCoinsTopUpTroughTon() {
MessageBox(tr("transfer_trough_ton"), `
<div class="messagebox-content-header">
${ tr("transfer_ton_contents") }
</div>
<div style="margin-top: 30px">` +
{tr("transfer_ton_address", OPENVK_ROOT_CONF['openvk']['preferences']['ton']['address'], str_replace("$1", $thisUser->getId(), OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["hint"]))} +
`<div style="text-align: center;">
<img width="225" height="225" src="data:` + {$qrCodeType} + `;base64,` + {$qrCodeData} + `"><br>
<input oninput="convertCurrency(this.value)"> = <span class="coins_dialog_conv">0 TON</span>
</div>
</div>`
, [tr("close")], [
Function.noop
]);
}
</script> </script>
{elseif $isFinanceTU} {elseif $isFinanceTU}

View file

@ -592,6 +592,11 @@
"transferred_to_you" = "transferred to you"; "transferred_to_you" = "transferred to you";
"transfer_trough_ton" = "Top up with TON";
"transfer_ton_contents" = "You can top up your balance with TON cryptocurrency. It's just enough to scan the QR-code with the Tonkeeper app, or manually send TON according to the requisites. Within a few minutes you will receive a certain amount of votes.";
"transfer_ton_address" = "<b>Wallet address:</b> $1<br/><b>Message content:</b> $2";
"transfer_ton_currency_per_ton" = "$1 TON";
"receiver_address" = "Receiver address"; "receiver_address" = "Receiver address";
"coins_count" = "Number of votes"; "coins_count" = "Number of votes";
"message" = "Message"; "message" = "Message";

View file

@ -624,6 +624,11 @@
"transferred_to_you" = "передал вам"; "transferred_to_you" = "передал вам";
"transfer_trough_ton" = "Пополнить с помощью TON";
"transfer_ton_contents" = "Вы можете пополнить ваш баланс с помощью криптовалюты TON. Достаточно отсканировать QR-code приложением Tonkeeper, или вручную отправить TON по реквизитам. В течении нескольких минут вам придут определенное количество голосов.";
"transfer_ton_address" = "<b>Адрес кошелька:</b> $1<br/><b>Содержание сообщения:</b> $2";
"transfer_ton_currency_per_ton" = "$1 TON";
"receiver_address" = "Адрес получателя"; "receiver_address" = "Адрес получателя";
"coins_count" = "Количество голосов"; "coins_count" = "Количество голосов";
"message" = "Сообщение"; "message" = "Сообщение";

View file

@ -53,6 +53,14 @@ openvk:
processingLimit: 3000 processingLimit: 3000
emojiProcessingLimit: 1000 emojiProcessingLimit: 1000
commerce: false commerce: false
ton:
enabled: false
address: "🅿"
testnet: false # Only for testing purposes.
rate: 0.02 # TONs per 1 coin
regex: "ovk=([0-9]+)"
hint: "ovk=$1"
# Please read docs to understand how to turn on automatic checking for new translations
menu: menu:
links: links:
- name: "@left_menu_donate" - name: "@left_menu_donate"