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

2x weekly promotion of develop to main #1327

Merged
merged 16 commits into from
Oct 16, 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
Binary file added src/assets/images/wallets/fastAuth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/components/home/Contracts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const Contracts = () => {
gap="xl"
columnsPhone="minmax(0, 1fr)"
columnsTablet="minmax(0, 1fr)"
style={{ flexGrow: 1 }}
style={{ height: '88%' }}
>
<Flex stack justify="space-between">
<Flex stack gap="m">
Expand Down Expand Up @@ -119,7 +119,7 @@ export const Contracts = () => {
</Flex>

<Tabs.Root value={language}>
<Flex stack justify="space-between" style={{ flexGrow: 1 }}>
<Flex stack justify="space-between" style={{ height: '100%' }}>
<Tabs.Content value="js">
<Title> One Command Setup </Title>
<Code code={`npx create-near-app@latest`} language="bash" />
Expand Down
5 changes: 3 additions & 2 deletions src/components/home/DecentralizedApps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const Carousel = styled.div`
const WalletImg = styled(Image)`
margin: 0 2px;
height: 40px;
width: 40px;
border-radius: 4px;
`;

Expand All @@ -80,7 +81,7 @@ export const DecentralizedApps = () => {
gapTablet="xl"
columnsPhone="minmax(0, 1fr)"
columnsTablet="minmax(0, 1fr)"
style={{ flex: 1 }}
style={{ height: '88%' }}
>
<Flex stack justify="space-between">
<Flex stack gap="m">
Expand All @@ -97,7 +98,7 @@ export const DecentralizedApps = () => {
</Flex>
</Flex>

<Flex stack gap="m" justify="space-between" style={{ flexGrow: 1 }}>
<Flex stack gap="m" justify="space-between" style={{ height: '100%' }}>
<Flex stack>
<Title> NEAR React App </Title>
<Code code={ReactApp} height={450} language="ts" />
Expand Down
30 changes: 22 additions & 8 deletions src/components/sidebar-navigation/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as HoverCard from '@radix-ui/react-hover-card';
import Link from 'next/link';
import React, { useCallback, useEffect, useRef, useState } from 'react';

import { networkId } from '@/config';
import useDebounce from '@/hooks/useDebounce';
import { fetchSearchHits } from '@/utils/algoliaSearchApi';
import { fetchCatalog } from '@/utils/catalogSearchApi';
Expand Down Expand Up @@ -51,11 +52,15 @@ export const Search = ({ inputRef }: { inputRef: any }) => {
const fetchResults = useCallback(async () => {
setIsLoading(true);

const [docs, apps, components] = await Promise.all([
const isMainnet = networkId === 'mainnet';

const fetchPromises = [
fetchSearchHits('Docs', debouncedSearchTerm),
fetchCatalog(debouncedSearchTerm),
fetchSearchHits('Components', debouncedSearchTerm),
]);
isMainnet ? fetchCatalog(debouncedSearchTerm) : Promise.resolve(),
isMainnet ? fetchSearchHits('Components', debouncedSearchTerm) : Promise.resolve(),
];

const [docs, apps, components] = await Promise.all(fetchPromises);

setResults({
Docs: renderResults('Docs', docs),
Expand Down Expand Up @@ -135,11 +140,20 @@ export const Search = ({ inputRef }: { inputRef: any }) => {
<S.Tab $active={activeTab === 'Docs'} onClick={() => handleTabChange('Docs')} $isFirst={true}>
Docs
</S.Tab>
<S.Tab $active={activeTab === 'Apps'} onClick={() => handleTabChange('Apps')}>
Apps
<S.Tab
$active={activeTab === 'Apps'}
onClick={() => handleTabChange('Apps')}
disabled={networkId == 'testnet'}
>
Apps {networkId == 'testnet' && '(Mainnet only)'}
</S.Tab>
<S.Tab $active={activeTab === 'Components'} onClick={() => handleTabChange('Components')} $isLast={true}>
Components
<S.Tab
$active={activeTab === 'Components'}
onClick={() => handleTabChange('Components')}
disabled={networkId == 'testnet'}
$isLast={true}
>
Components {networkId == 'testnet' && '(Mainnet only)'}
</S.Tab>
</S.TabContainer>

Expand Down
72 changes: 62 additions & 10 deletions src/components/sidebar-navigation/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Tooltip } from '@near-pagoda/ui';
import { Dropdown, SvgIcon, Tooltip } from '@near-pagoda/ui';
import { CaretDown } from '@phosphor-icons/react';
import Image from 'next/image';
import { useRouter } from 'next/router';
import { useCallback, useEffect, useRef } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';
import { useContext } from 'react';
import styled from 'styled-components';

import { useSignInRedirect } from '@/hooks/useSignInRedirect';
import { networkId } from '@/config';

import { NearContext } from '../wallet-selector/WalletSelector';
import NearIconSvg from './icons/near-icon.svg';
Expand All @@ -14,6 +16,26 @@ import * as S from './styles';
import { UserDropdownMenu } from './UserDropdownMenu';
import { currentPathMatchesRoute } from './utils';

const Redirect = styled.a<{ selected?: boolean }>`
text-decoration: none;
color: #444;
`;

const Badge = styled.div`
display: flex;
align-items: center;
justify-content: center;
padding: 0.25rem 0.5rem;
gap: 4px;
font-size: 0.75rem;
font-weight: 600;
color: ${() => (networkId === 'mainnet' ? '#0072de' : '#d14e00')};
background-color: ${() => (networkId === 'mainnet' ? '#0084f116' : '#f9900026')};
text-transform: capitalize;
border-radius: 0.25rem;
letter-spacing: 0.05em;
`;

export const Sidebar = () => {
const router = useRouter();
const expandedDrawer = useNavigationStore((store) => store.expandedDrawer);
Expand All @@ -22,12 +44,14 @@ export const Sidebar = () => {
const toggleExpandedSidebar = useNavigationStore((store) => store.toggleExpandedSidebar);
const handleBubbledClickInSidebar = useNavigationStore((store) => store.handleBubbledClickInSidebar);
const tooltipsDisabled = isSidebarExpanded;
const { signedAccountId } = useContext(NearContext);
const { requestAuthentication } = useSignInRedirect();
const { wallet, signedAccountId } = useContext(NearContext);
const inputRef = useRef<HTMLInputElement>(null);
const [isOpenNetwork, setIsOpenNetwork] = useState(false);

const handleCreateAccount = () => {
requestAuthentication(true);
const preventRedirect = (network: string) => (e: React.MouseEvent) => {
if (networkId == network) {
e.preventDefault();
}
};

const isNavigationItemActive = useCallback(
Expand All @@ -53,6 +77,34 @@ export const Sidebar = () => {
<S.Logo href="/" aria-label="Go Home">
<Image src={NearIconSvg} alt="NEAR" />
</S.Logo>
<S.Network>
<Dropdown.Root open={isOpenNetwork} onOpenChange={(open) => setIsOpenNetwork(open)}>
<Dropdown.Trigger asChild>
<Badge>
{networkId}{' '}
<SvgIcon
icon={<CaretDown />}
size="xs"
style={{
marginBottom: '1px',
transform: isOpenNetwork ? 'rotate(180deg)' : 'rotate(0deg)',
transition: 'all 200ms',
}}
/>
</Badge>
</Dropdown.Trigger>
<Dropdown.Content>
<Dropdown.Section>
<Redirect href="https://dev.near.org" target="_blank" onClick={preventRedirect('mainnet')}>
<Dropdown.Item>Mainnet</Dropdown.Item>
</Redirect>
<Redirect href="https://test.near.org" target="_blank" onClick={preventRedirect('testnet')}>
<Dropdown.Item>Testnet</Dropdown.Item>
</Redirect>
</Dropdown.Section>
</Dropdown.Content>
</Dropdown.Root>
</S.Network>

<S.ToggleExpandButton type="button" aria-label="Expand/Collapse Menu" onClick={toggleExpandedSidebar}>
<i className={`ph-bold ${isSidebarExpanded ? 'ph-arrow-line-left' : 'ph-list'}`} />
Expand Down Expand Up @@ -202,10 +254,10 @@ export const Sidebar = () => {
{signedAccountId ? (
<UserDropdownMenu collapsed={!isSidebarExpanded} />
) : (
<Tooltip content="Sign-up or Login" side="right" disabled={tooltipsDisabled} asChild>
<S.LoginItem $active={false} $type="featured" onClick={handleCreateAccount}>
<Tooltip content="Login" side="right" disabled={tooltipsDisabled} asChild>
<S.LoginItem $active={false} $type="featured" onClick={wallet?.signIn}>
<i className="ph-bold ph-user" />
<span>Sign-up or Login</span>
<span>Login</span>
</S.LoginItem>
</Tooltip>
)}
Expand Down
47 changes: 37 additions & 10 deletions src/components/sidebar-navigation/SmallScreenHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { Button } from '@near-pagoda/ui';
import { MagnifyingGlass } from '@phosphor-icons/react';
import { Button, Dropdown } from '@near-pagoda/ui';
import { MagnifyingGlass, WifiHigh } from '@phosphor-icons/react';
import Image from 'next/image';
import { useRouter } from 'next/router';
import { useContext } from 'react';
import styled from 'styled-components';

import { useSignInRedirect } from '@/hooks/useSignInRedirect';
import { networkId } from '@/config';

import { NearContext } from '../wallet-selector/WalletSelector';
import NearIconSvg from './icons/near-icon.svg';
import { useNavigationStore } from './store';
import * as S from './styles';
import { UserDropdownMenu } from './UserDropdownMenu';

const Redirect = styled.a<{ selected?: boolean }>`
text-decoration: none;
color: #444;
`;

export const SmallScreenHeader = () => {
const router = useRouter();
const redirect = (url: string) => () => router.push(url);
Expand All @@ -20,11 +26,12 @@ export const SmallScreenHeader = () => {
const setNavigation = useNavigationStore((store) => store.set);
const showDrawerCollapse = useNavigationStore((store) => store.isOpenedOnSmallScreens && !!store.expandedDrawer);
const expandedDrawerTitle = useNavigationStore((store) => store.expandedDrawerTitle);
const { signedAccountId } = useContext(NearContext);
const { requestAuthentication } = useSignInRedirect();
const { wallet, signedAccountId } = useContext(NearContext);

const handleCreateAccount = () => {
requestAuthentication(true);
const preventRedirect = (network: string) => (e: React.MouseEvent) => {
if (networkId == network) {
e.preventDefault();
}
};

return (
Expand All @@ -50,7 +57,6 @@ export const SmallScreenHeader = () => {
<Image src={NearIconSvg} alt="NEAR" />
</S.SmallScreenHeaderLogo>
)}

{signedAccountId ? (
<S.SmallScreenHeaderActions $hidden={isOpenedOnSmallScreens} $gap="16px">
<Button label="search" icon={<MagnifyingGlass />} variant="secondary" onClick={redirect('/search')} />
Expand All @@ -59,14 +65,35 @@ export const SmallScreenHeader = () => {
) : (
<>
<Button
label="Sign-up or Login"
label="Login"
variant="primary"
onClick={handleCreateAccount}
onClick={wallet?.signIn}
style={{ alignSelf: 'center', marginRight: '1rem' }}
/>
</>
)}
<Dropdown.Root>
<Dropdown.Trigger asChild>
<Button
label={networkId}
icon={<WifiHigh fill="bold" style={{ color: networkId == 'mainnet' ? '#0072de' : '#d14e00' }} />}
fill="outline"
style={{ alignSelf: 'center' }}
type="button"
/>
</Dropdown.Trigger>

<Dropdown.Content>
<Dropdown.Section>
<Redirect href="https://dev.near.org" target="_blank" onClick={preventRedirect('mainnet')}>
<Dropdown.Item>Mainnet</Dropdown.Item>
</Redirect>
<Redirect href="https://test.near.org" target="_blank" onClick={preventRedirect('testnet')}>
<Dropdown.Item>Testnet</Dropdown.Item>
</Redirect>
</Dropdown.Section>
</Dropdown.Content>
</Dropdown.Root>
<S.SmallScreenHeaderIconButton
type="button"
aria-label="Expand/Collapse Menu"
Expand Down
6 changes: 4 additions & 2 deletions src/components/sidebar-navigation/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export const Logo = styled(Link)`
}
`;

export const Network = styled.div``;

export const ToggleExpandButton = styled.button`
all: unset;
box-sizing: border-box;
Expand Down Expand Up @@ -605,13 +607,13 @@ export const Sidebar = styled.div<{
${NavigationItem} span,
${SectionLabelIconLink},
${SectionLabel},
${Logo} {
${Logo},
${Network} {
pointer-events: none;
opacity: 0;
padding: 0;
width: 0;
}

${SectionLabel} {
margin-bottom: -2rem;
}
Expand Down
8 changes: 7 additions & 1 deletion src/components/tools/FungibleToken/CreateTokenForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,13 @@ const CreateTokenForm = ({ reload }: { reload: (delay: number) => void }) => {
label="Total Supply"
placeholder="e.g. 1000"
error={errors.total_supply?.message}
{...register('total_supply', { required: 'Total supply is required' })}
{...register('total_supply', {
required: 'Total supply is required',
pattern: {
value: /^[1-9][0-9]*$/,
message: 'Total supply must be a whole number greater than 0',
},
})}
disabled={!signedAccountId}
/>
<Input
Expand Down
Loading
Loading