Skip to content

Commit

Permalink
Merge pull request #422 from xmtp-labs/dj/portable-consent-changes
Browse files Browse the repository at this point in the history
Portable Consent Changes
  • Loading branch information
daria-github authored Jan 23, 2024
2 parents a02edc8 + f35b2a3 commit e57d4ab
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 128 deletions.
170 changes: 86 additions & 84 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions src/component-library/components/AddressInput/AddressInput.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
ChevronLeftIcon,
InformationCircleIcon,
} from "@heroicons/react/outline";
import { ChevronLeftIcon, XCircleIcon } from "@heroicons/react/outline";
import { useTranslation } from "react-i18next";
import { Avatar } from "../Avatar/Avatar";
import { classNames } from "../../../helpers";
Expand Down Expand Up @@ -41,10 +38,6 @@ interface AddressInputProps {
* Upon submit, is something loading?
*/
isLoading?: boolean;
/**
* Is there a tooltip click event that needs to be handled?
*/
onTooltipClick?: () => void;
/**
* Input Value
*/
Expand All @@ -53,6 +46,10 @@ interface AddressInputProps {
* Is there a left icon click event that needs to be handled?
*/
onLeftIconClick?: () => void;
/**
* Is there a right icon click event that needs to be handled?
*/
onRightIconClick?: () => void;
}

export const AddressInput = ({
Expand All @@ -61,9 +58,9 @@ export const AddressInput = ({
avatarUrlProps,
onChange,
isError,
onTooltipClick,
value,
onLeftIconClick,
onRightIconClick,
}: AddressInputProps) => {
const { t } = useTranslation();
const subtextColor = isError ? "text-red-600" : "text-gray-500";
Expand Down Expand Up @@ -127,8 +124,12 @@ export const AddressInput = ({
</div>
</div>
</form>
{onTooltipClick && (
<InformationCircleIcon onClick={onTooltipClick} height="24" />
{onRightIconClick && (
<XCircleIcon
onClick={onRightIconClick}
height="24"
className="text-red-600 cursor-pointer"
/>
)}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const AcceptOrDeny = ({ address }: { address: string }) => {
const { t } = useTranslation();
const { allow, deny } = useConsent();
const activeTab = useXmtpStore((s) => s.activeTab);
const setActiveTab = useXmtpStore((s) => s.setActiveTab);
const changedConsentCount = useXmtpStore((s) => s.changedConsentCount);
const setChangedConsentCount = useXmtpStore((s) => s.setChangedConsentCount);

const [modalOpen, setModalOpen] = useState(true);

Expand All @@ -51,8 +52,8 @@ const AcceptOrDeny = ({ address }: { address: string }) => {
className="text-indigo-600 flex w-full justify-center border border-2 border-indigo-600 rounded-md p-2 hover:bg-indigo-600 hover:text-white"
onClick={() => {
void allow([address]);
setActiveTab("messages");
setModalOpen(false);
setChangedConsentCount(changedConsentCount + 1);
}}>
{t("consent.accept")}
</button>
Expand All @@ -61,8 +62,8 @@ const AcceptOrDeny = ({ address }: { address: string }) => {
className="text-red-600 flex w-full justify-center border border-2 border-red-600 rounded-md p-2 hover:bg-red-600 hover:text-white"
onClick={() => {
void deny([address]);
setActiveTab("blocked");
setModalOpen(false);
setChangedConsentCount(changedConsentCount + 1);
}}>
{t("consent.block")}
</button>
Expand Down
10 changes: 9 additions & 1 deletion src/controllers/AddressInputController.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from "react";
import { useConversation } from "@xmtp/react-sdk";
import { useConversation, useConsent } from "@xmtp/react-sdk";
import { AddressInput } from "../component-library/components/AddressInput/AddressInput";
import { getRecipientInputSubtext, shortAddress } from "../helpers";
import useWindowSize from "../hooks/useWindowSize";
Expand All @@ -20,7 +20,11 @@ export const AddressInputController = () => {
const setRecipientInput = useXmtpStore((s) => s.setRecipientInput);
const setStartedFirstMessage = useXmtpStore((s) => s.setStartedFirstMessage);
const setConversationTopic = useXmtpStore((s) => s.setConversationTopic);
const changedConsentCount = useXmtpStore((s) => s.changedConsentCount);
const setChangedConsentCount = useXmtpStore((s) => s.setChangedConsentCount);

const { getCachedByPeerAddress, getCachedByTopic } = useConversation();
const { deny } = useConsent();

// manage address input state
useAddressInput();
Expand Down Expand Up @@ -100,6 +104,10 @@ export const AddressInputController = () => {
setStartedFirstMessage(false);
setConversationTopic("");
}}
onRightIconClick={() => {
void deny([recipientAddress]);
setChangedConsentCount(changedConsentCount + 1);
}}
/>
);
};
Loading

1 comment on commit e57d4ab

@vercel
Copy link

@vercel vercel bot commented on e57d4ab Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.