Skip to content

Commit 27a780f

Browse files
committed
Trader app - testing
1 parent f7377c3 commit 27a780f

14 files changed

Lines changed: 181 additions & 145 deletions

web/apps/p2p/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
window.pajaxUrl = '/apps/p2p/index.php'
22
window.pBeforeSend = (formData) => {
3-
Pace.restart();
3+
//Pace.restart();
44
}
55
window.pOnComplete = () => {
6-
Pace.stop();
6+
//Pace.stop();
77
}
88
window.pOnError = (json) => {
99
showError('There was an error performing your action')

web/apps/p2p/cli.php

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,42 @@
99
ini_set('display_errors', 1);
1010
error_reporting(E_ALL ^ E_DEPRECATED);
1111
require_once dirname(__DIR__)."/apps.inc.php";
12-
require_once __DIR__ . "/vendor/autoload.php";
12+
require __DIR__.'/inc/autoloader.php';
1313

1414
$_config['log_file']='tmp/p2p.log';
1515

1616
$command = @$argv[1];
1717

18-
$command = "all";
18+
//$command = "all";
1919
//$command = "resendTx";
2020

2121

2222
//$command="processDeposit";
2323
//$argv[2]="PHP";
2424
//$argv[3]="GSjU1gfsVzkHPJ3R4bs3yJHzpQo57EMASyuYMaoaDiN8";
2525

26-
if($command == "checkExpiredCreatedOffers") {
27-
CliService::checkExpiredCreatedOffers();
28-
} else if ($command == "checkExpiredOpenOffers") {
29-
CliService::checkExpiredOpenOffers();
30-
} else if ($command == "checkPhpDeposits") {
31-
// CliService::checkPhpDeposits();
32-
} else if ($command == "checkPhpTransferring") {
33-
// CliService::checkPhpTransferring();
34-
} else if ($command == "checkCoinDeposits") {
35-
// CliService::checkCoinDeposits();
26+
if(empty($command)) {
27+
_log("Empty command");
28+
exit;
29+
}
30+
3631

3732

3833

39-
} else if ($command == "checkCanceledOffers") {
40-
// CliService::checkCanceledOffers();
34+
if($command == "checkAssetsDeposits") {
35+
CliService::checkAssetsDeposits();
36+
} else if ($command == "checkExpiredCreatedOffers") {
37+
CliService::checkExpiredCreatedOffers();
4138
} else if ($command == "checkExpiredAcceptedOffers") {
4239
CliService::checkExpiredAcceptedOffers();
43-
} else if ($command == "checkCoinTransferring") {
44-
// CliService::checkCoinTransferring();
40+
} else if ($command == "checkAssetsTransferring") {
41+
CliService::checkAssetsTransferring();
4542
} else if ($command == "processTreansferred") {
4643
CliService::processTreansferred();
4744
} else if ($command == "processPayingOffers") {
4845
CliService::processPayingOffers();
46+
} else if ($command == "checkIncompleteTransferLogs") {
47+
CliService::checkIncompleteTransferLogs();
4948
} else if ($command == "generateAddress") {
5049
CliService::generateAddress();
5150
} else if ($command == "all") {
@@ -56,16 +55,6 @@
5655
CliService::checkExpiredAcceptedOffers();
5756
CliService::checkExpiredCreatedOffers();
5857
CliService::checkAssetsDeposits();
59-
} else if ($command == "manualSetOfferDepositing") {
60-
$offer_id = @$argv[2];
61-
$deposit_tx_id = @$argv[3];
62-
if(empty($offer_id) || empty($deposit_tx_id)) {
63-
_log("Empty offer_id and deposit_tx_id");
64-
exit;
65-
}
66-
// CliService::manualSetOfferDepositing($offer_id, $deposit_tx_id);
67-
} else if ($command == "resendTx") {
68-
CliService::resendTx();
6958
} else if ($command == "processDeposit") {
7059
$symbol = @$argv[2];
7160
$deposit_tx_id = @$argv[3];
@@ -75,5 +64,7 @@
7564
}
7665
$service = OfferService::getService($asset['service']);
7766
CliService::processDepositTxId($service, $asset, $deposit_tx_id);
67+
} else {
68+
_log("Unknown command $command");
7869
}
7970

web/apps/p2p/css/mobile.css

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/apps/p2p/css/mobile.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/apps/p2p/css/mobile.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
}
88
}
99
#market-info {
10+
margin-bottom: 0 !important;
1011
#market-info-details-toggle {
1112
display: inline-block !important;
1213
}
@@ -23,6 +24,7 @@
2324
}
2425
#offers-book {
2526
display: flex;
27+
min-height: 30vh;
2628
thead {
2729
display: none;
2830
}
@@ -81,11 +83,16 @@
8183
}
8284
}
8385

