Skip to content

Commit 15676bd

Browse files
reverse nft array & format
1 parent 5c7212e commit 15676bd

File tree

6 files changed

+203
-199
lines changed

6 files changed

+203
-199
lines changed

components/NFTCard.tsx

+11-14
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@ import { formatEther } from 'viem'
77
import { getIpfsImage } from '../utils/AxiosHelper'
88
import { nftData } from '../pages/store'
99

10-
1110
interface NFTCardProps {
1211
tokenId: number
1312
addToCart: Function
1413
removeFromCart: Function
1514
contractProps: MintingContractProps
1615
paymentTokenSymbol: string
1716
owned: boolean
18-
name: string,
19-
description: string,
20-
image: string,
21-
price: bigint,
22-
setIsMysteryMint: Function,
17+
name: string
18+
description: string
19+
image: string
20+
price: bigint
21+
setIsMysteryMint: Function
2322
isMysteryMint: boolean
2423
emptyCart: Function
2524
}
@@ -37,7 +36,7 @@ export const NFTCard: React.FC<NFTCardProps> = ({
3736
price,
3837
setIsMysteryMint,
3938
isMysteryMint,
40-
emptyCart
39+
emptyCart,
4140
}) => {
4241
// const [ipfsData, setIpfsData] = useState({}) as any
4342
const [ipfsImage, setIpfsImage] = useState() as any
@@ -75,7 +74,6 @@ export const NFTCard: React.FC<NFTCardProps> = ({
7574
useEffect(() => {
7675
setNftData({ name, description, image, tokenId, tokenPrice: price })
7776
}, [name, description, image, price])
78-
7977

8078
useEffect(() => {
8179
setTimeout(() => {
@@ -107,20 +105,20 @@ export const NFTCard: React.FC<NFTCardProps> = ({
107105
}
108106

109107
const handleCart = () => {
110-
const {tokenId: id, name: name, tokenPrice: price } = nftData
108+
const { tokenId: id, name: name, tokenPrice: price } = nftData
111109
setIsInCart((prevIsInCart) => !prevIsInCart)
112110
setRandomMsg(randomMessage())
113111
if (isMysteryMint) {
114112
emptyCart()
115-
setIsMysteryMint(false);
113+
setIsMysteryMint(false)
116114
}
117115

118116
if (!isInCart) {
119117
console.log('adding to cart', id, name, price)
120118
addToCart({ tokenId: id, name, tokenPrice: price })
121119
showFadeInOutText()
122120
} else {
123-
removeFromCart({ tokenId: id, name, tokenPrice: price})
121+
removeFromCart({ tokenId: id, name, tokenPrice: price })
124122
}
125123
}
126124

@@ -173,10 +171,9 @@ export const NFTCard: React.FC<NFTCardProps> = ({
173171
if (image && !ipfsImage) {
174172
getIpfsImage(image).then((res) => {
175173
setIpfsImage(res)
176-
}
177-
)
174+
})
178175
}
179-
},[image, ipfsImage, name, description])
176+
}, [image, ipfsImage, name, description])
180177

181178
useEffect(() => {
182179
setTokenSymbol(paymentTokenSymbol)

components/cartModal.tsx

+33-22
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,30 @@ interface cartItems {
1010
paymentTokenSymbol: string
1111
userBalance: bigint
1212
emptyCart: Function
13-
isMysteryMint: boolean;
13+
isMysteryMint: boolean
1414
}
1515

16-
export const CartModal = ({ userBalance, itemsArray, itemSum, isMintModal, paymentTokenSymbol, emptyCart, isMysteryMint }: cartItems) => {
16+
export const CartModal = ({
17+
userBalance,
18+
itemsArray,
19+
itemSum,
20+
isMintModal,
21+
paymentTokenSymbol,
22+
emptyCart,
23+
isMysteryMint,
24+
}: cartItems) => {
1725
const [tokenSymbol, setTokenSymbol] = useState('ETH')
18-
const cartItems = Array.from(itemsArray).map((item) => (
19-
console.log('token name on cart modal', item.name),
20-
<li key={item.tokenId}>
21-
{' '}
22-
{ isMysteryMint ? '????' : item.name}: {formatEther(item.tokenPrice)} {tokenSymbol}
23-
</li>
24-
))
26+
const cartItems = Array.from(itemsArray).map(
27+
(item) => (
28+
console.log('token name on cart modal', item.name),
29+
(
30+
<li key={item.tokenId}>
31+
{' '}
32+
{isMysteryMint ? '????' : item.name}: {formatEther(item.tokenPrice)} {tokenSymbol}
33+
</li>
34+
)
35+
),
36+
)
2537

2638
useEffect(() => {
2739
setTokenSymbol(paymentTokenSymbol)
@@ -32,19 +44,18 @@ export const CartModal = ({ userBalance, itemsArray, itemSum, isMintModal, payme
3244
<div className="box-content border-solid border-2 lg:w-96 bg-orange-300 dark:bg-orange-800 rounded-lg border-grey-600 ">
3345
<div className="p-4 space-y-1">
3446
<div>
35-
<h3 className=" inline text-lg font-semibold">Current Mitch Cart</h3>
36-
<button
37-
className={
38-
itemsArray.length === 0
39-
? 'inline float-right text-xs p-1 bg-gray-200 text-gray-400 cursor-default rounded-lg'
40-
: 'inline float-right text-xs p-1 bg-orange-400 dark:bg-orange-700 rounded-lg active:scale-90 transition-transform duration-100'
41-
}
42-
disabled={itemsArray.length === 0}
43-
onClick={() => emptyCart()}
44-
>
45-
Empty Cart
46-
</button>
47-
47+
<h3 className=" inline text-lg font-semibold">Current Mitch Cart</h3>
48+
<button
49+
className={
50+
itemsArray.length === 0
51+
? 'inline float-right text-xs p-1 bg-gray-200 text-gray-400 cursor-default rounded-lg'
52+
: 'inline float-right text-xs p-1 bg-orange-400 dark:bg-orange-700 rounded-lg active:scale-90 transition-transform duration-100'
53+
}
54+
disabled={itemsArray.length === 0}
55+
onClick={() => emptyCart()}
56+
>
57+
Empty Cart
58+
</button>
4859
</div>
4960
<hr className="border-t border-gray-400 dark:border-gray-300 my-4" />
5061

components/mint.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ export const MintModal = ({
325325
<div className="space-y-2 font-medium dark:text-white">
326326
<p>Amazing! Thank you so much for minting some mitch and supporting me in my goals!</p>
327327
<>
328-
<h3 className="text-xl font-bold">Check out your Mitch's here:</h3>
329-
<ul>{tokenLinks}</ul>
328+
<h3 className="text-xl font-bold">Check out your Mitch's here:</h3>
329+
<ul>{tokenLinks}</ul>
330330
</>
331331

332332
<p>

components/navbar.tsx

+46-47
Original file line numberDiff line numberDiff line change
@@ -42,91 +42,90 @@ IProps) => {
4242
abi: MintingContractJSON.abi,
4343
functionName: 'nativeMintEnabled',
4444
args: [],
45-
chainId: chainId
46-
}).then((response) => {
47-
setIsNativeMinting(response as boolean)
48-
}).catch((error) => {
49-
console.log('error', error, 'chainID', chainId)
50-
}
51-
)
45+
chainId: chainId,
46+
})
47+
.then((response) => {
48+
setIsNativeMinting(response as boolean)
49+
})
50+
.catch((error) => {
51+
console.log('error', error, 'chainID', chainId)
52+
})
5253
}
53-
54+
5455
const getMitchTokenBalance = async (mitchTokenAddress: string) => {
55-
if (account.address !== undefined ) {
56+
if (account.address !== undefined) {
5657
fetchBalance({
5758
address: `0x${account.address?.substring(2)}`,
5859
token: `0x${mitchTokenAddress}`,
5960
chainId: contractProps?.chainId,
60-
}).then((response) => {
61-
if (response !== undefined) {
62-
const formattedBalance = parseFloat(formatEther(response.value))
63-
setRewardTokenBalance(formattedBalance)
64-
}
65-
}).catch((error) => {
66-
console.log('error', error)
67-
}
68-
)
61+
})
62+
.then((response) => {
63+
if (response !== undefined) {
64+
const formattedBalance = parseFloat(formatEther(response.value))
65+
setRewardTokenBalance(formattedBalance)
66+
}
67+
})
68+
.catch((error) => {
69+
console.log('error', error)
70+
})
6971
}
7072
}
7173

7274
const getContractBalance = async (address: string, chainId: number) => {
73-
isNativeMinting ?
74-
fetchBalance({
75+
isNativeMinting
76+
? fetchBalance({
7577
address: `0x${address}`,
78+
}).then((response) => {
79+
setBalance(parseFloat(formatEther(response.value)))
7680
})
77-
.then((response) => {
78-
setBalance(parseFloat(formatEther(response.value)))
79-
})
80-
:
81-
readContract({
82-
address: `0x${address}`,
83-
abi: MintingContractJSON.abi,
84-
functionName: 'paymentToken',
85-
args: [],
86-
chainId: chainId,
87-
}).then((response) => {
88-
fetchBalance({
81+
: readContract({
8982
address: `0x${address}`,
90-
token: `0x${(response as string).substring(2) }`,
83+
abi: MintingContractJSON.abi,
84+
functionName: 'paymentToken',
85+
args: [],
9186
chainId: chainId,
92-
}).then((response) => {
93-
if (response !== undefined) {
94-
const formattedBalance = parseFloat(formatEther(response.value))
95-
setBalance(formattedBalance)
96-
}
9787
})
98-
}).catch((error) => {
99-
console.log('error', error)
100-
}
101-
)
88+
.then((response) => {
89+
fetchBalance({
90+
address: `0x${address}`,
91+
token: `0x${(response as string).substring(2)}`,
92+
chainId: chainId,
93+
}).then((response) => {
94+
if (response !== undefined) {
95+
const formattedBalance = parseFloat(formatEther(response.value))
96+
setBalance(formattedBalance)
97+
}
98+
})
99+
})
100+
.catch((error) => {
101+
console.log('error', error)
102+
})
102103
}
103104
useEffect(() => {
104105
if (isRightNetwork && contractProps?.address && contractProps?.chainId && contractProps?.mitchTokenAddress) {
105106
getContractBalance(contractProps.address, contractProps.chainId)
106107
getMitchTokenBalance(contractProps.mitchTokenAddress)
107108
}
108109
}, [contractProps, isNativeMinting, updateBalance, isRightNetwork])
109-
110+
110111
useEffect(() => {
111112
if (network !== undefined) {
112113
setContractProps(selectContractAddress(network))
113114
}
114115
}, [network])
115-
116+
116117
useEffect(() => {
117118
if (contractProps?.address && contractProps?.chainId) {
118119
getNativeMintEnabled(contractProps?.address, contractProps?.chainId)
119120
}
120-
}
121-
, [contractProps])
121+
}, [contractProps])
122122

123123
useEffect(() => {
124124
const maxEthNeeded = 32
125125
const percentComplete = ((2.25 + balance!) / maxEthNeeded) * 100
126126
setProgressBar(Number(percentComplete.toFixed(3)))
127127
}, [balance])
128128

129-
130129
return (
131130
<nav className="flex flex-col z-30 lg:flex-row items-center bg-gradient-to-r from-cyan-500 to-blue-500 dark:from-blue-500 dark:to-cyan-500 sm:max-w-screen justify-between py-2 px-4 navBarBorder">
132131
{/* Logo */}

pages/_app.tsx

+4-7
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@ import '@rainbow-me/rainbowkit/styles.css'
55

66
import type { AppProps } from 'next/app'
77
import { ThemeProvider } from 'next-themes'
8-
import { getDefaultWallets, RainbowKitProvider } from '@rainbow-me/rainbowkit'
8+
import { getDefaultWallets, RainbowKitProvider } from '@rainbow-me/rainbowkit'
99
import { configureChains, createConfig, WagmiConfig } from 'wagmi'
10-
import {infuraProvider} from 'wagmi/providers/infura'
10+
import { infuraProvider } from 'wagmi/providers/infura'
1111
import { constants } from '../utils/constants'
1212
import { Analytics } from '@vercel/analytics/react'
1313
import { jsonRpcProvider } from 'wagmi/providers/jsonRpc'
14-
import { publicProvider } from 'wagmi/providers/public';
15-
14+
import { publicProvider } from 'wagmi/providers/public'
1615

1716
const walletConnectId = process.env.WALLET_CONNECT_PROJECT as string
1817
const infuraID = process.env.NEXT_PUBLIC_INFURA_ID as string
1918
// const { NEXT_PUBLIC_ALCHEMY_ID } = config
2019
const NEXT_PUBLIC_GNOSIS_RPC_URL = process.env.NEXT_PUBLIC_GNOSIS_RPC_URL as string
2120
// const alchemyId = NEXT_PUBLIC_ALCHEMY_ID as string
2221

23-
2422
let appChains: any[] = []
2523
if (process.env.NODE_ENV === 'development') {
2624
appChains = constants.DEVELOPMENT_CHAINS
@@ -29,7 +27,7 @@ if (process.env.NODE_ENV === 'development') {
2927
}
3028

3129
const { chains, publicClient } = configureChains(appChains, [
32-
infuraProvider({ apiKey: infuraID}),
30+
infuraProvider({ apiKey: infuraID }),
3331
jsonRpcProvider({ rpc: () => ({ http: NEXT_PUBLIC_GNOSIS_RPC_URL }) }),
3432
publicProvider(),
3533
])
@@ -40,7 +38,6 @@ const { connectors } = getDefaultWallets({
4038
chains,
4139
})
4240

43-
4441
const wagmiClient = createConfig({
4542
autoConnect: true,
4643
connectors,

0 commit comments

Comments
 (0)