Skip to content

Commit

Permalink
Fix bip39 passphrase not showing in advanced mode (#260)
Browse files Browse the repository at this point in the history
* Fix bip39 passphrase not showing in advanced mode

* Add password to menonicToSeed

* Empty password field when hidden
  • Loading branch information
Duddino authored Nov 13, 2023
1 parent 60d7cd1 commit c1ac0e7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
12 changes: 8 additions & 4 deletions scripts/dashboard/AccessWallet.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup>
import coinPlant from '../../assets/coin_plant.svg';
import pLogo from '../../assets/p_logo.svg';
import { ref, watch } from 'vue';
import { ref, watch, toRefs } from 'vue';
import { translation } from '../i18n.js';
import { isBase64 } from '../misc';
Expand All @@ -13,7 +13,7 @@ const passwordPlaceholder = ref(translation.password);
const props = defineProps({
advancedMode: Boolean,
});
const advancedMode = ref(props.advancedMode);
const { advancedMode } = toRefs(props);
/**
* Secret is the thing being imported:
Expand All @@ -26,12 +26,12 @@ const secret = ref('');
*/
const password = ref('');
watch(secret, (secret) => {
watch([secret, advancedMode], ([secret, advancedMode]) => {
// If it cointains spaces, it's likely a bip39 seed
const fContainsSpaces = secret.trim().includes(' ');
// Show password input if it's a bip39 seed and we're in advanced mode
if (fContainsSpaces && advancedMode.value) {
if (fContainsSpaces && advancedMode) {
showPassword.value = true;
}
// If it's a Base64 secret, it's likely an MPW encrypted import,
Expand All @@ -48,6 +48,10 @@ watch(secret, (secret) => {
? translation.optionalPassphrase
: translation.password;
});
watch(showPassword, (showPassword) => {
// Empty password prompt when hidden
if (!showPassword) password.value = '';
});
const emit = defineEmits(['import-wallet']);
function importWallet() {
emit('import-wallet', secret.value, password.value);
Expand Down
15 changes: 9 additions & 6 deletions scripts/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ watch(showExportModal, async (showExportModal) => {
keyToBackup.value = '';
}
});
getEventEmitter().on(
'advanced-mode',
(fAdvancedMode) => (advancedMode.value = fAdvancedMode)
);
getEventEmitter().on('advanced-mode', (fAdvancedMode) => {
advancedMode.value = fAdvancedMode;
});
/**
* Parses whatever the secret is to a MasterKey
Expand Down Expand Up @@ -118,7 +117,7 @@ async function parseSecret(secret, password = '') {
);
if (!ok) throw new Error(msg);
return new HdMasterKey({
seed: await mnemonicToSeed(phrase),
seed: await mnemonicToSeed(phrase, password),
});
},
},
Expand Down Expand Up @@ -491,7 +490,11 @@ defineExpose({
<template>
<div id="keypair" class="tabcontent">
<div class="row m-0">
<Login v-show="!isImported" @import-wallet="importWallet" />
<Login
v-show="!isImported"
:advancedMode="advancedMode"
@import-wallet="importWallet"
/>
<br />
Expand Down
7 changes: 7 additions & 0 deletions scripts/dashboard/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import pLogo from '../../assets/p_logo.svg';
import VanityGen from './VanityGen.vue';
import CreateWallet from './CreateWallet.vue';
import AccessWallet from './AccessWallet.vue';
import { watch, toRefs } from 'vue';
defineEmits(['import-wallet']);
const props = defineProps({
advancedMode: Boolean,
});
const { advancedMode } = toRefs(props);
</script>

<template>
Expand Down Expand Up @@ -67,6 +73,7 @@ defineEmits(['import-wallet']);

<br />
<AccessWallet
:advancedMode="advancedMode"
@import-wallet="
(secret, password) =>
$emit('import-wallet', { type: 'hd', secret, password })
Expand Down

0 comments on commit c1ac0e7

Please sign in to comment.