|
1 | 1 | import assert from 'node:assert/strict' |
2 | 2 | import test from 'node:test' |
3 | 3 |
|
4 | | -import type { WalletOperation } from '../src/api/client.ts' |
| 4 | +import type { FilecoinReadinessData, WalletOperation } from '../src/api/client.ts' |
5 | 5 | import { |
6 | 6 | buildWalletOperationConfirmation, |
7 | 7 | createWalletOperationDraft, |
8 | 8 | decimalToBaseUnits, |
9 | 9 | fundedUntilCaption, |
10 | 10 | fundedUntilTone, |
11 | 11 | topUpNeeded, |
| 12 | + walletFwssApprovalState, |
12 | 13 | walletOperationDetail, |
13 | 14 | walletOperationDialogShouldClearDraft, |
14 | 15 | walletOperationMutationError, |
@@ -71,6 +72,63 @@ test('wallet operation mutation error follows the active operation type', () => |
71 | 72 | assert.equal(walletOperationMutationError(null, fundError, withdrawError, approveError), null) |
72 | 73 | }) |
73 | 74 |
|
| 75 | +test('wallet FWSS approval action follows readiness state', () => { |
| 76 | + const ready = walletFwssApprovalState({ |
| 77 | + readiness: readinessData('ready', [ |
| 78 | + { id: 'fwss_approval', status: 'ready', message: 'FWSS approval is sufficient.' }, |
| 79 | + ]), |
| 80 | + }) |
| 81 | + assert.equal(ready.status, 'ready') |
| 82 | + assert.equal(ready.canApprove, false) |
| 83 | + |
| 84 | + const blocked = walletFwssApprovalState({ |
| 85 | + readiness: readinessData('blocked', [ |
| 86 | + { |
| 87 | + id: 'fwss_approval', |
| 88 | + status: 'blocked', |
| 89 | + message: 'FWSS payment approval is missing or too low.', |
| 90 | + action: 'Approve FWSS spending before uploading to Filecoin.', |
| 91 | + }, |
| 92 | + ]), |
| 93 | + }) |
| 94 | + assert.equal(blocked.status, 'blocked') |
| 95 | + assert.equal(blocked.canApprove, true) |
| 96 | + assert.equal(blocked.action, 'Approve FWSS spending before uploading to Filecoin.') |
| 97 | + |
| 98 | + const blockedWithoutMessage = walletFwssApprovalState({ |
| 99 | + readiness: readinessData('blocked', [{ id: 'fwss_approval', status: 'blocked', message: '' }]), |
| 100 | + }) |
| 101 | + assert.equal(blockedWithoutMessage.message, 'FWSS approval is required.') |
| 102 | + |
| 103 | + const unknown = walletFwssApprovalState({ |
| 104 | + readiness: readinessData('unknown', [ |
| 105 | + { id: 'fwss_approval', status: 'unknown', message: 'FWSS approval could not be checked.' }, |
| 106 | + ]), |
| 107 | + }) |
| 108 | + assert.equal(unknown.status, 'unknown') |
| 109 | + assert.equal(unknown.canApprove, false) |
| 110 | + |
| 111 | + assert.equal(walletFwssApprovalState({ readiness: readinessData('ready', []) }).canApprove, false) |
| 112 | + assert.equal( |
| 113 | + walletFwssApprovalState({ |
| 114 | + readiness: readinessData('blocked', [ |
| 115 | + { id: 'fwss_approval', status: 'blocked', message: 'FWSS approval is required.' }, |
| 116 | + ]), |
| 117 | + isLoading: true, |
| 118 | + }).canApprove, |
| 119 | + false |
| 120 | + ) |
| 121 | + assert.equal( |
| 122 | + walletFwssApprovalState({ |
| 123 | + readiness: readinessData('blocked', [ |
| 124 | + { id: 'fwss_approval', status: 'blocked', message: 'FWSS approval is required.' }, |
| 125 | + ]), |
| 126 | + error: new Error('readiness unavailable'), |
| 127 | + }).canApprove, |
| 128 | + false |
| 129 | + ) |
| 130 | +}) |
| 131 | + |
74 | 132 | test('wallet operation detail exposes failure reason', () => { |
75 | 133 | const operation: WalletOperation = { |
76 | 134 | id: 1, |
@@ -179,3 +237,15 @@ test('funded until tone highlights low runway ranges', () => { |
179 | 237 | assert.equal(fundedUntilTone({ ...base, runway_seconds: 45 * 86_400 }), 'neutral') |
180 | 238 | assert.equal(fundedUntilTone({ ...base, no_active_spend: true, runway_seconds: undefined }), 'neutral') |
181 | 239 | }) |
| 240 | + |
| 241 | +function readinessData( |
| 242 | + status: FilecoinReadinessData['status'], |
| 243 | + checks: FilecoinReadinessData['checks'] |
| 244 | +): FilecoinReadinessData { |
| 245 | + return { |
| 246 | + status, |
| 247 | + mode: 'runtime', |
| 248 | + checked_at: '2026-06-22T00:00:00Z', |
| 249 | + checks, |
| 250 | + } |
| 251 | +} |
0 commit comments