From 19a8f14ad9abd970b148dc9471aff16174db2edf Mon Sep 17 00:00:00 2001
From: biohzrddd <biohzrd@gmail.com>
Date: Sun, 16 Apr 2023 12:36:22 +0100
Subject: [PATCH] Fixes Issue 495 Transfer allowed from same account (#902)

---
 .../src/components/accounts/TransactionsTable.js           | 5 +++++
 .../src/components/autocomplete/NewPayeeAutocomplete.js    | 7 ++-----
 upcoming-release-notes/902.md                              | 6 ++++++
 3 files changed, 13 insertions(+), 5 deletions(-)
 create mode 100644 upcoming-release-notes/902.md

diff --git a/packages/desktop-client/src/components/accounts/TransactionsTable.js b/packages/desktop-client/src/components/accounts/TransactionsTable.js
index 37f520618..81b92b7f0 100644
--- a/packages/desktop-client/src/components/accounts/TransactionsTable.js
+++ b/packages/desktop-client/src/components/accounts/TransactionsTable.js
@@ -379,6 +379,7 @@ function StatusCell({
 function PayeeCell({
   id,
   payeeId,
+  accountId,
   focused,
   inherited,
   payees,
@@ -396,6 +397,9 @@ function PayeeCell({
   const isNewAutocompleteEnabled = useFeatureFlag('newAutocomplete');
   let isCreatingPayee = useRef(false);
 
+  // Filter out the account we're currently in as it is not a valid transfer
+  accounts = accounts.filter(account => account.id !== accountId);
+
   return (
     <CustomCell
       width="flex"
@@ -786,6 +790,7 @@ export const Transaction = React.memo(function Transaction(props) {
           <PayeeCell
             id={id}
             payeeId={payeeId}
+            accountId={accountId}
             focused={focusedField === 'payee'}
             inherited={inheritedFields && inheritedFields.has('payee')}
             payees={payees}
diff --git a/packages/desktop-client/src/components/autocomplete/NewPayeeAutocomplete.js b/packages/desktop-client/src/components/autocomplete/NewPayeeAutocomplete.js
index 888217e6c..6c4f31c8c 100644
--- a/packages/desktop-client/src/components/autocomplete/NewPayeeAutocomplete.js
+++ b/packages/desktop-client/src/components/autocomplete/NewPayeeAutocomplete.js
@@ -3,8 +3,6 @@ import { useDispatch } from 'react-redux';
 import { components as SelectComponents } from 'react-select';
 
 import { createPayee } from 'loot-core/src/client/actions/queries';
-import { useCachedAccounts } from 'loot-core/src/client/data-hooks/accounts';
-import { useCachedPayees } from 'loot-core/src/client/data-hooks/payees';
 import { getActivePayees } from 'loot-core/src/client/reducers/queries';
 
 import Add from '../../icons/v1/Add';
@@ -51,6 +49,8 @@ function MenuListWithFooter(props) {
 }
 
 export default function PayeeAutocomplete({
+  payees,
+  accounts,
   value,
   multi = false,
   showMakeTransfer = true,
@@ -60,9 +60,6 @@ export default function PayeeAutocomplete({
   onManagePayees,
   ...props
 }) {
-  const payees = useCachedPayees();
-  const accounts = useCachedAccounts();
-
   const [focusTransferPayees, setFocusTransferPayees] = useState(
     defaultFocusTransferPayees,
   );
diff --git a/upcoming-release-notes/902.md b/upcoming-release-notes/902.md
new file mode 100644
index 000000000..ff004d0a4
--- /dev/null
+++ b/upcoming-release-notes/902.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [biohzrddd]
+---
+
+Remove currently viewed account from list of possible transfer accounts
-- 
GitLab