From e7eb5fde523c38cb25142a5b64cbe0f15cbe3a13 Mon Sep 17 00:00:00 2001 From: 0age <37939117+0age@users.noreply.github.com> Date: Sun, 8 Dec 2024 17:37:48 -0800 Subject: [PATCH] got it --- frontend/src/hooks/useWithdrawalStatus.ts | 16 ---------------- src/__tests__/balance.test.ts | 22 ++++++++++++++-------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/frontend/src/hooks/useWithdrawalStatus.ts b/frontend/src/hooks/useWithdrawalStatus.ts index 382d736..af28eee 100644 --- a/frontend/src/hooks/useWithdrawalStatus.ts +++ b/frontend/src/hooks/useWithdrawalStatus.ts @@ -49,17 +49,7 @@ export function useWithdrawalStatus(balances: Balance[]): WithdrawalStatuses { balances.forEach((balance) => { const statusKey = getStatusKey(balance.chainId, balance.lockId); - console.log( - `[Chain ${balance.chainId}, Lock ${balance.lockId}] Status Check:`, - { - withdrawalStatus: balance.withdrawalStatus, - withdrawableAt: balance.withdrawableAt, - now, - } - ); - if (balance.withdrawalStatus === 0) { - console.log(`[${statusKey}] -> ACTIVE (status=0)`); newStatuses[statusKey] = { canExecute: false, timeRemaining: null, @@ -72,7 +62,6 @@ export function useWithdrawalStatus(balances: Balance[]): WithdrawalStatuses { : now + 600; // default to 10 minutes if not set if (timestamp <= now) { - console.log(`[${statusKey}] -> READY (status=1, time elapsed)`); newStatuses[statusKey] = { canExecute: true, timeRemaining: 'Ready', @@ -80,9 +69,6 @@ export function useWithdrawalStatus(balances: Balance[]): WithdrawalStatuses { }; } else { const remaining = formatTimeRemaining(timestamp); - console.log( - `[${statusKey}] -> PENDING (status=1, ${remaining} remaining)` - ); newStatuses[statusKey] = { canExecute: false, timeRemaining: remaining, @@ -90,7 +76,6 @@ export function useWithdrawalStatus(balances: Balance[]): WithdrawalStatuses { }; } } else { - console.log(`[${statusKey}] -> DEFAULT to ACTIVE (unexpected state)`); newStatuses[statusKey] = { canExecute: false, timeRemaining: null, @@ -99,7 +84,6 @@ export function useWithdrawalStatus(balances: Balance[]): WithdrawalStatuses { } }); - console.log('Final Statuses:', newStatuses); setStatuses(newStatuses); }, [balances]); diff --git a/src/__tests__/balance.test.ts b/src/__tests__/balance.test.ts index 907c183..b5b5dfe 100644 --- a/src/__tests__/balance.test.ts +++ b/src/__tests__/balance.test.ts @@ -26,7 +26,7 @@ describe('Balance Functions', () => { nonce bytea NOT NULL CHECK (length(nonce) = 32), expires BIGINT NOT NULL, compact_id bytea NOT NULL CHECK (length(compact_id) = 32), - amount TEXT NOT NULL, + amount bytea NOT NULL CHECK (length(amount) = 32), witness_type_string TEXT, witness_hash bytea CHECK (witness_hash IS NULL OR length(witness_hash) = 32), signature bytea NOT NULL, @@ -69,7 +69,9 @@ describe('Balance Functions', () => { compact_id: hexToBytes( '0x0000000000000000000000000000000000000000000000000000000000123000' ), - amount: '1000', + amount: hexToBytes( + '0x0000000000000000000000000000000000000000000000000000000000000064' + ), // 100 in hex signature: hexToBytes( '0x1234000000000000000000000000000000000000000000000000000000001234' ), @@ -90,7 +92,9 @@ describe('Balance Functions', () => { compact_id: hexToBytes( '0x0000000000000000000000000000000000000000000000000000000000123000' ), - amount: '2000', + amount: hexToBytes( + '0x00000000000000000000000000000000000000000000000000000000000000c8' + ), // 200 in hex signature: hexToBytes( '0x5678000000000000000000000000000000000000000000000000000000005678' ), @@ -111,7 +115,9 @@ describe('Balance Functions', () => { compact_id: hexToBytes( '0x0000000000000000000000000000000000000000000000000000000000123000' ), - amount: '3000', + amount: hexToBytes( + '0x000000000000000000000000000000000000000000000000000000000000012c' + ), // 300 in hex signature: hexToBytes( '0x9abc000000000000000000000000000000000000000000000000000000009abc' ), @@ -164,8 +170,8 @@ describe('Balance Functions', () => { [] ); - // Should include both active and not-fully-expired compacts (1000 + 2000) - expect(balance.toString()).toBe(BigInt(3000).toString()); + // Should include both active and not-fully-expired compacts (100 + 200) + expect(balance.toString()).toBe(BigInt(300).toString()); }); it('should exclude processed claims from allocated balance', async () => { @@ -177,8 +183,8 @@ describe('Balance Functions', () => { ['0x1000000000000000000000000000000000000000000000000000000000000001'] // Processed claim for the active compact ); - // Should only include the not-fully-expired compact (2000) - expect(balance.toString()).toBe(BigInt(2000).toString()); + // Should only include the not-fully-expired compact (200) + expect(balance.toString()).toBe(BigInt(200).toString()); }); it('should return zero for all processed or expired claims', async () => {