Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from BTS-CM/context_isolation
Browse files Browse the repository at this point in the history
Context isolation
  • Loading branch information
grctest authored Aug 16, 2023
2 parents 0f98074 + c630081 commit fd0a2b9
Show file tree
Hide file tree
Showing 169 changed files with 932 additions and 5,499 deletions.
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"type": "git",
"url": "git+https://github.com/BTS-CM/NFT_Viewer.git"
},
"license": "ISC",
"license": "MIT",
"bugs": {
"url": "https://github.com/BTS-CM/NFT_Viewer/issues"
},
Expand Down Expand Up @@ -48,45 +48,45 @@
}
},
"dependencies": {
"@babel/core": "^7.22.9",
"@babel/core": "^7.22.10",
"@emotion/react": "^11.11.1",
"@mantine/carousel": "^6.0.17",
"@mantine/core": "^6.0.17",
"@mantine/form": "^6.0.17",
"@mantine/hooks": "^6.0.17",
"@vitejs/plugin-react": "^4.0.3",
"@mantine/carousel": "^6.0.19",
"@mantine/core": "^6.0.19",
"@mantine/form": "^6.0.19",
"@mantine/hooks": "^6.0.19",
"@vitejs/plugin-react": "^4.0.4",
"assert": "^2.0.0",
"beet-js": "https://github.com/bitshares/beet-js#develop",
"bitsharesjs": "https://github.com/bitshares/bitsharesjs#develop",
"bitsharesjs-ws": "^6.0.0",
"buffer": "^6.0.3",
"embla-carousel-react": "^7.1.0",
"esbuild-plugin-polyfill-node": "^0.3.0",
"events": "^3.3.0",
"i18next": "^23.3.0",
"i18next": "^23.4.4",
"process": "^0.11.10",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-i18next": "^13.0.2",
"react-i18next": "^13.1.2",
"react-icons": "^4.10.1",
"react-qrcode-logo": "^2.9.0",
"react-router-dom": "^6.14.2",
"react-router-dom": "^6.15.0",
"simple-websocket": "^9.1.0",
"stream-browserify": "^3.0.0",
"util": "^0.12.5",
"uuid": "^9.0.0",
"vite": "^4.4.7",
"zustand": "^4.3.9"
"vite": "^4.4.9",
"zustand": "^4.4.1"
},
"devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"concurrently": "^8.2.0",
"cross-env": "^7.0.3",
"electron": "^25.3.2",
"electron": "^26.0.0",
"electron-builder": "^24.6.3",
"electronmon": "^2.0.2",
"esbuild": "^0.18.17",
"esbuild": "^0.19.2",
"vite-plugin-electron": "^0.12.0",
"vite-plugin-i18next-loader": "^2.0.4",
"wait-on": "^7.0.1"
},
"browserslist": {
Expand Down
247 changes: 202 additions & 45 deletions public/electron.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,53 @@
const { app, BrowserWindow, ipcMain, shell } = require('electron');
const path = require('path');
const url = require("url");
const url = require('url');
const { v4: uuidv4 } = require('uuid');
//import BeetConnection from 'beet-js/src/lib/BeetConnection';
//const { BeetConnection } = require('beet-js/src/lib/BeetConnection');

const {
fetchUserNFTBalances,
fetchIssuedAssets,
fetchAssets,
fetchObject,
fetchDynamicData,
fetchOrderBook,
accountSearch
} = require('../src/lib/queries');

const {
beetBroadcast,
generateDeepLink,
generateQRContents
} = require('../src/preload/generate');

let allowed = {
"gallery": "https://nftea.gallery/gallery",
"viewer": "https://github.com/BTS-CM/NFT_Viewer",
"beet": "https://github.com/bitshares/beet/releases",
"airdrop": "https://github.com/BTS-CM/airdrop_tool",
"nft_tool": "https://github.com/BTS-CM/Bitshares_NFT_Issuance_Tool",
"gallery": "https://nftea.gallery/gallery",
"ipfs_pinata": "https://www.pinata.cloud/",
"ipfs_nft_storage": "https://nft.storage/",
"ipfs_web3_storage": "https://web3.storage/",
"ipfs_fleek": "https://fleek.co/ipfs-gateway/",
"ipfs_infura": "https://infura.io/product/ipfs",
"ipfs_storj": "https://landing.storj.io/permanently-pin-with-storj-dcs",
"ipfs_eternum": "https://www.eternum.io/",
"ipfs_docs": "https://blog.ipfs.io/2021-04-05-storing-nfts-on-ipfs/",
"nft_spec": "https://github.com/Bit20-Creative-Group/BitShares-NFT-Specification"
}

const createWindow = () => {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
enableRemoteModule:true,
contextIsolation:false,
nodeIntegration: false,
enableRemoteModule: false,
contextIsolation: true,
preload: path.join(__dirname, "preload.js"),
partition: 'persist:nft_viewer'
}
Expand All @@ -31,23 +68,34 @@ const createWindow = () => {
}
}

