Skip to content

Commit 46524ec

Browse files
Merge pull request #3496 from xiangxn/fix-3490
Fix credit offer repayment period "No limit" #3490
2 parents 16d359d + 616edd7 commit 46524ec

File tree

7 files changed

+28
-40
lines changed

7 files changed

+28
-40
lines changed

app/actions/CreditOfferActions.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ import moment from "moment";
44
import {Asset} from "../lib/common/MarketClasses";
55
import WalletDb from "../stores/WalletDb";
66
import {Apis} from "bitsharesjs-ws";
7+
import humanizeDuration from "humanize-duration";
78

89
export const FEE_RATE_DENOM = 1000000; // Denominator for SameT Fund fee calculation
910
export const listRepayPeriod = [43200, 86400, 259200, 604800, 2592000, 7776000];
1011

11-
export const parsingTime = (time, uints = ["day", "hour", "minute"]) => {
12-
let str = "";
13-
let days = Math.floor(time / 86400);
14-
if (days > 0) str = days + uints[0];
15-
let hours = Math.floor((time % 86400) / 3600);
16-
if (hours > 0) str = str + hours + uints[1];
17-
let minute = Math.floor(((time % 86400) % 3600) / 60);
18-
if (minute > 0) str = str + minute + uints[2];
19-
return str;
12+
export const parsingTime = (time, locale) => {
13+
if (locale === "zh") locale = "zh_CN";
14+
return humanizeDuration(parseInt(time) * 1000, {
15+
language: locale,
16+
delimiter: " ",
17+
units: ["d", "h", "m"]
18+
});
2019
};
2120

2221
class CreditOfferActions {

app/assets/locales/locale-en.json

-3
Original file line numberDiff line numberDiff line change
@@ -3038,9 +3038,6 @@
30383038
"period_4": "30 Days",
30393039
"period_5": "90 days"
30403040
},
3041-
"uint_day": "Days",
3042-
"uint_hour": "Hours",
3043-
"uint_minute": "Minutes",
30443041
"info_borrow_err": "Can't borrow from oneself !",
30453042
"asset": "Asset",
30463043
"total_amount": "Total",

app/assets/locales/locale-zh.json

-3
Original file line numberDiff line numberDiff line change
@@ -3027,9 +3027,6 @@
30273027
"period_4": "30天",
30283028
"period_5": "90天"
30293029
},
3030-
"uint_day": "",
3031-
"uint_hour": "",
3032-
"uint_minute": "",
30333030
"info_borrow_err": "不能向自己借款!",
30343031
"asset": "资产",
30353032
"total_amount": "总数量",

app/components/Account/CreditOffer/CreditOfferList.jsx

+6-12
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import CreateModal from "./CreateModal";
1414
import EditModal from "./EditModal";
1515
import CreditOfferActions, {
1616
FEE_RATE_DENOM,
17-
listRepayPeriod
17+
parsingTime
1818
} from "../../../actions/CreditOfferActions";
1919
import CreditOfferStore from "../../../stores/CreditOfferStore";
2020
import LinkToAssetById from "../../Utility/LinkToAssetById";
2121
import FormattedAsset from "../../Utility/FormattedAsset";
2222
import moment from "moment";
23+
import IntlStore from "stores/IntlStore";
2324

