Skip to content

Commit fd0657f

Browse files
Revert "Socket updates: on-demand contract verification fix, indexing event rename (blockscout#2629)"
This reverts commit a4fc2ac.
1 parent c35b4a4 commit fd0657f

File tree

7 files changed

+22
-40
lines changed

7 files changed

+22
-40
lines changed

lib/socket/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ interface SocketMessageParamsGeneric<Event extends string | undefined, Payload e
4949

5050
export namespace SocketMessage {
5151
export type NewBlock = SocketMessageParamsGeneric<'new_block', NewBlockSocketResponse>;
52-
export type BlocksIndexStatus = SocketMessageParamsGeneric<'index_status', { finished: boolean; ratio: string }>;
53-
export type InternalTxsIndexStatus = SocketMessageParamsGeneric<'index_status', { finished: boolean; ratio: string }>;
52+
export type BlocksIndexStatus = SocketMessageParamsGeneric<'block_index_status', { finished: boolean; ratio: string }>;
53+
export type InternalTxsIndexStatus = SocketMessageParamsGeneric<'internal_txs_index_status', { finished: boolean; ratio: string }>;
5454
export type TxStatusUpdate = SocketMessageParamsGeneric<'collated', NewBlockSocketResponse>;
5555
export type TxRawTrace = SocketMessageParamsGeneric<'raw_trace', RawTracesResponse>;
5656
export type NewTx = SocketMessageParamsGeneric<'transaction', { transaction: number }>;
5757
export type NewPendingTx = SocketMessageParamsGeneric<'pending_transaction', { pending_transaction: number }>;
58-
export type NewOptimisticDeposits = SocketMessageParamsGeneric<'new_optimism_deposits', { deposits: number }>;
58+
export type NewOptimisticDeposits = SocketMessageParamsGeneric<'deposits', { deposits: number }>;
5959
export type NewArbitrumDeposits = SocketMessageParamsGeneric<'new_messages_to_rollup_amount', { new_messages_to_rollup_amount: number }>;
6060
export type AddressBalance = SocketMessageParamsGeneric<'balance', { balance: string; block_number: number; exchange_rate: string }>;
6161
export type AddressCurrentCoinBalance =

lib/socket/useSocketChannel.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from 'react';
33

44
import { useSocket } from './context';
55

6-
const CHANNEL_REGISTRY: Record<string, { channel: Channel; subscribers: number }> = {};
6+
const CHANNEL_REGISTRY: Record<string, Channel> = {};
77

88
interface Params {
99
topic: string | undefined;
@@ -53,12 +53,11 @@ export default function useSocketChannel({ topic, params, isDisabled, onJoin, on
5353

5454
let ch: Channel;
5555
if (CHANNEL_REGISTRY[topic]) {
56-
ch = CHANNEL_REGISTRY[topic].channel;
57-
CHANNEL_REGISTRY[topic].subscribers++;
56+
ch = CHANNEL_REGISTRY[topic];
5857
onJoinRef.current?.(ch, '');
5958
} else {
6059
ch = socket.channel(topic);
61-
CHANNEL_REGISTRY[topic] = { channel: ch, subscribers: 1 };
60+
CHANNEL_REGISTRY[topic] = ch;
6261
ch.join()
6362
.receive('ok', (message) => onJoinRef.current?.(ch, message))
6463
.receive('error', () => {
@@ -69,14 +68,8 @@ export default function useSocketChannel({ topic, params, isDisabled, onJoin, on
6968
setChannel(ch);
7069

7170
return () => {
72-
if (CHANNEL_REGISTRY[topic]) {
73-
CHANNEL_REGISTRY[topic].subscribers > 0 && CHANNEL_REGISTRY[topic].subscribers--;
74-
if (CHANNEL_REGISTRY[topic].subscribers === 0) {
75-
ch.leave();
76-
delete CHANNEL_REGISTRY[topic];
77-
}
78-
}
79-
71+
ch.leave();
72+
delete CHANNEL_REGISTRY[topic];
8073
setChannel(undefined);
8174
};
8275
}, [ socket, topic, params, isDisabled, onSocketError ]);

ui/address/contract/ContractDetails.pw.tsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ test.describe('full view', () => {
4040
},
4141
};
4242
const component = await render(<ContractDetails/>, { hooksConfig }, { withSocket: true });
43-
const socket = await createSocket();
44-
await socketServer.joinChannel(socket, `addresses:${ addressMock.contract.hash.toLowerCase() }`);
43+
await createSocket();
4544
await expect(component).toHaveScreenshot();
4645
});
4746

@@ -52,8 +51,7 @@ test.describe('full view', () => {
5251
},
5352
};
5453
const component = await render(<ContractDetails/>, { hooksConfig }, { withSocket: true });
55-
const socket = await createSocket();
56-
await socketServer.joinChannel(socket, `addresses:${ addressMock.contract.hash.toLowerCase() }`);
54+
await createSocket();
5755
await expect(component).toHaveScreenshot();
5856
});
5957

@@ -64,8 +62,7 @@ test.describe('full view', () => {
6462
},
6563
};
6664
const component = await render(<ContractDetails/>, { hooksConfig }, { withSocket: true });
67-
const socket = await createSocket();
68-
await socketServer.joinChannel(socket, `addresses:${ addressMock.contract.hash.toLowerCase() }`);
65+
await createSocket();
6966
await expect(component).toHaveScreenshot();
7067
});
7168

@@ -76,8 +73,7 @@ test.describe('full view', () => {
7673
},
7774
};
7875
const component = await render(<ContractDetails/>, { hooksConfig }, { withSocket: true });
79-
const socket = await createSocket();
80-
await socketServer.joinChannel(socket, `addresses:${ addressMock.contract.hash.toLowerCase() }`);
76+
await createSocket();
8177
await expect(component).toHaveScreenshot();
8278
});
8379
});
@@ -89,8 +85,7 @@ test.describe('mobile view', () => {
8985
await mockApiResponse('contract', contractMock.withChangedByteCode, { pathParams: { hash: addressMock.contract.hash } });
9086
await mockApiResponse('contract', contractMock.withChangedByteCode, { pathParams: { hash: addressMock.contract.implementations?.[0].address as string } });
9187
const component = await render(<ContractDetails/>, { hooksConfig }, { withSocket: true });
92-
const socket = await createSocket();
93-
await socketServer.joinChannel(socket, `addresses:${ addressMock.contract.hash.toLowerCase() }`);
88+
await createSocket();
9489
await expect(component).toHaveScreenshot();
9590
});
9691
});
@@ -100,19 +95,17 @@ test('verified via lookup in eth_bytecode_db', async({ render, mockApiResponse,
10095
await render(<ContractDetails/>, { hooksConfig }, { withSocket: true });
10196

10297
const socket = await createSocket();
103-
const channel = await socketServer.joinChannel(socket, `addresses:${ addressMock.contract.hash.toLowerCase() }`);
98+
const channel = await socketServer.joinChannel(socket, 'addresses:' + addressMock.contract.hash.toLowerCase());
10499
await page.waitForResponse(contractApiUrl);
105100
socketServer.sendMessage(socket, channel, 'smart_contract_was_verified', {});
106101
const request = await page.waitForRequest(addressApiUrl);
107102

108103
expect(request).toBeTruthy();
109104
});
110105

111-
test('verified with multiple sources', async({ render, page, mockApiResponse, createSocket }) => {
106+
test('verified with multiple sources', async({ render, page, mockApiResponse }) => {
112107
await mockApiResponse('contract', contractMock.withMultiplePaths, { pathParams: { hash: addressMock.contract.hash } });
113108
await render(<ContractDetails/>, { hooksConfig }, { withSocket: true });
114-
const socket = await createSocket();
115-
await socketServer.joinChannel(socket, `addresses:${ addressMock.contract.hash.toLowerCase() }`);
116109

117110
const section = page.locator('section', { hasText: 'Contract source code' });
118111
await expect(section).toHaveScreenshot();
@@ -124,27 +117,23 @@ test('verified with multiple sources', async({ render, page, mockApiResponse, cr
124117
await expect(section).toHaveScreenshot();
125118
});
126119

127-
test('self destructed', async({ render, mockApiResponse, page, createSocket }) => {
120+
test('self destructed', async({ render, mockApiResponse, page }) => {
128121
const hooksConfig = {
129122
router: {
130123
query: { hash: addressMock.contract.hash, tab: 'contract_bytecode' },
131124
},
132125
};
133126
await mockApiResponse('contract', contractMock.selfDestructed, { pathParams: { hash: addressMock.contract.hash } });
134127
await render(<ContractDetails/>, { hooksConfig }, { withSocket: true });
135-
const socket = await createSocket();
136-
await socketServer.joinChannel(socket, `addresses:${ addressMock.contract.hash.toLowerCase() }`);
137128

138129
const section = page.locator('section', { hasText: 'Contract creation code' });
139130
await expect(section).toHaveScreenshot();
140131
});
141132

142-
test('non verified', async({ render, mockApiResponse, createSocket }) => {
133+
test('non verified', async({ render, mockApiResponse }) => {
143134
await mockApiResponse('address', { ...addressMock.contract, name: null }, { pathParams: { hash: addressMock.contract.hash } });
144135
await mockApiResponse('contract', contractMock.nonVerified, { pathParams: { hash: addressMock.contract.hash } });
145136
const component = await render(<ContractDetails/>, { hooksConfig }, { withSocket: true });
146-
const socket = await createSocket();
147-
await socketServer.joinChannel(socket, `addresses:${ addressMock.contract.hash.toLowerCase() }`);
148137

149138
await expect(component).toHaveScreenshot();
150139
});

ui/address/contract/ContractDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const ContractDetails = ({ addressHash, channel, mainContractQuery }: Props) =>
5757
const contractQuery = useApiQuery('contract', {
5858
pathParams: { hash: selectedItem?.address },
5959
queryOptions: {
60-
enabled: Boolean(selectedItem?.address && !mainContractQuery.isPlaceholderData),
60+
enabled: Boolean(selectedItem?.address),
6161
refetchOnMount: false,
6262
placeholderData: addressInfo?.is_verified ? stubs.CONTRACT_CODE_VERIFIED : stubs.CONTRACT_CODE_UNVERIFIED,
6363
},

ui/home/latestDeposits/LatestOptimisticDeposits.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ const LatestOptimisticDeposits = () => {
3737
}, [ setNum ]);
3838

3939
const channel = useSocketChannel({
40-
topic: 'optimism:new_deposits',
40+
topic: 'optimism_deposits:new_deposits',
4141
onSocketClose: handleSocketClose,
4242
onSocketError: handleSocketError,
4343
isDisabled: false,
4444
});
4545

4646
useSocketMessage({
4747
channel,
48-
event: 'new_optimism_deposits',
48+
event: 'deposits',
4949
handler: handleNewDepositMessage,
5050
});
5151

ui/snippets/footer/IntTxsIndexingStatus.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const IntTxsIndexingStatus = () => {
3939

4040
useSocketMessage({
4141
channel: internalTxsIndexingChannel,
42-
event: 'index_status',
42+
event: 'internal_txs_index_status',
4343
handler: handleInternalTxsIndexStatus,
4444
});
4545

ui/snippets/header/alerts/IndexingBlocksAlert.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const IndexingBlocksAlert = () => {
5151

5252
useSocketMessage({
5353
channel: blockIndexingChannel,
54-
event: 'index_status',
54+
event: 'block_index_status',
5555
handler: handleBlocksIndexStatus,
5656
});
5757

0 commit comments

Comments
 (0)