Skip to content

Commit 67fc366

Browse files
committed
Merge branch 'frontend-type-post-calls'
2 parents a91f790 + 47a6a58 commit 67fc366

File tree

11 files changed

+83
-40
lines changed

11 files changed

+83
-40
lines changed

frontends/web/src/api/account.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,6 @@ export const addAccount = (coinCode: string, name: string): Promise<TAddAccount>
374374
});
375375
};
376376

377-
export const testRegister = (pin: string): Promise<null> => {
378-
return apiPost('test/register', { pin });
379-
};
380-
381377
export const connectKeystore = (code: AccountCode): Promise<{ success: boolean; }> => {
382378
return apiPost(`account/${code}/connect-keystore`);
383379
};
@@ -394,7 +390,6 @@ export type TSignWalletConnectTx = {
394390
rawTx: string;
395391
}
396392

397-
398393
export const ethSignMessage = (code: AccountCode, message: string): Promise<TSignMessage> => {
399394
return apiPost(`account/${code}/eth-sign-msg`, message);
400395
};
@@ -420,4 +415,3 @@ export type AddressSignResponse = {
420415
export const signAddress = (format: ScriptType | '', msg: string, code: AccountCode): Promise<AddressSignResponse> => {
421416
return apiPost(`account/${code}/sign-address`, { format, msg, code });
422417
};
423-

frontends/web/src/api/bitbox02.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2023 Shift Crypto AG
2+
* Copyright 2023-2024 Shift Crypto AG
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -181,3 +181,7 @@ export const getRootFingerprint = (
181181
export const invokeBIP85 = (deviceID: string): Promise<SuccessResponse | FailResponse> => {
182182
return apiPost(`devices/bitbox02/${deviceID}/invoke-bip85`);
183183
};
184+
185+
export const gotoStartupSettings = (deviceID: string) => {
186+
return apiPost(`devices/bitbox02/${deviceID}/goto-startup-settings`);
187+
};

frontends/web/src/api/keystores.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2023 Shift Crypto AG
2+
* Copyright 2023-2024 Shift Crypto AG
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { subscribeEndpoint, TUnsubscribe } from './subscribe';
18-
import { apiGet } from '../utils/request';
18+
import { apiGet, apiPost } from '../utils/request';
1919

2020
export type { TUnsubscribe };
2121

@@ -31,3 +31,11 @@ export const subscribeKeystores = (
3131
export const getKeystores = (): Promise<TKeystores> => {
3232
return apiGet('keystores');
3333
};
34+
35+
export const registerTest = (pin: string): Promise<null> => {
36+
return apiPost('test/register', { pin });
37+
};
38+
39+
export const deregisterTest = (): Promise<null> => {
40+
return apiPost('test/deregister');
41+
};

frontends/web/src/api/node.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright 2024 Shift Crypto AG
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { apiPost } from '../utils/request';
18+
import { SuccessResponse } from './response';
19+
20+
type TCertResponse = {
21+
success: true;
22+
pemCert: string;
23+
} | {
24+
success: false;
25+
errorMessage: string;
26+
};
27+
28+
export const downloadCert = (electrumServer: string): Promise<TCertResponse> => {
29+
return apiPost('certs/download', electrumServer);
30+
};
31+
32+
export type TElectrumServer = {
33+
server: string;
34+
tls: boolean;
35+
pemCert: string;
36+
};
37+
38+
type TCheckElectrumResponse = SuccessResponse | {
39+
success: false;
40+
errorMessage: string;
41+
};
42+
43+
export const checkElectrum = (server: TElectrumServer): Promise<TCheckElectrumResponse> => {
44+
return apiPost('electrum/check', server);
45+
};

frontends/web/src/components/sidebar/sidebar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright 2018 Shift Devices AG
3-
* Copyright 2021 Shift Crypto AG
3+
* Copyright 2021-2024 Shift Crypto AG
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -16,20 +16,20 @@
1616
*/
1717

1818
import React, { useContext, useEffect } from 'react';
19+
import { useLocation } from 'react-router';
1920
import { Link, NavLink } from 'react-router-dom';
2021
import { useTranslation } from 'react-i18next';
2122
import { useKeystores } from '../../hooks/backend';
2223
import { IAccount } from '../../api/account';
24+
import { deregisterTest } from '../../api/keystores';
2325
import coins from '../../assets/icons/coins.svg';
2426
import ejectIcon from '../../assets/icons/eject.svg';
2527
import shieldIcon from '../../assets/icons/shield_grey.svg';
2628
import linechart from '../../assets/icons/linechart.svg';
2729
import settings from '../../assets/icons/settings-alt.svg';
2830
import settingsGrey from '../../assets/icons/settings-alt_disabled.svg';
2931
import { debug } from '../../utils/env';
30-
import { apiPost } from '../../utils/request';
3132
import Logo, { AppLogoInverted } from '../icon/logo';
32-
import { useLocation } from 'react-router';
3333
import { CloseXWhite, USBSuccess } from '../icon';
3434
import { getAccountsByKeystore, isAmbiguiousName, isBitcoinOnly } from '../../routes/account/utils';
3535
import { SkipForTesting } from '../../routes/device/components/skipfortesting';
@@ -67,7 +67,7 @@ const GetAccountLink = ({
6767
};
6868

6969
const eject = (e: React.SyntheticEvent): void => {
70-
apiPost('test/deregister');
70+
deregisterTest();
7171
e.preventDefault();
7272
};
7373

frontends/web/src/routes/device/components/skipfortesting.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import React, { useState } from 'react';
18-
import { testRegister } from '../../../api/account';
18+
import { registerTest } from '../../../api/keystores';
1919
import { getTesting } from '../../../api/backend';
2020
import { Button } from '../../../components/forms';
2121
import { PasswordSingleInput } from '../../../components/password';
@@ -29,7 +29,7 @@ export const SkipForTesting = () => {
2929
const [testPIN, setTestPIN] = useState('');
3030
const registerTestingDevice = async (e: React.SyntheticEvent) => {
3131
e.preventDefault();
32-
await testRegister(testPIN);
32+
await registerTest(testPIN);
3333
setDialog(false);
3434
};
3535

frontends/web/src/routes/settings/components/device-settings/go-to-startup-settings.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2023 Shift Crypto AG
2+
* Copyright 2023-2024 Shift Crypto AG
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,10 +16,10 @@
1616

1717
import { useState } from 'react';
1818
import { useTranslation } from 'react-i18next';
19+
import { gotoStartupSettings } from '../../../../api/bitbox02';
1920
import { ChevronRightDark } from '../../../../components/icon';
2021
import { SettingsItem } from '../settingsItem/settingsItem';
2122
import { WaitDialog } from '../../../../components/wait-dialog/wait-dialog';
22-
import { apiPost } from '../../../../utils/request';
2323

2424
type TGoToStartupSettingsProps = {
2525
deviceID: string;
@@ -49,7 +49,7 @@ const GoToStartupSettings = ({ deviceID }: TGoToStartupSettingsProps) => {
4949
const [show, setShow] = useState(false);
5050
const handleGoToStartupSettings = async () => {
5151
setShow(true);
52-
await apiPost(`devices/bitbox02/${deviceID}/goto-startup-settings`).catch(console.error);
52+
await gotoStartupSettings(deviceID).catch(console.error);
5353
setShow(false);
5454
};
5555
return (

frontends/web/src/routes/settings/electrum-add-server.tsx

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

1717
import { useState } from 'react';
1818
import { useTranslation } from 'react-i18next';
19+
import { checkElectrum, downloadCert, TElectrumServer } from '../../api/node';
1920
import { Button, Input } from '../../components/forms';
20-
import { apiPost } from '../../utils/request';
2121
import { alertUser } from '../../components/alert/Alert';
22-
import { TElectrumServer } from './types';
2322
import style from './electrum.module.css';
2423

2524
type Props = {
@@ -50,9 +49,9 @@ export const ElectrumAddServer = ({
5049
setElectrumCert('');
5150
};
5251

53-
const downloadCert = async () => {
52+
const downloadCertificate = async () => {
5453
setLoadingCert(true);
55-
const data = await apiPost('certs/download', electrumServer.trim());
54+
const data = await downloadCert(electrumServer.trim());
5655
if (data.success) {
5756
setElectrumCert(data.pemCert);
5857
} else {
@@ -63,13 +62,13 @@ export const ElectrumAddServer = ({
6362

6463
const check = async () => {
6564
setLoadingCheck(true);
66-
const { success, errorMessage } = await apiPost('electrum/check', getServer());
67-
if (success) {
65+
const response = await checkElectrum(getServer());
66+
if (response.success) {
6867
alertUser(t('settings.electrum.checkSuccess', { host: electrumServer }));
6968
} else {
70-
alertUser(t('settings.electrum.checkFailed') + ':\n' + errorMessage);
69+
alertUser(t('settings.electrum.checkFailed') + ':\n' + response.errorMessage);
7170
}
72-
setValid(success);
71+
setValid(response.success);
7372
setLoadingCheck(false);
7473
};
7574

@@ -108,7 +107,7 @@ export const ElectrumAddServer = ({
108107
placeholder={'-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----'}
109108
/>
110109
<div className={[style.block, 'flex flex-row flex-end'].join(' ')}>
111-
<Button primary disabled={downloadCertButtonDisabled} onClick={downloadCert}>
110+
<Button primary disabled={downloadCertButtonDisabled} onClick={downloadCertificate}>
112111
{
113112
loadingCert && (
114113
<div className={style.miniSpinnerContainer}>

frontends/web/src/routes/settings/electrum-server.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
import { useState } from 'react';
1818
import { useTranslation } from 'react-i18next';
19-
import { apiPost } from '../../utils/request';
19+
import { TElectrumServer, checkElectrum } from '../../api/node';
2020
import { alertUser } from '../../components/alert/Alert';
21-
import { TElectrumServer } from './types';
2221
import style from './electrum.module.css';
2322

2423
type Props = {
@@ -35,15 +34,15 @@ export const ElectrumServer = ({
3534

3635
const check = async () => {
3736
setLoadingCheck(true);
38-
const { success, errorMessage } = await apiPost('electrum/check', {
37+
const response = await checkElectrum({
3938
server: server.server.trim(),
4039
pemCert: server.pemCert,
4140
tls: server.tls,
4241
});
43-
if (success) {
42+
if (response.success) {
4443
alertUser(t('settings.electrum.checkSuccess', { host: server.server }));
4544
} else {
46-
alertUser(t('settings.electrum.checkFailed') + ':\n' + errorMessage);
45+
alertUser(t('settings.electrum.checkFailed') + ':\n' + response.errorMessage);
4746
}
4847
setLoadingCheck(false);
4948
};

frontends/web/src/routes/settings/electrum-servers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
import { useEffect, useState } from 'react';
1818
import { useTranslation } from 'react-i18next';
19+
import type { TElectrumServer } from '../../api/node';
1920
import { ElectrumAddServer } from './electrum-add-server';
2021
import { ElectrumServer } from './electrum-server';
21-
import { TElectrumServer } from './types';
2222
import { getDefaultConfig } from '../../api/backend';
2323
import { getConfig, setConfig } from '../../utils/config';
2424
import { confirmation } from '../../components/confirm/Confirm';

frontends/web/src/routes/settings/types.ts

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

17-
export type TElectrumServer = {
18-
server: string;
19-
tls: boolean;
20-
pemCert: string;
21-
};
22-
2317
export type TPagePropsWithSettingsTabs = {
2418
deviceIDs: string[];
2519
hasAccounts: boolean;
26-
};
20+
};

0 commit comments

Comments
 (0)