Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions components/BankCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import React from 'react'
import Copy from './Copy'

const BankCard = ({ account, userName, showBalance = true }: CreditCardProps) => {

console.log(account);
return (
<div className="flex flex-col">
<Link href={`/transaction-history/?id=${account.appwriteItemId}`} className="bank-card">
Expand Down Expand Up @@ -60,7 +58,7 @@ const BankCard = ({ account, userName, showBalance = true }: CreditCardProps) =>
/>
</Link>

{showBalance && <Copy title={account?.sharaebleId} />}
{showBalance && <Copy title={account?.shareableId} />}
</div>
)
}
Expand Down
4 changes: 2 additions & 2 deletions components/BankDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export const BankDropdown = ({
}: BankDropdownProps) => {
const searchParams = useSearchParams();
const router = useRouter();
const [selected, setSeclected] = useState(accounts[0]);
const [selected, setSelected] = useState(accounts[0]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Handle empty accounts in initial state

If accounts is empty, useState(accounts[0]) will set undefined and subsequent selected.name access will throw. Default to null or the first account if present.

-  const [selected, setSelected] = useState(accounts[0]);
+  const [selected, setSelected] = useState<Account | null>(accounts[0] ?? null);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const [selected, setSelected] = useState(accounts[0]);
const [selected, setSelected] = useState<Account | null>(accounts[0] ?? null);
🤖 Prompt for AI Agents
In components/BankDropdown.tsx around line 24, the initial useState(accounts[0])
can be undefined when accounts is empty; change the initializer to
accounts.length > 0 ? accounts[0] : null, update the state type to allow null,
and add guards (or optional chaining) wherever selected is used (e.g.,
selected?.name) so the component handles an empty accounts array safely.


const handleBankChange = (id: string) => {
const account = accounts.find((account) => account.appwriteItemId === id)!;

setSeclected(account);
setSelected(account);
const newUrl = formUrlQuery({
params: searchParams.toString(),
key: "id",
Expand Down
4 changes: 2 additions & 2 deletions components/MobileNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const MobileNav = ({ user }: MobileNavProps) => {
const pathname = usePathname();

return (
<section className="w-fulll max-w-[264px]">
<section className="w-full max-w-[264px]">
<Sheet>
<SheetTrigger>
<Image
Expand Down Expand Up @@ -69,7 +69,7 @@ const MobileNav = ({ user }: MobileNavProps) => {
)
})}

USER

</nav>
</SheetClose>

Expand Down
2 changes: 1 addition & 1 deletion components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { usePathname } from 'next/navigation'
import Footer from './Footer'
import PlaidLink from './PlaidLink'

const Sidebar = ({ user }: SiderbarProps) => {
const Sidebar = ({ user }: SidebarProps) => {
const pathname = usePathname();

return (
Expand Down
10 changes: 5 additions & 5 deletions lib/actions/bank.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const getAccounts = async ({ userId }: getAccountsProps) => {
type: accountData.type as string,
subtype: accountData.subtype! as string,
appwriteItemId: bank.$id,
sharaebleId: bank.shareableId,
shareableId: bank.shareableId,
};

return account;
Expand Down Expand Up @@ -138,9 +138,9 @@ export const getInstitution = async ({
country_codes: ["US"] as CountryCode[],
});

const intitution = institutionResponse.data.institution;
const institution = institutionResponse.data.institution;

return parseStringify(intitution);
return parseStringify(institution);
} catch (error) {
console.error("An error occurred while getting the accounts:", error);
}
Expand All @@ -162,7 +162,7 @@ export const getTransactions = async ({

const data = response.data;

transactions = response.data.added.map((transaction) => ({
transactions.push(...response.data.added.map((transaction) => ({
id: transaction.transaction_id,
name: transaction.name,
paymentChannel: transaction.payment_channel,
Expand All @@ -173,7 +173,7 @@ export const getTransactions = async ({
category: transaction.category ? transaction.category[0] : "",
date: transaction.date,
image: transaction.logo_url,
}));
})));

hasMore = data.has_more;
}
Expand Down