Skip to content

Commit 279998f

Browse files
committed
frontend/add-account: ask user to connect BitBox02 to continue
Since watchonly, one can enter this screen without a keystore connected. If so, we ask the user to connect to proceed.
1 parent 3115751 commit 279998f

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

frontends/web/src/api/backend.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { AccountCode, CoinCode } from './account';
1818
import { apiGet, apiPost } from '../utils/request';
1919
import { FailResponse, SuccessResponse } from './response';
20-
import { TSubscriptionCallback, subscribeEndpoint } from './subscribe';
20+
import { TSubscriptionCallback, TUnsubscribe, subscribeEndpoint } from './subscribe';
2121

2222
export interface ICoin {
2323
coinCode: CoinCode;
@@ -125,3 +125,15 @@ export const subscribeAuth = (
125125
) => (
126126
subscribeEndpoint('auth', cb)
127127
);
128+
129+
/**
130+
* Returns a function that subscribes a callback on "keystores". It is called whenever a keystore
131+
* is connected or disconnected.
132+
*/
133+
export const syncKeystores = (
134+
cb: () => void
135+
): TUnsubscribe => {
136+
return subscribeEndpoint('keystores', () => {
137+
cb();
138+
});
139+
};

frontends/web/src/routes/account/add/add.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import React, { useEffect, useRef, useState } from 'react';
17+
import React, { useCallback, useEffect, useRef, useState } from 'react';
1818
import { useTranslation } from 'react-i18next';
1919
import * as backendAPI from '../../../api/backend';
2020
import { SimpleMarkup } from '../../../utils/markup';
@@ -45,10 +45,6 @@ export const AddAccount = () => {
4545

4646
const { t } = useTranslation();
4747

48-
useEffect(() => {
49-
startProcess();
50-
}, []);
51-
5248
useEffect(() => {
5349
if (step === 'choose-name') {
5450
inputRef.current?.focus();
@@ -59,7 +55,7 @@ export const AddAccount = () => {
5955
return supportedCoins.length === 1;
6056
};
6157

62-
const startProcess = async () => {
58+
const startProcess = useCallback(async () => {
6359
try {
6460
const coins = await backendAPI.getSupportedCoins();
6561
const onlyOneCoinIsSupported = (coins.length === 1);
@@ -73,7 +69,16 @@ export const AddAccount = () => {
7369
} catch (err) {
7470
console.error(err);
7571
}
76-
};
72+
}, []);
73+
74+
useEffect(() => {
75+
startProcess();
76+
77+
const unsubscribe = backendAPI.syncKeystores(() => {
78+
startProcess();
79+
});
80+
return unsubscribe;
81+
}, [startProcess]);
7782

7883
const back = () => {
7984
switch (step) {
@@ -122,6 +127,13 @@ export const AddAccount = () => {
122127
const renderContent = () => {
123128
switch (step) {
124129
case 'select-coin':
130+
if (supportedCoins.length === 0) {
131+
return (
132+
<div className="text-center">
133+
{t('connectKeystore.promptNoName')}
134+
</div>
135+
);
136+
}
125137
return (
126138
<CoinDropDown
127139
onChange={coin => {

0 commit comments

Comments
 (0)