Skip to content

Commit

Permalink
- update return param for resolvedAddresses according to new spec
Browse files Browse the repository at this point in the history
  • Loading branch information
lennardevertz committed Aug 22, 2024
1 parent eb070ce commit 6375757
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/idriss-crypto/snap/tree/main/packages/snap"
},
"source": {
"shasum": "e62eZBXNxmhAJNEekne9FE4al/PwbyFoesoGWgHptGM=",
"shasum": "rZ3/bn8vq8mEBpc9WsKQTIgmz+Rs/SzZX4QUfnpmN3g=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
6 changes: 6 additions & 0 deletions packages/snap/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('onNameLookup', () => {
{
resolvedAddress: TWITTER_ADDRESS_MOCK,
protocol: 'IDriss',
domainName: TWITTER_MOCK,
},
],
});
Expand All @@ -57,6 +58,7 @@ describe('onNameLookup', () => {
{
resolvedAddress: MAIL_ADDRESS_MOCK,
protocol: 'IDriss',
domainName: MAIL_MOCK,
},
],
});
Expand Down Expand Up @@ -84,6 +86,7 @@ describe('onNameLookup', () => {
{
resolvedAddress: UD_ADDRESS_MOCK,
protocol: 'Unstoppable Domains',
domainName: UD_DOMAIN_MOCK,
},
],
});
Expand Down Expand Up @@ -111,6 +114,7 @@ describe('onNameLookup', () => {
{
resolvedAddress: ENS_ADDRESS_MOCK,
protocol: 'ENS',
domainName: ENS_DOMAIN_MOCK,
},
],
});
Expand Down Expand Up @@ -138,6 +142,7 @@ describe('onNameLookup', () => {
{
resolvedAddress: FARCASTER_ADDRESS_MOCK,
protocol: 'Farcaster',
domainName: FARCASTER_DOMAIN_MOCK,
},
],
});
Expand Down Expand Up @@ -165,6 +170,7 @@ describe('onNameLookup', () => {
{
resolvedAddress: LENS_ADDRESS_MOCK,
protocol: 'Lens',
domainName: LENS_DOMAIN_MOCK,
},
],
});
Expand Down
8 changes: 6 additions & 2 deletions packages/snap/src/resolvers/ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const provider = new JsonRpcProvider(ETHEREUM_RPC_URL);
*/
export async function resolveENS(
domain: string,
): Promise<{ resolvedAddress: string; protocol: string }[]> {
): Promise<
{ resolvedAddress: string; protocol: string; domainName: string }[]
> {
const resolvedENS = await provider.resolveName(domain);
if (!resolvedENS) {
return [];
Expand All @@ -28,5 +30,7 @@ export async function resolveENS(
console.log('Error resolving ens:', error);
return [];
}
return [{ resolvedAddress: resolvedENS, protocol: 'ENS' }];
return [
{ resolvedAddress: resolvedENS, protocol: 'ENS', domainName: domain },
];
}
12 changes: 10 additions & 2 deletions packages/snap/src/resolvers/farcaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { BASE_API_URL } from '../constants';
*/
export async function resolveFarcasterName(
domain: string,
): Promise<{ resolvedAddress: string; protocol: string }[]> {
): Promise<
{ resolvedAddress: string; protocol: string; domainName: string }[]
> {
try {
let userFID: string;
let connectedAddress = '';
Expand Down Expand Up @@ -45,7 +47,13 @@ export async function resolveFarcasterName(
}

if (connectedAddress) {
return [{ resolvedAddress: connectedAddress, protocol: 'Farcaster' }];
return [
{
resolvedAddress: connectedAddress,
protocol: 'Farcaster',
domainName: domain,
},
];
}
return [];
} catch (error) {
Expand Down
12 changes: 10 additions & 2 deletions packages/snap/src/resolvers/idriss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const resolverContract = contract as IDrissResolver;
export async function resolveIDriss(
userInput: string,
resolveOptions: ResolveOptions = {},
): Promise<{ resolvedAddress: string; protocol: string }[]> {
): Promise<
{ resolvedAddress: string; protocol: string; domainName: string }[]
> {
const identifier = await transformIdentifier(userInput);
const filteredWalletTags = filterWalletTags(resolveOptions);

Expand Down Expand Up @@ -72,5 +74,11 @@ export async function resolveIDriss(

const publicETH = entries.find((entry) => entry[0] === 'Public ETH');
const resolvedIDriss = publicETH?.[1] ?? entries[0]?.[1] ?? '';
return [{ resolvedAddress: resolvedIDriss, protocol: 'IDriss' }];
return [
{
resolvedAddress: resolvedIDriss,
protocol: 'IDriss',
domainName: userInput,
},
];
}
8 changes: 6 additions & 2 deletions packages/snap/src/resolvers/lens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const client = new LensClient({
*/
export async function resolveLensProfile(
domain: string,
): Promise<{ resolvedAddress: string; protocol: string }[]> {
): Promise<
{ resolvedAddress: string; protocol: string; domainName: string }[]
> {
try {
const handle = domain.replace('@', '').replace('.lens', '');

Expand All @@ -22,7 +24,9 @@ export async function resolveLensProfile(
// Resolve the address using LensClient
const address = await client.handle.resolveAddress({ handle: lensHandle });
if (address) {
return [{ resolvedAddress: address, protocol: 'Lens' }];
return [
{ resolvedAddress: address, protocol: 'Lens', domainName: domain },
];
}
return [];
} catch (error) {
Expand Down
8 changes: 6 additions & 2 deletions packages/snap/src/resolvers/unstoppable_domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ import { BASE_API_URL } from '../constants';
*/
export async function resolveUnstoppableDomain(
domain: string,
): Promise<{ resolvedAddress: string; protocol: string }[]> {
): Promise<
{ resolvedAddress: string; protocol: string; domainName: string }[]
> {
const response = await fetch(
`${BASE_API_URL}resolve-unstoppable-domains?domain=${domain}`,
);
const data = await response.json();
const resolvedAddress = data.records['crypto.ETH.address'] as string;
if (resolvedAddress) {
return [{ resolvedAddress, protocol: 'Unstoppable Domains' }];
return [
{ resolvedAddress, protocol: 'Unstoppable Domains', domainName: domain },
];
}
return [];
}

0 comments on commit 6375757

Please sign in to comment.