Skip to content

Commit

Permalink
feat: poc v2
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsimao committed Dec 4, 2024
1 parent 174ea7d commit 25e7e00
Show file tree
Hide file tree
Showing 25 changed files with 455 additions and 1,290 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 @@
"@yudiel/react-qr-scanner": "^2.0.4",
"@zerodev/sdk": "^5.3.4",
"big.js": "catalog:",
"bitcoin-address-validation": "^2.2.3",
"date-fns": "catalog:",
"graphql-request": "catalog:",
"negotiator": "catalog:",
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
12 changes: 5 additions & 7 deletions apps/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@
},
"dependencies": {
"@binance/w3w-wagmi-connector-v2": "1.2.4-alpha.0",
"@gobob/bob-sdk": "^3.1.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",
"@eth-optimism/sdk": "^3.1.6",
"@ethersproject/providers": "^5.7.2",
"@gobob/bob-sdk": "^3.1.0",
"@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 @@ -43,11 +40,12 @@
"@scure/base": "^1.1.9",
"@scure/btc-signer": "^1.4.0",
"@sentry/nextjs": "catalog:",
"@tanstack/react-store": "catalog:",
"@tanstack/react-query": "catalog:",
"@tanstack/react-store": "catalog:",
"@vercel/kv": "catalog:",
"@wagmi/core": "catalog:",
"big.js": "catalog:",
"bitcoin-address-validation": "catalog:",
"date-fns": "catalog:",
"graphql-request": "catalog:",
"lottie-react": "^2.4.0",
Expand All @@ -63,8 +61,8 @@
"use-count-up": "^3.0.1",
"usehooks-ts": "catalog:",
"viem": "catalog:",
"yup": "catalog:",
"wagmi": "catalog:"
"wagmi": "catalog:",
"yup": "catalog:"
},
"devDependencies": {
"@gobob/test-utils": "workspace:^",
Expand Down
6 changes: 2 additions & 4 deletions apps/evm/src/app/[lang]/(bridge)/hooks/useGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { GatewayQuoteParams } from '@gobob/bob-sdk';
import { Bitcoin, CurrencyAmount, ERC20Token } from '@gobob/currency';

import { BITCOIN } from '@gobob/tokens';
import { toast } from '@gobob/ui';
import { t } from '@lingui/macro';
Expand All @@ -20,9 +19,9 @@ import { Dispatch, SetStateAction, useCallback, useEffect, useMemo, useState } f
import { DebouncedState, useDebounceValue } from 'usehooks-ts';
import { Address, isAddress } from 'viem';
import { useAccount } from 'wagmi';
import { AddressType } from 'bitcoin-address-validation';

import { INTERVAL } from '@/constants';

import {
BtcFeeRateReturnType,
useBtcAccount,
Expand All @@ -41,7 +40,6 @@ import {
InitGatewayTransaction,
TransactionType
} from '@/types';
import { BtcAddressType } from '@gobob/utils';

const DUST_THRESHOLD = 1000;

Expand Down Expand Up @@ -176,7 +174,7 @@ const useGateway = ({ params, onError, onMutate, onSuccess }: UseGatewayLiquidit

const minAmount = useMemo(() => getMinAmount(isTopUpEnabled), [isTopUpEnabled]);

const isTapRootAddress = btcAddressType === BtcAddressType.p2tr;
const isTapRootAddress = btcAddressType === AddressType.p2tr;

const liquidityQueryEnabled = Boolean(
params.toChain && params.toToken && params.type === GatewayTransactionType.STAKE ? params.strategyAddress : true
Expand Down
4 changes: 2 additions & 2 deletions apps/evm/src/app/[lang]/sign-up/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const SignUp = (): JSX.Element | null => {

useAccountEffect({
onConnect: () => {
if (isConnecting) {
signUp({});
if (isConnecting && address) {
signUp(address);

setConnecting(false);
}
Expand Down
8 changes: 4 additions & 4 deletions apps/evm/src/components/AuthButton/AuthButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import { useDynamicContext, useDynamicModals } from '@dynamic-labs/sdk-react-core';
import { ChainId, getChainName } from '@gobob/chains';
import { Button, ButtonProps } from '@gobob/ui';
import { useAccount, useSwitchChain } from '@gobob/wagmi';
import { Trans } from '@lingui/macro';
import { PressEvent } from '@react-aria/interactions';
import { useIsClient } from 'usehooks-ts';
import { useAccount, useSwitchChain } from 'wagmi';

import { useBtcAccount } from '@/hooks';

Expand Down Expand Up @@ -71,8 +70,9 @@ const AuthButton = ({
const name = getChainName(chainProp);
const capitalizedName = name.charAt(0).toUpperCase() + name.slice(1);

const handlePress = async (e: PressEvent) => {
await switchChainAsync?.({ chainId: chainProp });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handlePress = async (e: any) => {
switchChainAsync?.({ chainId: chainProp });

if (shouldPressAfterSwitch) {
onPress?.(e);
Expand Down
50 changes: 50 additions & 0 deletions apps/evm/src/components/Layout/ConnectButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use client';

import { Button, Drawer } from '@gobob/ui';
import { truncateBtcAddress, truncateEthAddress } from '@gobob/utils';
import { Trans } from '@lingui/macro';
import { useAccount } from 'wagmi';
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { useState } from 'react';

import { useBtcAccount } from '@/hooks';

const ConnectButton = (): JSX.Element => {
const { setShowAuthFlow } = useDynamicContext();

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

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

const isAuthenticated = evmAddress || btcAddress;

if (!isAuthenticated) {
const handleConnect = () => {
setShowAuthFlow(true);
};

return (
<Button onPress={handleConnect}>
<Trans>Connect Wallet</Trans>
</Button>
);
}

const handleOpen = () => setOpen(true);

const handleClose = () => setOpen(false);

return (
<>
<Button onPress={handleOpen}>
{evmAddress ? truncateEthAddress(evmAddress) : btcAddress ? truncateBtcAddress(btcAddress) : undefined}
</Button>
<Drawer isOpen={isOpen} onClose={handleClose}>
Here
</Drawer>
</>
);
};

export { ConnectButton };
5 changes: 3 additions & 2 deletions apps/evm/src/components/Layout/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import { DynamicWidget } from '@dynamic-labs/sdk-react-core';
import {
Bars3,
Button,
Expand All @@ -26,6 +25,7 @@ import { StyledHeader, StyledLogoWrapper } from './Layout.style';
import { useLayoutContext } from './LayoutContext';
import { Nav } from './Nav';
import { NavItem } from './NavItem';
import { ConnectButton } from './ConnectButton';

import { DocsLinks, RoutesPath } from '@/constants';
import { useUserAgent } from '@/user-agent';
Expand Down Expand Up @@ -114,7 +114,8 @@ const Header = ({ isTestnet, isFusion, ...props }: HeaderProps): JSX.Element =>
</Popover>
<SocialsGroup hidden={isMobile} variant='ghost' />
<FusionPopover />
<DynamicWidget />
<ConnectButton />
{/* <DynamicWidget /> */}
</Flex>
</StyledHeader>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/evm/src/components/LoginButton/LoginButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mergeProps } from '@react-aria/utils';
import { useState } from 'react';
import { useAccount, useAccountEffect } from 'wagmi';

import { useGetUser, useLogin } from '@/hooks';
import { useLogin } from '@/hooks';

type LoginButtonProps = ButtonProps;

Expand Down
4 changes: 2 additions & 2 deletions apps/evm/src/components/SignUpButton/SignUpButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const SignUpButton = (props: SignUpButtonProps): JSX.Element => {

useAccountEffect({
onConnect: () => {
if (isConnecting) {
signUp({});
if (isConnecting && address) {
signUp(address);

setConnecting(false);
}
Expand Down
114 changes: 0 additions & 114 deletions apps/evm/src/connect-ui/component/AuthButton/AuthButton.tsx

This file was deleted.

Loading

0 comments on commit 25e7e00

Please sign in to comment.