feat: display user stark domain in sidebar
irisdv opened this issue · comments
Iris commented
This feature will allow users to see their main domain instead of their hex address.
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]
});
In starknet-snap:
- Create a new method in Starknet MetaMask Snap API :
starkNet_getStarkName
- In starknet-snap/src create a
getStarkName
function
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 functiongetStarkName
that will use the starknet.js functiongetStarkName
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
- In useStarkNetSnap.ts, add a call to our function
starkNet_getStarkName
- Then we can use it in the SideBar component
- update AccountAddress.view.tsx to have a new variable
name
interface Props {
address: string;
full?: boolean;
placement?: PopperPlacementType;
// new variable
name?: string
}
- if
name
is defined then showname
instead ofaddress
. It would require to create ashortenName
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 !
Mario Christopher commented
Looks good.