Skip to content

Commit

Permalink
added tx and email frame
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavyagor12 committed Jun 30, 2024
1 parent 574af52 commit 8f8fe23
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 18 deletions.
35 changes: 21 additions & 14 deletions packages/nextjs/app/api/orchestrator/[frameId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,32 @@ async function getResponse(req: NextRequest): Promise<NextResponse> {
const frameId = url.replace(`/api/orchestrator`, "");
const body = await req.json();
console.log("body", body);
const state = JSON.parse(decodeURIComponent(body.untrustedData.state as string));
console.log("state", state);
// Creating Analytics for the frame asynchronously
storeAnalytics(body, state).catch(err => console.error("Error Saving Analytics", err));
// Adding State for Button Press and Inputted Text on last frame
state.frame_id = frameId;
const stateUpdate = {
...state,
[`${frameId}ButtonPressed`]: body.untrustedData.buttonIndex,
[`${frameId}InputtedText`]: body.untrustedData.inputText,
};
const state = JSON.parse(decodeURIComponent(body.untrustedData?.state as string));
let stateUpdate
if (state) {
console.log("state", state);
// Creating Analytics for the frame asynchronously
storeAnalytics(body, state).catch(err => console.error("Error Saving Analytics", err));
// Adding State for Button Press and Inputted Text on last frame
state.frame_id = frameId;
stateUpdate = {
...state,
[`${frameId}ButtonPressed`]: body.untrustedData.buttonIndex,
[`${frameId}InputtedText`]: body.untrustedData.inputText,
};
}

const dbFrame = await getFrameAtServer(frameId);
if (!dbFrame) {
return new NextResponse(JSON.stringify({ message: "Frame not found" }), { status: 404 });
}
const nextFrame = dbFrame.frameJson;
nextFrame.state = {
...stateUpdate,
};
if (state) {
nextFrame.state = {
...stateUpdate
};
}

return new NextResponse(getFrameHtmlResponse(nextFrame));
}

Expand Down
8 changes: 6 additions & 2 deletions packages/nextjs/app/api/shopify/products/route.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { NextResponse } from "next/dist/server/web/spec-extension/response";
import { NextRequest } from "next/server";
import { getShopifyProducts } from "~~/services/shopify/fetchProducts";

// get all frames
export async function GET() {
const products = await getShopifyProducts();
export async function POST(request: NextRequest) {
const req = request as NextRequest;
const body = await req.json();
const { storeName, apiKey } = body;
const products = await getShopifyProducts(storeName, apiKey);
const responseBody = JSON.stringify(products);

return new NextResponse(responseBody, {
Expand Down
52 changes: 50 additions & 2 deletions packages/nextjs/components/ShopifyModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState } from "react";
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, TextField } from "@mui/material";
import { createJourney } from "~~/services/frames";
import { getShopifyProducts } from "~~/services/shopify/fetchProducts";
import { notification } from "~~/utils/scaffold-eth";

interface ModalProps {
isOpen: boolean;
Expand All @@ -18,8 +20,54 @@ const ShopifyModal: React.FC<ModalProps> = ({ isOpen, onClose }) => {
};

const onAddButton = async () => {
const products = await getShopifyProducts(storeName, apiKey);
console.log(products);
try {
const response = await fetch(`/api/shopify/products`, {
method: "POST",
headers: new Headers({
"Content-Type": "application/json",
}),
body: JSON.stringify({
storeName,
apiKey,
}),
});

if (!response.ok) {
throw new Error("Failed to fetch products");
}

const products = await response.json();
if (!products || products.length === 0) {
notification.error("No products found");
return;
}

const createJourneyPromises = products.map((product: any) => {
const { title, image, body_html, variants } = product;
const variant = variants[0];
console.log({ title, image: image.src, body_html, price: variant.price, productId: variant.product_id });

return createJourney({
name: title,
price: variant.price,
desc: body_html,
image: image.src,
quantity: 10,
})
.then(data => {
console.log(data);
})
.catch(error => {
console.error(`Error creating journey for product ${title}:`, error);
});
});

await Promise.all(createJourneyPromises);
console.log("All createJourney calls completed");
} catch (error) {
console.error("Error in onAddButton:", error);
notification.error("An error occurred while adding products");
}
};
return (
<Dialog open={isOpen} onClose={handleClose} className="fixed z-50 overflow-y-auto w-[100%]">
Expand Down
118 changes: 118 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,7 @@ __metadata:
eslint-config-next: ^14.0.4
eslint-config-prettier: ^8.5.0
eslint-plugin-prettier: ^4.2.1
html-react-parser: ^5.1.10
mongoose: ^8.2.4
next: ^14.0.4
next-themes: ^0.2.1
Expand Down Expand Up @@ -6373,6 +6374,44 @@ __metadata:
languageName: node
linkType: hard

"dom-serializer@npm:^2.0.0":
version: 2.0.0
resolution: "dom-serializer@npm:2.0.0"
dependencies:
domelementtype: ^2.3.0
domhandler: ^5.0.2
entities: ^4.2.0
checksum: cd1810544fd8cdfbd51fa2c0c1128ec3a13ba92f14e61b7650b5de421b88205fd2e3f0cc6ace82f13334114addb90ed1c2f23074a51770a8e9c1273acbc7f3e6
languageName: node
linkType: hard

"domelementtype@npm:^2.3.0":
version: 2.3.0
resolution: "domelementtype@npm:2.3.0"
checksum: ee837a318ff702622f383409d1f5b25dd1024b692ef64d3096ff702e26339f8e345820f29a68bcdcea8cfee3531776b3382651232fbeae95612d6f0a75efb4f6
languageName: node
linkType: hard

"domhandler@npm:5.0.3, domhandler@npm:^5.0.2, domhandler@npm:^5.0.3":
version: 5.0.3
resolution: "domhandler@npm:5.0.3"
dependencies:
domelementtype: ^2.3.0
checksum: 0f58f4a6af63e6f3a4320aa446d28b5790a009018707bce2859dcb1d21144c7876482b5188395a188dfa974238c019e0a1e610d2fc269a12b2c192ea2b0b131c
languageName: node
linkType: hard

"domutils@npm:^3.1.0":
version: 3.1.0
resolution: "domutils@npm:3.1.0"
dependencies:
dom-serializer: ^2.0.0
domelementtype: ^2.3.0
domhandler: ^5.0.3
checksum: e5757456ddd173caa411cfc02c2bb64133c65546d2c4081381a3bafc8a57411a41eed70494551aa58030be9e58574fcc489828bebd673863d39924fb4878f416
languageName: node
linkType: hard

"dotenv@npm:^16.0.3":
version: 16.4.5
resolution: "dotenv@npm:16.4.5"
Expand Down Expand Up @@ -6561,6 +6600,13 @@ __metadata:
languageName: node
linkType: hard

"entities@npm:^4.2.0, entities@npm:^4.5.0":
version: 4.5.0
resolution: "entities@npm:4.5.0"
checksum: 853f8ebd5b425d350bffa97dd6958143179a5938352ccae092c62d1267c4e392a039be1bae7d51b6e4ffad25f51f9617531fedf5237f15df302ccfb452cbf2d7
languageName: node
linkType: hard

"env-paths@npm:^2.2.0":
version: 2.2.1
resolution: "env-paths@npm:2.2.1"
Expand Down Expand Up @@ -8879,6 +8925,46 @@ __metadata:
languageName: node
linkType: hard

"html-dom-parser@npm:5.0.8":
version: 5.0.8
resolution: "html-dom-parser@npm:5.0.8"
dependencies:
domhandler: 5.0.3
htmlparser2: 9.1.0
checksum: f264d58665ab1c49e84b9aa28aad4366b5661a9ed742d40827315ba2b8a2915d16624ec517c743421e5543cc7eeb62c0cadfb07b1399d5f11fecf6611861b04d
languageName: node
linkType: hard

"html-react-parser@npm:^5.1.10":
version: 5.1.10
resolution: "html-react-parser@npm:5.1.10"
dependencies:
domhandler: 5.0.3
html-dom-parser: 5.0.8
react-property: 2.0.2
style-to-js: 1.1.12
peerDependencies:
"@types/react": 17 || 18
react: 0.14 || 15 || 16 || 17 || 18
peerDependenciesMeta:
"@types/react":
optional: true
checksum: b304921bd085dc6ac3979e7c9f1d4ebb096b135e2f3bdeccccfa2e93023051ec8c17a9255d0c50db757cdde14ad9f1a37305f327a3ef25f19c647547d7e155c5
languageName: node
linkType: hard

"htmlparser2@npm:9.1.0":
version: 9.1.0
resolution: "htmlparser2@npm:9.1.0"
dependencies:
domelementtype: ^2.3.0
domhandler: ^5.0.3
domutils: ^3.1.0
entities: ^4.5.0
checksum: e5f8d5193967e4a500226f37bdf2c0f858cecb39dde14d0439f24bf2c461a4342778740d988fbaba652b0e4cb6052f7f2e99e69fc1a329a86c629032bb76e7c8
languageName: node
linkType: hard

"http-basic@npm:^8.1.1":
version: 8.1.3
resolution: "http-basic@npm:8.1.3"
Expand Down Expand Up @@ -9136,6 +9222,13 @@ __metadata:
languageName: node
linkType: hard

"inline-style-parser@npm:0.2.3":
version: 0.2.3
resolution: "inline-style-parser@npm:0.2.3"
checksum: ed6454de80759e7faef511f51b5716b33c40a6b05b8a8f5383dc01e8a087c6fd5df877446d05e8e3961ae0751e028e25e180f5cffc192a5ce7822edef6810ade
languageName: node
linkType: hard

"internal-slot@npm:^1.0.4, internal-slot@npm:^1.0.7":
version: 1.0.7
resolution: "internal-slot@npm:1.0.7"
Expand Down Expand Up @@ -12282,6 +12375,13 @@ __metadata:
languageName: node
linkType: hard

"react-property@npm:2.0.2":
version: 2.0.2
resolution: "react-property@npm:2.0.2"
checksum: c67fb2590dad9102239b2e574fbc078b472e227b66c3d64e1949426e33889d78c2ac5369cc4c740bb8fe61665505940e39a78d113261ac52410f7538089fe367
languageName: node
linkType: hard

"react-remove-scroll-bar@npm:^2.3.4":
version: 2.3.6
resolution: "react-remove-scroll-bar@npm:2.3.6"
Expand Down Expand Up @@ -13608,6 +13708,24 @@ __metadata:
languageName: node
linkType: hard

"style-to-js@npm:1.1.12":
version: 1.1.12
resolution: "style-to-js@npm:1.1.12"
dependencies:
style-to-object: 1.0.6
checksum: 8c66706981d600f4384c929a7072a89b25efa96625d72738bc001403397838806d8de5f41186d8d0771efa833f05fc4bfee3fc607622a37798625ecf498f7622
languageName: node
linkType: hard

"style-to-object@npm:1.0.6":
version: 1.0.6
resolution: "style-to-object@npm:1.0.6"
dependencies:
inline-style-parser: 0.2.3
checksum: 5b58295dcc2c21f1da1b9308de1e81b4a987b876a177e677453a76b2e3151a0e21afc630e99c1ea6c82dd8dbec0d01a8b1a51a829422aca055162b03e52572a9
languageName: node
linkType: hard

"styled-jsx@npm:5.1.1":
version: 5.1.1
resolution: "styled-jsx@npm:5.1.1"
Expand Down

0 comments on commit 8f8fe23

Please sign in to comment.