Skip to content

Commit

Permalink
[DDW-619] Replace momentjs with dayjs
Browse files Browse the repository at this point in the history
  • Loading branch information
topseniors committed May 3, 2021
1 parent e103a2f commit 41920d1
Show file tree
Hide file tree
Showing 44 changed files with 284 additions and 182 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
"classnames": "2.2.6",
"csv-stringify": "5.5.1",
"cucumber-html-reporter": "5.2.0",
"dayjs": "1.10.4",
"electron": "8.2.2",
"electron-log-daedalus": "2.2.21",
"electron-store": "5.1.1",
Expand All @@ -216,7 +217,6 @@
"mobx-react": "6.3.0",
"mobx-react-form": "2.0.8",
"mobx-react-router": "4.1.0",
"moment": "2.29.0",
"node-downloader-helper": "1.0.14",
"omit-deep-lodash": "1.1.5",
"pbkdf2": "3.0.17",
Expand Down
4 changes: 2 additions & 2 deletions source/common/types/locales.types.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export const humanizedDurationLanguages = {
'ja-JP': 'ja',
};

export const momentLocales: {
export const dayjsLocales: {
[key: Locale]: string,
} = {
'en-US': 'en-us',
'en-US': 'en',
'ja-JP': 'ja',
};
9 changes: 6 additions & 3 deletions source/common/utils/files.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// @flow
import moment from 'moment';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import sanitizeFilename from 'sanitize-filename';

dayjs.extend(utc);

export const defaultProps = {
prefix: 'logs',
extension: 'zip',
Expand All @@ -12,7 +15,7 @@ export const defaultProps = {
type Props = {
prefix?: string,
extension?: string,
date?: moment,
date?: dayjs.Dayjs,
isUTC?: boolean,
sanitize?: boolean,
};
Expand All @@ -22,7 +25,7 @@ export const generateFileNameWithTimestamp = (props?: Props = {}) => {
...defaultProps,
...props,
};
let date = props.date || moment();
let date = props.date || dayjs();
let z = '';
if (isUTC === true) {
if (!props || !Object.prototype.hasOwnProperty.call(props, 'date'))
Expand Down
9 changes: 6 additions & 3 deletions source/main/cardano/CardanoNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import type { ChildProcess } from 'child_process';
import type { WriteStream } from 'fs';
import type { Launcher } from 'cardano-launcher';
import { get, toInteger } from 'lodash';
import moment from 'moment';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import rfs from 'rotating-file-stream';
import { environment } from '../environment';
import {
Expand Down Expand Up @@ -34,6 +35,8 @@ import { launcherConfig } from '../config';
import type { NodeConfig } from '../config';
import type { Logger } from '../../common/types/logging.types';

dayjs.extend(utc);

/* eslint-disable consistent-return */

type Actions = {
Expand Down Expand Up @@ -317,7 +320,7 @@ export class CardanoNode {
(time) => {
// The module works by writing to the one file name before it is rotated out.
if (!time) return 'node.log';
const timestamp = moment.utc().format('YYYYMMDDHHmmss');
const timestamp = dayjs.utc().format('YYYYMMDDHHmmss');
return `node.log-${timestamp}`;
},
{
Expand All @@ -332,7 +335,7 @@ export class CardanoNode {
(time) => {
// The module works by writing to the one file name before it is rotated out.
if (!time) return 'cardano-wallet.log';
const timestamp = moment.utc().format('YYYYMMDDHHmmss');
const timestamp = dayjs.utc().format('YYYYMMDDHHmmss');
return `cardano-wallet.log-${timestamp}`;
},
{
Expand Down
27 changes: 15 additions & 12 deletions source/renderer/app/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import { split, get, map, last, size, concat, flatten } from 'lodash';
import { action } from 'mobx';
import BigNumber from 'bignumber.js';
import moment from 'moment';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import duration from 'dayjs/plugin/duration';
// domains
import Wallet, {
WalletDelegationStatuses,
Expand Down Expand Up @@ -239,6 +241,9 @@ import Asset from '../domains/Asset';
import { getAssets } from './assets/requests/getAssets';
import { getAccountPublicKey } from './wallets/requests/getAccountPublicKey';

dayjs.extend(utc);
dayjs.extend(duration);

const { isIncentivizedTestnet } = global;

export default class AdaApi {
Expand Down Expand Up @@ -448,9 +453,9 @@ export default class AdaApi {
}
);
if (fromDate)
params.start = `${moment.utc(fromDate).format('YYYY-MM-DDTHH:mm:ss')}Z`;
params.start = `${dayjs.utc(fromDate).format('YYYY-MM-DDTHH:mm:ss')}Z`;
if (toDate)
params.end = `${moment.utc(toDate).format('YYYY-MM-DDTHH:mm:ss')}Z`;
params.end = `${dayjs.utc(toDate).format('YYYY-MM-DDTHH:mm:ss')}Z`;

try {
let response;
Expand Down Expand Up @@ -482,13 +487,13 @@ export default class AdaApi {
// cachedTransactions: request.cachedTransactions.length,
// });
// logger.debug('AdaApi::searchHistory called', { parameters: requestStats });
// const requestTimestamp = moment();
// const requestTimestamp = dayjs();
// const params = {
// wallet_id: walletId,
// page: skip === 0 ? 1 : skip + 1,
// per_page: perPage,
// sort_by: 'DES[created_at]',
// created_at: `LTE[${moment.utc().format('YYYY-MM-DDTHH:mm:ss')}]`,
// created_at: `LTE[${dayjs.utc().format('YYYY-MM-DDTHH:mm:ss')}]`,
// // ^^ By setting created_at filter to current time we make sure
// // all subsequent multi-pages requests load the same set of transactions
// };
Expand Down Expand Up @@ -516,15 +521,15 @@ export default class AdaApi {
// page: skip === 0 ? 1 : skip + 1,
// per_page: perPage,
// sort_by: 'DES[created_at]',
// created_at: `LTE[${moment.utc().format('YYYY-MM-DDTHH:mm:ss')}]`,
// created_at: `LTE[${dayjs.utc().format('YYYY-MM-DDTHH:mm:ss')}]`,
// // ^^ By setting created_at filter to current time we make sure
// // all subsequent multi-pages requests load the same set of transactions
// };
//
// const shouldLoadOnlyFresh =
// !isFirstLoad && !isRestoreActive && !isRestoreCompleted;
// if (shouldLoadOnlyFresh) {
// const tenMinutesAgo = moment
// const tenMinutesAgo = dayjs
// .utc(Date.now() - TX_AGE_POLLING_THRESHOLD)
// .format('YYYY-MM-DDTHH:mm:ss');
// // Since we load all transactions in a first load, later on we only care about fresh ones
Expand Down Expand Up @@ -570,7 +575,7 @@ export default class AdaApi {
//
// if (isRestoreActive || isRestoreCompleted) {
// const latestLoadedTransactionDate = transactions[0].date;
// const latestLoadedTransactionDateString = moment
// const latestLoadedTransactionDateString = dayjs
// .utc(latestLoadedTransactionDate)
// .format('YYYY-MM-DDTHH:mm:ss');
// // During restoration we need to fetch only transactions older than the latest loaded one
Expand Down Expand Up @@ -612,9 +617,7 @@ export default class AdaApi {
// daedalusCached: cachedTransactions.length,
// daedalusLoaded: total - cachedTransactions.length,
// daedalusTotal: total,
// requestDurationInMs: moment
// .duration(moment().diff(requestTimestamp))
// .as('milliseconds'),
// requestDurationInMs: dayjs.duration(dayjs().diff(requestTimestamp)).as('milliseconds'),
// };
// logger.debug(
// `AdaApi::searchHistory success: ${total} transactions loaded`,
Expand Down Expand Up @@ -2327,7 +2330,7 @@ export default class AdaApi {
minimum_utxo_value: minimumUtxoValue,
eras,
} = networkParameters;
const blockchainStartTime = moment(blockchain_start_time).valueOf();
const blockchainStartTime = dayjs(blockchain_start_time).valueOf();

return {
genesisBlockHash,
Expand Down
7 changes: 5 additions & 2 deletions source/renderer/app/api/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// @flow
import moment from 'moment';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import blakejs from 'blakejs';

dayjs.extend(utc);

// time utils
export const unixTimestampToDate = (timestamp: number) =>
new Date(timestamp * 1000);
export const utcStringToDate = (createDate: string) =>
moment.utc(createDate).toDate();
dayjs.utc(createDate).toDate();

// passphrase utils
const bytesToB16 = (bytes) => Buffer.from(bytes).toString('hex');
Expand Down
9 changes: 6 additions & 3 deletions source/renderer/app/components/news/AlertsOverlay.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import React, { Component } from 'react';
import moment from 'moment';
import dayjs from 'dayjs';
import localeData from 'dayjs/plugin/localeData';
import { observer } from 'mobx-react';
import { get } from 'lodash';
import ReactMarkdown from 'react-markdown';
Expand All @@ -11,6 +12,8 @@ import closeCrossThin from '../../assets/images/close-cross-thin.inline.svg';
import ButtonLink from '../widgets/ButtonLink';
import styles from './AlertsOverlay.scss';

dayjs.extend(localeData);

type State = {
showOverlay: boolean,
};
Expand Down Expand Up @@ -38,7 +41,7 @@ export default class AlertsOverlay extends Component<Props, State> {
localizedDateFormat: 'MM/DD/YYYY';

componentDidMount() {
this.localizedDateFormat = moment.localeData().longDateFormat('L');
this.localizedDateFormat = dayjs.localeData().longDateFormat('L');
}

contentClickHandler(event: SyntheticMouseEvent<HTMLElement>) {
Expand Down Expand Up @@ -112,7 +115,7 @@ export default class AlertsOverlay extends Component<Props, State> {
{this.renderCounter(alerts)}
<h1 className={styles.title}>{title}</h1>
<span className={styles.date}>
{moment(date).format(currentDateFormat)}
{dayjs(date).format(currentDateFormat)}
</span>
<div
className={styles.content}
Expand Down
9 changes: 6 additions & 3 deletions source/renderer/app/components/news/IncidentOverlay.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import React, { Component } from 'react';
import moment from 'moment';
import dayjs from 'dayjs';
import localeData from 'dayjs/plugin/localeData';
import { observer } from 'mobx-react';
import { get, camelCase } from 'lodash';
import ReactMarkdown from 'react-markdown';
Expand All @@ -10,6 +11,8 @@ import News from '../../domains/News';
import ButtonLink from '../widgets/ButtonLink';
import styles from './IncidentOverlay.scss';

dayjs.extend(localeData);

type Props = {
incident: News.News,
onOpenExternalLink: Function,
Expand All @@ -22,7 +25,7 @@ export default class IncidentOverlay extends Component<Props> {
localizedDateFormat: 'MM/DD/YYYY';

componentDidMount() {
this.localizedDateFormat = moment.localeData().longDateFormat('L');
this.localizedDateFormat = dayjs.localeData().longDateFormat('L');
}

contentClickHandler(event: SyntheticMouseEvent<HTMLElement>) {
Expand Down Expand Up @@ -68,7 +71,7 @@ export default class IncidentOverlay extends Component<Props> {
<div className={componentClasses}>
<h1 className={styles.title}>{title}</h1>
<span className={styles.date}>
{moment(date).format(currentDateFormat)}
{dayjs(date).format(currentDateFormat)}
</span>
<div
className={styles.content}
Expand Down
4 changes: 2 additions & 2 deletions source/renderer/app/components/news/NewsItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { Component } from 'react';
import { observer } from 'mobx-react';
import classNames from 'classnames';
import ReactMarkdown from 'react-markdown';
import moment from 'moment';
import dayjs from 'dayjs';
import { get } from 'lodash';
import AnimateHeight from 'react-animate-height';
import { ButtonSkin } from 'react-polymorph/lib/skins/simple/ButtonSkin';
Expand Down Expand Up @@ -126,7 +126,7 @@ export default class NewsItem extends Component<Props, State> {
>
{title}
<div className={styles.newsItemDate}>
{moment(newsItem.date).format(currentDateFormat)}
{dayjs(newsItem.date).format(currentDateFormat)}
</div>
<div className={styles.newsItemContentWrapper}>
<AnimateHeight
Expand Down
4 changes: 2 additions & 2 deletions source/renderer/app/components/news/UpdateItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import classNames from 'classnames';
import moment from 'moment';
import dayjs from 'dayjs';
import News /* , { NewsTypes } */ from '../../domains/News';
import styles from './UpdateItem.scss';

Expand Down Expand Up @@ -64,7 +64,7 @@ export default class UpdateItem extends Component<Props> {
>
{title}
<div className={styles.date}>
{moment(updateItem.date).format(currentDateFormat)}
{dayjs(updateItem.date).format(currentDateFormat)}
</div>
{!isUpdatePostponed && (
<div className={styles.downloadProgress}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import { defineMessages, intlShape } from 'react-intl';
import moment from 'moment';
import dayjs from 'dayjs';
import StakingChartTooltipItem from './StakingChartTooltipItem';
import styles from './StakingChartTooltip.scss';

Expand Down Expand Up @@ -75,7 +75,7 @@ export default class StakingChartTooltip extends Component<Props> {
<div className={styles.slot}>
{`#${slot}`} {intl.formatMessage(messages.slot)}
</div>
<div className={styles.date}>{moment(time).format(dateFormat)}</div>
<div className={styles.date}>{dayjs(time).format(dateFormat)}</div>
<div className={styles.hash}>{hash}</div>
<StakingChartTooltipItem
key="transactions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { observer } from 'mobx-react';
import { intlShape } from 'react-intl';
import { get, map } from 'lodash';
import BigNumber from 'bignumber.js';
import moment from 'moment';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import 'dayjs/locale/ja';
import classNames from 'classnames';
import {
formattedWalletAmount,
Expand All @@ -15,6 +17,8 @@ import styles from './StakePoolsTable.scss';
import { getColorFromRange, getSaturationColor } from '../../../utils/colors';
import StakePool from '../../../domains/StakePool';

dayjs.extend(relativeTime);

type TableBodyProps = {
sortedStakePoolList: StakePool,
numberOfRankedStakePools: number,
Expand Down Expand Up @@ -58,7 +62,7 @@ export class StakePoolsTableBody extends Component<TableBodyProps> {
);
const potentialRewards = formattedWalletAmount(memberRewards);
const retirement =
retiring && moment(retiring).locale(intl.locale).fromNow(true);
retiring && dayjs(retiring).locale(intl.locale).fromNow(true);
const pledgeValue = formattedWalletAmount(pledge, false, false);
const costValue = formattedWalletAmount(cost, false, false);
const progressBarContentClassnames = classNames([
Expand Down
8 changes: 6 additions & 2 deletions source/renderer/app/components/staking/widgets/TooltipPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import { Button } from 'react-polymorph/lib/components/Button';
import { PopOver } from 'react-polymorph/lib/components/PopOver';
import CopyToClipboard from 'react-copy-to-clipboard';
import classnames from 'classnames';
import moment from 'moment';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import 'dayjs/locale/ja';
import SVGInline from 'react-svg-inline';
import { ButtonSkin } from 'react-polymorph/lib/skins/simple/ButtonSkin';
import { Link } from 'react-polymorph/lib/components/Link';
Expand All @@ -37,6 +39,8 @@ import {
IS_SATURATION_DATA_AVAILABLE,
} from '../../../config/stakingConfig';

dayjs.extend(relativeTime);

const messages = defineMessages({
ranking: {
id: 'staking.stakePools.tooltip.ranking',
Expand Down Expand Up @@ -450,7 +454,7 @@ export default class TooltipPool extends Component<Props, State> {
const { id, name, description, ticker, homepage, retiring } = stakePool;

const retirementFromNow = retiring
? moment(retiring).locale(intl.locale).fromNow(true)
? dayjs(retiring).locale(intl.locale).fromNow(true)
: '';

const idCopyIcon = idCopyFeedback ? copyCheckmarkIcon : copyIcon;
Expand Down
Loading

0 comments on commit 41920d1

Please sign in to comment.