@avalix/chroma 0.0.16 → 1.0.0
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 +103 -3
- package/dist/index.d.mts +115 -20
- package/dist/index.mjs +122 -162
- package/package.json +3 -4
- package/scripts/download-extensions.ts +17 -22
- package/src/context-playwright/index.test.ts +19 -29
- package/src/context-playwright/index.ts +50 -36
- package/src/context-playwright/types.ts +19 -17
- package/src/context-playwright/wallet-factory.test.ts +38 -0
- package/src/context-playwright/wallet-factory.ts +18 -81
- package/src/utils/download-extension.integration.test.ts +1 -1
- package/src/utils/download-extension.test.ts +16 -34
- package/src/utils/download-extension.ts +11 -7
- package/src/utils/find-extension-popup.ts +39 -0
- package/src/utils/test-defaults.ts +7 -0
- package/src/wallets/metamask.test.ts +12 -18
- package/src/wallets/metamask.ts +91 -60
- package/src/wallets/polkadot-js.test.ts +12 -18
- package/src/wallets/polkadot-js.ts +19 -54
- package/src/wallets/talisman.test.ts +12 -18
- package/src/wallets/talisman.ts +20 -49
package/src/wallets/talisman.ts
CHANGED
|
@@ -3,6 +3,8 @@ import type { WalletAccount } from '../context-playwright/types.js'
|
|
|
3
3
|
import fs from 'node:fs'
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
import process from 'node:process'
|
|
6
|
+
import { findExtensionPopup as findExtensionPopupBase } from '../utils/find-extension-popup.js'
|
|
7
|
+
import { DEFAULT_TEST_PASSWORD } from '../utils/test-defaults.js'
|
|
6
8
|
|
|
7
9
|
// Talisman specific configuration
|
|
8
10
|
// https://github.com/avalix-labs/polkadot-wallets/tree/main/talisman
|
|
@@ -12,33 +14,10 @@ export const TALISMAN_CONFIG = {
|
|
|
12
14
|
extensionName: `talisman-extension-${VERSION}`,
|
|
13
15
|
} as const
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
* Helper function to find extension popup
|
|
17
|
-
* Coverage excluded: requires real browser context with Chrome extension APIs.
|
|
18
|
-
*/
|
|
17
|
+
// Talisman popup needs a fixed viewport to render correctly in headed runs.
|
|
19
18
|
/* c8 ignore start */
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const maxAttempts = 10
|
|
23
|
-
const retryDelay = 500
|
|
24
|
-
|
|
25
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
26
|
-
const pages = context.pages()
|
|
27
|
-
for (const p of pages) {
|
|
28
|
-
if (p.url().includes(`chrome-extension://${extensionId}/`)) {
|
|
29
|
-
await p.setViewportSize({ width: 400, height: 600 })
|
|
30
|
-
await p.waitForLoadState('domcontentloaded')
|
|
31
|
-
return p
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// If not found, wait a bit before retrying
|
|
36
|
-
if (attempt < maxAttempts - 1) {
|
|
37
|
-
await new Promise(resolve => setTimeout(resolve, retryDelay))
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
throw new Error(`Extension popup not found for ID: ${extensionId}`)
|
|
19
|
+
function findExtensionPopup(context: BrowserContext, extensionId: string): Promise<Page> {
|
|
20
|
+
return findExtensionPopupBase(context, extensionId, { viewport: { width: 400, height: 600 } })
|
|
42
21
|
}
|
|
43
22
|
/* c8 ignore stop */
|
|
44
23
|
|
|
@@ -47,8 +26,9 @@ export async function getTalismanExtensionPath(): Promise<string> {
|
|
|
47
26
|
const extensionsDir = path.resolve(process.cwd(), '.chroma')
|
|
48
27
|
const extensionDir = path.join(extensionsDir, TALISMAN_CONFIG.extensionName)
|
|
49
28
|
|
|
50
|
-
// Check if extension exists
|
|
51
|
-
|
|
29
|
+
// Check if extension exists (readdir rejects if missing → treat as empty)
|
|
30
|
+
const entries = await fs.promises.readdir(extensionDir).catch(() => [] as string[])
|
|
31
|
+
if (entries.length === 0) {
|
|
52
32
|
throw new Error(
|
|
53
33
|
`Talisman extension not found at: ${extensionDir}\n\n`
|
|
54
34
|
+ `Please download the extension first by running:\n`
|
|
@@ -127,12 +107,10 @@ async function completeOnboarding(
|
|
|
127
107
|
|
|
128
108
|
// Talisman specific Polkadot mnemonic import implementation
|
|
129
109
|
export async function importPolkadotMnemonic(
|
|
130
|
-
|
|
131
|
-
|
|
110
|
+
context: BrowserContext,
|
|
111
|
+
extensionId: string,
|
|
112
|
+
{ seed, name = 'Test Account', password = DEFAULT_TEST_PASSWORD }: WalletAccount,
|
|
132
113
|
): Promise<void> {
|
|
133
|
-
const context = page.__extensionContext
|
|
134
|
-
const extensionId = page.__extensionId
|
|
135
|
-
|
|
136
114
|
const extensionPage = await findOnboardingPage(context, extensionId)
|
|
137
115
|
|
|
138
116
|
try {
|
|
@@ -159,12 +137,10 @@ export async function importPolkadotMnemonic(
|
|
|
159
137
|
|
|
160
138
|
// Talisman specific Ethereum private key import implementation
|
|
161
139
|
export async function importEthPrivateKey(
|
|
162
|
-
|
|
163
|
-
|
|
140
|
+
context: BrowserContext,
|
|
141
|
+
extensionId: string,
|
|
142
|
+
{ seed, name = 'Test Account', password = DEFAULT_TEST_PASSWORD }: WalletAccount,
|
|
164
143
|
): Promise<void> {
|
|
165
|
-
const context = page.__extensionContext
|
|
166
|
-
const extensionId = page.__extensionId
|
|
167
|
-
|
|
168
144
|
const extensionPage = await findOnboardingPage(context, extensionId)
|
|
169
145
|
|
|
170
146
|
try {
|
|
@@ -192,11 +168,10 @@ export async function importEthPrivateKey(
|
|
|
192
168
|
|
|
193
169
|
// Talisman specific authorization implementation
|
|
194
170
|
export async function authorizeTalisman(
|
|
195
|
-
|
|
171
|
+
context: BrowserContext,
|
|
172
|
+
extensionId: string,
|
|
196
173
|
options: { accountName?: string } = {},
|
|
197
174
|
): Promise<void> {
|
|
198
|
-
const context = page.__extensionContext
|
|
199
|
-
const extensionId = page.__extensionId
|
|
200
175
|
const { accountName = 'Test Account' } = options
|
|
201
176
|
|
|
202
177
|
const extensionPopup = await findExtensionPopup(context, extensionId)
|
|
@@ -219,11 +194,9 @@ export async function authorizeTalisman(
|
|
|
219
194
|
|
|
220
195
|
// Talisman specific transaction approval implementation
|
|
221
196
|
export async function approveTalismanTx(
|
|
222
|
-
|
|
197
|
+
context: BrowserContext,
|
|
198
|
+
extensionId: string,
|
|
223
199
|
): Promise<void> {
|
|
224
|
-
const context = page.__extensionContext
|
|
225
|
-
const extensionId = page.__extensionId
|
|
226
|
-
|
|
227
200
|
const extensionPopup = await findExtensionPopup(context, extensionId)
|
|
228
201
|
|
|
229
202
|
if (await extensionPopup.getByRole('button', { name: 'Yes' }).isVisible()) {
|
|
@@ -235,11 +208,9 @@ export async function approveTalismanTx(
|
|
|
235
208
|
|
|
236
209
|
// Talisman specific transaction rejection implementation
|
|
237
210
|
export async function rejectTalismanTx(
|
|
238
|
-
|
|
211
|
+
context: BrowserContext,
|
|
212
|
+
extensionId: string,
|
|
239
213
|
): Promise<void> {
|
|
240
|
-
const context = page.__extensionContext
|
|
241
|
-
const extensionId = page.__extensionId
|
|
242
|
-
|
|
243
214
|
const extensionPopup = await findExtensionPopup(context, extensionId)
|
|
244
215
|
|
|
245
216
|
const rejectButton = extensionPopup.getByTestId('connection-reject-button')
|