From 7189abc7beac7ba497dd44aac59e5b3ccb723819 Mon Sep 17 00:00:00 2001 From: Matt Solomon Date: Wed, 31 Mar 2021 19:42:35 -0700 Subject: [PATCH] Allow scan private key to be entered without 0x prefix --- frontend/src/pages/AccountReceive.vue | 10 ++++++---- frontend/src/store/settings.ts | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/AccountReceive.vue b/frontend/src/pages/AccountReceive.vue index 29933a2c1..f80c4e6e6 100644 --- a/frontend/src/pages/AccountReceive.vue +++ b/frontend/src/pages/AccountReceive.vue @@ -85,7 +85,7 @@ function useScan() { const userAnnouncements = ref([]); // Start and end blocks for advanced mode settings - const { advancedMode, startBlock, endBlock, setScanBlocks, setScanPrivateKey } = useSettingsStore(); + const { advancedMode, startBlock, endBlock, setScanBlocks, setScanPrivateKey, scanPrivateKey } = useSettingsStore(); const startBlockLocal = ref(); const endBlockLocal = ref(); const scanPrivateKeyLocal = ref(); @@ -93,12 +93,14 @@ function useScan() { const settingsFormRef = ref(); // for programtically verifying settings form // Form validators and configurations - const invalidPrivateKeyMsg = 'Please enter a valid private key starting with 0x'; - const isValidPrivateKey = (val: string) => !val || (isHexString(val) && val.length === 66) || invalidPrivateKeyMsg; + const badPrivKeyMsg = 'Please enter a valid private key'; + const isAnyHex = (val: string) => isHexString(val) || isHexString(`0x${val}`); + const isValidPrivateKey = (val: string) => !val || (isAnyHex(val) && [66, 64].includes(val.length)) || badPrivKeyMsg; const isValidStartBlock = (val: string) => !val || Number(val) > 0 || 'Please enter a valid start block'; const isValidEndBlock = (val: string) => !val || Number(val) > 0 || 'Please enter a valid start block'; const setFormStatus = (scanStatusVal: ScanStatus, scanPrivateKey: string) => { scanStatus.value = scanStatusVal; + if (scanPrivateKey.length === 64) scanPrivateKey = `0x${scanPrivateKey}`; setScanPrivateKey(scanPrivateKey); scanPrivateKeyLocal.value = scanPrivateKey; }; @@ -136,7 +138,7 @@ function useScan() { // Check for manually entered private key in advancedMode, otherwise use the key from user's signature const chooseKey = (keyPair: string | undefined | null) => { - if (advancedMode.value && scanPrivateKeyLocal.value) return String(scanPrivateKeyLocal.value); + if (advancedMode.value && scanPrivateKey.value) return String(scanPrivateKey.value); return String(keyPair); }; diff --git a/frontend/src/store/settings.ts b/frontend/src/store/settings.ts index f02c2c3da..25ff22ef5 100644 --- a/frontend/src/store/settings.ts +++ b/frontend/src/store/settings.ts @@ -50,6 +50,7 @@ export default function useSettingsStore() { } function setScanPrivateKey(key: string) { + if (key.length === 64) key = `0x${key}`; scanPrivateKey.value = key; // we save this in memory for access by components, but do not save it to LocalStorage }