From 04ab84538215cefeab890ee59f26f053b658ac31 Mon Sep 17 00:00:00 2001 From: veselcraft Date: Sat, 7 May 2022 15:42:25 +0300 Subject: [PATCH] Coin: Add dialog with QR-code and requisites + tweak config --- CLI/FetchToncoinTransactions.php | 24 ++++++++----------- Web/Presenters/UserPresenter.php | 12 ++++++++++ Web/Presenters/templates/User/Settings.xml | 27 +++++++++++++++++++++- locales/en.strings | 5 ++++ locales/ru.strings | 5 ++++ openvk-example.yml | 8 +++++++ 6 files changed, 66 insertions(+), 15 deletions(-) diff --git a/CLI/FetchToncoinTransactions.php b/CLI/FetchToncoinTransactions.php index fac83eae..82cbc2f9 100755 --- a/CLI/FetchToncoinTransactions.php +++ b/CLI/FetchToncoinTransactions.php @@ -51,7 +51,7 @@ class FetchToncoinTransactions extends Command } $testnet_subdomain = OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["testnet"] ? "testnet." : ""; - $url = "https://" . $testnet_subdomain . "toncenter.com/api/v2/getTransactions?"; + $url = "https://" . $testnet_subdomain . "toncenter.com/api/v2/getTransactions?"; $opts = [ "http" => [ @@ -61,8 +61,8 @@ class FetchToncoinTransactions extends Command ]; $selection = $this->transactions->select('hash, lt')->order("id DESC")->limit(1)->fetch(); - $tr_hash = $selection->hash ?? NULL; - $tr_lt = $selection->lt ?? NULL; + $tr_hash = $selection->hash ?? NULL; + $tr_lt = $selection->lt ?? NULL; $data = http_build_query([ "address" => OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["address"], @@ -78,17 +78,13 @@ class FetchToncoinTransactions extends Command foreach($response["result"] as $transfer) { $output_array; - preg_match('/ovk=([0-9]+)/', $transfer["in_msg"]["message"], $output_array); - $userid = ctype_digit($output_array[1]) ? intval($output_array[1]) : null; - if($userid === null) - { + 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; + if($userid === NULL) { $header->writeln(["Well, that's a donation. Thanks! XD"]); - } - else - { + } else { $user = (new Users)->get($userid); - if(!$user) - { + if(!$user) { $header->writeln(["Well, that's a donation. Thanks! XD"]); } else { $value = ($transfer["in_msg"]["value"] / NANOTON) / OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["rate"]; @@ -97,9 +93,9 @@ class FetchToncoinTransactions extends Command (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"]); $this->transactions->insert([ - "id" => null, + "id" => NULL, "hash" => $transfer["transaction_id"]["hash"], - "lt" => $transfer["transaction_id"]["lt"] + "lt" => $transfer["transaction_id"]["lt"] ]); } } diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 0f741654..b55d9f5e 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -449,6 +449,18 @@ final class UserPresenter extends OpenVKPresenter "main", "privacy", "finance", "finance.top-up", "interface" ]) ? $this->queryParam("act") : "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->themes = Themepacks::i()->getThemeList(); } diff --git a/Web/Presenters/templates/User/Settings.xml b/Web/Presenters/templates/User/Settings.xml index 03300a81..31433a91 100644 --- a/Web/Presenters/templates/User/Settings.xml +++ b/Web/Presenters/templates/User/Settings.xml @@ -383,7 +383,10 @@ {_on_your_account}
{$thisUser->getCoins()}
{_points_count}
- [{_have_voucher}?] + [{_have_voucher}?]
+ + [{_transfer_trough_ton}] +

@@ -393,6 +396,28 @@ balance.style.width = Math.ceil(balance.parentNode.getBoundingClientRect().width) + "px"; 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"), ` +
+ ${ tr("transfer_ton_contents") } +
+
` + + {tr("transfer_ton_address", OPENVK_ROOT_CONF['openvk']['preferences']['ton']['address'], str_replace("$1", $thisUser->getId(), OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["hint"]))} + + `
+
+ = 0 TON +
+
` + , [tr("close")], [ + Function.noop + ]); + } {elseif $isFinanceTU} diff --git a/locales/en.strings b/locales/en.strings index 398d14ef..abec1983 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -592,6 +592,11 @@ "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" = "Wallet address: $1
Message content: $2"; +"transfer_ton_currency_per_ton" = "$1 TON"; + "receiver_address" = "Receiver address"; "coins_count" = "Number of votes"; "message" = "Message"; diff --git a/locales/ru.strings b/locales/ru.strings index 0e65c0eb..2d4fe21a 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -624,6 +624,11 @@ "transferred_to_you" = "передал вам"; +"transfer_trough_ton" = "Пополнить с помощью TON"; +"transfer_ton_contents" = "Вы можете пополнить ваш баланс с помощью криптовалюты TON. Достаточно отсканировать QR-code приложением Tonkeeper, или вручную отправить TON по реквизитам. В течении нескольких минут вам придут определенное количество голосов."; +"transfer_ton_address" = "Адрес кошелька: $1
Содержание сообщения: $2"; +"transfer_ton_currency_per_ton" = "$1 TON"; + "receiver_address" = "Адрес получателя"; "coins_count" = "Количество голосов"; "message" = "Сообщение"; diff --git a/openvk-example.yml b/openvk-example.yml index 9e4a5d58..cceb2be3 100644 --- a/openvk-example.yml +++ b/openvk-example.yml @@ -53,6 +53,14 @@ openvk: processingLimit: 3000 emojiProcessingLimit: 1000 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: links: - name: "@left_menu_donate"