Skip to content

Commit

Permalink
Add Credit Offers Page
Browse files Browse the repository at this point in the history
* #16 Add getAsset & getAccount in utilities to top level

* #16 Credit Offers Page

* #22 Credit Offers Updates

* #22 Add toggle show only active for credit offers page
  • Loading branch information
ihorml authored Oct 26, 2022
1 parent 0aa21dc commit bd1dc0c
Show file tree
Hide file tree
Showing 13 changed files with 445 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/app.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'app.welcome',
'app.generic-search',
'app.pools',
'app.credit_offers'
]);
})();

Expand Down
38 changes: 20 additions & 18 deletions app/core/app.utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
'use strict';

angular.module('app')
.factory('utilities', ['$filter', utilities]);
.factory('utilities', ['$filter', 'appConfig', '$http', utilities]);

function utilities($filter) {
function utilities($filter, appConfig, $http) {

function satToFloat(number, presicion) {
var divideby = Math.pow(10, presicion);
Expand Down Expand Up @@ -49,8 +49,26 @@
}
}
}

// function to reduce the amount of duplicated code within operation asset fetch/amount calculation
const getAsset = (asset_id, amount = 0) => {
return $http.get(appConfig.urls.python_backend() + "/asset?asset_id=" + asset_id).then((asset) => {
return {
asset: asset.data,
symbol: asset.data.symbol,
amount: formatNumber(amount, asset.data.precision)
}
})
}

// function to reduce the amount of duplicated code within operation account fetch
const getAccount = (account_id) => {
return $http.get(appConfig.urls.python_backend() + "/account_name?account_id=" + account_id).then((response) => response.data);
}

return {
getAsset: getAsset,
getAccount: getAccount,
formatBalance: function (number, precision=null) {
return formatNumber(number, precision);
},
Expand Down Expand Up @@ -98,22 +116,6 @@
var operation_text;
var fee_paying_account;

// function to reduce the amount of duplicated code within operation account fetch
const getAccount = (account_id) => {
return $http.get(appConfig.urls.python_backend() + "/account_name?account_id=" + account_id).then((response) => response.data);
}

// function to reduce the amount of duplicated code within operation asset fetch/amount calculation
const getAsset = (asset_id, amount = 0) => {
return $http.get(appConfig.urls.python_backend() + "/asset?asset_id=" + asset_id).then((asset) => {
return {
asset: asset.data,
symbol: asset.data.symbol,
amount: formatNumber(amount, asset.data.precision)
}
})
}

const getLink = () => ({
asset: (assetName) => ({
text: assetName,
Expand Down
3 changes: 3 additions & 0 deletions app/core/config.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@

.when('/pools', {templateUrl: 'html/pools.html', reloadOnSearch: false})
.when('/pools/:name', {templateUrl: 'html/pool.html'})

.when('/credit-offers', {templateUrl: 'html/credit_offers.html'})
.when('/credit-offers/:name', {templateUrl: 'html/credit_offer.html'})

.when('/welcome', {templateUrl: 'html/welcome.html'})

Expand Down
54 changes: 54 additions & 0 deletions app/core/service.market.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,60 @@
callback(last_ops);
});
},
getCreditOffers: function () {
return $http.get(appConfig.urls.python_backend() + "/creditoffers").then((response) => {
const data = response && response.data;
const fetchNames = data.map((item) => utilities.getAsset(item.acceptable_collateral_raw[0][0]));
return Promise.all(fetchNames).then((values) => {
values.forEach((value, i) => {
data[i].collateral = value.symbol;
})

return data;
})
})
},
getCreditOfferOperationsHistory: function (credit_offer_id, limit, offset, from) {
let last_ops = [];

return $http.get(appConfig.urls.python_backend() + "/creditoffer_operation_history", { params: {
creditoffer_id: credit_offer_id,
offset: offset,
limit: limit,
from: (from == 0 ? "&from_date=now-1y" : "&from_date=2015-10-10")
}}).then((response) => {
const unique_data = response.data.filter((v,i,a)=>a.findIndex(t=>(t.operation_id_num === v.operation_id_num))===i);

angular.forEach(unique_data, function (value) {
let operation = {};
operation.block_num = value.block_data.block_num;
operation.operation_id = value.account_history.operation_id;
operation.operation_id_num = value.operation_id_num;
operation.time = value.block_data.block_time;
operation.witness = value.witness;
operation.sequence = value.account_history.sequence;

let parsed_op = value.operation_history.op_object;
if (parsed_op == undefined)
parsed_op = JSON.parse(value.operation_history.op)[1];
if (parsed_op.amount)
parsed_op.amount_ = parsed_op.amount;
const _with_result = {...parsed_op, result: value.operation_history.operation_result};
if (typeof _with_result.result === "string") _with_result.result = JSON.parse(value.operation_history.operation_result);
utilities.opText(appConfig, $http, value.operation_type, _with_result, function(returnData) {
operation.operation_text = returnData;
});

const type_res = utilities.operationType(value.operation_type);
operation.type = type_res[0];
operation.color = type_res[1];

last_ops.push(operation);
});

return last_ops
})
}
};
}

