Browse Source

Fix file type detection (application/vnd.ms-excel instead of text/csv)

pull/587/head
Thomas 4 years ago
parent
commit
b17d58931b
  1. 7
      apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts

7
apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts

@ -188,7 +188,7 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
const fileContent = readerEvent.target.result as string; const fileContent = readerEvent.target.result as string;
try { try {
if (file.type === 'application/json') { if (file.name.endsWith('.json')) {
const content = JSON.parse(fileContent); const content = JSON.parse(fileContent);
if (!isArray(content.orders)) { if (!isArray(content.orders)) {
@ -203,11 +203,12 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
this.handleImportSuccess(); this.handleImportSuccess();
} catch (error) { } catch (error) {
console.error(error);
this.handleImportError({ error, orders: content.orders }); this.handleImportError({ error, orders: content.orders });
} }
return; return;
} else if (file.type === 'text/csv') { } else if (file.name.endsWith('.csv')) {
try { try {
await this.importTransactionsService.importCsv({ await this.importTransactionsService.importCsv({
fileContent, fileContent,
@ -217,6 +218,7 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
this.handleImportSuccess(); this.handleImportSuccess();
} catch (error) { } catch (error) {
console.error(error);
this.handleImportError({ this.handleImportError({
error: { error: {
error: { message: error?.error?.message ?? [error?.message] } error: { message: error?.error?.message ?? [error?.message] }
@ -230,6 +232,7 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
throw new Error(); throw new Error();
} catch (error) { } catch (error) {
console.error(error);
this.handleImportError({ this.handleImportError({
error: { error: { message: ['Unexpected format'] } }, error: { error: { message: ['Unexpected format'] } },
orders: [] orders: []

Loading…
Cancel
Save