generated from Borodutch/frontend-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18b0589
commit a3bdc75
Showing
18 changed files
with
4,417 additions
and
253 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
VITE_WALLET_CONNECT_PROJECT_ID=de445b653db5d8cad1fbc18bf3f4c00b | ||
VITE_ALCHEMY=https://base-mainnet.g.alchemy.com/v2/123 | ||
VITE_CONTRACT_ADDRESS=0x5AA6b79A8ea7c240c8DE59a83765AC984912A8f3 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
v20.11.0 | ||
v20.11.1 |
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
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,13 +1,17 @@ | ||
import { Suspense } from 'preact/compat' | ||
import UserCount from 'components/UserCount' | ||
import { ConnectButton } from '@rainbow-me/rainbowkit' | ||
import Knock from 'components/Knock' | ||
import Wallet from 'components/Wallet' | ||
|
||
export default function () { | ||
return ( | ||
<div className="container mx-auto max-w-prose p-10 prose"> | ||
<h1>Frontend template</h1> | ||
<Suspense fallback={<p>Loading...</p>}> | ||
<UserCount /> | ||
</Suspense> | ||
</div> | ||
<Wallet> | ||
<div className="container mx-auto max-w-prose p-10 prose"> | ||
<div className="flex flex-col gap-4"> | ||
<h1>knockknock</h1> | ||
<ConnectButton /> | ||
<Knock /> | ||
</div> | ||
</div> | ||
</Wallet> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { useAccount } from 'wagmi' | ||
import { useState } from 'preact/hooks' | ||
import contract from 'helpers/contract' | ||
import useEthersSigner from 'hooks/useEthersSigner' | ||
|
||
export default function () { | ||
const { isConnected } = useAccount() | ||
if (!isConnected) { | ||
return <p>Please, connect a wallet!</p> | ||
} | ||
const [loading, setLoading] = useState(false) | ||
const [error, setError] = useState('') | ||
const [success, setSuccess] = useState(false) | ||
const signer = useEthersSigner() | ||
|
||
return ( | ||
<div className="flex flex-col gap-2"> | ||
<button | ||
class="btn btn-primary" | ||
onClick={async () => { | ||
setLoading(true) | ||
setSuccess(false) | ||
setError('') | ||
try { | ||
if (!signer) { | ||
throw new Error('No signer found') | ||
} | ||
const signedContract = contract.connect(signer) | ||
await (await signedContract.knock()).wait() | ||
setSuccess(true) | ||
} catch (error) { | ||
const errorText = error instanceof Error ? error.message : error | ||
console.error(errorText) | ||
setError(errorText) | ||
} finally { | ||
setLoading(false) | ||
} | ||
}} | ||
disabled={loading} | ||
> | ||
{loading && '🤔 '}Knock! | ||
</button> | ||
{success && ( | ||
<div role="alert" class="alert alert-success"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
class="stroke-current shrink-0 h-6 w-6" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" | ||
/> | ||
</svg> | ||
<span>Yay, you knocked!</span> | ||
</div> | ||
)} | ||
{error && ( | ||
<div role="alert" class="alert alert-error"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
class="stroke-current shrink-0 h-6 w-6" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" | ||
/> | ||
</svg> | ||
<span>Oh, no! Something went wrong! {error}</span> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import '@rainbow-me/rainbowkit/styles.css' | ||
import { PropsWithChildren } from 'preact/compat' | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { RainbowKitProvider, getDefaultConfig } from '@rainbow-me/rainbowkit' | ||
import { WagmiProvider } from 'wagmi' | ||
import { base } from 'wagmi/chains' | ||
import env from 'helpers/env' | ||
|
||
const config = getDefaultConfig({ | ||
appName: 'knockknock', | ||
projectId: env.VITE_WALLET_CONNECT_PROJECT_ID, | ||
chains: [base], | ||
}) | ||
|
||
const queryClient = new QueryClient() | ||
|
||
export default function ({ children }: PropsWithChildren) { | ||
return ( | ||
<WagmiProvider config={config}> | ||
<QueryClientProvider client={queryClient}> | ||
<RainbowKitProvider coolMode>{children}</RainbowKitProvider> | ||
</QueryClientProvider> | ||
</WagmiProvider> | ||
) | ||
} |
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,4 @@ | ||
import { KnockKnock__factory } from '@borodutch/knockknock-contract' | ||
import env from 'helpers/env' | ||
|
||
export default KnockKnock__factory.connect(env.VITE_CONTRACT_ADDRESS) |
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,7 @@ | ||
import { cleanEnv, str } from 'envalid' | ||
|
||
export default cleanEnv(import.meta.env, { | ||
VITE_WALLET_CONNECT_PROJECT_ID: str(), | ||
VITE_ALCHEMY: str(), | ||
VITE_CONTRACT_ADDRESS: str(), | ||
}) |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Buffer } from 'buffer' | ||
|
||
window.global = window.global ?? window | ||
window.Buffer = window.Buffer ?? Buffer | ||
window.process = window.process ?? { env: {} } // Minimal process polyfill | ||
|
||
export {} |
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,24 @@ | ||
import * as React from 'react' | ||
import { BrowserProvider, JsonRpcSigner, Networkish } from 'ethers' | ||
import { UseWalletClientReturnType, useWalletClient } from 'wagmi' | ||
|
||
function walletClientToSigner(walletClient: UseWalletClientReturnType) { | ||
if (!walletClient.data) return null | ||
const { account, chain, transport } = walletClient.data | ||
const network = { | ||
chainId: chain.id, | ||
name: chain.name, | ||
ensAddress: chain.contracts?.ensRegistry?.address, | ||
} | ||
const provider = new BrowserProvider(transport, network as Networkish) | ||
const signer = new JsonRpcSigner(provider, account.address) | ||
return signer | ||
} | ||
|
||
export default function ({ chainId }: { chainId?: number } = {}) { | ||
const data = useWalletClient({ chainId }) | ||
return React.useMemo( | ||
() => (data ? walletClientToSigner(data) : undefined), | ||
[data] | ||
) | ||
} |
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,3 +1,4 @@ | ||
import 'helpers/polyfills' | ||
import 'index.css' | ||
import { render } from 'preact' | ||
import App from 'App' | ||
|
Oops, something went wrong.