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

V2 ChainButton, WalletButton and LoadingPill #1489

Merged
merged 22 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cc6269b
feat: add StatusIndicator component to webb-ui-kit
AtelyPham Jul 27, 2023
319cedd
Merge remote-tracking branch 'origin/hubble-bridge-v2' into trung-tin…
AtelyPham Jul 27, 2023
81b3f99
fix: move StatusIndicator to svg to fix the width issue
AtelyPham Jul 27, 2023
50fa1ef
chore: add Storybook for StatusIndicator
AtelyPham Jul 27, 2023
292e7ad
chore: rename Button to buttons for namespace purpose
AtelyPham Jul 29, 2023
fcbda55
chore: export default for Button*
AtelyPham Jul 29, 2023
01a88dd
feat: add v2 ChainButton component
AtelyPham Jul 29, 2023
5d916c5
Merge remote-tracking branch 'origin/trung-tin/status-indicator' into…
AtelyPham Jul 29, 2023
9562c31
chore: move StatusIndicator into icons lib to use with ChainIcon
AtelyPham Jul 29, 2023
79cc5ff
feat: add status for ChainButton
AtelyPham Jul 29, 2023
378305e
Merge branch 'hubble-bridge-v2' into trung-tin/v2-chain-wallet-buttons
AtelyPham Jul 31, 2023
5e70f9b
feat: add WalletButton component
AtelyPham Jul 31, 2023
39bcbba
Merge remote-tracking branch 'origin/develop' into trung-tin/v2-chain…
AtelyPham Jul 31, 2023
74d9540
Merge branch 'hubble-bridge-v2' into trung-tin/v2-chain-wallet-buttons
AtelyPham Jul 31, 2023
15ca596
Hubble Stats Breadcrumbs (#1470)
devpavan04 Jul 31, 2023
06bd9d6
Fix Token Approval Issue (#1480)
AtelyPham Aug 1, 2023
27dcf65
Add More Rpc Urls to Support Multiple Providers (#1471)
AtelyPham Aug 1, 2023
45498f0
Merge branch 'develop' into trung-tin/v2-chain-wallet-buttons
AtelyPham Aug 1, 2023
d089c42
chore: integrate new chain button into the bridge
AtelyPham Aug 1, 2023
0103685
fix: the theme issue
AtelyPham Aug 1, 2023
a222f26
chore: integrate new wallet button into the bridge
AtelyPham Aug 1, 2023
7c022a1
feat: add LoadingPill component
AtelyPham Aug 1, 2023
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
35 changes: 0 additions & 35 deletions apps/bridge-dapp/src/components/Header/ChainSwitcherButton.tsx

This file was deleted.

25 changes: 17 additions & 8 deletions apps/bridge-dapp/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { useWebContext } from '@webb-tools/api-provider-environment';
import { ContrastTwoLine } from '@webb-tools/icons';
import {
Breadcrumbs,
BreadcrumbsItem,
Button,
ChainButton,
NavigationMenu,
NavigationMenuContent,
NavigationMenuTrigger,
useWebbUI,
} from '@webb-tools/webb-ui-components';
import { FC, useCallback, useMemo } from 'react';
import { NavLink, useLocation } from 'react-router-dom';
import { NavLink } from 'react-router-dom';
import { useConnectWallet } from '../../hooks';
import { ChainSwitcherButton } from './ChainSwitcherButton';
import { WalletButton } from './WalletButton';
import { ChainListCardWrapper } from '../ChainListCardWrapper';
import { WalletDropdown } from './WalletDropdown';
import { HeaderProps } from './types';
import { ContrastTwoLine } from '@webb-tools/icons';

/**
* The statistic `Header` for `Layout` container
*/
export const Header: FC<HeaderProps> = () => {
const { activeAccount, activeWallet, activeChain, loading } = useWebContext();

const { setMainComponent } = useWebbUI();

const { toggleModal } = useConnectWallet();

// On connect wallet button click - connect to the default chain(ETH Goerli)
Expand All @@ -35,7 +39,7 @@ export const Header: FC<HeaderProps> = () => {
);

return (
<header className="pt-6 pb-10 px-4">
<header className="px-4 pt-6 pb-10">
<div className="flex justify-between max-w-[1160px] h-[40px] mx-auto">
<Breadcrumbs>
<NavLink to="/bridge">
Expand All @@ -53,10 +57,15 @@ export const Header: FC<HeaderProps> = () => {
{/** Wallet is actived */}
{isDisplayNetworkSwitcherAndWalletButton &&
activeAccount &&
activeWallet ? (
activeWallet &&
activeChain ? (
<div className="hidden lg:!flex items-center space-x-2">
<ChainSwitcherButton />
<WalletButton account={activeAccount} wallet={activeWallet} />
<ChainButton
chain={activeChain}
status="success"
onClick={() => setMainComponent(<ChainListCardWrapper />)}
/>
<WalletDropdown account={activeAccount} wallet={activeWallet} />
</div>
) : (
<Button
Expand Down
17 changes: 0 additions & 17 deletions apps/bridge-dapp/src/components/Header/HeaderButton.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Account } from '@webb-tools/abstract-api-provider';
import { useWebContext } from '@webb-tools/api-provider-environment';
import { downloadString } from '@webb-tools/browser-utils';
import { ManagedWallet, WalletConfig } from '@webb-tools/dapp-config';
import { WebbError, WebbErrorCodes } from '@webb-tools/dapp-types';
import {
ExternalLinkLine,
LoginBoxLineIcon,
Expand All @@ -11,26 +12,24 @@ import {
} from '@webb-tools/icons';
import { useNoteAccount, useWallets } from '@webb-tools/react-hooks';
import { Note } from '@webb-tools/sdk-core';
import { WebbWeb3Provider, isViemError } from '@webb-tools/web3-api-provider';
import {
Avatar,
Button,
Dropdown,
DropdownBasicButton,
DropdownBody,
IconWithTooltip,
KeyValueWithButton,
MenuItem,
shortenString,
Typography,
WalletButton,
useWebbUI,
IconWithTooltip,
} from '@webb-tools/webb-ui-components';
import { FC, useCallback, useMemo, useState } from 'react';
import { ClearDataModal } from './ClearDataModal';
import { HeaderButton } from './HeaderButton';
import { WebbWeb3Provider, isViemError } from '@webb-tools/web3-api-provider';
import { WebbError, WebbErrorCodes } from '@webb-tools/dapp-types';

export const WalletButton: FC<{ account: Account; wallet: WalletConfig }> = ({
export const WalletDropdown: FC<{ account: Account; wallet: WalletConfig }> = ({
account,
wallet,
}) => {
Expand Down Expand Up @@ -68,19 +67,6 @@ export const WalletButton: FC<{ account: Account; wallet: WalletConfig }> = ({
[allNotes]
);

const displayText = useMemo(() => {
if (account.name) {
return account.name;
}

// if account address starts with 0x, then truncate it to xxxx...xxxx
if (account.address.toLowerCase().startsWith('0x')) {
return shortenString(account.address.substring(2), 4);
}

return shortenString(account.address, 4);
}, [account]);

// Get the note account keypair to display public + encryption key
const keyPair = useMemo(() => noteManager?.getKeypair(), [noteManager]);

Expand Down Expand Up @@ -192,13 +178,7 @@ export const WalletButton: FC<{ account: Account; wallet: WalletConfig }> = ({
<>
<Dropdown>
<DropdownTrigger asChild>
<HeaderButton className="rounded-full">
{wallet.Logo}

<Typography variant="body1" fw="bold">
{displayText}
</Typography>
</HeaderButton>
<WalletButton wallet={wallet} address={account.address} />
</DropdownTrigger>

<DropdownBody className="mt-6 w-[480px] p-4 space-y-4 dark:bg-mono-160">
Expand Down
1 change: 0 additions & 1 deletion apps/bridge-dapp/src/components/Header/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './Header';
export * from './ChainSwitcherButton';
export * from './WalletModal';
1 change: 1 addition & 0 deletions apps/bridge-dapp/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const defaultTheme = require('tailwindcss/defaultTheme');
const { createGlobPatternsForDependencies } = require('@nx/react/tailwind');
const { join } = require('path');

/** @type {import('tailwindcss').Config} */
module.exports = {
presets: [preset],
content: [
Expand Down
8 changes: 5 additions & 3 deletions apps/hubble-stats/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use client';

import {
WebbUIProvider,
Footer,
SideBar,
Logo,
LogoWithoutName,
} from '@webb-tools/webb-ui-components';
import '@webb-tools/webb-ui-components/tailwind.css';

import { WEBB_MKT_URL } from '@webb-tools/webb-ui-components/constants';
import { Header } from '../components';
import '@webb-tools/webb-ui-components/tailwind.css';
import { sideBarProps } from '../constants';

export default function RootLayout({
Expand All @@ -21,7 +23,7 @@ export default function RootLayout({
<body className="h-screen bg-body dark:bg-body_dark bg-cover flex">
<SideBar {...sideBarProps} className="hidden lg:block" />
<main className="flex-1 px-3 md:px-5 lg:px-10 overflow-y-auto">
<Header />
<Header tvlValue="$13,642,124" volumeValue="$8,562,122" />
{children}
<Footer isMinimal className="max-w-none" />
</main>
Expand Down
68 changes: 47 additions & 21 deletions apps/hubble-stats/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BlockIcon, CoinIcon, ContrastLine, Spinner } from '@webb-tools/icons';
import { IconBase } from '@webb-tools/icons/types';
import { FC, useMemo } from 'react';
import Link from 'next/link';
import {
Expand All @@ -7,34 +9,58 @@ import {
ChipProps,
SideBarMenu,
} from '@webb-tools/webb-ui-components';
import { BlockIcon, GridFillIcon, Spinner } from '@webb-tools/icons';
import { IconBase } from '@webb-tools/icons/types';
import { HeaderProps, Breadcrumb } from './types';
import { usePathname } from 'next/navigation';

import { sideBarProps } from '../../constants';

const Header = () => {
const tvl = useMemo(() => {
return 'TVL: $13,642,124';
}, []);
const Header = ({ tvlValue, volumeValue }: HeaderProps) => {
const pathname = usePathname();

const breadCrumbs = useMemo(() => {
const parts = pathname.split('/');
const activeItem = parts[parts.length - 1];

const breadCrumbItems: Breadcrumb[] = [
{
label: 'Hubble Overview',
isLast: activeItem !== '' ? false : true,
icon: (
<ContrastLine className={activeItem !== '' ? 'fill-mono-120' : ''} />
),
href: '/',
},
];

if (activeItem !== '') {
breadCrumbItems.push({
label: activeItem,
isLast: true,
icon: <CoinIcon />,
href: '',
});
}

const volume = useMemo(() => {
return 'volume: $8,562,122';
}, []);
return breadCrumbItems;
}, [pathname]);

return (
<div className="flex items-center justify-between pt-6 pb-4">
{/* Breadcrumbs */}
<div className="flex gap-2 items-center">
<SideBarMenu {...sideBarProps} className="lg:hidden" />
<Breadcrumbs>
<Link href="/">
<BreadcrumbsItem
icon={<GridFillIcon />}
className="ml-0 bg-[rgba(156,160,176,0.10)] dark:bg-[rgba(255,255,255,0.05)]"
>
Hubble Overview
</BreadcrumbsItem>
</Link>
{breadCrumbs.map((breadcrumb, index) => (
<Link key={index} href={breadcrumb.href}>
<BreadcrumbsItem
icon={breadcrumb.icon}
className={breadcrumb.className}
isLast={breadcrumb.isLast}
>
{breadcrumb.label}
</BreadcrumbsItem>
</Link>
))}
</Breadcrumbs>
</div>

Expand All @@ -45,16 +71,16 @@ const Header = () => {
Icon={BlockIcon}
iconSize="lg"
iconClassName="stroke-blue-90 dark:stroke-blue-30"
value={tvl}
isLoading={tvl ? false : true}
value={tvlValue}
isLoading={tvlValue ? false : true}
/>
<VolumeChip
color="blue"
Icon={BlockIcon}
iconSize="lg"
iconClassName="stroke-blue-90 dark:stroke-blue-30"
value={volume}
isLoading={volume ? false : true}
value={volumeValue}
isLoading={volumeValue ? false : true}
/>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions apps/hubble-stats/components/Header/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as Header } from './Header';
export * from './types';
12 changes: 12 additions & 0 deletions apps/hubble-stats/components/Header/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type Breadcrumb = {
label: string;
isLast: boolean;
icon: JSX.Element;
href: string;
className?: string;
};

export type HeaderProps = {
tvlValue: string;
volumeValue: string;
};
18 changes: 9 additions & 9 deletions libs/api-provider-environment/src/WebbProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -620,17 +620,17 @@ const WebbProviderInner: FC<WebbProviderProps> = ({ children, appEvent }) => {

if (currentChainId !== chain.id) {
await webbWeb3Provider.switchOrAddChain(chain.id);

// Emit events
appEvent.send('networkSwitched', [
{
chainType: chain.chainType,
chainId: chain.id,
},
wallet.id,
]);
}

// Emit events
appEvent.send('networkSwitched', [
{
chainType: chain.chainType,
chainId: chain.id,
},
wallet.id,
]);

await setActiveApiWithAccounts(
webbWeb3Provider,
chain,
Expand Down
2 changes: 1 addition & 1 deletion libs/dapp-config/src/chains/chain-config.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022 @webb-tools/
// SPDX-License-Identifier: Apache-2.0

import { ChainType } from '@webb-tools/sdk-core';
import { ChainType } from '@webb-tools/sdk-core/typed-chain-id';
import type { Chain } from '@wagmi/chains';

import { AppEnvironment } from '../types';
Expand Down
Loading
Loading