Skip to content

Commit

Permalink
fix: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vvava committed Nov 15, 2024
1 parent d481576 commit d3866c4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/background/services/wallet/handlers/importLedger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ export class ImportLedgerHandler implements HandlerType {
}

handle: HandlerType['handle'] = async ({ request }) => {
const [
{ xpub, xpubXP, pubKeys, secretType, name, onlyCheckWalletIsExist },
] = request.params;
const [{ xpub, xpubXP, pubKeys, secretType, name, dryRun }] =
request.params;

if (
secretType !== SecretType.Ledger &&
Expand Down Expand Up @@ -70,11 +69,12 @@ export class ImportLedgerHandler implements HandlerType {
};
}

if (onlyCheckWalletIsExist) {
if (dryRun) {
return {
...request,
result: {
id: '0',
name,
type: secretType,
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/background/services/wallet/handlers/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type ImportLedgerWalletParams = {
pubKeys?: PubKeyType[];
secretType: SecretType.Ledger | SecretType.LedgerLive;
name?: string;
onlyCheckWalletIsExist?: boolean;
dryRun?: boolean;
};

export type ImportWalletResult = {
Expand Down
14 changes: 7 additions & 7 deletions src/components/ledger/LedgerConnector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export interface LedgerConnectorData {
interface LedgerConnectorProps {
onSuccess: (data: LedgerConnectorData) => void;
onTroubleshoot: () => void;
checkWalletIsExist?: boolean;
checkWalletExists?: boolean;
}

export function LedgerConnector({
onSuccess,
onTroubleshoot,
checkWalletIsExist,
checkWalletExists,
}: LedgerConnectorProps) {
const theme = useTheme();
const { capture } = useAnalyticsContext();
Expand Down Expand Up @@ -128,7 +128,7 @@ export function LedgerConnector({
derivationPath === DerivationPath.BIP44
? SecretType.Ledger
: SecretType.LedgerLive,
onlyCheckWalletIsExist: true,
dryRun: true,
});
} catch (e) {
setIsLedgerExistsError(true);
Expand All @@ -144,7 +144,7 @@ export function LedgerConnector({
const xpubXPValue = await getExtendedPublicKey(
Avalanche.LedgerWallet.getAccountPath('X')
);
if (checkWalletIsExist) {
if (checkWalletExists) {
await checkLedgerWalletIsExist({
xpub: xpubValue,
xpubXP: xpubXPValue,
Expand All @@ -170,7 +170,7 @@ export function LedgerConnector({
}, [
capture,
checkLedgerWalletIsExist,
checkWalletIsExist,
checkWalletExists,
getAddressFromXpubKey,
getExtendedPublicKey,
onSuccess,
Expand Down Expand Up @@ -225,7 +225,7 @@ export function LedgerConnector({
...pubKeys,
{ evm: pubKey.toString('hex'), xp: pubKeyXP.toString('hex') },
];
if (checkWalletIsExist) {
if (checkWalletExists) {
await checkLedgerWalletIsExist({
xpub: '',
xpubXP: '',
Expand All @@ -251,7 +251,7 @@ export function LedgerConnector({
[
capture,
checkLedgerWalletIsExist,
checkWalletIsExist,
checkWalletExists,
getAvaxBalance,
getPublicKey,
onSuccess,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Accounts/AddWalletWithLedger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export function AddWalletWithLedger() {
<LedgerConnector
onSuccess={onSuccess}
onTroubleshoot={() => setStep(Step.Troubleshoot)}
checkWalletIsExist
checkWalletExists
/>
</Stack>
<Stack sx={{ p: 2, mb: 2, rowGap: 1 }}>
Expand Down
2 changes: 0 additions & 2 deletions src/pages/ImportPrivateKey/ImportPrivateKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ export function ImportPrivateKey() {
[allAccounts]
);

console.log('allAccounts: ', allAccounts);

const isLoading = hasFocus && !derivedAddresses && !error;

const handleImport = async () => {
Expand Down

0 comments on commit d3866c4

Please sign in to comment.