Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix/seed' into tmp/20241224
Browse files Browse the repository at this point in the history
  • Loading branch information
richardo2016x committed Dec 23, 2024
2 parents 9379ffa + 25885f9 commit 53d2f6e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
33 changes: 21 additions & 12 deletions apps/mobile/src/components/HDSetting/SettingHDKeyring.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import { LedgerHDPathType } from '@rabby-wallet/eth-keyring-ledger/dist/utils';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { MainContainer, settingAtom } from './MainContainer';
import { requestKeyring } from '@/core/apis/keyring';
import { KEYRING_CLASS } from '@rabby-wallet/keyring-utils';
import { useAtom } from 'jotai';
import { apiMnemonic } from '@/core/apis';

export const SettingHDKeyring: React.FC<{
onDone: () => void;
mnemonics: string;
passphrase: string;
keyringId: number;
}> = ({ onDone, keyringId }) => {
}> = ({ onDone, mnemonics, passphrase }) => {
const { t } = useTranslation();
const [setting, setSetting] = useAtom(settingAtom);

Expand Down Expand Up @@ -45,19 +43,30 @@ export const SettingHDKeyring: React.FC<{
[t],
);

const mnemonicKeyringRef = React.useRef<
ReturnType<typeof apiMnemonic.getKeyringByMnemonic> | undefined
>(undefined);
const getMnemonicKeyring = React.useCallback(() => {
if (mnemonics) {
if (!mnemonicKeyringRef.current) {
mnemonicKeyringRef.current = apiMnemonic.getKeyringByMnemonic(
mnemonics!,
passphrase!,
);
}
return mnemonicKeyringRef.current;
}
return undefined;
}, [mnemonics, passphrase]);

const handleConfirm = React.useCallback(
async value => {
await requestKeyring(
KEYRING_CLASS.MNEMONIC,
'setHDPathType',
keyringId || null,
value.hdPath,
);

const keyring = await getMnemonicKeyring();
await keyring?.setHDPathType(value.hdPath);
setSetting(value);
onDone?.();
},
[keyringId, onDone, setSetting],
[getMnemonicKeyring, onDone, setSetting],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ export const ImportMoreAddress: React.FC<Props> = ({ params, onCancel }) => {
async (index: number) => {
const res =
params.type === KEYRING_TYPE.HdKeyring
? await apiKeyring.requestKeyring(
KEYRING_TYPE.HdKeyring,
'getAddresses',
params?.keyringId ?? null,
? await getMnemonicKeyring()?.getAddresses(
index,
index + stepCountRef.current,
)
Expand Down Expand Up @@ -171,7 +168,7 @@ export const ImportMoreAddress: React.FC<Props> = ({ params, onCancel }) => {
});
}
},
[apiHD, params?.keyringId, params.type],
[apiHD, getMnemonicKeyring, params.type],
);

const handleLoadAddress = React.useCallback(async () => {
Expand Down Expand Up @@ -384,9 +381,22 @@ export const ImportMoreAddress: React.FC<Props> = ({ params, onCancel }) => {
onDone: () => {
removeGlobalBottomSheetModal2024(id);
},
...(params.type ? { keyringId: params.keyringId } : {}),
...(params.type
? {
keyringId: params.keyringId,
mnemonics: params.mnemonics,
passphrase: params.passphrase,
}
: {}),
});
}, [params.brand, params.keyringId, params.type, settingModalName]);
}, [
params.brand,
params.keyringId,
params.mnemonics,
params.passphrase,
params.type,
settingModalName,
]);

return (
<View style={styles.root}>
Expand Down

0 comments on commit 53d2f6e

Please sign in to comment.