Skip to content

Commit

Permalink
Allow scan private key to be entered without 0x prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
mds1 committed Apr 1, 2021
1 parent 850bf71 commit 7189abc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions frontend/src/pages/AccountReceive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,22 @@ function useScan() {
const userAnnouncements = ref<UserAnnouncement[]>([]);
// 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<number>();
const endBlockLocal = ref<number>();
const scanPrivateKeyLocal = ref<string>();
const needsSignature = computed(() => !hasKeys.value && !scanPrivateKeyLocal.value);
const settingsFormRef = ref<QForm>(); // 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;
};
Expand Down Expand Up @@ -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);
};
Expand Down
1 change: 1 addition & 0 deletions frontend/src/store/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 7189abc

Please sign in to comment.