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

ENS avatar don't reset after disconnecting the wallet #223

Merged
Merged
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
9 changes: 8 additions & 1 deletion components/01-atoms/DisconnectWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import { PowerIcon } from "@/components/01-atoms";
import { PowerIcon, SwapContext } from "@/components/01-atoms";
import { useSidebar } from "@/lib/client/contexts/SidebarContext.tsx";
import { useAuthenticatedUser } from "@/lib/client/hooks/useAuthenticatedUser";
import { useDisconnect } from "wagmi";
import cc from "classcat";
import { useTheme } from "next-themes";
import { useContext } from "react";

export const DisconnectWallet = () => {
const { disconnect } = useDisconnect();
const { systemTheme, theme } = useTheme();
const currentTheme = theme === "system" ? systemTheme : theme;
const isDark = currentTheme === "dark";
const { toggleSidebar } = useSidebar();
const { authenticatedUserAddress } = useAuthenticatedUser();

const { validateAddressToSwap, setInputAddress } = useContext(SwapContext);

const handleClick = () => {
setInputAddress("");
validateAddressToSwap(authenticatedUserAddress, null);
toggleSidebar();
disconnect();
};
Expand Down
5 changes: 3 additions & 2 deletions components/01-atoms/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ export const SearchBar = () => {
name="search"
type="search"
className={cc([
`h-11 w-full border-gray-100 focus:ring-0 focus:ring-transparent focus:outline-none focus-visible:border-gray-300 placeholder:p-small text-ellipsis bg-inherit
border-none dark:border-none bg-transparent dark:bg-transparent contrast-50`,
`h-11 w-full border-gray-100 focus:ring-0 focus:ring-transparent focus:outline-none focus-visible:border-gray-300 placeholder:p-small text-ellipsis
border-none bg-transparent dark:border-none dark:bg-transparent contrast-50`,
])}
placeholder="Search username, address or ENS"
value={inputAddress}
onChange={({ target }) => setInputAddress(target.value)}
/>
</div>
Expand Down
13 changes: 3 additions & 10 deletions components/03-organisms/SwappingShelfs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const SwappingShelfs = () => {
useState<SwappingShelfID>(SwappingShelfID.THEIR_ITEMS);

const {
validatedAddressToSwap,
setAuthenticatedUserTokensList,
setSearchedUserTokensList,
setInputAddress,
Expand All @@ -35,7 +34,7 @@ export const SwappingShelfs = () => {
setAuthenticatedUserTokensList([]);
setSearchedUserTokensList([]);
setInputAddress("");
}, [chain]);
}, [chain, authenticatedUserAddress]);

return (
<div className="w-full h-full dark:bg-[#212322] dark:border-[#353836] border border-[#D6D5D5] rounded-2xl dark:shadow-swap-station shadow-swap-station-light">
Expand All @@ -53,16 +52,10 @@ export const SwappingShelfs = () => {
</div>
<div className="p-5">
<div className={cc([activeSwappingShelfID ? "hidden" : "block"])}>
<TokensShelf
address={validatedAddressToSwap}
variant={TokensShelfVariant.Their}
/>
<TokensShelf variant={TokensShelfVariant.Their} />
</div>
<div className={cc([activeSwappingShelfID ? "block" : "hidden"])}>
<TokensShelf
address={authenticatedUserAddress}
variant={TokensShelfVariant.Your}
/>
<TokensShelf variant={TokensShelfVariant.Your} />
</div>
</div>
</div>
Expand Down
22 changes: 16 additions & 6 deletions components/03-organisms/TokensShelf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getERC721TokensFromAddress,
getERC20TokensFromAddress,
} from "@/lib/client/blockchain-utils";
import { EthereumAddress, Token } from "@/lib/shared/types";
import { Token } from "@/lib/shared/types";
import { TokensList } from "@/components/02-molecules";
import { SelectUserIcon, SwapContext } from "@/components/01-atoms";
import { useSupportedNetworks } from "@/lib/client/hooks/useSupportedNetworks";
Expand All @@ -19,7 +19,6 @@ export enum TokensShelfVariant {
}

interface TokensShelfProps {
address: EthereumAddress | null;
variant: TokensShelfVariant;
}

Expand All @@ -30,7 +29,7 @@ interface TokensShelfProps {
*
* @returns Tokens Shelf based in status of given address
*/
export const TokensShelf = ({ address, variant }: TokensShelfProps) => {
export const TokensShelf = ({ variant }: TokensShelfProps) => {
const { chain } = useNetwork();
const { isNetworkSupported } = useSupportedNetworks();
const [allTokensList, setAllTokensList] = useState<Token[]>([]);
Expand All @@ -43,6 +42,11 @@ export const TokensShelf = ({ address, variant }: TokensShelfProps) => {
const { validatedAddressToSwap, inputAddress, destinyChain } =
useContext(SwapContext);

const address =
variant === TokensShelfVariant.Their
? validatedAddressToSwap
: authenticatedUserAddress;

const getUserTokens = async () => {
const chainId = authenticatedUserAddress?.equals(address)
? chain?.id
Expand All @@ -51,7 +55,7 @@ export const TokensShelf = ({ address, variant }: TokensShelfProps) => {
let queriedTokens: Token[] = [];
let tokensCount = allTokensList.length;

if (address && chainId) {
if (address && chainId && !!authenticatedUserAddress) {
setTokensQueryStatus(TokensQueryStatus.LOADING);

Promise.all([
Expand Down Expand Up @@ -81,8 +85,14 @@ export const TokensShelf = ({ address, variant }: TokensShelfProps) => {

// will only reload if network isNetworkSupported changes
useEffect(() => {
isNetworkSupported && getUserTokens();
}, [address, isNetworkSupported, destinyChain]);
!!authenticatedUserAddress && isNetworkSupported && getUserTokens();
}, [
address,
isNetworkSupported,
authenticatedUserAddress,
validatedAddressToSwap,
destinyChain,
]);

const conditionallyCleanTokensList = (condition: boolean) => {
if (condition) {
Expand Down