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

New Tab: IBC #795

Merged
merged 5 commits into from
Mar 20, 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
Expand Up @@ -33,8 +33,8 @@ export const TransactionApproval = () => {

return (
<div className='flex h-screen flex-col justify-between'>
<div className='grow overflow-auto p-[30px] pt-10'>
<p className='bg-text-linear bg-clip-text font-headline text-2xl font-bold text-transparent'>
<div className='grow overflow-auto p-[30px] pb-44 pt-10'>
<p className='bg-text-linear bg-clip-text pb-2 font-headline text-2xl font-bold text-transparent'>
Comment on lines +36 to +37
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixes bug where tx approval window does not scroll all the way down given approve/deny buttons overlap it with a fixed position

Confirm transaction
</p>

Expand Down
2 changes: 1 addition & 1 deletion apps/minifront/src/components/extension-unavailable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const ExtensionUnavailable = () => {
<>
<HeadTag />

<SplashPage title='Penumbra extension unavailble'>
<SplashPage title='Penumbra extension unavailable'>
<p className='mb-2'>We can&apos;t currently connect to the Penumbra extension.</p>
<p className='mb-2'>
This page may have been left open for too long, causing a timeout. Please reload this page
Expand Down
6 changes: 3 additions & 3 deletions apps/minifront/src/components/header/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const headerLinks: HeaderLink[] = [
href: PagePath.SEND,
label: 'Send',
active: true,
subLinks: [PagePath.RECEIVE, PagePath.IBC],
subLinks: [PagePath.RECEIVE],
mobileIcon: <ArrowTopRightIcon className='size-5 text-muted-foreground' />,
},
{
Expand All @@ -39,8 +39,8 @@ export const headerLinks: HeaderLink[] = [
mobileIcon: <TextAlignLeftIcon className='size-5 text-muted-foreground' />,
},
{
href: PagePath.GOVERNANCE,
label: 'Governance',
href: PagePath.IBC,
label: 'IBC',
active: false,
mobileIcon: <MixerHorizontalIcon className='size-5 text-muted-foreground' />,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@penumbra-zone/ui';
import { cn } from '@penumbra-zone/ui/lib/utils';
import { useState } from 'react';
import { useStore } from '../../../state';
import { ibcSelector } from '../../../state/ibc';
import { testnetIbcChains } from '@penumbra-zone/constants/src/chains';
import { useStore } from '../../state';
import { ibcSelector } from '../../state/ibc';

export const ChainSelector = () => {
const { chain, setChain } = useStore(ibcSelector);
Expand Down Expand Up @@ -34,7 +34,7 @@ export const ChainSelector = () => {
key={index}
value={i.displayName}
className={cn(
'hover:bg-brown ',
'hover:bg-brown',
chain?.displayName === i.displayName && 'bg-charcoal-secondary',
)}
>
Expand Down
9 changes: 9 additions & 0 deletions apps/minifront/src/components/ibc/ibc-in-form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Card } from '@penumbra-zone/ui';

export const IbcInForm = () => {
return (
<Card gradient className='md:p-5'>
To come...
</Card>
);
};
25 changes: 25 additions & 0 deletions apps/minifront/src/components/ibc/ibc-loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { LoaderFunction } from 'react-router-dom';
import { testnetIbcChains } from '@penumbra-zone/constants/src/chains';
import { BalancesResponse } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';
import { getBalances } from '../../fetchers/balances';
import { useStore } from '../../state';
import { filterBalancesPerChain } from '../../state/ibc';

export type IbcLoaderResponse = BalancesResponse[];

export const IbcLoader: LoaderFunction = async (): Promise<IbcLoaderResponse> => {
const assetBalances = await getBalances();

if (assetBalances[0]) {
const initialChain = testnetIbcChains[0];
const initialSelection = filterBalancesPerChain(assetBalances, initialChain)[0];

// set initial account if accounts exist and asset if account has asset list
useStore.setState(state => {
state.ibc.selection = initialSelection;
state.ibc.chain = initialChain;
});
}

return assetBalances;
};
90 changes: 90 additions & 0 deletions apps/minifront/src/components/ibc/ibc-out-form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { Button, Card, Input } from '@penumbra-zone/ui';
import { ChainSelector } from './chain-selector';
import { useLoaderData } from 'react-router-dom';
import { useStore } from '../../state';
import { filterBalancesPerChain, ibcSelector, ibcValidationErrors } from '../../state/ibc';
import InputToken from '../shared/input-token';
import { InputBlock } from '../shared/input-block';
import { IbcLoaderResponse } from './ibc-loader';

export const IbcOutForm = () => {
const assetBalances = useLoaderData() as IbcLoaderResponse;
const {
sendIbcWithdraw,
destinationChainAddress,
setDestinationChainAddress,
amount,
setAmount,
selection,
setSelection,
chain,
} = useStore(ibcSelector);
const filteredBalances = filterBalancesPerChain(assetBalances, chain);
const validationErrors = useStore(ibcValidationErrors);

return (
<Card gradient className='md:p-5'>
<form
className='flex flex-col gap-4'
onSubmit={e => {
e.preventDefault();
void sendIbcWithdraw();
}}
>
<ChainSelector />
<InputToken
label='Amount to send'
placeholder='Enter an amount'
className='mb-1'
selection={selection}
setSelection={setSelection}
value={amount}
onChange={e => {
if (Number(e.target.value) < 0) return;
setAmount(e.target.value);
}}
validations={[
{
type: 'error',
issue: 'insufficient funds',
checkFn: () => validationErrors.amountErr,
},
]}
balances={filteredBalances}
/>
<InputBlock
label='Recipient on destination chain'
className='mb-1'
value={destinationChainAddress}
validations={[
{
type: 'error',
issue: 'address not valid',
checkFn: () => validationErrors.recipientErr,
},
]}
>
<Input
variant='transparent'
placeholder='Enter the address'
value={destinationChainAddress}
onChange={e => setDestinationChainAddress(e.target.value)}
/>
</InputBlock>
<Button
type='submit'
variant='gradient'
className='mt-9'
disabled={
!Number(amount) ||
!destinationChainAddress ||
!!Object.values(validationErrors).find(Boolean) ||
!selection
}
>
Send
</Button>
</form>
</Card>
);
};
11 changes: 11 additions & 0 deletions apps/minifront/src/components/ibc/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IbcInForm } from './ibc-in-form';
import { IbcOutForm } from './ibc-out-form';

export const IbcLayout = () => {
return (
<div className='grid md:grid-cols-2 md:gap-5'>
<IbcInForm />
<IbcOutForm />
</div>
);
};
4 changes: 0 additions & 4 deletions apps/minifront/src/components/metadata/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ export const metadata: Record<PagePath, PageMetadata> = {
title: 'Penumbra | Swap',
description: eduPanelContent[EduPanel.TEMP_FILLER],
},
[PagePath.GOVERNANCE]: {
title: 'Penumbra | Governance',
description: eduPanelContent[EduPanel.TEMP_FILLER],
},
[PagePath.STAKING]: {
title: 'Penumbra | Staking',
description: eduPanelContent[EduPanel.TEMP_FILLER],
Expand Down
3 changes: 1 addition & 2 deletions apps/minifront/src/components/metadata/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ export enum PagePath {
INDEX = '/',
SWAP = '/swap',
SEND = '/send',
GOVERNANCE = '/governance',
STAKING = '/staking',
RECEIVE = '/send/receive',
TRANSACTIONS = '/dashboard/transactions',
DASHBOARD = '/dashboard',
IBC = '/send/ibc',
IBC = '/ibc',
NFTS = '/dashboard/nfts',
TRANSACTION_DETAILS = '/tx/:hash',
}
13 changes: 7 additions & 6 deletions apps/minifront/src/components/root-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { DashboardLayout } from './dashboard/layout';
import { TxDetails, TxDetailsErrorBoundary, TxDetailsLoader } from './tx-details';
import { SendLayout } from './send/layout';
import { SendAssetBalanceLoader, SendForm } from './send/send-form';
import IbcForm, { IbcAssetBalanceLoader } from './send/ibc/ibc-form';
import { Receive } from './send/receive';
import { ErrorBoundary } from './shared/error-boundary';
import { SwapLayout } from './swap/layout';
import { SwapLoader } from './swap/swap-loader';
import { StakingLayout, StakingLoader } from './staking/layout';
import { IbcLoader } from './ibc/ibc-loader';
import { IbcLayout } from './ibc/layout';

export const rootRouter = createHashRouter([
{
Expand Down Expand Up @@ -53,11 +54,6 @@ export const rootRouter = createHashRouter([
path: PagePath.RECEIVE,
element: <Receive />,
},
{
path: PagePath.IBC,
loader: IbcAssetBalanceLoader,
element: <IbcForm />,
},
],
},
{
Expand All @@ -76,6 +72,11 @@ export const rootRouter = createHashRouter([
loader: StakingLoader,
element: <StakingLayout />,
},
{
path: PagePath.IBC,
loader: IbcLoader,
element: <IbcLayout />,
},
],
},
]);
6 changes: 0 additions & 6 deletions apps/minifront/src/components/send/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ export const sendTabsHelper: SendTabMap = {
label: 'Receiving Funds',
content: EduPanel.RECEIVING_FUNDS,
},
[PagePath.IBC]: {
src: './ibc-gradient.svg',
label: 'IBC withdraw',
content: EduPanel.IBC_WITHDRAW,
},
};

export const sendTabs = [
{ title: 'Send', href: PagePath.SEND, active: true },
{ title: 'Receive', href: PagePath.RECEIVE, active: true },
{ title: 'IBC', href: PagePath.IBC, active: false },
];
117 changes: 0 additions & 117 deletions apps/minifront/src/components/send/ibc/ibc-form.tsx

This file was deleted.

Loading
Loading