Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchand-Nicolas committed Jun 29, 2024
1 parent b8ec512 commit df8466a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
45 changes: 18 additions & 27 deletions components/UI/modalProfilePic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ 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;
isModalOpen: boolean;
nftData: StarkscanNftProps;
tokenId: string;
setPfpTxHash: (hash: string) => void;
back: () => void;
};

const ModalProfilePic: FunctionComponent<ModalProfilePicProps> = ({
Expand All @@ -30,13 +29,10 @@ const ModalProfilePic: FunctionComponent<ModalProfilePicProps> = ({
isModalOpen,
nftData,
tokenId,
back,
}) => {
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 @@ -51,27 +47,22 @@ 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

const handleConfirm = () => {
execute();
closeModal(false);
back();
};

return (
Expand Down Expand Up @@ -114,7 +105,7 @@ const ModalProfilePic: FunctionComponent<ModalProfilePicProps> = ({
/>
}
description=""
onClick={handleConfirm}
onClick={confirm}
/>
<div className={ppStyles.modalBack} onClick={() => closeModal(true)}>
<ArrowLeftIcon width="24" color={theme.palette.secondary.main} />
Expand Down
1 change: 0 additions & 1 deletion components/identities/updateProfilePic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const UpdateProfilePic: FunctionComponent<UpdateProfilePicProps> = ({
nftData={selectedPfp as StarkscanNftProps}
tokenId={tokenId}
setPfpTxHash={setPfpTxHash}
back={back}
/>
</>
);
Expand Down

0 comments on commit df8466a

Please sign in to comment.