-
Notifications
You must be signed in to change notification settings - Fork 146
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
added new contract task type in the admin dashboard #843
Changes from 2 commits
8cd7973
3607c21
a14e4ed
1d05f15
0dc904c
6a85acf
077bb2b
54db25b
a52008e
8c6d97b
bf2e368
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ type StepMap = | |
| { type: "Custom"; data: WithNewField<CustomInputType, "id", number> } | ||
| { type: "Domain"; data: WithNewField<DomainInputType, "id", number> } | ||
| { type: "Balance"; data: WithNewField<BalanceInputType, "id", number> } | ||
| { type: "Contract"; data: WithNewField<ContractInputType, "id", number> } | ||
| { type: "None"; data: object }; | ||
|
||
export default function Page({ params }: QuestIdProps) { | ||
|
@@ -215,6 +216,18 @@ export default function Page({ params }: QuestIdProps) { | |
balance_href: task.href, | ||
}, | ||
}; | ||
} else if (task.task_type === "contract") { | ||
return { | ||
type: "Contract", | ||
data: { | ||
id: task.id, | ||
contract_name: task.name, | ||
contract_desc: task.desc, | ||
contract_href: task.href, | ||
contract_cta: task.cta, | ||
contract_calls: task.calls, | ||
}, | ||
}; | ||
} | ||
}); | ||
|
||
|
@@ -509,6 +522,15 @@ export default function Page({ params }: QuestIdProps) { | |
cta: step.data.balance_cta, | ||
href: step.data.balance_href, | ||
}); | ||
} else if (step.type === "Contract") { | ||
await AdminService.createContract({ | ||
quest_id: questId.current, | ||
name: step.data.contract_name, | ||
desc: step.data.contract_desc, | ||
href: step.data.contract_href, | ||
cta: step.data.contract_cta, | ||
calls: step.data.calls, | ||
}); | ||
} | ||
} catch (error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this catch, you can add showNotification(`Error adding ${step.type} task: ${error}`, "error"); So that if there is any issue while parsing the JSON, the user is instantly informed |
||
console.error(`Error adding task of type ${step.type}:`, error); | ||
|
@@ -607,6 +629,15 @@ export default function Page({ params }: QuestIdProps) { | |
cta: step.data.balance_cta, | ||
href: step.data.balance_href, | ||
}); | ||
} else if (step.type === "Contract") { | ||
await AdminService.updateContract({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also you could wrap this call with a try catch and add show Notification(`Error updating ${step.type} task: ${error}`, "error"); in the catch |
||
id: step.data.id, | ||
name: step.data.contract_name, | ||
desc: step.data.contract_desc, | ||
href: step.data.contract_href, | ||
cta: step.data.contract_cta, | ||
calls: step.data.calls, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here for JSON.parse() |
||
}); | ||
} | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import DomainStep from "../taskSteps/domainStep"; | |
import Typography from "@components/UI/typography/typography"; | ||
import { TEXT_TYPE } from "@constants/typography"; | ||
import BalanceStep from "../taskSteps/balanceStep"; | ||
import ContractStep from "../taskSteps/contractStep"; | ||
|
||
type TaskDetailsFormProps = { | ||
steps: StepMap[]; | ||
|
@@ -104,6 +105,14 @@ const TaskDetailsForm: FunctionComponent<TaskDetailsFormProps> = ({ | |
step={step} | ||
/> | ||
); | ||
} else if (step?.type === "Contract") { | ||
return ( | ||
<ContractStep | ||
Comment on lines
+109
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing closing parenthesis |
||
handleTasksInputChange={handleTasksInputChange} | ||
index={currentTask} | ||
step={step} | ||
/> | ||
); | ||
} | ||
}; | ||
return ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { FunctionComponent } from "react"; | ||
import TextInput from "../textInput"; | ||
|
||
type ContractStepProps = { | ||
handleTasksInputChange: ( | ||
e: React.ChangeEvent<HTMLInputElement>, | ||
index: number | ||
) => void; | ||
step: StepMap; | ||
index: number; | ||
}; | ||
Marchand-Nicolas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const ContractStep: FunctionComponent<ContractStepProps> = ({ | ||
handleTasksInputChange, | ||
step, | ||
index, | ||
}) => { | ||
return ( | ||
<div className="flex flex-col gap-4 pt-2"> | ||
<TextInput | ||
onChange={(e) => handleTasksInputChange(e, index)} | ||
value={step.data.contract_name || ""} | ||
name="contract_name" | ||
label="Name" | ||
placeholder="Name" | ||
/> | ||
<TextInput | ||
onChange={(e) => handleTasksInputChange(e, index)} | ||
value={step.data.contract_desc || ""} | ||
name="contract_desc" | ||
label="Description" | ||
placeholder="Description" | ||
multiline={4} | ||
/> | ||
<TextInput | ||
onChange={(e) => handleTasksInputChange(e, index)} | ||
value={step.data.contract_href || ""} | ||
name="contract_href" | ||
label="URL" | ||
placeholder="URL" | ||
/> | ||
<TextInput | ||
onChange={(e) => handleTasksInputChange(e, index)} | ||
value={step.data.contract_cta || ""} | ||
name="contract_cta" | ||
label="CTA" | ||
placeholder="CTA" | ||
/> | ||
<TextInput | ||
onChange={(e) => handleTasksInputChange(e, index)} | ||
value={step.data.calls || ""} | ||
PoulavBhowmick03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name="calls" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still not working, because here it should be |
||
label="Calls (JSON)" | ||
placeholder='e.g.: [{ "contract": "0x...", "entry_point": "transfer", "call_data": ["0x..."], "regex": "..." }]' | ||
multiline={4} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ContractStep; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -315,7 +315,8 @@ type StepMap = | |
| { type: "Custom"; data: CustomInputType } | ||
| { type: "None"; data: object } | ||
| { type: "Domain"; data: DomainInputType } | ||
| { type: "Balance"; data: BalanceInputType }; | ||
| { type: "Balance"; data: BalanceInputType } | ||
| { type: "Contract"; data: ContractInputType }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the ";" at the end of this line |
||
|
||
type CustomInputType = typeof CustomInput; | ||
type DiscordInputType = typeof DiscordInput; | ||
|
@@ -324,6 +325,7 @@ type QuizInputType = typeof QuizDefaultInput; | |
type TwitterFwInputType = typeof TwitterFwInput; | ||
type TwitterRwInputType = typeof TwitterRwInput; | ||
type BalanceInputType = typeof BalanceInput; | ||
type ContractInputType = typeof ContractInput; | ||
type TaskType = | ||
| "Quiz" | ||
| "TwitterFw" | ||
|
@@ -332,6 +334,7 @@ type TaskType = | |
| "TwitterRw" | ||
| "Domain" | ||
| "Balance" | ||
| "Contract" | ||
| "None"; | ||
|
||
type networks = "MAINNET" | "TESTNET"; |
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.
Here, this needs to be an object, not a string. You can simply use JSON.parse()