Skip to content
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

fix: avatar selection confirmation #849

Open
wants to merge 9 commits into
base: testnet
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions components/UI/modalProfilePic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import ClickableAction from "./iconsComponents/clickableAction";
import theme from "../../styles/theme";
import DoneFilledIcon from "./iconsComponents/icons/doneFilledIcon";
import ArrowLeftIcon from "./iconsComponents/icons/arrowLeftIcon";
import { useContractWrite } from "@starknet-react/core";
import { Call } from "starknet";
import identityChangeCalls from "../../utils/callData/identityChangeCalls";
import { hexToDecimal, toUint256 } from "../../utils/feltService";
import { getImgUrl } from "../../utils/stringService";
import { useNotificationManager } from "../../hooks/useNotificationManager";
import { NotificationType, TransactionType } from "../../utils/constants";
import { useAccount } from "@starknet-react/core";

type ModalProfilePicProps = {
closeModal: (cancel: boolean) => void;
Expand All @@ -31,10 +31,8 @@ const ModalProfilePic: FunctionComponent<ModalProfilePicProps> = ({
tokenId,
}) => {
const [callData, setCallData] = useState<Call[]>([]);
const { account } = useAccount();
const { addTransaction } = useNotificationManager();
const { writeAsync: execute, data: updateData } = useContractWrite({
calls: callData,
});

useEffect(() => {
if (!nftData) return;
Expand All @@ -49,22 +47,23 @@ const ModalProfilePic: FunctionComponent<ModalProfilePicProps> = ({
]);
}, [nftData, tokenId]);

useEffect(() => {
if (!updateData?.transaction_hash) return;
addTransaction({
timestamp: Date.now(),
subtext: `For identity ${tokenId}`,
type: NotificationType.TRANSACTION,
data: {
type: TransactionType.SET_PFP,
hash: updateData.transaction_hash,
status: "pending",
},
const confirm = () => {
if (!account) return;
account.execute(callData).then((tx) => {
addTransaction({
timestamp: Date.now(),
subtext: `For identity ${tokenId}`,
type: NotificationType.TRANSACTION,
data: {
type: TransactionType.SET_PFP,
hash: tx.transaction_hash,
status: "pending",
},
});
setPfpTxHash(tx.transaction_hash);
closeModal(false);
});
setPfpTxHash(updateData.transaction_hash);
closeModal(false);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [updateData]); // We want to trigger this only when the tx passed
};
Marchand-Nicolas marked this conversation as resolved.
Show resolved Hide resolved

return (
<Modal
Expand Down Expand Up @@ -106,7 +105,7 @@ const ModalProfilePic: FunctionComponent<ModalProfilePicProps> = ({
/>
}
description=""
onClick={() => execute()}
onClick={confirm}
/>
<div className={ppStyles.modalBack} onClick={() => closeModal(true)}>
Marchand-Nicolas marked this conversation as resolved.
Show resolved Hide resolved
<ArrowLeftIcon width="24" color={theme.palette.secondary.main} />
Expand Down