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: Make the dapp install snap v0.7.1 #55

Merged
merged 1 commit into from
Apr 17, 2024
Merged
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
44 changes: 23 additions & 21 deletions packages/site/src/script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const snapId = 'npm:@consensys/linea-voyager';
const snapVersion = "^0.7.0";
var isAccountConnected = false;
const snapVersion = '^0.7.1';
let isAccountConnected = false;

/*
* Use EIP-6963 to detect MetaMask
Expand All @@ -19,9 +19,8 @@ const MetaMaskFound = async (providerDetail) => {
if (Object.keys(snaps).includes(snapId)) {
// snap installed, go to step 2
return await snapAlreadyInstalled(provider);
} else {
// the snap was not installed
}
// the snap was not installed
} catch (error) {}

const btn = document.createElement('button');
Expand All @@ -39,7 +38,7 @@ const MetaMaskFound = async (providerDetail) => {
method: 'wallet_requestSnaps',
params: {
[snapId]: {
"version": snapVersion
version: snapVersion,
},
},
});
Expand All @@ -64,7 +63,7 @@ const MetaMaskFound = async (providerDetail) => {
document.getElementById('loading').appendChild(btn);
};

const snapAlreadyInstalled = async (provider) => {
const snapAlreadyInstalled = async (provider) => {
const response = await provider.request({
method: 'wallet_invokeSnap',
params: {
Expand All @@ -83,16 +82,17 @@ const snapAlreadyInstalled = async (provider) => {
message.appendChild(address);
document.getElementById('context').textContent = '';
document.getElementById('context').appendChild(message);
isAccountConnected = true;
} else {}
await snapInstalled(provider, true);
};
isAccountConnected = true;
} else {
}
await snapInstalled(provider, true);
};

const snapInstalled = async (provider, skippedStep1 = false) => {
const btn = document.createElement('button');
btn.id = 'accountConnectionButton';
btn.id = 'accountConnectionButton';
btn.className = 'btn btn-primary btn-lg';
btn.textContent = isAccountConnected? 'Change Account' : 'Connect Account';
btn.textContent = isAccountConnected ? 'Change Account' : 'Connect Account';

const caption = document.createElement('p');
caption.className = 'caption';
Expand Down Expand Up @@ -156,25 +156,27 @@ const snapInstalled = async (provider, skippedStep1 = false) => {
const address = document.createElement('code');
address.textContent = `${accounts[0]}`;
message.appendChild(address);
isAccountConnected = true;
isAccountConnected = true;
try {
document.getElementById('accountConnectionButton').textContent = 'Change Address';
}
catch (error) {}
document.getElementById('accountConnectionButton').textContent =
'Change Address';
} catch (error) {}
} else {
message.textContent = 'Failed to connect address';
isAccountConnected = false;
isAccountConnected = false;
try {
document.getElementById('accountConnectionButton').textContent = 'Connect Address';
}
catch (error) {}
document.getElementById('accountConnectionButton').textContent =
'Connect Address';
} catch (error) {}
}
document.getElementById('context').textContent = '';
document.getElementById('context').appendChild(message);
}
};
document.getElementById('loading').textContent = '';
if(!skippedStep1) document.getElementById('loading').appendChild(caption);
if (!skippedStep1) {
document.getElementById('loading').appendChild(caption);
}
document.getElementById('loading').appendChild(btn);
document.getElementById('loading').appendChild(alternate);
};
Expand Down
Loading