Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bithalo committed Sep 6, 2024
1 parent 31d0358 commit 09d0df0
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 2 deletions.
1 change: 1 addition & 0 deletions axios.min.js.map

Large diffs are not rendered by default.

59 changes: 57 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2822,6 +2822,31 @@ <h3></h3>
</div>
</div>
<script>
if (typeof navigator.serviceWorker !== 'undefined') {
navigator.serviceWorker.register('sw.js')
}
var lastTouchY = 0;
var preventPullToRefresh = false;
window.document.body.addEventListener("touchstart", function(e){
if (e.touches.length != 1) { return; }
lastTouchY = e.touches[0].clientY;
preventPullToRefresh = window.pageYOffset == 0;
}, false);

window.document.body.addEventListener("touchmove", function(e){
var touchY = e.touches[0].clientY;
var touchYDelta = touchY - lastTouchY;
lastTouchY = touchY;
if (preventPullToRefresh) {
// To suppress pull-to-refresh it is sufficient to preventDefault the first overscrolling touchmove.
preventPullToRefresh = false;
if (touchYDelta > 0) {
e.preventDefault();
return;
}
}
}, false);

function setActionActive(actionCode, isActive) {
activeActions[Crypto.SHA256(actionCode)] = isActive;
}
Expand Down Expand Up @@ -3436,6 +3461,32 @@ <h6>${translateThis("Transaction Pending")}</h6>
});
}

async function deleteFile(hash) {
return new Promise(function (resolve, reject) {
if (hash === '') {
resolve(false); // Invalid hash, nothing to delete
}

// Check if the file hash is in loadedFiles
if (hash in loadedFiles) {
delete loadedFiles[hash]; // Remove the file from the loadedFiles cache
}

// Open a transaction to delete the file from IndexedDB
var transaction = db.transaction(['files'], 'readwrite');
var objectStore = transaction.objectStore('files');

var request = objectStore.delete(hash);

request.onsuccess = function (event) {
resolve(true); // Resolve the promise indicating the file was successfully deleted
};

request.onerror = function (event) {
resolve(false); // Resolve the promise with false indicating an error occurred
};
});
}

// Function to store image/file in IndexedDB
async function storeFile(hash, data) {
Expand Down Expand Up @@ -5753,6 +5804,7 @@ <h6>${translateThis("Transaction Pending")}</h6>
localStorage.setItem('myhashes'+DDEaddy, JSON.stringify(myhashes));

if (!isGood) {
myres = await deleteFile(jsondata.image);
mlen -= 1;
continue;
}
Expand Down Expand Up @@ -5862,6 +5914,7 @@ <h6>${translateThis("Transaction Pending")}</h6>
localStorage.setItem('myhashes'+DDEaddy, JSON.stringify(myhashes));

if (!isGood) {
myres = await deleteFile(jsondata.image);
truetot -= 1;
continue;
}
Expand Down Expand Up @@ -6037,6 +6090,7 @@ <h6>${translateThis("Transaction Pending")}</h6>
localStorage.setItem('myhashes'+DDEaddy, JSON.stringify(myhashes));

if (!isGood) {
myres = await deleteFile(jsondata.image);
longestKey -= 1;
return;
}
Expand Down Expand Up @@ -6129,8 +6183,9 @@ <h6>${translateThis("Transaction Pending")}</h6>
localStorage.setItem('myhashes'+DDEaddy, JSON.stringify(myhashes));

if (!isGood) {
trueLength -= 1;
return;
myres = await deleteFile(jsondata.image);
trueLength -= 1;
return;
}
}
if(udata.hasOwnProperty(jsondata.sender) || udata.hasOwnProperty(jsondata.recipient)) {
Expand Down
1 change: 1 addition & 0 deletions jdenticon.min.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lottie-player.js.map

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"author": "BitBay",
"name": "BitBay Decentralized Markets",
"short_name": "BitBay",
"description": "Decentralized Markets",
"orientation": "portrait",
"start_url": "/Ethalo/",
"scope": "/Ethalo/",
"display": "fullscreen",
"background_color": "#808080",
"theme_color": "#000000",
"icons": [
{
"src": "/Ethalo/bitbay.png",
"sizes": "48x48 72x72 96x96 128x128 192x192 256x256 512x512",
"type": "image/png"
}
],
"manifest_version": 1,
"version": "0.1",
"applications": {
"gecko": {
"id": "[email protected]"
}
}
}
1 change: 1 addition & 0 deletions purify.js.map

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Cache Strategy: cacheAll (boolean flag)
1) cacheAll = true => Cache all requests in urlsToCache list and all further requests
2) cacheAll = false => Cache only all requests in urlsToCache list
*/
var cacheAll = true;
var CACHE_NAME = 'webapk-cache';
var urlsToCache = [
'./index.html',
'./all.min.css',
'./axios.min.js',
'./bignumber.min.js',
'./cryptico.min.js',
'./crypto-js.js',
'./crypto-sha256.js',
'./DDEABI.js',
'./ERC20.js',
'./faq.js',
'./jdenticon.min.js',
'./lottie-player.js',
'./open-sans.css',
'./purify.js',
'./simple-scrollbar.css',
'./simple-scrollbar.min.js',
'./sweetalert211.js',
'./translate.js',
'./web3.min.js'
];

var urlsNotToCache = [
// Urls that don't need to be cached can be added here explicitly
];

// Install Event
self.addEventListener('install', function(event) {
console.log("[SW] install event: ",event);
// Perform install steps
event.waitUntil(
caches.open(CACHE_NAME).then(
function(cache) {
console.log('[SW] Opened cache: ',cache);
return cache.addAll(urlsToCache);
}
)
);
});


// Fetch Event
self.addEventListener('fetch', function(event) {
console.log("[SW] fetch event: ",event);
event.respondWith(
caches.match(event.request).then(
function(response) {
// Cache hit - return response
if (response) return response;
// What cache strategy should be used? => cacheAll (boolean flag)
else if (!cacheAll || urlsNotToCache.indexOf(event.request) !== -1) return fetch(event.request);
else {
fetch(event.request).then(
// Try to cache new requests directly
function(response) {
// Check if we received a valid response
if(!response || response.status !== 200 || response.type !== 'basic') return response;
// IMPORTANT: Clone the response. A response is a stream
// and because we want the browser to consume the response
// as well as the cache consuming the response, we need
// to clone it so we have two streams.
var responseToCache = response.clone();
caches.open(CACHE_NAME).then(
function(cache) {
cache.put(event.request, responseToCache);
}
);
return response;
}
);
}
}
)
);
});

1 change: 1 addition & 0 deletions web3.min.js.map

Large diffs are not rendered by default.

0 comments on commit 09d0df0

Please sign in to comment.