chore(ui-toolkit): add pseudo random instead Math.random (#2997)
This commit is contained in:
parent
4e2b6b2d04
commit
94509a29c5
@ -12,7 +12,7 @@ import type { ReactNode } from 'react';
|
|||||||
import { AppFailure } from './app-failure';
|
import { AppFailure } from './app-failure';
|
||||||
import { Web3Provider } from './web3-provider';
|
import { Web3Provider } from './web3-provider';
|
||||||
|
|
||||||
const DynamicLoader = dynamic(() => import('../preloader/preloader'), {
|
export const DynamicLoader = dynamic(() => import('../preloader/preloader'), {
|
||||||
loading: () => <>Loading...</>,
|
loading: () => <>Loading...</>,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ import { Connectors } from '../lib/vega-connectors';
|
|||||||
import { ViewingBanner } from '../components/viewing-banner';
|
import { ViewingBanner } from '../components/viewing-banner';
|
||||||
import { Banner } from '../components/banner';
|
import { Banner } from '../components/banner';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { AppLoader } from '../components/app-loader';
|
import { AppLoader, DynamicLoader } from '../components/app-loader';
|
||||||
|
|
||||||
const DEFAULT_TITLE = t('Welcome to Vega trading!');
|
const DEFAULT_TITLE = t('Welcome to Vega trading!');
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ function VegaTradingApp(props: AppProps) {
|
|||||||
// Prevent HashRouter from being server side rendered as it
|
// Prevent HashRouter from being server side rendered as it
|
||||||
// relies on presence of document object
|
// relies on presence of document object
|
||||||
if (status === 'default') {
|
if (status === 'default') {
|
||||||
return null;
|
return <DynamicLoader />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -12,6 +12,8 @@ export default function Document() {
|
|||||||
type="font/woff2"
|
type="font/woff2"
|
||||||
crossOrigin="anonymous"
|
crossOrigin="anonymous"
|
||||||
/>
|
/>
|
||||||
|
{/* eslint-disable-next-line @next/next/no-css-tags */}
|
||||||
|
<link rel="stylesheet" href="/preloader.css" media="all" />
|
||||||
<link
|
<link
|
||||||
rel="icon"
|
rel="icon"
|
||||||
type="image/x-icon"
|
type="image/x-icon"
|
||||||
|
106
apps/trading/public/preloader.css
Normal file
106
apps/trading/public/preloader.css
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
.pre-loader {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 100vh;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(0) {
|
||||||
|
animation-delay: 0ms;
|
||||||
|
animation-direction: reverse;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:first-child {
|
||||||
|
animation-delay: -0.2s;
|
||||||
|
animation-direction: alternate;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(2) {
|
||||||
|
animation-delay: 0.1s;
|
||||||
|
animation-direction: reverse;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(3) {
|
||||||
|
animation-delay: -0.15s;
|
||||||
|
animation-direction: alternate;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(4) {
|
||||||
|
animation-delay: 1s;
|
||||||
|
animation-direction: reverse;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(5) {
|
||||||
|
animation-delay: -0.25s;
|
||||||
|
animation-direction: alternate;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(6) {
|
||||||
|
animation-delay: 0.3s;
|
||||||
|
animation-direction: reverse;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(7) {
|
||||||
|
animation-delay: -1.05s;
|
||||||
|
animation-direction: alternate;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(8) {
|
||||||
|
animation-delay: 0.8s;
|
||||||
|
animation-direction: reverse;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(9) {
|
||||||
|
animation-delay: -0.9s;
|
||||||
|
animation-direction: alternate;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(10) {
|
||||||
|
animation-delay: 0.5s;
|
||||||
|
animation-direction: reverse;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(11) {
|
||||||
|
animation-delay: -2.75s;
|
||||||
|
animation-direction: alternate;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(12) {
|
||||||
|
animation-delay: 2.4s;
|
||||||
|
animation-direction: reverse;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(13) {
|
||||||
|
animation-delay: -0.65s;
|
||||||
|
animation-direction: alternate;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(14) {
|
||||||
|
animation-delay: 0.7s;
|
||||||
|
animation-direction: reverse;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(15) {
|
||||||
|
animation-delay: -3s;
|
||||||
|
animation-direction: alternate;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item:nth-child(16) {
|
||||||
|
animation-delay: 2.4s;
|
||||||
|
animation-direction: reverse;
|
||||||
|
}
|
||||||
|
.pre-loader .pre-loader-center {
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.pre-loader .pre-loader-wrapper {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
.pre-loader .loader-item {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
background: #000;
|
||||||
|
animation: flickering 0.4s steps(2, jump-none) infinite alternate;
|
||||||
|
}
|
||||||
|
@keyframes flickering {
|
||||||
|
0% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
25% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
26% {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,13 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
|
|
||||||
|
const pseudoRandom = (seed: number) => {
|
||||||
|
let value = seed;
|
||||||
|
return () => {
|
||||||
|
value = (value * 16807) % 2147483647;
|
||||||
|
return value / 1000000000;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export interface LoaderProps {
|
export interface LoaderProps {
|
||||||
size?: 'small' | 'large';
|
size?: 'small' | 'large';
|
||||||
@ -35,6 +43,8 @@ export const Loader = ({
|
|||||||
size === 'small' ? 'w-[15px] h-[15px]' : 'w-[50px] h-[50px]';
|
size === 'small' ? 'w-[15px] h-[15px]' : 'w-[50px] h-[50px]';
|
||||||
const items = size === 'small' ? 9 : 16;
|
const items = size === 'small' ? 9 : 16;
|
||||||
|
|
||||||
|
const generate = useMemo(() => pseudoRandom(1), []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="flex flex-col items-center pre-loader-center"
|
className="flex flex-col items-center pre-loader-center"
|
||||||
@ -47,7 +57,7 @@ export const Loader = ({
|
|||||||
className={itemClasses}
|
className={itemClasses}
|
||||||
key={i}
|
key={i}
|
||||||
style={{
|
style={{
|
||||||
opacity: Math.random() > 0.75 ? 1 : 0,
|
opacity: generate() > 1.5 ? 1 : 0,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user