Skip to content

Commit

Permalink
feat(evm): add dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsimao committed Jan 30, 2025
1 parent db5ab1c commit 5f28e22
Show file tree
Hide file tree
Showing 69 changed files with 1,421 additions and 1,355 deletions.
1 change: 1 addition & 0 deletions apps/bob-pay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@wagmi/core": "catalog:",
"@yudiel/react-qr-scanner": "^2.0.4",
"@zerodev/sdk": "^5.3.4",
"bitcoin-address-validation": "catalog:",
"big.js": "catalog:",
"date-fns": "catalog:",
"graphql-request": "catalog:",
Expand Down
12 changes: 6 additions & 6 deletions apps/bob-pay/src/app/[lang]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Metadata } from 'next';
import { Inter, Chakra_Petch } from 'next/font/google';
import { PropsWithChildren } from 'react';
import { t } from '@lingui/macro';
import { GoogleAnalytics, GoogleTagManager } from '@next/third-parties/google';
import { cookieToInitialState } from 'wagmi';
import { Metadata } from 'next';
import { Chakra_Petch, Inter } from 'next/font/google';
import { headers } from 'next/headers';
import { PropsWithChildren } from 'react';
import { cookieToInitialState } from 'wagmi';

import linguiConfig from '../../../lingui.config';

Expand All @@ -15,8 +15,8 @@ import { allMessages, getI18nInstance } from '@/i18n/appRouterI18n';
import { LinguiClientProvider } from '@/i18n/provider';
import { PageLangParam, withLinguiLayout } from '@/i18n/withLigui';

const chakraPetch = Chakra_Petch({ subsets: ['latin'], display: 'swap', weight: '700' });
const inter = Inter({ subsets: ['latin'], display: 'swap' });
const chakraPetch = Chakra_Petch({ subsets: ['latin'], display: 'swap', weight: '700' });

