Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the new BitBox02 library #1406

Open
shonsirsha opened this issue Apr 18, 2024 · 3 comments
Open

Use the new BitBox02 library #1406

shonsirsha opened this issue Apr 18, 2024 · 3 comments

Comments

@shonsirsha
Copy link

shonsirsha commented Apr 18, 2024

Hey, a new BitBox02 library is available: https://www.npmjs.com/package/bitbox-api which replaces the current bitbox02-api (deprecated).

This new one is much smaller in size, comes with TS, is a proper ES6 module, and based on WASM. Would you be open to use this? If so, I'd be happy to contribute to this effort.

This is the sandbox for the new library, and you could also find some more information one the Bitbox02 Developer Resources.

Thanks.

@refi93
Copy link
Collaborator

refi93 commented Apr 18, 2024

Hi @shonsirsha, thanks for the heads up. Sure, feel free to make the PR and we'll review it 👍 When it comes to the lib size, we are currently tackling the problem by using async imports so it's not a pressing issue for us. Nevertheless, updating the lib would streamline/simplify our current integration which relies on manually added type definitions

@shonsirsha
Copy link
Author

Hey @refi93 , I noticed that when using any instance of the new bitbox-api package anywhere in the app, the app will crash with no error logs. Just a total white screen. The error boundary also didn't catch any error.

Reproducible commit: shonsirsha@49b8151 (see app.tsx)

More detail:

The app crashes from anything as simple as the following:

import * as bitbox from "bitbox-api"

// ....

  useEffect(() => {
    console.log('Bitbox module:', bitbox)
  }, [])

This console.log didn't even run.

I've also tried installing the bitbox-api package in a fresh preact project (using Vite) and this issue didn't occur. Same with react + webpack.

I'm wondering if there's anything specific I should know about the error handling in this project, or anything in particular in the Adalite app you'd suggest me taking a look at? Thanks a lot.

Note: keeping only the import statement didn't cause the crash.

Crash screenshots:

xassax WSOD

renders undefined in the DOM

@refi93
Copy link
Collaborator

refi93 commented May 20, 2024

Hi @shonsirsha , bitbox-api is apparently wasm-based. What worked for me was either to load the module asynchronously:

useEffect(() => {
    const fn = async () => {
      const bitbox = await import('bitbox-api')
      bitbox.bitbox02ConnectAuto(() => {
        console.log('Onclose')
      }).then((x) => {
        console.log('Debug bitbox connect', x)
      }).catch((e) => console.error('BB lib error', e))
    }
    fn()
  }, [])

or for some reason that I don't understand yet, require seems to work fine as well :D

const bitbox = require('bitbox-api')

TBH I'm not sure why an ordinaryimport completely bricks the app, I can only vaguely imagine that doing calls while the underlying wasm module is being loaded/fetched can result in unpredictable behavior. Why it does work on other project I'm not sure TBH and I'd say it's not that much worth the investigation as it can be quite a lot of time for little added value as the solutions above seem to otherwise work fine.

All in all, I think it would anyway be the most sensible to load the bitbox lib asynchronously when actually used because the wasm module is ~725kB which while not that much, is still quite significant for a lib that is relevant only for a small fraction of users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants