Skip to content

Commit

Permalink
Resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arhtudormorar committed Sep 16, 2024
1 parent 3bbb81e commit 84c6afc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ export async function initializeWebsocketConnection() {
let batchTimeout: NodeJS.Timeout | null = null;

const handleMessageReceived = (message: string) => {
console.log(
'\x1b[42m%s\x1b[0m',
'handleMessageReceived -> message',
message
);
if (messageTimeout) {
clearTimeout(messageTimeout);
}
Expand Down Expand Up @@ -64,7 +59,7 @@ export async function initializeWebsocketConnection() {
return;
}

websocketConnection.current = io(websocketUrl, {
websocketConnection.instance = io(websocketUrl, {
forceNew: true,
reconnectionAttempts: RECONNECTION_ATTEMPTS,
timeout: TIMEOUT,
Expand All @@ -73,27 +68,27 @@ export async function initializeWebsocketConnection() {

websocketConnection.status = WebsocketConnectionStatusEnum.COMPLETED;

websocketConnection.current.onAny(handleMessageReceived);
websocketConnection.instance.onAny(handleMessageReceived);

websocketConnection.current.on(BATCH_UPDATED_EVENT, handleBatchUpdate);
websocketConnection.instance.on(BATCH_UPDATED_EVENT, handleBatchUpdate);

websocketConnection.current.on(CONNECT, () => {
websocketConnection.instance.on(CONNECT, () => {
console.log('Websocket connected.');
});

websocketConnection.current.on(DISCONNECT, () => {
websocketConnection.instance.on(DISCONNECT, () => {
console.warn('Websocket disconnected. Trying to reconnect...');
setTimeout(() => {
console.log('Websocket reconnecting...');
websocketConnection.current?.connect();
websocketConnection.instance?.connect();
}, RETRY_INTERVAL);
});
},
{ retries: 2, delay: RETRY_INTERVAL }
);

const closeConnection = () => {
websocketConnection.current?.close();
websocketConnection.instance?.close();
websocketConnection.status = WebsocketConnectionStatusEnum.NOT_INITIALIZED;
if (messageTimeout) {
clearTimeout(messageTimeout);
Expand All @@ -107,7 +102,7 @@ export async function initializeWebsocketConnection() {
address &&
websocketConnection.status ===
WebsocketConnectionStatusEnum.NOT_INITIALIZED &&
!websocketConnection.current?.active
!websocketConnection.instance?.active
) {
await initializeConnection();
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/methods/initApp/websocket/websocket.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export enum WebsocketConnectionStatusEnum {
}

export const websocketConnection: {
current: Socket | null;
instance: Socket | null;
// Use the connection status to avoid multiple websocket connections
status: WebsocketConnectionStatusEnum;
} = {
current: null,
instance: null,
status: WebsocketConnectionStatusEnum.NOT_INITIALIZED
};
13 changes: 0 additions & 13 deletions src/core/methods/signTransactions/signTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,4 @@ export const signTransactions = async (
(await provider.signTransactions(transacitonsToSign)) ?? [];

return signedTransactions;

// const { needs2FaSigning, sendTransactionsToGuardian } =
// checkNeedsGuardianSigning({
// transactions: signedTransactions,
// sessionId,
// callbackRoute,
// isGuarded: isGuarded && allowGuardian,
// walletAddress
// });

// if (needs2FaSigning) {
// return sendTransactionsToGuardian();
// }
};
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export async function checkBatch({
// Call the onSuccess or onFail callback only if the transactions are sent normally (not using batch transactions mechanism).
// The batch transactions mechanism will call the callbacks separately.

// TODO: check grouping and sequential transactions
if (hasCompleted /* && !customTransactionInformation?.grouping */) {
const isSuccessful = serverTransactions.every(
(tx) => tx.status === TransactionServerStatusesEnum.success
Expand Down

0 comments on commit 84c6afc

Please sign in to comment.