Skip to content

Commit

Permalink
fix: Fix a update memorized functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Jan 12, 2024
1 parent 4c5b750 commit b32c1ba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const SideMenuContainer: React.FC<SideMenuContainerProps> = ({ open, setOpen })
const close = useCallback(async () => {
setOpen(false);
}, [setOpen]);

const { data: sideMenuAccounts = [] } = useQuery<SideMenuAccountInfo[]>(
['sideMenuAccounts', accountNames, accounts, accountNativeBalances, currentNetwork],
() => {
Expand Down
22 changes: 16 additions & 6 deletions packages/adena-extension/src/hooks/use-current-account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { Account } from 'adena-module';
import { useRecoilState } from 'recoil';
import { useAdenaContext, useWalletContext } from './use-context';
import { useNetwork } from './use-network';
import { useCallback, useEffect, useState } from 'react';
import { useCallback } from 'react';
import { useEvent } from './use-event';
import { EventMessage } from '@inject/message/event-message';
import { useQuery } from '@tanstack/react-query';

export const useCurrentAccount = (): {
currentAccount: Account | null;
Expand All @@ -18,7 +19,6 @@ export const useCurrentAccount = (): {
const { wallet } = useWalletContext();
const { currentNetwork } = useNetwork();
const { dispatchEvent } = useEvent();
const [currentAddress, setCurrentAddress] = useState<string | null>(null);

const getCurrentAddress = useCallback(async (prefix?: string) => {
if (!currentAccount) {
Expand Down Expand Up @@ -48,13 +48,23 @@ export const useCurrentAccount = (): {
[currentNetwork],
);

useEffect(() => {
getCurrentAddress(currentNetwork.addressPrefix).then(setCurrentAddress);
}, [getCurrentAddress, currentNetwork]);
const { data: currentAddress } = useQuery<string | null>(
['sideMenuAccounts', currentAccount, currentNetwork],
async () => {
if (!currentAccount) {
return null;
}
const address = await currentAccount.getAddress(currentNetwork.addressPrefix ?? 'g');
return address;
},
{
enabled: currentAccount !== null,
},
);

return {
currentAccount,
currentAddress,
currentAddress: currentAddress || null,
getCurrentAddress,
changeCurrentAccount,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const TransferSummaryContainer: React.FC = () => {

const { signed } = await transactionService.createTransaction(wallet, document);
return transactionService.sendTransaction(wallet, currentAccount, signed);
}, [summaryInfo, currentAccount, currentAccount]);
}, [summaryInfo, currentAccount, currentNetwork]);

const hasNetworkFee = useCallback(async () => {
if (!gnoProvider || !currentAddress) {
Expand Down Expand Up @@ -126,7 +126,7 @@ const TransferSummaryContainer: React.FC = () => {
return transferByLedger();
}
return transferByCommon();
}, [summaryInfo, currentAccount, currentAccount, isSent]);
}, [summaryInfo, currentAccount, isSent, hasNetworkFee]);

const transferByCommon = useCallback(async () => {
try {
Expand All @@ -139,23 +139,23 @@ const TransferSummaryContainer: React.FC = () => {
}
setIsSent(false);
return false;
}, [summaryInfo, currentAccount, currentAccount, isSent]);
}, [summaryInfo, currentAccount, isSent, hasNetworkFee]);

const transferByLedger = useCallback(async () => {
const document = await createDocument();
if (document) {
navigate(RoutePath.TransferLedgerLoading, { state: { document } });
}
return true;
}, [summaryInfo, currentAccount, currentAccount, isSent]);
}, [summaryInfo, currentAccount, isSent, hasNetworkFee]);

const onClickCancel = useCallback(() => {
if (summaryInfo.isTokenSearch === true) {
navigate(RoutePath.Wallet);
return;
}
normalNavigate(-2);
}, []);
}, [summaryInfo, navigate]);

return (
<TransferSummaryLayout>
Expand Down

0 comments on commit b32c1ba

Please sign in to comment.