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

feat: privy login, query hooks #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

0xlazykitty
Copy link
Collaborator

No description provided.

Copy link

changeset-bot bot commented Oct 29, 2024

⚠️ No Changeset found

Latest commit: 590df49

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@0xlazykitty 0xlazykitty requested a review from peersky October 29, 2024 12:18
Copy link
Member

@peersky peersky left a comment

Choose a reason for hiding this comment

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

Few notes:

  • When cross-domain lookup is is disabled, the targetDomain field should be disabled/hidden (append empty bytes string to payload corresponding value)
  • remove "domain.com" input field , mockups ment the browser address string there
  • Query button also should require web3 login
  • Pressing submit on query widget should trigger query logic on chain and attempt resolve user name

return query;
}

type QueryByFullDetailsArgs = {
Copy link
Member

Choose a reason for hiding this comment

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

You can import this structure from rankify-contracts/types

Copy link
Member

Choose a reason for hiding this comment

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

Consider using this (copy whatever useful):

import { Multipass } from "rankify-js";
import { Web3ProviderInterface } from "../types";
import { useMutation, useQuery } from "react-query";
import { queryCacheProps } from "./hookCommon";
import { BigNumber, ethers } from "ethers";
import { MultipassDiamond } from "rankify-contracts/types";
import { LibMultipass } from "rankify-contracts/types/src/facets/DNSFacet";
export const useMultipass = ({
    web3ctx,
}: {
    web3ctx: Web3ProviderInterface;
}) => {
    if (!web3ctx.chainId) throw new Error("chain Id not defined");
    const chainDeploymentName = web3ctx.getChainFromId(web3ctx.chainId);
    if (!chainDeploymentName) throw new Error("chain not supported");
    const multipassDiamond =
        require(`rankify-contracts/deployments/${chainDeploymentName}/Multipass.json`) as any;

    const queryKey = ["multipass"];

    const userName = useQuery(
        [...queryKey, "username", web3ctx.account],

        () => {
            const contract = new ethers.Contract(
                multipassDiamond.address,
                multipassDiamond.abi,
                web3ctx.signer
            ) as MultipassDiamond;

            const mp = new Multipass({
                chainId: web3ctx.chainId,
                contractName: "MultipassDNS",
                version: "0.0.1",
            });

            return contract
                .resolveRecord(
                    mp.formQueryByAddress({
                        address: web3ctx.account ?? "",
                        domainName: "Rankify.it",
                    })
                )
                .then(([success, record]) => ({
                    name: ethers.utils.parseBytes32String(record.name),
                    id: record.id,
                }));
        },
        {
            ...queryCacheProps,
            refetchInterval: 3000,
            enabled:
                !!web3ctx.account && !!web3ctx.chainId && !!web3ctx.provider,
            onSettled: (e) => {},
        }
    );

    const emptyUserQuery: LibMultipass.NameQueryStruct = {
        name: ethers.utils.formatBytes32String(""),
        id: ethers.utils.formatBytes32String(""),
        domainName: ethers.utils.formatBytes32String(""),
        wallet: ethers.constants.AddressZero,
        targetDomain: ethers.utils.formatBytes32String(""),
    };

    const signUp = useMutation(
        ({
            message,
            registrarSignature,
            deadline,
        }: {
            message: LibMultipass.RecordStruct;
            deadline: BigNumber;
            registrarSignature: string;
        }) => {
            const contract = new ethers.Contract(
                multipassDiamond.address,
                multipassDiamond.abi,
                web3ctx.signer
            ) as MultipassDiamond;

            return contract.register(
                message,
                message.domainName,
                registrarSignature,
                deadline,
                emptyUserQuery,
                ethers.constants.HashZero,
                { maxFeePerGas: 100000000000, maxPriorityFeePerGas: 1000000000 }
            );
        },
        {
            onSuccess: (e) => {
                userName.refetch();
            },
        }
    );

    const resolveAddress = async (address: string) => {
        const contract = new ethers.Contract(
            multipassDiamond.address,
            multipassDiamond.abi,
            web3ctx.signer
        ) as MultipassDiamond;

        const mp = new Multipass({
            chainId: web3ctx.chainId,
            contractName: "MultipassDNS",
            version: "0.0.1",
        });
        return contract
            .resolveRecord(
                mp.formQueryByAddress({
                    address: address,
                    domainName: "Rankify.it",
                })
            )
            .then(([success, record]) => {
                return ethers.utils.parseBytes32String(record.name);
            })
            .then((r) => (r === "" ? address : r));
    };

    return { userName, signUp, resolveAddress };
};

export const LoginForm = ({ onLogIn }: { onLogIn: () => void }) => {
export const LoginForm = () => {
const { login } = usePrivy();

return (
<div className="flex flex-col gap-2 border rounded-xl p-4">
<DomainDropdown />
Copy link
Member

Choose a reason for hiding this comment

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

Can you index all possible domains from event data on contract?

You can query by

    /**
     * @dev Emitted when a domain is activated.
     * @param domainName The name of the activated domain.
     */
    event DomainActivated(bytes32 indexed domainName);

    /**
     * @dev Emitted when a domain is deactivated.
     * @param domainName The name of the deactivated domain.
     */
    event DomainDeactivated(bytes32 indexed domainName);

Domains that were activated and were not disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants