Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #3490, Credit offer repayment period 'No limit' #3493

Merged
merged 1 commit into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/actions/CreditOfferActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import {Apis} from "bitsharesjs-ws";
export const FEE_RATE_DENOM = 1000000; // Denominator for SameT Fund fee calculation
export const listRepayPeriod = [43200, 86400, 259200, 604800, 2592000, 7776000];

export const parsingTime = (time, uints = ["day", "hour", "minute"]) => {
let str = "";
let days = Math.floor(time / 86400);
if (days > 0) str = days + uints[0];
let hours = Math.floor((time % 86400) / 3600);
if (hours > 0) str = str + hours + uints[1];
let minute = Math.floor(((time % 86400) % 3600) / 60);
if (minute > 0) str = str + minute + uints[2];
return str;
};

class CreditOfferActions {
create({
owner_account,
Expand Down
3 changes: 3 additions & 0 deletions app/assets/locales/locale-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3035,6 +3035,9 @@
"period_4": "30 Days",
"period_5": "90 days"
},
"uint_day": "Days",
"uint_hour": "Hours",
"uint_minute": "Minutes",
"info_borrow_err": "Can't borrow from oneself !",
"asset": "Asset",
"total_amount": "Total",
Expand Down
3 changes: 3 additions & 0 deletions app/assets/locales/locale-zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -3024,6 +3024,9 @@
"period_4": "30天",
"period_5": "90天"
},
"uint_day": "天",
"uint_hour": "时",
"uint_minute": "分",
"info_borrow_err": "不能向自己借款!",
"asset": "资产",
"total_amount": "总数量",
Expand Down
13 changes: 9 additions & 4 deletions app/components/Account/CreditOffer/CreditOfferList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ class CreditOfferList extends React.Component {
}
}

_getUnits() {
return [
counterpart.translate("credit_offer.uint_day"),
counterpart.translate("credit_offer.uint_hour"),
counterpart.translate("credit_offer.uint_minute")
];
}

_getColumns() {
let header = [
{
Expand Down Expand Up @@ -143,10 +151,7 @@ class CreditOfferList extends React.Component {
title: counterpart.translate("credit_offer.repay_period"),
dataIndex: "max_duration_seconds",
render: item => {
let index = listRepayPeriod.indexOf(item);
return counterpart.translate(
"credit_offer.list_repay_period.period_" + index
);
return parsingTime(item, this._getUnits());
}
},
{
Expand Down
24 changes: 14 additions & 10 deletions app/components/Account/CreditOffer/CreditOfferPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import moment from "moment";
import utils from "../../../lib/common/utils";
import CreditOfferActions, {
FEE_RATE_DENOM,
listRepayPeriod
listRepayPeriod,
parsingTime
} from "../../../actions/CreditOfferActions";

import AccountStore from "stores/AccountStore";
Expand Down Expand Up @@ -149,6 +150,14 @@ class CreditOfferPage extends React.Component {
return aAsset - bAsset;
}

_getUnits() {
return [
counterpart.translate("credit_offer.uint_day"),
counterpart.translate("credit_offer.uint_hour"),
counterpart.translate("credit_offer.uint_minute")
];
}

_getColumns() {
return [
{
Expand Down Expand Up @@ -244,10 +253,7 @@ class CreditOfferPage extends React.Component {
sorter: (a, b) =>
a.max_duration_seconds - b.max_duration_seconds,
render: item => {
let index = listRepayPeriod.indexOf(item);
return counterpart.translate(
"credit_offer.list_repay_period.period_" + index
);
return parsingTime(item, this._getUnits());
}
},
{
Expand Down Expand Up @@ -576,11 +582,9 @@ class CreditOfferPage extends React.Component {
width: "100%"
}}
>
{counterpart.translate(
"credit_offer.list_repay_period.period_" +
listRepayPeriod.indexOf(
info.max_duration_seconds
)
{parsingTime(
info.max_duration_seconds,
this._getUnits()
)}
</div>
</Form.Item>
Expand Down