let allowed = {
"gallery": "https://nftea.gallery/gallery",
"viewer": "https://github.com/BTS-CM/NFT_Viewer",
"beet": "https://github.com/bitshares/beet/releases",
"airdrop": "https://github.com/BTS-CM/airdrop_tool",
"nft_tool": "https://github.com/BTS-CM/Bitshares_NFT_Issuance_Tool",
"gallery": "https://nftea.gallery/gallery",
"ipfs_pinata": "https://www.pinata.cloud/",
"ipfs_nft_storage": "https://nft.storage/",
"ipfs_web3_storage": "https://web3.storage/",
"ipfs_fleek": "https://fleek.co/ipfs-gateway/",
"ipfs_infura": "https://infura.io/product/ipfs",
"ipfs_storj": "https://landing.storj.io/permanently-pin-with-storj-dcs",
"ipfs_eternum": "https://www.eternum.io/",
"ipfs_docs": "https://blog.ipfs.io/2021-04-05-storing-nfts-on-ipfs/",
"nft_spec": "https://github.com/Bit20-Creative-Group/BitShares-NFT-Specification"
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow();

app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})

app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
// On certificate error we disable default behaviour (stop loading the page)
// and we then say "it is all fine - true" to the callback
event.preventDefault();
callback(true);
});
})

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== "darwin") {
app.quit();
}
})

ipcMain.on('openURL', (event, arg) => {
if (allowed.hasOwnProperty(arg)) {
Expand All @@ -73,31 +121,140 @@ ipcMain.on('openDEX', (event, arg) => {
}
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow();
ipcMain.handle('getUUID', async (event, arg) => {
return await uuidv4();
});

app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
ipcMain.handle('fetchUserNFTBalances', async (event, ...args) => {
return await fetchUserNFTBalances(...args);
});

app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
// On certificate error we disable default behaviour (stop loading the page)
// and we then say "it is all fine - true" to the callback
event.preventDefault();
callback(true);
ipcMain.handle('fetchIssuedAssets', async (event, ...args) => {
return await fetchIssuedAssets(...args);
});

ipcMain.handle('fetchAssets', async (event, ...args) => {
return await fetchAssets(...args);
});

ipcMain.handle('fetchObject', async (event, ...args) => {
return await fetchObject(...args);
});

ipcMain.handle('fetchDynamicData', async (event, ...args) => {
return await fetchDynamicData(...args);
});

ipcMain.handle('fetchOrderBook', async (event, ...args) => {
return await fetchOrderBook(...args);
});

ipcMain.handle('accountSearch', async (event, ...args) => {
return await accountSearch(...args);
});

import('beet-js').then((beet) => {
ipcMain.handle('checkBeet', async (event, ...args) => {
console.log('checkBeet')
return await beet.checkBeet(...args);
});
})

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== "darwin") {
app.quit();
}
})
ipcMain.handle('connect', async (event, ...args) => {
console.log('connect')
const connection = await beet.connect(...args);
return JSON.stringify(connection, (key, value) => {
if (key === 'io' || key === 'socket' || key === 'nsp') {
return undefined;
}
return value;
});
});

ipcMain.handle('link', async (event, ...args) => {
if (!args.length) {
console.log(new Error('No arguments provided'));
return;
}

const beetOnline = await beet.checkBeet(true)
if (!beetOnline) {
console.log('Beet is not online');
return;
}

const connection = await beet.connect(
"NFT Viewer",
"Application",
"localhost",
null,
null
);

const chain = args[0] ?? null;
let linkage;
try {
linkage = await beet.link(chain, connection);
} catch (error) {
console.log(error)
return;
}

return JSON.stringify(connection, (key, value) => {
if (key === 'io' || key === 'socket' || key === 'nsp') {
return undefined;
}
return value;
});
});

ipcMain.handle('beetBroadcast', async (event, ...args) => {

const chain = args[0] ?? null;
const node = args[1] ?? null;
const opType = args[2] ?? null;
const operations = args[3] ?? null;
const identity = args[4] ?? null;
const {
beetkey,
next_identification,
secret
} = args[5] ?? null;

const connection = await beet.connect(
"NFT Viewer",
"Application",
"localhost",
null,
identity
);

if (!connection) {
console.log('No connection');
return;
}

connection.beetkey = beetkey;
connection.next_identification = next_identification;
connection.secret = secret;
connection.id = next_identification;

return await beetBroadcast(
connection,
chain,
node,
opType,
operations
);
});

ipcMain.handle('generateDeepLink', async (event, ...args) => {
return await generateDeepLink(...args);
});

ipcMain.handle('generateQRContents', async (event, ...args) => {
return await generateQRContents(...args);
});

}).catch((err) => {
console.error(err);
});
Loading

0 comments on commit fd0a2b9

Please sign in to comment.