Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to import private key to validate it #3614

Merged
merged 3 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions background/utils/internal-signer.ts

This file was deleted.

4 changes: 2 additions & 2 deletions ui/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -1030,4 +1030,4 @@
"earn": "Earn",
"settings": "Settings"
}
}
}
30 changes: 14 additions & 16 deletions ui/pages/Onboarding/Tabbed/ImportPrivateKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<typeof importSigner>

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<typeof importSigner>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: you should be able to drop the as chain here now :) The dependency bumps included a typing rework that properly types dispatch.


if (success) {
dispatch(sendEvent(OneTimeAnalyticsEvent.ONBOARDING_FINISHED))
finalize()
} else {
setErrorMessage(t("error"))
setIsImporting(false)
setErrorMessage(t("errorImport"))
}
}, [dispatch, privateKey, setIsImporting, finalize, t])

Expand Down