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/profile activity #395

Merged
merged 10 commits into from
Jan 24, 2025
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
1 change: 0 additions & 1 deletion apps/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"@sentry/nextjs": "catalog:",
"@tanstack/react-query": "catalog:",
"@tanstack/react-store": "catalog:",
"@tanstack/react-virtual": "catalog:",
"@vercel/kv": "catalog:",
"@wagmi/core": "catalog:",
"big.js": "catalog:",
Expand Down
9 changes: 3 additions & 6 deletions apps/evm/src/app/[lang]/(bridge)/bridge/Bridge.style.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Card, Flex } from '@gobob/ui';
import { Card } from '@gobob/ui';
import styled from 'styled-components';

const StyledFlex = styled(Flex)`
width: 100%;
`;

const StyledCard = styled(Card)`
width: 100%;
min-width: 100%;
`;

export { StyledCard, StyledFlex };
export { StyledCard };
168 changes: 113 additions & 55 deletions apps/evm/src/app/[lang]/(bridge)/bridge/Bridge.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
'use client';

import { ChainId, getChainIdByChainName, getChainName } from '@gobob/chains';
import { Tabs, TabsItem } from '@gobob/ui';
import { useAccount as useSatsAccount } from '@gobob/sats-wagmi';
import { Button, Card, Flex, Skeleton, SolidClock, Span, Spinner, Tabs, TabsItem } from '@gobob/ui';
import { Trans } from '@lingui/macro';
import { useRouter } from 'next/navigation';
import { Key, useCallback, useEffect, useMemo, useState } from 'react';
import { useAccount } from 'wagmi';

import { Layout, TransactionList } from '../components';
import { BannerCarousel } from '../components/BannerCarousel';

import { StyledCard, StyledFlex } from './Bridge.style';
import { StyledCard } from './Bridge.style';
import { BridgeForm } from './components';
import { useGetTransactions } from './hooks';

import { Main } from '@/components';
import { useConnectModal } from '@/connect-ui';
import { L1_CHAIN, L2_CHAIN } from '@/constants';
import { useGetBridgeTransactions } from '@/hooks';
import { SharedStoreProfileTxStatus, SharedStoreProfileTxType, store } from '@/lib/store';
import { TransactionDirection } from '@/types';

const externalUnsupportedTokens = ['LBTC'];
Expand Down Expand Up @@ -50,15 +55,16 @@ interface Props {
}

