Skip to content

frontend/add-account: ask user to connect BitBox02 to continue #2388

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

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions frontends/web/src/routes/account/add/add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* limitations under the License.
*/

import React, { useEffect, useRef, useState } from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import * as backendAPI from '../../../api/backend';
import * as keystoresAPI from '../../../api/keystores';
import { SimpleMarkup } from '../../../utils/markup';
import { Message } from '../../../components/message/message';
import { Button, Input } from '../../../components/forms';
Expand Down Expand Up @@ -45,10 +46,6 @@ export const AddAccount = () => {

const { t } = useTranslation();

useEffect(() => {
startProcess();
}, []);

useEffect(() => {
if (step === 'choose-name') {
inputRef.current?.focus();
Expand All @@ -59,7 +56,7 @@ export const AddAccount = () => {
return supportedCoins.length === 1;
};

const startProcess = async () => {
const startProcess = useCallback(async () => {
try {
const coins = await backendAPI.getSupportedCoins();
const onlyOneCoinIsSupported = (coins.length === 1);
Expand All @@ -73,7 +70,16 @@ export const AddAccount = () => {
} catch (err) {
console.error(err);
}
};
}, []);

useEffect(() => {
startProcess();

const unsubscribe = keystoresAPI.subscribeKeystores(() => {
startProcess();
});
return unsubscribe;
}, [startProcess]);

const back = () => {
switch (step) {
Expand Down Expand Up @@ -122,6 +128,13 @@ export const AddAccount = () => {
const renderContent = () => {
switch (step) {
case 'select-coin':
if (supportedCoins.length === 0) {
return (
<Message type="info">
{t('connectKeystore.promptNoName')}
</Message>
);
}
return (
<CoinDropDown
onChange={coin => {
Expand Down