Skip to content

Commit

Permalink
got it
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Dec 9, 2024
1 parent c3af441 commit e7eb5fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
16 changes: 0 additions & 16 deletions frontend/src/hooks/useWithdrawalStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -72,25 +62,20 @@ 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',
status: 'ready',
};
} else {
const remaining = formatTimeRemaining(timestamp);
console.log(
`[${statusKey}] -> PENDING (status=1, ${remaining} remaining)`
);
newStatuses[statusKey] = {
canExecute: false,
timeRemaining: remaining,
status: 'pending',
};
}
} else {
console.log(`[${statusKey}] -> DEFAULT to ACTIVE (unexpected state)`);
newStatuses[statusKey] = {
canExecute: false,
timeRemaining: null,
Expand All @@ -99,7 +84,6 @@ export function useWithdrawalStatus(balances: Balance[]): WithdrawalStatuses {
}
});

console.log('Final Statuses:', newStatuses);
setStatuses(newStatuses);
}, [balances]);

Expand Down
22 changes: 14 additions & 8 deletions src/__tests__/balance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -69,7 +69,9 @@ describe('Balance Functions', () => {
compact_id: hexToBytes(
'0x0000000000000000000000000000000000000000000000000000000000123000'
),
amount: '1000',
amount: hexToBytes(
'0x0000000000000000000000000000000000000000000000000000000000000064'
), // 100 in hex
signature: hexToBytes(
'0x1234000000000000000000000000000000000000000000000000000000001234'
),
Expand All @@ -90,7 +92,9 @@ describe('Balance Functions', () => {
compact_id: hexToBytes(
'0x0000000000000000000000000000000000000000000000000000000000123000'
),
amount: '2000',
amount: hexToBytes(
'0x00000000000000000000000000000000000000000000000000000000000000c8'
), // 200 in hex
signature: hexToBytes(
'0x5678000000000000000000000000000000000000000000000000000000005678'
),
Expand All @@ -111,7 +115,9 @@ describe('Balance Functions', () => {
compact_id: hexToBytes(
'0x0000000000000000000000000000000000000000000000000000000000123000'
),
amount: '3000',
amount: hexToBytes(
'0x000000000000000000000000000000000000000000000000000000000000012c'
), // 300 in hex
signature: hexToBytes(
'0x9abc000000000000000000000000000000000000000000000000000000009abc'
),
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down

0 comments on commit e7eb5fd

Please sign in to comment.