const Bridge = ({ searchParams }: Props) => {
const {
data: transactions,
isInitialLoading: isTransactionsInitialLoading,
refetch,
txPendingUserAction
} = useGetTransactions();

const router = useRouter();

const { txPendingUserAction, isPending } = useGetBridgeTransactions();
const { open } = useConnectModal();

const { address: evmAddress } = useAccount();
const { address: btcAddress } = useSatsAccount();

const isLoggedIn = !!(evmAddress || btcAddress);

const urlSearchParams = useMemo(() => new URLSearchParams(searchParams), [searchParams]);
const type = (urlSearchParams.get('type') as Type) || Type.Deposit;
const direction = type === Type.Deposit ? TransactionDirection.L1_TO_L2 : TransactionDirection.L2_TO_L1;
Expand Down Expand Up @@ -122,6 +128,37 @@ const Bridge = ({ searchParams }: Props) => {
urlSearchParams.set('network', network);
};

const hasPendingTx = txPendingUserAction && txPendingUserAction > 0;

const handleOpenProfile = () => {
store.setState((state) => ({
...state,
shared: {
...state.shared,
profile: {
...state.shared.profile,
isOpen: true,
selectedTab: 'activity',
transactions: {
filters: {
...state.shared.profile.transactions.filters,
status: hasPendingTx ? SharedStoreProfileTxStatus.NEEDED_ACTION : undefined,
type: SharedStoreProfileTxType.NATIVE_BRIDGE
}
}
}
}
}));
};

const handleActivity = () => {
if (!isLoggedIn) {
return open({ onConnectBtc: handleOpenProfile, onConnectEvm: handleOpenProfile });
}

handleOpenProfile();
};

useEffect(() => {
const chain = getChain();

Expand All @@ -140,51 +177,72 @@ const Bridge = ({ searchParams }: Props) => {
const tabsDisabledKeys = isWithdrawTabDisabled ? [Type.Withdraw] : undefined;

return (
<Layout>
<StyledFlex alignItems='flex-start' direction={{ base: 'column', md: 'row' }} gap='2xl' marginTop='xl'>
<StyledCard>
<Tabs
fullWidth
disabledKeys={tabsDisabledKeys}
selectedKey={type}
size='lg'
onSelectionChange={handleChangeTab}
>
<TabsItem key={Type.Deposit} title={<Trans>Deposit</Trans>}>
<></>
</TabsItem>
<TabsItem
key={Type.Withdraw}
title={<Trans>Withdraw</Trans>}
tooltipProps={{
isDisabled: !isWithdrawTabDisabled,
label: <Trans>Withdrawals back to BTC are currently not supported</Trans>
}}
<Main maxWidth='lg' padding='md'>
<BannerCarousel hasImgOpacity />
<Flex justifyContent='center' marginTop='2xl' style={{ width: '100%' }}>
<Flex direction='column' gap='md' style={{ width: '100%' }}>
<Flex justifyContent='flex-end'>
<Button size='s' style={{ gap: 4, alignItems: 'center' }} onPress={handleActivity}>
<SolidClock />
{isLoggedIn && isPending ? (
<Skeleton height='1.5rem' width='5rem' />
) : txPendingUserAction && txPendingUserAction > 0 ? (
<Card
alignItems='center'
background='primary-500'
direction='row'
gap='s'
paddingX='md'
paddingY='xs'
rounded='s'
>
<Span size='xs'>
<Trans>Action needed</Trans>
</Span>
<Spinner color='default' size='12' thickness={2} />
</Card>
) : (
<Trans>Activity</Trans>
)}
</Button>
</Flex>
<StyledCard>
<Tabs
fullWidth
disabledKeys={tabsDisabledKeys}
selectedKey={type}
size='lg'
onSelectionChange={handleChangeTab}
>
<></>
</TabsItem>
</Tabs>
<BridgeForm
bridgeOrigin={bridgeOrigin}
chain={chain}
direction={direction}
isBobBridgeDisabled={isBobBridgeDisabled}
isExternalBridgeDisabled={isExternalBridgeDisabled}
symbol={symbol}
onChangeChain={handleChangeChain}
onChangeOrigin={handleChangeOrigin}
onChangeSymbol={handleChangeSymbol}
/>
</StyledCard>
<TransactionList
data={transactions}
isInitialLoading={isTransactionsInitialLoading}
txPendingUserAction={txPendingUserAction}
onProveSuccess={refetch.bridge}
onRelaySuccess={refetch.bridge}
/>
</StyledFlex>
</Layout>
<TabsItem key={Type.Deposit} title={<Trans>Deposit</Trans>}>
<></>
</TabsItem>
<TabsItem
key={Type.Withdraw}
title={<Trans>Withdraw</Trans>}
tooltipProps={{
isDisabled: !isWithdrawTabDisabled,
label: <Trans>Withdrawals back to BTC are currently not supported</Trans>
}}
>
<></>
</TabsItem>
</Tabs>
<BridgeForm
bridgeOrigin={bridgeOrigin}
chain={chain}
direction={direction}
isBobBridgeDisabled={isBobBridgeDisabled}
isExternalBridgeDisabled={isExternalBridgeDisabled}
symbol={symbol}
onChangeChain={handleChangeChain}
onChangeOrigin={handleChangeOrigin}
onChangeSymbol={handleChangeSymbol}
/>
</StyledCard>
</Flex>
</Flex>
</Main>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ const BobBridgeForm = ({
to: recipient,
l1Token: l1Address,
l2Token: l2Address,
type: TransactionType.Bridge
type: TransactionType.Bridge,
logoUrl: selectedToken.l1Token.logoUrl
};

const to = recipient || address!;
Expand Down Expand Up @@ -297,7 +298,8 @@ const BobBridgeForm = ({
to: recipient,
l1Token: l1Address,
l2Token: l2Address,
type: TransactionType.Bridge
type: TransactionType.Bridge,
logoUrl: selectedToken.l2Token.logoUrl
};

const to = recipient || address!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { useAccount as useSatsAccount } from '@gobob/sats-wagmi';

import { BridgeTransactionModal, GatewayTransactionModal } from '../../../components';
import { BridgeOrigin } from '../../Bridge';
import { useGetTransactions } from '../../hooks';
import { ChainSelect } from '../ChainSelect';
import { ExternalBridgeForm } from '../ExternalBridgeForm';

Expand All @@ -22,7 +21,7 @@ import { StyledChainsGrid, StyledRadio } from './BridgeForm.style';
import { BtcBridgeForm } from './BtcBridgeForm';

import { INTERVAL, L1_CHAIN, L2_CHAIN } from '@/constants';
import { TokenData } from '@/hooks';
import { TokenData, useGetBridgeTransactions, useGetGatewayTransactions } from '@/hooks';
import { gatewaySDK } from '@/lib/bob-sdk';
import { bridgeKeys } from '@/lib/react-query';
import { BridgeTransaction, InitBridgeTransaction, InitGatewayTransaction, TransactionDirection } from '@/types';
Expand Down Expand Up @@ -80,7 +79,9 @@ const BridgeForm = ({
const { i18n } = useLingui();
const { connector } = useSatsAccount();

const { refetch: refetchTransactions, addPlaceholderTransaction } = useGetTransactions();
const { refetch: refetchBridgeTransactions, addPlaceholderTransaction: addBridgePlaceholderTransaction } =
useGetBridgeTransactions();
const { refetch: refetchGatewayTransactions } = useGetGatewayTransactions();

const [bridgeModalState, setBridgeModalState] = useState<TransactionModalState>({
isOpen: false,
Expand Down Expand Up @@ -120,9 +121,9 @@ const BridgeForm = ({
};

const handleBridgeSuccess = (data: BridgeTransaction) => {
addPlaceholderTransaction.bridge(data);
addBridgePlaceholderTransaction(data);

refetchTransactions.bridge();
refetchBridgeTransactions();

setBridgeModalState({ isOpen: true, data, step: 'submitted' });
};
Expand All @@ -140,7 +141,7 @@ const BridgeForm = ({
};

const handleGatewaySuccess = (data: InitGatewayTransaction) => {
refetchTransactions.gateway();
refetchGatewayTransactions();

setGatewayModalState({ isOpen: true, data });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { CurrencyAmount, ERC20Token } from '@gobob/currency';
import { Alert, Avatar, Flex, Input, Item, P, Select, Skeleton, Link } from '@gobob/ui';
import { Alert, Avatar, Flex, Input, Item, Link, P, Select, Skeleton } from '@gobob/ui';
import { t, Trans } from '@lingui/macro';
import { useLingui } from '@lingui/react';
import { chain, mergeProps } from '@react-aria/utils';
Expand All @@ -10,11 +10,11 @@ import { useMemo } from 'react';
import { useAccount } from 'wagmi';

import { BtcTokenInput, GatewayGasSwitch, GatewayTransactionDetails } from '../../../components';
import { useGateway, useGatewayForm, useGetGatewayTransactions } from '../../../hooks';
import { useGateway, useGatewayForm } from '../../../hooks';

import { AuthButton } from '@/connect-ui';
import { isProd, mempoolUrl } from '@/constants';
import { TokenData } from '@/hooks';
import { TokenData, useGetGatewayTransactions } from '@/hooks';
import { BRIDGE_RECIPIENT, BridgeFormValues } from '@/lib/form/bridge';
import { GatewayTransactionType, InitGatewayTransaction } from '@/types';

Expand Down
1 change: 0 additions & 1 deletion apps/evm/src/app/[lang]/(bridge)/bridge/hooks/index.ts

This file was deleted.

Loading