Skip to content

Commit ebc2ebf

Browse files
[MMSDK] Updates mmsdk to latest and fixes a bad call when extension doesn't exist (#354)
* chore: updates mmsdk to latest * fix: avoids a call to eth_accounts when the only provider is mmsdk and the connection doesn't exist yet * fix: fixes a bad reference to the provider UUID
1 parent db5fb41 commit ebc2ebf

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@metamask/eslint-config-nodejs": "^6.0.0",
4444
"@metamask/eth-sig-util": "^7.0.1",
4545
"@metamask/onboarding": "^1.0.0",
46-
"@metamask/sdk": "^0.26.5",
46+
"@metamask/sdk": "^0.27.0",
4747
"@openzeppelin/contracts": "4.9.6",
4848
"@walletconnect/modal": "^2.6.2",
4949
"@web3modal/ethers5": "^3.2.0",

src/connections.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function handleSdkConnect(name, button, isConnected) {
6363
updateFormElements();
6464
updateSdkConnectionState(false);
6565
removeProviderDetail(name);
66-
sdk.terminate();
66+
await sdk.terminate();
6767
button.innerText = 'Sdk Connect';
6868
button.classList.add('btn-primary');
6969
button.classList.remove('btn-danger');

src/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,13 @@ const detectEip6963 = () => {
553553

554554
export const setActiveProviderDetail = async (providerDetail) => {
555555
closeProvider();
556+
// When the extension is not installed the providerDetails comes in undefined
557+
// but because the SDK is already init the window.ethereum has been injected
558+
// this doesn't mean we can refer to it directly as the connection may have
559+
// not been approved which is there uuid comes in as empty
560+
if (!providerDetail || providerDetail.info.uuid === '') {
561+
return;
562+
}
556563
provider = providerDetail.provider;
557564
await initializeProvider();
558565

@@ -791,7 +798,7 @@ const initializeProvider = async () => {
791798

792799
if (isMetaMaskInstalled()) {
793800
provider.autoRefreshOnNetworkChange = false;
794-
getNetworkAndChainId();
801+
await getNetworkAndChainId();
795802

796803
provider.on('chainChanged', handleNewChain);
797804
provider.on('chainChanged', handleEIP1559Support);
@@ -3268,7 +3275,11 @@ const setDeeplinks = () => {
32683275
const initialize = async () => {
32693276
await setActiveProviderDetailWindowEthereum();
32703277
detectEip6963();
3271-
await setActiveProviderDetail(providerDetails[0]);
3278+
// We only want to set the activeProviderDetail is there is one instead of
3279+
// assuming it exists
3280+
if (providerDetails.length > 0) {
3281+
await setActiveProviderDetail(providerDetails[0]);
3282+
}
32723283
initializeFormElements();
32733284
setDeeplinks();
32743285
};

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,10 @@
684684
resolved "https://registry.yarnpkg.com/@metamask/safe-event-emitter/-/safe-event-emitter-3.1.1.tgz#e89b840a7af8097a8ed4953d8dc8470d1302d3ef"
685685
integrity sha512-ihb3B0T/wJm1eUuArYP4lCTSEoZsClHhuWyfo/kMX3m/odpqNcPfsz5O2A3NT7dXCAgWPGDQGPqygCpgeniKMw==
686686

687-
"@metamask/sdk-communication-layer@0.26.4":
688-
version "0.26.4"
689-
resolved "https://registry.yarnpkg.com/@metamask/sdk-communication-layer/-/sdk-communication-layer-0.26.4.tgz#dda8e33a327f29962095b82c598799b852e40d81"
690-
integrity sha512-+X4GEc5mV1gWK4moSswVlKsUh+RsA48qPlkxBLTUxQODSnyBe0TRMxE6mH+bSrfponnTzvBkGUXyEjvDwDjDHw==
687+
"@metamask/sdk-communication-layer@0.27.0":
688+
version "0.27.0"
689+
resolved "https://registry.yarnpkg.com/@metamask/sdk-communication-layer/-/sdk-communication-layer-0.27.0.tgz#8d618fadd39f11627d5b3ef1bc72867439e33ff4"
690+
integrity sha512-G9LCaQzIqp5WmUmvHN6UUdjWrBh67MbRobmbbs5fcc2+9XFhj3vBgtyleUYjun91jSlPHoZeo+f/Pj4/WoPIJg==
691691
dependencies:
692692
bufferutil "^4.0.8"
693693
date-fns "^2.29.3"
@@ -702,14 +702,14 @@
702702
dependencies:
703703
qr-code-styling "^1.6.0-rc.1"
704704

705-
"@metamask/sdk@^0.26.5":
706-
version "0.26.5"
707-
resolved "https://registry.yarnpkg.com/@metamask/sdk/-/sdk-0.26.5.tgz#8adf2957918d0ec06be499d995da15d2171c058e"
708-
integrity sha512-HS/MPQCCYRS+m3dDdGLcAagwYHiPv9iUshDMBjINUywCtfUN4P2BH8xdvPOgtnzRIuRSMXqMWBbZnTvEvBeQvA==
705+
"@metamask/sdk@^0.27.0":
706+
version "0.27.0"
707+
resolved "https://registry.yarnpkg.com/@metamask/sdk/-/sdk-0.27.0.tgz#38617985b8305a0f5d482cdd7af8ddec87968bb7"
708+
integrity sha512-6sMjr/0qR700X1svPGEQ4rBdtccidBLeTC27fYQc7r9ROgSixB1DUUAyu/LoySVqt3Hu/Zm7NnAHXuT228ht7A==
709709
dependencies:
710710
"@metamask/onboarding" "^1.0.1"
711711
"@metamask/providers" "16.1.0"
712-
"@metamask/sdk-communication-layer" "0.26.4"
712+
"@metamask/sdk-communication-layer" "0.27.0"
713713
"@metamask/sdk-install-modal-web" "0.26.5"
714714
"@types/dom-screen-wake-lock" "^1.0.0"
715715
bowser "^2.9.0"

0 commit comments

Comments
 (0)