-
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.
✨ webapp: get deliverables on server
- Loading branch information
1 parent
fa2d323
commit 7f164f3
Showing
9 changed files
with
70 additions
and
28 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,11 @@ | ||
import { baseGoerli, foundry, type Chain } from 'viem/chains'; | ||
import { deliverableAddress as deliverable } from './contracts'; | ||
import type { Address } from 'viem'; | ||
|
||
const chain = { | ||
[baseGoerli.id]: baseGoerli, | ||
[foundry.id]: foundry, | ||
}[Object.keys(deliverable)[0]] as Chain; | ||
|
||
export default chain; | ||
export const deliverableAddress = (deliverable as Record<number, Address>)[chain.id]; |
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,14 @@ | ||
import getDeliverables from '../server/getDeliverables'; | ||
|
||
export default async function Home() { | ||
return <main></main>; | ||
const deliverables = await getDeliverables(); | ||
return ( | ||
<main> | ||
<ul> | ||
{deliverables.map((id) => ( | ||
<li key={String(id)}>{String(id)}</li> | ||
))} | ||
</ul> | ||
</main> | ||
); | ||
} |
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,16 +1,18 @@ | ||
'use client'; | ||
|
||
import { foundry } from 'viem/chains'; | ||
import { createConfig, http } from 'wagmi'; | ||
import { coinbaseWallet, injected, walletConnect } from 'wagmi/connectors'; | ||
import { createConfig, http } from 'wagmi'; | ||
import { foundry } from 'viem/chains'; | ||
import { test } from '../e2e/utils/connectors'; | ||
import chain from '../app/chain'; | ||
|
||
const projectId = 'f1e5a989573bf31c595b3642fffa6036'; | ||
|
||
export const config = createConfig({ | ||
chains: [foundry], | ||
transports: { [foundry.id]: http() }, | ||
connectors: JSON.parse(process.env.NEXT_PUBLIC_E2E ?? 'false') | ||
? [test()] | ||
: [injected(), coinbaseWallet({ appName: 'receba' }), walletConnect({ projectId })], | ||
chains: [chain], | ||
transports: { [chain.id]: http() }, | ||
connectors: | ||
chain.id === foundry.id | ||
? [test()] | ||
: [injected(), coinbaseWallet({ appName: 'receba' }), walletConnect({ projectId })], | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use server'; | ||
|
||
import { cache } from 'react'; | ||
import { revalidateTag } from 'next/cache'; | ||
import { getFunctionSelector } from 'viem'; | ||
import { readContract, readContracts } from '@wagmi/core'; | ||
import { deliverableAddress as address } from '../app/chain'; | ||
import { deliverableAbi as abi } from '../app/contracts'; | ||
import { config } from './wagmi'; | ||
|
||
export default cache(async function getDeliverables() { | ||
const total = Number(await readContract(config, { functionName: 'totalSupply', abi, address })); | ||
return readContracts(config, { | ||
allowFailure: false, | ||
contracts: [...Array(total)].map((_, i) => ({ functionName: 'tokenByIndex', args: [i], abi, address })), | ||
}); | ||
}); | ||
|
||
export async function revalidate() { | ||
revalidateTag(`${address}:${getFunctionSelector('totalSupply()')}`); | ||
} |
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,19 +1,16 @@ | ||
import { foundry as chain } from 'viem/chains'; | ||
import { readFileSync, readdirSync } from 'fs'; | ||
import { defineConfig } from '@wagmi/cli'; | ||
import { getAddress } from 'viem'; | ||
import { foundry } from '@wagmi/cli/plugins'; | ||
import { address as receba } from '../deployments/localhost/Receba.json' assert { type: 'json' }; | ||
import { address as deliverable } from '../deployments/localhost/Deliverable.json' assert { type: 'json' }; | ||
|
||
const deployments = `../deployments/${process.env.CHAIN ?? 'testnet'}`; | ||
const chainId = Number(readFileSync(`${deployments}/.chainId`)); | ||
|
||
export default defineConfig({ | ||
out: 'app/contracts.ts', | ||
plugins: [ | ||
foundry({ | ||
project: '..', | ||
deployments: { | ||
Receba: { [chain.id]: getAddress(receba) }, | ||
Deliverable: { [chain.id]: getAddress(deliverable) }, | ||
}, | ||
contracts: readdirSync(deployments) | ||
.filter((file) => file.endsWith('.json')) | ||
.map((file) => { | ||
const { abi, address } = JSON.parse(readFileSync(`${deployments}/${file}`).toString()); | ||
return { name: file.replace('.json', ''), abi, address: { [chainId]: getAddress(address) } }; | ||
}), | ||
], | ||
}); |