2425
class CreditOfferList extends React.Component {
2526
constructor(props) {
@@ -77,14 +78,6 @@ class CreditOfferList extends React.Component {
7778
}
7879
}
7980

80-
_getUnits() {
81-
return [
82-
counterpart.translate("credit_offer.uint_day"),
83-
counterpart.translate("credit_offer.uint_hour"),
84-
counterpart.translate("credit_offer.uint_minute")
85-
];
86-
}
87-
8881
_getColumns() {
8982
let header = [
9083
{
@@ -151,7 +144,7 @@ class CreditOfferList extends React.Component {
151144
title: counterpart.translate("credit_offer.repay_period"),
152145
dataIndex: "max_duration_seconds",
153146
render: item => {
154-
return parsingTime(item, this._getUnits());
147+
return parsingTime(item, this.props.locale);
155148
}
156149
},
157150
{
@@ -304,13 +297,14 @@ class CreditOfferList extends React.Component {
304297

305298
CreditOfferList = connect(CreditOfferList, {
306299
listenTo() {
307-
return [AccountStore, CreditOfferStore];
300+
return [AccountStore, CreditOfferStore, IntlStore];
308301
},
309302
getProps(props) {
310303
return {
311304
currentAccount: AccountStore.getState().currentAccount,
312305
passwordAccount: AccountStore.getState().passwordAccount,
313-
listByOwner: CreditOfferStore.getState().listByOwner
306+
listByOwner: CreditOfferStore.getState().listByOwner,
307+
locale: IntlStore.getState().currentLocale
314308
};
315309
}
316310
});

app/components/Account/CreditOffer/CreditOfferPage.jsx

+8-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import moment from "moment";
1717
import utils from "../../../lib/common/utils";
1818
import CreditOfferActions, {
1919
FEE_RATE_DENOM,
20-
listRepayPeriod,
2120
parsingTime
2221
} from "../../../actions/CreditOfferActions";
2322

@@ -31,6 +30,7 @@ import Translate from "react-translate-component";
3130
import FeeAssetSelector from "../../Utility/FeeAssetSelector";
3231
import {checkBalance} from "common/trxHelper";
3332
import notify from "actions/NotificationActions";
33+
import IntlStore from "stores/IntlStore";
3434

3535
const getUninitializedFeeAmount = () =>
3636
new Asset({amount: 0, asset_id: "1.3.0"});
@@ -150,15 +150,9 @@ class CreditOfferPage extends React.Component {
150150
return aAsset - bAsset;
151151
}
152152

153-
_getUnits() {
154-
return [
155-
counterpart.translate("credit_offer.uint_day"),
156-
counterpart.translate("credit_offer.uint_hour"),
157-
counterpart.translate("credit_offer.uint_minute")
158-
];
159-
}
160-
161153
_getColumns() {
154+
let {locale} = this.props;
155+
if (locale === "zh") locale = "zh_CN";
162156
return [
163157
{
164158
title: "ID",
@@ -253,7 +247,7 @@ class CreditOfferPage extends React.Component {
253247
sorter: (a, b) =>
254248
a.max_duration_seconds - b.max_duration_seconds,
255249
render: item => {
256-
return parsingTime(item, this._getUnits());
250+
return parsingTime(item, locale);
257251
}
258252
},
259253
{
@@ -583,7 +577,7 @@ class CreditOfferPage extends React.Component {
583577
>
584578
{parsingTime(
585579
info.max_duration_seconds,
586-
this._getUnits()
580+
this.props.locale
587581
)}
588582
</div>
589583
</Form.Item>
@@ -716,13 +710,14 @@ class CreditOfferPage extends React.Component {
716710

717711
CreditOfferPage = connect(CreditOfferPage, {
718712
listenTo() {
719-
return [AccountStore, CreditOfferStore];
713+
return [AccountStore, CreditOfferStore, IntlStore];
720714
},
721715
getProps(props) {
722716
return {
723717
currentAccount: AccountStore.getState().currentAccount,
724718
passwordAccount: AccountStore.getState().passwordAccount,
725-
allList: CreditOfferStore.getState().allList
719+
allList: CreditOfferStore.getState().allList,
720+
locale: IntlStore.getState().currentLocale
726721
};
727722
}
728723
});

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
"handlebars": "^4.7.7",
162162
"hirestime": "^3.2.1",
163163
"html2canvas": "^1.3.3",
164+
"humanize-duration": "^3.27.1",
164165
"ifvisible": "^1.1.0",
165166
"immutable": "3.8.2",
166167
"indexeddbshim": "^2.2.1",

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -6279,6 +6279,11 @@ human-signals@^2.1.0:
62796279
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
62806280
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==
62816281

6282+
humanize-duration@^3.27.1:
6283+
version "3.27.1"
6284+
resolved "https://registry.npmjs.org/humanize-duration/-/humanize-duration-3.27.1.tgz#2cd4ea4b03bd92184aee6d90d77a8f3d7628df69"
6285+
integrity sha512-jCVkMl+EaM80rrMrAPl96SGG4NRac53UyI1o/yAzebDntEY6K6/Fj2HOjdPg8omTqIe5Y0wPBai2q5xXrIbarA==
6286+
62826287
husky@^0.14.3:
62836288
version "0.14.3"
62846289
resolved "https://registry.yarnpkg.com/husky/-/husky-0.14.3.tgz#c69ed74e2d2779769a17ba8399b54ce0b63c12c3"

0 commit comments

Comments
 (0)