Skip to content

Commit

Permalink
Merge branch 'frontend-refactor-account-III'
Browse files Browse the repository at this point in the history
  • Loading branch information
thisconnect committed Oct 5, 2022
2 parents cae608e + 6cd7d12 commit c9674d4
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 303 deletions.
6 changes: 6 additions & 0 deletions frontends/web/src/api/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ export const getQRCode = (data: string) => {
return apiGet(`qr?data=${encodeURIComponent(data)}`);
};
};

export const isMoonpayBuySupported = (code: string) => {
return (): Promise<boolean> => {
return apiGet(`exchange/moonpay/buy-supported/${code}`);
};
};
6 changes: 6 additions & 0 deletions frontends/web/src/api/bitbox02.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export const getDeviceInfo = (
});
};

export const checkSDCard = (
deviceID: string,
): Promise<boolean> => {
return apiGet(`devices/bitbox02/${deviceID}/check-sdcard`);
};

export const setDeviceName = (
deviceID: string,
newDeviceName: string,
Expand Down
58 changes: 58 additions & 0 deletions frontends/web/src/hooks/sdcard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright 2022 Shift Crypto AG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { DependencyList, useEffect, useState } from 'react';
import { TDevices } from '../api/devices';
import { checkSDCard } from '../api/bitbox02';
import { getDeviceInfo as getBitBox01DeviceInfo } from '../api/bitbox01';
import { useMountedRef } from './utils';

/**
* useSDCard hook to check if one of the devices has a SDCard plugged in
* @param devices which to check
* @param dependencies optional array to re-run the check if any of the dependency change, devices is automatically added to the dependencies list
*/
export const useSDCard = (
devices: TDevices,
dependencies?: DependencyList,
) => {
const [sdcard, setSDCard] = useState<boolean>(false);
const mounted = useMountedRef();
useEffect(() => {
const deviceIDs = Object.keys(devices);
Promise.all(deviceIDs.map(deviceID => {
switch (devices[deviceID]) {
case 'bitbox':
return getBitBox01DeviceInfo(deviceID)
.then(({ sdcard }) => sdcard);
case 'bitbox02':
return checkSDCard(deviceID);
default:
return false;
}
}))
.then(sdcards => sdcards.some(sdcard => sdcard))
.then(result => {
if (mounted.current) {
setSDCard(result);
}
})
.catch(console.error);
// disable warning about mounted not in the dependency list
}, [devices, ...(dependencies || [])] ); // eslint-disable-line react-hooks/exhaustive-deps

return sdcard;
};
8 changes: 0 additions & 8 deletions frontends/web/src/locales/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
"exportTransactions": "Export transactions to downloads folder as CSV file",
"fatalError": "There was an unexpected error.",
"incoming": "Incoming",
"info": {
"btc-p2pkh": "This is a legacy Bitcoin account. It is recommended that you use the Segwit Bitcoin account instead, as it incurs lower network fees.",
"btc-p2wpkh": "This Native Segwit Bitcoin account incurs even lower network fees through the bech32 address format. It's bleeding edge technology but not yet widely supported.",
"btc-p2wpkh-p2sh": "This is a Segwit Bitcoin account, and is recommended for lower network fees. If you have just upgraded from the previous app, you can find your funds in the Bitcoin Legacy account, which you can enable in the settings. If you want to try cutting edge technology and save even more network fees, go to Settings and enable a Native Segwit Bitcoin account, which uses the Bech32 address format.",
"tbtc-p2pkh": "$t(account.info.btc-p2pkh)",
"tbtc-p2wpkh": "$t(account.info.btc-p2wpkh)",
"tbtc-p2wpkh-p2sh": "$t(account.info.btc-p2wpkh-p2sh)"
},
"initializing": "Getting information from the blockchain…",
"maybeProxyError": "Tor proxy enabled. Ensure that your Tor proxy is running properly, or disable the proxy setting.",
"reconnecting": "Lost connection, trying to reconnect…",
Expand Down
Loading

0 comments on commit c9674d4

Please sign in to comment.