Skip to content

Commit

Permalink
Merge branch 'fix/keystone' into tmp/20241010
Browse files Browse the repository at this point in the history
  • Loading branch information
heisenberg-2077 committed Oct 8, 2024
2 parents 160b8d3 + d5b2e3a commit 86540d2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 15 deletions.
5 changes: 4 additions & 1 deletion apps/mobile/src/components/HDSetting/MainContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface Setting {
startNumber: number;
}

interface Props {
export interface Props {
hdPathOptions: {
title: string;
description: string;
Expand All @@ -46,6 +46,7 @@ interface Props {
setting: Setting;
loading?: boolean;
children?: React.ReactNode;
disableHdPathOptions?: boolean;
}

const getStyles = (colors: AppColorsVariants) =>
Expand Down Expand Up @@ -143,6 +144,7 @@ export const MainContainer: React.FC<Props> = ({
onConfirm,
loading,
children,
disableHdPathOptions,
}) => {
const [fetching, setFetching] = React.useState(false);
const { t } = useTranslation();
Expand Down Expand Up @@ -201,6 +203,7 @@ export const MainContainer: React.FC<Props> = ({
<View style={styles.list}>
{currentHdPathOptions.map(option => (
<TouchableOpacity
disabled={disableHdPathOptions}
style={styles.item}
onPress={() => {
setHdPath(option.value);
Expand Down
68 changes: 54 additions & 14 deletions apps/mobile/src/components/HDSetting/SettingKeystone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { useAtom } from 'jotai';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Modal, StyleSheet, Text, View } from 'react-native';
import { isLoadedAtom, MainContainer, settingAtom } from './MainContainer';
import {
isLoadedAtom,
MainContainer,
settingAtom,
Props as MainContainerProps,
} from './MainContainer';
import { HardwareSVG } from '@/assets/icons/address';
import { AppColorsVariants } from '@/constant/theme';
import { useThemeColors } from '@/hooks/theme';
Expand Down Expand Up @@ -97,19 +102,53 @@ export const SettingKeystone: React.FC<{
}> = ({ onDone, brand }) => {
const { t } = useTranslation();
const [, setLoading] = React.useState(false);
const hdPathOptions = React.useMemo(
() => [
{
title: 'Default',
description: t('page.newAddress.hd.keystone.hdPathType.bip44'),
noChainDescription: t(
'page.newAddress.hd.keystone.hdPathTypeNoChain.bip44',
),
value: LedgerHDPathType.BIP44,
},
],
[t],
);
const [hdPathOptions, setHdPathOptions] = React.useState<
MainContainerProps['hdPathOptions']
>([]);

React.useEffect(() => {
const getHdPathOptions = async () => {
const hdPathType = await apiKeystone.getCurrentUsedHDPathType();

if (hdPathType === LedgerHDPathType.BIP44) {
return [
{
title: 'BIP44',
description: t('page.newAddress.hd.keystone.hdPathType.bip44'),
noChainDescription: t(
'page.newAddress.hd.keystone.hdPathTypeNoChain.bip44',
),
value: LedgerHDPathType.BIP44,
},
];
} else if (hdPathType === LedgerHDPathType.LedgerLive) {
return [
{
title: 'Ledger Live',
description: t('page.newAddress.hd.keystone.hdPathType.legerLive'),
noChainDescription: t(
'page.newAddress.hd.keystone.hdPathTypeNoChain.legerLive',
),
value: LedgerHDPathType.LedgerLive,
},
];
} else {
return [
{
title: 'Legacy',
description: t('page.newAddress.hd.keystone.hdPathType.legacy'),
noChainDescription: t(
'page.newAddress.hd.keystone.hdPathTypeNoChain.legacy',
),
value: LedgerHDPathType.Legacy,
},
];
}
};

getHdPathOptions().then(setHdPathOptions);
}, [t]);

const colors = useThemeColors();
const styles = React.useMemo(() => getStyles(colors), [colors]);
const [setting, setSetting] = useAtom(settingAtom);
Expand Down Expand Up @@ -151,6 +190,7 @@ export const SettingKeystone: React.FC<{
return (
<MainContainer
hdPathOptions={hdPathOptions}
disableHdPathOptions
onConfirm={handleConfirm}
setting={setting}>
<TouchableOpacity onPress={handleOpenSwitch} style={styles.switchButton}>
Expand Down

0 comments on commit 86540d2

Please sign in to comment.