Skip to content

Commit

Permalink
[DDW-807] Detect and display dates in user's date format
Browse files Browse the repository at this point in the history
  • Loading branch information
DeeJayElly committed Aug 16, 2019
1 parent 8e4f39d commit 2656140
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 8 deletions.
8 changes: 8 additions & 0 deletions source/common/ipc/api.js
Expand Up @@ -207,3 +207,11 @@ export type SetCachedCardanoStatusMainResponse = void;
export const DETECT_SYSTEM_LOCALE_CHANNEL = 'DETECT_SYSTEM_LOCALE_CHANNEL';
export type DetectSystemLocaleRendererRequest = void;
export type DetectSystemLocaleMainResponse = string;

/**
* Channel where renderer can ask main process for the result of electron's app.getLocale()
*/
export const DETECT_SYSTEM_DATE_LOCALE_CHANNEL =
'DETECT_SYSTEM_DATE_LOCALE_CHANNEL';
export type DetectSystemDateLocaleRendererRequest = void;
export type DetectSystemDateLocaleMainResponse = string;
12 changes: 11 additions & 1 deletion source/main/index.js
Expand Up @@ -27,10 +27,14 @@ import { CardanoNode } from './cardano/CardanoNode';
import { safeExitWithCode } from './utils/safeExitWithCode';
import { buildAppMenus } from './utils/buildAppMenus';
import { getLocale } from './utils/getLocale';
import { detectSystemLocale } from './utils/detectSystemLocale';
import {
detectSystemLocale,
detectSystemDateLocale,
} from './utils/detectSystemLocale';
import { ensureXDGDataIsSet } from './cardano/config';
import { rebuildApplicationMenu } from './ipc/rebuild-application-menu';
import { detectSystemLocaleChannel } from './ipc/detect-system-locale';
import { detectSystemDateLocaleChannel } from './ipc/detect-system-date-locale';
import { getStateDirectoryPathChannel } from './ipc/getStateDirectoryPathChannel';
import { CardanoNodeStates } from '../common/types/cardano-node.types';
import type { CheckDiskSpaceResponse } from '../common/types/no-disk-space.types';
Expand Down Expand Up @@ -88,6 +92,8 @@ const onAppReady = async () => {
const startTime = new Date().toISOString();
// first checks for japanese locale, otherwise returns english
const systemLocale = detectSystemLocale();
// first checks for japanese locale, otherwise returns english
const systemDateLocale = detectSystemDateLocale();

const systemInfo = logSystemInfo({
cardanoVersion,
Expand Down Expand Up @@ -157,6 +163,10 @@ const onAppReady = async () => {

detectSystemLocaleChannel.onRequest(() => Promise.resolve(systemLocale));

detectSystemDateLocaleChannel.onRequest(() =>
Promise.resolve(systemDateLocale)
);

getNumberOfEpochsConsolidated();

setStateSnapshotLogChannel.onReceive(data => {
Expand Down
12 changes: 12 additions & 0 deletions source/main/ipc/detect-system-date-locale.js
@@ -0,0 +1,12 @@
// @flow
import { MainIpcChannel } from './lib/MainIpcChannel';
import { DETECT_SYSTEM_DATE_LOCALE_CHANNEL } from '../../common/ipc/api';
import type {
DetectSystemDateLocaleMainResponse,
DetectSystemDateLocaleRendererRequest,
} from '../../common/ipc/api';

export const detectSystemDateLocaleChannel: MainIpcChannel<
DetectSystemDateLocaleRendererRequest,
DetectSystemDateLocaleMainResponse
> = new MainIpcChannel(DETECT_SYSTEM_DATE_LOCALE_CHANNEL);
10 changes: 9 additions & 1 deletion source/main/utils/detectSystemLocale.js
Expand Up @@ -9,5 +9,13 @@ export const detectSystemLocale = (): string => {
if (systemLocale === 'ja') {
return LOCALES.japanese;
}
return LOCALES.english;
if (systemLocale === 'en-US') {
return LOCALES.english;
}
return systemLocale;
};

export const detectSystemDateLocale = (): string => {
const systemDateLocale = app.getLocale();
return systemDateLocale;
};
4 changes: 2 additions & 2 deletions source/renderer/app/containers/staking/StakingRewardsPage.js
Expand Up @@ -33,12 +33,12 @@ export default class StakingRewardsPage extends Component<Props> {

render() {
const { rewards } = this.props.stores.staking;
const { currentLocale } = this.props.stores.profile;
const { systemDateLocale } = this.props.stores.profile;

return (
<StakingRewards
rewards={rewards}
locale={currentLocale}
locale={systemDateLocale}
isLoading={false}
onLearnMoreClick={this.handleLearnMoreClick}
/>
Expand Down
4 changes: 2 additions & 2 deletions source/renderer/app/containers/wallet/WalletSummaryPage.js
Expand Up @@ -43,7 +43,7 @@ export default class WalletSummaryPage extends Component<Props> {
render() {
const { intl } = this.context;
const { app, wallets, transactions, profile } = this.props.stores;
const { currentLocale } = profile;
const { systemDateLocale } = profile;
const {
openExternalLink,
environment: { network },
Expand Down Expand Up @@ -79,7 +79,7 @@ export default class WalletSummaryPage extends Component<Props> {
hasMoreToLoad={false}
assuranceMode={wallet.assuranceMode}
walletId={wallet.id}
locale={currentLocale}
locale={systemDateLocale}
isRestoreActive={isRestoreActive}
formattedWalletAmount={formattedWalletAmount}
showMoreTransactionsButton={
Expand Down
Expand Up @@ -44,7 +44,7 @@ export default class WalletTransactionsPage extends Component<Props> {
const { intl } = this.context;
const { actions, stores } = this.props;
const { app, wallets, profile } = stores;
const { currentLocale } = profile;
const { systemDateLocale } = profile;
const {
openExternalLink,
environment: { network },
Expand Down Expand Up @@ -100,7 +100,7 @@ export default class WalletTransactionsPage extends Component<Props> {
hasMoreToLoad={hasMoreToLoad()}
onLoadMore={actions.transactions.loadMoreTransactions.trigger}
assuranceMode={activeWallet.assuranceMode}
locale={currentLocale}
locale={systemDateLocale}
walletId={activeWallet.id}
formattedWalletAmount={formattedWalletAmount}
onOpenExternalLink={openExternalLink}
Expand Down
12 changes: 12 additions & 0 deletions source/renderer/app/ipc/detect-system-date-locale.js
@@ -0,0 +1,12 @@
// @flow
import { RendererIpcChannel } from './lib/RendererIpcChannel';
import { DETECT_SYSTEM_DATE_LOCALE_CHANNEL } from '../../../common/ipc/api';
import type {
DetectSystemDateLocaleMainResponse,
DetectSystemDateLocaleRendererRequest,
} from '../../../common/ipc/api';

export const detectSystemDateLocaleChannel: RendererIpcChannel<
DetectSystemDateLocaleMainResponse,
DetectSystemDateLocaleRendererRequest
> = new RendererIpcChannel(DETECT_SYSTEM_DATE_LOCALE_CHANNEL);
13 changes: 13 additions & 0 deletions source/renderer/app/stores/ProfileStore.js
Expand Up @@ -15,6 +15,7 @@ import { formattedBytesToSize } from '../utils/formatters';
import { Logger } from '../utils/logging';
import { setStateSnapshotLogChannel } from '../ipc/setStateSnapshotLogChannel';
import { detectSystemLocaleChannel } from '../ipc/detect-system-locale';
import { detectSystemDateLocaleChannel } from '../ipc/detect-system-date-locale';
import { LOCALES } from '../../../common/types/locales.types';
import {
compressLogsChannel,
Expand All @@ -38,6 +39,7 @@ export default class ProfileStore extends Store {
];

@observable systemLocale: string = LOCALES.english;
@observable systemDateLocale: string = LOCALES.english;
@observable bigNumberDecimalFormat = {
decimalSeparator: '.',
groupSeparator: ',',
Expand Down Expand Up @@ -107,6 +109,7 @@ export default class ProfileStore extends Store {
this._redirectToMainUiAfterDataLayerMigrationIsAccepted,
]);
this._getSystemLocale();
this._getSystemDateLocale();
this._getTermsOfUseAcceptance();
this._getDataLayerMigrationAcceptance();
}
Expand Down Expand Up @@ -196,6 +199,12 @@ export default class ProfileStore extends Store {
this._onReceiveSystemLocale(await detectSystemLocaleChannel.request());
};

_getSystemDateLocale = async () => {
this._onReceiveSystemDateLocale(
await detectSystemDateLocaleChannel.request()
);
};

_updateLocale = async ({ locale }: { locale: string }) => {
await this.setProfileLocaleRequest.execute(locale);
await this.getProfileLocaleRequest.execute();
Expand Down Expand Up @@ -494,6 +503,10 @@ export default class ProfileStore extends Store {
this.systemLocale = systemLocale;
};

@action _onReceiveSystemDateLocale = (systemDateLocale: string) => {
this.systemDateLocale = systemDateLocale;
};

@action _reset = () => {
this.error = null;
this.compressedLogsFilePath = null;
Expand Down

0 comments on commit 2656140

Please sign in to comment.