Added integrity check button
This commit is contained in:
parent
2cf55956f2
commit
720ed0557b
76
index.html
76
index.html
@ -65,6 +65,7 @@
|
|||||||
</sm-popup>
|
</sm-popup>
|
||||||
<script src="scripts/components.min.js"></script>
|
<script src="scripts/components.min.js"></script>
|
||||||
<script src="https://unpkg.com/uhtml@3.0.1/es.js"></script>
|
<script src="https://unpkg.com/uhtml@3.0.1/es.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const { html, svg, render: renderElem } = uhtml;
|
const { html, svg, render: renderElem } = uhtml;
|
||||||
const uiGlobals = {}
|
const uiGlobals = {}
|
||||||
@ -118,7 +119,7 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
//Function for displaying toast notifications. pass in error for mode param if you want to show an error.
|
//Function for displaying toast notifications. pass in error for mode param if you want to show an error.
|
||||||
function notify(message, mode, options = { timeout, pinned }) {
|
function notify(message, mode, options = {}) {
|
||||||
let icon
|
let icon
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 'success':
|
case 'success':
|
||||||
@ -335,7 +336,7 @@
|
|||||||
const { hash: knownHash, appLink } = elem.closest('.dapp-card').dataset;
|
const { hash: knownHash, appLink } = elem.closest('.dapp-card').dataset;
|
||||||
getRepoHash(appLink.split('/').pop()).then(latestHash => {
|
getRepoHash(appLink.split('/').pop()).then(latestHash => {
|
||||||
if (latestHash !== knownHash) {
|
if (latestHash !== knownHash) {
|
||||||
notify(`The dapp you are trying to download has been modified. Dapp won't be downloaded.`, 'error')
|
notify(`The dapp you are trying to download has failed integrity check. Dapp won't be downloaded.`, 'error')
|
||||||
} else {
|
} else {
|
||||||
if (preventDownloadInfoPopup === null || preventDownloadInfoPopup === 'false')
|
if (preventDownloadInfoPopup === null || preventDownloadInfoPopup === 'false')
|
||||||
openPopup('download_info_popup')
|
openPopup('download_info_popup')
|
||||||
@ -387,7 +388,7 @@
|
|||||||
"borrow"
|
"borrow"
|
||||||
],
|
],
|
||||||
"category": "finance",
|
"category": "finance",
|
||||||
"hash": "197f0c491e8cabf866603d03c437f9b96ad5b58ce55de2f6bc0d39a633fdf5e1"
|
"hash": "197f0c491e8cabf866603d03c437f9b96ad5b58ce55de2f6bc0d39a633fdf5e2"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "BTC Wallet",
|
"name": "BTC Wallet",
|
||||||
@ -609,6 +610,9 @@
|
|||||||
<p class="dapp-card__description">${description}</p>
|
<p class="dapp-card__description">${description}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex gap-0-5 align-center flex-wrap">
|
<div class="flex gap-0-5 align-center flex-wrap">
|
||||||
|
<button class="button dapp-card__link" onclick=${checkIntegrity}>
|
||||||
|
Check integrity
|
||||||
|
</button>
|
||||||
<a href=${`https://github.com/ranchimall/${appLink.split('/').pop()}/archive/refs/heads/master.zip`} class="button dapp-card__link dapp-download-button" title="Download dapp Zip">
|
<a href=${`https://github.com/ranchimall/${appLink.split('/').pop()}/archive/refs/heads/master.zip`} class="button dapp-card__link dapp-download-button" title="Download dapp Zip">
|
||||||
<svg class="icon" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/></g><g><path d="M18,15v3H6v-3H4v3c0,1.1,0.9,2,2,2h12c1.1,0,2-0.9,2-2v-3H18z M17,11l-1.41-1.41L13,12.17V4h-2v8.17L8.41,9.59L7,11l5,5 L17,11z"/></g></svg>
|
<svg class="icon" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/></g><g><path d="M18,15v3H6v-3H4v3c0,1.1,0.9,2,2,2h12c1.1,0,2-0.9,2-2v-3H18z M17,11l-1.41-1.41L13,12.17V4h-2v8.17L8.41,9.59L7,11l5,5 L17,11z"/></g></svg>
|
||||||
</a>
|
</a>
|
||||||
@ -620,6 +624,41 @@
|
|||||||
</li>
|
</li>
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
function pseudoDisable(element, disable) {
|
||||||
|
if (disable) {
|
||||||
|
element.dataset.disabled = true
|
||||||
|
element.style.pointerEvents = 'none'
|
||||||
|
element.tabIndex = -1
|
||||||
|
} else {
|
||||||
|
delete element.dataset.disabled
|
||||||
|
element.style.pointerEvents = 'auto'
|
||||||
|
element.tabIndex = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function checkIntegrity(e) {
|
||||||
|
const dappCard = e.target.closest('.dapp-card')
|
||||||
|
const { hash: knownHash, appLink } = dappCard.dataset;
|
||||||
|
pseudoDisable(e.target, true)
|
||||||
|
renderElem(e.target, html`Checking...<sm-spinner></sm-spinner>`)
|
||||||
|
getRepoHash(appLink.split('/').pop()).then(latestHash => {
|
||||||
|
if (latestHash !== knownHash) {
|
||||||
|
notify(`The dapp has failed integrity check. Dapp won't be allowed to use.`, 'error')
|
||||||
|
renderElem(e.target.closest('.flex'), html`
|
||||||
|
<strong style="color: var(--danger-color)">Failed integrity check</strong>
|
||||||
|
`)
|
||||||
|
} else {
|
||||||
|
notify(`The dapp has passed integrity check. Dapp can be used safely.`, 'success')
|
||||||
|
renderElem(e.target, html`Check integrity`)
|
||||||
|
pseudoDisable(e.target, false)
|
||||||
|
}
|
||||||
|
}).catch(e => {
|
||||||
|
pseudoDisable(e.target, false)
|
||||||
|
console.error(e)
|
||||||
|
notify('There was an error while checking integrity. Please try again later.', 'error', {
|
||||||
|
timeout: 10000,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
function renderHome(state) {
|
function renderHome(state) {
|
||||||
const { params: { category = 'all', query = '' }, page, viewTransition, lastPage } = state
|
const { params: { category = 'all', query = '' }, page, viewTransition, lastPage } = state
|
||||||
getRef('page_container').dataset.page = 'home';
|
getRef('page_container').dataset.page = 'home';
|
||||||
@ -690,6 +729,37 @@
|
|||||||
);
|
);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
function downloadAllDapps() {
|
||||||
|
// const downloadAllButton = getRef('download_all_button')
|
||||||
|
// const downloadAllButtonContent = downloadAllButton.innerHTML
|
||||||
|
// downloadAllButton.innerHTML = 'Downloading...<sm-spinner></sm-spinner>'
|
||||||
|
// downloadAllButton.disabled = true
|
||||||
|
const verificationPromises = dappsList.map(({ appLink }) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const appRepoName = appLink.split('/').pop()
|
||||||
|
getRepoHash(appRepoName).then(latestHash => {
|
||||||
|
const { hash: knownHash } = dappsList.find(dapp => dapp.appLink === appLink)
|
||||||
|
if (latestHash !== knownHash) {
|
||||||
|
notify(`The dapp '${appRepoName}' has failed integrity check. Dapp won't be downloaded.`, 'error')
|
||||||
|
reject()
|
||||||
|
} else {
|
||||||
|
resolve(`https://github.com/ranchimall/${appRepoName}/archive/refs/heads/master.zip`)
|
||||||
|
}
|
||||||
|
}).catch(e => {
|
||||||
|
console.error(e)
|
||||||
|
notify('There was an error while trying to download the dapp. Please try again later.', 'error', {
|
||||||
|
timeout: 10000,
|
||||||
|
})
|
||||||
|
reject()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
Promise.allSettled(verificationPromises).then(downloadLinks => {
|
||||||
|
downloadLinks = downloadLinks.filter(({ status }) => status === 'fulfilled').map(({ value }) => value)
|
||||||
|
// pack and download all dapps
|
||||||
|
const zip = new JSZip();
|
||||||
|
})
|
||||||
|
}
|
||||||
function verifyLink() {
|
function verifyLink() {
|
||||||
const linkToVerify = getRef('link_verification__input').value.trim();
|
const linkToVerify = getRef('link_verification__input').value.trim();
|
||||||
if (linkToVerify === '')
|
if (linkToVerify === '')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user