/
InstructionsDialogContainer.js
94 lines (84 loc) · 2.61 KB
/
InstructionsDialogContainer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// @flow
import React, { Component } from 'react';
import path from 'path';
import { observer, inject } from 'mobx-react';
import moment from 'moment';
import { showSaveDialogChannel } from '../../../../ipc/show-file-dialog-channels';
import InstructionsDialog from '../../../../components/wallet/paper-wallet-certificate/InstructionsDialog';
import type { InjectedDialogContainerProps } from '../../../../types/injectedPropsType';
import { generateFileNameWithTimestamp } from '../../../../../../common/utils/files';
type Props = InjectedDialogContainerProps;
type pdfType = 'pdf';
type saveDialogChannelFilterType = {
name: string,
extensions: pdfType[],
};
type saveDialogChannelType = {
defaultPath: string,
filters: saveDialogChannelFilterType[],
};
@inject('stores', 'actions')
@observer
export default class InstructionsDialogContainer extends Component<Props> {
static defaultProps = {
actions: null,
stores: null,
children: null,
onClose: () => {},
};
onPrint = async () => {
const {
currentDateFormat,
currentTimeFormatShort,
} = this.props.stores.profile;
const date = moment();
const formattedDate = date.format(currentDateFormat);
const formattedTime = date.format(currentTimeFormatShort);
const timestamp = `${formattedDate} - ${formattedTime}`;
const name = generateFileNameWithTimestamp({
prefix: 'paper-wallet-certificate',
date,
extension: '',
isUTC: false,
});
const { desktopDirectoryPath } = this.props.stores.profile;
const defaultPath: string = path.join(desktopDirectoryPath, `${name}.pdf`);
const params: saveDialogChannelType = {
defaultPath,
filters: [
{
name,
extensions: ['pdf'],
},
],
};
const { filePath } = await showSaveDialogChannel.send(params);
// if cancel button is clicked or path is empty
if (!filePath) return;
this.props.actions.wallets.generateCertificate.trigger({
filePath,
timestamp,
});
};
handleOpenExternalLink = (url: string) => {
const { openExternalLink } = this.props.stores.app;
openExternalLink(url);
};
render() {
const { wallets, app } = this.props.stores;
const {
environment: { network, rawNetwork },
} = app;
return (
<InstructionsDialog
inProgress={wallets.generatingCertificateInProgress}
error={wallets.generatingCertificateError}
network={network}
rawNetwork={rawNetwork}
onPrint={this.onPrint}
onClose={this.props.onClose}
onOpenExternalLink={this.handleOpenExternalLink}
/>
);
}
}