Page MenuHomePhabricator

[Cashtab] [Chronik Websocket Notifications] [Part 1] Connect to websocket
ClosedPublic

Authored by bytesofman on May 27 2022, 23:18.

Details

Summary

T2447

Part 1 of a stacked diff for moving incoming transaction notifications to chronik websockets.

This diff

  • Adds chronik-client and its dependencies
  • Adds a chronik connection URL to the app settings object
  • Implements websocket connection in useWallet.js, so that the connection function runs each time the user loads a new wallet
Test Plan

npm start
Observe console.log statement matching the one in onConnect clause of initializeWebsocket function, "Chronik websocket connected"

Diff Detail

Repository
rABC Bitcoin ABC
Branch
connect-to-chronik-ws
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 19169
Build 38086: Build Diffcashtab-tests
Build 38085: arc lint + arc unit

Event Timeline

Your description above says the connection function is meant to run each time the user loads a new wallet, but I'm observing no new websocket connection statements upon new wallet creation, switching to a saved wallet or import of a new wallet (which reflects the initializeWebsocket function since the obj is still in state).

This suggests it's still using the initial websocket connection, which will result in the user switching to another wallet and receiving websocket notifications for previous wallets they were working on. This in itself isn't a huge issue (metamask is like this too) but wanted to check this is what you're expecting in case your subsequent diffs are assuming separate websocket connections.

Also are you planning to wait for the next chronik-client iteration where the explicit protobufjs dependency is not necessary as it's a sizeable module?

Your description above says the connection function is meant to run each time the user loads a new wallet, but I'm observing no new websocket connection statements upon new wallet creation, switching to a saved wallet or import of a new wallet (which reflects the initializeWebsocket function since the obj is still in state).

The function runs each time the wallet changes. However, it is not meant to reconnect each time. You can see in the function logic that the connection is only initialized if there has been no connection yet, i.e.

let ws = chronikWebsocket;
        if (ws === null) {

Once the connection is up, it's already set to reconnect automatically. This diff does not subscribe to addresses, so the connection is identical (and identically useless) for any wallet selected.

See Part 3 and 4 (D11534 and D11535) to check out how the function adapts the websocket connection for wallet changes.

This suggests it's still using the initial websocket connection, which will result in the user switching to another wallet and receiving websocket notifications for previous wallets they were working on. This in itself isn't a huge issue (metamask is like this too) but wanted to check this is what you're expecting in case your subsequent diffs are assuming separate websocket connections.

Should be the same websocket connection for every wallet -- though the addresses being subscribed to will change.

Also are you planning to wait for the next chronik-client iteration where the explicit protobufjs dependency is not necessary as it's a sizeable module?

I compared the bundle size of this diff with cashtab.com by using this approach:

  1. On this diff,
cd web/cashtab
docker build -t cashtab_local .
docker run --rm -p 8080:80 --name cashtab cashtab_local
  1. Navigate to localhost:8080
  2. Open up the dev console and check the "Network" tab
  3. Hard refresh the page.
  4. Observe largest bundle size is 989kb

Checking the largest prod bundle size at Cashtab.com, we are at 958kb. So, even though the npm module is itself quite large, the impact on the prod bundle is I think acceptable.

This revision is now accepted and ready to land.May 31 2022, 23:26