From 92ed8b35cb227bf27d61376483785c40fa6792f0 Mon Sep 17 00:00:00 2001 From: sKiLdUsT Date: Wed, 28 Oct 2020 15:17:03 +0100 Subject: [PATCH] fix: Cannot read property 'amount_inquired' of null #585 --- .../ListItems/BunqMeTabListItem.jsx | 28 +++++++++++++------ src/react/Locales/de.json | 3 +- src/react/Locales/en.json | 3 +- src/react/Locales/nl.json | 3 +- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/react/Components/ListItems/BunqMeTabListItem.jsx b/src/react/Components/ListItems/BunqMeTabListItem.jsx index 9d1ce9f0..40c41b12 100644 --- a/src/react/Components/ListItems/BunqMeTabListItem.jsx +++ b/src/react/Components/ListItems/BunqMeTabListItem.jsx @@ -99,13 +99,20 @@ class BunqMeTabListItem extends React.Component { }, 0); // format the amounts - const formattedInquiredAmount = formatMoney(bunqMeTab.bunqme_tab_entry.amount_inquired.value); - const formattedTotalPaid = formatMoney(totalPaidAmount); - - const merchantList = bunqMeTab.bunqme_tab_entry.merchant_available - .filter(merchant => merchant.available) - .map(merchant => merchant.merchant_type) - .join(", "); + // fill with empty values first + let formattedInquiredAmount = formatMoney(0.00); + let formattedTotalPaid = formatMoney(0.00); + let merchantList = []; + + // only fill real values if tab isn't canceled, will crash otherwise + if (bunqMeTab.status !== 'CANCELLED' && bunqMeTab.bunqme_tab_entry !== null) { + formattedInquiredAmount = formatMoney(bunqMeTab.bunqme_tab_entry.amount_inquired.value); + formattedTotalPaid = formatMoney(totalPaidAmount); + merchantList = bunqMeTab.bunqme_tab_entry.merchant_available + .filter(merchant => merchant.available) + .map(merchant => merchant.merchant_type) + .join(", "); + } const avatarStandalone = ( @@ -126,6 +133,11 @@ class BunqMeTabListItem extends React.Component { ); + const primaryText = + bunqMeTab.bunqme_tab_entry !== null + ? bunqMeTab.bunqme_tab_entry.description + : t("Cancelled payment request") + const secondaryText = bunqMeTabPayments.length > 0 ? `${t("Received")}: ${formattedTotalPaid}` @@ -134,7 +146,7 @@ class BunqMeTabListItem extends React.Component { return [ {itemAvatar} - + diff --git a/src/react/Locales/de.json b/src/react/Locales/de.json index b4507eca..6ac1ecb3 100644 --- a/src/react/Locales/de.json +++ b/src/react/Locales/de.json @@ -65,6 +65,7 @@ "Cancel editing": "Bearbeitung abbrechen", "Cancel request": "Anfrage abbrechen", "Cancelled": "Abgebrochen", + "Cancelled payment request": "Abgebrochene Zahlungsanfrage", "Capslock active": "Feststelltaste aktiviert", "Card": "Karte", "Card filter": "Kartenfilter", @@ -695,4 +696,4 @@ "weeks": "Wochen", "year": "Jahr", "years": "Jahre" -} \ No newline at end of file +} diff --git a/src/react/Locales/en.json b/src/react/Locales/en.json index d42e88fb..427546c6 100644 --- a/src/react/Locales/en.json +++ b/src/react/Locales/en.json @@ -65,6 +65,7 @@ "Cancel editing": "Cancel editing", "Cancel request": "Cancel request", "Cancelled": "Cancelled", + "Cancelled payment request": "Cancelled payment request", "Capslock active": "Capslock active", "Card": "Card", "Card filter": "Card filter", @@ -698,4 +699,4 @@ "weeks": "weeks", "year": "year", "years": "years" -} \ No newline at end of file +} diff --git a/src/react/Locales/nl.json b/src/react/Locales/nl.json index f5340f39..6c188c36 100644 --- a/src/react/Locales/nl.json +++ b/src/react/Locales/nl.json @@ -63,6 +63,7 @@ "Cancel editing": "Bewerken annuleren", "Cancel request": "Verzoek annuleren", "Cancelled": "Geannuleerd", + "Cancelled payment request": "Geannuleerd Betalingsverzoek", "Capslock active": "Capslock actief", "Card": "Pas", "Card filter": "Passen", @@ -687,4 +688,4 @@ "weeks": "weken", "year": "jaar", "years": "jaren" -} \ No newline at end of file +}