Skip to content

Commit

Permalink
refactor: injected connector provider
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Dec 30, 2021
1 parent 37d39d1 commit 0bff89a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 31 deletions.
6 changes: 6 additions & 0 deletions .changeset/silent-badgers-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'wagmi-private': patch
'wagmi': patch
---

update injected connector
22 changes: 0 additions & 22 deletions .github/workflows/size.yml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/pages/docs/hooks/useSignMessage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const App = () => {

if (!data)
return (
<button disabled={loading} onClick={() => await signMessage()}>
<button disabled={loading} onClick={async () => await signMessage()}>
Sign message
</button>
)
Expand Down
5 changes: 1 addition & 4 deletions packages/private/src/connectors/injectedConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@ export class InjectedConnector extends Connector<
typeof window !== 'undefined' && window.ethereum?.isMetaMask
? 'MetaMask'
: 'Injected'
readonly provider = window?.ethereum
readonly ready = typeof window !== 'undefined' && !!window.ethereum

constructor(config?: { chains?: Chain[] }) {
super({ ...config, options: undefined })
}

get provider() {
return window?.ethereum
}

async connect() {
try {
if (!this.provider) throw new ConnectorNotFoundError()
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/hooks/accounts/useSignMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ describe('useSignMessage', () => {

const res = await result.current.signMessage[1]()
if (typeof res !== 'string') throw new Error('No signature')
const recovered = verifyNormalizedMessage(messageLookup.basic, res)
const account =
await result.current.connect[0].data.connector?.getAccount()
const recovered = verifyNormalizedMessage(messageLookup.basic, res)
expect(account).toEqual(recovered)
})

Expand All @@ -65,12 +65,12 @@ describe('useSignMessage', () => {
"loading": false,
}
`)
const account =
await result.current.connect[0].data.connector?.getAccount()
const recovered = verifyNormalizedMessage(
messageLookup.basic,
<any>result.current.signMessage[0]?.data,
)
const account =
await result.current.connect[0].data.connector?.getAccount()
expect(account).toEqual(recovered)
})

Expand All @@ -85,9 +85,9 @@ describe('useSignMessage', () => {
message: messageLookup.basic,
})
if (typeof res !== 'string') throw new Error('No signature')
const recovered = verifyNormalizedMessage(messageLookup.basic, res)
const account =
await result.current.connect[0].data.connector?.getAccount()
const recovered = verifyNormalizedMessage(messageLookup.basic, res)
expect(account).toEqual(recovered)
})
})
Expand Down

0 comments on commit 0bff89a

Please sign in to comment.