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

feat(tangle-cloud): Configure Layout, Network, and Wallet #2651

Merged
merged 42 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2f1f6b9
feat(webb-ui): Add side bar to Tangle Cloud
AtelyPham Nov 5, 2024
b905eb4
ci(repo): Setup husky
AtelyPham Nov 5, 2024
d40dc29
fix(webb-ui): Remove warnings on side bar menu component
AtelyPham Nov 6, 2024
b0251e7
feat(webb-ui): Add action button to side bar comp
AtelyPham Nov 6, 2024
bd6a686
feat(webb-ui): Add collapse button for sidebar
AtelyPham Nov 6, 2024
605add1
style(webb-ui): Add border color to sidebar on dark mode
AtelyPham Nov 7, 2024
44ef183
refactor(repo): Remove the need of fetching on chain config
AtelyPham Nov 4, 2024
468d02d
feat(webb-ui): Add Tangle Cloud logo
AtelyPham Nov 5, 2024
1521d2e
feat(tangle-cloud): Add footer
AtelyPham Nov 7, 2024
ac3c70f
style(tangle-cloud): Style layout for main page
AtelyPham Nov 11, 2024
6482396
feat(tangle-shared-ui): Initialize shared ui library
AtelyPham Nov 11, 2024
4f7cdd2
refactor(tangle-shared-ui): move useNetworkStore to share lib
AtelyPham Nov 11, 2024
40bda5a
refactor(tangle-dapp): Move `OnboardingPageKey` to `tangle-shared-ui`
AtelyPham Nov 12, 2024
bd9aadf
refactor(tangle-dapp): Move `Payout` type to `tangle-shared-ui`
AtelyPham Nov 12, 2024
68c5cc5
refactor(tangle-dapp): Move `bridge` types to `tangle-shared-ui`
AtelyPham Nov 12, 2024
a2ac270
refactor(tangle-dapp): Move `LsProtocolId` to shared ui lib
AtelyPham Nov 12, 2024
13ae6b8
refactor(tangle-dapp): Move `LiquidStakingItem` to shared ui lib
AtelyPham Nov 12, 2024
9fe8cec
refactor(tangle-dapp): Move liquid staking types to shared ui lib
AtelyPham Nov 12, 2024
a21e22d
refactor(tangle-dapp): Move Optional class to shared ui lib
AtelyPham Nov 12, 2024
b372f02
refactor(tangle-dapp): Move useLocalStorage to shared ui lib
AtelyPham Nov 12, 2024
ec18891
refactor(tangle-dapp): move useInitialNetwork to tangle-shared-ui
AtelyPham Nov 12, 2024
a82a807
refactor(tangle-dapp): move ensureError to tangle-shared-ui
AtelyPham Nov 12, 2024
11281f1
refactor(tangle-dapp): move polkadot api to shared ui lib
AtelyPham Nov 12, 2024
dfef25a
refactor(tangle-dapp): move useNetworkSwitcher to shared ui lib
AtelyPham Nov 12, 2024
727d299
chore: fix build and lint errors
AtelyPham Nov 12, 2024
6645c7d
refactor(tangle-dapp): Move network selector to shared ui lib
AtelyPham Nov 12, 2024
d50edbf
refactor(tangle-dapp): Move useIsMountedRef to webb-ui-components
AtelyPham Nov 12, 2024
84a1c42
refactor(tangle-dapp): Move `usePromise` to tangle-shared-ui
AtelyPham Nov 12, 2024
68a2fdf
feat: Add `useActiveAccount` hook
AtelyPham Nov 12, 2024
97f8f03
refactor(tangle-dapp): Move `UpdateMetadataButton` to tangle-shared-ui
AtelyPham Nov 12, 2024
b0b2a4d
chore: fix build and lint
AtelyPham Nov 12, 2024
94e111b
Merge remote-tracking branch 'origin/develop' into trung-tin/wallet-c…
AtelyPham Nov 12, 2024
26b41b1
refactor(tangle-dapp): Move wallet and network connection to shared u…
AtelyPham Nov 12, 2024
722b462
feat(tangle-cloud): add network and wallet connection
AtelyPham Nov 12, 2024
ab93104
fix(repo): Fix sidebar style and add role dropdown
AtelyPham Nov 12, 2024
ae33481
fix(tangle-dapp): Remove the hardcoded provider type
AtelyPham Nov 12, 2024
db5fec2
fix(repo): Add connected accounts check in polkadot provider
AtelyPham Nov 12, 2024
dcd8bb4
fix(webb-ui-components): Add missing target typed chain ids
AtelyPham Nov 12, 2024
80df839
style(tangle-cloud): Fix inconsistent padding on footer
AtelyPham Nov 12, 2024
8d07298
chore(repo): Add tangle-shared-ui to PR template
AtelyPham Nov 12, 2024
e4dd257
fix(repo): Address feedback and improve code
AtelyPham Nov 13, 2024
7f7e3aa
chore(repo): Remove husky
AtelyPham Nov 13, 2024
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
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ _Put an `x` in the boxes that apply._

