281025/sync_value_between_18_input_grid_and_full_text_input
This commit is contained in:
parent
673d12669e
commit
658c758a72
@ -143,6 +143,28 @@ export function useNeptuneWallet() {
|
|||||||
return JSON.parse(resultJson)
|
return JSON.parse(resultJson)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const importFromViewKey = async (viewKeyHex: string): Promise<{ receiver_identifier: string }> => {
|
||||||
|
try {
|
||||||
|
store.setLoading(true)
|
||||||
|
store.setError(null)
|
||||||
|
|
||||||
|
const result = await decodeViewKey(viewKeyHex)
|
||||||
|
|
||||||
|
store.setViewKey(viewKeyHex)
|
||||||
|
store.setReceiverId(result.receiver_identifier)
|
||||||
|
// Note: When importing from viewkey, we don't have the seed phrase
|
||||||
|
// and address needs to be derived from viewkey
|
||||||
|
|
||||||
|
return result
|
||||||
|
} catch (err) {
|
||||||
|
const errorMsg = err instanceof Error ? err.message : 'Failed to import from view key'
|
||||||
|
store.setError(errorMsg)
|
||||||
|
throw err
|
||||||
|
} finally {
|
||||||
|
store.setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ===== API METHODS =====
|
// ===== API METHODS =====
|
||||||
|
|
||||||
const getUtxos = async (
|
const getUtxos = async (
|
||||||
@ -275,6 +297,7 @@ export function useNeptuneWallet() {
|
|||||||
initWasm: ensureWasmInitialized,
|
initWasm: ensureWasmInitialized,
|
||||||
generateWallet,
|
generateWallet,
|
||||||
importWallet,
|
importWallet,
|
||||||
|
importFromViewKey,
|
||||||
getViewKeyFromSeed,
|
getViewKeyFromSeed,
|
||||||
getAddressFromSeed,
|
getAddressFromSeed,
|
||||||
validateSeedPhrase,
|
validateSeedPhrase,
|
||||||
|
|||||||
@ -1,32 +1,71 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { ButtonCommon, FormCommon } from '@/components'
|
import { ButtonCommon, FormCommon } from '@/components'
|
||||||
import { validateSeedPhrase18 } from '@/utils/helpers/seedPhrase'
|
import { validateSeedPhrase18 } from '@/utils/helpers/seedPhrase'
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(
|
(
|
||||||
e: 'import-success',
|
e: 'import-success',
|
||||||
data: { type: 'seed' | 'keystore'; value: string | string[]; passphrase?: string }
|
data: { type: 'seed' | 'keystore'; value: string | string[] }
|
||||||
): void
|
): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const tab = ref<'seedphrase' | 'keystore'>('seedphrase')
|
const tab = ref<'seedphrase' | 'keystore'>('seedphrase')
|
||||||
const seedWords = ref<string[]>(Array(18).fill(''))
|
const passphrase = ref('') // Source of truth - full seed phrase text
|
||||||
const seedError = ref('')
|
const seedError = ref('')
|
||||||
const passphrase = ref('')
|
|
||||||
const keystore = ref('')
|
const keystore = ref('')
|
||||||
const keystoreError = ref('')
|
const keystoreError = ref('')
|
||||||
|
|
||||||
|
// Computed array for grid inputs - synced with passphrase
|
||||||
|
const seedWords = computed({
|
||||||
|
get: () => {
|
||||||
|
const words = passphrase.value.trim().split(/\s+/).filter(w => w)
|
||||||
|
// Always return array of 18 elements
|
||||||
|
return Array.from({ length: 18 }, (_, i) => words[i] || '')
|
||||||
|
},
|
||||||
|
set: (newWords: string[]) => {
|
||||||
|
// Update passphrase from grid
|
||||||
|
passphrase.value = newWords.filter(w => w.trim()).join(' ')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const inputBoxFocus = (idx: number) => {
|
const inputBoxFocus = (idx: number) => {
|
||||||
document.getElementById('input-' + idx)?.focus()
|
document.getElementById('input-' + idx)?.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleGridInput = (index: number, value: string) => {
|
||||||
|
const newWords = [...seedWords.value]
|
||||||
|
newWords[index] = value
|
||||||
|
seedWords.value = newWords
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlePaste = (event: ClipboardEvent, index: number) => {
|
||||||
|
event.preventDefault()
|
||||||
|
const pastedData = event.clipboardData?.getData('text') || ''
|
||||||
|
|
||||||
|
// Split by whitespace and filter empty strings
|
||||||
|
const words = pastedData.trim().split(/\s+/).filter(w => w)
|
||||||
|
|
||||||
|
if (words.length === 0) return
|
||||||
|
|
||||||
|
// Fill words starting from the current index
|
||||||
|
const newWords = [...seedWords.value]
|
||||||
|
for (let i = 0; i < words.length && index + i < 18; i++) {
|
||||||
|
newWords[index + i] = words[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
seedWords.value = newWords
|
||||||
|
seedError.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
const validateSeed = () => {
|
const validateSeed = () => {
|
||||||
if (seedWords.value.some((w) => !w.trim())) {
|
const words = seedWords.value.filter(w => w.trim())
|
||||||
|
|
||||||
|
if (words.length !== 18) {
|
||||||
seedError.value = 'Please enter all 18 words.'
|
seedError.value = 'Please enter all 18 words.'
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (!validateSeedPhrase18(seedWords.value)) {
|
if (!validateSeedPhrase18(words)) {
|
||||||
seedError.value = 'One or more words are invalid.'
|
seedError.value = 'One or more words are invalid.'
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -48,8 +87,7 @@ const handleContinue = () => {
|
|||||||
if (validateSeed()) {
|
if (validateSeed()) {
|
||||||
emit('import-success', {
|
emit('import-success', {
|
||||||
type: 'seed',
|
type: 'seed',
|
||||||
value: seedWords.value,
|
value: seedWords.value.filter(w => w.trim()),
|
||||||
passphrase: passphrase.value,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -78,6 +116,19 @@ const handleContinue = () => {
|
|||||||
<div class="seed-row-radio">
|
<div class="seed-row-radio">
|
||||||
<div class="radio active">18 words</div>
|
<div class="radio active">18 words</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Full seed phrase input (shares state with grid) -->
|
||||||
|
<div class="form-row">
|
||||||
|
<FormCommon
|
||||||
|
v-model="passphrase"
|
||||||
|
type="text"
|
||||||
|
label="Paste your seed phrase (all 18 words)"
|
||||||
|
placeholder="word1 word2 word3 ... word18"
|
||||||
|
@focus="seedError = ''"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Individual input grid -->
|
||||||
<div class="seed-inputs">
|
<div class="seed-inputs">
|
||||||
<div class="seed-input-grid">
|
<div class="seed-input-grid">
|
||||||
<div v-for="(word, i) in seedWords" :key="i" class="seed-box">
|
<div v-for="(word, i) in seedWords" :key="i" class="seed-box">
|
||||||
@ -88,23 +139,18 @@ const handleContinue = () => {
|
|||||||
autocapitalize="off"
|
autocapitalize="off"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
spellcheck="false"
|
spellcheck="false"
|
||||||
v-model="seedWords[i]"
|
:value="word"
|
||||||
:placeholder="i + 1 + '.'"
|
:placeholder="i + 1 + '.'"
|
||||||
maxlength="24"
|
maxlength="24"
|
||||||
@keydown.enter="inputBoxFocus(i + 1)"
|
@keydown.enter="inputBoxFocus(i + 1)"
|
||||||
:class="{ error: seedError && !word.trim() }"
|
:class="{ error: seedError && !word.trim() }"
|
||||||
@focus="seedError = ''"
|
@focus="seedError = ''"
|
||||||
|
@input="handleGridInput(i, ($event.target as HTMLInputElement).value)"
|
||||||
|
@paste="handlePaste($event, i)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row mt-sm">
|
|
||||||
<FormCommon
|
|
||||||
v-model="passphrase"
|
|
||||||
:label="'Seed passphrase (optional)'"
|
|
||||||
placeholder="Enter seed passphrase"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div v-if="seedError" class="error-text">{{ seedError }}</div>
|
<div v-if="seedError" class="error-text">{{ seedError }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="tab-pane">
|
<div v-else class="tab-pane">
|
||||||
@ -126,7 +172,7 @@ const handleContinue = () => {
|
|||||||
size="large"
|
size="large"
|
||||||
:disabled="
|
:disabled="
|
||||||
tab === 'seedphrase'
|
tab === 'seedphrase'
|
||||||
? !seedWords.every((w) => w) || !!seedError
|
? seedWords.filter(w => w.trim()).length !== 18 || !!seedError
|
||||||
: !keystore || !!keystoreError
|
: !keystore || !!keystoreError
|
||||||
"
|
"
|
||||||
@click="handleContinue"
|
@click="handleContinue"
|
||||||
@ -240,6 +286,15 @@ const handleContinue = () => {
|
|||||||
margin-top: 19px;
|
margin-top: 19px;
|
||||||
margin-bottom: 4px;
|
margin-bottom: 4px;
|
||||||
}
|
}
|
||||||
|
.paste-hint {
|
||||||
|
text-align: center;
|
||||||
|
font-size: var(--font-sm);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
margin-top: var(--spacing-md);
|
||||||
|
padding: var(--spacing-sm) var(--spacing-md);
|
||||||
|
background: var(--bg-secondary);
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
}
|
||||||
.mt-sm {
|
.mt-sm {
|
||||||
margin-top: 9px;
|
margin-top: 9px;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,9 +8,8 @@ const stage = ref<'import' | 'password'>('import')
|
|||||||
const importData = ref<any>(null)
|
const importData = ref<any>(null)
|
||||||
|
|
||||||
const handleImported = (payload: {
|
const handleImported = (payload: {
|
||||||
type: 'seed' | 'privatekey'
|
type: 'seed' | 'keystore'
|
||||||
value: string | string[]
|
value: string | string[]
|
||||||
passphrase?: string
|
|
||||||
}) => {
|
}) => {
|
||||||
importData.value = payload
|
importData.value = payload
|
||||||
stage.value = 'password'
|
stage.value = 'password'
|
||||||
@ -23,7 +22,12 @@ const handleNavigateToCreate = () => {
|
|||||||
<template>
|
<template>
|
||||||
<div class="login-tab">
|
<div class="login-tab">
|
||||||
<ImportWalletComponent v-if="stage === 'import'" @import-success="handleImported" />
|
<ImportWalletComponent v-if="stage === 'import'" @import-success="handleImported" />
|
||||||
<OpenWalletComponent v-else @navigateToCreate="handleNavigateToCreate" />
|
<OpenWalletComponent
|
||||||
|
v-else
|
||||||
|
:import-data="importData"
|
||||||
|
@navigateToCreate="handleNavigateToCreate"
|
||||||
|
@back="stage = 'import'"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@ -1,9 +1,27 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
import { message } from 'ant-design-vue'
|
||||||
import { ButtonCommon, FormCommon } from '@/components'
|
import { ButtonCommon, FormCommon } from '@/components'
|
||||||
|
import { useNeptuneWallet } from '@/composables/useNeptuneWallet'
|
||||||
|
|
||||||
|
interface ImportData {
|
||||||
|
type: 'seed' | 'keystore'
|
||||||
|
value: string | string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
importData?: ImportData | null
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
navigateToCreate: []
|
||||||
|
back: []
|
||||||
|
}>()
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const { importWallet, importFromViewKey } = useNeptuneWallet()
|
||||||
|
|
||||||
const password = ref('')
|
const password = ref('')
|
||||||
const passwordError = ref('')
|
const passwordError = ref('')
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
@ -14,26 +32,53 @@ const handleOpenWallet = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!props.importData) {
|
||||||
|
passwordError.value = 'No import data available'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
passwordError.value = ''
|
passwordError.value = ''
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1500))
|
// TODO: Use password to decrypt the wallet data
|
||||||
|
// For now, we'll just import directly
|
||||||
|
|
||||||
|
if (props.importData.type === 'seed') {
|
||||||
|
const seedPhrase = Array.isArray(props.importData.value)
|
||||||
|
? props.importData.value
|
||||||
|
: props.importData.value.split(' ')
|
||||||
|
|
||||||
|
await importWallet(seedPhrase, 'testnet')
|
||||||
|
message.success('Wallet imported successfully from seed phrase!')
|
||||||
|
} else if (props.importData.type === 'keystore') {
|
||||||
|
// Assume keystore contains the view key hex string
|
||||||
|
const viewKey = typeof props.importData.value === 'string'
|
||||||
|
? props.importData.value
|
||||||
|
: props.importData.value.join('')
|
||||||
|
|
||||||
|
await importFromViewKey(viewKey)
|
||||||
|
message.success('Wallet imported successfully from keystore!')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Navigate to home after successful import
|
||||||
router.push('/')
|
router.push('/')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
passwordError.value = 'Invalid password. Please try again.'
|
const errorMsg = error instanceof Error ? error.message : 'Failed to import wallet'
|
||||||
|
passwordError.value = errorMsg
|
||||||
|
message.error(errorMsg)
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
navigateToCreate: []
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const navigateToNewWallet = () => {
|
const navigateToNewWallet = () => {
|
||||||
emit('navigateToCreate')
|
emit('navigateToCreate')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleBack = () => {
|
||||||
|
emit('back')
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -119,12 +164,17 @@ const navigateToNewWallet = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="import-info" v-if="importData">
|
||||||
|
<div class="info-label">Importing from:</div>
|
||||||
|
<div class="info-value">{{ importData.type === 'seed' ? 'Seed Phrase' : 'Keystore' }}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<FormCommon
|
<FormCommon
|
||||||
v-model="password"
|
v-model="password"
|
||||||
type="password"
|
type="password"
|
||||||
label="Enter your password"
|
label="Create a password to encrypt your wallet"
|
||||||
placeholder="Password"
|
placeholder="Enter password"
|
||||||
show-password-toggle
|
show-password-toggle
|
||||||
required
|
required
|
||||||
:error="passwordError"
|
:error="passwordError"
|
||||||
@ -163,15 +213,20 @@ const navigateToNewWallet = () => {
|
|||||||
:loading="isLoading"
|
:loading="isLoading"
|
||||||
@click="handleOpenWallet"
|
@click="handleOpenWallet"
|
||||||
>
|
>
|
||||||
{{ isLoading ? 'Opening...' : 'Open Wallet' }}
|
{{ isLoading ? 'Importing...' : 'Import Wallet' }}
|
||||||
</ButtonCommon>
|
</ButtonCommon>
|
||||||
<ButtonCommon type="default" size="large" block @click="navigateToNewWallet">
|
<div class="button-row">
|
||||||
|
<ButtonCommon type="default" size="large" @click="handleBack" :disabled="isLoading">
|
||||||
|
Back
|
||||||
|
</ButtonCommon>
|
||||||
|
<ButtonCommon type="default" size="large" @click="navigateToNewWallet" :disabled="isLoading">
|
||||||
New Wallet
|
New Wallet
|
||||||
</ButtonCommon>
|
</ButtonCommon>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@ -194,6 +249,26 @@ const navigateToNewWallet = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.auth-card-content {
|
.auth-card-content {
|
||||||
|
.import-info {
|
||||||
|
text-align: center;
|
||||||
|
padding: var(--spacing-md);
|
||||||
|
background: var(--primary-light);
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
margin-bottom: var(--spacing-lg);
|
||||||
|
|
||||||
|
.info-label {
|
||||||
|
font-size: var(--font-sm);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
margin-bottom: var(--spacing-xs);
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-value {
|
||||||
|
font-size: var(--font-md);
|
||||||
|
font-weight: var(--font-semibold);
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.form-group {
|
.form-group {
|
||||||
margin-bottom: var(--spacing-xl);
|
margin-bottom: var(--spacing-xl);
|
||||||
}
|
}
|
||||||
@ -274,6 +349,15 @@ const navigateToNewWallet = () => {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: var(--spacing-md);
|
gap: var(--spacing-md);
|
||||||
margin-bottom: var(--spacing-xl);
|
margin-bottom: var(--spacing-xl);
|
||||||
|
|
||||||
|
.button-row {
|
||||||
|
display: flex;
|
||||||
|
gap: var(--spacing-md);
|
||||||
|
|
||||||
|
> * {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Help Links
|
// Help Links
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user