Skip to content
Permalink
Browse files

[DDW-637] Handling open file error

  • Loading branch information...
daniloprates committed May 13, 2019
1 parent ead9b5f commit 4dc5e418c3fd7a24b6ca65fcfe93b741b1961347
@@ -6,7 +6,9 @@ import { defineMessages, intlShape, FormattedMessage } from 'react-intl';
import Dialog from '../../widgets/Dialog';
import DialogCloseButton from '../../widgets/DialogCloseButton';
import { getNetworkExplorerUrl } from '../../../utils/network';
import LocalizableError from '../../../i18n/LocalizableError';
import styles from './InstructionsDialog.scss';
import { handleFormErrors } from '../../../utils/ReactToolboxMobxForm';
import {
PAPER_WALLET_RECOVERY_PHRASE_WORD_COUNT,
PAPER_WALLET_WRITTEN_WORDS_COUNT,
@@ -109,6 +111,7 @@ type Props = {
onClose: Function,
onOpenExternalLink: Function,
onPrint: Function,
error?: ?LocalizableError,
};

@observer
@@ -121,6 +124,12 @@ export default class InstructionsDialog extends Component<Props> {
network: DEVELOPMENT,
};

componentWillReceiveProps(newProps: Props) {
if (!this.props.error && newProps.error) {
handleFormErrors('.InstructionsDialog_error', { focusElement: true });
}
}

render() {
const { intl } = this.context;
const {
@@ -129,6 +138,7 @@ export default class InstructionsDialog extends Component<Props> {
inProgress,
onOpenExternalLink,
network,
error,
} = this.props;
const dialogClasses = classnames([styles.component, 'instructionsDialog']);

@@ -213,6 +223,8 @@ export default class InstructionsDialog extends Component<Props> {
<p className={styles.printingInstructions}>
<strong>{intl.formatMessage(messages.printingInstructions)}</strong>
</p>

{error && <p className={styles.error}>{intl.formatMessage(error)}</p>}
</div>
</Dialog>
);
@@ -1,4 +1,5 @@
@import '../../../themes/mixins/loading-spinner';
@import '../../../themes/mixins/error-message';

.instructionsContentWrapper {
color: var(--theme-instructions-text-color);
@@ -59,6 +60,11 @@
}
}

.error {
@include error-message;
margin: 1rem 0;
}

.submitButtonSpinning {
box-shadow: none !important;
@include loading-spinner('../../../assets/images/spinner-light.svg');
@@ -51,35 +51,24 @@ export default class InstructionsDialogContainer extends Component<Props> {
isUTC: false,
});

try {
// TODO: refactor this direct access to the dialog api
const filePath = global.dialog.showSaveDialog({
defaultPath: `${name}.pdf`,
filters: [
{
name,
extensions: ['pdf'],
},
],
});

// if cancel button is clicked or path is empty
if (!filePath) return;

this.props.actions.wallets.generateCertificate.trigger({
filePath,
timestamp,
});
} catch (error) {
console.log('ERROR: -----------');
console.log(error);
// TODO: refactor this direct access to the dialog api
const filePath = global.dialog.showSaveDialog({
defaultPath: `${name}.pdf`,
filters: [
{
name,
extensions: ['pdf'],
},
],
});

alert(
'Please, close the existing PDF file or save with a different name'
);
// if cancel button is clicked or path is empty
if (!filePath) return;

return false;
}
this.props.actions.wallets.generateCertificate.trigger({
filePath,
timestamp,
});
};

render() {
@@ -91,6 +80,7 @@ export default class InstructionsDialogContainer extends Component<Props> {
return (
<InstructionsDialog
inProgress={wallets.generatingCertificateInProgress}
error={wallets.generatingCertificateError}
network={network}
onPrint={this.onPrint}
onClose={this.props.onClose}
@@ -55,3 +55,13 @@ export class WalletSupportRequestLogsCompressError extends LocalizableError {
});
}
}

export class WalletPaperWalletOpenPdfError extends LocalizableError {
constructor() {
super({
id: 'global.errors.paperWalletOpenPdfError',
defaultMessage:
'!!!The file you are trying to replace is open. Please close it and try again.',
});
}
}
@@ -55,6 +55,13 @@ export default defineMessages({
description:
"Error message shown when wallet password and repeat passwords don't match in create wallet dialog.",
},
paperWalletOpenPdfError: {
id: 'global.errors.paperWalletOpenPdfError',
defaultMessage:
'!!!The file you are trying to replace is open. Please close it and try again.',
description:
'Error message shown when the file the user tries to replace is open.',
},
passwordInstructions: {
id: 'global.passwordInstructions',
defaultMessage:
@@ -51,6 +51,7 @@
"global.errors.invalidRepeatPassword": "!!!Doesn't match.",
"global.errors.invalidSpendingPassword": "!!!Invalid password",
"global.errors.invalidWalletName": "!!!Wallet name requires at least 3 and at most 40 letters.",
"global.errors.paperWalletOpenPdfError": "!!!The file you are trying to replace is open. Please close it and try again.",
"global.labels.cancel": "!!!Cancel",
"global.labels.change": "!!!Change",
"global.labels.create": "!!!Create",
Oops, something went wrong.

0 comments on commit 4dc5e41

Please sign in to comment.
You can’t perform that action at this time.