-
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
Showing
5 changed files
with
261 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
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,8 +1,138 @@ | ||
import { FrameMetadataType } from "@coinbase/onchainkit"; | ||
import { DEFAULT_FRAME } from "~~/constants"; | ||
|
||
export const GetDefaultFrame = async (journey_id: string) => { | ||
let frame: FrameMetadataType = DEFAULT_FRAME; | ||
frame.state.journey_id = journey_id; | ||
return frame; | ||
}; | ||
import { FrameMetadataType } from "@coinbase/onchainkit"; | ||
import { APP_URL, DEFAULT_FRAME, txFrame } from "~~/constants"; | ||
|
||
export const GetDefaultFrame = async (journey_id: string) => { | ||
const frame: FrameMetadataType = DEFAULT_FRAME; | ||
if (frame.state) { | ||
frame.state.journey_id = journey_id; | ||
} | ||
return frame; | ||
}; | ||
|
||
export const GetProductFrame = async ( | ||
journey_id: string, | ||
frame_id: string, | ||
frame_id_2: string, | ||
frame_id_3: string, | ||
productImage: any, | ||
) => { | ||
const PRODUCT_FRAME: FrameMetadataType = { | ||
buttons: [ | ||
{ | ||
action: "post", | ||
target: APP_URL + "/api/orchestrator/" + frame_id_2, | ||
label: "Get Details", | ||
}, | ||
{ | ||
action: "post", | ||
target: APP_URL + "/api/orchestrator/" + frame_id_3, | ||
label: "Buy Now", | ||
}, | ||
], | ||
image: { | ||
src: productImage, | ||
}, | ||
state: { | ||
journey_id: journey_id, | ||
frame_id: frame_id, | ||
}, | ||
}; | ||
return PRODUCT_FRAME; | ||
}; | ||
|
||
export const GetDescriptionFrame = async ( | ||
journey_id: string, | ||
frame_id: string, | ||
next_frame_id: string, | ||
productDesc: string, | ||
) => { | ||
const DESCRIPTION_FRAME: FrameMetadataType = { | ||
buttons: [ | ||
{ | ||
action: "post", | ||
target: APP_URL + "/api/orchestrator/" + next_frame_id, | ||
label: "Buy Now", | ||
}, | ||
], | ||
image: { | ||
src: "https://via.placeholder.com/150", | ||
}, | ||
state: { | ||
journey_id: journey_id, | ||
frame_id: frame_id, | ||
}, | ||
}; | ||
return DESCRIPTION_FRAME; | ||
}; | ||
|
||
export const GetEmailFrame = async ( | ||
journey_id: string, | ||
frame_id: string, | ||
next_frame_id: string, | ||
productImage: string, | ||
) => { | ||
const EMAIL_FRAME: FrameMetadataType = { | ||
buttons: [ | ||
{ | ||
action: "post", | ||
target: APP_URL + "/api/orchestrator/" + next_frame_id, | ||
label: "Next", | ||
}, | ||
], | ||
image: { | ||
src: productImage, | ||
}, | ||
state: { | ||
journey_id: journey_id, | ||
frame_id: frame_id, | ||
}, | ||
input: { | ||
text: "Enter your email address", | ||
}, | ||
}; | ||
return EMAIL_FRAME; | ||
}; | ||
|
||
export const GetBuyFrame = async (journey_id: string, frame_id: string, next_frame_id: string) => { | ||
const newTxFrame = { | ||
buttons: [ | ||
{ | ||
action: "tx", | ||
label: "Buy", | ||
postUrl: `${APP_URL}/api/orchestrator/` + next_frame_id, | ||
target: `${APP_URL}/api/orchestrator/tx`, | ||
}, | ||
], | ||
image: { | ||
src: `https://amber-causal-cougar-937.mypinata.cloud/ipfs/QmafH4oZDZWFynGyK9gHVvPRFTTFFrbwYwGQNps4FDLky2`, | ||
}, | ||
input: { | ||
text: "Enter No of items", | ||
}, | ||
state: { | ||
journey_id: journey_id, | ||
frame_id: frame_id, | ||
}, | ||
} as FrameMetadataType; | ||
return newTxFrame; | ||
}; | ||
|
||
export const GetSuccessFrame = async (journey_id: string, frame_id: string) => { | ||
const SUCCESS_FRAME: FrameMetadataType = { | ||
image: { | ||
src: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTW_BNf9b9fUN735sATwS1OfxlfV-LD9RhVMA&s", | ||
}, | ||
state: { | ||
journey_id: journey_id, | ||
frame_id: frame_id, | ||
}, | ||
buttons: [ | ||
{ | ||
action: "link", | ||
target: APP_URL, | ||
label: "Finish", | ||
}, | ||
], | ||
}; | ||
return SUCCESS_FRAME; | ||
}; |
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,76 @@ | ||
import { createFrame, saveFrame, saveJourney } from "../frames"; | ||
import { | ||
GetBuyFrame, | ||
GetDescriptionFrame, | ||
GetEmailFrame, | ||
GetProductFrame, | ||
GetQuantityFrame, | ||
GetSuccessFrame, | ||
} from "./frameGetters"; | ||
import { FrameMetadataType } from "@coinbase/onchainkit"; | ||
import { emailFrame } from "~~/constants"; | ||
|
||
export const initJourneyWithFrames = async ( | ||
journeyId: string, | ||
productPrice: string, | ||
productDesc: string, | ||
productImage: string, | ||
) => { | ||
const Frames = []; | ||
for (let i = 0; i <= 4; i++) { | ||
const frameBody: FrameMetadataType = { | ||
image: "https://via.placeholder.com/150", | ||
}; | ||
const Frame = await createFrame({ | ||
name: "Frame", | ||
frameJson: frameBody, | ||
}); | ||
Frames.push(Frame._id); | ||
} | ||
// First Frame | ||
const ProductFrameJson = await GetProductFrame(journeyId, Frames[0], Frames[1], Frames[2], productImage); | ||
const status = await saveFrame({ | ||
_id: Frames[0], | ||
name: "Product Frame", | ||
frameJson: ProductFrameJson, | ||
}); | ||
console.log("Product Frame Status", status); | ||
// Second Frame | ||
const DescriptionFrameJson = await GetDescriptionFrame(journeyId, Frames[1], Frames[2], productDesc); | ||
const desStatus = await saveFrame({ | ||
_id: Frames[1], | ||
name: "Description Frame", | ||
frameJson: DescriptionFrameJson, | ||
}); | ||
console.log("Description Frame Status", desStatus); | ||
// Third Frame | ||
const emailFrameJson = await GetEmailFrame(journeyId, Frames[2], Frames[3], productImage); | ||
const emailFrameStatus = await saveFrame({ | ||
_id: Frames[2], | ||
name: "Email Frame", | ||
frameJson: emailFrameJson, | ||
}); | ||
console.log("Email Frame Status", emailFrameStatus); | ||
// Fourth Frame | ||
const BuyFrameJson = await GetBuyFrame(journeyId, Frames[3], Frames[4]); | ||
const buyStatus = await saveFrame({ | ||
_id: Frames[3], | ||
name: "Buy Frame", | ||
frameJson: BuyFrameJson, | ||
}); | ||
console.log("Buy Frame Status", buyStatus); | ||
//Fifth Frame | ||
const SuccessFrameJson = await GetSuccessFrame(journeyId, Frames[4]); | ||
const sucStatus = await saveFrame({ | ||
_id: Frames[4], | ||
name: "Success Frame", | ||
frameJson: SuccessFrameJson, | ||
}); | ||
console.log("Success Frame Status", sucStatus); | ||
// Saving to journey | ||
const journey = await saveJourney({ | ||
_id: journeyId, | ||
frames: Frames, | ||
}); | ||
return journey; | ||
}; |