Skip to content

Commit

Permalink
feat: improve wallet detection logic for multiple sites
Browse files Browse the repository at this point in the history
- Add enhanced modal detection with multiple selectors
- Implement loading state checks for app initialization
- Add debug logging for better troubleshooting
- Update wallet connection button selectors
- Improve icon and name detection logic

Co-Authored-By: [email protected] <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and originalix committed Dec 26, 2024
1 parent 220b81f commit df02894
Show file tree
Hide file tree
Showing 4 changed files with 6,262 additions and 46 deletions.
8 changes: 6 additions & 2 deletions packages/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ export default defineConfig({
...devices['Desktop Chrome'],
viewport: { width: 1440, height: 800 },
launchOptions: {
args: ['--no-sandbox', '--disable-setuid-sandbox']
}
args: ['--no-sandbox', '--disable-setuid-sandbox'],
headless: true
},
actionTimeout: 120000,
navigationTimeout: 120000,
testTimeout: 120000,
},
},
{
Expand Down
19 changes: 16 additions & 3 deletions packages/e2e/tests/connectButton/universal.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types';
import { expect, test } from '@playwright/test';
import path from 'node:path';
import * as path from 'node:path';
import { Locator } from 'playwright/test';

import * as fs from 'fs';
Expand All @@ -24,6 +24,7 @@ async function dbg(locator: Locator) {
});
}
test.describe('Connect Button Hack', () => {
test.setTimeout(120000); // Increase timeout to 2 minutes
console.log('total sites:', sitesConfig.length);
// const startWebSite = 'app.vesper.finance';
// const startIdx = sitesConfig.findIndex((e) => e.urls.includes(startWebSite));
Expand Down Expand Up @@ -94,7 +95,15 @@ test.describe('Connect Button Hack', () => {
}
const walletId = createWalletId(provider as IInjectedProviderNames, updatedName);
const locator = page.locator(walletId.walletIdSelector).first();
const existed = await locator.evaluate((el) => !!el );
// Debug: Log the modal content
const modalContent = await page.evaluate(() => {
const modal = document.querySelector("div[role='dialog']");
console.log('[dbg]: modal content', modal?.innerHTML);
return modal?.innerHTML;
});
console.log('[dbg]: modal content from test', modalContent);

const existed = await locator.evaluate((el) => !!el);
console.log('[dbg]: walletId found existed', walletId.walletId, existed);

if(!existed){
Expand All @@ -113,9 +122,13 @@ test.describe('Connect Button Hack', () => {
// const url = page.url() || 'unknown-url';
let hostname = siteUrl as string;
try {
hostname = new URL(siteUrl as string).hostname;
// Handle domain-only URLs by adding https:// if needed
const urlString = siteUrl.startsWith('http') ? siteUrl : `https://${siteUrl}`;

Check failure on line 126 in packages/e2e/tests/connectButton/universal.e2e.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest, 20)

Unsafe assignment of an `any` value

Check failure on line 126 in packages/e2e/tests/connectButton/universal.e2e.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest, 20)

Unsafe member access .startsWith on an `any` value

Check failure on line 126 in packages/e2e/tests/connectButton/universal.e2e.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest, 20)

Unsafe call of an `any` typed value

Check failure on line 126 in packages/e2e/tests/connectButton/universal.e2e.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest, 20)

Invalid type "any" of template literal expression
hostname = new URL(urlString).hostname;

Check failure on line 127 in packages/e2e/tests/connectButton/universal.e2e.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest, 20)

Unsafe argument of type `any` assigned to a parameter of type `string | URL`
} catch (error) {
console.error('Failed to parse URL:', error);
// Keep the original hostname if parsing fails
hostname = siteUrl.replace(/^https?:\/\//, '');

Check failure on line 131 in packages/e2e/tests/connectButton/universal.e2e.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest, 20)

Unsafe assignment of an `any` value

Check failure on line 131 in packages/e2e/tests/connectButton/universal.e2e.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest, 20)

Unsafe member access .replace on an `any` value

Check failure on line 131 in packages/e2e/tests/connectButton/universal.e2e.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest, 20)

Unsafe call of an `any` typed value
}

// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
Expand Down
Loading

0 comments on commit df02894

Please sign in to comment.