Skip to content

Commit d1cfbfd

Browse files
committed
Fix lockfile
2 parents 532ed48 + 5b6de64 commit d1cfbfd

File tree

11 files changed

+147
-80
lines changed

11 files changed

+147
-80
lines changed

packages/onchainkit/src/signature/components/SignatureProvider.test.tsx

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,25 @@ describe('SignatureProvider', () => {
4141
let mockOnSuccess: Mock;
4242
let mockSignMessage: Mock;
4343
let mockSignTypedData: Mock;
44+
let mockResetMessage: Mock;
45+
let mockResetTypedData: Mock;
4446

4547
beforeEach(() => {
4648
mockOnError = vi.fn();
4749
mockOnStatus = vi.fn();
4850
mockOnSuccess = vi.fn();
4951
mockSignMessage = vi.fn();
5052
mockSignTypedData = vi.fn();
53+
mockResetMessage = vi.fn();
54+
mockResetTypedData = vi.fn();
5155

5256
(useSignMessage as Mock).mockReturnValue({
5357
signMessageAsync: mockSignMessage,
54-
reset: vi.fn(),
58+
reset: mockResetMessage,
5559
});
5660
(useSignTypedData as Mock).mockReturnValue({
5761
signTypedDataAsync: mockSignTypedData,
58-
reset: vi.fn(),
62+
reset: mockResetTypedData,
5963
});
6064
});
6165

@@ -161,8 +165,8 @@ describe('SignatureProvider', () => {
161165
});
162166

163167
await waitFor(() => {
164-
expect(useSignMessage().reset).toHaveBeenCalled();
165-
expect(useSignTypedData().reset).toHaveBeenCalled();
168+
expect(mockResetMessage).toHaveBeenCalled();
169+
expect(mockResetTypedData).toHaveBeenCalled();
166170
});
167171
});
168172

@@ -251,4 +255,37 @@ describe('SignatureProvider', () => {
251255
);
252256
});
253257
});
258+
259+
it('should not reset after unmount', async () => {
260+
vi.useFakeTimers();
261+
mockSignMessage.mockResolvedValue('0x456');
262+
263+
const { unmount } = render(
264+
<SignatureProvider
265+
message="Test message"
266+
onSuccess={mockOnSuccess}
267+
resetAfter={1000}
268+
>
269+
<TestComponent />
270+
</SignatureProvider>,
271+
);
272+
273+
fireEvent.click(screen.getByText('sign'));
274+
275+
// RTL waitFor will never resolve with fake timers
276+
await vi.waitFor(() => {
277+
if (vi.getTimerCount() !== 1) {
278+
throw new Error('setTimeout was not called');
279+
}
280+
});
281+
282+
unmount();
283+
284+
vi.advanceTimersByTime(1000);
285+
286+
expect(mockResetMessage).not.toHaveBeenCalled();
287+
expect(mockResetTypedData).not.toHaveBeenCalled();
288+
289+
vi.useRealTimers();
290+
});
254291
});

