Skip to content

Commit f7c30e9

Browse files
committed
fix (frontend): show balance and threshold in BTC
1 parent deecdce commit f7c30e9

5 files changed

Lines changed: 40 additions & 33 deletions

File tree

frontend/public/config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"networkStatusRefetchIntervalS": 60,
66
"bridgeStatusRefetchIntervalS": 120,
77
"balanceRefetchIntervalS": 30,
8-
"faucetBalanceSatsThresholds": {
9-
"signet": 20000000000,
10-
"alpen": 20000000000
8+
"faucetBalanceBtcThresholds": {
9+
"signet": 200,
10+
"alpen": 200
1111
},
1212
"environment": "staging"
1313
}

frontend/src/components/BridgeOperatorBalance.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
import type {
1+
import {
22
BridgeOperatorBalances,
33
BridgeOperatorWalletBalance,
44
} from '../hooks/useBalances';
5-
import { truncateHex } from '../utils';
5+
import { formatBTC, truncateHex } from '../utils';
66

77
interface BridgeOperatorBalanceProps {
88
bridgeOperators: BridgeOperatorBalances;
99
title: string;
1010
}
1111

12-
function formatSats(sats: number): string {
13-
if (sats === 0) return '0 SATS';
14-
15-
// Add comma separators for readability
16-
const formattedNumber = sats.toLocaleString();
17-
return `${formattedNumber} SATS`;
18-
}
19-
2012
export default function BridgeOperatorBalance({
2113
bridgeOperators,
2214
title,
@@ -103,12 +95,12 @@ export default function BridgeOperatorBalance({
10395
</td>
10496
<td className="table-cell">
10597
{operator.generalWalletBalance
106-
? formatSats(operator.generalWalletBalance.balance_sats)
98+
? formatBTC(operator.generalWalletBalance.balance_sats)
10799
: '-'}
108100
</td>
109101
<td className="table-cell">
110102
{operator.stakeChainWalletBalance
111-
? formatSats(operator.stakeChainWalletBalance.balance_sats)
103+
? formatBTC(operator.stakeChainWalletBalance.balance_sats)
112104
: '-'}
113105
</td>
114106
</tr>

frontend/src/components/FaucetBalance.tsx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import type { FaucetBalances } from '../hooks/useBalances';
22
import { useConfig } from '../hooks/useConfig';
3+
import { btcToSats } from '../utils';
4+
import { formatBTC } from '../utils';
35

46
interface FaucetBalanceProps {
57
faucet: FaucetBalances;
68
title: string;
79
}
810

9-
function formatSats(sats: number): string {
10-
if (sats === 0) return '0 SATS';
11-
12-
const formattedNumber = sats.toLocaleString('en-US');
13-
return `${formattedNumber} SATS`;
14-
}
15-
16-
function getHealthStatus(balanceSats: number, thresholdSats: number): string {
11+
function getHealthStatus(balanceSats: number, thresholdBtc: number): string {
12+
const thresholdSats = btcToSats(thresholdBtc);
1713
return balanceSats >= thresholdSats ? 'Healthy' : 'Low';
1814
}
1915

@@ -24,12 +20,12 @@ export default function FaucetBalance({ faucet, title }: FaucetBalanceProps) {
2420
{
2521
name: 'Signet wallet',
2622
balance_sats: faucet.l1_balance_sats,
27-
threshold_sats: config.faucetBalanceSatsThresholds.signet,
23+
threshold_btc: config.faucetBalanceBtcThresholds.signet,
2824
},
2925
{
3026
name: 'Alpen wallet',
3127
balance_sats: faucet.l2_balance_sats,
32-
threshold_sats: config.faucetBalanceSatsThresholds.alpen,
28+
threshold_btc: config.faucetBalanceBtcThresholds.alpen,
3329
},
3430
];
3531

@@ -50,14 +46,10 @@ export default function FaucetBalance({ faucet, title }: FaucetBalanceProps) {
5046
{faucetWallets.map(wallet => (
5147
<tr key={wallet.name} className="operators-row">
5248
<td className="table-cell">{wallet.name}</td>
49+
<td className="table-cell">{formatBTC(wallet.balance_sats)}</td>
50+
<td className="table-cell">{wallet.threshold_btc} BTC</td>
5351
<td className="table-cell">
54-
{formatSats(wallet.balance_sats)}
55-
</td>
56-
<td className="table-cell">
57-
{formatSats(wallet.threshold_sats)}
58-
</td>
59-
<td className="table-cell">
60-
{getHealthStatus(wallet.balance_sats, wallet.threshold_sats)}
52+
{getHealthStatus(wallet.balance_sats, wallet.threshold_btc)}
6153
</td>
6254
</tr>
6355
))}

frontend/src/providers/ConfigProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface AppConfig {
99
networkStatusRefetchIntervalS: number;
1010
balanceRefetchIntervalS: number;
1111
environment: string;
12-
faucetBalanceSatsThresholds: {
12+
faucetBalanceBtcThresholds: {
1313
signet: number;
1414
alpen: number;
1515
};

frontend/src/utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
// utils.ts
22

3+
// Bitcoin conversion constants
4+
const SATOSHIS_PER_BTC = 100_000_000;
5+
6+
// Convert BTC to satoshis
7+
export const btcToSats = (btc: number): number => btc * SATOSHIS_PER_BTC;
8+
9+
// Convert satoshis to BTC
10+
export const satsToBtc = (sats: number): number => sats / SATOSHIS_PER_BTC;
11+
312
/**
413
* Truncate a hex string to a short display format.
514
* E.g., "0xabcdef...123456"
@@ -8,3 +17,17 @@ export function truncateHex(hex: string, length: number = 6): string {
817
if (hex.length <= 2 * length + 2) return hex;
918
return `${hex.slice(0, length)}...${hex.slice(-length)}`;
1019
}
20+
21+
/**
22+
* Format satoshis as BTC with 2 decimal places and comma separators.
23+
* E.g., "1,234.56 BTC"
24+
*/
25+
export function formatBTC(sats: number): string {
26+
if (sats === 0) return '0.00 BTC';
27+
28+
// Convert satoshis to BTC using the utility function
29+
const btc = satsToBtc(sats);
30+
31+
// Display as BTC with 2 decimal places and comma separators
32+
return `${btc.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })} BTC`;
33+
}

0 commit comments

Comments
 (0)