- [ ] `apps/tangle-dapp`
- [ ] `apps/tangle-cloud`
- [ ] `libs/tangle-shared-ui`
- [ ] `libs/webb-ui-components`

### Associated issue(s)
Expand Down
1 change: 1 addition & 0 deletions .husky/commit-msg
AtelyPham marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx --no-install commitlint --edit $1
8 changes: 8 additions & 0 deletions .husky/pre-push
AtelyPham marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
yarn run lint

yarn run format:check

if [ $? -ne 0 ]; then
echo "Lint or format check(s) failed, aborting push."
exit 1
fi
10 changes: 9 additions & 1 deletion apps/tangle-cloud/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { headers } from 'next/headers';
import { Suspense } from 'react';
import { cookieToInitialState } from 'wagmi';
import Providers from './providers';
import Layout from '../components/Layout';
import { getSidebarStateFromCookie } from '@webb-tools/webb-ui-components/next-utils';

export const metadata = {
title: 'Welcome to tangle-cloud',
Expand All @@ -22,11 +24,17 @@ export default function RootLayout({
headers().get('cookie'),
);

const isSidebarInitiallyExpanded = getSidebarStateFromCookie();

return (
<html lang="en" suppressHydrationWarning>
<body>
<Suspense>
<Providers wagmiInitialState={initialState}>{children}</Providers>
<Providers wagmiInitialState={initialState}>
<Layout isSidebarInitiallyExpanded={isSidebarInitiallyExpanded}>
{children}
</Layout>
</Providers>
</Suspense>
</body>
</html>
Expand Down
24 changes: 12 additions & 12 deletions apps/tangle-cloud/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Typography } from '@webb-tools/webb-ui-components/typography/Typography';
import Header from '../components/Header';

export default function Index() {
/*
* Replace the elements below with your own.
*
* Note: The corresponding styles are in the ./index.css file.
*/
return (
<Typography
variant="h3"
ta="center"
className="flex items-center justify-center min-h-screen"
>
Hello there, Welcome tangle-cloud 👋
</Typography>
<div className="max-w-screen-xl mx-auto">
<Header />

<Typography
variant="h3"
ta="center"
className="flex items-center justify-center min-h-full"
>
Hello there, Welcome tangle-cloud 👋
</Typography>
</div>
);
}
22 changes: 22 additions & 0 deletions apps/tangle-cloud/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import NetworkSelectorDropdown from '@webb-tools/tangle-shared-ui/components/NetworkSelectorDropdown';
import ConnectWalletButton from '@webb-tools/tangle-shared-ui/components/ConnectWalletButton';
import { ComponentProps } from 'react';
import { twMerge } from 'tailwind-merge';

export default function Header({
className,
...props
}: ComponentProps<'header'>) {
return (
<header
className={twMerge('p-4 max-w-screen-xl mx-auto', className)}
{...props}
>
<div className="flex items-center justify-end gap-2">
<NetworkSelectorDropdown />

<ConnectWalletButton />
</div>
</header>
);
}
44 changes: 44 additions & 0 deletions apps/tangle-cloud/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Footer } from '@webb-tools/webb-ui-components/components/Footer';
import Sidebar from './Sidebar';
import { FC, PropsWithChildren } from 'react';
import {
bottomLinks,
TANGLE_PRIVACY_POLICY_URL,
TANGLE_SOCIAL_URLS_RECORD,
TANGLE_TERMS_OF_SERVICE_URL,
} from '@webb-tools/webb-ui-components/constants';

type Props = {
isSidebarInitiallyExpanded?: boolean;
};

const BOTTOM_LINK_OVERRIDES: Partial<
Record<(typeof bottomLinks)[number]['name'], string>
> = {
'Terms of Service': TANGLE_TERMS_OF_SERVICE_URL,
'Privacy Policy': TANGLE_PRIVACY_POLICY_URL,
};

const Layout: FC<PropsWithChildren<Props>> = ({
children,
isSidebarInitiallyExpanded,
}) => {
return (
<div className={`flex min-h-screen bg-body body-bg`}>
<Sidebar isExpandedAtDefault={isSidebarInitiallyExpanded} />

<div className="flex flex-col flex-1 min-h-screen overflow-y-auto scrollbar-hide">
<main className="flex-1">{children}</main>

<Footer
socialsLinkOverrides={TANGLE_SOCIAL_URLS_RECORD}
bottomLinkOverrides={BOTTOM_LINK_OVERRIDES}
isMinimal
className="px-6 py-8"
/>
</div>
</div>
);
};

export default Layout;
167 changes: 167 additions & 0 deletions apps/tangle-cloud/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
'use client';

import { DropdownMenuTrigger } from '@radix-ui/react-dropdown-menu';
import { HomeIcon, PersonIcon } from '@radix-ui/react-icons';
import { ArrowRight } from '@webb-tools/icons';
import CommandFillIcon from '@webb-tools/icons/CommandFillIcon';
import { DocumentationIcon } from '@webb-tools/icons/DocumentationIcon';
import GlobalLine from '@webb-tools/icons/GlobalLine';
import { GridFillIcon } from '@webb-tools/icons/GridFillIcon';
import { getIconSizeInPixel } from '@webb-tools/icons/utils';
import Button from '@webb-tools/webb-ui-components/components/buttons/Button';
import {
Dropdown,
DropdownBody,
DropdownMenuItem,
} from '@webb-tools/webb-ui-components/components/Dropdown';
import {
SideBar as SideBarCmp,
SideBarFooterType,
SideBarItemProps,
SideBarMenu,
SidebarTangleClosedIcon,
} from '@webb-tools/webb-ui-components/components/SideBar';
import { TangleCloudLogo } from '@webb-tools/webb-ui-components/components/TangleCloudLogo';
import {
TANGLE_DAPP_URL,
TANGLE_DOCS_URL,
} from '@webb-tools/webb-ui-components/constants';
import { setSidebarCookieOnToggle } from '@webb-tools/webb-ui-components/next-utils';
import cx from 'classnames';
import capitalize from 'lodash/capitalize';
import { usePathname } from 'next/navigation';
import { FC, useMemo } from 'react';
import useRoleStore, { Role } from '../stores/roleStore';
import { PagePath } from '../types';

type Props = {
isExpandedAtDefault?: boolean;
};

const SIDEBAR_ITEMS: SideBarItemProps[] = [
{
name: 'Home',
href: PagePath.HOME,
isInternal: true,
isNext: true,
Icon: HomeIcon,
subItems: [],
},
{
name: 'Blueprints',
href: PagePath.BLUEPRINTS,
isInternal: true,
isNext: true,
Icon: GridFillIcon,
subItems: [],
},
{
name: 'Operators',
href: PagePath.OPERATORS,
isInternal: true,
isNext: true,
Icon: GlobalLine,
subItems: [],
},

// External links
{
Icon: CommandFillIcon,
href: TANGLE_DAPP_URL,
isInternal: false,
name: 'dApp',
subItems: [],
},
];

const SIDEBAR_FOOTER: SideBarFooterType = {
Icon: DocumentationIcon,
href: TANGLE_DOCS_URL,
isInternal: false,
name: 'Docs',
useNextThemesForThemeToggle: true,
};

const ActionButton: FC<{ isExpanded: boolean }> = ({ isExpanded }) => {
const { role, setRole } = useRoleStore();

const capitalizedRole = useMemo(() => capitalize(role), [role]);

return (
<Dropdown>
<DropdownMenuTrigger asChild>
<Button
title={capitalizedRole}
isFullWidth
rightIcon={
isExpanded ? (
<ArrowRight size="lg" className="!fill-mono-0" />
) : (
<PersonIcon
width={getIconSizeInPixel('lg')}
height={getIconSizeInPixel('lg')}
/>
)
}
className={cx(!isExpanded && '!p-2')}
>
{isExpanded ? capitalizedRole : ''}
</Button>
</DropdownMenuTrigger>

<DropdownBody
className={cx('mt-2', isExpanded && 'w-[248px]')}
align="center"
>
<DropdownMenuItem
isActive={role === Role.OPERATOR}
onClick={() => setRole(Role.OPERATOR)}
>
Operate
</DropdownMenuItem>
<DropdownMenuItem
isActive={role === Role.DEPLOYER}
onClick={() => setRole(Role.DEPLOYER)}
>
Deploy
</DropdownMenuItem>
</DropdownBody>
</Dropdown>
);
};

const Sidebar: FC<Props> = ({ isExpandedAtDefault }) => {
const pathname = usePathname();

return (
<>
{/* Large screen sidebar */}
<SideBarCmp
ClosedLogo={SidebarTangleClosedIcon}
items={SIDEBAR_ITEMS}
footer={SIDEBAR_FOOTER}
Logo={TangleCloudLogo}
logoLink={pathname}
pathnameOrHash={pathname}
className="hidden lg:block"
isExpandedAtDefault={isExpandedAtDefault}
onSideBarToggle={setSidebarCookieOnToggle}
ActionButton={ActionButton}
/>

{/* Small screen sidebar */}
<SideBarMenu
ClosedLogo={SidebarTangleClosedIcon}
items={SIDEBAR_ITEMS}
footer={SIDEBAR_FOOTER}
Logo={TangleCloudLogo}
logoLink={pathname}
pathnameOrHash={pathname}
className="fixed top-4 left-5 lg:hidden"
ActionButton={ActionButton}
/>
</>
);
};

export default Sidebar;
3 changes: 2 additions & 1 deletion apps/tangle-cloud/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"defaultConfiguration": "development",
"options": {
"buildTarget": "tangle-cloud:build",
"dev": true
"dev": true,
"port": 4300
},
"configurations": {
"development": {
Expand Down
26 changes: 26 additions & 0 deletions apps/tangle-cloud/stores/roleStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';

export enum Role {
OPERATOR = 'operator',
DEPLOYER = 'deployer',
}

export interface RoleState {
role: Role;
setRole: (role: Role) => void;
}

const useRoleStore = create<RoleState>()(
persist(
(set) => ({
role: Role.DEPLOYER,
setRole: (role) => set(() => ({ role })),
}),
{
name: 'role',
},
),
);

export default useRoleStore;
5 changes: 5 additions & 0 deletions apps/tangle-cloud/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum PagePath {
HOME = '/',
BLUEPRINTS = '/blueprints',
OPERATORS = '/operators',
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Option } from '@polkadot/types';
import type { TanglePrimitivesServicesOperatorPreferences } from '@polkadot/types/lookup';
import useNetworkStore from '@webb-tools/tangle-shared-ui/context/useNetworkStore';
import { useCallback } from 'react';
import { combineLatest, switchMap } from 'rxjs';

import useNetworkStore from '../../../context/useNetworkStore';
import { extractOperatorData } from '../../../data/blueprints/utils/blueprintHelpers';
import { toPrimitiveBlueprint } from '../../../data/blueprints/utils/toPrimitiveBlueprint';
import useRestakeAssetMap from '../../../data/restake/useRestakeAssetMap';
Expand Down
2 changes: 1 addition & 1 deletion apps/tangle-dapp/app/bridge/hooks/useBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import { isAddress } from '@polkadot/util-crypto';
import { ChainConfig } from '@webb-tools/dapp-config/chains/chain-config.interface';
import { AddressType } from '@webb-tools/dapp-config/types';
import ensureError from '@webb-tools/tangle-shared-ui/utils/ensureError';
import { useWebbUI } from '@webb-tools/webb-ui-components/hooks/useWebbUI';
import Decimal from 'decimal.js';
import { useCallback, useEffect, useMemo } from 'react';
import useSWR from 'swr';

import { useBridge } from '../../../context/BridgeContext';
import useActiveAccountAddress from '../../../hooks/useActiveAccountAddress';
import ensureError from '../../../utils/ensureError';
import { isEvmAddress } from '../../../utils/isEvmAddress';
import {
getEvmContractBalance,
Expand Down
3 changes: 2 additions & 1 deletion apps/tangle-dapp/app/bridge/hooks/useBridgeFee.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use client';

import { BridgeType } from '@webb-tools/tangle-shared-ui/types/bridge';
import { useEffect } from 'react';

import { useBridge } from '../../../context/BridgeContext';
import { BridgeFeeType, BridgeType } from '../../../types/bridge';
import { BridgeFeeType } from '../../../types/bridge';
import useSelectedToken from './useSelectedToken';

export default function useBridgeFee() {
Expand Down
Loading
Loading