Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only use 1 source wallet | memoize components that call balances #255

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 7 additions & 19 deletions components/bank/components/sendBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import IbcSendForm from '../forms/ibcSendForm';
import env from '@/config/env';
import { CombinedBalanceInfo } from '@/utils/types';
import { ChainContext } from '@cosmos-kit/core';
import React from 'react';

export interface IbcChain {
id: string;
Expand All @@ -13,7 +14,7 @@ export interface IbcChain {
chainID: string;
}

export default function SendBox({
export default React.memo(function SendBox({
address,
balances,
isBalancesLoading,
Expand All @@ -23,11 +24,6 @@ export default function SendBox({
isGroup,
admin,
refetchProposals,
osmosisBalances,
isOsmosisBalancesLoading,
refetchOsmosisBalances,
resolveOsmosisRefetch,
chains,
}: {
address: string;
balances: CombinedBalanceInfo[];
Expand All @@ -38,11 +34,6 @@ export default function SendBox({
selectedDenom?: string;
isGroup?: boolean;
admin?: string;
osmosisBalances: CombinedBalanceInfo[];
isOsmosisBalancesLoading: boolean;
refetchOsmosisBalances: () => void;
resolveOsmosisRefetch: () => void;
chains: Record<string, ChainContext>;
}) {
const ibcChains = useMemo<IbcChain[]>(
() => [
Expand Down Expand Up @@ -74,6 +65,8 @@ export default function SendBox({
const [selectedFromChain, setSelectedFromChain] = useState<IbcChain>(ibcChains[0]);
const [selectedToChain, setSelectedToChain] = useState<IbcChain>(ibcChains[1]);

const memoizedBalances = useMemo(() => balances, [balances]);

useEffect(() => {
if (selectedFromChain && selectedToChain && selectedFromChain.id === selectedToChain.id) {
// If chains match, switch the destination chain to the other available chain
Expand Down Expand Up @@ -132,25 +125,20 @@ export default function SendBox({
setSelectedToChain={setSelectedToChain}
address={address}
destinationChain={selectedToChain}
balances={balances}
balances={memoizedBalances}
isBalancesLoading={isBalancesLoading}
refetchBalances={refetchBalances}
refetchHistory={refetchHistory}
selectedDenom={selectedDenom}
osmosisBalances={osmosisBalances}
isGroup={isGroup}
admin={admin}
refetchProposals={refetchProposals}
isOsmosisBalancesLoading={isOsmosisBalancesLoading}
refetchOsmosisBalances={refetchOsmosisBalances}
resolveOsmosisRefetch={resolveOsmosisRefetch}
availableToChains={getAvailableToChains}
chains={chains}
/>
) : (
<SendForm
address={address}
balances={balances}
balances={memoizedBalances}
isBalancesLoading={isBalancesLoading}
refetchBalances={refetchBalances}
refetchHistory={refetchHistory}
Expand All @@ -165,4 +153,4 @@ export default function SendBox({
</div>
</div>
);
}
});
23 changes: 5 additions & 18 deletions components/bank/components/tokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@ interface TokenListProps {
admin?: string;
refetchProposals?: () => void;
searchTerm?: string;
osmosisBalances?: CombinedBalanceInfo[] | undefined;
isOsmosisBalancesLoading?: boolean;
refetchOsmosisBalances?: () => void;
resolveOsmosisRefetch?: () => void;
chains: Record<string, ChainContext>;
}

export function TokenList(props: Readonly<TokenListProps>) {
export const TokenList = React.memo(function TokenList(props: Readonly<TokenListProps>) {
const {
balances,
isLoading,
Expand All @@ -36,11 +31,6 @@ export function TokenList(props: Readonly<TokenListProps>) {
admin,
refetchProposals,
searchTerm = '',
osmosisBalances,
isOsmosisBalancesLoading,
refetchOsmosisBalances,
resolveOsmosisRefetch,
chains,
} = props;
const [selectedDenom, setSelectedDenom] = useState<any>(null);
const [isSendModalOpen, setIsSendModalOpen] = useState(false);
Expand Down Expand Up @@ -91,6 +81,8 @@ export function TokenList(props: Readonly<TokenListProps>) {
[totalPages]
);

const memoizedBalances = useMemo(() => props.balances ?? [], [props.balances]);

return (
<div className="w-full mx-auto rounded-[24px] h-full flex flex-col">
<div className="flex-1 overflow-y-auto">
Expand Down Expand Up @@ -228,7 +220,7 @@ export function TokenList(props: Readonly<TokenListProps>) {
modalId="send-modal"
isOpen={isSendModalOpen}
address={address}
balances={balances ?? []}
balances={memoizedBalances}
isBalancesLoading={isLoading}
refetchBalances={refetchBalances}
refetchHistory={refetchHistory}
Expand All @@ -237,12 +229,7 @@ export function TokenList(props: Readonly<TokenListProps>) {
isGroup={isGroup}
admin={admin}
refetchProposals={refetchProposals}
osmosisBalances={osmosisBalances ?? []}
isOsmosisBalancesLoading={isOsmosisBalancesLoading ?? false}
refetchOsmosisBalances={refetchOsmosisBalances ?? (() => {})}
resolveOsmosisRefetch={resolveOsmosisRefetch ?? (() => {})}
chains={chains}
/>
</div>
);
}
});
Loading
Loading