Skip to content

Commit 0e6e687

Browse files
committed
backend/devices: split bb02 and nova product names
We want to be able to show different banners to bb02 and bb02nova users. This adds a backend check to differentiate the product name and adds a new banner category for the nova.
1 parent 1577e22 commit 0e6e687

File tree

13 files changed

+69
-26
lines changed

13 files changed

+69
-26
lines changed

backend/backend.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ func (backend *Backend) Register(theDevice device.Interface) error {
792792
backend.Notify(observable.Event{
793793
Subject: fmt.Sprintf(
794794
"devices/%s/%s/%s",
795-
theDevice.ProductName(),
795+
theDevice.PlatformName(),
796796
theDevice.Identifier(),
797797
event.Subject),
798798
Action: event.Action,
@@ -814,8 +814,10 @@ func (backend *Backend) Register(theDevice device.Interface) error {
814814
switch theDevice.ProductName() {
815815
case bitbox.ProductName:
816816
backend.banners.Activate(banners.KeyBitBox01)
817-
case bitbox02.ProductName:
817+
case bitbox02.BitBox02ProductName:
818818
backend.banners.Activate(banners.KeyBitBox02)
819+
case bitbox02.BitBox02NovaProductName:
820+
backend.banners.Activate(banners.KeyBitBox02Nova)
819821
}
820822
return nil
821823
}
@@ -834,8 +836,10 @@ func (backend *Backend) Deregister(deviceID string) {
834836
switch device.ProductName() {
835837
case bitbox.ProductName:
836838
backend.banners.Deactivate(banners.KeyBitBox01)
837-
case bitbox02.ProductName:
839+
case bitbox02.BitBox02ProductName:
838840
backend.banners.Deactivate(banners.KeyBitBox02)
841+
case bitbox02.BitBox02NovaProductName:
842+
backend.banners.Deactivate(banners.KeyBitBox02Nova)
839843
}
840844

841845
}

backend/banners/banners.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ const (
5252
KeyBitBox01 MessageKey = "bitbox01"
5353
// KeyBitBox02 is the message key for the event when a BitBox02 gets connected.
5454
KeyBitBox02 MessageKey = "bitbox02"
55+
// KeyBitBox02Nova is the message key for the event when a BitBox02 Nova gets connected.
56+
KeyBitBox02Nova MessageKey = "bitbox02nova"
5557
)
5658

5759
// Message is one entry in the banners json.
@@ -77,8 +79,9 @@ type Banners struct {
7779

7880
url string
7981
banners struct {
80-
BitBox01 *Message `json:"bitbox01"`
81-
BitBox02 *Message `json:"bitbox02"`
82+
BitBox01 *Message `json:"bitbox01"`
83+
BitBox02 *Message `json:"bitbox02"`
84+
BitBox02nova *Message `json:"bitbox02nova"`
8285
}
8386

8487
active map[MessageKey]struct{}
@@ -162,6 +165,8 @@ func (banners *Banners) GetMessage(key MessageKey) *Message {
162165
return banners.banners.BitBox01
163166
case KeyBitBox02:
164167
return banners.banners.BitBox02
168+
case KeyBitBox02Nova:
169+
return banners.banners.BitBox02nova
165170
default:
166171
banners.log.Errorf("unrecognized key: %s", key)
167172
return nil

backend/devices/bitbox/device.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,11 @@ func (dbb *Device) ProductName() string {
10741074
return ProductName
10751075
}
10761076

1077+
// PlatformName implements device.Interface.
1078+
func (dbb *Device) PlatformName() string {
1079+
return ProductName
1080+
}
1081+
10771082
// Identifier implements device.Interface.
10781083
func (dbb *Device) Identifier() string {
10791084
return dbb.deviceID

backend/devices/bitbox02/device.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,23 @@ import (
2828
"github.com/sirupsen/logrus"
2929
)
3030

31-
// ProductName is the name of the BitBox02 product.
32-
// If you change this, be sure to check the frontend and other places which assume this is a
31+
// If you change these, be sure to check the frontend and other places which assume they are
3332
// constant.
34-
const ProductName = "bitbox02"
33+
const (
34+
// BitBox02ProductName is the name of the BitBox02 product.
35+
BitBox02ProductName = "bitbox02"
36+
// BitBox02NovaProductName is the name of the BitBox02 Nova product.
37+
BitBox02NovaProductName = "bitbox02nova"
38+
// PlatformName is the name of the BitVox02 platform.
39+
PlatformName = "bitbox02"
40+
)
3541

3642
// Device implements device.Device.
3743
type Device struct {
3844
firmware.Device
39-
deviceID string
40-
log *logrus.Entry
45+
deviceID string
46+
productName string
47+
log *logrus.Entry
4148

4249
observable.Implementation
4350
}
@@ -51,10 +58,16 @@ func NewDevice(
5158
communication firmware.Communication,
5259
opts ...firmware.DeviceOption,
5360
) *Device {
61+
productName := BitBox02ProductName
62+
// BitBox02Plus is the internal code name for the BitBox Nova.
63+
if product == bitbox02common.ProductBitBox02PlusBTCOnly ||
64+
product == bitbox02common.ProductBitBox02PlusMulti {
65+
productName = BitBox02NovaProductName
66+
}
5467
log := logging.Get().
5568
WithGroup("device").
5669
WithField("deviceID", deviceID).
57-
WithField("productName", ProductName).
70+
WithField("productName", productName).
5871
WithField("product", product)
5972

6073
log.Info("Plugged in device")
@@ -67,8 +80,9 @@ func NewDevice(
6780
logger{log},
6881
opts...,
6982
),
70-
deviceID: deviceID,
71-
log: log,
83+
deviceID: deviceID,
84+
productName: productName,
85+
log: log,
7286
}
7387
device.Device.SetOnEvent(func(ev firmware.Event, meta interface{}) {
7488
switch ev {
@@ -116,7 +130,12 @@ func (device *Device) init() {
116130

117131
// ProductName implements device.Device.
118132
func (device *Device) ProductName() string {
119-
return ProductName
133+
return device.productName
134+
}
135+
136+
// PlatformName implements device.Device.
137+
func (device *Device) PlatformName() string {
138+
return PlatformName
120139
}
121140

122141
// Identifier implements device.Device.

backend/devices/bitbox02bootloader/device.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ func (device *Device) ProductName() string {
119119
return ProductName
120120
}
121121

122+
// PlatformName implements device.Device.
123+
func (device *Device) PlatformName() string {
124+
return ProductName
125+
}
126+
122127
// Identifier implements device.Device.
123128
func (device *Device) Identifier() string {
124129
return device.deviceID

backend/devices/device/device.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ type Interface interface {
2525
observable.Interface
2626

2727
Init(testing bool) error
28-
// ProductName returns the product name of the device in lowercase/no spaces.
29-
// It acts as an identifier for the device type, not for display.
30-
// If you change a device's product name, be sure to check the frontend and other places which
28+
// PlatformName returns the Platform name of the device in lowercase/no spaces.
29+
// It acts as an identifier for the device type, not for the specific model (e.g.
30+
// it return bitbox02 for both the bitbox02 and the bitbox02 nova).
31+
// If you change a device's platform name, be sure to check the frontend and other places which
3132
// assume this is a constant.
33+
PlatformName() string
34+
35+
// ProductName is the actual model of the product in lowercase/no spaces
36+
// (e.g. bitbox, bitbox02, bitbox02nova).
3237
ProductName() string
3338

3439
// Identifier returns the hash of the type and the serial number.

backend/handlers/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ func (handlers *Handlers) postAccountsReinitialize(*http.Request) interface{} {
913913
func (handlers *Handlers) getDevicesRegistered(*http.Request) interface{} {
914914
jsonDevices := map[string]string{}
915915
for deviceID, device := range handlers.backend.DevicesRegistered() {
916-
jsonDevices[deviceID] = device.ProductName()
916+
jsonDevices[deviceID] = device.PlatformName()
917917
}
918918
return jsonDevices
919919
}

frontends/web/src/api/devices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
import { apiGet } from '@/utils/request';
1818

19-
export type TProductName = 'bitbox' | 'bitbox02' | 'bitbox02-bootloader';
19+
export type TPlatformName = 'bitbox' | 'bitbox02' | 'bitbox02-bootloader';
2020

2121
export type TDevices = {
22-
readonly [key in string]: TProductName;
22+
readonly [key in string]: TPlatformName;
2323
};
2424

2525
export const getDeviceList = (): Promise<TDevices> => {

frontends/web/src/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ export const App = () => {
188188
<Aopp />
189189
<KeystoreConnectPrompt />
190190
{
191-
Object.entries(devices).map(([deviceID, productName]) => {
192-
if (productName === 'bitbox02') {
191+
Object.entries(devices).map(([deviceID, platformName]) => {
192+
if (platformName === 'bitbox02') {
193193
return (
194194
<Fragment key={deviceID}>
195195
<BitBox02Wizard

frontends/web/src/components/banners/banner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { A } from '@/components/anchor/anchor';
2323
import style from './banner.module.css';
2424

2525
type TBannerProps = {
26-
msgKey: 'bitbox01' | 'bitbox02';
26+
msgKey: 'bitbox01' | 'bitbox02' | 'bitbox02nova';
2727
}
2828

2929
export const Banner = ({ msgKey }: TBannerProps) => {

0 commit comments

Comments
 (0)