Skip to content

Commit

Permalink
rebase:
Browse files Browse the repository at this point in the history
- add tari-tower animation lib
- remove old build files
- update imports and uses
- implement complete canvas removal
- update workflows to include setting up npm credentials
  • Loading branch information
shanimal08 committed Jan 30, 2025
1 parent 332bb9e commit 83f7242
Show file tree
Hide file tree
Showing 30 changed files with 183 additions and 4,977 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
AIRDROP_BASE_URL: http://localhost:4000
AIRDROP_API_BASE_URL: http://localhost:3004
AIRDROP_TWITTER_AUTH_URL: http://localhost:3004/auth/twitter
TELEMETRY_API_URL: http://localhost:3004
TELEMETRY_API_URL: http://localhost:3004
run: |
cargo install cargo-lints
cargo lints clippy --all-targets --all-features
Expand Down Expand Up @@ -115,6 +115,11 @@ jobs:
with:
node-version: lts/*
cache: 'npm'
- name: Set up NPM credentials
run: |
printf -- "//npm.pkg.github.com/:_authToken=${PACKAGE_TOKEN}\n@tari-labs:registry=https://npm.pkg.github.com" > .npmrc
env:
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
- name: Install dependencies (node)
run: npm ci
- uses: dtolnay/rust-toolchain@stable
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ jobs:
with:
cache: 'npm'
node-version: lts/*
- name: Set up NPM credentials
run: |
printf -- "//npm.pkg.github.com/:_authToken=${PACKAGE_TOKEN}\n@tari-labs:registry=https://npm.pkg.github.com" > .npmrc
env:
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
- name: Install Node.js dependencies
run: npm ci
- name: check lint/prettier errors
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ jobs:
./tauri.windows.conf.json
cat ./tauri.windows.conf.json
cargo install [email protected] --locked
- name: Set up NPM credentials
run: |
printf -- "//npm.pkg.github.com/:_authToken=${PACKAGE_TOKEN}\n@tari-labs:registry=https://npm.pkg.github.com" > .npmrc
env:
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
- name: Install Dependencies - Node
run: |
npm --version
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@tari-labs:registry=https://npm.pkg.github.com
71 changes: 3 additions & 68 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
crossorigin
/>

<script type="module" crossorigin src="/assets/glApp.js"></script>
<title>Tari Universe | Testnet</title>
<style>
/* Poppins Font Faces */
Expand Down Expand Up @@ -182,78 +181,14 @@
padding: 0;
margin: 0;
}

#canvas {
#tower-canvas {
position: absolute;
pointer-events: auto;
}
</style>
</head>
<body>
<main id="main">
<div id="root"></div>
<canvas id="canvas"></canvas>
<script type="module" src="src/main.tsx"></script>
<script>
let time;
let lastRender;
let targetFPS = 40;
let frameInterval = 1 / targetFPS;

function preload() {
glApp.preload(
{
canvas: document.getElementById('canvas'),
orbitTarget: document.getElementById('canvas'),
ASSETS_PATH: '/assets/',
},
() => {
init();
}
);
}

function init() {
glApp.init();
time = performance.now() / 1000;
lastRender = time;
window.addEventListener('resize', onResize);

onResize();
animate();
}

function animate() {
let newTime = performance.now() / 1000;
let dt = newTime - time;
if (newTime - lastRender >= frameInterval) {
lastRender = newTime;
update(dt);
time = newTime;
}

requestAnimationFrame(animate);
}

function update(dt) {
glApp.render(dt);
}

function onResize() {
const sidebarOffset = 348 + 20; // sidebar + padding
glApp.properties.cameraOffsetX = sidebarOffset / window.innerWidth;
glApp.setSize(window.innerWidth, window.innerHeight);
}

document.addEventListener('DOMContentLoaded', () => {
if (!window.WebGL2RenderingContext && !window.WebGLRenderingContext) {
console.error('WebGL not supported!');
return;
}

preload();
});
</script>
</main>
<div id="root"></div>
<script type="module" src="src/main.tsx"></script>
</body>
</html>
51 changes: 51 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@floating-ui/react": "^0.26.28",
"@lottiefiles/dotlottie-react": "^0.12.0",
"@sentry/react": "^8.48.0",
"@tari-labs/tari-tower": "^0.0.11",
"@tauri-apps/api": "^2.2.0",
"@tauri-apps/plugin-clipboard-manager": "^2.2.0",
"@tauri-apps/plugin-os": "^2.2.0",
Expand Down Expand Up @@ -72,4 +73,4 @@
"typescript-eslint": "^8.19.1",
"vite": "^5.4.14"
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
4,732 changes: 0 additions & 4,732 deletions public/assets/glApp.js

