Skip to content

Commit 276691d

Browse files
committed
add cli preview and format code
1 parent 8c2bbb7 commit 276691d

File tree

7 files changed

+11
-12
lines changed

7 files changed

+11
-12
lines changed

.github/preview.gif

219 KB
Loading

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<br>
66
<h1>Node.js Kafka Example</h1>
77
<p>Realtime Bitcoin Wallet Tracker Example App with Node.js and Kafka</p>
8+
<img width="420px" src="./.github/preview.gif" />
89
</div>
910

1011
# Features
@@ -49,6 +50,10 @@
4950

5051
- http://localhost:8080 (Redpanda Console)
5152

53+
**Notes**
54+
55+
- Fetching the balance might stop working at some point, because [Blockcypher](https://www.blockcypher.com) limits the amount of requests one can send to their API
56+
5257
# Codebase
5358

5459
- [`cli.ts`](cli.ts) (CLI application to read wallet data in realtime)

balance.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ async function main() {
1919
const url = `${API_URL}/${currency}/main/addrs/${address}/balance`
2020

2121
const {data} = await axios.get(url)
22-
const balance =
23-
currency === 'btc' ? data.balance / 100000000 : data.balance / 1000000000000000000
22+
const balance = currency === 'btc' ? data.balance / 100000000 : data.balance / 1000000000000000000
2423

2524
const payload = JSON.stringify({balance})
2625
await producer.send({

cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ ws.on('message', (json: string) => {
3333

3434
process.stdout.write(`Wallet: ${currency.toUpperCase()}\n`)
3535
process.stdout.write(`Price: ${price < 0 ? '...' : formatUSD(Number(price))}\n`)
36-
process.stdout.write(`Balance: ${balance < 0 ? '...' : balance}\n`)
37-
process.stdout.write(`Value: ${balance < 0 ? '...' : formatUSD(balance * price)}\n`)
36+
process.stdout.write(`Balance: ${balance < 0 || !balance ? '...' : balance}\n`)
37+
process.stdout.write(`Value: ${balance < 0 || !balance ? '...' : formatUSD(balance * price)}\n`)
3838
process.stdout.moveCursor(0, -OUTPUT_LINES_COUNT)
3939

4040
break

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
"singleQuote": true,
2121
"bracketSpacing": false,
2222
"semi": false,
23-
"printWidth": 100
23+
"printWidth": 110
2424
}
2525
}

price.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ async function main() {
2424
},
2525
}
2626

27-
const wsRef = client.combinedStreams(
28-
[`${BTC_USDT_TICKER}@ticker`, `${ETH_USDT_TICKER}@ticker`],
29-
callbacks
30-
)
27+
const wsRef = client.combinedStreams([`${BTC_USDT_TICKER}@ticker`, `${ETH_USDT_TICKER}@ticker`], callbacks)
3128

3229
// setTimeout(() => client.unsubscribe(wsRef), 3000)
3330
}

server.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ async function main() {
4242

4343
if (wallet && wallet.currency === currency) {
4444
const balance = walletBalances.get(wallet.address) || null
45-
ws.send(
46-
JSON.stringify({type: 'balance', data: {balance, price: prices[currency], currency}})
47-
)
45+
ws.send(JSON.stringify({type: 'balance', data: {balance, price: prices[currency], currency}}))
4846
}
4947
})
5048
},

0 commit comments

Comments
 (0)