@avalix/chroma 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -2
- package/dist/index.d.mts +53987 -0
- package/dist/{index.js → index.mjs} +79 -51
- package/package.json +15 -14
- package/scripts/download-extensions.ts +26 -1
- package/src/context-playwright/index.ts +0 -1
- package/src/context-playwright/types.ts +1 -0
- package/src/context-playwright/wallet-factory.ts +17 -0
- package/src/utils/download-extension.ts +33 -6
- package/src/wallets/polkadot-js.ts +49 -19
- package/src/wallets/talisman.ts +62 -38
- package/dist/index.d.ts +0 -64
package/src/wallets/talisman.ts
CHANGED
|
@@ -5,22 +5,32 @@ import path from 'node:path'
|
|
|
5
5
|
import process from 'node:process'
|
|
6
6
|
|
|
7
7
|
// Talisman specific configuration
|
|
8
|
+
// https://github.com/avalix-labs/polkadot-wallets/tree/main/talisman
|
|
9
|
+
const VERSION = '3.1.13'
|
|
8
10
|
export const TALISMAN_CONFIG = {
|
|
9
|
-
downloadUrl:
|
|
10
|
-
extensionName:
|
|
11
|
+
downloadUrl: `https://github.com/avalix-labs/polkadot-wallets/raw/refs/heads/main/talisman/talisman-${VERSION}.zip`,
|
|
12
|
+
extensionName: `talisman-extension-${VERSION}`,
|
|
11
13
|
} as const
|
|
12
14
|
|
|
13
15
|
// Helper function to find extension popup
|
|
14
16
|
async function findExtensionPopup(context: BrowserContext, extensionId: string): Promise<Page> {
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
for (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
p.
|
|
23
|
-
|
|
17
|
+
// Wait for extension popup to appear with retry logic
|
|
18
|
+
const maxAttempts = 10
|
|
19
|
+
const retryDelay = 500
|
|
20
|
+
|
|
21
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
22
|
+
const pages = context.pages()
|
|
23
|
+
for (const p of pages) {
|
|
24
|
+
if (p.url().includes(`chrome-extension://${extensionId}/`)) {
|
|
25
|
+
await p.setViewportSize({ width: 400, height: 600 })
|
|
26
|
+
await p.waitForLoadState('domcontentloaded')
|
|
27
|
+
return p
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// If not found, wait a bit before retrying
|
|
32
|
+
if (attempt < maxAttempts - 1) {
|
|
33
|
+
await new Promise(resolve => setTimeout(resolve, retryDelay))
|
|
24
34
|
}
|
|
25
35
|
}
|
|
26
36
|
|
|
@@ -37,13 +47,10 @@ export async function getTalismanExtensionPath(): Promise<string> {
|
|
|
37
47
|
throw new Error(
|
|
38
48
|
`Talisman extension not found at: ${extensionDir}\n\n`
|
|
39
49
|
+ `Please download the extension first by running:\n`
|
|
40
|
-
+ ` npx @avalix/chroma download-extensions\n
|
|
41
|
-
+ `Or if you're using this as a dependency:\n`
|
|
42
|
-
+ ` npm run chroma:download\n`,
|
|
50
|
+
+ ` npx @avalix/chroma download-extensions\n`,
|
|
43
51
|
)
|
|
44
52
|
}
|
|
45
53
|
|
|
46
|
-
console.log(`✅ Found Talisman extension at: ${extensionDir}`)
|
|
47
54
|
return extensionDir
|
|
48
55
|
}
|
|
49
56
|
|
|
@@ -55,38 +62,42 @@ export async function importEthPrivateKey(
|
|
|
55
62
|
const context = page.__extensionContext
|
|
56
63
|
const extensionId = page.__extensionId
|
|
57
64
|
|
|
58
|
-
// Wait for Talisman to open its onboarding tab
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// Find the onboarding tab
|
|
65
|
+
// Wait for Talisman to open its onboarding tab with retry logic
|
|
66
|
+
const maxAttempts = 20
|
|
67
|
+
const retryDelay = 500
|
|
62
68
|
let extensionPage: Page | null = null
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
|
|
70
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
71
|
+
const pages = context.pages()
|
|
72
|
+
|
|
73
|
+
for (const p of pages) {
|
|
74
|
+
const url = p.url()
|
|
75
|
+
if (url.includes('onboarding.html') || url.includes(`chrome-extension://${extensionId}/`)) {
|
|
76
|
+
extensionPage = p
|
|
77
|
+
break
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (extensionPage) {
|
|
71
82
|
break
|
|
72
83
|
}
|
|
84
|
+
|
|
85
|
+
// If not found, wait before retrying
|
|
86
|
+
if (attempt < maxAttempts - 1) {
|
|
87
|
+
await new Promise(resolve => setTimeout(resolve, retryDelay))
|
|
88
|
+
}
|
|
73
89
|
}
|
|
74
90
|
|
|
75
91
|
if (!extensionPage) {
|
|
76
|
-
throw new Error(`Talisman onboarding page not found`)
|
|
92
|
+
throw new Error(`Talisman onboarding page not found after ${maxAttempts} attempts`)
|
|
77
93
|
}
|
|
78
94
|
|
|
79
95
|
try {
|
|
80
96
|
// Bring the onboarding page to front
|
|
81
97
|
await extensionPage.bringToFront()
|
|
82
98
|
|
|
83
|
-
// Reload the onboarding page to ensure fresh state
|
|
84
|
-
console.log('🔄 Reloading onboarding page for fresh state...')
|
|
85
|
-
await extensionPage.reload()
|
|
86
|
-
|
|
87
99
|
// Wait for the page to load and become interactive
|
|
88
100
|
await extensionPage.waitForLoadState('domcontentloaded')
|
|
89
|
-
// await extensionPage.waitForTimeout(20000) // Give Talisman more time to initialize
|
|
90
101
|
|
|
91
102
|
// Click the get started button
|
|
92
103
|
await extensionPage.getByTestId('onboarding-get-started-button').click()
|
|
@@ -111,8 +122,6 @@ export async function importEthPrivateKey(
|
|
|
111
122
|
await extensionPage.getByRole('button', { name: 'Save' }).click()
|
|
112
123
|
|
|
113
124
|
await extensionPage.close()
|
|
114
|
-
|
|
115
|
-
console.log('✅ Talisman account import completed')
|
|
116
125
|
}
|
|
117
126
|
catch (error) {
|
|
118
127
|
console.error('❌ Error during Talisman account import:', error)
|
|
@@ -128,7 +137,6 @@ export async function authorizeTalisman(
|
|
|
128
137
|
const { accountName = 'Test Account' } = options
|
|
129
138
|
const context = page.__extensionContext
|
|
130
139
|
const extensionId = page.__extensionId
|
|
131
|
-
await new Promise(resolve => setTimeout(resolve, 1000))
|
|
132
140
|
|
|
133
141
|
const extensionPopup = await findExtensionPopup(context, extensionId)
|
|
134
142
|
|
|
@@ -141,7 +149,6 @@ export async function authorizeTalisman(
|
|
|
141
149
|
await anotherPopup.getByRole('button', { name: 'Approve' }).click()
|
|
142
150
|
}
|
|
143
151
|
catch {
|
|
144
|
-
console.log('No another popup found, skipping')
|
|
145
152
|
}
|
|
146
153
|
}
|
|
147
154
|
|
|
@@ -152,8 +159,25 @@ export async function approveTalismanTx(
|
|
|
152
159
|
const context = page.__extensionContext
|
|
153
160
|
const extensionId = page.__extensionId
|
|
154
161
|
|
|
155
|
-
await new Promise(resolve => setTimeout(resolve, 1000))
|
|
156
162
|
const extensionPopup = await findExtensionPopup(context, extensionId)
|
|
157
163
|
|
|
164
|
+
try {
|
|
165
|
+
await extensionPopup.getByRole('button', { name: 'Yes' }).click()
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
console.log('No another popup found, skipping')
|
|
169
|
+
}
|
|
170
|
+
|
|
158
171
|
await extensionPopup.getByRole('button', { name: 'Approve' }).click()
|
|
159
172
|
}
|
|
173
|
+
|
|
174
|
+
// Talisman specific transaction rejection implementation
|
|
175
|
+
export async function rejectTalismanTx(
|
|
176
|
+
page: Page & { __extensionContext: BrowserContext, __extensionId: string },
|
|
177
|
+
): Promise<void> {
|
|
178
|
+
const context = page.__extensionContext
|
|
179
|
+
const extensionId = page.__extensionId
|
|
180
|
+
|
|
181
|
+
const extensionPopup = await findExtensionPopup(context, extensionId)
|
|
182
|
+
await extensionPopup.getByTestId('connection-reject-button').click()
|
|
183
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { BrowserContext, Page, expect } from "@playwright/test";
|
|
2
|
-
import * as playwright_test0 from "playwright/test";
|
|
3
|
-
|
|
4
|
-
//#region src/context-playwright/types.d.ts
|
|
5
|
-
type WalletType = 'polkadot-js' | 'talisman';
|
|
6
|
-
interface WalletAccount {
|
|
7
|
-
seed: string;
|
|
8
|
-
name?: string;
|
|
9
|
-
password?: string;
|
|
10
|
-
}
|
|
11
|
-
interface WalletConfig {
|
|
12
|
-
type: WalletType;
|
|
13
|
-
downloadUrl?: string;
|
|
14
|
-
}
|
|
15
|
-
interface BaseWalletInstance {
|
|
16
|
-
extensionId: string;
|
|
17
|
-
importMnemonic: (options: WalletAccount) => Promise<void>;
|
|
18
|
-
authorize: (options?: {
|
|
19
|
-
accountName?: string;
|
|
20
|
-
}) => Promise<void>;
|
|
21
|
-
approveTx: (options?: {
|
|
22
|
-
password?: string;
|
|
23
|
-
}) => Promise<void>;
|
|
24
|
-
}
|
|
25
|
-
interface PolkadotJsWalletInstance extends BaseWalletInstance {
|
|
26
|
-
type: 'polkadot-js';
|
|
27
|
-
}
|
|
28
|
-
interface TalismanWalletInstance extends BaseWalletInstance {
|
|
29
|
-
type: 'talisman';
|
|
30
|
-
importEthPrivateKey: (options: {
|
|
31
|
-
privateKey: string;
|
|
32
|
-
name?: string;
|
|
33
|
-
password?: string;
|
|
34
|
-
}) => Promise<void>;
|
|
35
|
-
}
|
|
36
|
-
interface WalletTypeMap {
|
|
37
|
-
'polkadot-js': PolkadotJsWalletInstance;
|
|
38
|
-
'talisman': TalismanWalletInstance;
|
|
39
|
-
}
|
|
40
|
-
type Wallets = WalletTypeMap;
|
|
41
|
-
type ConfiguredWallets<T extends readonly WalletConfig[]> = { [K in T[number]['type']]: WalletTypeMap[K] };
|
|
42
|
-
type ExtendedPage = Page & {
|
|
43
|
-
__extensionContext: BrowserContext;
|
|
44
|
-
__walletExtensionIds: Map<string, string>;
|
|
45
|
-
};
|
|
46
|
-
interface ChromaTestOptions<T extends readonly WalletConfig[] = WalletConfig[]> {
|
|
47
|
-
wallets?: T;
|
|
48
|
-
headless?: boolean;
|
|
49
|
-
slowMo?: number;
|
|
50
|
-
}
|
|
51
|
-
interface WalletFixtures<W = Wallets> {
|
|
52
|
-
page: ExtendedPage;
|
|
53
|
-
wallets: W;
|
|
54
|
-
}
|
|
55
|
-
interface WalletWorkerFixtures {
|
|
56
|
-
walletContext: BrowserContext;
|
|
57
|
-
walletExtensionIds: Map<string, string>;
|
|
58
|
-
}
|
|
59
|
-
//#endregion
|
|
60
|
-
//#region src/context-playwright/index.d.ts
|
|
61
|
-
declare function createWalletTest<const T extends readonly WalletConfig[]>(options?: ChromaTestOptions<T>): playwright_test0.TestType<playwright_test0.PlaywrightTestArgs & playwright_test0.PlaywrightTestOptions & WalletFixtures<T extends readonly WalletConfig[] ? ConfiguredWallets<T> : WalletTypeMap>, playwright_test0.PlaywrightWorkerArgs & playwright_test0.PlaywrightWorkerOptions & WalletWorkerFixtures>;
|
|
62
|
-
declare const test: ReturnType<typeof createWalletTest>;
|
|
63
|
-
//#endregion
|
|
64
|
-
export { createWalletTest, expect, test };
|