Skip to content

Commit

Permalink
refactor: renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
vvava committed Dec 2, 2024
1 parent 7e76a7c commit 8d1999b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
18 changes: 10 additions & 8 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;
isWalletExist?: boolean;
checkIfWalletExists?: boolean;
}

export function LedgerConnector({
onSuccess,
onTroubleshoot,
isWalletExist,
checkIfWalletExists,
}: LedgerConnectorProps) {
const theme = useTheme();
const { capture } = useAnalyticsContext();
Expand Down Expand Up @@ -131,8 +131,10 @@ export function LedgerConnector({
dryRun: true,
});
} catch (e) {
setIsLedgerExistsError(true);
throw new Error('wallet already exists');
if (typeof e === 'string' && e === 'This wallet already exists') {
setIsLedgerExistsError(true);
}
throw new Error(String(e));
}
},
[importLedger]
Expand All @@ -144,7 +146,7 @@ export function LedgerConnector({
const xpubXPValue = await getExtendedPublicKey(
Avalanche.LedgerWallet.getAccountPath('X')
);
if (isWalletExist) {
if (checkIfWalletExists) {
await isLedgerWalletExist({
xpub: xpubValue,
xpubXP: xpubXPValue,
Expand All @@ -170,7 +172,7 @@ export function LedgerConnector({
}, [
capture,
isLedgerWalletExist,
isWalletExist,
checkIfWalletExists,
getAddressFromXpubKey,
getExtendedPublicKey,
onSuccess,
Expand Down Expand Up @@ -225,7 +227,7 @@ export function LedgerConnector({
...pubKeys,
{ evm: pubKey.toString('hex'), xp: pubKeyXP.toString('hex') },
];
if (isWalletExist) {
if (checkIfWalletExists) {
await isLedgerWalletExist({
xpub: '',
xpubXP: '',
Expand All @@ -251,7 +253,7 @@ export function LedgerConnector({
[
capture,
isLedgerWalletExist,
isWalletExist,
checkIfWalletExists,
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)}
isWalletExist
checkIfWalletExists
/>
</Stack>
<Stack sx={{ p: 2, mb: 2, rowGap: 1 }}>
Expand Down
12 changes: 6 additions & 6 deletions src/pages/ImportPrivateKey/ImportPrivateKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export function ImportPrivateKey() {
const history = useHistory();
const { allAccounts } = useAccountsContext();
const [isKnownAccount, setIsKnownAccount] = useState(false);
const [isDuplicatedAccountDialogOpen, setIsDuplicatedDialogDialogOpen] =
const [isDuplicatedAccountDialogOpen, setIsDuplicatedAccountDialogOpen] =
useState(false);

const checkAccount = useCallback(
const checkIfAccountExists = useCallback(
(address) => {
const findAccount = allAccounts.find(
({ addressC }) => addressC.toLowerCase() === address.toLowerCase()
Expand All @@ -75,7 +75,7 @@ export function ImportPrivateKey() {
const handleImport = async () => {
capture('ImportPrivateKeyClicked');
if (isKnownAccount && !isDuplicatedAccountDialogOpen) {
setIsDuplicatedDialogDialogOpen(true);
setIsDuplicatedAccountDialogOpen(true);
return;
}
try {
Expand Down Expand Up @@ -103,7 +103,7 @@ export function ImportPrivateKey() {
const publicKey = getPublicKeyFromPrivateKey(strippedPk);

const addressC = getEvmAddressFromPubKey(publicKey);
checkAccount(addressC);
checkIfAccountExists(addressC);

const addressBTC = getBtcAddressFromPubKey(
publicKey,
Expand All @@ -121,7 +121,7 @@ export function ImportPrivateKey() {
} else {
errorHandler();
}
}, [checkAccount, isKnownAccount, network?.isTestnet, privateKey]);
}, [checkIfAccountExists, isKnownAccount, network?.isTestnet, privateKey]);

useEffect(() => {
if (derivedAddresses && updateBalanceOnNetworks) {
Expand All @@ -136,7 +136,7 @@ export function ImportPrivateKey() {
<>
{isKnownAccount && (
<DuplicatedAccountDialog
onClose={() => setIsDuplicatedDialogDialogOpen(false)}
onClose={() => setIsDuplicatedAccountDialogOpen(false)}
onConfirm={() => handleImport()}
open={isDuplicatedAccountDialogOpen}
/>
Expand Down

0 comments on commit 8d1999b

Please sign in to comment.