export async function generateStaticParams() {
return linguiConfig.locales.map((lang) => ({ lang }));
Expand Down Expand Up @@ -65,7 +65,7 @@ export default withLinguiLayout(function LangLayout({ children, params: { lang }
const initialState = cookieToInitialState(config, headers().get('cookie'));

return (
<html className={`${chakraPetch.className} ${inter.className}`} lang={lang}>
<html className={`${inter.className} ${chakraPetch.className}`} lang={lang}>
<GoogleTagManager gtmId={process.env.NEXT_PUBLIC_GTM_ID} />
<GoogleAnalytics gaId={process.env.NEXT_PUBLIC_GA_ID} />
<body>
Expand Down
4 changes: 2 additions & 2 deletions apps/bob-pay/src/lib/form/yup.custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Big from 'big.js';
import * as yup from 'yup';
import { AnyObject, Maybe } from 'yup/lib/types';
import { isValidBTCAddress, BitcoinNetwork } from '@gobob/utils';
import { validate, Network as BitcoinNetwork } from 'bitcoin-address-validation';
import { isAddress } from 'viem';

yup.addMethod<yup.StringSchema>(yup.string, 'requiredAmount', function (action: string, customMessage?: string) {
Expand Down Expand Up @@ -73,7 +73,7 @@ yup.addMethod<yup.StringSchema>(

yup.addMethod<yup.StringSchema>(yup.string, 'btcAddress', function (network: BitcoinNetwork, customMessage?: string) {
return this.test('btcAddress', (value, ctx) => {
if (!value || !isValidBTCAddress(value, network)) {
if (!value || !validate(value, network)) {
const message = customMessage || 'Please enter a valid address';

return ctx.createError({ message });
Expand Down
10 changes: 9 additions & 1 deletion apps/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@
},
"dependencies": {
"@binance/w3w-wagmi-connector-v2": "1.2.4-alpha.0",
"@dynamic-labs/bitcoin": "^3.6.2",
"@dynamic-labs/ethereum": "^3.6.2",
"@dynamic-labs/iconic": "^3.6.2",
"@dynamic-labs/sdk-react-core": "^3.6.2",
"@dynamic-labs/wagmi-connector": "^3.6.2",
"@dynamic-labs/wallet-book": "^3.8.5",
"@gobob/bob-sdk": "^3.1.2",
"@gobob/chains": "workspace:^",
"@gobob/currency": "workspace:^",
"@gobob/hooks": "workspace:^",
"@gobob/icons": "workspace:^",
"@gobob/sats-wagmi": "workspace:^",
"@gobob/tokens": "workspace:^",
"@gobob/ui": "workspace:^",
"@gobob/utils": "workspace:^",
Expand All @@ -34,12 +39,15 @@
"@react-aria/interactions": "catalog:",
"@react-aria/label": "^3.7.6",
"@react-aria/utils": "catalog:",
"@scure/base": "^1.1.9",
"@scure/btc-signer": "^1.4.0",
"@sentry/nextjs": "catalog:",
"@tanstack/react-query": "catalog:",
"@tanstack/react-store": "catalog:",
"@vercel/kv": "catalog:",
"@wagmi/core": "catalog:",
"big.js": "catalog:",
"bitcoin-address-validation": "catalog:",
"boring-avatars": "^1.11.2",
"date-fns": "catalog:",
"graphql-request": "catalog:",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { Button, Card, Flex, Skeleton, SolidClock, Span, Spinner } from '@gobob/ui';
import { Trans } from '@lingui/macro';
import { useAccount } from 'wagmi';
import { useAccount as useSatsAccount } from '@gobob/sats-wagmi';

import { useBtcAccount, useGetBridgeTransactions } from '@/hooks';
import { SharedStoreProfileTxStatus, SharedStoreProfileTxType, ShareStoreProfileTabs, store } from '@/lib/store';
import { useGetBridgeTransactions } from '@/hooks';
import { useConnectModal } from '@/connect-ui';

const ActivityButton = (): JSX.Element => {
const { address: evmAddress } = useAccount();
const { address: btcAddress } = useSatsAccount();
const { address: btcAddress } = useBtcAccount();
const { txPendingUserAction, isPending: isBridgeTxPending } = useGetBridgeTransactions();
const { open } = useConnectModal();

const handleOpenProfile = () => {
store.setState((state) => ({
Expand All @@ -38,7 +35,9 @@ const ActivityButton = (): JSX.Element => {

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

handleOpenProfile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import { USDC } from '@gobob/tokens';
import { Flex, Input, TokenInput, TokenSelectItemProps, toast, useForm } from '@gobob/ui';
import { t } from '@lingui/macro';
import { useLingui } from '@lingui/react';
import { sendGAEvent } from '@next/third-parties/google';
import { mergeProps } from '@react-aria/utils';
import { useMutation } from '@tanstack/react-query';
import Big from 'big.js';
import { useEffect, useMemo, useState } from 'react';
import { useDebounceValue } from 'usehooks-ts';
import { Address } from 'viem';
import { useAccount, usePublicClient } from 'wagmi';
import { sendGAEvent } from '@next/third-parties/google';

import { BridgeAlert } from './BridgeAlert';

import { l1StandardBridgeAbi } from '@/abis/L1StandardBridge.abi';
import { l2StandardBridgeAbi } from '@/abis/L2StandardBridge.abi';
import { AuthButton } from '@/connect-ui';
import { AuthButton } from '@/components';
import { L1_CHAIN, L2_CHAIN, publicClientL1, publicClientL2 } from '@/constants';
import { bridgeContracts } from '@/constants/bridge';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { Token } from '@gobob/currency';
import { Alert, ArrowRight, Divider, Flex, RadioGroup } from '@gobob/ui';
import { Trans, t } from '@lingui/macro';
import { useLingui } from '@lingui/react';
import { sendGAEvent } from '@next/third-parties/google';
import { useQuery } from '@tanstack/react-query';
import { Key, useCallback, useMemo, useState } from 'react';
import { useAccount, useChainId } from 'wagmi';
import { sendGAEvent } from '@next/third-parties/google';
import { useAccount as useSatsAccount } from '@gobob/sats-wagmi';

import { BridgeTransactionModal, GatewayTransactionModal } from '../../../components';
import { BridgeOrigin } from '../../Bridge';
Expand All @@ -21,7 +20,7 @@ import { StyledChainsGrid, StyledRadio } from './BridgeForm.style';
import { BtcBridgeForm } from './BtcBridgeForm';

import { INTERVAL, L1_CHAIN, L2_CHAIN } from '@/constants';
import { TokenData, useGetBridgeTransactions, useGetGatewayTransactions } from '@/hooks';
import { TokenData, useBtcAccount, 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 @@ -77,8 +76,8 @@ const BridgeForm = ({
onChangeChain
}: BridgeFormProps): JSX.Element => {
const { i18n } = useLingui();
const { connector: satsConnector, address: btcAddress } = useSatsAccount();
const { connector, address } = useAccount();
const { address: btcAddress, connector: btcConnector } = useBtcAccount();

const { refetch: refetchBridgeTransactions, addPlaceholderTransaction: addBridgePlaceholderTransaction } =
useGetBridgeTransactions();
Expand Down Expand Up @@ -152,7 +151,7 @@ const BridgeForm = ({
tx_id: data.txId,
evm_address: JSON.stringify(address),
btc_address: btcAddress,
btc_wallet: satsConnector?.name,
btc_wallet: btcConnector?.name,
evm_wallet: connector?.name
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useAccount } from 'wagmi';
import { BtcTokenInput, GatewayGasSwitch, GatewayTransactionDetails } from '../../../components';
import { useGateway, useGatewayForm } from '../../../hooks';

import { AuthButton } from '@/connect-ui';
import { AuthButton } from '@/components';
import { isProd } from '@/constants';
import { TokenData } from '@/hooks';
import { BRIDGE_RECIPIENT, BridgeFormValues } from '@/lib/form/bridge';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Currency, CurrencyAmount } from '@gobob/currency';
import { useAccount as useSatsAccount } from '@gobob/sats-wagmi';
import { BITCOIN } from '@gobob/tokens';
import {
Alert,
Expand Down Expand Up @@ -27,6 +26,7 @@ import { GatewayFeeSettingsModal } from './GatewayFeeSettingsModal';
import { StyledDlGroup, StyledDt } from './GatewayTransactionDetails.style';

import { AmountLabel } from '@/components';
import { useBtcAccount } from '@/hooks';
import { GatewayTransactionType } from '@/types';

type GatewayTransactionDetailsProps = {
Expand All @@ -50,7 +50,7 @@ const GatewayTransactionDetails = ({
}: GatewayTransactionDetailsProps): JSX.Element => {
const { i18n } = useLingui();

const { address: btcAddress } = useSatsAccount();
const { address: btcAddress } = useBtcAccount();

const [isOpen, setOpen] = useState(false);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useAccount as useSatsAccount } from '@gobob/sats-wagmi';
import { act, renderHook } from '@testing-library/react-hooks';
import { describe, expect, it, Mock, vi } from 'vitest';
import { useAccount } from 'wagmi';

import { useGateway } from '../useGateway';

import { useBtcAccount } from '@/hooks/btc';
import { wrapper } from '@/test-utils';
import { GatewayTransactionType } from '@/types';

Expand All @@ -17,12 +17,12 @@ vi.mock(import('wagmi'), async (importOriginal) => {
};
});

vi.mock(import('@gobob/sats-wagmi'), async (importOriginal) => {
vi.mock(import('@/hooks/btc'), async (importOriginal) => {
const actual = await importOriginal();

return {
...actual,
useAccount: vi.fn()
useBtcAccount: vi.fn()
};
});

Expand All @@ -31,7 +31,7 @@ describe('useGateway', () => {
vi.clearAllMocks();

(useAccount as Mock).mockReturnValue({ address: '0x123456789abcdef' });
(useSatsAccount as Mock).mockReturnValue({ connector: vi.fn() });
(useBtcAccount as Mock).mockReturnValue({ connector: vi.fn() });
});

it('should initialize correctly with default settings', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useAccount as useSatsAccount } from '@gobob/sats-wagmi';
import { act, renderHook } from '@testing-library/react-hooks';
import { Mock, vi } from 'vitest';
import { useAccount } from 'wagmi';

import { useGatewayForm } from '../useGatewayForm';

import { useBtcAccount } from '@/hooks/btc';
import { useIsContract } from '@/hooks';
import { BRIDGE_AMOUNT, BRIDGE_ASSET, BRIDGE_RECIPIENT } from '@/lib/form/bridge';
import { GatewayTransactionType } from '@/types';
Expand All @@ -27,12 +27,12 @@ vi.mock(import('@/hooks'), async (importOriginal) => {
};
});

vi.mock(import('@gobob/sats-wagmi'), async (importOriginal) => {
vi.mock(import('@/hooks/btc'), async (importOriginal) => {
const actual = await importOriginal();

return {
...actual,
useAccount: vi.fn()
useBtcAccount: vi.fn()
};
});

Expand All @@ -49,7 +49,7 @@ describe('useGatewayForm', () => {
beforeEach(() => {
(useAccount as Mock).mockReturnValue({ address: '0x123' });
(useIsContract as Mock).mockReturnValue({ isContract: false });
(useSatsAccount as Mock).mockReturnValue({ address: 'bc1qaddress' });
(useBtcAccount as Mock).mockReturnValue({ address: 'bc1qaddress' });
});

it('should initialize with correct default values', () => {
Expand Down
Loading

0 comments on commit 5f28e22

Please sign in to comment.