Browse Source
- Add duplicate check in ImportAccountView before account import - Add duplicate check in ImportDerivedAccountView for derived accounts - Add safety check in saveNewIdentity function to prevent duplicate saves - Implement user-friendly warning messages for duplicate attempts - Add comprehensive error handling to catch duplicate errors from saveNewIdentity - Create Playwright tests to verify duplicate prevention functionality - Add documentation for duplicate prevention implementation The system now prevents users from importing the same account multiple times by checking for existing DIDs both before import (pre-check) and during save (post-check). Users receive clear warning messages instead of technical errors when attempting to import duplicate accounts. Files modified: - src/views/ImportAccountView.vue: Add duplicate check and error handling - src/views/ImportDerivedAccountView.vue: Add duplicate check for derived accounts - src/libs/util.ts: Add duplicate prevention in saveNewIdentity - test-playwright/duplicate-import-test.spec.ts: Add comprehensive tests - doc/duplicate-account-import-implementation.md: Add implementation docs Resolves: Prevent duplicate account imports in IdentitySwitcherViewpull/190/head
5 changed files with 204 additions and 7 deletions
@ -0,0 +1,26 @@ |
|||
## What Works (Evidence) |
|||
|
|||
- ✅ **ImportAccountView duplicate check** |
|||
- **Time**: 2025-01-27T14:30:00Z |
|||
- **Evidence**: Added `checkForDuplicateAccount()` method with DID derivation and database query |
|||
- **Verify at**: `src/views/ImportAccountView.vue:180-200` |
|||
|
|||
- ✅ **ImportAccountView error handling** |
|||
- **Time**: 2025-01-27T15:00:00Z |
|||
- **Evidence**: Enhanced error handling to catch duplicate errors from saveNewIdentity and display user-friendly warnings |
|||
- **Verify at**: `src/views/ImportAccountView.vue:230-240` |
|||
|
|||
- ✅ **ImportDerivedAccountView duplicate check** |
|||
- **Time**: 2025-01-27T14:30:00Z |
|||
- **Evidence**: Added duplicate check in `incrementDerivation()` method |
|||
- **Verify at**: `src/views/ImportDerivedAccountView.vue:170-190` |
|||
|
|||
- ✅ **saveNewIdentity safety check** |
|||
- **Time**: 2025-01-27T14:30:00Z |
|||
- **Evidence**: Added database query before INSERT operation |
|||
- **Verify at**: `src/libs/util.ts:625-635` |
|||
|
|||
- ✅ **User-friendly error messages** |
|||
- **Time**: 2025-01-27T14:30:00Z |
|||
- **Evidence**: Clear warning messages in both import views |
|||
- **Verify at**: ImportAccountView and ImportDerivedAccountView notification calls |
@ -0,0 +1,63 @@ |
|||
import { test, expect } from '@playwright/test'; |
|||
import { importUserFromAccount, getTestUserData } from './testUtils'; |
|||
|
|||
/** |
|||
* Test duplicate account import functionality |
|||
* |
|||
* This test verifies that: |
|||
* 1. A user can successfully import an account the first time |
|||
* 2. Attempting to import the same account again shows a warning message |
|||
* 3. The duplicate import is prevented |
|||
*/ |
|||
test.describe('Duplicate Account Import', () => { |
|||
test('should prevent importing the same account twice', async ({ page }) => { |
|||
const userData = getTestUserData("00"); |
|||
|
|||
// First import - should succeed
|
|||
await page.goto("./start"); |
|||
await page.getByText("You have a seed").click(); |
|||
await page.getByPlaceholder("Seed Phrase").fill(userData.seedPhrase); |
|||
await page.getByRole("button", { name: "Import" }).click(); |
|||
|
|||
// Verify first import was successful
|
|||
await expect(page.getByRole("code")).toContainText(userData.did); |
|||
|
|||
// Navigate back to start page for second import attempt
|
|||
await page.goto("./start"); |
|||
await page.getByText("You have a seed").click(); |
|||
await page.getByPlaceholder("Seed Phrase").fill(userData.seedPhrase); |
|||
await page.getByRole("button", { name: "Import" }).click(); |
|||
|
|||
// Verify duplicate import shows warning message
|
|||
// The warning can appear either from the pre-check or from the saveNewIdentity error handling
|
|||
await expect(page.getByText("This account has already been imported")).toBeVisible(); |
|||
await expect(page.getByText("Please use a different seed phrase or check your existing accounts")).toBeVisible(); |
|||
|
|||
// Verify we're still on the import page (not redirected to account)
|
|||
await expect(page.getByPlaceholder("Seed Phrase")).toBeVisible(); |
|||
}); |
|||
|
|||
test('should allow importing different accounts', async ({ page }) => { |
|||
const userZeroData = getTestUserData("00"); |
|||
const userOneData = getTestUserData("01"); |
|||
|
|||
// Import first user
|
|||
await page.goto("./start"); |
|||
await page.getByText("You have a seed").click(); |
|||
await page.getByPlaceholder("Seed Phrase").fill(userZeroData.seedPhrase); |
|||
await page.getByRole("button", { name: "Import" }).click(); |
|||
|
|||
// Verify first import was successful
|
|||
await expect(page.getByRole("code")).toContainText(userZeroData.did); |
|||
|
|||
// Navigate back to start page for second user import
|
|||
await page.goto("./start"); |
|||
await page.getByText("You have a seed").click(); |
|||
await page.getByPlaceholder("Seed Phrase").fill(userOneData.seedPhrase); |
|||
await page.getByRole("button", { name: "Import" }).click(); |
|||
|
|||
// Verify second import was successful (should not show duplicate warning)
|
|||
await expect(page.getByRole("code")).toContainText(userOneData.did); |
|||
await expect(page.getByText("This account has already been imported")).not.toBeVisible(); |
|||
}); |
|||
}); |
Loading…
Reference in new issue