-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update transactions based on subscriptions events and remove po…
…lling (#583) * fix: only show deployed contract notifications when address changes * transaction subscription and refresh working * rename plugin * cleanup * move plugin to a hook, rename back to listener, fix notification logic and improve deployment detection * cleanup logs and todos * cleanup * move notify back, update unit tests * implement tx subscription system * cleanup, fix tests * add unit test for listener hook * remove pending computed test, add unit test for tx refresh * exclude frontend test folder from sonarcloud analysis * remove client_session_id from transactions --------- Co-authored-by: Den <[email protected]> Co-authored-by: Cristiam Da Silva <[email protected]>
- Loading branch information
1 parent
cb516e4
commit 771db2a
Showing
22 changed files
with
310 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
backend/database_handler/migration/versions/579e86111b36_remove_client_session_id_from_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""remove client session id from transactions | ||
Revision ID: 579e86111b36 | ||
Revises: ab256b41602a | ||
Create Date: 2024-11-08 10:41:56.112444 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "579e86111b36" | ||
down_revision: Union[str, None] = "ab256b41602a" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("transactions", "client_session_id") | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"transactions", | ||
sa.Column( | ||
"client_session_id", | ||
sa.VARCHAR(length=255), | ||
autoincrement=False, | ||
nullable=True, | ||
), | ||
) | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useTransactionsStore } from '@/stores'; | ||
import type { TransactionItem } from '@/types'; | ||
import { useWebSocketClient } from '@/hooks'; | ||
|
||
export function useTransactionListener() { | ||
const transactionsStore = useTransactionsStore(); | ||
const webSocketClient = useWebSocketClient(); | ||
|
||
function init() { | ||
webSocketClient.on( | ||
'transaction_status_updated', | ||
handleTransactionStatusUpdate, | ||
); | ||
} | ||
|
||
async function handleTransactionStatusUpdate(eventData: any) { | ||
const newTx = await transactionsStore.getTransaction(eventData.data.hash); | ||
|
||
if (!newTx) { | ||
console.warn('Server tx not found for local tx:', newTx); | ||
transactionsStore.removeTransaction(newTx); | ||
return; | ||
} | ||
|
||
const currentTx = transactionsStore.transactions.find( | ||
(t: TransactionItem) => t.hash === eventData.data.hash, | ||
); | ||
|
||
if (!currentTx) { | ||
// This happens regularly when local transactions get cleared (e.g. user clears all txs or deploys new contract instance) | ||
return; | ||
} | ||
|
||
transactionsStore.updateTransaction(newTx); | ||
} | ||
|
||
return { | ||
init, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './persistStore'; | ||
export * from './transactionsListener'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.