Expand Down
10 changes: 9 additions & 1 deletion app/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,21 @@
"BTS/BTC VOLUME": "BTS/BTC VOLUME",
"WITNESSES": "WITNESSES",
"COMMITTEE": "COMMITTEE",

"Credit Offers": "Credit Offers",
"Credit Offer Operations History": "Credit Offer Operations History",
"Fees": "Fees",
"Fee schedule": "Fee schedule",
"Basic": "Basic",
"Premium": "Premium",
"Price per KB": "Price per KB",

"short-day": "d",
"short-hour": "h",
"short-minute": "min",
"short-second": "s",

"Type to search": "Type to search",

"per Block": "per Block",

"Objects": "Objects",
Expand Down
63 changes: 63 additions & 0 deletions app/sections/credit_offers/credit_offer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<script type="text/ng-template" id="operations-table.html">

<div ng-if="index === 'operation_text'" ng-bind-html="row.operation_text | to_trusted"></div>

<div ng-if="index === 'operation_id'">
<a href='#/operations/{{cell}}/'>{{cell}}</a>
</div>

<div ng-if="index === 'time'"> {{ cell | dateFilter }} </div>

<div ng-if="index === 'block_num'">
<a href="#/blocks/{{ cell }}">{{ cell | number }}</a>
</div>

<div ng-if="index === 'type'">
<span class="badge badge-primary" style="background-color: #{{row.color}};">{{row.type}}</span>
</div>

</script>

<div class="page page-table pools" data-ng-controller="creditOffersCtrl">
<div class="row">
<div class="col-md-6">
<ol class="breadcrumb">
<li><a href="#/"><span data-translate="Home"></span></a></li>
<li><a href="#/pools/"><span data-translate="Credit Offers"></span></a></li>
<li class="active"><a href="#/credit-offers/{{credit_offer_id}}">{{credit_offer_id}}</a></li>
</ol>
</div>
<div class="col-md-6">
</div>
</div>
<h2><span data-translate="Credit Offer Operations History"></span></h2>
<div class="panel-body table-responsive">
<responsive-table data-data="operations"
data-columns="operationsColumns"
data-loading="operationsLoading"
data-template="operations-table.html"
data-loading-error="operationsLoadingError"
></responsive-table>

<footer class="table-footer">
<div class="row">
<div class="col-md-6 page-num-info">
</div>
<div class="col-md-6 text-right pagination-container">
<ul
uib-pagination class="pagination-sm"
ng-model="currentPage"
total-items="total_ops"
max-size="4"
ng-change="currentPage===undefined || select(currentPage)"
items-per-page="20"
rotate="false"
previous-text="&lsaquo;" next-text="&rsaquo;"
boundary-links="true"
></ul>
</div>
</div>
</footer>
</div>
</div>
</div>
Loading

0 comments on commit bd1dc0c

Please sign in to comment.