Skip to content

Commit 68f8446

Browse files
committed
trade with submit and verify process
1 parent 3f6db24 commit 68f8446

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

js/controller/trade.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,32 @@ myApp.controller("TradeCtrl", [ '$scope', '$rootScope', 'XrpApi', 'XrpOrderbook'
237237
$scope.refreshOffer();
238238
$scope.refreshBook();
239239
});
240-
$scope.$on("txSuccess", function(e, tx) {
241-
console.debug('txSuccess event', tx);
242-
$scope.refreshOffer();
243-
$scope.refreshBook();
244-
});
245240

246241
$scope.buying = false;
247-
$scope.buy_ok;
248242
$scope.buy_fail;
249243
$scope.selling = false;
250-
$scope.sell_ok;
251244
$scope.sell_fail;
245+
246+
$scope.buy_hash = "";
247+
$scope.buy_state = "";
248+
$scope.sell_hash = "";
249+
$scope.sell_state = "";
250+
$scope.$on("txSuccess", function(e, tx) {
251+
console.debug('txSuccess event', tx);
252+
if (tx.hash == $scope.buy_hash) $scope.buy_state = "success";
253+
if (tx.hash == $scope.sell_hash) $scope.sell_state = "success";
254+
$scope.refreshOffer();
255+
$scope.refreshBook();
256+
$scope.$apply();
257+
});
258+
$scope.$on("txFail", function(e, tx) {
259+
console.debug('txFail event', tx);
260+
if (tx.hash == $scope.buy_hash) $scope.buy_state = "fail";
261+
if (tx.hash == $scope.sell_hash) $scope.sell_state = "fail";
262+
$scope.refreshOffer();
263+
$scope.refreshBook();
264+
$scope.$apply();
265+
});
252266

253267
$scope.buy_price;
254268
$scope.buy_amount;
@@ -308,7 +322,8 @@ myApp.controller("TradeCtrl", [ '$scope', '$rootScope', 'XrpApi', 'XrpOrderbook'
308322
$scope.offer = function(type) {
309323
$scope['fatfinger' + type] = false; // hide the fatfinger warning
310324
$scope[type + 'ing'] = true;
311-
$scope[type + '_ok'] = false;
325+
$scope[type + '_hash'] = "";
326+
$scope[type + '_state'] = "";
312327
$scope[type + '_fail'] = "";
313328
var option = {
314329
type : type,
@@ -324,9 +339,10 @@ myApp.controller("TradeCtrl", [ '$scope', '$rootScope', 'XrpApi', 'XrpOrderbook'
324339
option.amount = $scope.sell_amount;
325340
option.price = $scope.sell_price;
326341
}
327-
XrpApi.offer(option).then(result => {
342+
XrpApi.offer(option).then(hash => {
328343
$scope[type + 'ing'] = false;
329-
$scope[type + '_ok'] = true;
344+
$scope[type + '_hash'] = hash;
345+
$scope[type + '_state'] = "submitted";
330346
$scope[type + '_amount'] = "";
331347
$scope[type + '_price'] = "";
332348
$scope[type + '_volume'] = "";

js/ripple/api.factory.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,16 @@ myApp.factory('XrpApi', ['$rootScope', 'AuthenticationFactory', 'ServerManager',
413413
order.memos = [{data: _client, type: 'client', format: 'text'}];
414414
return new Promise(async (resolve, reject) => {
415415
try {
416+
let ledger = await _remote.getLedger();
416417
let prepared = await _remote.prepareOrder(this.address, order);
417-
const {signedTransaction} = AuthenticationFactory.sign(this, prepared.txJSON);
418+
const {signedTransaction, id} = AuthenticationFactory.sign(this, prepared.txJSON);
418419
let result = await _remote.submit(signedTransaction);
419-
if ("tesSUCCESS" !== result.engine_result) {
420+
this.verifyTx(id, ledger.ledgerVersion, prepared.instructions.maxLedgerVersion);
421+
if ("tesSUCCESS" !== result.engine_result && "terQUEUED" !== result.engine_result) {
420422
console.warn(result);
421423
return reject(new Error(result.engine_result_message || result.engine_result));
422424
}
423-
resolve(result);
425+
resolve(id);
424426
} catch (err) {
425427
console.error('offer', err);
426428
reject(err);

pages/trade.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ <h3 class="manager_title">{{'buy' | translate}} {{base_code}}</h3>
137137
<div class="overview">
138138
{{'you_have' | translate}} {{getBalance(counter_code, counter_issuer)}} {{counter_code}}
139139
</div>
140-
<div class="s-alert s-alert--success" ng-show="buy_ok" translate="offer_success">Offer successfully created</div>
140+
<div class="s-alert s-alert--info" ng-show="buy_state=='submitted'" translate="submitted">Transaction submitted.</div>
141+
<div class="s-alert s-alert--success" ng-show="buy_state=='success'" translate="offer_success">Offer successfully created</div>
141142
<div class="s-alert s-alert--error" ng-show="buy_fail">{{buy_fail}}</div>
142143
<button class="btn btn-success" ng-click="offerWithCheck('buy')" ng-disabled="buying">{{'buy' | translate}} {{base_code}}</button>
143144
</div>
@@ -176,7 +177,8 @@ <h3 class="manager_title">{{'sell' | translate}} {{base_code}}</h3>
176177
<div class="overview">
177178
{{'you_have' | translate}} {{getBalance(base_code, base_issuer)}} {{base_code}}
178179
</div>
179-
<div class="s-alert s-alert--success" ng-show="sell_ok" translate="offer_success">Offer successfully created</div>
180+
<div class="s-alert s-alert--info" ng-show="sell_state=='submitted'" translate="submitted">Transaction submitted</div>
181+
<div class="s-alert s-alert--success" ng-show="sell_state=='success'" translate="offer_success">Offer successfully created</div>
180182
<div class="s-alert s-alert--error" ng-show="sell_fail">{{sell_fail}}</div>
181183
<button class="btn btn-success" ng-click="offerWithCheck('sell')" ng-disabled="selling">{{'sell' | translate}} {{base_code}}</button>
182184
</div>

0 commit comments

Comments
 (0)