Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: limit to 1M block transaction to get historical data in finance area #601

Open
wants to merge 5 commits into
base: next
Choose a base branch
from

Conversation

cswni
Copy link
Contributor

@cswni cswni commented Mar 7, 2025

This pull request includes several changes to enhance functionality and code quality in the project. The most important changes include adding a new constant to the global configuration, updating the smart wallet transactions hook to fetch the block number dynamically, and removing an unnecessary console log statement.

Current poor performance when load from 0n transactions and made too many request to blockchain.

> Should Add VITE_BLOCK_FROM=1000000 to .env files.

Enhancements to global configuration and hooks:

Code quality improvements:

geolffreym and others added 5 commits March 5, 2025 20:35
- Updated `use-get-smart-wallet-transactions.ts`:
  - Added logic to dynamically fetch the starting block number using `publicClient.getBlockNumber` with a configurable offset (`GLOBAL_CONSTANTS.FROM_BLOCK`).
  - Refactored fromBlock assignment to use the fetched block number instead of a hardcoded value.
  - Improved error handling for block number fetch failures.
- Updated `config-global.ts`:
  - Introduced a new global constant `FROM_BLOCK` to configure the starting block for fetching transactions.

This change improves flexibility and enables querying specific block ranges dynamically.
- Removed a debug `console.log` statement from `finance-transactions-history.tsx`.
- The cleanup ensures no unnecessary logs are left in production code.
```
- Updated `fromBlock` in `use-get-smart-wallet-transactions.ts` to default to `0n` if undefined.
- This ensures that the hook functions correctly even when `fromBlock` is not provided.
- Updated FROM_BLOCK key in `src/config-global.ts` to use `VITE_FROM_BLOCK` instead of `VITE_BLOCK_FROM`.
- This ensures consistency with the defined environment variable naming conventions.
@cswni cswni added the Refactor label Mar 7, 2025
@cswni cswni requested review from geolffreym and Jadapema March 7, 2025 00:09
@cswni cswni self-assigned this Mar 7, 2025
@cswni cswni linked an issue Mar 7, 2025 that may be closed by this pull request
Copy link

sonarqubecloud bot commented Mar 7, 2025

@@ -101,17 +101,26 @@ export default function useGetSmartWalletTransactions() {
return;
}

const fetchBlockNumber = async () => {
try {
return await publicClient.getBlockNumber().then((block) => BigInt(block - BigInt(GLOBAL_CONSTANTS.FROM_BLOCK)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aca el await no es necesario..

import {useDispatch, useSelector} from 'react-redux'
import {Address, formatUnits, parseAbiItem} from 'viem'
import {publicClient} from '@src/clients/viem/publicClient.ts'
import {GLOBAL_CONSTANTS} from '@src/config-global.ts'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constantes y abis moverlos al final de los imports por convention

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: On review
Development

Successfully merging this pull request may close these issues.

refactor: limit calls to blockchain to get only last 100 blocks
2 participants