Skip to content

Commit

Permalink
add mech loading gif
Browse files Browse the repository at this point in the history
  • Loading branch information
samepant committed Jan 23, 2024
1 parent 147446d commit d76944f
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 41 deletions.
Binary file added frontend/public/loading-short.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions frontend/src/components/Connect/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from "react"
import useWalletConnect, { Session } from "../../hooks/useWalletConnect"
import Spinner from "../Spinner"
import Loading from "../Loading"

import classes from "./Connect.module.css"
import Button from "../Button"
Expand Down Expand Up @@ -44,7 +44,7 @@ const MechConnect: React.FC = () => {
placeholder="wc:9e5b70f5-ddef-4403-999e-"
/>
</div>
{loading && <Spinner />}
{loading && <Loading />}

{sessions.length > 0 && (
<>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Deploy/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react"
import Spinner from "../Spinner"
import Loading from "../Loading"

import classes from "./Deploy.module.css"
import Button from "../Button"
Expand All @@ -18,7 +18,7 @@ const MechDeploy: React.FC<Props> = ({ deployPending, deploy }) => {
<Button onClick={deploy} disabled={deployPending}>
{deployPending ? (
<>
<Spinner /> Deploying...
<Loading /> Deploying...
</>
) : (
"Deploy"
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/components/Loading/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react"

import classes from "./style.module.css"

const Loading: React.FC = () => (
<div className={classes.container}>
<img src="/loading-short.gif" alt="Loading" />
</div>
)

export default Loading
10 changes: 10 additions & 0 deletions frontend/src/components/Loading/style.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.container {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}

.container img {
max-width: 150px;
}
6 changes: 3 additions & 3 deletions frontend/src/components/NFTGrid/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import NFTGridItem from "../NFTGridItem"
import Spinner from "../Spinner"
import Loading from "../Loading"

import classes from "./NFTGrid.module.css"
import { useChainId } from "wagmi"
Expand Down Expand Up @@ -35,7 +35,7 @@ export const AccountNftGrid: React.FC<Props> = ({ address }) => {

const nfts = nftBalances.map((nft) => ({ ...nft, deployed: isDeployed(nft) }))

if (isLoading) return <Spinner />
if (isLoading) return <Loading />

if (nfts.length === 0) {
return (
Expand Down Expand Up @@ -84,7 +84,7 @@ export const CollectionNftGrid: React.FC<Props> = ({ address }) => {

const nfts = nftBalances.map((nft) => ({ ...nft, deployed: isDeployed(nft) }))

if (isLoading) return <Spinner />
if (isLoading) return <Loading />

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/NFTItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import copy from "copy-to-clipboard"
import clsx from "clsx"

import useTokenBalances from "../../hooks/useTokenBalances"
import Spinner from "../Spinner"
import Loading from "../Loading"
import { useDeployMech } from "../../hooks/useDeployMech"

import { calculateMechAddress } from "../../utils/calculateMechAddress"
Expand Down Expand Up @@ -105,7 +105,7 @@ const NFTItem: React.FC<Props> = ({ nft, chainId }) => {
)}
>
{mechBalancesError && <p>Failed to load assets</p>}
{mechBalancesLoading && <Spinner />}
{mechBalancesLoading && <Loading />}

{mechBalances.length === 0 && <p>No assets found</p>}
<ul className={classes.assetList}>
Expand Down
22 changes: 18 additions & 4 deletions frontend/src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,35 @@ import classes from "./Search.module.css"
import SearchResults, { SearchResult } from "./SearchResults"
import { useChainId, usePublicClient } from "wagmi"
import parseMechBytecode from "../../utils/parseMechBytecode"
import Loading from "../Loading"

const Search = () => {
const chainId = useChainId()
const client = usePublicClient()
const [search, setSearch] = useState("")
const [validSearch, setValidSearch] = useState(true)
const [results, setResults] = useState<SearchResult[]>([])
const [resultsLoading, setResultsLoading] = useState(false)

const handleSearch = async (e: React.ChangeEvent<HTMLInputElement>) => {
setResultsLoading(true)
setResults([])
const newSearch = e.target.value || ""
setSearch(newSearch)

if (!newSearch) {
setResultsLoading(false)
return setValidSearch(true)
}
setValidSearch(isAddress(newSearch))

if (isAddress(newSearch)) {
const valid = isAddress(newSearch)
setValidSearch(valid)

if (!valid) {
return setResultsLoading(false)
}

if (valid) {
// check if address is deployed contract
// check if bytecode is mech
// if not mech, check if address is nft collection
Expand Down Expand Up @@ -51,6 +61,7 @@ const Search = () => {
type: "account",
},
])
setResultsLoading(false)
return
}

Expand All @@ -62,6 +73,7 @@ const Search = () => {
name: nftCollection.name,
},
])
setResultsLoading(false)
} else {
// only an EOA
setResults([
Expand All @@ -70,6 +82,7 @@ const Search = () => {
type: "account",
},
])
setResultsLoading(false)
}
}
}
Expand Down Expand Up @@ -102,9 +115,10 @@ const Search = () => {
<p>Please use a valid address</p>
</div>
)}
{results.length > 0 && (
{(resultsLoading || results.length > 0) && (
<div className={classes.results}>
<SearchResults results={results} />
{results.length > 0 && <SearchResults results={results} />}
{resultsLoading && <Loading />}
</div>
)}
</div>
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/components/Spinner/index.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions frontend/src/components/Spinner/style.module.css

This file was deleted.

4 changes: 2 additions & 2 deletions frontend/src/routes/Mech/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Layout from "../../components/Layout"
import NFTItem from "../../components/NFTItem"

import classes from "./Mech.module.css"
import Spinner from "../../components/Spinner"
import Loading from "../../components/Loading"
import MechConnect from "../../components/Connect"
import { ProvideWalletConnect } from "../../hooks/useWalletConnect"
import { useHandleRequest } from "../../hooks/useHandleRequest"
Expand Down Expand Up @@ -60,7 +60,7 @@ const Mech: React.FC = () => {
return (
<Layout>
<div className={classes.container}>
{isLoading && <Spinner />}
{isLoading && <Loading />}
{!error && !isLoading && nft && mechAddress && (
<>
<NFTItem nft={nft} chainId={chain.id} />
Expand Down

1 comment on commit d76944f

@vercel
Copy link

@vercel vercel bot commented on d76944f Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.