Skip to content

Commit

Permalink
remove project id
Browse files Browse the repository at this point in the history
  • Loading branch information
alissacrane-cb committed Dec 17, 2024
1 parent fe9c92b commit 215761b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/buy/components/Buy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export function Buy({
onSuccess,
toToken,
fromToken,
projectId,
}: BuyReact) {
return (
<BuyProvider
Expand All @@ -57,7 +56,6 @@ export function Buy({
onSuccess={onSuccess}
toToken={toToken}
fromToken={fromToken}
projectId={projectId}
>
<BuyContent className={className} />
</BuyProvider>
Expand Down
9 changes: 8 additions & 1 deletion src/buy/components/BuyDropdown.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { openPopup } from '@/ui-react/internal/utils/openPopup';
import { act, fireEvent, render, screen } from '@testing-library/react';
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import { useOnchainKit } from '../../core-react/useOnchainKit';
import { BuyDropdown } from './BuyDropdown';
import { useBuyContext } from './BuyProvider';
import { degenToken, ethToken, usdcToken } from '../../token/constants';
Expand Down Expand Up @@ -29,6 +30,10 @@ vi.mock('wagmi', async () => {
};
});

vi.mock('../../core-react/useOnchainKit', () => ({
useOnchainKit: vi.fn(),
}));

const mockStartPopupMonitor = vi.fn();

const mockContextValue = {
Expand All @@ -40,7 +45,6 @@ const mockContextValue = {
fromETH: { token: ethToken },
fromUSDC: { token: usdcToken },
from: { token: { symbol: 'DAI' } },
projectId: 'mock-project-id',
startPopupMonitor: mockStartPopupMonitor,
setIsDropdownOpen: vi.fn(),
};
Expand All @@ -49,6 +53,9 @@ describe('BuyDropdown', () => {
beforeEach(() => {
vi.clearAllMocks();
(useBuyContext as Mock).mockReturnValue(mockContextValue);
(useOnchainKit as Mock).mockReturnValue({
projectId: 'mock-project-id',
});
});

it('renders the dropdown with correct content', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/buy/components/BuyDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useOnchainKit } from '@/core-react/useOnchainKit';
import { openPopup } from '@/ui-react/internal/utils/openPopup';
import { useCallback, useMemo } from 'react';
import { useAccount } from 'wagmi';
Expand All @@ -11,8 +12,8 @@ import { useBuyContext } from './BuyProvider';
import { BuyTokenItem } from './BuyTokenItem';

export function BuyDropdown() {
const { to, fromETH, fromUSDC, from, projectId, startPopupMonitor } =
useBuyContext();
const { projectId } = useOnchainKit();
const { to, fromETH, fromUSDC, from, startPopupMonitor } = useBuyContext();
const { address } = useAccount();

const handleOnrampClick = useCallback(
Expand Down
3 changes: 0 additions & 3 deletions src/buy/components/BuyProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ const wrapper = ({ children }: { children: React.ReactNode }) => (
config={{ maxSlippage: 5 }}
experimental={{ useAggregator: true }}
toToken={degenToken}
projectId="mock-project-id"
fromToken={daiToken}
>
{children}
Expand Down Expand Up @@ -178,7 +177,6 @@ const renderWithProviders = ({
onSuccess={onSuccess}
toToken={degenToken}
fromToken={daiToken}
projectId="mock-project-id"
>
<Component />
</BuyProvider>
Expand Down Expand Up @@ -829,7 +827,6 @@ describe('BuyProvider', () => {
<BuyProvider
config={config}
experimental={{ useAggregator: true }}
projectId="test"
toToken={usdcToken}
>
{children}
Expand Down
10 changes: 8 additions & 2 deletions src/buy/components/BuyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export function BuyProvider({
onSuccess,
toToken,
fromToken,
projectId,
}: BuyProviderReact) {
const {
config: { paymaster } = { paymaster: undefined },
Expand Down Expand Up @@ -89,6 +88,14 @@ export function BuyProvider({

// Refreshes balances and inputs post-swap
const resetInputs = useResetBuyInputs({ fromETH, fromUSDC, from, to });

const { projectId } = useOnchainKit();
if (!projectId) {
throw new Error(

Check failure on line 94 in src/buy/components/BuyProvider.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/buy/components/BuyProvider.test.tsx > useBuyContext > should throw an error when used outside of BuyProvider

Error: Buy: Project ID is required, please set the projectId in the OnchainKitProvider ❯ BuyProvider src/buy/components/BuyProvider.tsx:94:11 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22

Check failure on line 94 in src/buy/components/BuyProvider.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/buy/components/BuyProvider.test.tsx > useBuyContext > should provide context when used within BuyProvider

Error: Buy: Project ID is required, please set the projectId in the OnchainKitProvider ❯ BuyProvider src/buy/components/BuyProvider.tsx:94:11 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22

Check failure on line 94 in src/buy/components/BuyProvider.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/buy/components/BuyProvider.test.tsx > BuyProvider > should reset inputs when setLifecycleStatus is called with success

Error: Buy: Project ID is required, please set the projectId in the OnchainKitProvider ❯ BuyProvider src/buy/components/BuyProvider.tsx:94:11 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22

Check failure on line 94 in src/buy/components/BuyProvider.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/buy/components/BuyProvider.test.tsx > BuyProvider > should handle batched transactions

Error: Buy: Project ID is required, please set the projectId in the OnchainKitProvider ❯ BuyProvider src/buy/components/BuyProvider.tsx:94:11 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22

Check failure on line 94 in src/buy/components/BuyProvider.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/buy/components/BuyProvider.test.tsx > BuyProvider > should emit onError when setLifecycleStatus is called with error

Error: Buy: Project ID is required, please set the projectId in the OnchainKitProvider ❯ BuyProvider src/buy/components/BuyProvider.tsx:94:11 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22

Check failure on line 94 in src/buy/components/BuyProvider.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/buy/components/BuyProvider.test.tsx > BuyProvider > should emit onStatus when setLifecycleStatus is called with amountChange

Error: Buy: Project ID is required, please set the projectId in the OnchainKitProvider ❯ BuyProvider src/buy/components/BuyProvider.tsx:94:11 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22

Check failure on line 94 in src/buy/components/BuyProvider.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/buy/components/BuyProvider.test.tsx > BuyProvider > should persist statusData when upodating lifecycle status

Error: Buy: Project ID is required, please set the projectId in the OnchainKitProvider ❯ BuyProvider src/buy/components/BuyProvider.tsx:94:11 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22

Check failure on line 94 in src/buy/components/BuyProvider.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/buy/components/BuyProvider.test.tsx > BuyProvider > should not persist error when updating lifecycle status

Error: Buy: Project ID is required, please set the projectId in the OnchainKitProvider ❯ BuyProvider src/buy/components/BuyProvider.tsx:94:11 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22

Check failure on line 94 in src/buy/components/BuyProvider.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/buy/components/BuyProvider.test.tsx > BuyProvider > should emit onStatus when setLifecycleStatus is called with transactionPending

Error: Buy: Project ID is required, please set the projectId in the OnchainKitProvider ❯ BuyProvider src/buy/components/BuyProvider.tsx:94:11 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22

Check failure on line 94 in src/buy/components/BuyProvider.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/buy/components/BuyProvider.test.tsx > BuyProvider > should emit onStatus when setLifecycleStatus is called with transactionApproved

Error: Buy: Project ID is required, please set the projectId in the OnchainKitProvider ❯ BuyProvider src/buy/components/BuyProvider.tsx:94:11 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22
'Buy: Project ID is required, please set the projectId in the OnchainKitProvider',
);
}

// For batched transactions, listens to and awaits calls from the Wallet server
const awaitCallsStatus = useAwaitCalls({
accountConfig,
Expand Down Expand Up @@ -462,7 +469,6 @@ export function BuyProvider({
setIsDropdownOpen,
toToken,
fromToken,
projectId,
startPopupMonitor,
});

Expand Down
3 changes: 0 additions & 3 deletions src/buy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export type BuyReact = {
onSuccess?: (transactionReceipt?: TransactionReceipt) => void; // An optional callback function that exposes the transaction receipt
fromToken?: Token; // An optional token to swap from
toToken: Token; // The token to swap to
projectId: string; // A CDP project ID (found at https://portal.cdp.coinbase.com/)
};

export type BuyContextType = {
Expand All @@ -41,7 +40,6 @@ export type BuyContextType = {
transactionHash: string;
isDropdownOpen: boolean;
setIsDropdownOpen: (open: boolean) => void;
projectId: string;
startPopupMonitor: (popupWindow: Window) => void;
};

Expand All @@ -59,7 +57,6 @@ export type BuyProviderReact = {
onSuccess?: (transactionReceipt?: TransactionReceipt) => void; // An optional callback function that exposes the transaction receipt
fromToken?: Token;
toToken: Token;
projectId: string;
};

export type BuyTokens = {
Expand Down

0 comments on commit 215761b

Please sign in to comment.