From 941afad799c155ff44925e935d31b7e9636ad0cc Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 23 Aug 2023 11:07:01 -1000 Subject: [PATCH 1/5] Provide safer access for filename param if it happens to be missing --- src/libs/ReceiptUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReceiptUtils.js b/src/libs/ReceiptUtils.js index c1c02807369..e9c72249e6a 100644 --- a/src/libs/ReceiptUtils.js +++ b/src/libs/ReceiptUtils.js @@ -34,10 +34,10 @@ function validateReceipt(file) { * Grab the appropriate receipt image and thumbnail URIs based on file type * * @param {String} path URI to image, i.e. blob:new.expensify.com/9ef3a018-4067-47c6-b29f-5f1bd35f213d or expensify.com/receipts/w_e616108497ef940b7210ec6beb5a462d01a878f4.jpg - * @param {String} filename of uploaded image or last part of remote URI + * @param {String} [filename] of uploaded image or last part of remote URI * @returns {Object} */ -function getThumbnailAndImageURIs(path, filename) { +function getThumbnailAndImageURIs(path, filename = '') { // For local files, we won't have a thumbnail yet if (path.startsWith('blob:') || path.startsWith('file:')) { return {thumbnail: null, image: path}; From 27cdd5846a33bb5cb02f01c258557aa142f2ea27 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 23 Aug 2023 11:21:53 -1000 Subject: [PATCH 2/5] Show generic receipt image when there is no receipt --- src/libs/ReceiptUtils.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/ReceiptUtils.js b/src/libs/ReceiptUtils.js index e9c72249e6a..38625adada3 100644 --- a/src/libs/ReceiptUtils.js +++ b/src/libs/ReceiptUtils.js @@ -38,6 +38,11 @@ function validateReceipt(file) { * @returns {Object} */ function getThumbnailAndImageURIs(path, filename = '') { + // For things that don't actually have files we will show the generic receipt icon. + if (!filename) { + return {thumbnail: null, image: ReceiptGeneric}; + } + // For local files, we won't have a thumbnail yet if (path.startsWith('blob:') || path.startsWith('file:')) { return {thumbnail: null, image: path}; From 548683163ab249f6aacc567fe736f662c5b32552 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 23 Aug 2023 11:37:20 -1000 Subject: [PATCH 3/5] Only show receipt images for receipts that have receiptID --- src/libs/ReceiptUtils.js | 9 ++------- src/libs/TransactionUtils.js | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/libs/ReceiptUtils.js b/src/libs/ReceiptUtils.js index 38625adada3..c1c02807369 100644 --- a/src/libs/ReceiptUtils.js +++ b/src/libs/ReceiptUtils.js @@ -34,15 +34,10 @@ function validateReceipt(file) { * Grab the appropriate receipt image and thumbnail URIs based on file type * * @param {String} path URI to image, i.e. blob:new.expensify.com/9ef3a018-4067-47c6-b29f-5f1bd35f213d or expensify.com/receipts/w_e616108497ef940b7210ec6beb5a462d01a878f4.jpg - * @param {String} [filename] of uploaded image or last part of remote URI + * @param {String} filename of uploaded image or last part of remote URI * @returns {Object} */ -function getThumbnailAndImageURIs(path, filename = '') { - // For things that don't actually have files we will show the generic receipt icon. - if (!filename) { - return {thumbnail: null, image: ReceiptGeneric}; - } - +function getThumbnailAndImageURIs(path, filename) { // For local files, we won't have a thumbnail yet if (path.startsWith('blob:') || path.startsWith('file:')) { return {thumbnail: null, image: path}; diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index 9656e03f436..83e5650c393 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -79,7 +79,7 @@ function buildOptimisticTransaction( * @returns {Boolean} */ function hasReceipt(transaction) { - return !_.isEmpty(lodashGet(transaction, 'receipt')); + return Boolean(lodashGet(transaction, 'receipt.receiptID')); } /** From 12890a90c36a8011b19a52f369b4c29f2940ab05 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 23 Aug 2023 11:51:36 -1000 Subject: [PATCH 4/5] All receipts will have a source property so we will use this to tell if a transaction has a receipt --- src/libs/TransactionUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index 83e5650c393..9c7685417c4 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -79,7 +79,7 @@ function buildOptimisticTransaction( * @returns {Boolean} */ function hasReceipt(transaction) { - return Boolean(lodashGet(transaction, 'receipt.receiptID')); + return Boolean(lodashGet(transaction, 'receipt.source')); } /** From a5c4deae73b037781dd8ea7c08937b420fcd69ef Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 23 Aug 2023 12:43:02 -1000 Subject: [PATCH 5/5] use state --- src/libs/TransactionUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/TransactionUtils.js b/src/libs/TransactionUtils.js index 9c7685417c4..b72c6e03217 100644 --- a/src/libs/TransactionUtils.js +++ b/src/libs/TransactionUtils.js @@ -79,7 +79,7 @@ function buildOptimisticTransaction( * @returns {Boolean} */ function hasReceipt(transaction) { - return Boolean(lodashGet(transaction, 'receipt.source')); + return lodashGet(transaction, 'receipt.state', '') !== ''; } /**