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

✨ Add check connected address button to searchbar #247

Merged
merged 2 commits into from
Dec 6, 2024
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
Original file line number Diff line number Diff line change
@@ -1,28 +1,62 @@
'use client';

import AddressSearchBox from 'components/common/AddressSearchBox';
import Button from 'components/common/Button';
import { useCsrRouter } from 'lib/i18n/csr-navigation';
import { NextPage } from 'next';
import { useState } from 'react';
import { useTranslations } from 'next-intl';
import { useRef, useState } from 'react';
import { twMerge } from 'tailwind-merge';
import { useAccount } from 'wagmi';

interface Props {
chainId: number;
placeholder: string;
}

const TokenApprovalCheckerSearchBox: NextPage<Props> = ({ chainId, placeholder }) => {
const t = useTranslations();
const router = useCsrRouter();
const [value, setValue] = useState<string>('');

const [isFocused, setIsFocused] = useState<boolean>(false);
const { address } = useAccount();
const timerRef = useRef<NodeJS.Timeout>();

const onFocus = () => {
clearTimeout(timerRef.current);
setIsFocused(true);
};

const onBlur = () => {
timerRef.current = setTimeout(() => setIsFocused(false), 200);
};

const onClick = () => {
if (address) {
setValue(address);
router.push(`/address/${address}`, { retainSearchParams: ['chainId'] });
}
};

return (
<AddressSearchBox
id="tac-search"
onSubmit={() => router.push(`/address/${value}?chainId=${chainId}`)}
onChange={(ev) => setValue(ev.target.value.trim())}
value={value}
placeholder={placeholder}
className="w-full max-w-3xl text-base sm:text-lg"
/>
<div className="relative w-full max-w-3xl">
<AddressSearchBox
id="tac-search"
onSubmit={() => router.push(`/address/${value}?chainId=${chainId}`)}
onChange={(ev) => setValue(ev.target.value.trim())}
value={value}
placeholder={placeholder}
className="w-full text-base sm:text-lg"
onFocus={onFocus}
onBlur={onBlur}
/>
<div className={twMerge('absolute mt-2', (!isFocused || !address) && 'hidden')}>
<Button style="secondary" size="md" onClick={onClick}>
{t('common.buttons.check_connected_address')}
</Button>
</div>
</div>
);
};

Expand Down
49 changes: 40 additions & 9 deletions components/header/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,55 @@
'use client';

import AddressSearchBox from 'components/common/AddressSearchBox';
import Button from 'components/common/Button';
import { useCsrRouter } from 'lib/i18n/csr-navigation';
import { useTranslations } from 'next-intl';
import { useState } from 'react';
import { useRef, useState } from 'react';
import { twMerge } from 'tailwind-merge';
import { useAccount } from 'wagmi';

const SearchBar = () => {
const t = useTranslations();
const router = useCsrRouter();
const [value, setValue] = useState<string>('');
const [isFocused, setIsFocused] = useState<boolean>(false);
const { address } = useAccount();
const timerRef = useRef<NodeJS.Timeout>();

const onFocus = () => {
clearTimeout(timerRef.current);
setIsFocused(true);
};

const onBlur = () => {
timerRef.current = setTimeout(() => setIsFocused(false), 200);
};

const onClick = () => {
if (address) {
setValue(address);
router.push(`/address/${address}`, { retainSearchParams: ['chainId'] });
}
};

return (
<AddressSearchBox
id="global-search"
onSubmit={() => router.push(`/address/${value}`, { retainSearchParams: ['chainId'] })}
onChange={(ev) => setValue(ev.target.value.trim())}
value={value}
placeholder={t('common.nav.search')}
className="w-full text-base sm:text-lg border-x-0 rounded-none border-zinc-400 dark:border-zinc-600 py-6 focus-within:ring-0 focus-within:border-black dark:focus-within:border-white"
/>
<div className="relative w-full">
<AddressSearchBox
id="global-search"
onSubmit={() => router.push(`/address/${value}`, { retainSearchParams: ['chainId'] })}
onChange={(ev) => setValue(ev.target.value.trim())}
value={value}
placeholder={t('common.nav.search')}
className="w-full text-base sm:text-lg border-x-0 rounded-none border-zinc-400 dark:border-zinc-600 py-6 focus-within:ring-0 focus-within:border-black dark:focus-within:border-white"
onFocus={onFocus}
onBlur={onBlur}
/>
<div className={twMerge('absolute mt-2', (!isFocused || !address) && 'hidden')}>
<Button style="secondary" size="md" onClick={onClick}>
{t('common.buttons.check_connected_address')}
</Button>
</div>
</div>
);
};

Expand Down
Loading