Skip to content

Commit

Permalink
πŸƒβ€β™€οΈ Activate browser wallet check options type in runtime (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
yivlad committed Oct 31, 2022
1 parent 14c271f commit 50d1ac2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-turtles-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@usedapp/core': patch
---

Safely handle invalid runtime parameters in `activateBrowserWallet`
9 changes: 8 additions & 1 deletion packages/core/src/providers/network/connectors/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ export function ConnectorContextProvider({ children }: ConnectorContextProviderP
)

const activateBrowserWallet: ActivateBrowserWallet = useCallback(
async ({ type } = { type: 'metamask' }) => {
async (options) => {
// done for backward compatibility.
// If the options object looks like an event object or is undefined,
// it's not a valid option and will be ignored
if (!options || typeof (options as any).preventDefault === 'function') {
options = { type: 'metamask' }
}
const { type } = options
if (!connectors[type]) {
throw new Error(`Connector ${type} is not configured`)
}
Expand Down
8 changes: 4 additions & 4 deletions packages/example/playwright/without-metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ export const withoutMetamaskTest = (baseUrl: string) => {
await page.goto(`${baseUrl}multichain`)

await waitForExpect(async () => {
expect(await page.isVisible(XPath.text('span', 'Chain id:', 4))).to.be.true
expect(await page.isVisible(XPath.text('span', 'Current block timestamp:', 4))).to.be.true
expect(await page.isVisible(XPath.text('span', 'Current difficulty:', 4))).to.be.true
expect(await page.isVisible(XPath.text('span', 'Current block:', 4))).to.be.true
expect(await page.isVisible(XPath.text('span', 'Chain id:', 2))).to.be.true
expect(await page.isVisible(XPath.text('span', 'Current block timestamp:', 2))).to.be.true
expect(await page.isVisible(XPath.text('span', 'Current difficulty:', 2))).to.be.true
expect(await page.isVisible(XPath.text('span', 'Current block:', 2))).to.be.true
})
})
})
Expand Down

2 comments on commit 50d1ac2

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://example.usedapp.io as production
πŸš€ Deployed on https://635ffcf3f27b700097b630f3--usedapp-example.netlify.app

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰ Published on https://usedapp.io as production
πŸš€ Deployed on https://635ffcfbaea2e600746002a2--usedapp-website.netlify.app

Please sign in to comment.