-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Wire up create font project submit button to the backend and s…
…mart contract apis (#11)
- Loading branch information
1 parent
8c599a4
commit 8f582d4
Showing
13 changed files
with
581 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import connectContract from '../../utils/connectContract'; | ||
|
||
|
||
export async function createIPFontProject({ | ||
files, | ||
name, | ||
description, | ||
perCharacterMintPrice, | ||
mintLimit | ||
}) { | ||
const ipfontsContract = connectContract(); | ||
|
||
if (!ipfontsContract) { | ||
console.log('Cound not connect to contract'); | ||
return; | ||
} | ||
|
||
const formData = new FormData(); | ||
|
||
for (let i = 0; i < files.length; i++) { | ||
formData.append('fonts', files[i]); | ||
}; | ||
|
||
try { | ||
const uploadFontResponse = await fetch('/api/upload-font', { | ||
method: 'POST', | ||
body: formData | ||
}); | ||
|
||
const { | ||
ok: fontUploadOk, | ||
cid: fontFilesCID, | ||
error: fontUploadError | ||
} = await uploadFontResponse.json(); | ||
|
||
console.log({ | ||
fontUploadOk, | ||
fontFilesCID, | ||
fontUploadError | ||
}); | ||
|
||
if (!fontUploadOk) { | ||
console.log(fontUploadError); | ||
return; | ||
} | ||
|
||
const uploadMetadataResponse = await fetch('/api/upload-metadata', { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
name, | ||
description | ||
}) | ||
}); | ||
|
||
const { | ||
ok: metadataUploadOk, | ||
cid: fontMetadataCID, | ||
error: metadataUploadError | ||
} = await uploadMetadataResponse.json(); | ||
|
||
console.log({ | ||
metadataUploadOk, | ||
fontMetadataCID, | ||
metadataUploadError | ||
}); | ||
|
||
if (!metadataUploadOk) { | ||
console.log(metadataUploadError); | ||
return; | ||
} | ||
|
||
const createdAt = Date.now(); | ||
|
||
const txn = await ipfontsContract.createFontProject( | ||
createdAt, | ||
createdAt, | ||
perCharacterMintPrice, | ||
mintLimit, | ||
process.env.NEXT_PUBLIC_SUPERFLUID_MATICX_TOKEN_ADDRESS, | ||
fontMetadataCID, | ||
fontFilesCID, | ||
{ gasLimit: 900000 } | ||
); | ||
console.log("IPFonts : Creating font project entity", txn.hash); | ||
|
||
await txn.wait(); | ||
console.log("IPFonts : Font project entity created", txn.hash); | ||
} catch(err) { | ||
console.log(err); | ||
} | ||
} |
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,23 @@ | ||
import { readContract } from '@wagmi/core' | ||
import connectContract from '../../utils/connectContract'; | ||
import abiJSON from "../../utils/FontProject.json"; | ||
|
||
const contractAddress = process.env.NEXT_PUBLIC_CONTRACT_ADDRESS; | ||
|
||
export async function getIPFontsUser({ | ||
address | ||
}) { | ||
const ipfontsContract = connectContract(); | ||
|
||
if (!ipfontsContract) { | ||
console.log('Cound not connect to contract'); | ||
return; | ||
} | ||
|
||
return await readContract({ | ||
address: contractAddress, | ||
abi: abiJSON.abi, | ||
functionName: 'addressToUser', | ||
args: [lensAddress] | ||
}); | ||
} |
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
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,41 @@ | ||
import { withIronSessionApiRoute } from 'iron-session/next'; | ||
import ironOptions from '../../config/ironOptions'; | ||
import { storeMetadataFileIPFS } from '../../utils/storeMetadataFileIPFS'; | ||
|
||
async function handler(req, res) { | ||
if (req.method === "POST") { | ||
// Check that user has signed in and is authorized to uplaod files | ||
if (!req.session.siwe) { | ||
return res.status(401).json({ message: 'You have to sign-in first' }); | ||
} | ||
|
||
return await storeFontMetadata(req, res); | ||
} else { | ||
return res | ||
.setHeader('Allow', ['POST']) | ||
.status(405) | ||
.json({ message: "Method not allowed", success: false }); | ||
} | ||
} | ||
|
||
async function storeFontMetadata(req, res) { | ||
const body = req.body; | ||
|
||
try { | ||
const file = { | ||
path : '/tmp/data.json', | ||
content: Buffer.from(body) | ||
}; | ||
|
||
const cid = await storeMetadataFileIPFS(file); | ||
|
||
return res.status(200).json({ ok: true, cid: cid }); | ||
} catch (err) { | ||
console.log(err); | ||
return res | ||
.status(500) | ||
.json({ error: "Error uploading font metadata", ok: false }); | ||
} | ||
} | ||
|
||
export default withIronSessionApiRoute(handler, ironOptions) |
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,26 @@ | ||
import { create } from 'ipfs-http-client' | ||
|
||
function makeInfuraStorageClient() { | ||
const idKeySecretPair = `${process.env.INFURA_IPFS_PROJECT_ID}:${process.env.INFURA_IPFS_KEY_SECRET}`; | ||
const auth = 'Basic ' + Buffer.from(idKeySecretPair).toString('base64'); | ||
|
||
return create({ | ||
host: process.env.INFURA_IPFS_HOST, | ||
port: process.env.INFURA_IPFS_PORT, | ||
protocol: 'https', | ||
headers: { | ||
authorization: auth, | ||
}, | ||
}); | ||
} | ||
|
||
export async function storeMetadataFileIPFS(file) { | ||
const client = makeInfuraStorageClient(); | ||
|
||
const result = await client.add({ | ||
path : file.path, | ||
content : file.content | ||
}); | ||
|
||
return result.cid.toString(); | ||
} |
Oops, something went wrong.
8f582d4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
app-interplanetaryfonts – ./
app-interplanetaryfonts-interplanetaryfonts.vercel.app
app-interplanetaryfonts-git-master-interplanetaryfonts.vercel.app
app-interplanetaryfonts.vercel.app
www.interplanetaryfonts.xyz
www.ipfonts.xyz
interplanetaryfonts.xyz
ipfonts.xyz