Skip to content

Commit

Permalink
fix: reload balances, txs and channels after transfer is complete (#706)
Browse files Browse the repository at this point in the history
* fix: reload balances, txs and channels after transfer is complete

* chore: use promise all
  • Loading branch information
im-adithya authored Sep 25, 2024
1 parent 8ebb4ad commit 4f263ee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
6 changes: 3 additions & 3 deletions frontend/src/components/TransferFundsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { request } from "src/utils/request";
type TransferFundsButtonProps = {
channels: Channel[] | undefined;
albyBalance: AlbyBalance;
reloadAlbyBalance: () => void;
onTransferComplete: () => Promise<unknown>;
} & ButtonProps;

export function TransferFundsButton({
channels,
albyBalance,
reloadAlbyBalance,
onTransferComplete,
children,
...props
}: TransferFundsButtonProps) {
Expand Down Expand Up @@ -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!",
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/screens/channels/Channels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node[]>([]);
Expand Down Expand Up @@ -270,7 +270,13 @@ export default function Channels() {
variant="outline"
channels={channels}
albyBalance={albyBalance}
reloadAlbyBalance={reloadAlbyBalance}
onTransferComplete={() =>
Promise.all([
reloadAlbyBalance(),
reloadBalances(),
reloadChannels(),
])
}
>
Migrate
</TransferFundsButton>
Expand Down
12 changes: 10 additions & 2 deletions frontend/src/screens/wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Loading />;
Expand Down Expand Up @@ -61,7 +63,13 @@ function Wallet() {
<TransferFundsButton
channels={channels}
albyBalance={albyBalance}
reloadAlbyBalance={reloadAlbyBalance}
onTransferComplete={() =>
Promise.all([
reloadAlbyBalance(),
reloadBalances(),
reloadTransactions(),
])
}
>
Migrate Funds
</TransferFundsButton>
Expand Down

0 comments on commit 4f263ee

Please sign in to comment.