From e4c2e85d89897f3b95e3784ad22bfe6d4c2f22ca Mon Sep 17 00:00:00 2001 From: im-adithya Date: Wed, 25 Sep 2024 09:27:56 +0530 Subject: [PATCH 1/2] fix: reload balances, txs and channels after transfer is complete --- frontend/src/components/TransferFundsButton.tsx | 6 +++--- frontend/src/screens/channels/Channels.tsx | 10 +++++++--- frontend/src/screens/wallet/index.tsx | 10 ++++++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/TransferFundsButton.tsx b/frontend/src/components/TransferFundsButton.tsx index 91b24902..38f44953 100644 --- a/frontend/src/components/TransferFundsButton.tsx +++ b/frontend/src/components/TransferFundsButton.tsx @@ -7,13 +7,13 @@ import { request } from "src/utils/request"; type TransferFundsButtonProps = { channels: Channel[] | undefined; albyBalance: AlbyBalance; - reloadAlbyBalance: () => void; + onTransferComplete: () => Promise; } & ButtonProps; export function TransferFundsButton({ channels, albyBalance, - reloadAlbyBalance, + onTransferComplete, children, ...props }: TransferFundsButtonProps) { @@ -46,7 +46,7 @@ export function TransferFundsButton({ "Content-Type": "application/json", }, }); - await reloadAlbyBalance(); + await onTransferComplete(); toast({ title: "🎉 Funds from Alby shared wallet transferred to your Alby Hub!", diff --git a/frontend/src/screens/channels/Channels.tsx b/frontend/src/screens/channels/Channels.tsx index 8c381dbd..c5f725c2 100644 --- a/frontend/src/screens/channels/Channels.tsx +++ b/frontend/src/screens/channels/Channels.tsx @@ -67,9 +67,9 @@ import { request } from "src/utils/request"; export default function Channels() { useSyncWallet(); - const { data: channels } = useChannels(); + const { data: channels, mutate: reloadChannels } = useChannels(); const { data: nodeConnectionInfo } = useNodeConnectionInfo(); - const { data: balances } = useBalances(); + const { data: balances, mutate: reloadBalances } = useBalances(); const { data: albyBalance, mutate: reloadAlbyBalance } = useAlbyBalance(); const navigate = useNavigate(); const [nodes, setNodes] = React.useState([]); @@ -270,7 +270,11 @@ export default function Channels() { variant="outline" channels={channels} albyBalance={albyBalance} - reloadAlbyBalance={reloadAlbyBalance} + onTransferComplete={async () => { + await reloadAlbyBalance(); + await reloadBalances(); + await reloadChannels(); + }} > Migrate diff --git a/frontend/src/screens/wallet/index.tsx b/frontend/src/screens/wallet/index.tsx index 46d4b83d..c2eab816 100644 --- a/frontend/src/screens/wallet/index.tsx +++ b/frontend/src/screens/wallet/index.tsx @@ -23,12 +23,14 @@ import { useAlbyBalance } from "src/hooks/useAlbyBalance"; import { useBalances } from "src/hooks/useBalances"; import { useChannels } from "src/hooks/useChannels"; import { useInfo } from "src/hooks/useInfo"; +import { useTransactions } from "src/hooks/useTransactions"; function Wallet() { const { data: info, hasChannelManagement } = useInfo(); - const { data: balances } = useBalances(); + const { data: balances, mutate: reloadBalances } = useBalances(); const { data: channels } = useChannels(); const { data: albyBalance, mutate: reloadAlbyBalance } = useAlbyBalance(); + const { mutate: reloadTransactions } = useTransactions(); if (!info || !balances) { return ; @@ -61,7 +63,11 @@ function Wallet() { { + await reloadAlbyBalance(); + await reloadBalances(); + await reloadTransactions(); + }} > Migrate Funds From 5ffded0393ba173bf831798e1d221eb8ffa68d97 Mon Sep 17 00:00:00 2001 From: im-adithya Date: Wed, 25 Sep 2024 11:39:11 +0530 Subject: [PATCH 2/2] chore: use promise all --- frontend/src/components/TransferFundsButton.tsx | 2 +- frontend/src/screens/channels/Channels.tsx | 12 +++++++----- frontend/src/screens/wallet/index.tsx | 12 +++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/TransferFundsButton.tsx b/frontend/src/components/TransferFundsButton.tsx index 38f44953..4076fd16 100644 --- a/frontend/src/components/TransferFundsButton.tsx +++ b/frontend/src/components/TransferFundsButton.tsx @@ -7,7 +7,7 @@ import { request } from "src/utils/request"; type TransferFundsButtonProps = { channels: Channel[] | undefined; albyBalance: AlbyBalance; - onTransferComplete: () => Promise; + onTransferComplete: () => Promise; } & ButtonProps; export function TransferFundsButton({ diff --git a/frontend/src/screens/channels/Channels.tsx b/frontend/src/screens/channels/Channels.tsx index c5f725c2..24554225 100644 --- a/frontend/src/screens/channels/Channels.tsx +++ b/frontend/src/screens/channels/Channels.tsx @@ -270,11 +270,13 @@ export default function Channels() { variant="outline" channels={channels} albyBalance={albyBalance} - onTransferComplete={async () => { - await reloadAlbyBalance(); - await reloadBalances(); - await reloadChannels(); - }} + onTransferComplete={() => + Promise.all([ + reloadAlbyBalance(), + reloadBalances(), + reloadChannels(), + ]) + } > Migrate diff --git a/frontend/src/screens/wallet/index.tsx b/frontend/src/screens/wallet/index.tsx index c2eab816..a43b07c0 100644 --- a/frontend/src/screens/wallet/index.tsx +++ b/frontend/src/screens/wallet/index.tsx @@ -63,11 +63,13 @@ function Wallet() { { - await reloadAlbyBalance(); - await reloadBalances(); - await reloadTransactions(); - }} + onTransferComplete={() => + Promise.all([ + reloadAlbyBalance(), + reloadBalances(), + reloadTransactions(), + ]) + } > Migrate Funds