Skip to content

Commit

Permalink
fix imports and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
alissacrane-cb committed Dec 16, 2024
1 parent c8df918 commit 5bd9007
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 39 deletions.
2 changes: 0 additions & 2 deletions src/buy/components/BuyAmountInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { render, screen, fireEvent } from '@testing-library/react';
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import { BuyAmountInput } from './BuyAmountInput';
import { useBuyContext } from './BuyProvider';
import { TextInput } from '../../internal/components/TextInput';
import { Token, TokenChip } from '../../token';

vi.mock('./BuyProvider', () => ({
useBuyContext: vi.fn(),
Expand Down
2 changes: 1 addition & 1 deletion src/buy/components/BuyAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useCallback } from 'react';
import { isValidAmount } from '../../core/utils/isValidAmount';
import { TextInput } from '../../internal/components/TextInput';
import { cn, pressable } from '../../styles/theme';
import { TokenChip } from '../../token';
import { formatAmount } from '../../swap/utils/formatAmount';
import { TokenChip } from '../../token';
import { useBuyContext } from './BuyProvider';

export function BuyAmountInput() {
Expand Down
4 changes: 1 addition & 3 deletions src/buy/components/BuyButton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { render, screen, fireEvent } from '@testing-library/react';
import { fireEvent, render, screen } from '@testing-library/react';
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import { BuyButton } from './BuyButton';
import { useBuyContext } from './BuyProvider';
import { Spinner } from '../../internal/components/Spinner';
import { checkmarkSvg } from '../../internal/svg/checkmarkSvg';

vi.mock('./BuyProvider', () => ({
useBuyContext: vi.fn(),
Expand Down
2 changes: 1 addition & 1 deletion src/buy/components/BuyDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function BuyDropdown() {
}
};
},
[address, to, projectId],
[address, to, projectId, startPopupMonitor],
);

const formattedAmountUSD = useMemo(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/buy/components/BuyOnrampItem.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, screen, fireEvent } from '@testing-library/react';
import { beforeEach, describe, expect, it, Mock, vi } from 'vitest';
import { fireEvent, render, screen } from '@testing-library/react';
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import { BuyOnrampItem } from './BuyOnrampItem';
import { useBuyContext } from './BuyProvider';

Expand Down
14 changes: 7 additions & 7 deletions src/buy/components/BuyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import { useCapabilitiesSafe } from '../../core-react/internal/hooks/useCapabili
import { useValue } from '../../core-react/internal/hooks/useValue';
import { useOnchainKit } from '../../core-react/useOnchainKit';
import { buildSwapTransaction } from '../../core/api/buildSwapTransaction';
import { getBuyQuote } from '../utils/getBuyQuote';
import { setupOnrampEventListeners } from '../../fund';
import type { EventMetadata, OnrampError } from '../../fund/types';
import { GENERIC_ERROR_MESSAGE } from '../../transaction/constants';
import { isUserRejectedRequestError } from '../../transaction/utils/isUserRejectedRequestError';
import type { EventMetadata } from '../../fund/types';
import { FALLBACK_DEFAULT_MAX_SLIPPAGE } from '../../swap/constants';
import { useAwaitCalls } from '../../swap/hooks/useAwaitCalls';
import { useLifecycleStatus } from '../../swap/hooks/useLifecycleStatus';
import type { SwapUnit } from '../../swap/types';
import { isSwapError } from '../../swap/utils/isSwapError';
import { processSwapTransaction } from '../../swap/utils/processSwapTransaction';
import { GENERIC_ERROR_MESSAGE } from '../../transaction/constants';
import { isUserRejectedRequestError } from '../../transaction/utils/isUserRejectedRequestError';
import { useBuyTokens } from '../hooks/useBuyTokens';
import { usePopupMonitor } from '../hooks/usePopupMonitor';
import { useResetBuyInputs } from '../hooks/useResetBuyInputs';
import { BuyContextType, BuyProviderReact } from '../types';
import type { BuyContextType, BuyProviderReact } from '../types';
import { getBuyQuote } from '../utils/getBuyQuote';

const emptyContext = {} as BuyContextType;

Expand Down Expand Up @@ -114,7 +114,7 @@ export function BuyProvider({
statusName: 'success',
statusData: {},
});
}, []);
}, [updateLifecycleStatus]);

const onPopupClose = useCallback(() => {
updateLifecycleStatus({
Expand All @@ -124,7 +124,7 @@ export function BuyProvider({
maxSlippage: config.maxSlippage,
},
});
}, [updateLifecycleStatus]);
}, [updateLifecycleStatus, config.maxSlippage]);

useEffect(() => {
const unsubscribe = setupOnrampEventListeners({
Expand Down
8 changes: 4 additions & 4 deletions src/buy/components/BuyTokenItem.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { render, screen, fireEvent } from '@testing-library/react';
import { beforeEach, describe, expect, it, Mock, vi } from 'vitest';
import { BuyTokenItem } from './BuyTokenItem';
import { useBuyContext } from './BuyProvider';
import { fireEvent, render, screen } from '@testing-library/react';
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import { getRoundedAmount } from '../../core/utils/getRoundedAmount';
import { ethToken } from '../../token/constants';
import { useBuyContext } from './BuyProvider';
import { BuyTokenItem } from './BuyTokenItem';

vi.mock('./BuyProvider', () => ({
useBuyContext: vi.fn(),
Expand Down
2 changes: 1 addition & 1 deletion src/buy/components/BuyTokenItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useCallback, useMemo } from 'react';
import { getRoundedAmount } from '../../core/utils/getRoundedAmount';
import { cn, color } from '../../styles/theme';
import { TokenImage } from '../../token';
import type { SwapUnit } from '../../swap/types';
import { TokenImage } from '../../token';
import { useBuyContext } from './BuyProvider';

export function BuyTokenItem({ swapUnit }: { swapUnit?: SwapUnit }) {
Expand Down
33 changes: 18 additions & 15 deletions src/buy/hooks/usePopupMonitor.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { useRef, useEffect, useCallback } from 'react';
import { useCallback, useEffect, useRef } from 'react';

export const usePopupMonitor = (onClose?: () => void) => {
const intervalRef = useRef<number | null>(null);

// Start monitoring the popup
const startPopupMonitor = useCallback((popupWindow: Window) => {
if (intervalRef.current) {
clearInterval(intervalRef.current);
}
intervalRef.current = window.setInterval(() => {
if (popupWindow.closed) {
if (intervalRef.current) {
clearInterval(intervalRef.current);
intervalRef.current = null;
}
console.log('Popup closed');
onClose?.();
const startPopupMonitor = useCallback(
(popupWindow: Window) => {
if (intervalRef.current) {
clearInterval(intervalRef.current);
}
}, 500);
}, []);
intervalRef.current = window.setInterval(() => {
if (popupWindow.closed) {
if (intervalRef.current) {
clearInterval(intervalRef.current);
intervalRef.current = null;
}
console.log('Popup closed');
onClose?.();
}
}, 500);
},
[onClose],
);

// Stop monitoring the popup
const stopPopupMonitor = useCallback(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/buy/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
import type {
LifecycleStatus,
LifecycleStatusUpdate,
SwapConfig,
SwapError,
SwapUnit,
} from '@/swap/types';
import { Token } from '@/token';
import { Address, TransactionReceipt } from 'viem';
import type { Token } from '@/token';
import type { Address, TransactionReceipt } from 'viem';

export type BuyReact = {
className?: string; // Optional className override for top div element.
Expand Down

0 comments on commit 5bd9007

Please sign in to comment.