Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "xk7O5itVsuV3Dfldq3rI3WgggHa3z7HX7e17jzheE8w=",
"shasum": "xFeB7CqtdR3GLUmfSmxzes32oUFEVzCbniKprMtx7vY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/name-lookup/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ChainId } from '@metamask/snaps-sdk';

import { onNameLookup } from '.';

const DOMAIN_MOCK = 'test.domain';
const DOMAIN_MOCK = 'fooBar';
const ADDRESS_MOCK = '0xc0ffee254729296a45a3885639AC7E10F9d54979';
const CHAIN_ID_MOCK = 'eip155:1' as ChainId;

Expand Down
34 changes: 29 additions & 5 deletions packages/examples/packages/name-lookup/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,36 @@ export const onNameLookup: OnNameLookupHandler = async (request) => {
}

if (domain) {
const resolvedAddress = '0xc0ffee254729296a45a3885639AC7E10F9d54979';
return {
resolvedAddresses: [
{ resolvedAddress, protocol: 'test protocol', domainName: domain },
],
const resolutions = {
fooBar: '0xc0ffee254729296a45a3885639AC7E10F9d54979',
bar: '0x0000000000000000000000000000000000000000',
barstool: '0x1234567890123456789012345678901234567890',
};

const getResolution = (domainName: string) => {
if (resolutions[domainName]) {
return {
resolvedAddress: resolutions[domainName],
domainName,
protocol: 'test protocol',
};
}
const entries = Object.entries(resolutions);
for (const [key, value] of entries) {
if (key.toLowerCase().startsWith(domainName.toLowerCase())) {
return {
domainName: key,
resolvedAddress: value,
protocol: 'test protocol',
};
}
}
return null;
};
const fetchedResolution = getResolution(domain);
if (fetchedResolution !== null) {
return { resolvedAddresses: [fetchedResolution] };
}
}

return null;
Expand Down
Loading