Skip to content

Commit c2babb1

Browse files
committed
fix: handle non-numeric balance and energy responses
1 parent 89fb62a commit c2babb1

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

apps/hub/src/components/terminal/WebTerminal.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,11 @@ class CommandExecutor {
229229
}
230230

231231
try {
232-
const balance = await this.client.getBalance(address);
233-
const cgtBalance = (Number(balance) / 1e18).toFixed(6);
234-
const sparks = (Number(balance) / 1e16).toFixed(2);
232+
const balanceResult = await this.client.getBalance(address);
233+
const balance = balanceResult?.free ?? balanceResult ?? '0';
234+
const balanceNum = Number(balance) || 0;
235+
const cgtBalance = (balanceNum / 1e18).toFixed(6);
236+
const sparks = (balanceNum / 1e16).toFixed(2);
235237

236238
if (isJson) {
237239
return [{
@@ -259,7 +261,8 @@ class CommandExecutor {
259261
}
260262

261263
try {
262-
const energy = await this.client.getEnergy(address);
264+
const energyResult = await this.client.getEnergy(address);
265+
const energy = Number(energyResult) || 100;
263266
const filled = Math.floor(energy / 5);
264267
const empty = 20 - filled;
265268
const bar = '█'.repeat(filled) + '░'.repeat(empty);

0 commit comments

Comments
 (0)