Consensys / starknet-snap

The MetaMask Snap for Starknet

Home Page:https://snaps.consensys.net/starknet

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat: display user stark domain in sidebar

irisdv opened this issue · comments

This feature will allow users to see their main domain instead of their hex address.

Capture d’écran 2023-11-30 à 14 48 46

Implementation proposal

To retrieve the stark name from the user address, we can call the function address_to_domain from the starknet ID naming contract. This function returns an array of felt that need to be decoded to be readable. You can find more information on our encoding and decoding algorithm here.

callContract({
    contractAddress: namingContract,
    entrypoint: 'address_to_domain',
    calldata: [address]
});

Source code

In starknet-snap:

export async function getStarkName(params: ApiParams) {
  try {
    const { state, requestParams } = params;
    const requestParamsObj = requestParams as GetStarkNameRequestParam;

    // validate requestParamsObj.address argument
    // get network

    // Call a util function to get the stark domain
    const name = await getStarkNameUtil(network, requestParamsObj.address);
    logger.log(`getStarkName: name:\n${toJson(name)}`);

    return name;
  } catch (err) {
    logger.error(`Problem found: ${err}`);
    throw err;
  }
}
  • In starknetUtils.ts, create a util function getStarkName that will use the starknet.js function getStarkName which already implement calling the starknet ID naming contract and decoding stark domain.
export const getStarkName = async (
  network: Network,
  address: string,
): Promise<string> => {
  const provider = getProvider(network);
  return provider.getStarkName(address)
};

In wallet-ui

interface Props {
  address: string;
  full?: boolean;
  placement?: PopperPlacementType;
  // new variable 
  name?: string
}
  • if name is defined then show name instead of address. It would require to create a shortenName function to shorten the name if it is too long to fit in the UI.

If a significant number of contributors agree with our approach I'll start working on Pull Request.

Please feel free to answer on this issue and tell me what you think !

Looks good.