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: add new minimal connect button, connect wallet #224

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
62 changes: 44 additions & 18 deletions src/features/connect/connect-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import { useProviderManifests } from '@/shared/api/providerManifests';
import dynamic from 'next/dynamic';

const ConnectButtonInner = observer(
({ actionType = 'accent' }: { actionType?: ButtonProps['actionType'] }) => {
({
actionType = 'accent',
variant = 'default',
}: {
actionType?: ButtonProps['actionType'];
variant?: 'default' | 'minimal';
}) => {
const [isOpen, setIsOpen] = useState(false);
const { data: providerManifests } = useProviderManifests();

Expand All @@ -32,23 +38,43 @@ const ConnectButtonInner = observer(

return (
<>
<Density sparse>
{providerOrigins.length === 0 ? (
<Button
icon={Wallet2}
actionType={actionType}
onClick={() =>
window.open('https://praxwallet.com/', '_blank', 'noopener,noreferrer')
}
>
Install Prax
</Button>
) : (
<Button icon={Wallet2} actionType={actionType} onClick={onConnectClick}>
Connect wallet
</Button>
)}
</Density>
{variant === 'default' ? (
<Density sparse>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking):

Suggested change
<Density sparse>
<Density variant={variant === 'default' ? 'sparse' : 'compact'}>

Since penumbra-zone/web#1942, it is possible to provide dynamic variant prop to Density, to not duplicate the code

{providerOrigins.length === 0 ? (
<Button
icon={Wallet2}
actionType={actionType}
onClick={() =>
window.open('https://praxwallet.com/', '_blank', 'noopener,noreferrer')
}
>
Install Prax
</Button>
) : (
<Button icon={Wallet2} actionType={actionType} onClick={onConnectClick}>
Connect wallet
</Button>
)}
</Density>
) : (
<Density compact>
{providerOrigins.length === 0 ? (
<Button
icon={Wallet2}
actionType={actionType}
onClick={() =>
window.open('https://praxwallet.com/', '_blank', 'noopener,noreferrer')
}
>
Install Prax
</Button>
) : (
<Button actionType={actionType} onClick={onConnectClick}>
Connect wallet
</Button>
)}
</Density>
)}

<Dialog isOpen={isOpen} onClose={() => setIsOpen(false)}>
<Dialog.Content title='Choose wallet'>
Expand Down
9 changes: 8 additions & 1 deletion src/pages/trade/ui/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { observer } from 'mobx-react-lite';
import { DurationWindow, durationWindows } from '@/shared/utils/duration.ts';
import { CandleWithVolume } from '@/shared/api/server/candles/utils';
import { BlockchainError } from '@/shared/ui/blockchain-error';

const ChartLoadingState = () => {
return (
Expand Down Expand Up @@ -260,7 +261,13 @@
))}
</div>

{error && <div className='text-white'>Error loading pair selector: ${String(error)}</div>}
{error && (
<div className='w-full h-full flex items-center justify-center'>
<div className='w-[450px] h-full flex items-center justify-center'>
<BlockchainError onDetailsClick={() => console.log('Details clicked')} />

Check failure on line 267 in src/pages/trade/ui/chart.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: in the near future, this should open the dialog, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the next step for this PR, I wanted a preliminary review regardless.

</div>
</div>
)}

<div className='grow w-full h-full max-h-full pt-2 pl-4 pb-4 self-center flex items-center'>
{isLoading && <ChartLoadingState />}
Expand Down
17 changes: 12 additions & 5 deletions src/pages/trade/ui/positions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import { ValueViewComponent } from '@penumbra-zone/ui/ValueView';
import dynamic from 'next/dynamic';
import { Density } from '@penumbra-zone/ui/Density';
import { Order, PositionData, stateToString, usePositions } from '@/pages/trade/api/positions.ts';
import { Button } from '@penumbra-zone/ui/Button';
import {
PositionId,
PositionState_PositionStateEnum,
} from '@penumbra-zone/protobuf/penumbra/core/component/dex/v1/dex_pb';
import { bech32mPositionId } from '@penumbra-zone/bech32m/plpid';
import { Button } from '@penumbra-zone/ui/Button';
import { positionsStore } from '@/pages/trade/model/positions';
import Link from 'next/link';
import { SquareArrowOutUpRight } from 'lucide-react';
import { SquareArrowOutUpRight, Wallet2 } from 'lucide-react';
import { ConnectButton } from '@/features/connect/connect-button';

const LoadingRow = () => {
return (
Expand All @@ -30,10 +31,16 @@ const LoadingRow = () => {

const NotConnectedNotice = () => {
return (
<div className='p-5'>
<Text small color='text.secondary'>
Connect your wallet
<div className='flex flex-col items-center justify-center h-[400px] gap-4'>
<div className='w-12 h-12 text-text-secondary'>
<Wallet2 className='w-full h-full' />
</div>
<Text color='text.secondary' small>
Connect wallet to see your positions
</Text>
<div className='w-fit'>
<ConnectButton variant='minimal' actionType='default' />
</div>
</div>
);
};
Expand Down
7 changes: 3 additions & 4 deletions src/pages/trade/ui/summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ValueViewComponent } from '@penumbra-zone/ui/ValueView';
import { round } from '@penumbra-zone/types/round';
import { Density } from '@penumbra-zone/ui/Density';
import { SummaryData } from '@/shared/api/server/summary/types.ts';
import { BlockchainError } from '@/shared/ui/blockchain-error';

const SummaryCard = ({
title,
Expand Down Expand Up @@ -49,9 +50,7 @@ export const Summary = () => {
if (error) {
return (
<SummaryCard title=''>
<Text detail color='destructive.light'>
{String(error)}
</Text>
<BlockchainError />
</SummaryCard>
);
}
Expand Down Expand Up @@ -95,7 +94,7 @@ export const Summary = () => {
</SummaryCard>
<SummaryCard title='24h Volume' loading={isLoading}>
{data && 'directVolume' in data ? (
<Density slim>
<Density compact>
<ValueViewComponent valueView={data.directVolume} context='table' abbreviate />
</Density>
) : (
Expand Down
26 changes: 26 additions & 0 deletions src/shared/ui/blockchain-error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Ban } from 'lucide-react';
import { Button } from '@penumbra-zone/ui/Button';
import { Density } from '@penumbra-zone/ui/Density';
import { Text } from '@penumbra-zone/ui/Text';

interface BlockchainErrorProps {
message?: string;
onDetailsClick?: () => void;
}

export function BlockchainError({
message = 'An error occurred when loading data from the blockchain',
onDetailsClick,
}: BlockchainErrorProps) {
return (
<Density compact>
<div className='flex flex-row items-center w-full justify-center gap-4 flex-wrap'>
<Ban className='h-8 w-8 text-red-400' />
<Text small color='text.secondary'>
{message}
</Text>
<Button onClick={onDetailsClick}>Details</Button>
</div>
</Density>
);
}
Loading