Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
shonsirsha committed May 14, 2024
1 parent 76141fe commit 49b8151
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 4 deletions.
13 changes: 13 additions & 0 deletions app/frontend/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {ADALITE_CONFIG} from '../config'
import Exchange from './pages/exchange/exchange'
import NufiPreviewPage from './pages/nufiPreview/nufiPreviewPage'
import ErrorBoundary from './errorBoundary'
import * as bitbox from 'bitbox-api'
import {useEffect} from 'preact/hooks'

const {ADALITE_LOGOUT_AFTER} = ADALITE_CONFIG

Expand All @@ -25,6 +27,17 @@ const App = connect((state) => ({
shouldShowContactFormModal: state.shouldShowContactFormModal,
shouldShowUnexpectedErrorModal: state.shouldShowUnexpectedErrorModal,
}))(({pathname, displayWelcome, shouldShowContactFormModal, shouldShowUnexpectedErrorModal}) => {
useEffect(() => {

This comment has been minimized.

Copy link
@shonsirsha

shonsirsha May 20, 2024

Author Owner

Putting here just for debugging the crash

try {
bitbox.bitbox02ConnectAuto(() => {
console.log('Onclose')
}).then((x) => {
console.log('Debug bitbox connect', x)
})
} catch (e) {
console.error('BB lib error', e)
}
}, [])
const currentTab = pathname.split('/')[1]
if (currentTab === 'exchange') {
return <Exchange />
Expand Down
20 changes: 20 additions & 0 deletions app/frontend/components/pages/login/hardwareAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,26 @@ const LoadByHardwareWalletSection = () => {
<BitBoxLogoWhite />
</div>
</button>

<button
disabled={!ADALITE_CONFIG.ADALITE_ENABLE_BITBOX02 || isMobileOnly}
{...tooltip(
'Support for BitBox02 is temporarily disabled',
!ADALITE_CONFIG.ADALITE_ENABLE_BITBOX02
)}
{...tooltip('Not supported on mobile devices', isMobileOnly)}
className="button primary thin-data-balloon"
onClick={async () => {
// console.log('a')

}
}
>
<span className="authentication-button-label">Unlock with NEW </span>
<div className="bitbox-logo-container">
<BitBoxLogoWhite />
</div>
</button>
</div>
</div>
<div className="authentication-hw-bulk-public-export">
Expand Down
2 changes: 2 additions & 0 deletions app/frontend/wallet/helpers/cryptoProviderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export function getDeviceBrandName(providerType: HwWalletCryptoProviderType): Wa

export function getWalletName(providerType: CryptoProviderType): WalletName {
switch (providerType) {
case CryptoProviderType.BITBOX02_NEW:
return WalletName.BITBOX02_NEW
case CryptoProviderType.BITBOX02:
return WalletName.BITBOX02
case CryptoProviderType.LEDGER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import ShelleyTrezorCryptoProvider from './shelley-trezor-crypto-provider'
import ShelleyLedgerCryptoProvider from './shelley-ledger-crypto-provider'
import {CryptoProvider} from '../../types'
import {InternalError, InternalErrorReason} from '../../errors'
import XShelleyBitBox02CryptoProvider from './shelley-new-bb020-crypto-provider'

const ShelleyCryptoProviderFactory = (() => {
const getCryptoProvider = (
cryptoProviderType: CryptoProviderType,
options: any
): Promise<CryptoProvider> => {
switch (cryptoProviderType) {
case CryptoProviderType.BITBOX02_NEW:
return XShelleyBitBox02CryptoProvider(options)
case CryptoProviderType.BITBOX02:
return ShelleyBitBox02CryptoProvider(options)
case CryptoProviderType.TREZOR:
Expand Down
39 changes: 39 additions & 0 deletions app/frontend/wallet/shelley/shelley-new-bb020-crypto-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {Network} from '../types'

import * as bitbox from 'bitbox-api'


let NEWactiveBitBox02: bitbox.PairedBitBox | null = null

type CryptoProviderParams = {
network: Network
config: any
}


const XShelleyBitBox02CryptoProvider = async ({
network,
config,
}: CryptoProviderParams): Promise<any> => {

if (NEWactiveBitBox02 !== null) {
try {
NEWactiveBitBox02.close()
} finally {
NEWactiveBitBox02 = null
}
}


async function withDevice<T>(f: (BitBox02API) => Promise<T>): Promise<any> {
try {


} catch (err) {

}
}

}

export default XShelleyBitBox02CryptoProvider
2 changes: 2 additions & 0 deletions app/frontend/wallet/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../types'

export const enum WalletName {
BITBOX02_NEW = 'BitBox02New',
BITBOX02 = 'BitBox02',
LEDGER = 'Ledger',
TREZOR = 'Trezor',
Expand Down Expand Up @@ -38,6 +39,7 @@ export type Network = {
}

export enum CryptoProviderType {
BITBOX02_NEW = 'BITBOX02_NEW',
BITBOX02 = 'BITBOX02',
LEDGER = 'LEDGER',
TREZOR = 'TREZOR',
Expand Down
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"babel-polyfill": "6.26.0",
"bignumber.js": "^9.0.2",
"bip39-light": "^1.0.7",
"bitbox-api": "^0.3.2",
"bitbox02-api": "^0.13.0",
"cardano-crypto.js": "^6.1.2",
"cbor": "^8.1.0",
Expand Down
10 changes: 10 additions & 0 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,11 @@ bip66@^1.1.5:
dependencies:
safe-buffer "^5.0.1"

bitbox-api@^0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/bitbox-api/-/bitbox-api-0.3.2.tgz#cc0acf3170400d203cc2c3618a13c928da00e263"
integrity sha512-w85zT4FFtMhaK3bNGQH7PVpOPvO0VDv8ZQxhgqqElqaGVGhv+ql+pE091/+St8R869Wot8HOEwMMd36osArnDQ==

bitbox02-api@^0.13.0:
version "0.13.0"
resolved "https://registry.yarnpkg.com/bitbox02-api/-/bitbox02-api-0.13.0.tgz#06566f943e960199b935abb4dc948cf6f84e53e1"
Expand Down Expand Up @@ -3956,6 +3961,11 @@ yallist@^4.0.0:
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==

yarn@^1.22.22:
version "1.22.22"
resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.22.tgz#ac34549e6aa8e7ead463a7407e1c7390f61a6610"
integrity sha512-prL3kGtyG7o9Z9Sv8IPfBNrWTDmXB4Qbes8A9rEzt6wkJV8mUvoirjU0Mp3GGAU06Y0XQyA3/2/RQFVuK7MTfg==

yauzl@^2.10.0:
version "2.10.0"
resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"
Expand Down
12 changes: 8 additions & 4 deletions webpack.build.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,16 @@ module.exports = {
// to avoid including webpack's 'crypto' if window.crypto is available - reduces bundle size
crypto: 'crypto',
},
experiments: {
asyncWebAssembly: true, // Enable async WebAssembly
topLevelAwait: true,
},
module: {
rules: [
{
test: /\.wasm$/,
type: 'webassembly/async',
},
{
test: /\.tsx?$/,
loader: 'ts-loader',
Expand Down Expand Up @@ -128,10 +136,6 @@ module.exports = {
},
},
},
// {
// test: /\.wasm$/,
// type: 'webassembly/experimental',
// },
],
},
resolve: {
Expand Down

0 comments on commit 49b8151

Please sign in to comment.