chore: small refactor using CVA
This commit is contained in:
parent
057b3c1e53
commit
4d0f13a197
|
@ -1,25 +1,21 @@
|
||||||
import * as Dialog from "@radix-ui/react-dialog"
|
import * as Dialog from "@radix-ui/react-dialog"
|
||||||
import { Chain, useLume } from "../LumeProvider"
|
import { Chain, useLume } from "../LumeProvider"
|
||||||
import Logo from "../../../assets/lume-logo.png";
|
import Logo from "../../../assets/lume-logo.png"
|
||||||
|
import { cva } from "class-variance-authority"
|
||||||
|
import { cn } from "../../utils"
|
||||||
|
|
||||||
const SYNCSTATE_TO_TEXT: Record<Chain['syncState'], string> = {
|
|
||||||
done: 'Synced',
|
const SYNCSTATE_TO_TEXT: Record<Chain["syncState"], string> = {
|
||||||
error: 'Issue',
|
done: "Synced",
|
||||||
syncing: 'Syncing'
|
error: "Issue",
|
||||||
|
syncing: "Syncing"
|
||||||
}
|
}
|
||||||
|
|
||||||
const SYNC_STATE_TO_TW_COLOR: Record<Chain['syncState'], string> = {
|
|
||||||
'done': 'text-primary',
|
|
||||||
'error': 'text-red-500',
|
|
||||||
'syncing': 'text-orange-500',
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const LumeDashboard = () => {
|
const LumeDashboard = () => {
|
||||||
const { chains } = useLume()
|
const { chains } = useLume()
|
||||||
|
|
||||||
const contentChains = chains.filter(c => c.type === 'content');
|
const contentChains = chains.filter((c) => c.type === "content")
|
||||||
const blockchainChains = chains.filter(c => c.type === 'blockchain');
|
const blockchainChains = chains.filter((c) => c.type === "blockchain")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog.Root>
|
<Dialog.Root>
|
||||||
|
@ -33,14 +29,24 @@ const LumeDashboard = () => {
|
||||||
<div className="mt-4 mb-8">
|
<div className="mt-4 mb-8">
|
||||||
<h2 className="text-xl mb-4"> Content </h2>
|
<h2 className="text-xl mb-4"> Content </h2>
|
||||||
<div className="grid grid-cols-2">
|
<div className="grid grid-cols-2">
|
||||||
{contentChains.map((chain, index) => <ChainIndicator key={`Content_ChainIndicator_${index}`} chain={chain} />)}
|
{contentChains.map((chain, index) => (
|
||||||
|
<ChainIndicator
|
||||||
|
key={`Content_ChainIndicator_${index}`}
|
||||||
|
chain={chain}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-4 mb-8">
|
<div className="mt-4 mb-8">
|
||||||
<h2 className="text-xl mb-4"> Blockchain </h2>
|
<h2 className="text-xl mb-4"> Blockchain </h2>
|
||||||
<div className="grid grid-cols-2">
|
<div className="grid grid-cols-2">
|
||||||
{blockchainChains.map((chain, index) => <ChainIndicator key={`Blockchain_ChainIndicator_${index}`} chain={chain} />)}
|
{blockchainChains.map((chain, index) => (
|
||||||
|
<ChainIndicator
|
||||||
|
key={`Blockchain_ChainIndicator_${index}`}
|
||||||
|
chain={chain}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Dialog.Content>
|
</Dialog.Content>
|
||||||
|
@ -49,14 +55,29 @@ const LumeDashboard = () => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const chainIndicatorVariant = cva("chainIndicatorVariant", {
|
||||||
|
variants: {
|
||||||
|
syncState: {
|
||||||
|
done: "text-primary",
|
||||||
|
error: "text-red-500",
|
||||||
|
syncing: "text-orange-500"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
const ChainIndicator = ({ chain }: { chain: Chain }) => {
|
const ChainIndicator = ({ chain }: { chain: Chain }) => {
|
||||||
return <div key={chain.chainId} className="flex flex-row gap-x-2 items-center ">
|
return (
|
||||||
<CircularProgress chain={chain} />
|
<div key={chain.chainId} className="flex flex-row gap-x-2 items-center ">
|
||||||
<div className="flex flex-col">
|
<CircularProgress chain={chain} />
|
||||||
<span>{chain.name}</span>
|
<div className="flex flex-col">
|
||||||
<span className={`text-[12px] -mt-1 ${SYNC_STATE_TO_TW_COLOR[chain.syncState]}`}> {SYNCSTATE_TO_TEXT[chain.syncState]} </span>
|
<span>{chain.name}</span>
|
||||||
|
<span
|
||||||
|
className={cn(['text-[12px] -mt-1', chainIndicatorVariant({syncState: chain.syncState})])}
|
||||||
|
>
|
||||||
|
{SYNCSTATE_TO_TEXT[chain.syncState]}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const CircularProgress = ({
|
const CircularProgress = ({
|
||||||
|
@ -71,7 +92,7 @@ const CircularProgress = ({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<svg
|
<svg
|
||||||
className={`${className} ${SYNC_STATE_TO_TW_COLOR[chain.syncState]}`}
|
className={cn([className, chainIndicatorVariant({syncState: chain.syncState})])}
|
||||||
width="36"
|
width="36"
|
||||||
height="36"
|
height="36"
|
||||||
viewBox="0 0 100 100"
|
viewBox="0 0 100 100"
|
||||||
|
|
|
@ -8,9 +8,7 @@ import { LumeIdentityContext, Session } from './LumeIdentityContext';
|
||||||
import { LazyMotion, domAnimation } from 'framer-motion';
|
import { LazyMotion, domAnimation } from 'framer-motion';
|
||||||
import * as Dialog from '@radix-ui/react-dialog';
|
import * as Dialog from '@radix-ui/react-dialog';
|
||||||
|
|
||||||
type Props = {}
|
const LumeIdentity: React.FC = () => {
|
||||||
|
|
||||||
const LumeIdentity: React.FC<Props> = ({}) => {
|
|
||||||
const { visibleComponent, setVisibleComponent } = useSwitchableComponent(ComponentList.SubmitButton)
|
const { visibleComponent, setVisibleComponent } = useSwitchableComponent(ComponentList.SubmitButton)
|
||||||
|
|
||||||
const isSubmitButtonInView = [ComponentList.SubmitButton.index].includes(visibleComponent.index)
|
const isSubmitButtonInView = [ComponentList.SubmitButton.index].includes(visibleComponent.index)
|
||||||
|
@ -81,4 +79,4 @@ export default function Wrapped() {
|
||||||
</Dialog.Portal>
|
</Dialog.Portal>
|
||||||
</Dialog.Root>
|
</Dialog.Root>
|
||||||
</LumeIdentityContext.Provider>
|
</LumeIdentityContext.Provider>
|
||||||
};
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import React from "react";
|
||||||
import { useLumeIndentity } from "./LumeIdentityContext";
|
import { useLumeIndentity } from "./LumeIdentityContext";
|
||||||
|
|
||||||
// Extracted components
|
// Extracted components
|
||||||
const SubmitButtonComponent = ({ }) => {
|
const SubmitButtonComponent = () => {
|
||||||
const { setVisibleComponent } = useSwitchableComponent();
|
const { setVisibleComponent } = useSwitchableComponent();
|
||||||
return (
|
return (
|
||||||
<Button className='w-full h-12' variant={"outline"} onClick={() => setVisibleComponent(components.SeedPhraseInput)}>
|
<Button className='w-full h-12' variant={"outline"} onClick={() => setVisibleComponent(components.SeedPhraseInput)}>
|
||||||
|
@ -16,7 +16,7 @@ const SubmitButtonComponent = ({ }) => {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
const SeedPhraseInputComponent = ({ }) => {
|
const SeedPhraseInputComponent = () => {
|
||||||
const { signIn } = useLumeIndentity();
|
const { signIn } = useLumeIndentity();
|
||||||
return (
|
return (
|
||||||
<m.form className='flex-col flex gap-y-4' onSubmit={(e) => {
|
<m.form className='flex-col flex gap-y-4' onSubmit={(e) => {
|
||||||
|
@ -57,7 +57,7 @@ const SetupAccountKeyComponent = () => {
|
||||||
transition={{ type: "just", delay: 0.1 }}
|
transition={{ type: "just", delay: 0.1 }}
|
||||||
className="min-h-12 h-full max-w-full"
|
className="min-h-12 h-full max-w-full"
|
||||||
style={{ maxWidth: width ?? 'auto' }}
|
style={{ maxWidth: width ?? 'auto' }}
|
||||||
ref={(t) => setTimeout(() => setWidth(t?.getBoundingClientRect().width!), 0)}
|
ref={(t) => setTimeout(() => setWidth(t!.getBoundingClientRect().width!), 0)}
|
||||||
>
|
>
|
||||||
<Button className='w-full h-full' onClick={() => setVisibleComponent(components.SeedPhraseGeneration)}>
|
<Button className='w-full h-full' onClick={() => setVisibleComponent(components.SeedPhraseGeneration)}>
|
||||||
<span className="text-center text-lg font-normal leading-normal">I get it, I'll keep it safe. Let's see the key.</span>
|
<span className="text-center text-lg font-normal leading-normal">I get it, I'll keep it safe. Let's see the key.</span>
|
||||||
|
|
|
@ -22,10 +22,10 @@
|
||||||
"noUnusedParameters": true,
|
"noUnusedParameters": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
// "paths": {
|
||||||
"@/*": ["src/*"],
|
// "@/*": ["src/*"],
|
||||||
"@/styles/*": ["styles/*"],
|
// "@/styles/*": ["styles/*"],
|
||||||
},
|
// },
|
||||||
"typeRoots": ["src/vite-env.d.ts"]
|
"typeRoots": ["src/vite-env.d.ts"]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react'
|
||||||
// import scopeTailwind from "vite-plugin-scope-tailwind";
|
import scopeTailwind from "vite-plugin-scope-tailwind";
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
// import reactTailwindClassnamePrefixer from "./lib/vite-plugin-react-classname-prefixer";
|
// import reactTailwindClassnamePrefixer from "./lib/vite-plugin-react-classname-prefixer";
|
||||||
import svgr from "vite-plugin-svgr";
|
import svgr from "vite-plugin-svgr";
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [svgr(), react()],
|
plugins: [svgr(), react(), scopeTailwind({react: true})],
|
||||||
resolve: {
|
resolve: {
|
||||||
|
// I have no clue why aliases are not working at all...
|
||||||
alias: {
|
alias: {
|
||||||
'@/styles/': resolve(__dirname, './styles'),
|
'@styles/': resolve(__dirname, './styles'),
|
||||||
'@/': resolve(__dirname, './src'),
|
'@components/': resolve(__dirname, './src/components'),
|
||||||
|
'@assets/': resolve(__dirname, './src/assets'),
|
||||||
|
'@': resolve(__dirname, './src'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue