Skip to content

Commit

Permalink
Merge branch 'testnet' into feat/update-sid.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchand-Nicolas committed Oct 7, 2024
2 parents 61edb4a + 833faea commit 04473e9
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 52 deletions.
19 changes: 17 additions & 2 deletions app/admin/quests/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export default function Page() {
} catch (error) {
console.error("Error while creating balance task:", error);
}
}else if (step.type === "CustomApi") {
} else if (step.type === "CustomApi") {
try {
await AdminService.createCustomApi({
quest_id: questId,
Expand All @@ -383,6 +383,21 @@ export default function Page() {
} catch (error) {
console.error("Error while creating balance task:", error);
}

} else if (step.type === "Contract") {
try {
await AdminService.createContract({
quest_id: questId,
name: step.data.contract_name,
desc: step.data.contract_desc,
href: step.data.contract_href,
cta: step.data.contract_cta,
calls: JSON.parse(step.data.contract_calls),
});
} catch (error) {
console.error("Error while creating contract task:", error);
showNotification(`Error adding ${step.type} task: ${error}`, "error");
}
}
});
setButtonLoading(false);
Expand Down Expand Up @@ -480,7 +495,7 @@ export default function Page() {
<AdminQuestDetails
quest={finalQuestData}
// eslint-disable-next-line @typescript-eslint/no-empty-function
setShowDomainPopup={() => {}}
setShowDomainPopup={() => { }}
hasRootDomain={false}
rewardButtonTitle={finalQuestData.disabled ? "Enable" : "Disable"}
onRewardButtonClick={async () => {
Expand Down
39 changes: 37 additions & 2 deletions app/admin/quests/dashboard/[questId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: "CustomApi"; data: WithNewField<CustomApiInputType, "id", number> }
| { type: "None"; data: object };

Expand Down Expand Up @@ -216,6 +217,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,
},
};
} else if(task.task_type === "custom_api"){
return {
type: "CustomApi",
Expand Down Expand Up @@ -524,6 +537,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: JSON.parse(step.data.contract_calls),
});
}
else if(step.type === "CustomApi"){
await AdminService.createCustomApi({
Expand All @@ -537,7 +559,7 @@ export default function Page({ params }: QuestIdProps) {
})
}
} catch (error) {
console.error(`Error adding task of type ${step.type}:`, error);
showNotification(`Error adding ${step.type} task: ${error}`, "error");
}
}
}, []);
Expand Down Expand Up @@ -633,6 +655,19 @@ export default function Page({ params }: QuestIdProps) {
cta: step.data.balance_cta,
href: step.data.balance_href,
});
} else if (step.type === "Contract") {
try {
await AdminService.updateContract({
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: JSON.parse(step.data.contract_calls),
});
} catch (error) {
showNotification(`Error updating ${step.type} task: ${error}`, "error");
}
} else if (step.type === "CustomApi") {
await AdminService.updateCustomApi({
id: step.data.id,
Expand Down Expand Up @@ -782,7 +817,7 @@ export default function Page({ params }: QuestIdProps) {
<AdminQuestDetails
quest={questData}
// eslint-disable-next-line @typescript-eslint/no-empty-function
setShowDomainPopup={() => {}}
setShowDomainPopup={() => { }}
hasRootDomain={false}
rewardButtonTitle={questData.disabled ? "Enable" : "Disable"}
onRewardButtonClick={async () => {
Expand Down
2 changes: 1 addition & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function RootLayout({
<body className="default_background_color">
<Providers>
<Navbar />
<main>
<main className="mt-[48px]">
{children}
</main>
<Footer />
Expand Down
47 changes: 47 additions & 0 deletions components/UI/CopyAddress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useState } from 'react';
import CopyIcon from "@components/UI/iconsComponents/icons/copyIcon";
import VerifiedIcon from "@components/UI/iconsComponents/icons/verifiedIcon";
import Typography from "@components/UI/typography/typography";
import { TEXT_TYPE } from "@constants/typography";

interface CopyAddressProps {
address: string;
className?: string;
iconSize?: string;
wallet:boolean;
}

const CopyAddress: React.FC<CopyAddressProps> = ({ address, className, iconSize = "24",wallet=false }) => {
const [copied, setCopied] = useState(false);


const copyAddress = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
setCopied(true);
navigator.clipboard.writeText(address ?? "");
setTimeout(() => {
setCopied(false);
}, 1500);
};

return (
<button className={className} onClick={copyAddress}>
{!copied ? (
<CopyIcon width={iconSize} color={wallet ? undefined : "#F4FAFF"} />
) : (
<VerifiedIcon width={iconSize} />
)}
{wallet && (
<Typography
color="secondary500"
type={TEXT_TYPE.BUTTON_SMALL}
style={{ textTransform: 'none', }}
>
Copy Address
</Typography>
)}
</button>
);
};

export default CopyAddress;
26 changes: 7 additions & 19 deletions components/UI/profileCard/profileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import useCreationDate from "@hooks/useCreationDate";
import shareSrc from "public/icons/share.svg";
import theme from "@styles/theme";
import { Skeleton, Tooltip } from "@mui/material";
import VerifiedIcon from "../iconsComponents/icons/verifiedIcon";
import CopyAddress from "@components/UI/CopyAddress";
import ProfilIcon from "../iconsComponents/icons/profilIcon";
import Link from "next/link";
import SocialMediaActions from "../actions/socialmediaActions";
Expand All @@ -41,13 +41,6 @@ const ProfileCard: FunctionComponent<ProfileCard> = ({
const [userPercentile, setUserPercentile] = useState("");
const [userXp, setUserXp] = useState<number>();

const copyToClipboard = () => {
setCopied(true);
writeToClipboard(identity?.owner);
setTimeout(() => {
setCopied(false);
}, 1500);
};

const rankFormatter = useCallback((rank: number) => {
if (rank > 10000) return "+10k";
Expand Down Expand Up @@ -111,17 +104,12 @@ const ProfileCard: FunctionComponent<ProfileCard> = ({
</Typography>
<Typography type={TEXT_TYPE.H2} className={styles.profile_name}>{identity.domain.domain}</Typography>
<div className={styles.address_div}>
<div onClick={() => copyToClipboard()}>
{!copied ? (
<Tooltip title="Copy" arrow>
<div onClick={() => copyToClipboard()}>
<CopyIcon width="20" color="#F4FAFF" />
</div>
</Tooltip>
) : (
<VerifiedIcon width="20" />
)}
</div>
<CopyAddress
address={identity?.owner ?? ""}
iconSize="24"
className={styles.copyButton}
wallet={false}
/>
<Typography type={TEXT_TYPE.BODY_SMALL} className={styles.addressText} color="secondary">
{minifyAddress(addressOrDomain ?? identity?.owner, 8)}
</Typography>
Expand Down
19 changes: 14 additions & 5 deletions components/admin/formSteps/TaskDetailsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
import CustomApiStep from "../taskSteps/customApiStep"

type TaskDetailsFormProps = {
Expand Down Expand Up @@ -105,8 +106,16 @@ const TaskDetailsForm: FunctionComponent<TaskDetailsFormProps> = ({
step={step}
/>
);
} else if(step?.type === "CustomApi"){
return(
} else if (step?.type === "Contract") {
return (
<ContractStep
handleTasksInputChange={handleTasksInputChange}
index={currentTask}
step={step}
/>
);
} else if (step?.type === "CustomApi") {
return (
<CustomApiStep
handleTasksInputChange={handleTasksInputChange}
index={currentTask}
Expand Down Expand Up @@ -207,7 +216,7 @@ const TaskDetailsForm: FunctionComponent<TaskDetailsFormProps> = ({
] as TaskType,
data: getDefaultValues(
TWITTER_OPTIONS[
category as keyof typeof TWITTER_OPTIONS
category as keyof typeof TWITTER_OPTIONS
] as TaskType
),
};
Expand All @@ -220,12 +229,12 @@ const TaskDetailsForm: FunctionComponent<TaskDetailsFormProps> = ({
cursor: "pointer",
backgroundColor:
steps[currentTask]?.type ===
TWITTER_OPTIONS[category as keyof typeof TWITTER_OPTIONS]
TWITTER_OPTIONS[category as keyof typeof TWITTER_OPTIONS]
? "#ffffff"
: "#29282B",
color:
steps[currentTask]?.type ===
TWITTER_OPTIONS[category as keyof typeof TWITTER_OPTIONS]
TWITTER_OPTIONS[category as keyof typeof TWITTER_OPTIONS]
? "#29282B"
: "#ffffff",
}}
Expand Down
61 changes: 61 additions & 0 deletions components/admin/taskSteps/contractStep.tsx
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;
};

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.contract_calls || ""}
name="contract_calls"
label="Calls (JSON)"
placeholder='e.g.: [{ "contract": "0x...", "entry_point": "transfer", "call_data": ["0x..."], "regex": "..." }]'
multiline={4}
/>
</div>
);
};

export default ContractStep;
3 changes: 3 additions & 0 deletions components/discover/appIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const AppIcon = ({ app }: { app: string }) => {
if (appName.toLocaleLowerCase().includes("jediswap")) {
return "/jediswap/favicon.ico";
}
if (appName.toLocaleLowerCase().includes("haiko_solvers")) {
return "/haiko/favicon.ico";
}
return `/${appName.toLowerCase()}/favicon.ico`;
}, []);
return (
Expand Down
31 changes: 9 additions & 22 deletions components/navbar/walletButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import TrophyIcon from "@components/UI/iconsComponents/icons/trophyIcon";
import Typography from "@components/UI/typography/typography";
import { TEXT_TYPE } from "@constants/typography";
import { Connector } from "starknetkit";
import CopyAddress from "@components/UI/CopyAddress"; // Import the new CopyAddress component

type WalletButtonProps = {
setShowWallet: (showWallet: boolean) => void;
Expand Down Expand Up @@ -79,15 +80,6 @@ const WalletButton: FunctionComponent<WalletButtonProps> = ({
}
}, [notifications]);

const copyAddress = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
setCopied(true);
navigator.clipboard.writeText(address ?? "");
setTimeout(() => {
setCopied(false);
}, 1500);
};

const handleDisconnect = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation();
disconnectByClick();
Expand Down Expand Up @@ -167,19 +159,14 @@ const WalletButton: FunctionComponent<WalletButtonProps> = ({
</Typography>
</button>
</Link>
<button onClick={copyAddress}>
{copied ? (
<VerifiedIcon width="24" />
) : (
<CopyIcon width="24" />
)}
<Typography
color="secondary500"
type={TEXT_TYPE.BUTTON_SMALL}
>
Copy Address
</Typography>
</button>
<div className="flex items-center">
<CopyAddress
address={address ?? ""}
iconSize="24"
className={styles.copyButton}
wallet={true}
/>
</div>
{isWebWallet && (
<button onClick={handleOpenWebWallet}>
<ArgentIcon width="24" />
Expand Down
Loading

0 comments on commit 04473e9

Please sign in to comment.