86+
#markets-card {
87+
min-height: 30vh;
88+
}
89+
8490
#buy-sell-switch {
8591
display: flex !important;
8692
}
8793
#buy-card {
8894
display: none;
95+
margin-bottom: 0;
8996
&.open {
9097
display: block;
9198
position: fixed;
@@ -97,9 +104,13 @@
97104
#close-buy-card {
98105
display: flex !important;
99106
}
107+
.close-btn {
108+
display: inline-block !important;
109+
}
100110
}
101111
#sell-card {
102112
display: none;
113+
margin-bottom: 0;
103114
&.open {
104115
display: block;
105116
position: fixed;
@@ -111,6 +122,9 @@
111122
#close-sell-card {
112123
display: flex !important;
113124
}
125+
.close-btn {
126+
display: inline-block !important;
127+
}
114128
}
115129
.center-col {
116130
height: auto !important;

web/apps/p2p/inc/autoloader.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
22

3-
spl_autoload_register(function ($class) {
3+
require 'phar://' . dirname(__DIR__) . '/vendor.phar/autoload.php';
4+
require __DIR__ . "/functions.php";
45

5-
$file = __DIR__."/class/$class.php";
6-
if (file_exists($file)) {
6+
spl_autoload_register(function ($class) {
7+
// Convert namespace to directory structure
8+
$path = str_replace('\\', DIRECTORY_SEPARATOR, $class);
9+
$file = __DIR__ . '/class/' . $path . '.php';
10+
if (is_file($file)) {
711
require_once $file;
812
}
9-
10-
11-
});
13+
});

web/apps/p2p/inc/class/AppView.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ function createdViewTemplate($offer) {
391391
}
392392
?>
393393
<div class="card p-2">
394-
<div class="d-flex flex-wrap">
394+
<div class="d-flex flex-wrap flex-sm-nowrap">
395395
<div>
396396
<h5>Your offer is in status created</h5>
397397
<h6>You need to deposit <?= $depositCoin ?> to make offer available for other users</h6>
@@ -582,8 +582,8 @@ function acceptedViewTemplate($offer) {
582582
}
583583
?>
584584
<div class="card p-2">
585-
<div class="d-flex flex-wrap">
586-
<div>
585+
<div class="d-flex flex-wrap flex-column flex-sm-row">
586+
<div style="flex:1">
587587
<h5>You accepted this offer</h5>
588588
<h6>You need to transfer your <?= $transferCoin ?> to escrow address</h6>
589589
<dl class="row my-3">
@@ -620,7 +620,7 @@ function acceptedViewTemplate($offer) {
620620
</p>
621621
</div>
622622
</div>
623-
<div class="text-center">
623+
<div class="text-sm-center text-start">
624624
Remain time
625625
<div class="circle-progress mt-2" style="--progress: <?=$remain['perc']?>">
626626
<div class="circle-inner">
@@ -633,7 +633,7 @@ function acceptedViewTemplate($offer) {
633633
<?php } ?>
634634
<?php if ($offer['user_created']==OfferService::userAddress()) { ?>
635635
<div class="card p-2 d-flex flex-row">
636-
<div>
636+
<div style="flex:1">
637637
<h5>Your offer is accepted</h5>
638638
<h6>Please wait until another party starts trade</h6>
639639
<p class="text-muted">
@@ -744,7 +744,7 @@ function payingViewTemplate($offer) {
744744
$paymentAddress = $offer['base_receive_address'];
745745
$paymentAddressLink = $service->addressLink($paymentAddress);
746746
$paymentTxId = $offer['base_transfer_tx_id'];
747-
$paymentTxLink = $service->txLink($paymentAddress);
747+
$paymentTxLink = $service->txLink($paymentTxId);
748748
$last_height = $service->getLastHeight();
749749
$tx = $service->findTransaction($paymentTxId);
750750
$confirmations = $last_height - $tx['height'];

web/apps/p2p/inc/class/CliService.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,24 @@ static function processDepositTxId($service, $asset, $depositTxId, $block_height
5252
}
5353
$offer = OfferService::getOfferByReceiveTx($depositTxId);
5454
if($offer) {
55-
_log("Found offer {$offer['id']} for deposit #{$depositTxId}");
5655
if($offer['status'] != OfferService::STATUS_DEPOSITING) {
57-
_log("offer #{$offer['id']} status is {$offer['status']}");
56+
_log($asset['symbol']. " Offer #{$offer['id']} status is {$offer['status']} - not deposit status");
5857
return;
5958
}
6059
$depositTx = $service->findTransaction($depositTxId);
6160
$last_height = $depositTx['height'];
6261
if(!$depositTx) {
63-
_log("Transaction #{$depositTxId} not found");
62+
_log($asset['symbol']. " Offer #{$offer['id']} Transaction {$depositTxId} not found");
6463
return;
6564
}
6665
$confirmations= $block_height - $last_height;
6766
$requiredConfirmations=$service->getConfirmations('wait');
6867
if($confirmations <= $requiredConfirmations) {
69-
_log("Deposit #{$depositTxId} waiting confirmations $confirmations/".$requiredConfirmations);
68+
_log($asset['symbol']. " Offer #{$offer['id']} deposit {$depositTxId} waiting confirmations $confirmations/".$requiredConfirmations);
7069
return;
7170
}
7271
OfferService::setOfferOpen($offer['id']);
73-
_log("Deposit #{$depositTxId} opened");
72+
_log($asset['symbol']. " Offer #{$offer['id']} Deposit #{$depositTxId} - set status opened");
7473
} else {
7574
_log("Not found offer by deposit tx id {$depositTxId}");
7675
if($depositTxId == "0x07fbf96ce3b9e25ccfa09e2511c5e43be9c7f882cad09a51f09a12bdcd296aca") {
@@ -100,8 +99,8 @@ static function processDepositTxId($service, $asset, $depositTxId, $block_height
10099

101100
public static function checkExpiredAcceptedOffers()
102101
{
103-
_log("Checking expired accepted offers");
104102
$expiredOffers = OfferService::getExpiredAcceoptedOffers();
103+
_log("Checking expired accepted offers count=".count($expiredOffers));
105104
foreach ($expiredOffers as $offer) {
106105
$accepted_at = strtotime($offer['accepted_at']);
107106
$now = time();
@@ -135,23 +134,22 @@ public static function checkAssetTransferring($asset)
135134
foreach ($txIds as $txId) {
136135
$offer = OfferService::getOffersByReceiveTxId($txId);
137136
if($offer) {
138-
_log("Found offer #{$offer['id']} for transfer transaction $txId status: ".$offer['status']);
139137
if(!($offer['status']==OfferService::STATUS_TRANSFERRING && $offer['accept_tx_id'] == $txId)) {
140-
_log("Not valid offer");
138+
_log($asset['symbol'] . " Offer #{$offer['id']} status={$offer['status']} - not transferring");
141139
continue;
142140
}
143141
$tx = $service->findTransaction($txId);
144142
if(!$tx) {
145-
_log("Transaction #{$txId} not found");
143+
_log($asset['symbol'] . " Offer #{$offer['id']} - Transaction #{$txId} not found");
146144
continue;
147145
}
148146
$confirmations = $block_height - $tx['height'];
149147
$requiredConfirmations = $service->getConfirmations('transferring');
150148
if($confirmations <= $requiredConfirmations) {
151-
_log("Waiting confirmations $confirmations / ".$requiredConfirmations." for offer transfer {$offer['id']}");
149+
_log($asset['symbol'] . " Offer #{$offer['id']} Waiting confirmations $confirmations / ".$requiredConfirmations);
152150
continue;
153151
}
154-
_log("Set offer #{$offer['id']} for transfer transaction $txId completed");
152+
_log($asset['symbol'] . " Offer #{$offer['id']} - set offer transferred");
155153
OfferService::setAcceptedOfferTransferred($offer['id']);
156154
} else {
157155
$tx = $service->findTransaction($txId);
@@ -247,7 +245,7 @@ public static function processPayingOffers()
247245
$confirmations= $block_height - $tx['height'];
248246
$requiredConfirmations=$baseService->getConfirmations('paying');
249247
if($confirmations <= $requiredConfirmations) {
250-
_log("Waiting confirmations $confirmations / ".$requiredConfirmations);
248+
_log("Offer #".$offer['id']." base=".$market['base']." tx=".$offer['base_transfer_tx_id']." Waiting confirmations $confirmations / ".$requiredConfirmations);
251249
continue;
252250
}
253251
if(empty($offer['quote_transfer_tx_id'])) {
@@ -264,9 +262,10 @@ public static function processPayingOffers()
264262
$confirmations= $block_height - $tx['height'];
265263
$requiredConfirmations=$baseService->getConfirmations('paying');
266264
if($confirmations <= $requiredConfirmations) {
267-
_log("Waiting confirmations $confirmations / ".$requiredConfirmations);
265+
_log("Offer #".$offer['id']." base=".$market['quote']." tx=".$offer['quote_transfer_tx_id']." Waiting confirmations $confirmations / ".$requiredConfirmations);
268266
continue;
269267
}
268+
_log("Offer #".$offer['id']." payments completed - closed");
270269
OfferService::setOfferClosed($offer);
271270
}
272271
}

web/apps/p2p/inc/class/OfferService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ public static function getAssets()
629629

630630
public static function getMinCoinTrade()
631631
{
632-
return 0.1;
632+
return 1;
633633
}
634634

635635
public static function getMarketByName(mixed $market)

0 commit comments

Comments
 (0)