Skip to content

Commit

Permalink
fix: WIP fix historic balance chart
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolastmaia committed Jan 17, 2025
1 parent 5d133ad commit 464d176
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/localServer/workers/utilities/utilV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,15 +686,17 @@ function generateDaysArrayForBalanceChart(): number[] {
while (tempDate < currentDate) {
// Set the time to 00:00:00 UTC (midnight) on the selected day
tempDate.setUTCHours(0, 0, 0, 0); // Set to 00:00 UTC
daysArray.push(tempDate.getTime()); // Push the timestamp (UTC)
const timestampInSeconds = tempDate.getTime() / 1000;
daysArray.push(timestampInSeconds); // Push the timestamp (UTC)

// Add 7 days in UTC
tempDate.setUTCDate(tempDate.getUTCDate() + 7);
}

// Add today's timestamp in UTC (at 00:00 UTC)
currentDate.setUTCHours(0, 0, 0, 0); // Set to 00:00 UTC
daysArray.push(currentDate.getTime()); // Push today's timestamp (UTC)
const timestampInSeconds = currentDate.getTime() / 1000;
daysArray.push(timestampInSeconds); // Push today's timestamp (UTC)

return daysArray;
}
14 changes: 6 additions & 8 deletions src/localServer/workers/utilities/web3Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2300,12 +2300,10 @@ const scanWUSDT = async (walletAddr: string) => {
}

const scanTronUSDT = async(walletAddr: string) => {

return await scan_erc20_balance(walletAddr, tron_USDT, provideTron)
}

const scanArbUSDT = async(walletAddr: string) => {

return await scan_erc20_balance(walletAddr, Arbitrum_USDT, provideArbOne)
}

Expand Down Expand Up @@ -2373,8 +2371,8 @@ const scan_erc20_balance: (walletAddr: string, erc20Address: string, provide: an

const getBalanceByTimestamp = async (erc20Contract, walletAddress: string, timestamp: number)=>{
try {
const blockNumber = await getBlockByTimestamp(provideCONET, timestamp);
const balance = await getBalanceByBlockNumber(erc20Contract, walletAddress, blockNumber);
const block = await getBlockByTimestamp(provideCONET, timestamp);
const balance = await getBalanceByBlockNumber(erc20Contract, walletAddress, block);

return balance
} catch (ex) {
Expand All @@ -2383,10 +2381,10 @@ const getBalanceByTimestamp = async (erc20Contract, walletAddress: string, times
}
}

const getBalanceByBlockNumber = async (erc20Contract, walletAddress, blockNumber)=>{
const getBalanceByBlockNumber = async (erc20Contract, walletAddress, block)=>{
try {
const balance = await erc20Contract.balanceOf(walletAddress, {
blockTag: blockNumber,
blockTag: block.number,
});

return balance
Expand All @@ -2403,11 +2401,11 @@ const getBlockByTimestamp = async (
let earliestBlock = await provider.getBlock(0);

// Ensure the target timestamp is valid
if (targetTimestamp < earliestBlock.timestamp * 1000) {
if (targetTimestamp < earliestBlock.timestamp) {
throw new Error("Timestamp is earlier than the first block");
}

if (targetTimestamp > latestBlock.timestamp * 1000) {
if (targetTimestamp > latestBlock.timestamp) {
throw new Error("Timestamp is in the future");
}

Expand Down

0 comments on commit 464d176

Please sign in to comment.