Skip to content

Commit

Permalink
feat: upgrade @metamask/sdk package to version '0.12.4' (#3237)
Browse files Browse the repository at this point in the history
* feat: upgrade @metamask/sdk package to version '0.12.2'

* chore: code clean

* chore: remove the extensionOnly option

* fix: sdk is not disconnecting

* feat: upgrade @metamask/sdk package to version '0.12.4'

* feat: bump version

---------

Co-authored-by: Tom Meagher <tom@meagher.co>
  • Loading branch information
omridan159 and tmm authored Dec 8, 2023
1 parent d84e11a commit 4bc85b1
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/connectors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"dependencies": {
"@coinbase/wallet-sdk": "3.9.0-canary.2",
"@ledgerhq/connect-kit-loader": "^1.1.2",
"@metamask/sdk": "^0.8.0",
"@metamask/sdk": "^0.14.1",
"@safe-global/safe-apps-provider": "^0.18.0",
"@safe-global/safe-apps-sdk": "^8.1.0",
"@walletconnect/ethereum-provider": "^2.10.1",
Expand Down
12 changes: 10 additions & 2 deletions packages/connectors/src/metaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
provider.removeListener('disconnect', this.onDisconnect.bind(this))
provider.on('connect', this.onConnect.bind(this) as Listener)

sdk.terminate()

// Add shim signalling connector is disconnected
await config.storage?.setItem('metaMaskSDK.disconnected', true)
},
Expand Down Expand Up @@ -174,9 +176,15 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
})
await sdk.init()
}
walletProvider = sdk.getProvider()
try {
walletProvider = sdk.getProvider()
} catch (error) {
// TODO: SDK sometimes throws errors when MM extension or mobile provider is not detected (don't throw for those errors)
const regex = /^SDK state invalid -- undefined( mobile)? provider$/
if (!regex.test((error as Error).message)) throw error
}
}
return walletProvider
return walletProvider!
},
async isAuthorized() {
try {
Expand Down
3 changes: 1 addition & 2 deletions playgrounds/vite-react/src/wagmi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { http, createConfig } from 'wagmi'
import { celo, mainnet, optimism, sepolia } from 'wagmi/chains'
import {
coinbaseWallet,
injected,
ledger,
metaMask,
safe,
Expand Down Expand Up @@ -33,8 +32,8 @@ export const config = createConfig({
ledger({ projectId: import.meta.env.VITE_WC_PROJECT_ID }),
safe({ debug: true, shimDisconnect: true }),
metaMask(),
injected(),
],
multiInjectedProviderDiscovery: false,
transports: {
[mainnet.id]: http(
'https://eth-mainnet.g.alchemy.com/v2/StF61Ht3J9nXAojZX-b21LVt9l0qDL38',
Expand Down
Loading

0 comments on commit 4bc85b1

Please sign in to comment.