-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor + connect page + header
- Loading branch information
1 parent
c3a3092
commit a5a9dd5
Showing
19 changed files
with
440 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,60 @@ | ||
import { useAccount, useConnect, useDisconnect } from 'wagmi' | ||
import { useAccount } from 'wagmi' | ||
import { useWriteContracts, useCallsStatus } from 'wagmi/experimental' | ||
import Connect from './components/Connect' | ||
import Payout from './components/Payout' | ||
|
||
const abi = [ | ||
{ | ||
stateMutability: 'nonpayable', | ||
type: 'function', | ||
inputs: [{ name: 'to', type: 'address' }], | ||
name: 'safeMint', | ||
outputs: [], | ||
} | ||
{ | ||
stateMutability: 'nonpayable', | ||
type: 'function', | ||
inputs: [{ name: 'to', type: 'address' }], | ||
name: 'safeMint', | ||
outputs: [], | ||
} | ||
] as const | ||
|
||
function App() { | ||
const account = useAccount() | ||
const { connectors, connect, status, error } = useConnect() | ||
const { disconnect } = useDisconnect() | ||
const { data: id, writeContracts } = useWriteContracts() | ||
const { data: callsStatus } = useCallsStatus({ | ||
id: id as string, | ||
query: { | ||
enabled: !!id, | ||
// Poll every second until the calls are confirmed | ||
refetchInterval: (data) => | ||
data.state.data?.status === "CONFIRMED" ? false : 1000, | ||
}, | ||
}); | ||
|
||
const handleMint = () => { | ||
writeContracts({ | ||
contracts: [ | ||
{ | ||
address: "0x119Ea671030FBf79AB93b436D2E20af6ea469a19", | ||
abi, | ||
functionName: "safeMint", | ||
args: [account.address], | ||
}, | ||
{ | ||
address: "0x119Ea671030FBf79AB93b436D2E20af6ea469a19", | ||
abi, | ||
functionName: "safeMint", | ||
args: [account.address], | ||
const account = useAccount() | ||
const { data: id, writeContracts } = useWriteContracts() | ||
const { data: callsStatus } = useCallsStatus({ | ||
id: id as string, | ||
query: { | ||
enabled: !!id, | ||
// Poll every second until the calls are confirmed | ||
refetchInterval: (data) => | ||
data.state.data?.status === "CONFIRMED" ? false : 1000, | ||
}, | ||
{ | ||
address: "0x119Ea671030FBf79AB93b436D2E20af6ea469a19", | ||
abi, | ||
functionName: "safeMint", | ||
args: [account.address], | ||
} | ||
], | ||
}) | ||
} | ||
|
||
|
||
return ( | ||
<> | ||
<div> | ||
<h2>Account</h2> | ||
|
||
<div> | ||
status: {account.status} | ||
<br /> | ||
addresses: {JSON.stringify(account.addresses)} | ||
<br /> | ||
chainId: {account.chainId} | ||
</div> | ||
|
||
{account.status === 'connected' && ( | ||
<button type="button" onClick={() => disconnect()}> | ||
Disconnect | ||
</button> | ||
)} | ||
</div> | ||
|
||
<div> | ||
<h2>Connect</h2> | ||
{connectors.map((connector) => ( | ||
<button | ||
key={connector.uid} | ||
onClick={() => connect({ connector })} | ||
type="button" | ||
> | ||
{connector.name} | ||
</button> | ||
))} | ||
<div>{status}</div> | ||
<div>{error?.message}</div> | ||
<div> | ||
<button onClick={handleMint}>Mint</button> | ||
{callsStatus && <div> Status: {callsStatus.status}</div>} | ||
</div> | ||
</div> | ||
</> | ||
) | ||
}); | ||
|
||
const handleMint = () => { | ||
writeContracts({ | ||
contracts: [ | ||
{ | ||
address: "0x119Ea671030FBf79AB93b436D2E20af6ea469a19", | ||
abi, | ||
functionName: "safeMint", | ||
args: [account.address], | ||
}, | ||
{ | ||
address: "0x119Ea671030FBf79AB93b436D2E20af6ea469a19", | ||
abi, | ||
functionName: "safeMint", | ||
args: [account.address], | ||
}, | ||
{ | ||
address: "0x119Ea671030FBf79AB93b436D2E20af6ea469a19", | ||
abi, | ||
functionName: "safeMint", | ||
args: [account.address], | ||
} | ||
], | ||
}) | ||
} | ||
|
||
if (!account.isConnected) | ||
return (<Connect />) | ||
else | ||
return (<Payout />) | ||
} | ||
|
||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as logoutIcon } from "./logout.png"; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from "react"; | ||
import styles from "../styles/Connect.module.scss"; | ||
import { useConnect } from "wagmi"; | ||
|
||
export default function Connect(): React.JSX.Element { | ||
const { connectors, connect, error, isPending } = useConnect(); | ||
|
||
return ( | ||
<div className={styles.main}> | ||
<h1>The Batch Payouts App</h1> | ||
<span className={styles.subtitle}>Powered by Crypto</span> | ||
<button | ||
key={connectors[0].uid} | ||
className={`${styles.connectBttn} ${isPending ? styles.shimmer : ""}`} | ||
onClick={() => connect({ connector: connectors[0] })} | ||
type="button" | ||
> | ||
{connectors[0].name} | ||
</button> | ||
{error && <span className={styles.errorMsg}>{error.message}</span>} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from "react"; | ||
import styles from "../../styles/Payout/Header.module.scss"; | ||
import { useAccount, useDisconnect } from "wagmi"; | ||
import { toast } from "react-toastify"; | ||
import { logoutIcon } from "../../assets"; | ||
|
||
export default function Header(): React.JSX.Element { | ||
const { address, chain } = useAccount(); | ||
const { disconnect, isPending } = useDisconnect(); | ||
|
||
const copyToClipboard = () => { | ||
try { | ||
navigator.clipboard.writeText(address as string); | ||
toast.success("Copied to clipboard!") | ||
} catch (err) { | ||
toast.error("Failed to copy!") | ||
} | ||
} | ||
|
||
return ( | ||
<div className={styles.main}> | ||
<h1>The Batch Payouts App</h1> | ||
<div className={styles.walletContainer}> | ||
<div | ||
onClick={copyToClipboard} | ||
className={`${styles.address} ${isPending ? styles.shimmer : ""}`}> | ||
{address?.slice(0, 5) + "..." + address?.slice(-5)} | ||
</div> | ||
<div className={styles.details}> | ||
<span>Network: {chain?.name}</span> | ||
<button className={styles.logoutBttn} onClick={() => { disconnect(); }}> | ||
<img src={logoutIcon} alt="Logout" /> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react"; | ||
import styles from "../../styles/Payout/Payout.module.scss"; | ||
import Header from "./Header"; | ||
|
||
export default function Payout(): React.JSX.Element { | ||
return ( | ||
<div className={styles.main}> | ||
<div className={styles.inner}> | ||
<Header /> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { http, createConfig } from 'wagmi'; | ||
import { baseSepolia } from 'wagmi/chains'; | ||
import { coinbaseWallet } from 'wagmi/connectors'; | ||
|
||
export const config = createConfig({ | ||
chains: [baseSepolia], | ||
connectors: [ | ||
coinbaseWallet({ appName: 'Batch Payouts', preference: 'smartWalletOnly' }), | ||
], | ||
transports: { | ||
[baseSepolia.id]: http(), | ||
}, | ||
}); | ||
|
||
declare module 'wagmi' { | ||
interface Register { | ||
config: typeof config; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@import './_variables.scss'; | ||
@import './_animations.scss'; | ||
|
||
.main { | ||
width: 100%; | ||
height: 100vh; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column; | ||
text-align: center; | ||
|
||
.subtitle { | ||
text-transform: uppercase; | ||
font-size: small; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.connectBttn { | ||
padding: 10px 40px; | ||
background-color: $coinbase-blue; | ||
color: white; | ||
border-radius: 30px; | ||
border: none; | ||
outline: none; | ||
cursor: pointer; | ||
} | ||
|
||
.errorMsg { | ||
color: red; | ||
font-size: small; | ||
} | ||
} |
Oops, something went wrong.