Skip to content

Commit

Permalink
Merge branch 'fb-view-wallet-ui-186336176' into ui
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbartnik committed Nov 7, 2023
2 parents 77f21ba + 15497dd commit 121f456
Show file tree
Hide file tree
Showing 83 changed files with 15,145 additions and 6,439 deletions.
7 changes: 5 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
plugins: [
'@typescript-eslint',
'only-warn'
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
};
};
39 changes: 15 additions & 24 deletions apps/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"composite": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"paths": {
"@xai-vanguard-node/core": ["../../packages/core"]
}
},
"include": [
"src/"
],
"exclude": ["node_modules"],
"references": [
{
"path": "../../packages/core"
}
]
}
"extends": "../../packages/tsconfig/tsconfig.base.json",
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
"rootDir": "src",
"outDir": "dist",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@vanguard-node/*": ["../../packages/*/src"]
}
},

}
8 changes: 7 additions & 1 deletion apps/vanguard-client-desktop/electron-builder.json5
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,11 @@
"AppImage"
],
"artifactName": "vanguard-client-linux.${ext}"
}
},
"protocols": [
{
name: "Xai Sentry",
schemes: ["xai-sentry"]
}
]
}
54 changes: 52 additions & 2 deletions apps/vanguard-client-desktop/electron/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { app, BrowserWindow, ipcMain, shell, safeStorage } from 'electron'
import os from 'os';
import fs from 'fs';
import path from 'path';
import express from 'express';

const isWindows = os.platform() === "win32";

// The built directory structure
//
// ├─┬─┬ dist
Expand All @@ -19,6 +22,15 @@ let win: BrowserWindow | null
// 🚧 Use ['ENV_NAME'] avoid vite:define plugin - [email protected]
const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL']

const protocolUrl = 'xai-sentry';
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient(protocolUrl, process.execPath, [path.resolve(process.argv[1])]);
}
} else {
app.setAsDefaultProtocolClient(protocolUrl);
}

ipcMain.on('open-external', (_, url) => {
void shell.openExternal(url);
});
Expand Down Expand Up @@ -63,7 +75,6 @@ ipcMain.handle('buffer-from', (_, str, encoding) => {
return Buffer.from(str, encoding);
});


