Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/update-sc #35

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/web/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function getAuthOptions(req: IncomingMessage): NextAuthOptions {
id: siwe.address,
}
} catch (_e) {
console.log(_e)
console.error(_e)
return null
}
},
Expand Down
64 changes: 38 additions & 26 deletions apps/web/pages/api/v0/course/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const handleGetRequest = async (
.status(200)
.json({ status: ApiResponseStatus.success, data: { course: course } })
} catch (error) {
console.log(error)
console.error(error)
return res.status(500).json({
status: ApiResponseStatus.error,
message:
Expand Down Expand Up @@ -86,35 +86,47 @@ const handlePostRequest = async (
const karmaAccessControlAddress =
karmaAccessControlCreatedLogDecoded.args.karmaAccessControl

const [symbol, baseURI, baseMagisterKarma, baseDiscipulusKarma] =
await Promise.all([
client.readContract({
address: courseContractAddress,
abi: CredentialsBurnableAbi,
functionName: 'symbol',
}),
client.readContract({
address: courseContractAddress,
abi: CredentialsBurnableAbi,
functionName: 'baseURI',
}),
client.readContract({
address: karmaAccessControlAddress,
abi: KarmaAccessControlAbiUint64,
functionName: 'BASE_MAGISTER_KARMA',
}),
client.readContract({
address: karmaAccessControlAddress,
abi: KarmaAccessControlAbiUint64,
functionName: 'BASE_DISCIPULUS_KARMA',
}),
])
const [
symbol,
baseURI,
contractURI,
baseMagisterKarma,
baseDiscipulusKarma,
] = await Promise.all([
client.readContract({
address: courseContractAddress,
abi: CredentialsBurnableAbi,
functionName: 'symbol',
}),
client.readContract({
address: courseContractAddress,
abi: CredentialsBurnableAbi,
functionName: 'baseURI',
}),
client.readContract({
address: courseContractAddress,
abi: CredentialsBurnableAbi,
functionName: 'contractURI',
}),
client.readContract({
address: karmaAccessControlAddress,
abi: KarmaAccessControlAbiUint64,
functionName: 'BASE_MAGISTER_KARMA',
}),
client.readContract({
address: karmaAccessControlAddress,
abi: KarmaAccessControlAbiUint64,
functionName: 'BASE_DISCIPULUS_KARMA',
}),
])

const timestamp = (
await client.getBlock({ blockNumber: txReceipt.blockNumber })
).timestamp

const metadataResponse = await fetch(baseURI)
const metadataURL = baseURI + contractURI

const metadataResponse = await fetch(metadataURL)

if (!metadataResponse.ok) {
return res.status(500).json({
Expand Down Expand Up @@ -149,7 +161,7 @@ const handlePostRequest = async (
image_url: jsonMetadata.image,
website_url: jsonMetadata.website,
symbol: symbol,
ipfs_metadata: baseURI,
ipfs_metadata: metadataURL,
timestamp: Number(timestamp),
chain_id: Number(chainId),
karma_access_control_address: sanitizeAddress(
Expand Down
2 changes: 1 addition & 1 deletion apps/web/pages/api/v0/course/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const handlePostRequest = async (
data: { metadata: ipfsCourseMetadata },
})
} catch (error: any) {
console.log(error)
console.error(error)
return res.status(500).json({
status: ApiResponseStatus.error,
message:
Expand Down
2 changes: 1 addition & 1 deletion apps/web/pages/api/v0/user/course/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const handleDeleteRequest = async (
data: { userCredential: deletedCredential },
})
} catch (error: any) {
console.log(error)
console.error(error)
return res.status(500).json({
status: ApiResponseStatus.error,
message:
Expand Down
32 changes: 13 additions & 19 deletions apps/web/pages/api/v0/user/course/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,17 @@ const handlePostRequest = async (
})),
})

// ONLY BEFORE TOKEN_URI FIX
const tempFixTokenURIResponse = multicallTokenURIResponses.map(
(tokenURI) => {
tokenURIs = multicallTokenURIResponses
.map((tokenURI) => {
return {
result: tokenURI.result
? tokenURI.result.split('/').slice(-1)[0]
: undefined,
}
},
)
///////////

tokenURIs = tempFixTokenURIResponse.map((response) => {
return response.result ? response.result : ''
})
})
.map((response) => {
return response.result ? response.result : ''
})
} else {
const tokenURIResponse = await Promise.all(
credentialsIssuedLogsDecoded.map((log) => {
Expand All @@ -156,15 +152,13 @@ const handlePostRequest = async (
}),
)

// ONLY BEFORE TOKEN_URI FIX
const tempFixTokenURIResponse = tokenURIResponse.map((tokenURI) => {
return tokenURI.split('/').slice(-1)[0]
})
///////////

tokenURIs = tempFixTokenURIResponse.map((response) => {
return response ? response : ''
})
tokenURIs = tokenURIResponse
.map((tokenURI) => {
return tokenURI.split('/').slice(-1)[0]
})
.map((response) => {
return response ? response : ''
})
}

const createCredentialsData = credentialsIssuedLogsDecoded.map(
Expand Down
18 changes: 18 additions & 0 deletions packages/abi/src/CredentialsBurnableAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export const CredentialsBurnableAbi = [
name: '_bUri',
type: 'string',
},
{
internalType: 'string',
name: '_contractURI',
type: 'string',
},
],
stateMutability: 'nonpayable',
type: 'constructor',
Expand Down Expand Up @@ -340,6 +345,19 @@ export const CredentialsBurnableAbi = [
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: 'tokenId',
type: 'uint256',
},
],
name: 'burnMagister',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [],
name: 'contractURI',
Expand Down
5 changes: 5 additions & 0 deletions packages/abi/src/CredentialsFactoryAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export const CredentialsFactoryAbi = [
name: '_bUri',
type: 'string',
},
{
internalType: 'string',
name: '_contractURI',
type: 'string',
},
{
internalType: 'uint64',
name: '_baseMagisterKarma',
Expand Down
2 changes: 1 addition & 1 deletion packages/chains/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export type ChainSnapshotWebsite =

export const FactoryContractAddress = {
[ChainId.ETHEREUM]: '',
[ChainId.SEPOLIA]: '0xb6c59c1538d362d9495f1564629ae2b59f0532af',
[ChainId.SEPOLIA]: '0xf39ff550e518c9044e6235e3708141fc28dbd4bb',
[ChainId.FOUNDRY]: process.env.NEXT_PUBLIC_FOUNDRY_FACTORY_CONTRACT_ADDRESS,
} as const

Expand Down
9 changes: 1 addition & 8 deletions packages/ui/src/Layouts/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
chakra,
Container,
Stack,
Text,
useColorModeValue,
VisuallyHidden,
} from '@chakra-ui/react'
Expand Down Expand Up @@ -51,15 +50,9 @@ export const Footer = () => {
py={4}
direction={{ base: 'column', md: 'row' }}
spacing={4}
justify={{ base: 'center', md: 'space-between' }}
justify={{ base: 'center', md: 'flex-end' }}
align={{ base: 'center', md: 'center' }}
>
<Text fontWeight={'bold'} fontSize={'md'}>
Version:{' '}
<Text fontWeight={'normal'} as="span">
{''}
</Text>
</Text>
<Stack direction={'row'} spacing={6}>
<SocialButton label={'Github'} href={'https://github.com/cubiclearn'}>
<FaGithub />
Expand Down
2 changes: 1 addition & 1 deletion packages/wagmi/src/hooks/web3/useBurnCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function useBurnCredential({
const { writeAsync: burn } = useContractWrite({
abi: CredentialsBurnableAbi,
address: courseAddress,
functionName: 'burn',
functionName: credentialType === 'MAGISTER' ? 'burnMagister' : 'burn',
})

const { removeModerator } = useEditSnapshotSpace(courseAddress, chain?.id)
Expand Down
3 changes: 2 additions & 1 deletion packages/wagmi/src/hooks/web3/useCreateCourse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ export function useCreateCourse({
args: [
name,
'DAEC',
uploadMetadataResponseJson.data.metadata.url,
`${process.env.NEXT_PUBLIC_IPFS_GATEWAY_URL}/`,
uploadMetadataResponseJson.data.metadata.hash,
BigInt(magisterBaseKarma),
BigInt(discipulusBaseKarma),
],
Expand Down
6 changes: 2 additions & 4 deletions packages/wagmi/src/hooks/web3/useTransferCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ export function useTransferCredentials({

state.setSigning()

const tokenURI = `${process.env.NEXT_PUBLIC_IPFS_GATEWAY_URL}/${credentialIPFSCid}`
if (mint === undefined) {
throw new Error(
'The data provided is incorrect. Please ensure that you have entered the correct information.',
)
}

const writeResult = await mint({
args: [userData.address, tokenURI, 2],
args: [userData.address, credentialIPFSCid, 2],
})

await fetch('/api/v0/transactions', {
Expand Down Expand Up @@ -197,7 +196,6 @@ export function useTransferCredentials({

try {
state.setValidating()
const tokenURI = `${process.env.NEXT_PUBLIC_IPFS_GATEWAY_URL}/${credentialIPFSCid}`

if (credentialType === 'OTHER') {
let accessList: { address: Address; hasAccess: boolean }[]
Expand Down Expand Up @@ -298,7 +296,7 @@ export function useTransferCredentials({
const writeResult = await multiMint({
args: [
addressToMint,
Array(addressToMint.length).fill(tokenURI),
Array(addressToMint.length).fill(credentialIPFSCid),
Array(addressToMint.length).fill(2),
],
})
Expand Down