This file was deleted.

File renamed without changes
File renamed without changes.
File renamed without changes
8 changes: 0 additions & 8 deletions public/assets/textures/LICENSES.txt

This file was deleted.

9 changes: 7 additions & 2 deletions src/App/AppWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { fetchAppConfig } from '../store/useAppConfigStore.ts';
import setupLogger from '../utils/shared-logger.ts';
import useListenForCriticalProblem from '@app/hooks/useListenForCriticalProblem.tsx';
import { setMiningNetwork } from '@app/store/miningStoreActions.ts';
import { loadTowerAnimation } from '@tari-labs/tari-tower';
import { sidebarTowerOffset } from '@app/store/useUIStore.ts';
import App from './App.tsx';

// FOR ANYTHING THAT NEEDS TO BE INITIALISED

setupLogger();

export default function AppWrapper() {
useDetectMode();
useDisableRefresh();
Expand All @@ -20,7 +22,10 @@ export default function AppWrapper() {

useEffect(() => {
async function initialize() {
await fetchAppConfig();
const config = await fetchAppConfig();
if (config?.visual_mode) {
loadTowerAnimation('tower-canvas', sidebarTowerOffset);
}
await setMiningNetwork();
}
void initialize();
Expand Down
41 changes: 31 additions & 10 deletions src/containers/main/Dashboard/components/VisualMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
import { ToggleSwitch } from '@app/components/elements/ToggleSwitch.tsx';
import { useAppConfigStore } from '@app/store/useAppConfigStore';
import { useUIStore } from '@app/store/useUIStore';
import { setVisualMode, useAppConfigStore } from '@app/store/useAppConfigStore';
import { sidebarTowerOffset, useUIStore } from '@app/store/useUIStore';
import { Typography } from '@app/components/elements/Typography';
import {
SettingsGroup,
Expand All @@ -13,23 +13,41 @@ import {
SettingsGroupWrapper,
} from '@app/containers/floating/Settings/components/SettingsGroup.styles';

import { loadTowerAnimation, removeTowerAnimation, setAnimationState } from '@tari-labs/tari-tower';

export const ErrorTypography = styled(Typography)(({ theme }) => ({
color: theme.palette.error.main,
}));

function VisualMode() {
const visualMode = useAppConfigStore((s) => s.visual_mode);
const setVisualMode = useAppConfigStore((s) => s.setVisualMode);
const visualModeToggleLoading = useAppConfigStore((s) => s.visualModeToggleLoading);
const isWebglNotSupported = useUIStore((s) => s.isWebglNotSupported);
const { t } = useTranslation('settings', { useSuspense: false });

const handleDisable = useCallback(() => {
const canvas = document.getElementById('tower-canvas');
if (canvas) {
canvas.style.opacity = '0';
}
setVisualMode(false);
removeTowerAnimation('tower-canvas');
}, []);

const handleEnable = useCallback(() => {
loadTowerAnimation('tower-canvas', sidebarTowerOffset).then(() => {
setVisualMode(true);
setAnimationState('showVisual');
});
}, []);

const handleSwitch = useCallback(() => {
const canvasElement = document.getElementById('canvas');
if (canvasElement) {
canvasElement.style.display = visualMode ? 'none' : 'block';
if (visualMode) {
handleDisable();
} else {
handleEnable();
}
setVisualMode(!visualMode);
}, [setVisualMode, visualMode]);
}, [handleDisable, handleEnable, visualMode]);

return (
<SettingsGroupWrapper>
Expand All @@ -41,11 +59,14 @@ function VisualMode() {
{isWebglNotSupported && <ErrorTypography color="error">{t('webgl-not-supported')}</ErrorTypography>}
</SettingsGroupContent>
<SettingsGroupAction style={{ alignItems: 'center' }}>
<ToggleSwitch disabled={isWebglNotSupported} checked={visualMode} onChange={handleSwitch} />
<ToggleSwitch
disabled={visualModeToggleLoading || isWebglNotSupported}
checked={visualMode}
onChange={handleSwitch}
/>
</SettingsGroupAction>
</SettingsGroup>
</SettingsGroupWrapper>
);
}

export default VisualMode;
Loading

0 comments on commit 83f7242

Please sign in to comment.