function createWindow() {
win = new BrowserWindow({
width: 1920,
Expand Down Expand Up @@ -119,4 +130,43 @@ app.on('ready', () => {
server.listen(7555);
})

app.whenReady().then(createWindow)
// Windows deep-link
if (isWindows) {
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on('second-instance', (event, commandLine) => {
console.log("event:", event);

// Someone tried to run a second instance, we should focus our window.
if (win) {
if (win.isMinimized()) win.restore();
win.focus();
}
// the commandLine is array of strings in which last element is deep link url
// dialog.showErrorBox('Welcome Back', `You arrived from: ${commandLine.pop()}`);
win?.webContents.send("assigned-wallet", commandLine.pop());
})

// Create mainWindow, load the rest of the app, etc...
app.whenReady().then(createWindow);
}
} else {
// Mac deep-link
app.whenReady().then(createWindow);
app.on('open-url', (event, url) => {
console.log("event:", event);

const fullProtocol = "xai-sentry://";
const instruction = url.slice(fullProtocol.length, url.indexOf("?"));

switch(instruction) {
case "assigned-wallet":
const txHash = url.slice(url.indexOf("=") + 1);
win?.webContents.send("assigned-wallet", txHash);
break;
}
});
}

139 changes: 75 additions & 64 deletions apps/vanguard-client-desktop/electron/preload.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,62 @@
import { contextBridge, ipcRenderer } from 'electron'

import {contextBridge, ipcRenderer} from 'electron';
// import {useSetAtom} from "jotai";
// import {assignedWalletModalAtom} from "../src/components/DeepLinkManager";

// --------- Expose some API to the Renderer process ---------
contextBridge.exposeInMainWorld('ipcRenderer', withPrototype(ipcRenderer))

contextBridge.exposeInMainWorld(
'electron',
{
openExternal: (url: string) => ipcRenderer.send('open-external', url),
}
'electron',
{
openExternal: (url: string) => ipcRenderer.send('open-external', url),
}
);

// `exposeInMainWorld` can't detect attributes and methods of `prototype`, manually patching it.
function withPrototype(obj: Record<string, any>) {
const protos = Object.getPrototypeOf(obj)

for (const [key, value] of Object.entries(protos)) {
if (Object.prototype.hasOwnProperty.call(obj, key)) continue

if (typeof value === 'function') {
// Some native APIs, like `NodeJS.EventEmitter['on']`, don't work in the Renderer process. Wrapping them into a function.
obj[key] = function (...args: any) {
return value.call(obj, ...args)
}
} else {
obj[key] = value
}
}
return obj
const protos = Object.getPrototypeOf(obj)

for (const [key, value] of Object.entries(protos)) {
if (Object.prototype.hasOwnProperty.call(obj, key)) continue

if (typeof value === 'function') {
// Some native APIs, like `NodeJS.EventEmitter['on']`, don't work in the Renderer process. Wrapping them into a function.
obj[key] = function (...args: any) {
return value.call(obj, ...args)
}
} else {
obj[key] = value
}
}
return obj
}

// --------- Preload scripts loading ---------
function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {
return new Promise(resolve => {
if (condition.includes(document.readyState)) {
resolve(true)
} else {
document.addEventListener('readystatechange', () => {
if (condition.includes(document.readyState)) {
resolve(true)
}
})
}
})
return new Promise(resolve => {
if (condition.includes(document.readyState)) {
resolve(true)
} else {
document.addEventListener('readystatechange', () => {
if (condition.includes(document.readyState)) {
resolve(true)
}
})
}
})
}

const safeDOM = {
append(parent: HTMLElement, child: HTMLElement) {
if (!Array.from(parent.children).find(e => e === child)) {
parent.appendChild(child)
}
},
remove(parent: HTMLElement, child: HTMLElement) {
if (Array.from(parent.children).find(e => e === child)) {
parent.removeChild(child)
}
},
append(parent: HTMLElement, child: HTMLElement) {
if (!Array.from(parent.children).find(e => e === child)) {
parent.appendChild(child)
}
},
remove(parent: HTMLElement, child: HTMLElement) {
if (Array.from(parent.children).find(e => e === child)) {
parent.removeChild(child)
}
},
}

/**
Expand All @@ -65,8 +66,8 @@ const safeDOM = {
* https://matejkustec.github.io/SpinThatShit
*/
function useLoading() {
const className = `loaders-css__square-spin`
const styleContent = `
const className = `loaders-css__square-spin`
const styleContent = `
@keyframes square-spin {
25% { transform: perspective(100px) rotateX(180deg) rotateY(0); }
50% { transform: perspective(100px) rotateX(180deg) rotateY(180deg); }
Expand Down Expand Up @@ -94,34 +95,44 @@ function useLoading() {
}
`

const oStyle = document.createElement('style')
const oDiv = document.createElement('div')

oStyle.id = 'app-loading-style'
oStyle.innerHTML = styleContent
oDiv.className = 'app-loading-wrap'
oDiv.innerHTML = `<div class="${className}"><div></div></div>`

return {
appendLoading() {
safeDOM.append(document.head, oStyle)
safeDOM.append(document.body, oDiv)
},
removeLoading() {
safeDOM.remove(document.head, oStyle)
safeDOM.remove(document.body, oDiv)
},
}
const oStyle = document.createElement('style')
const oDiv = document.createElement('div')

oStyle.id = 'app-loading-style'
oStyle.innerHTML = styleContent
oDiv.className = 'app-loading-wrap'
oDiv.innerHTML = `<div class="${className}"><div></div></div>`

return {
appendLoading() {
safeDOM.append(document.head, oStyle)
safeDOM.append(document.body, oDiv)
},
removeLoading() {
safeDOM.remove(document.head, oStyle)
safeDOM.remove(document.body, oDiv)
},
}
}

// ----------------------------------------------------------------------

const { appendLoading, removeLoading } = useLoading()
const {appendLoading, removeLoading} = useLoading();
domReady().then(appendLoading)

window.onmessage = ev => {
ev.data.payload === 'removeLoading' && removeLoading()
ev.data.payload === 'removeLoading' && removeLoading()
}

setTimeout(removeLoading, 4999)

contextBridge.exposeInMainWorld('deeplinks', {
assignedWallet: (callback: (_event, txHash) => void) => ipcRenderer.on("assigned-wallet", callback),
});

// ipcRenderer.on("test", (event, url) => {
// const setAssignedWalletModalState = useSetAtom(assignedWalletModalAtom);
// console.log(event);
// // alert(url);
// setAssignedWalletModalState(url);
// });
4 changes: 3 additions & 1 deletion apps/vanguard-client-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
"version": "0.1.0",
"scripts": {
"dev": "vite",
"clean": "rimraf dist && rimraf dist-electron && rimraf release && rimraf tsconfig.tsbuildinfo && rimraf vite.config.js && rimraf vite.config.d.ts",
"clean": "rimraf dist && rimraf dist-electron && rimraf release && rimraf public/web && rimraf tsconfig.tsbuildinfo && rimraf vite.config.js && rimraf vite.config.d.ts",
"build": "tsc --build && vite build && electron-builder",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@xai-vanguard-node/core": "workspace:*",
"@xai-vanguard-node/ui": "workspace:*",
"@xai-vanguard-node/web-connect": "workspace:*",
"classnames": "^2.3.2",
"crypto-js": "4.1.1",
"express": "^4.18.2",
Expand All @@ -36,6 +37,7 @@
"electron": "^26.1.0",
"electron-builder": "^24.6.4",
"eslint": "^8.48.0",
"eslint-plugin-only-warn": "^1.1.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"vite": "^4.4.9",
Expand Down
Loading

0 comments on commit 121f456

Please sign in to comment.