-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this 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 = { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 /> |
There was a problem hiding this comment.
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.
No description provided.