packages/onchainkit/src/signature/components/SignatureProvider.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ export function SignatureProvider({
6060

6161
useEffect(() => {
6262
if (lifecycleStatus.statusName === 'success' && resetAfter) {
63-
setTimeout(() => {
63+
const timeoutId = setTimeout(() => {
6464
resetSignMessage();
6565
resetSignTypedData();
6666
updateLifecycleStatus({
6767
statusName: 'init',
6868
statusData: null,
6969
});
7070
}, resetAfter);
71+
72+
return () => clearTimeout(timeoutId);
7173
}
7274
}, [
7375
updateLifecycleStatus,

packages/playground/app/mint/hooks/useEarningsData.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { useCollection } from '@/lib/nft/useCollection';
22
import { useToken } from '@/lib/nft/useToken';
3-
import type { ContractType } from '@/onchainkit/esm/nft/types';
43
import { useMemo } from 'react';
54

5+
type ContractType = 'ERC721' | 'ERC1155';
6+
7+
// eslint-disable-next-line complexity
68
export function useEarningsData(contractAddress: string, tokenId?: string) {
79
const { data: collection } = useCollection(contractAddress);
810

packages/playground/components/demo/FundCard.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FundCard } from '@coinbase/onchainkit/fund';
2-
import type { PresetAmountInputs } from '../../onchainkit/esm/fund/types';
2+
3+
type PresetAmountInputs = readonly [string, string, string];
34

45
export default function FundCardDemo() {
56
const presetAmountInputs: PresetAmountInputs = ['10', '20', '100'];

packages/playground/components/demo/Transaction.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import {
33
clickContracts,
44
heterogeneousClickCalls,
55
} from '@/lib/transactions';
6-
import type { Call } from '@/onchainkit/esm/transaction/types';
7-
import type { LifecycleStatus } from '@/onchainkit/src/transaction';
86
import { TransactionTypes } from '@/types/onchainkit';
97
import {
108
Transaction,
@@ -17,11 +15,14 @@ import {
1715
TransactionToastAction,
1816
TransactionToastIcon,
1917
TransactionToastLabel,
18+
LifecycleStatus,
2019
} from '@coinbase/onchainkit/transaction';
2120
import { useCallback, useContext, useEffect, useMemo } from 'react';
22-
import type { ContractFunctionParameters } from 'viem';
21+
import type { ContractFunctionParameters, Hex } from 'viem';
2322
import { AppContext } from '../AppProvider';
2423

24+
type Call = { to: Hex; data?: Hex; value?: bigint };
25+
2526
function TransactionDemo() {
2627
const { chainId, transactionType, isSponsored } = useContext(AppContext);
2728
const contracts = clickContracts as ContractFunctionParameters[];

packages/playground/lib/nft/buildMintTransaction.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import type { BuildMintTransactionDataProps } from '@/onchainkit/esm/nft/types';
2-
import type { Call } from '@/onchainkit/esm/transaction/types';
1+
import type { BuildMintTransaction } from '@coinbase/onchainkit/nft';
32
import type { definitions } from '@reservoir0x/reservoir-sdk';
43
import { ENVIRONMENT_VARIABLES } from '../constants';
4+
import { Hex } from 'viem';
5+
6+
type BuildMintTransactionDataProps = Parameters<BuildMintTransaction>[0];
7+
8+
type Call = { to: Hex; data?: Hex; value?: bigint };
59

610
const ERROR_MAP = {
711
'Unable to mint requested quantity (max mints per wallet possibly exceeded)':

packages/playground/lib/nft/useReservoirMintData.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import type { ContractType } from '@/onchainkit/esm/nft/types';
21
import { useMemo } from 'react';
32
import { useCollection } from './useCollection';
43
import { useOwners } from './useOwners';
54
import { useToken } from './useToken';
65

6+
type ContractType = 'ERC721' | 'ERC1155';
7+
8+
// eslint-disable-next-line complexity
79
export function useReservoirMintData(
810
contractAddress: string,
911
tokenId?: string,

packages/playground/lib/nft/useReservoirNFTData.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import type { ContractType } from '@/onchainkit/esm/nft/types';
21
import { useMemo } from 'react';
32
import { useToken } from './useToken';
43

4+
type ContractType = 'ERC721' | 'ERC1155';
5+
6+
// eslint-disable-next-line complexity
57
export function useReservoirNFTData(contractAddress: string, tokenId = '0') {
68
const { data: token } = useToken(contractAddress, tokenId);
79

packages/playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"graphql": "^14 || ^15 || ^16",
2626
"graphql-request": "^6.1.0",
2727
"lucide-react": "^0.416.0",
28-
"next": "^14.2.5",
28+
"next": "^14.2.26",
2929
"react": "^18",
3030
"react-dom": "^18",
3131
"tailwind-merge": "^2.4.0",

0 commit comments

Comments
 (0)