Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle account disconnects (lock wallet) #170

Draft
wants to merge 4 commits into
base: sidepanel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions extension/e2e/errorHandling.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { mock } from '@depay/web3-mock'
import { expect, test } from './fixture'
import { loadExtension } from './loadExtension'
import { mockWeb3 } from './mockWeb3'

test('handles wallet disconnect gracefully', async ({ page, extensionId }) => {
mockWeb3(page, () =>
mock({
blockchain: 'ethereum',
accounts: { return: ['0x0000000000000000000000000000000000000000'] },
})
)

const extension = await loadExtension(page, extensionId)

await extension.getByRole('link', { name: 'Configure routes' }).click()
await extension.getByRole('button', { name: 'Add Route' }).click()
await extension.getByRole('button', { name: 'Connect with MetaMask' }).click()

await expect(
extension.getByRole('alert', { name: 'Account disconnected' })
).toBeInViewport()

Check failure on line 22 in extension/e2e/errorHandling.spec.ts

View workflow job for this annotation

GitHub Actions / test

[chromium] › errorHandling.spec.ts:6:1 › handles wallet disconnect gracefully

1) [chromium] › errorHandling.spec.ts:6:1 › handles wallet disconnect gracefully ───────────────── Error: Timed out 5000ms waiting for expect(locator).toBeInViewport() Locator: getByRole('alert', { name: 'Account disconnected' }) Expected: in viewport Received: <element(s) not found> Call log: - expect.toBeInViewport with timeout 5000ms - waiting for getByRole('alert', { name: 'Account disconnected' }) 20 | await expect( 21 | extension.getByRole('alert', { name: 'Account disconnected' }) > 22 | ).toBeInViewport() | ^ 23 | }) 24 | at /home/runner/work/zodiac-pilot/zodiac-pilot/extension/e2e/errorHandling.spec.ts:22:5

Check failure on line 22 in extension/e2e/errorHandling.spec.ts

View workflow job for this annotation

GitHub Actions / test

[chromium] › errorHandling.spec.ts:6:1 › handles wallet disconnect gracefully

1) [chromium] › errorHandling.spec.ts:6:1 › handles wallet disconnect gracefully ───────────────── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toBeInViewport() Locator: getByRole('alert', { name: 'Account disconnected' }) Expected: in viewport Received: <element(s) not found> Call log: - expect.toBeInViewport with timeout 5000ms - waiting for getByRole('alert', { name: 'Account disconnected' }) 20 | await expect( 21 | extension.getByRole('alert', { name: 'Account disconnected' }) > 22 | ).toBeInViewport() | ^ 23 | }) 24 | at /home/runner/work/zodiac-pilot/zodiac-pilot/extension/e2e/errorHandling.spec.ts:22:5

Check failure on line 22 in extension/e2e/errorHandling.spec.ts

View workflow job for this annotation

GitHub Actions / test

[chromium] › errorHandling.spec.ts:6:1 › handles wallet disconnect gracefully

1) [chromium] › errorHandling.spec.ts:6:1 › handles wallet disconnect gracefully ───────────────── Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toBeInViewport() Locator: getByRole('alert', { name: 'Account disconnected' }) Expected: in viewport Received: <element(s) not found> Call log: - expect.toBeInViewport with timeout 5000ms - waiting for getByRole('alert', { name: 'Account disconnected' }) 20 | await expect( 21 | extension.getByRole('alert', { name: 'Account disconnected' }) > 22 | ).toBeInViewport() | ^ 23 | }) 24 | at /home/runner/work/zodiac-pilot/zodiac-pilot/extension/e2e/errorHandling.spec.ts:22:5
})
25 changes: 25 additions & 0 deletions extension/e2e/mockWeb3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Page } from '@playwright/test'
import { readFileSync } from 'fs'
import { MutableRefObject } from 'react'
import { fileURLToPath } from 'url'

const web3Content: MutableRefObject<string | null> = { current: null }

export const mockWeb3 = (page: Page, fn: () => unknown) => {
page.addInitScript({
content: `${getLibraryCode()}\n(${fn.toString().replaceAll('mock', 'Web3Mock.mock')})()`,
})
}

const getLibraryCode = () => {
if (web3Content.current == null) {
web3Content.current = readFileSync(
fileURLToPath(
import.meta.resolve('@depay/web3-mock/dist/umd/index.bundle.js')
),
'utf-8'
)
}

return web3Content.current
}
1 change: 1 addition & 0 deletions extension/src/components/RouteBubble/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const RouteBubble: React.FC = () => {
</Box>
<Link to="/routes">
<Box bg className={classes.connectionsContainer}>
<span className="sr-only">Configure routes</span>
<ConnectionsIcon height="100%" width="100%" />
</Box>
</Link>
Expand Down
Loading