Skip to content

Commit

Permalink
Merge pull request #2069 from oasisprotocol/lw/detect-eth-key
Browse files Browse the repository at this point in the history
Guide users who paste Eth private key into Consensus private key input
  • Loading branch information
lukaw3d authored Oct 21, 2024
2 parents 4afb9b7 + 4753833 commit 255335c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions .changelog/2069.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Guide users who paste Eth private key into Consensus private key input
4 changes: 4 additions & 0 deletions playwright/tests/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ test.describe('The extension popup should load', () => {
)
.click()
await expect(page.frameLocator('iframe')!.getByAltText('Powered by Transak')).toBeVisible()
// Wait for conversion to be loaded otherwise clicking "Buy now" early reloads the iframe
await expect(page.frameLocator('iframe')!.locator('#transak-calculator-source:disabled')).toHaveValue(
/\d/,
)
await page.frameLocator('iframe')!.getByText('Buy now').click()
await expect(page.frameLocator('iframe')!.getByText(/email/i).first()).toBeVisible()
})
Expand Down
4 changes: 4 additions & 0 deletions playwright/tests/fiat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ test.describe('Fiat on-ramp', () => {
)
.click()
await expect(page.frameLocator('iframe')!.getByAltText('Powered by Transak')).toBeVisible()
// Wait for conversion to be loaded otherwise clicking "Buy now" early reloads the iframe
await expect(page.frameLocator('iframe')!.locator('#transak-calculator-source:disabled')).toHaveValue(
/\d/,
)
await page.frameLocator('iframe')!.getByText('Buy now').click()
await expect(page.frameLocator('iframe')!.getByText(/email/i).first()).toBeVisible()
})
Expand Down
14 changes: 13 additions & 1 deletion src/app/pages/OpenWalletPage/Features/FromPrivateKey/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Header } from 'app/components/Header'
import { ChoosePasswordFields } from 'app/components/Persist/ChoosePasswordFields'
import { FormValue as ChoosePasswordFieldsFormValue } from 'app/components/Persist/ChoosePasswordInputFields'
import { preventSavingInputsToUserData } from 'app/lib/preventSavingInputsToUserData'
import { isValidEthPrivateKey, stripHexPrefix } from 'app/lib/eth-helpers'

interface Props {}

Expand Down Expand Up @@ -65,7 +66,18 @@ export function FromPrivateKey(props: Props) {
placeholder={t('openWallet.privateKey.enterPrivateKeyHere', 'Enter your private key here')}
autoFocus
validate={privateKey =>
isValidKey(privateKey) ? undefined : t('openWallet.privateKey.error', 'Invalid private key')
isValidKey(privateKey)
? undefined
: isValidEthPrivateKey(stripHexPrefix(privateKey))
? t(
'openWallet.privateKey.errorKeyIsInEthFormat',
'This input is intended for Oasis Consensus private keys. The private key you entered looks like an Ethereum-compatible private key (e.g. from MetaMask for Sapphire). If you want to use your Ethereum-compatible private key to move ROSE from Sapphire to Consensus, click "{{paratimesMenu}}", then "{{withdrawButton}}", and paste it there.',
{
paratimesMenu: t('menu.paraTimes', 'ParaTimes'),
withdrawButton: t('paraTimes.transfers.withdraw', 'Withdraw from ParaTime'),
},
)
: t('openWallet.privateKey.error', 'Invalid private key')
}
showTip={t('openWallet.privateKey.showPrivateKey', 'Show private key')}
hideTip={t('openWallet.privateKey.hidePrivateKey', 'Hide private key')}
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@
"privateKey": {
"enterPrivateKeyHere": "Enter your private key here",
"error": "Invalid private key",
"errorKeyIsInEthFormat": "This input is intended for Oasis Consensus private keys. The private key you entered looks like an Ethereum-compatible private key (e.g. from MetaMask for Sapphire). If you want to use your Ethereum-compatible private key to move ROSE from Sapphire to Consensus, click \"{{paratimesMenu}}\", then \"{{withdrawButton}}\", and paste it there.",
"header": "Enter your private key",
"hidePrivateKey": "Hide private key",
"instruction": "Enter your private key in Base64 format.",
Expand Down

0 comments on commit 255335c

Please sign in to comment.