|
| 1 | +import type { Page } from "@playwright/test" |
| 2 | +import { expect } from "@playwright/test" |
| 3 | +import type { SupportedChain } from "../../../types" |
| 4 | +const CHAIN_DATA_VALUES: Record<SupportedChain, string> = { |
| 5 | + solana: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp", // Solana mainnet |
| 6 | + ethereum: "eip155:1", // Ethereum mainnet |
| 7 | + base: "eip155:8453", // Base mainnet |
| 8 | + sui: "sui:mainnet", // Sui mainnet |
| 9 | + polygon: "eip155:137", // Polygon mainnet |
| 10 | + bitcoin: "bip122:000000000019d6689c085ae165831e93", // Bitcoin mainnet |
| 11 | +} |
| 12 | +/** |
| 13 | + * Imports a new single-chain account via private key on the Phantom Home page |
| 14 | + * @param page - The Phantom extension page |
| 15 | + * @param name - The display name for the imported account |
| 16 | + * @param chain - The chain to import the account on |
| 17 | + * @param privateKey - The private key to import |
| 18 | + */ |
| 19 | +export const addNewAccount = async ( |
| 20 | + page: Page, |
| 21 | + name: string, |
| 22 | + chain: SupportedChain, |
| 23 | + privateKey: string, |
| 24 | +): Promise<void> => { |
| 25 | + console.log("Implemented but not tested, code is commented") |
| 26 | + // Ensure UI is ready |
| 27 | + // await page.waitForLoadState("domcontentloaded") |
| 28 | + // await page.waitForLoadState("networkidle") |
| 29 | + |
| 30 | + // // Open settings / account menu |
| 31 | + // await page.getByTestId("settings-menu-open-button").click() |
| 32 | + // await page.getByTestId("sidebar_menu-button-add_account").click() |
| 33 | + |
| 34 | + // if (chain !== "solana") { |
| 35 | + // console.log( |
| 36 | + // `Selecting chain: ${chain} (Phantom defaults to Solana, changing to ${chain})`, |
| 37 | + // ) |
| 38 | + |
| 39 | + // // Click the chain dropdown button |
| 40 | + // await page.waitForSelector("[data-reach-listbox-button]", { |
| 41 | + // state: "visible", |
| 42 | + // }) |
| 43 | + // await page.click("[data-reach-listbox-button]") |
| 44 | + |
| 45 | + // // Wait for dropdown options to appear |
| 46 | + // await page.waitForSelector('[role="option"]', { |
| 47 | + // state: "visible", |
| 48 | + // }) |
| 49 | + |
| 50 | + // // Click the specific chain option using data-value attribute |
| 51 | + // const chainDataValue = CHAIN_DATA_VALUES[chain] |
| 52 | + // const chainSelector = `[role="option"][data-value="${chainDataValue}"]` |
| 53 | + |
| 54 | + // await page.waitForSelector(chainSelector, { |
| 55 | + // state: "visible", |
| 56 | + // }) |
| 57 | + // await page.click(chainSelector) |
| 58 | + |
| 59 | + // console.log(`Selected chain: ${chain} (${chainDataValue})`) |
| 60 | + |
| 61 | + // // Wait for the selection to be processed |
| 62 | + // await page.waitForLoadState("networkidle") |
| 63 | + // } else { |
| 64 | + // console.log("Using default Solana chain (no selection needed)") |
| 65 | + // } |
| 66 | + |
| 67 | + // // Step 4: Enter the private key name (if provided) |
| 68 | + // if (name) { |
| 69 | + // console.log(`Entering private key name: ${name}`) |
| 70 | + |
| 71 | + // // Target the name input by its name attribute and placeholder |
| 72 | + // const nameInput = page.locator('input[name="name"][placeholder="Name"]') |
| 73 | + // await nameInput.waitFor({ state: "visible" }) |
| 74 | + // await nameInput.fill(name) |
| 75 | + |
| 76 | + // console.log(`Private key name "${name}" entered successfully`) |
| 77 | + // } |
| 78 | + |
| 79 | + // // Step 5: Enter the private key |
| 80 | + // console.log("Entering private key...") |
| 81 | + |
| 82 | + // // Target the private key textarea by its name attribute and placeholder |
| 83 | + // const privateKeyTextarea = page.locator( |
| 84 | + // 'textarea[name="privateKey"][placeholder="Private key"]', |
| 85 | + // ) |
| 86 | + // await privateKeyTextarea.waitFor({ state: "visible" }) |
| 87 | + // await privateKeyTextarea.fill(privateKey) |
| 88 | + |
| 89 | + // // Step 6: Click the Import button to continue |
| 90 | + // await page.waitForTimeout(10000) |
| 91 | + |
| 92 | + // const importButton = page.getByTestId("onboarding-form-submit-button") |
| 93 | + // await importButton.waitFor({ state: "visible" }) |
| 94 | + |
| 95 | + // // Wait for the button to become enabled (form validation must pass) |
| 96 | + // await importButton.waitFor({ state: "attached" }) |
| 97 | + // await expect(importButton).toBeEnabled({ timeout: 10000 }) |
| 98 | + |
| 99 | + // await importButton.click() |
| 100 | + |
| 101 | + // await page.waitForLoadState("networkidle") |
| 102 | + // await page.waitForTimeout(3000) |
| 103 | + |
| 104 | + // // Small settle time |
| 105 | + // await page.waitForLoadState("networkidle") |
| 106 | +} |
0 commit comments