diff --git a/background/utils/internal-signer.ts b/background/utils/internal-signer.ts deleted file mode 100644 index 89ac445cd..000000000 --- a/background/utils/internal-signer.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* eslint-disable import/prefer-default-export */ -import { isHexString } from "ethers/lib/utils" - -export function validatePrivateKey(privateKey = ""): boolean { - try { - const paddedKey = privateKey.startsWith("0x") - ? privateKey - : `0x${privateKey}` - // valid pk has 32 bytes -> 64 hex characters - return ( - isHexString(paddedKey) && BigInt(paddedKey).toString(16).length === 64 - ) - } catch (e) { - return false - } -} diff --git a/ui/_locales/en/messages.json b/ui/_locales/en/messages.json index 97da9d778..b9cada0d7 100644 --- a/ui/_locales/en/messages.json +++ b/ui/_locales/en/messages.json @@ -411,7 +411,7 @@ "subtitle": "Importing a private key does not associate it to a secret recovery phrase, but it’s still protected by the same password", "inputLabel": "Paste private key string", "submit": "Import account", - "error": "Invalid private key", + "errorImport": "Importing private key failed", "privateKey": "Private key", "password": "JSON file password", "json": "JSON", @@ -1030,4 +1030,4 @@ "earn": "Earn", "settings": "Settings" } -} +} \ No newline at end of file diff --git a/ui/pages/Onboarding/Tabbed/ImportPrivateKey.tsx b/ui/pages/Onboarding/Tabbed/ImportPrivateKey.tsx index 6ecc06254..4cb850192 100644 --- a/ui/pages/Onboarding/Tabbed/ImportPrivateKey.tsx +++ b/ui/pages/Onboarding/Tabbed/ImportPrivateKey.tsx @@ -5,7 +5,6 @@ import { SignerSourceTypes } from "@tallyho/tally-background/services/internal-s import React, { ReactElement, useCallback, useState } from "react" import { useTranslation } from "react-i18next" import { AsyncThunkFulfillmentType } from "@tallyho/tally-background/redux-slices/utils" -import { validatePrivateKey } from "@tallyho/tally-background/utils/internal-signer" import SharedButton from "../../../components/Shared/SharedButton" import SharedSeedInput from "../../../components/Shared/SharedSeedInput" import { useBackgroundDispatch } from "../../../hooks" @@ -34,23 +33,22 @@ export default function ImportPrivateKey(props: Props): ReactElement { const importWallet = useCallback(async () => { const trimmedPrivateKey = privateKey.toLowerCase().trim() - if (validatePrivateKey(trimmedPrivateKey)) { - setIsImporting(true) - const { success } = (await dispatch( - importSigner({ - type: SignerSourceTypes.privateKey, - privateKey: trimmedPrivateKey, - }), - )) as unknown as AsyncThunkFulfillmentType - if (success) { - dispatch(sendEvent(OneTimeAnalyticsEvent.ONBOARDING_FINISHED)) - finalize() - } else { - setIsImporting(false) - } + setIsImporting(true) + + const { success } = (await dispatch( + importSigner({ + type: SignerSourceTypes.privateKey, + privateKey: trimmedPrivateKey, + }), + )) as unknown as AsyncThunkFulfillmentType + + if (success) { + dispatch(sendEvent(OneTimeAnalyticsEvent.ONBOARDING_FINISHED)) + finalize() } else { - setErrorMessage(t("error")) + setIsImporting(false) + setErrorMessage(t("errorImport")) } }, [dispatch, privateKey, setIsImporting, finalize, t])